Chromium Code Reviews| Index: media/filters/chunk_demuxer.cc |
| diff --git a/media/filters/chunk_demuxer.cc b/media/filters/chunk_demuxer.cc |
| index 17f1d96c9046de426f653cddef6ff0565b403901..fa54326fcb7d0b812c2cd030238823e2adfb255b 100644 |
| --- a/media/filters/chunk_demuxer.cc |
| +++ b/media/filters/chunk_demuxer.cc |
| @@ -177,6 +177,10 @@ class SourceState { |
| const StreamParser::BufferQueue& video_buffers, |
| const StreamParser::TextBufferQueueMap& text_map); |
| + void OnSourceInitDone(bool success, |
| + TimeDelta duration, |
| + bool auto_update_timestamp_offset); |
| + |
| CreateDemuxerStreamCB create_demuxer_stream_cb_; |
| NewTextTrackCB new_text_track_cb_; |
| @@ -216,6 +220,11 @@ class SourceState { |
| scoped_ptr<FrameProcessorBase> frame_processor_; |
| LogCB log_cb_; |
| + StreamParser::InitCB init_cb_; |
| + |
| + // Indicates that timestampOffset should be updated automatically during |
| + // OnNewBuffers() based on the earliest end timestamp of the buffers provided. |
| + bool auto_update_timestamp_offset_; |
| DISALLOW_COPY_AND_ASSIGN(SourceState); |
| }; |
| @@ -233,7 +242,8 @@ SourceState::SourceState( |
| audio_(NULL), |
| video_(NULL), |
| frame_processor_(frame_processor.release()), |
| - log_cb_(log_cb) { |
| + log_cb_(log_cb), |
| + auto_update_timestamp_offset_(false) { |
| DCHECK(!create_demuxer_stream_cb_.is_null()); |
| DCHECK(frame_processor_); |
| } |
| @@ -250,8 +260,10 @@ void SourceState::Init(const StreamParser::InitCB& init_cb, |
| const StreamParser::NeedKeyCB& need_key_cb, |
| const NewTextTrackCB& new_text_track_cb) { |
| new_text_track_cb_ = new_text_track_cb; |
| + init_cb_ = init_cb; |
| - stream_parser_->Init(init_cb, |
| + stream_parser_->Init(base::Bind(&SourceState::OnSourceInitDone, |
| + base::Unretained(this)), |
| base::Bind(&SourceState::OnNewConfigs, |
| base::Unretained(this), |
| allow_audio, |
| @@ -638,10 +650,39 @@ bool SourceState::OnNewBuffers( |
| DVLOG(2) << "OnNewBuffers()"; |
| DCHECK(timestamp_offset_during_append_); |
| - return frame_processor_->ProcessFrames( |
| - audio_buffers, video_buffers, text_map, |
| - append_window_start_during_append_, append_window_end_during_append_, |
| - &new_media_segment_, timestamp_offset_during_append_); |
| + const bool success = |
| + frame_processor_->ProcessFrames(audio_buffers, |
| + video_buffers, |
| + text_map, |
| + append_window_start_during_append_, |
| + append_window_end_during_append_, |
| + &new_media_segment_, |
| + timestamp_offset_during_append_); |
| + |
| + if (auto_update_timestamp_offset_) { |
| + const bool have_video_buffers = !video_buffers.empty(); |
| + base::TimeDelta new_timestamp_offset = |
|
acolwell GONE FROM CHROMIUM
2014/03/17 22:52:17
nit: Drop base:: since we've got a using directive
DaleCurtis
2014/03/18 00:14:02
Done.
|
| + have_video_buffers ? video_buffers.back()->timestamp() + |
| + video_buffers.back()->duration() |
| + : audio_buffers.back()->timestamp() + |
|
acolwell GONE FROM CHROMIUM
2014/03/17 22:52:17
You need an empty guard here if we only happened t
DaleCurtis
2014/03/18 00:14:02
Reflowed to a multi-if statement + helper function
|
| + audio_buffers.back()->duration(); |
| + if (have_video_buffers && !audio_buffers.empty()) { |
| + new_timestamp_offset = std::min( |
| + new_timestamp_offset, |
| + audio_buffers.back()->timestamp() + audio_buffers.back()->duration()); |
| + } |
| + |
| + *timestamp_offset_during_append_ = new_timestamp_offset; |
|
acolwell GONE FROM CHROMIUM
2014/03/17 22:52:17
You might need to snapshot *timestamp_offset_durin
DaleCurtis
2014/03/18 00:14:02
+wolenetz, what do you think? Probably we both sho
|
| + } |
| + |
| + return success; |
| +} |
| + |
| +void SourceState::OnSourceInitDone(bool success, |
| + TimeDelta duration, |
| + bool auto_update_timestamp_offset) { |
| + auto_update_timestamp_offset_ = auto_update_timestamp_offset; |
| + init_cb_.Run(success, duration, auto_update_timestamp_offset); |
| } |
| ChunkDemuxerStream::ChunkDemuxerStream(Type type) |
| @@ -1416,9 +1457,11 @@ bool ChunkDemuxer::IsSeekWaitingForData_Locked() const { |
| return false; |
| } |
| -void ChunkDemuxer::OnSourceInitDone(bool success, TimeDelta duration) { |
| - DVLOG(1) << "OnSourceInitDone(" << success << ", " |
| - << duration.InSecondsF() << ")"; |
| +void ChunkDemuxer::OnSourceInitDone(bool success, |
| + TimeDelta duration, |
| + bool auto_update_timestamp_offset) { |
|
acolwell GONE FROM CHROMIUM
2014/03/17 22:52:17
nit: No need to expose this detail to ChunkDemuxer
DaleCurtis
2014/03/18 00:14:02
Done.
|
| + DVLOG(1) << "OnSourceInitDone(" << success << ", " << duration.InSecondsF() |
| + << ", " << auto_update_timestamp_offset << ")"; |
| lock_.AssertAcquired(); |
| DCHECK_EQ(state_, INITIALIZING); |
| if (!success || (!audio_ && !video_)) { |