Chromium Code Reviews| Index: media/filters/chunk_demuxer.cc |
| diff --git a/media/filters/chunk_demuxer.cc b/media/filters/chunk_demuxer.cc |
| index b7244b93317c19dfd472a3dde125431327b4df1b..f2523fb0e23306dbe74eaf739538dfbc9bcec0c2 100644 |
| --- a/media/filters/chunk_demuxer.cc |
| +++ b/media/filters/chunk_demuxer.cc |
| @@ -118,18 +118,26 @@ class SourceState { |
| // ChunkDemuxerStreams managed by this object. |
| void Remove(TimeDelta start, TimeDelta end, TimeDelta duration); |
| - // Sets |timestamp_offset_| if possible. |
| - // Returns if the offset was set. Returns false if the offset could not be |
| - // updated at this time. |
| - bool SetTimestampOffset(TimeDelta timestamp_offset); |
| + // Sets user-specified |timestamp_offset_| if possible. |
| + // Returns true if the offset was set. Returns false if the offset could not |
| + // be updated at this time. |
| + bool SetTimestampOffset(double timestamp_offset); |
| + |
| + // Gets the current timestamp offset. |
| + // If |using_user_specified_timestamp_offset_| is true, meaning |
| + // |timestamp_offset_| was most recently updated by SetTimestampOffset(), |
| + // returns the exact double representation |user_specified_timestamp_offset_|. |
| + // Otherwise, |timestamp_offset_| has diverged since construction or the |
| + // last SetTimestampOffset(), such as may occur in "sequence" mode Append() |
| + // coded frame processing. In this case, returns a double representation of |
| + // the current |timestamp_offset_| TimeDelta. |
| + double GetTimestampOffset() const; |
| // Sets |sequence_mode_| to |sequence_mode| if possible. |
| // Returns true if the mode update was allowed. Returns false if the mode |
| // could not be updated at this time. |
| bool SetSequenceMode(bool sequence_mode); |
| - TimeDelta timestamp_offset() const { return timestamp_offset_; } |
| - |
| void set_append_window_start(TimeDelta start) { |
| append_window_start_ = start; |
| } |
| @@ -224,6 +232,12 @@ class SourceState { |
| // The offset to apply to media segment timestamps. |
| TimeDelta timestamp_offset_; |
| + // Enable exact round-tripping SetTimestampOffset()+GetTimestampOffset(), |
| + // unless the offset is updated in the interim by coded frame processing |
| + // in "sequence" mode Append() operations. |
| + double user_specified_timestamp_offset_; |
| + bool using_user_specified_timestamp_offset_; |
| + |
| // Tracks the mode by which appended media is processed. If true, then |
| // appended media is processed using "sequence" mode. Otherwise, appended |
| // media is processed using "segments" mode. |
| @@ -365,6 +379,8 @@ SourceState::SourceState(scoped_ptr<StreamParser> stream_parser, |
| const IncreaseDurationCB& increase_duration_cb) |
| : create_demuxer_stream_cb_(create_demuxer_stream_cb), |
| increase_duration_cb_(increase_duration_cb), |
| + user_specified_timestamp_offset_(0.0), |
| + using_user_specified_timestamp_offset_(true), |
| sequence_mode_(false), |
| append_window_end_(kInfiniteDuration()), |
| new_media_segment_(false), |
| @@ -408,14 +424,25 @@ void SourceState::Init(const StreamParser::InitCB& init_cb, |
| log_cb_); |
| } |
| -bool SourceState::SetTimestampOffset(TimeDelta timestamp_offset) { |
| +bool SourceState::SetTimestampOffset(double timestamp_offset) { |
| if (parsing_media_segment_) |
| return false; |
| - timestamp_offset_ = timestamp_offset; |
| + using_user_specified_timestamp_offset_ = true; |
| + user_specified_timestamp_offset_ = timestamp_offset; |
| + timestamp_offset_ = base::TimeDelta::FromMicroseconds( |
| + timestamp_offset * base::Time::kMicrosecondsPerSecond); |
| + |
| return true; |
| } |
| +double SourceState::GetTimestampOffset() const { |
| + if (using_user_specified_timestamp_offset_) |
| + return user_specified_timestamp_offset_; |
|
acolwell GONE FROM CHROMIUM
2014/02/25 17:24:28
I think we should just return NaN here. Blink alre
wolenetz
2014/02/25 20:32:20
Done, using TimeDelta, name change, and kNoTimesta
|
| + else |
|
acolwell GONE FROM CHROMIUM
2014/02/25 17:24:28
nit: drop else.
wolenetz
2014/02/25 20:32:20
Done.
|
| + return timestamp_offset_.InSecondsF(); |
| +} |
| + |
| bool SourceState::SetSequenceMode(bool sequence_mode) { |
| if (parsing_media_segment_) |
| return false; |
| @@ -1551,14 +1578,22 @@ void ChunkDemuxer::SetDuration(double duration) { |
| } |
| } |
| -bool ChunkDemuxer::SetTimestampOffset(const std::string& id, TimeDelta offset) { |
| +bool ChunkDemuxer::SetTimestampOffset(const std::string& id, double offset) { |
| base::AutoLock auto_lock(lock_); |
| - DVLOG(1) << "SetTimestampOffset(" << id << ", " << offset.InSecondsF() << ")"; |
| + DVLOG(1) << "SetTimestampOffset(" << id << ", " << offset << ")"; |
| CHECK(IsValidId(id)); |
| return source_state_map_[id]->SetTimestampOffset(offset); |
| } |
| +double ChunkDemuxer::GetTimestampOffset(const std::string& id) { |
| + base::AutoLock auto_lock(lock_); |
| + DVLOG(1) << "GetTimestampOffset(" << id << ")"; |
| + CHECK(IsValidId(id)); |
| + |
| + return source_state_map_[id]->GetTimestampOffset(); |
| +} |
| + |
| bool ChunkDemuxer::SetSequenceMode(const std::string& id, |
| bool sequence_mode) { |
| base::AutoLock auto_lock(lock_); |