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/source_buffer_range.h" | 5 #include "media/filters/source_buffer_range.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "media/base/timestamp_constants.h" | 9 #include "media/base/timestamp_constants.h" |
10 | 10 |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 } | 546 } |
547 | 547 |
548 DecodeTimestamp SourceBufferRange::GetEndTimestamp() const { | 548 DecodeTimestamp SourceBufferRange::GetEndTimestamp() const { |
549 DCHECK(!buffers_.empty()); | 549 DCHECK(!buffers_.empty()); |
550 return buffers_.back()->GetDecodeTimestamp(); | 550 return buffers_.back()->GetDecodeTimestamp(); |
551 } | 551 } |
552 | 552 |
553 DecodeTimestamp SourceBufferRange::GetBufferedEndTimestamp() const { | 553 DecodeTimestamp SourceBufferRange::GetBufferedEndTimestamp() const { |
554 DCHECK(!buffers_.empty()); | 554 DCHECK(!buffers_.empty()); |
555 base::TimeDelta duration = buffers_.back()->duration(); | 555 base::TimeDelta duration = buffers_.back()->duration(); |
556 if (duration == kNoTimestamp() || duration.is_zero()) | 556 if (duration == kNoTimestamp || duration.is_zero()) |
557 duration = GetApproximateDuration(); | 557 duration = GetApproximateDuration(); |
558 return GetEndTimestamp() + duration; | 558 return GetEndTimestamp() + duration; |
559 } | 559 } |
560 | 560 |
561 DecodeTimestamp SourceBufferRange::NextKeyframeTimestamp( | 561 DecodeTimestamp SourceBufferRange::NextKeyframeTimestamp( |
562 DecodeTimestamp timestamp) { | 562 DecodeTimestamp timestamp) { |
563 DCHECK(!keyframe_map_.empty()); | 563 DCHECK(!keyframe_map_.empty()); |
564 | 564 |
565 if (timestamp < GetStartTimestamp() || timestamp >= GetBufferedEndTimestamp()) | 565 if (timestamp < GetStartTimestamp() || timestamp >= GetBufferedEndTimestamp()) |
566 return kNoDecodeTimestamp(); | 566 return kNoDecodeTimestamp(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 | 599 |
600 base::TimeDelta SourceBufferRange::GetFudgeRoom() const { | 600 base::TimeDelta SourceBufferRange::GetFudgeRoom() const { |
601 // Because we do not know exactly when is the next timestamp, any buffer | 601 // Because we do not know exactly when is the next timestamp, any buffer |
602 // that starts within 2x the approximate duration of a buffer is considered | 602 // that starts within 2x the approximate duration of a buffer is considered |
603 // within this range. | 603 // within this range. |
604 return 2 * GetApproximateDuration(); | 604 return 2 * GetApproximateDuration(); |
605 } | 605 } |
606 | 606 |
607 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { | 607 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { |
608 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); | 608 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); |
609 DCHECK(max_interbuffer_distance != kNoTimestamp()); | 609 DCHECK(max_interbuffer_distance != kNoTimestamp); |
610 return max_interbuffer_distance; | 610 return max_interbuffer_distance; |
611 } | 611 } |
612 | 612 |
613 bool SourceBufferRange::GetBuffersInRange(DecodeTimestamp start, | 613 bool SourceBufferRange::GetBuffersInRange(DecodeTimestamp start, |
614 DecodeTimestamp end, | 614 DecodeTimestamp end, |
615 BufferQueue* buffers) { | 615 BufferQueue* buffers) { |
616 // Find the nearest buffer with a decode timestamp <= start. | 616 // Find the nearest buffer with a decode timestamp <= start. |
617 const DecodeTimestamp first_timestamp = KeyframeBeforeTimestamp(start); | 617 const DecodeTimestamp first_timestamp = KeyframeBeforeTimestamp(start); |
618 if (first_timestamp == kNoDecodeTimestamp()) | 618 if (first_timestamp == kNoDecodeTimestamp()) |
619 return false; | 619 return false; |
620 | 620 |
621 // Find all buffers involved in the range. | 621 // Find all buffers involved in the range. |
622 const size_t previous_size = buffers->size(); | 622 const size_t previous_size = buffers->size(); |
623 for (BufferQueue::iterator it = GetBufferItrAt(first_timestamp, false); | 623 for (BufferQueue::iterator it = GetBufferItrAt(first_timestamp, false); |
624 it != buffers_.end(); | 624 it != buffers_.end(); |
625 ++it) { | 625 ++it) { |
626 const scoped_refptr<StreamParserBuffer>& buffer = *it; | 626 const scoped_refptr<StreamParserBuffer>& buffer = *it; |
627 // Buffers without duration are not supported, so bail if we encounter any. | 627 // Buffers without duration are not supported, so bail if we encounter any. |
628 if (buffer->duration() == kNoTimestamp() || | 628 if (buffer->duration() == kNoTimestamp || |
629 buffer->duration() <= base::TimeDelta()) { | 629 buffer->duration() <= base::TimeDelta()) { |
630 return false; | 630 return false; |
631 } | 631 } |
632 if (buffer->end_of_stream() || | 632 if (buffer->end_of_stream() || |
633 buffer->timestamp() >= end.ToPresentationTime()) { | 633 buffer->timestamp() >= end.ToPresentationTime()) { |
634 break; | 634 break; |
635 } | 635 } |
636 | 636 |
637 if (buffer->timestamp() + buffer->duration() <= start.ToPresentationTime()) | 637 if (buffer->timestamp() + buffer->duration() <= start.ToPresentationTime()) |
638 continue; | 638 continue; |
639 buffers->push_back(buffer); | 639 buffers->push_back(buffer); |
640 } | 640 } |
641 return previous_size < buffers->size(); | 641 return previous_size < buffers->size(); |
642 } | 642 } |
643 | 643 |
644 } // namespace media | 644 } // namespace media |
OLD | NEW |