| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "media/filters/frame_processor.h" | 5 #include "media/filters/frame_processor.h" | 
| 6 | 6 | 
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" | 
| 8 #include "media/base/buffers.h" | 8 #include "media/base/buffers.h" | 
| 9 #include "media/base/stream_parser_buffer.h" | 9 #include "media/base/stream_parser_buffer.h" | 
| 10 | 10 | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 36   sequence_mode_ = sequence_mode; | 36   sequence_mode_ = sequence_mode; | 
| 37 } | 37 } | 
| 38 | 38 | 
| 39 bool FrameProcessor::ProcessFrames( | 39 bool FrameProcessor::ProcessFrames( | 
| 40     const StreamParser::BufferQueue& audio_buffers, | 40     const StreamParser::BufferQueue& audio_buffers, | 
| 41     const StreamParser::BufferQueue& video_buffers, | 41     const StreamParser::BufferQueue& video_buffers, | 
| 42     const StreamParser::TextBufferQueueMap& text_map, | 42     const StreamParser::TextBufferQueueMap& text_map, | 
| 43     base::TimeDelta append_window_start, | 43     base::TimeDelta append_window_start, | 
| 44     base::TimeDelta append_window_end, | 44     base::TimeDelta append_window_end, | 
| 45     bool* new_media_segment, | 45     bool* new_media_segment, | 
| 46     base::TimeDelta* timestamp_offset) { | 46     base::TimeDelta* timestamp_offset, | 
|  | 47     base::TimeDelta media_time) { | 
| 47   StreamParser::BufferQueue frames; | 48   StreamParser::BufferQueue frames; | 
| 48   if (!MergeBufferQueues(audio_buffers, video_buffers, text_map, &frames)) { | 49   if (!MergeBufferQueues(audio_buffers, video_buffers, text_map, &frames)) { | 
| 49     DVLOG(2) << "Parse error discovered while merging parser's buffers"; | 50     DVLOG(2) << "Parse error discovered while merging parser's buffers"; | 
| 50     return false; | 51     return false; | 
| 51   } | 52   } | 
| 52 | 53 | 
| 53   DCHECK(!frames.empty()); | 54   DCHECK(!frames.empty()); | 
| 54 | 55 | 
| 55   // Implements the coded frame processing algorithm's outer loop for step 1. | 56   // Implements the coded frame processing algorithm's outer loop for step 1. | 
| 56   // Note that ProcessFrame() implements an inner loop for a single frame that | 57   // Note that ProcessFrame() implements an inner loop for a single frame that | 
| 57   // handles "jump to the Loop Top step to restart processing of the current | 58   // handles "jump to the Loop Top step to restart processing of the current | 
| 58   // coded frame" per April 1, 2014 MSE spec editor's draft: | 59   // coded frame" per April 1, 2014 MSE spec editor's draft: | 
| 59   // https://dvcs.w3.org/hg/html-media/raw-file/d471a4412040/media-source/ | 60   // https://dvcs.w3.org/hg/html-media/raw-file/d471a4412040/media-source/ | 
| 60   //     media-source.html#sourcebuffer-coded-frame-processing | 61   //     media-source.html#sourcebuffer-coded-frame-processing | 
| 61   // 1. For each coded frame in the media segment run the following steps: | 62   // 1. For each coded frame in the media segment run the following steps: | 
| 62   for (StreamParser::BufferQueue::const_iterator frames_itr = frames.begin(); | 63   for (StreamParser::BufferQueue::const_iterator frames_itr = frames.begin(); | 
| 63        frames_itr != frames.end(); ++frames_itr) { | 64        frames_itr != frames.end(); ++frames_itr) { | 
| 64     if (!ProcessFrame(*frames_itr, append_window_start, append_window_end, | 65     if (!ProcessFrame(*frames_itr, append_window_start, append_window_end, | 
| 65                       timestamp_offset, new_media_segment)) { | 66                       timestamp_offset, new_media_segment, media_time)) { | 
| 66       return false; | 67       return false; | 
| 67     } | 68     } | 
| 68   } | 69   } | 
| 69 | 70 | 
| 70   // 2. - 4. Are handled by the WebMediaPlayer / Pipeline / Media Element. | 71   // 2. - 4. Are handled by the WebMediaPlayer / Pipeline / Media Element. | 
| 71 | 72 | 
| 72   // Step 5: | 73   // Step 5: | 
| 73   update_duration_cb_.Run(group_end_timestamp_); | 74   update_duration_cb_.Run(group_end_timestamp_); | 
| 74 | 75 | 
| 75   return true; | 76   return true; | 
| 76 } | 77 } | 
| 77 | 78 | 
| 78 bool FrameProcessor::ProcessFrame( | 79 bool FrameProcessor::ProcessFrame( | 
| 79     const scoped_refptr<StreamParserBuffer>& frame, | 80     const scoped_refptr<StreamParserBuffer>& frame, | 
| 80     base::TimeDelta append_window_start, | 81     base::TimeDelta append_window_start, | 
| 81     base::TimeDelta append_window_end, | 82     base::TimeDelta append_window_end, | 
| 82     base::TimeDelta* timestamp_offset, | 83     base::TimeDelta* timestamp_offset, | 
| 83     bool* new_media_segment) { | 84     bool* new_media_segment, | 
|  | 85     base::TimeDelta media_time) { | 
| 84   // Implements the loop within step 1 of the coded frame processing algorithm | 86   // Implements the loop within step 1 of the coded frame processing algorithm | 
| 85   // for a single input frame per April 1, 2014 MSE spec editor's draft: | 87   // for a single input frame per April 1, 2014 MSE spec editor's draft: | 
| 86   // https://dvcs.w3.org/hg/html-media/raw-file/d471a4412040/media-source/ | 88   // https://dvcs.w3.org/hg/html-media/raw-file/d471a4412040/media-source/ | 
| 87   //     media-source.html#sourcebuffer-coded-frame-processing | 89   //     media-source.html#sourcebuffer-coded-frame-processing | 
| 88 | 90 | 
| 89   while (true) { | 91   while (true) { | 
| 90     // 1. Loop Top: Let presentation timestamp be a double precision floating | 92     // 1. Loop Top: Let presentation timestamp be a double precision floating | 
| 91     //    point representation of the coded frame's presentation timestamp in | 93     //    point representation of the coded frame's presentation timestamp in | 
| 92     //    seconds. | 94     //    seconds. | 
| 93     // 2. Let decode timestamp be a double precision floating point | 95     // 2. Let decode timestamp be a double precision floating point | 
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 332     DVLOG(3) << __FUNCTION__ << ": Sending processed frame to stream, " | 334     DVLOG(3) << __FUNCTION__ << ": Sending processed frame to stream, " | 
| 333              << "PTS=" << presentation_timestamp.InSecondsF() | 335              << "PTS=" << presentation_timestamp.InSecondsF() | 
| 334              << ", DTS=" << decode_timestamp.InSecondsF(); | 336              << ", DTS=" << decode_timestamp.InSecondsF(); | 
| 335 | 337 | 
| 336     // Steps 13-18: | 338     // Steps 13-18: | 
| 337     // TODO(wolenetz): Collect and emit more than one buffer at a time, if | 339     // TODO(wolenetz): Collect and emit more than one buffer at a time, if | 
| 338     // possible. Also refactor SourceBufferStream to conform to spec GC timing. | 340     // possible. Also refactor SourceBufferStream to conform to spec GC timing. | 
| 339     // See http://crbug.com/371197. | 341     // See http://crbug.com/371197. | 
| 340     StreamParser::BufferQueue buffer_to_append; | 342     StreamParser::BufferQueue buffer_to_append; | 
| 341     buffer_to_append.push_back(frame); | 343     buffer_to_append.push_back(frame); | 
| 342     if (!track_buffer->stream()->Append(buffer_to_append)) { | 344     if (!track_buffer->stream()->Append(buffer_to_append, media_time)) { | 
| 343       DVLOG(3) << __FUNCTION__ << ": Failure appending frame to stream"; | 345       DVLOG(3) << __FUNCTION__ << ": Failure appending frame to stream"; | 
| 344       return false; | 346       return false; | 
| 345     } | 347     } | 
| 346 | 348 | 
| 347     // 19. Set last decode timestamp for track buffer to decode timestamp. | 349     // 19. Set last decode timestamp for track buffer to decode timestamp. | 
| 348     track_buffer->set_last_decode_timestamp(decode_timestamp); | 350     track_buffer->set_last_decode_timestamp(decode_timestamp); | 
| 349 | 351 | 
| 350     // 20. Set last frame duration for track buffer to frame duration. | 352     // 20. Set last frame duration for track buffer to frame duration. | 
| 351     track_buffer->set_last_frame_duration(frame_duration); | 353     track_buffer->set_last_frame_duration(frame_duration); | 
| 352 | 354 | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 364     DCHECK(group_end_timestamp_ >= base::TimeDelta()); | 366     DCHECK(group_end_timestamp_ >= base::TimeDelta()); | 
| 365 | 367 | 
| 366     return true; | 368     return true; | 
| 367   } | 369   } | 
| 368 | 370 | 
| 369   NOTREACHED(); | 371   NOTREACHED(); | 
| 370   return false; | 372   return false; | 
| 371 } | 373 } | 
| 372 | 374 | 
| 373 }  // namespace media | 375 }  // namespace media | 
| OLD | NEW | 
|---|