Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: media/filters/source_buffer_stream.h

Issue 447963003: Introduce DecodeTimestamp class to make it easier to distiguish presentation and decode timestamps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const LogCB& log_cb, 59 const LogCB& log_cb,
60 bool splice_frames_enabled); 60 bool splice_frames_enabled);
61 SourceBufferStream(const TextTrackConfig& text_config, 61 SourceBufferStream(const TextTrackConfig& text_config,
62 const LogCB& log_cb, 62 const LogCB& log_cb,
63 bool splice_frames_enabled); 63 bool splice_frames_enabled);
64 64
65 ~SourceBufferStream(); 65 ~SourceBufferStream();
66 66
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 // TODO(acolwell/wolenetz): This should be changed to a presentation
70 // timestamp. See http://crbug.com/402502
71 void OnNewMediaSegment(DecodeTimestamp media_segment_start_time);
70 72
71 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are 73 // 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 74 // 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 75 // of order or overlapping. Assumes all buffers within |buffers| are in
74 // presentation order and are non-overlapping. 76 // presentation order and are non-overlapping.
75 // Returns true if Append() was successful, false if |buffers| are not added. 77 // Returns true if Append() was successful, false if |buffers| are not added.
76 // TODO(vrk): Implement garbage collection. (crbug.com/125070) 78 // TODO(vrk): Implement garbage collection. (crbug.com/125070)
77 bool Append(const BufferQueue& buffers); 79 bool Append(const BufferQueue& buffers);
78 80
79 // Removes buffers between |start| and |end| according to the steps 81 // Removes buffers between |start| and |end| according to the steps
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // Attempts to delete approximately |total_bytes_to_free| amount of data from 162 // Attempts to delete approximately |total_bytes_to_free| amount of data from
161 // |ranges_|, starting after the last appended buffer before the current 163 // |ranges_|, starting after the last appended buffer before the current
162 // playback position. 164 // playback position.
163 int FreeBuffersAfterLastAppended(int total_bytes_to_free); 165 int FreeBuffersAfterLastAppended(int total_bytes_to_free);
164 166
165 // Gets the removal range to secure |byte_to_free| from 167 // Gets the removal range to secure |byte_to_free| from
166 // [|start_timestamp|, |end_timestamp|). 168 // [|start_timestamp|, |end_timestamp|).
167 // Returns the size of buffers to secure if future 169 // Returns the size of buffers to secure if future
168 // Remove(|start_timestamp|, |removal_end_timestamp|, duration) is called. 170 // Remove(|start_timestamp|, |removal_end_timestamp|, duration) is called.
169 // Will not update |removal_end_timestamp| if the returned size is 0. 171 // Will not update |removal_end_timestamp| if the returned size is 0.
170 int GetRemovalRange(base::TimeDelta start_timestamp, 172 int GetRemovalRange(DecodeTimestamp start_timestamp,
171 base::TimeDelta end_timestamp, int byte_to_free, 173 DecodeTimestamp end_timestamp, int byte_to_free,
172 base::TimeDelta* removal_end_timestamp); 174 DecodeTimestamp* removal_end_timestamp);
173 175
174 // Prepares |range_for_next_append_| so |new_buffers| can be appended. 176 // Prepares |range_for_next_append_| so |new_buffers| can be appended.
175 // This involves removing buffers between the end of the previous append 177 // This involves removing buffers between the end of the previous append
176 // and any buffers covered by the time range in |new_buffers|. 178 // and any buffers covered by the time range in |new_buffers|.
177 // |deleted_buffers| is an output parameter containing candidates for 179 // |deleted_buffers| is an output parameter containing candidates for
178 // |track_buffer_| if this method ends up removing the current playback 180 // |track_buffer_| if this method ends up removing the current playback
179 // position from the range. 181 // position from the range.
180 void PrepareRangesForNextAppend(const BufferQueue& new_buffers, 182 void PrepareRangesForNextAppend(const BufferQueue& new_buffers,
181 BufferQueue* deleted_buffers); 183 BufferQueue* deleted_buffers);
182 184
183 // Removes buffers, from the |track_buffer_|, that come after |timestamp|. 185 // Removes buffers, from the |track_buffer_|, that come after |timestamp|.
184 void PruneTrackBuffer(const base::TimeDelta timestamp); 186 void PruneTrackBuffer(const DecodeTimestamp timestamp);
185 187
186 // Checks to see if |range_with_new_buffers_itr| can be merged with the range 188 // Checks to see if |range_with_new_buffers_itr| can be merged with the range
187 // next to it, and merges them if so. 189 // next to it, and merges them if so.
188 void MergeWithAdjacentRangeIfNecessary( 190 void MergeWithAdjacentRangeIfNecessary(
189 const RangeList::iterator& range_with_new_buffers_itr); 191 const RangeList::iterator& range_with_new_buffers_itr);
190 192
191 // Returns true if |second_timestamp| is the timestamp of the next buffer in 193 // Returns true if |second_timestamp| is the timestamp of the next buffer in
192 // sequence after |first_timestamp|, false otherwise. 194 // sequence after |first_timestamp|, false otherwise.
193 bool AreAdjacentInSequence( 195 bool AreAdjacentInSequence(
194 base::TimeDelta first_timestamp, base::TimeDelta second_timestamp) const; 196 DecodeTimestamp first_timestamp, DecodeTimestamp second_timestamp) const;
195 197
196 // Helper method that returns the timestamp for the next buffer that 198 // Helper method that returns the timestamp for the next buffer that
197 // |selected_range_| will return from GetNextBuffer() call, or kNoTimestamp() 199 // |selected_range_| will return from GetNextBuffer() call, or kNoTimestamp()
198 // if in between seeking (i.e. |selected_range_| is null). 200 // if in between seeking (i.e. |selected_range_| is null).
199 base::TimeDelta GetNextBufferTimestamp(); 201 DecodeTimestamp GetNextBufferTimestamp();
200
201 // Returns the timestamp of the last buffer in the |selected_range_| or
202 // kNoTimestamp() if |selected_range_| is null.
203 base::TimeDelta GetEndBufferTimestamp();
204 202
205 // Finds the range that should contain a media segment that begins with 203 // Finds the range that should contain a media segment that begins with
206 // |start_timestamp| and returns the iterator pointing to it. Returns 204 // |start_timestamp| and returns the iterator pointing to it. Returns
207 // |ranges_.end()| if there's no such existing range. 205 // |ranges_.end()| if there's no such existing range.
208 RangeList::iterator FindExistingRangeFor(base::TimeDelta start_timestamp); 206 RangeList::iterator FindExistingRangeFor(DecodeTimestamp start_timestamp);
209 207
210 // Inserts |new_range| into |ranges_| preserving sorted order. Returns an 208 // Inserts |new_range| into |ranges_| preserving sorted order. Returns an
211 // iterator in |ranges_| that points to |new_range|. 209 // iterator in |ranges_| that points to |new_range|.
212 RangeList::iterator AddToRanges(SourceBufferRange* new_range); 210 RangeList::iterator AddToRanges(SourceBufferRange* new_range);
213 211
214 // Returns an iterator that points to the place in |ranges_| where 212 // Returns an iterator that points to the place in |ranges_| where
215 // |selected_range_| lives. 213 // |selected_range_| lives.
216 RangeList::iterator GetSelectedRangeItr(); 214 RangeList::iterator GetSelectedRangeItr();
217 215
218 // Sets the |selected_range_| to |range| and resets the next buffer position 216 // Sets the |selected_range_| to |range| and resets the next buffer position
219 // for the previous |selected_range_|. 217 // for the previous |selected_range_|.
220 void SetSelectedRange(SourceBufferRange* range); 218 void SetSelectedRange(SourceBufferRange* range);
221 219
222 // Seeks |range| to |seek_timestamp| and then calls SetSelectedRange() with 220 // Seeks |range| to |seek_timestamp| and then calls SetSelectedRange() with
223 // |range|. 221 // |range|.
224 void SeekAndSetSelectedRange(SourceBufferRange* range, 222 void SeekAndSetSelectedRange(SourceBufferRange* range,
225 base::TimeDelta seek_timestamp); 223 DecodeTimestamp seek_timestamp);
226 224
227 // Resets this stream back to an unseeked state. 225 // Resets this stream back to an unseeked state.
228 void ResetSeekState(); 226 void ResetSeekState();
229 227
230 // Returns true if |seek_timestamp| refers to the beginning of the first range 228 // Returns true if |seek_timestamp| refers to the beginning of the first range
231 // in |ranges_|, false otherwise or if |ranges_| is empty. 229 // in |ranges_|, false otherwise or if |ranges_| is empty.
232 bool ShouldSeekToStartOfBuffered(base::TimeDelta seek_timestamp) const; 230 bool ShouldSeekToStartOfBuffered(base::TimeDelta seek_timestamp) const;
233 231
234 // Returns true if the timestamps of |buffers| are monotonically increasing 232 // Returns true if the timestamps of |buffers| are monotonically increasing
235 // since the previous append to the media segment, false otherwise. 233 // since the previous append to the media segment, false otherwise.
236 bool IsMonotonicallyIncreasing(const BufferQueue& buffers) const; 234 bool IsMonotonicallyIncreasing(const BufferQueue& buffers) const;
237 235
238 // Returns true if |next_timestamp| and |next_is_keyframe| are valid for 236 // Returns true if |next_timestamp| and |next_is_keyframe| are valid for
239 // the first buffer after the previous append. 237 // the first buffer after the previous append.
240 bool IsNextTimestampValid(base::TimeDelta next_timestamp, 238 bool IsNextTimestampValid(DecodeTimestamp next_timestamp,
241 bool next_is_keyframe) const; 239 bool next_is_keyframe) const;
242 240
243 // Returns true if |selected_range_| is the only range in |ranges_| that 241 // Returns true if |selected_range_| is the only range in |ranges_| that
244 // HasNextBufferPosition(). 242 // HasNextBufferPosition().
245 bool OnlySelectedRangeIsSeeked() const; 243 bool OnlySelectedRangeIsSeeked() const;
246 244
247 // Measures the distances between buffer timestamps and tracks the max. 245 // Measures the distances between buffer timestamps and tracks the max.
248 void UpdateMaxInterbufferDistance(const BufferQueue& buffers); 246 void UpdateMaxInterbufferDistance(const BufferQueue& buffers);
249 247
250 // Sets the config ID for each buffer to |append_config_index_|. 248 // Sets the config ID for each buffer to |append_config_index_|.
251 void SetConfigIds(const BufferQueue& buffers); 249 void SetConfigIds(const BufferQueue& buffers);
252 250
253 // Called to complete a config change. Updates |current_config_index_| to 251 // Called to complete a config change. Updates |current_config_index_| to
254 // match the index of the next buffer. Calling this method causes 252 // match the index of the next buffer. Calling this method causes
255 // GetNextBuffer() to stop returning kConfigChange and start returning 253 // GetNextBuffer() to stop returning kConfigChange and start returning
256 // kSuccess. 254 // kSuccess.
257 void CompleteConfigChange(); 255 void CompleteConfigChange();
258 256
259 // Sets |selected_range_| and seeks to the nearest keyframe after 257 // Sets |selected_range_| and seeks to the nearest keyframe after
260 // |timestamp| if necessary and possible. This method only attempts to 258 // |timestamp| if necessary and possible. This method only attempts to
261 // set |selected_range_| if |seleted_range_| is null and |track_buffer_| 259 // set |selected_range_| if |seleted_range_| is null and |track_buffer_|
262 // is empty. 260 // is empty.
263 void SetSelectedRangeIfNeeded(const base::TimeDelta timestamp); 261 void SetSelectedRangeIfNeeded(const DecodeTimestamp timestamp);
264 262
265 // Find a keyframe timestamp that is >= |start_timestamp| and can be used to 263 // Find a keyframe timestamp that is >= |start_timestamp| and can be used to
266 // find a new selected range. 264 // find a new selected range.
267 // Returns kNoTimestamp() if an appropriate keyframe timestamp could not be 265 // Returns kNoTimestamp() if an appropriate keyframe timestamp could not be
268 // found. 266 // found.
269 base::TimeDelta FindNewSelectedRangeSeekTimestamp( 267 DecodeTimestamp FindNewSelectedRangeSeekTimestamp(
270 const base::TimeDelta start_timestamp); 268 const DecodeTimestamp start_timestamp);
271 269
272 // Searches |ranges_| for the first keyframe timestamp that is >= |timestamp|. 270 // Searches |ranges_| for the first keyframe timestamp that is >= |timestamp|.
273 // If |ranges_| doesn't contain a GOP that covers |timestamp| or doesn't 271 // If |ranges_| doesn't contain a GOP that covers |timestamp| or doesn't
274 // have a keyframe after |timestamp| then kNoTimestamp() is returned. 272 // have a keyframe after |timestamp| then kNoTimestamp() is returned.
275 base::TimeDelta FindKeyframeAfterTimestamp(const base::TimeDelta timestamp); 273 DecodeTimestamp FindKeyframeAfterTimestamp(const DecodeTimestamp timestamp);
276 274
277 // Returns "VIDEO" for a video SourceBufferStream, "AUDIO" for an audio 275 // Returns "VIDEO" for a video SourceBufferStream, "AUDIO" for an audio
278 // stream, and "TEXT" for a text stream. 276 // stream, and "TEXT" for a text stream.
279 std::string GetStreamTypeName() const; 277 std::string GetStreamTypeName() const;
280 278
281 // Returns true if we don't have any ranges or the last range is selected 279 // Returns true if we don't have any ranges or the last range is selected
282 // or there is a pending seek beyond any existing ranges. 280 // or there is a pending seek beyond any existing ranges.
283 bool IsEndSelected() const; 281 bool IsEndSelected() const;
284 282
285 // Deletes the range pointed to by |*itr| and removes it from |ranges_|. 283 // Deletes the range pointed to by |*itr| and removes it from |ranges_|.
286 // If |*itr| points to |selected_range_|, then |selected_range_| is set to 284 // If |*itr| points to |selected_range_|, then |selected_range_| is set to
287 // NULL. After the range is removed, |*itr| is to the range after the one that 285 // NULL. After the range is removed, |*itr| is to the range after the one that
288 // was removed or to |ranges_.end()| if the last range was removed. 286 // was removed or to |ranges_.end()| if the last range was removed.
289 void DeleteAndRemoveRange(RangeList::iterator* itr); 287 void DeleteAndRemoveRange(RangeList::iterator* itr);
290 288
291 // Helper function used by Remove() and PrepareRangesForNextAppend() to 289 // Helper function used by Remove() and PrepareRangesForNextAppend() to
292 // remove buffers and ranges between |start| and |end|. 290 // remove buffers and ranges between |start| and |end|.
293 // |is_exclusive| - If set to true, buffers with timestamps that 291 // |is_exclusive| - If set to true, buffers with timestamps that
294 // match |start| are not removed. If set to false, buffers with 292 // match |start| are not removed. If set to false, buffers with
295 // timestamps that match |start| will be removed. 293 // timestamps that match |start| will be removed.
296 // |*deleted_buffers| - Filled with buffers for the current playback position 294 // |*deleted_buffers| - Filled with buffers for the current playback position
297 // if the removal range included the current playback position. These buffers 295 // if the removal range included the current playback position. These buffers
298 // can be used as candidates for placing in the |track_buffer_|. 296 // can be used as candidates for placing in the |track_buffer_|.
299 void RemoveInternal( 297 void RemoveInternal(
300 base::TimeDelta start, base::TimeDelta end, bool is_exclusive, 298 DecodeTimestamp start, DecodeTimestamp end, bool is_exclusive,
301 BufferQueue* deleted_buffers); 299 BufferQueue* deleted_buffers);
302 300
303 Type GetType() const; 301 Type GetType() const;
304 302
305 // See GetNextBuffer() for additional details. This method handles splice 303 // See GetNextBuffer() for additional details. This method handles splice
306 // frame processing. 304 // frame processing.
307 Status HandleNextBufferWithSplice( 305 Status HandleNextBufferWithSplice(
308 scoped_refptr<StreamParserBuffer>* out_buffer); 306 scoped_refptr<StreamParserBuffer>* out_buffer);
309 307
310 // See GetNextBuffer() for additional details. This method handles preroll 308 // See GetNextBuffer() for additional details. This method handles preroll
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // Pointer to the seeked-to Range. This is the range from which 364 // Pointer to the seeked-to Range. This is the range from which
367 // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been 365 // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been
368 // emptied. 366 // emptied.
369 SourceBufferRange* selected_range_; 367 SourceBufferRange* selected_range_;
370 368
371 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If 369 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If
372 // |track_buffer_| is empty, return buffers from |selected_range_|. 370 // |track_buffer_| is empty, return buffers from |selected_range_|.
373 BufferQueue track_buffer_; 371 BufferQueue track_buffer_;
374 372
375 // The start time of the current media segment being appended. 373 // The start time of the current media segment being appended.
376 base::TimeDelta media_segment_start_time_; 374 DecodeTimestamp media_segment_start_time_;
377 375
378 // Points to the range containing the current media segment being appended. 376 // Points to the range containing the current media segment being appended.
379 RangeList::iterator range_for_next_append_; 377 RangeList::iterator range_for_next_append_;
380 378
381 // True when the next call to Append() begins a new media segment. 379 // True when the next call to Append() begins a new media segment.
382 bool new_media_segment_; 380 bool new_media_segment_;
383 381
384 // The timestamp of the last buffer appended to the media segment, set to 382 // The timestamp of the last buffer appended to the media segment, set to
385 // kNoTimestamp() if the beginning of the segment. 383 // kNoDecodeTimestamp() if the beginning of the segment.
386 base::TimeDelta last_appended_buffer_timestamp_; 384 DecodeTimestamp last_appended_buffer_timestamp_;
387 bool last_appended_buffer_is_keyframe_; 385 bool last_appended_buffer_is_keyframe_;
388 386
389 // The decode timestamp on the last buffer returned by the most recent 387 // The decode timestamp on the last buffer returned by the most recent
390 // GetNextBuffer() call. Set to kNoTimestamp() if GetNextBuffer() hasn't been 388 // GetNextBuffer() call. Set to kNoTimestamp() if GetNextBuffer() hasn't been
391 // called yet or a seek has happened since the last GetNextBuffer() call. 389 // called yet or a seek has happened since the last GetNextBuffer() call.
392 base::TimeDelta last_output_buffer_timestamp_; 390 DecodeTimestamp last_output_buffer_timestamp_;
393 391
394 // Stores the largest distance between two adjacent buffers in this stream. 392 // Stores the largest distance between two adjacent buffers in this stream.
395 base::TimeDelta max_interbuffer_distance_; 393 base::TimeDelta max_interbuffer_distance_;
396 394
397 // The maximum amount of data in bytes the stream will keep in memory. 395 // The maximum amount of data in bytes the stream will keep in memory.
398 int memory_limit_; 396 int memory_limit_;
399 397
400 // Indicates that a kConfigChanged status has been reported by GetNextBuffer() 398 // Indicates that a kConfigChanged status has been reported by GetNextBuffer()
401 // and GetCurrentXXXDecoderConfig() must be called to update the current 399 // and GetCurrentXXXDecoderConfig() must be called to update the current
402 // config. GetNextBuffer() must not be called again until 400 // config. GetNextBuffer() must not be called again until
(...skipping 14 matching lines...) Expand all
417 415
418 // Indicates that splice frame generation is enabled. 416 // Indicates that splice frame generation is enabled.
419 const bool splice_frames_enabled_; 417 const bool splice_frames_enabled_;
420 418
421 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); 419 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream);
422 }; 420 };
423 421
424 } // namespace media 422 } // namespace media
425 423
426 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ 424 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698