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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 kEndOfStream | 50 kEndOfStream |
51 }; | 51 }; |
52 | 52 |
53 enum Type { | 53 enum Type { |
54 kAudio, | 54 kAudio, |
55 kVideo, | 55 kVideo, |
56 kText | 56 kText |
57 }; | 57 }; |
58 | 58 |
59 SourceBufferStream(const AudioDecoderConfig& audio_config, | 59 SourceBufferStream(const AudioDecoderConfig& audio_config, |
60 const scoped_refptr<MediaLog>& media_log, | 60 const scoped_refptr<MediaLog>& media_log); |
61 bool splice_frames_enabled); | |
62 SourceBufferStream(const VideoDecoderConfig& video_config, | 61 SourceBufferStream(const VideoDecoderConfig& video_config, |
63 const scoped_refptr<MediaLog>& media_log, | 62 const scoped_refptr<MediaLog>& media_log); |
64 bool splice_frames_enabled); | |
65 SourceBufferStream(const TextTrackConfig& text_config, | 63 SourceBufferStream(const TextTrackConfig& text_config, |
66 const scoped_refptr<MediaLog>& media_log, | 64 const scoped_refptr<MediaLog>& media_log); |
67 bool splice_frames_enabled); | |
68 | 65 |
69 ~SourceBufferStream(); | 66 ~SourceBufferStream(); |
70 | 67 |
71 // Signals that the next buffers appended are part of a new coded frame group | 68 // Signals that the next buffers appended are part of a new coded frame group |
72 // starting at |coded_frame_group_start_time|. | 69 // starting at |coded_frame_group_start_time|. |
73 // TODO(acolwell/wolenetz): This should be changed to a presentation | 70 // TODO(acolwell/wolenetz): This should be changed to a presentation |
74 // timestamp. See http://crbug.com/402502 | 71 // timestamp. See http://crbug.com/402502 |
75 void OnStartOfCodedFrameGroup(DecodeTimestamp coded_frame_group_start_time); | 72 void OnStartOfCodedFrameGroup(DecodeTimestamp coded_frame_group_start_time); |
76 | 73 |
77 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are | 74 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 278 |
282 // Searches |ranges_| for the first keyframe timestamp that is >= |timestamp|. | 279 // Searches |ranges_| for the first keyframe timestamp that is >= |timestamp|. |
283 // If |ranges_| doesn't contain a GOP that covers |timestamp| or doesn't | 280 // If |ranges_| doesn't contain a GOP that covers |timestamp| or doesn't |
284 // have a keyframe after |timestamp| then kNoTimestamp is returned. | 281 // have a keyframe after |timestamp| then kNoTimestamp is returned. |
285 DecodeTimestamp FindKeyframeAfterTimestamp(const DecodeTimestamp timestamp); | 282 DecodeTimestamp FindKeyframeAfterTimestamp(const DecodeTimestamp timestamp); |
286 | 283 |
287 // Returns "VIDEO" for a video SourceBufferStream, "AUDIO" for an audio | 284 // Returns "VIDEO" for a video SourceBufferStream, "AUDIO" for an audio |
288 // stream, and "TEXT" for a text stream. | 285 // stream, and "TEXT" for a text stream. |
289 std::string GetStreamTypeName() const; | 286 std::string GetStreamTypeName() const; |
290 | 287 |
| 288 // (Audio only) If |new_buffers| overlap existing buffers, trims end of |
| 289 // existing buffers to remove overlap. |new_buffers| are not modified. |
| 290 void TrimSpliceOverlap(const BufferQueue& new_buffers); |
| 291 |
291 // Returns true if end of stream has been reached, i.e. the | 292 // Returns true if end of stream has been reached, i.e. the |
292 // following conditions are met: | 293 // following conditions are met: |
293 // 1. end of stream is marked and there is nothing in the track_buffer. | 294 // 1. end of stream is marked and there is nothing in the track_buffer. |
294 // 2. We don't have any ranges, or the last or no range is selected, | 295 // 2. We don't have any ranges, or the last or no range is selected, |
295 // or there is a pending seek beyond any existing ranges. | 296 // or there is a pending seek beyond any existing ranges. |
296 bool IsEndOfStreamReached() const; | 297 bool IsEndOfStreamReached() const; |
297 | 298 |
298 // Deletes the range pointed to by |*itr| and removes it from |ranges_|. | 299 // Deletes the range pointed to by |*itr| and removes it from |ranges_|. |
299 // If |*itr| points to |selected_range_|, then |selected_range_| is set to | 300 // If |*itr| points to |selected_range_|, then |selected_range_| is set to |
300 // NULL. After the range is removed, |*itr| is to the range after the one that | 301 // NULL. After the range is removed, |*itr| is to the range after the one that |
(...skipping 25 matching lines...) Expand all Loading... |
326 // Helper function used by RemoveInternal() to evaluate whether remove will | 327 // Helper function used by RemoveInternal() to evaluate whether remove will |
327 // disrupt the last appended GOP. If disruption is expected, reset state | 328 // disrupt the last appended GOP. If disruption is expected, reset state |
328 // tracking the last append. This will trigger frame filtering in Append() | 329 // tracking the last append. This will trigger frame filtering in Append() |
329 // until a new key frame is provided. | 330 // until a new key frame is provided. |
330 void UpdateLastAppendStateForRemove(DecodeTimestamp remove_start, | 331 void UpdateLastAppendStateForRemove(DecodeTimestamp remove_start, |
331 DecodeTimestamp remove_end, | 332 DecodeTimestamp remove_end, |
332 bool exclude_start); | 333 bool exclude_start); |
333 | 334 |
334 Type GetType() const; | 335 Type GetType() const; |
335 | 336 |
336 // See GetNextBuffer() for additional details. This method handles splice | |
337 // frame processing. | |
338 Status HandleNextBufferWithSplice( | |
339 scoped_refptr<StreamParserBuffer>* out_buffer); | |
340 | |
341 // See GetNextBuffer() for additional details. This method handles preroll | 337 // See GetNextBuffer() for additional details. This method handles preroll |
342 // frame processing. | 338 // frame processing. |
343 Status HandleNextBufferWithPreroll( | 339 Status HandleNextBufferWithPreroll( |
344 scoped_refptr<StreamParserBuffer>* out_buffer); | 340 scoped_refptr<StreamParserBuffer>* out_buffer); |
345 | 341 |
346 // See GetNextBuffer() for additional details. The internal method hands out | 342 // See GetNextBuffer() for additional details. The internal method hands out |
347 // single buffers from the |track_buffer_| and |selected_range_| without | 343 // single buffers from the |track_buffer_| and |selected_range_| without |
348 // additional processing for splice frame or preroll buffers. | 344 // additional processing for preroll buffers. |
349 Status GetNextBufferInternal(scoped_refptr<StreamParserBuffer>* out_buffer); | 345 Status GetNextBufferInternal(scoped_refptr<StreamParserBuffer>* out_buffer); |
350 | 346 |
351 // If the next buffer's timestamp is significantly beyond the last output | 347 // If the next buffer's timestamp is significantly beyond the last output |
352 // buffer, and if we just exhausted |track_buffer_| on the previous read, this | 348 // buffer, and if we just exhausted |track_buffer_| on the previous read, this |
353 // method logs a warning to |media_log_| that there could be perceivable | 349 // method logs a warning to |media_log_| that there could be perceivable |
354 // delay. Apps can avoid this behavior by not overlap-appending buffers near | 350 // delay. Apps can avoid this behavior by not overlap-appending buffers near |
355 // current playback position. | 351 // current playback position. |
356 void WarnIfTrackBufferExhaustionSkipsForward( | 352 void WarnIfTrackBufferExhaustionSkipsForward( |
357 const scoped_refptr<StreamParserBuffer>& next_buffer); | 353 const scoped_refptr<StreamParserBuffer>& next_buffer); |
358 | 354 |
359 // Called by PrepareRangesForNextAppend() before pruning overlapped buffers to | 355 // If |out_buffer| has preroll, sets |pending_buffer_| to feed out preroll and |
360 // generate a splice frame with a small portion of the overlapped buffers. If | 356 // returns true. Otherwise returns false. |
361 // a splice frame is generated, the first buffer in |new_buffers| will have | |
362 // its timestamps, duration, and fade out preroll updated. | |
363 void GenerateSpliceFrame(const BufferQueue& new_buffers); | |
364 | |
365 // If |out_buffer| has splice buffers or preroll, sets |pending_buffer_| | |
366 // appropriately and returns true. Otherwise returns false. | |
367 bool SetPendingBuffer(scoped_refptr<StreamParserBuffer>* out_buffer); | 357 bool SetPendingBuffer(scoped_refptr<StreamParserBuffer>* out_buffer); |
368 | 358 |
369 // Used to report log messages that can help the web developer figure out what | 359 // Used to report log messages that can help the web developer figure out what |
370 // is wrong with the content. | 360 // is wrong with the content. |
371 scoped_refptr<MediaLog> media_log_; | 361 scoped_refptr<MediaLog> media_log_; |
372 | 362 |
373 // List of disjoint buffered ranges, ordered by start time. | 363 // List of disjoint buffered ranges, ordered by start time. |
374 RangeList ranges_; | 364 RangeList ranges_; |
375 | 365 |
376 // Indicates which decoder config is being used by the decoder. | 366 // Indicates which decoder config is being used by the decoder. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 | 432 |
443 // The maximum amount of data in bytes the stream will keep in memory. | 433 // The maximum amount of data in bytes the stream will keep in memory. |
444 size_t memory_limit_; | 434 size_t memory_limit_; |
445 | 435 |
446 // Indicates that a kConfigChanged status has been reported by GetNextBuffer() | 436 // Indicates that a kConfigChanged status has been reported by GetNextBuffer() |
447 // and GetCurrentXXXDecoderConfig() must be called to update the current | 437 // and GetCurrentXXXDecoderConfig() must be called to update the current |
448 // config. GetNextBuffer() must not be called again until | 438 // config. GetNextBuffer() must not be called again until |
449 // GetCurrentXXXDecoderConfig() has been called. | 439 // GetCurrentXXXDecoderConfig() has been called. |
450 bool config_change_pending_ = false; | 440 bool config_change_pending_ = false; |
451 | 441 |
452 // Used by HandleNextBufferWithSplice() or HandleNextBufferWithPreroll() when | 442 // Used by HandleNextBufferWithPreroll() when a buffer with preroll is |
453 // a splice frame buffer or buffer with preroll is returned from | 443 // returned from GetNextBufferInternal(). |
454 // GetNextBufferInternal(). | |
455 scoped_refptr<StreamParserBuffer> pending_buffer_; | 444 scoped_refptr<StreamParserBuffer> pending_buffer_; |
456 | 445 |
457 // Indicates which of the splice buffers in |splice_buffer_| should be | |
458 // handled out next. | |
459 size_t splice_buffers_index_ = 0; | |
460 | |
461 // Indicates that all buffers before |pending_buffer_| have been handed out. | 446 // Indicates that all buffers before |pending_buffer_| have been handed out. |
462 bool pending_buffers_complete_ = false; | 447 bool pending_buffers_complete_ = false; |
463 | 448 |
464 // Indicates that splice frame generation is enabled. | 449 // To prevent log spam, count the number of logs for different log scenarios. |
465 const bool splice_frames_enabled_; | 450 int num_splice_logs_ = 0; |
466 | |
467 // To prevent log spam, count the number of warnings and successes logged. | |
468 int num_splice_generation_warning_logs_ = 0; | |
469 int num_splice_generation_success_logs_ = 0; | |
470 int num_track_buffer_gap_warning_logs_ = 0; | 451 int num_track_buffer_gap_warning_logs_ = 0; |
471 int num_garbage_collect_algorithm_logs_ = 0; | 452 int num_garbage_collect_algorithm_logs_ = 0; |
472 int num_strange_same_timestamps_logs_ = 0; | 453 int num_strange_same_timestamps_logs_ = 0; |
473 | 454 |
474 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); | 455 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); |
475 }; | 456 }; |
476 | 457 |
477 } // namespace media | 458 } // namespace media |
478 | 459 |
479 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ | 460 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
OLD | NEW |