| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // SourceBufferStream is a data structure that stores media Buffers in ranges. | 5 // SourceBufferStream is a data structure that stores media Buffers in ranges. |
| 6 // Buffers can be appended out of presentation order. Buffers are retrieved by | 6 // Buffers can be appended out of presentation order. Buffers are retrieved by |
| 7 // seeking to the desired start point and calling GetNextBuffer(). Buffers are | 7 // seeking to the desired start point and calling GetNextBuffer(). Buffers are |
| 8 // returned in sequential presentation order. | 8 // returned in sequential presentation order. |
| 9 | 9 |
| 10 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ | 10 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // Signals that the next buffers appended are part of a new media segment | 67 // Signals that the next buffers appended are part of a new media segment |
| 68 // starting at |media_segment_start_time|. | 68 // starting at |media_segment_start_time|. |
| 69 void OnNewMediaSegment(base::TimeDelta media_segment_start_time); | 69 void OnNewMediaSegment(base::TimeDelta media_segment_start_time); |
| 70 | 70 |
| 71 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are | 71 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are |
| 72 // expected to be in order, but multiple calls to Append() may add buffers out | 72 // expected to be in order, but multiple calls to Append() may add buffers out |
| 73 // of order or overlapping. Assumes all buffers within |buffers| are in | 73 // of order or overlapping. Assumes all buffers within |buffers| are in |
| 74 // presentation order and are non-overlapping. | 74 // presentation order and are non-overlapping. |
| 75 // Returns true if Append() was successful, false if |buffers| are not added. | 75 // Returns true if Append() was successful, false if |buffers| are not added. |
| 76 // TODO(vrk): Implement garbage collection. (crbug.com/125070) | 76 // TODO(vrk): Implement garbage collection. (crbug.com/125070) |
| 77 bool Append(const BufferQueue& buffers); | 77 bool Append(const BufferQueue& buffers, |
| 78 base::TimeDelta media_time); |
| 78 | 79 |
| 79 // Removes buffers between |start| and |end| according to the steps | 80 // Removes buffers between |start| and |end| according to the steps |
| 80 // in the "Coded Frame Removal Algorithm" in the Media Source | 81 // in the "Coded Frame Removal Algorithm" in the Media Source |
| 81 // Extensions Spec. | 82 // Extensions Spec. |
| 82 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc
e.html#sourcebuffer-coded-frame-removal | 83 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc
e.html#sourcebuffer-coded-frame-removal |
| 83 // | 84 // |
| 84 // |duration| is the current duration of the presentation. It is | 85 // |duration| is the current duration of the presentation. It is |
| 85 // required by the computation outlined in the spec. | 86 // required by the computation outlined in the spec. |
| 86 void Remove(base::TimeDelta start, base::TimeDelta end, | 87 void Remove(base::TimeDelta start, base::TimeDelta end, |
| 87 base::TimeDelta duration); | 88 base::TimeDelta duration); |
| 88 | 89 |
| 90 // Update the playback time. |
| 91 // This playback time is used to avoid garbage collecting buffers |
| 92 // corresponding to the playback time: |
| 93 // MSE spec - 2.4.4 SourceBuffer Monitoring. |
| 94 void NotifyMediaTimeUpdate(base::TimeDelta media_time); |
| 95 |
| 89 // Changes the SourceBufferStream's state so that it will start returning | 96 // Changes the SourceBufferStream's state so that it will start returning |
| 90 // buffers starting from the closest keyframe before |timestamp|. | 97 // buffers starting from the closest keyframe before |timestamp|. |
| 91 void Seek(base::TimeDelta timestamp); | 98 void Seek(base::TimeDelta timestamp); |
| 92 | 99 |
| 93 // Returns true if the SourceBufferStream has seeked to a time without | 100 // Returns true if the SourceBufferStream has seeked to a time without |
| 94 // buffered data and is waiting for more data to be appended. | 101 // buffered data and is waiting for more data to be appended. |
| 95 bool IsSeekPending() const; | 102 bool IsSeekPending() const; |
| 96 | 103 |
| 97 // Notifies the SourceBufferStream that the media duration has been changed to | 104 // Notifies the SourceBufferStream that the media duration has been changed to |
| 98 // |duration| so it should drop any data past that point. | 105 // |duration| so it should drop any data past that point. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 void set_memory_limit_for_testing(int memory_limit) { | 149 void set_memory_limit_for_testing(int memory_limit) { |
| 143 memory_limit_ = memory_limit; | 150 memory_limit_ = memory_limit; |
| 144 } | 151 } |
| 145 | 152 |
| 146 private: | 153 private: |
| 147 friend class SourceBufferStreamTest; | 154 friend class SourceBufferStreamTest; |
| 148 | 155 |
| 149 typedef std::list<SourceBufferRange*> RangeList; | 156 typedef std::list<SourceBufferRange*> RangeList; |
| 150 | 157 |
| 151 // Frees up space if the SourceBufferStream is taking up too much memory. | 158 // Frees up space if the SourceBufferStream is taking up too much memory. |
| 152 void GarbageCollectIfNeeded(); | 159 void GarbageCollectIfNeeded(base::TimeDelta media_time); |
| 153 | 160 |
| 154 // Attempts to delete approximately |total_bytes_to_free| amount of data | 161 // Attempts to delete approximately |total_bytes_to_free| amount of data |
| 155 // |ranges_|, starting at the front of |ranges_| and moving linearly forward | 162 // |ranges_|, starting at the front of |ranges_| and moving linearly forward |
| 156 // through the buffers. Deletes starting from the back if |reverse_direction| | 163 // through the buffers. Deletes starting from the back if |reverse_direction| |
| 157 // is true. Returns the number of bytes freed. | 164 // is true. Returns the number of bytes freed. |
| 158 int FreeBuffers(int total_bytes_to_free, bool reverse_direction); | 165 int FreeBuffers(int total_bytes_to_free, |
| 166 bool reverse_direction, |
| 167 base::TimeDelta media_time); |
| 159 | 168 |
| 160 // Attempts to delete approximately |total_bytes_to_free| amount of data from | 169 // Attempts to delete approximately |total_bytes_to_free| amount of data from |
| 161 // |ranges_|, starting after the last appended buffer before the current | 170 // |ranges_|, starting after the last appended buffer before the current |
| 162 // playback position. | 171 // playback position. |
| 163 int FreeBuffersAfterLastAppended(int total_bytes_to_free); | 172 int FreeBuffersAfterLastAppended(int total_bytes_to_free); |
| 164 | 173 |
| 165 // Gets the removal range to secure |byte_to_free| from | 174 // Gets the removal range to secure |byte_to_free| from |
| 166 // [|start_timestamp|, |end_timestamp|). | 175 // [|start_timestamp|, |end_timestamp|). |
| 167 // Returns the size of buffers to secure if future | 176 // Returns the size of buffers to secure if future |
| 168 // Remove(|start_timestamp|, |removal_end_timestamp|, duration) is called. | 177 // Remove(|start_timestamp|, |removal_end_timestamp|, duration) is called. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 bool end_of_stream_; | 370 bool end_of_stream_; |
| 362 | 371 |
| 363 // Timestamp of the last request to Seek(). | 372 // Timestamp of the last request to Seek(). |
| 364 base::TimeDelta seek_buffer_timestamp_; | 373 base::TimeDelta seek_buffer_timestamp_; |
| 365 | 374 |
| 366 // Pointer to the seeked-to Range. This is the range from which | 375 // Pointer to the seeked-to Range. This is the range from which |
| 367 // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been | 376 // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been |
| 368 // emptied. | 377 // emptied. |
| 369 SourceBufferRange* selected_range_; | 378 SourceBufferRange* selected_range_; |
| 370 | 379 |
| 380 // Current media time. |
| 381 // This does not need to be very accurate as long as it represents a lower |
| 382 // bound of the media time. |
| 383 base::TimeDelta current_media_time_; |
| 384 |
| 371 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If | 385 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If |
| 372 // |track_buffer_| is empty, return buffers from |selected_range_|. | 386 // |track_buffer_| is empty, return buffers from |selected_range_|. |
| 373 BufferQueue track_buffer_; | 387 BufferQueue track_buffer_; |
| 374 | 388 |
| 375 // The start time of the current media segment being appended. | 389 // The start time of the current media segment being appended. |
| 376 base::TimeDelta media_segment_start_time_; | 390 base::TimeDelta media_segment_start_time_; |
| 377 | 391 |
| 378 // Points to the range containing the current media segment being appended. | 392 // Points to the range containing the current media segment being appended. |
| 379 RangeList::iterator range_for_next_append_; | 393 RangeList::iterator range_for_next_append_; |
| 380 | 394 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 431 |
| 418 // Indicates that splice frame generation is enabled. | 432 // Indicates that splice frame generation is enabled. |
| 419 const bool splice_frames_enabled_; | 433 const bool splice_frames_enabled_; |
| 420 | 434 |
| 421 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); | 435 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); |
| 422 }; | 436 }; |
| 423 | 437 |
| 424 } // namespace media | 438 } // namespace media |
| 425 | 439 |
| 426 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ | 440 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
| OLD | NEW |