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..7153e0ba02b79f1af0190efe5d7b9746c6ca6c81 100644 |
| --- a/media/filters/chunk_demuxer.cc |
| +++ b/media/filters/chunk_demuxer.cc |
| @@ -109,7 +109,11 @@ class SourceState { |
| // Appends new data to the StreamParser. |
| // Returns true if the data was successfully appended. Returns false if an |
| // error occurred. |
| - bool Append(const uint8* data, size_t length); |
| + // If the append changed the source buffer's timestamp offset, sets |
| + // |*new_timestamp_offset| to the updated timestamp offset. Otherwise, sets |
| + // |*new_timestamp_offset| to kNoTimestamp() to indicate no change. |
| + bool Append(const uint8* data, size_t length, |
| + TimeDelta* new_timestamp_offset); |
| // Aborts the current append sequence and resets the parser. |
| void Abort(); |
| @@ -118,9 +122,9 @@ 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. |
| + // Sets user-specified |timestamp_offset_| if possible. |
| + // Returns true if the offset was set. Returns false if the offset could not |
| + // be set at this time. |
| bool SetTimestampOffset(TimeDelta timestamp_offset); |
| // Sets |sequence_mode_| to |sequence_mode| if possible. |
| @@ -128,8 +132,6 @@ class SourceState { |
| // 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 +226,10 @@ class SourceState { |
| // The offset to apply to media segment timestamps. |
| TimeDelta timestamp_offset_; |
| + // Flag that tracks whether or not the current Append() operation changed |
| + // |timestamp_offset_|. |
| + bool timestamp_offset_updated_by_append_; |
| + |
| // 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 +371,7 @@ 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), |
| + timestamp_offset_updated_by_append_(false), |
| sequence_mode_(false), |
| append_window_end_(kInfiniteDuration()), |
| new_media_segment_(false), |
| @@ -424,9 +431,19 @@ bool SourceState::SetSequenceMode(bool sequence_mode) { |
| return true; |
| } |
| +bool SourceState::Append(const uint8* data, size_t length, |
| + TimeDelta* new_timestamp_offset) { |
| + DCHECK(new_timestamp_offset); |
| + |
| + timestamp_offset_updated_by_append_ = false; |
| + bool err = stream_parser_->Parse(data, length); |
| -bool SourceState::Append(const uint8* data, size_t length) { |
| - return stream_parser_->Parse(data, length); |
| + if (timestamp_offset_updated_by_append_) |
| + *new_timestamp_offset = timestamp_offset_; |
|
acolwell GONE FROM CHROMIUM
2014/02/27 18:27:21
If we pass timestamp_offset here then we can just
wolenetz
2014/02/27 21:48:49
Done.
|
| + else |
| + *new_timestamp_offset = kNoTimestamp(); |
| + |
| + return err; |
| } |
| void SourceState::Abort() { |
| @@ -1408,11 +1425,15 @@ Ranges<TimeDelta> ChunkDemuxer::GetBufferedRanges(const std::string& id) const { |
| } |
| void ChunkDemuxer::AppendData(const std::string& id, |
| - const uint8* data, |
| - size_t length) { |
| + const uint8* data, size_t length, |
| + TimeDelta* new_timestamp_offset) { |
| DVLOG(1) << "AppendData(" << id << ", " << length << ")"; |
| DCHECK(!id.empty()); |
| + DCHECK(new_timestamp_offset); |
| + |
| + // Signal unchanged timestamp offset unless it is actually changed. |
| + *new_timestamp_offset = kNoTimestamp(); |
| Ranges<TimeDelta> ranges; |
| @@ -1432,7 +1453,8 @@ void ChunkDemuxer::AppendData(const std::string& id, |
| switch (state_) { |
| case INITIALIZING: |
| DCHECK(IsValidId(id)); |
| - if (!source_state_map_[id]->Append(data, length)) { |
| + if (!source_state_map_[id]->Append(data, length, |
| + new_timestamp_offset)) { |
| ReportError_Locked(DEMUXER_ERROR_COULD_NOT_OPEN); |
| return; |
| } |
| @@ -1440,7 +1462,8 @@ void ChunkDemuxer::AppendData(const std::string& id, |
| case INITIALIZED: { |
| DCHECK(IsValidId(id)); |
| - if (!source_state_map_[id]->Append(data, length)) { |
| + if (!source_state_map_[id]->Append(data, length, |
| + new_timestamp_offset)) { |
| ReportError_Locked(PIPELINE_ERROR_DECODE); |
| return; |
| } |