Chromium Code Reviews| 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 #include "media/filters/source_buffer_stream.h" | 5 #include "media/filters/source_buffer_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 // Returns true if the end of this range contains buffers that overlaps with | 146 // Returns true if the end of this range contains buffers that overlaps with |
| 147 // the beginning of |range|. | 147 // the beginning of |range|. |
| 148 bool EndOverlaps(const SourceBufferRange& range) const; | 148 bool EndOverlaps(const SourceBufferRange& range) const; |
| 149 | 149 |
| 150 // Returns true if |timestamp| is the timestamp of the next buffer in | 150 // Returns true if |timestamp| is the timestamp of the next buffer in |
| 151 // sequence after |buffer|, false otherwise. | 151 // sequence after |buffer|, false otherwise. |
| 152 bool IsNextInSequence( | 152 bool IsNextInSequence( |
| 153 const scoped_refptr<media::StreamParserBuffer>& buffer, | 153 const scoped_refptr<media::StreamParserBuffer>& buffer, |
| 154 base::TimeDelta timestamp) const; | 154 base::TimeDelta timestamp) const; |
| 155 | 155 |
| 156 // Returns true if |second_timestamp| is the timestamp of the next buffer in | |
| 157 // sequence after |first_timestamp|, false otherwise. | |
| 158 bool AreAdjacentInSequence( | |
| 159 base::TimeDelta first_timestamp, base::TimeDelta second_timestamp) const; | |
| 160 | |
| 156 int size_in_bytes() const { return size_in_bytes_; } | 161 int size_in_bytes() const { return size_in_bytes_; } |
| 157 | 162 |
| 158 private: | 163 private: |
| 159 typedef std::map<base::TimeDelta, size_t> KeyframeMap; | 164 typedef std::map<base::TimeDelta, size_t> KeyframeMap; |
| 160 | 165 |
| 161 // Seeks the range to the next keyframe after |timestamp|. If | 166 // Seeks the range to the next keyframe after |timestamp|. If |
| 162 // |skip_given_timestamp| is true, the seek will go to a keyframe with a | 167 // |skip_given_timestamp| is true, the seek will go to a keyframe with a |
| 163 // timestamp strictly greater than |timestamp|. | 168 // timestamp strictly greater than |timestamp|. |
| 164 void SeekAhead(base::TimeDelta timestamp, bool skip_given_timestamp); | 169 void SeekAhead(base::TimeDelta timestamp, bool skip_given_timestamp); |
| 165 | 170 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 ranges_.pop_front(); | 317 ranges_.pop_front(); |
| 313 } | 318 } |
| 314 | 319 |
| 315 STLDeleteElements(&audio_configs_); | 320 STLDeleteElements(&audio_configs_); |
| 316 STLDeleteElements(&video_configs_); | 321 STLDeleteElements(&video_configs_); |
| 317 } | 322 } |
| 318 | 323 |
| 319 void SourceBufferStream::OnNewMediaSegment( | 324 void SourceBufferStream::OnNewMediaSegment( |
| 320 base::TimeDelta media_segment_start_time) { | 325 base::TimeDelta media_segment_start_time) { |
| 321 media_segment_start_time_ = media_segment_start_time; | 326 media_segment_start_time_ = media_segment_start_time; |
| 327 new_media_segment_ = true; | |
| 322 | 328 |
| 323 // Find the range that will house the buffers appended through the next | 329 RangeList::iterator last_range = range_for_next_append_; |
| 324 // Append() call. | |
| 325 range_for_next_append_ = FindExistingRangeFor(media_segment_start_time); | 330 range_for_next_append_ = FindExistingRangeFor(media_segment_start_time); |
| 326 new_media_segment_ = true; | 331 |
| 327 last_buffer_timestamp_ = kNoTimestamp(); | 332 // Only reset |last_buffer_timestamp_| if this new media segment is not |
| 333 // adjacent to the previous media segment appended to the stream. | |
| 334 if (range_for_next_append_ == ranges_.end() || | |
| 335 !(*range_for_next_append_)->AreAdjacentInSequence( | |
|
acolwell GONE FROM CHROMIUM
2012/09/19 23:15:51
This is a little awkward because it calls into the
vrk (LEFT CHROMIUM)
2012/09/20 00:00:59
Done.
| |
| 336 last_buffer_timestamp_, media_segment_start_time)) { | |
| 337 last_buffer_timestamp_ = kNoTimestamp(); | |
| 338 } else { | |
| 339 DCHECK(last_range == range_for_next_append_); | |
| 340 } | |
| 328 } | 341 } |
| 329 | 342 |
| 330 bool SourceBufferStream::Append( | 343 bool SourceBufferStream::Append( |
| 331 const SourceBufferStream::BufferQueue& buffers) { | 344 const SourceBufferStream::BufferQueue& buffers) { |
| 332 DCHECK(!buffers.empty()); | 345 DCHECK(!buffers.empty()); |
| 333 DCHECK(media_segment_start_time_ != kNoTimestamp()); | 346 DCHECK(media_segment_start_time_ != kNoTimestamp()); |
| 334 | 347 |
| 335 // New media segments must begin with a keyframe. | 348 // New media segments must begin with a keyframe. |
| 336 if (new_media_segment_ && !buffers.front()->IsKeyframe()) { | 349 if (new_media_segment_ && !buffers.front()->IsKeyframe()) { |
| 337 DVLOG(1) << "Media segment did not begin with keyframe."; | 350 DVLOG(1) << "Media segment did not begin with keyframe."; |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1399 DCHECK(!buffers_.empty()); | 1412 DCHECK(!buffers_.empty()); |
| 1400 base::TimeDelta duration = buffers_.back()->GetDuration(); | 1413 base::TimeDelta duration = buffers_.back()->GetDuration(); |
| 1401 if (duration == kNoTimestamp() || duration == base::TimeDelta()) | 1414 if (duration == kNoTimestamp() || duration == base::TimeDelta()) |
| 1402 duration = GetApproximateDuration(); | 1415 duration = GetApproximateDuration(); |
| 1403 return GetEndTimestamp() + duration; | 1416 return GetEndTimestamp() + duration; |
| 1404 } | 1417 } |
| 1405 | 1418 |
| 1406 bool SourceBufferRange::IsNextInSequence( | 1419 bool SourceBufferRange::IsNextInSequence( |
| 1407 const scoped_refptr<media::StreamParserBuffer>& buffer, | 1420 const scoped_refptr<media::StreamParserBuffer>& buffer, |
| 1408 base::TimeDelta timestamp) const { | 1421 base::TimeDelta timestamp) const { |
| 1409 return buffer->GetDecodeTimestamp() < timestamp && | 1422 return AreAdjacentInSequence(buffer->GetDecodeTimestamp(), timestamp); |
| 1410 timestamp <= buffer->GetDecodeTimestamp() + GetFudgeRoom(); | 1423 } |
| 1424 | |
| 1425 bool SourceBufferRange::AreAdjacentInSequence( | |
| 1426 base::TimeDelta first_timestamp, base::TimeDelta second_timestamp) const { | |
| 1427 return first_timestamp < second_timestamp && | |
| 1428 second_timestamp <= first_timestamp + GetFudgeRoom(); | |
| 1411 } | 1429 } |
| 1412 | 1430 |
| 1413 base::TimeDelta SourceBufferRange::GetFudgeRoom() const { | 1431 base::TimeDelta SourceBufferRange::GetFudgeRoom() const { |
| 1414 // Because we do not know exactly when is the next timestamp, any buffer | 1432 // Because we do not know exactly when is the next timestamp, any buffer |
| 1415 // that starts within 2x the approximate duration of a buffer is considered | 1433 // that starts within 2x the approximate duration of a buffer is considered |
| 1416 // within this range. | 1434 // within this range. |
| 1417 return 2 * GetApproximateDuration(); | 1435 return 2 * GetApproximateDuration(); |
| 1418 } | 1436 } |
| 1419 | 1437 |
| 1420 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { | 1438 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { |
| 1421 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); | 1439 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); |
| 1422 DCHECK(max_interbuffer_distance != kNoTimestamp()); | 1440 DCHECK(max_interbuffer_distance != kNoTimestamp()); |
| 1423 return max_interbuffer_distance; | 1441 return max_interbuffer_distance; |
| 1424 } | 1442 } |
| 1425 | 1443 |
| 1426 } // namespace media | 1444 } // namespace media |
| OLD | NEW |