| 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/formats/webm/webm_cluster_parser.h" | 5 #include "media/formats/webm/webm_cluster_parser.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 // estimation may still apply in cases of encryption and codecs for which | 556 // estimation may still apply in cases of encryption and codecs for which |
| 557 // we do not extract encoded duration. Within a cluster, estimates are applied | 557 // we do not extract encoded duration. Within a cluster, estimates are applied |
| 558 // as Block Timecode deltas, or once the whole cluster is parsed in the case | 558 // as Block Timecode deltas, or once the whole cluster is parsed in the case |
| 559 // of the last Block in the cluster. See Track::AddBuffer and | 559 // of the last Block in the cluster. See Track::AddBuffer and |
| 560 // ApplyDurationEstimateIfNeeded(). | 560 // ApplyDurationEstimateIfNeeded(). |
| 561 if (encoded_duration != kNoTimestamp) { | 561 if (encoded_duration != kNoTimestamp) { |
| 562 DCHECK(encoded_duration != kInfiniteDuration); | 562 DCHECK(encoded_duration != kInfiniteDuration); |
| 563 DCHECK(encoded_duration > base::TimeDelta()); | 563 DCHECK(encoded_duration > base::TimeDelta()); |
| 564 buffer->set_duration(encoded_duration); | 564 buffer->set_duration(encoded_duration); |
| 565 | 565 |
| 566 DVLOG(3) << __FUNCTION__ << " : " | 566 DVLOG(3) << __func__ << " : " |
| 567 << "Using encoded duration " << encoded_duration.InSecondsF(); | 567 << "Using encoded duration " << encoded_duration.InSecondsF(); |
| 568 | 568 |
| 569 if (block_duration_time_delta != kNoTimestamp) { | 569 if (block_duration_time_delta != kNoTimestamp) { |
| 570 base::TimeDelta duration_difference = | 570 base::TimeDelta duration_difference = |
| 571 block_duration_time_delta - encoded_duration; | 571 block_duration_time_delta - encoded_duration; |
| 572 | 572 |
| 573 const auto kWarnDurationDiff = | 573 const auto kWarnDurationDiff = |
| 574 base::TimeDelta::FromMicroseconds(timecode_multiplier_ * 2); | 574 base::TimeDelta::FromMicroseconds(timecode_multiplier_ * 2); |
| 575 if (duration_difference.magnitude() > kWarnDurationDiff) { | 575 if (duration_difference.magnitude() > kWarnDurationDiff) { |
| 576 LIMITED_MEDIA_LOG(DEBUG, media_log_, num_duration_errors_, | 576 LIMITED_MEDIA_LOG(DEBUG, media_log_, num_duration_errors_, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 DCHECK(ready_buffers_.empty()); | 626 DCHECK(ready_buffers_.empty()); |
| 627 DCHECK(DecodeTimestamp() <= before_timestamp); | 627 DCHECK(DecodeTimestamp() <= before_timestamp); |
| 628 DCHECK(kNoDecodeTimestamp() != before_timestamp); | 628 DCHECK(kNoDecodeTimestamp() != before_timestamp); |
| 629 | 629 |
| 630 if (buffers_.empty()) | 630 if (buffers_.empty()) |
| 631 return; | 631 return; |
| 632 | 632 |
| 633 if (buffers_.back()->GetDecodeTimestamp() < before_timestamp) { | 633 if (buffers_.back()->GetDecodeTimestamp() < before_timestamp) { |
| 634 // All of |buffers_| are ready. | 634 // All of |buffers_| are ready. |
| 635 ready_buffers_.swap(buffers_); | 635 ready_buffers_.swap(buffers_); |
| 636 DVLOG(3) << __FUNCTION__ << " : " << track_num_ << " All " | 636 DVLOG(3) << __func__ << " : " << track_num_ << " All " |
| 637 << ready_buffers_.size() << " are ready: before upper bound ts " | 637 << ready_buffers_.size() << " are ready: before upper bound ts " |
| 638 << before_timestamp.InSecondsF(); | 638 << before_timestamp.InSecondsF(); |
| 639 return; | 639 return; |
| 640 } | 640 } |
| 641 | 641 |
| 642 // Not all of |buffers_| are ready yet. Move any that are ready to | 642 // Not all of |buffers_| are ready yet. Move any that are ready to |
| 643 // |ready_buffers_|. | 643 // |ready_buffers_|. |
| 644 while (true) { | 644 while (true) { |
| 645 const scoped_refptr<StreamParserBuffer>& buffer = buffers_.front(); | 645 const scoped_refptr<StreamParserBuffer>& buffer = buffers_.front(); |
| 646 if (buffer->GetDecodeTimestamp() >= before_timestamp) | 646 if (buffer->GetDecodeTimestamp() >= before_timestamp) |
| 647 break; | 647 break; |
| 648 ready_buffers_.push_back(buffer); | 648 ready_buffers_.push_back(buffer); |
| 649 buffers_.pop_front(); | 649 buffers_.pop_front(); |
| 650 DCHECK(!buffers_.empty()); | 650 DCHECK(!buffers_.empty()); |
| 651 } | 651 } |
| 652 | 652 |
| 653 DVLOG(3) << __FUNCTION__ << " : " << track_num_ << " Only " | 653 DVLOG(3) << __func__ << " : " << track_num_ << " Only " |
| 654 << ready_buffers_.size() << " ready, " << buffers_.size() | 654 << ready_buffers_.size() << " ready, " << buffers_.size() |
| 655 << " at or after upper bound ts " << before_timestamp.InSecondsF(); | 655 << " at or after upper bound ts " << before_timestamp.InSecondsF(); |
| 656 } | 656 } |
| 657 | 657 |
| 658 bool WebMClusterParser::Track::AddBuffer( | 658 bool WebMClusterParser::Track::AddBuffer( |
| 659 const scoped_refptr<StreamParserBuffer>& buffer) { | 659 const scoped_refptr<StreamParserBuffer>& buffer) { |
| 660 DVLOG(2) << "AddBuffer() : " << track_num_ | 660 DVLOG(2) << "AddBuffer() : " << track_num_ |
| 661 << " ts " << buffer->timestamp().InSecondsF() | 661 << " ts " << buffer->timestamp().InSecondsF() |
| 662 << " dur " << buffer->duration().InSecondsF() | 662 << " dur " << buffer->duration().InSecondsF() |
| 663 << " kf " << buffer->is_key_frame() | 663 << " kf " << buffer->is_key_frame() |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 } | 707 } |
| 708 | 708 |
| 709 LIMITED_MEDIA_LOG(INFO, media_log_, num_duration_estimates_, | 709 LIMITED_MEDIA_LOG(INFO, media_log_, num_duration_estimates_, |
| 710 kMaxDurationEstimateLogs) | 710 kMaxDurationEstimateLogs) |
| 711 << "Estimating WebM block duration to be " | 711 << "Estimating WebM block duration to be " |
| 712 << estimated_duration.InMilliseconds() | 712 << estimated_duration.InMilliseconds() |
| 713 << "ms for the last (Simple)Block in the Cluster for this Track. Use " | 713 << "ms for the last (Simple)Block in the Cluster for this Track. Use " |
| 714 "BlockGroups with BlockDurations at the end of each Track in a " | 714 "BlockGroups with BlockDurations at the end of each Track in a " |
| 715 "Cluster to avoid estimation."; | 715 "Cluster to avoid estimation."; |
| 716 | 716 |
| 717 DVLOG(2) << __FUNCTION__ << " new dur : ts " | 717 DVLOG(2) << __func__ << " new dur : ts " |
| 718 << last_added_buffer_missing_duration_->timestamp().InSecondsF() | 718 << last_added_buffer_missing_duration_->timestamp().InSecondsF() |
| 719 << " dur " | 719 << " dur " |
| 720 << last_added_buffer_missing_duration_->duration().InSecondsF() | 720 << last_added_buffer_missing_duration_->duration().InSecondsF() |
| 721 << " kf " << last_added_buffer_missing_duration_->is_key_frame() | 721 << " kf " << last_added_buffer_missing_duration_->is_key_frame() |
| 722 << " size " << last_added_buffer_missing_duration_->data_size(); | 722 << " size " << last_added_buffer_missing_duration_->data_size(); |
| 723 | 723 |
| 724 // Don't use the applied duration as a future estimation (don't use | 724 // Don't use the applied duration as a future estimation (don't use |
| 725 // QueueBuffer() here.) | 725 // QueueBuffer() here.) |
| 726 buffers_.push_back(last_added_buffer_missing_duration_); | 726 buffers_.push_back(last_added_buffer_missing_duration_); |
| 727 last_added_buffer_missing_duration_ = NULL; | 727 last_added_buffer_missing_duration_ = NULL; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 } | 788 } |
| 789 } | 789 } |
| 790 | 790 |
| 791 buffers_.push_back(buffer); | 791 buffers_.push_back(buffer); |
| 792 return true; | 792 return true; |
| 793 } | 793 } |
| 794 | 794 |
| 795 base::TimeDelta WebMClusterParser::Track::GetDurationEstimate() { | 795 base::TimeDelta WebMClusterParser::Track::GetDurationEstimate() { |
| 796 base::TimeDelta duration = estimated_next_frame_duration_; | 796 base::TimeDelta duration = estimated_next_frame_duration_; |
| 797 if (duration != kNoTimestamp) { | 797 if (duration != kNoTimestamp) { |
| 798 DVLOG(3) << __FUNCTION__ << " : using estimated duration"; | 798 DVLOG(3) << __func__ << " : using estimated duration"; |
| 799 } else { | 799 } else { |
| 800 DVLOG(3) << __FUNCTION__ << " : using hardcoded default duration"; | 800 DVLOG(3) << __func__ << " : using hardcoded default duration"; |
| 801 if (is_video_) { | 801 if (is_video_) { |
| 802 duration = base::TimeDelta::FromMilliseconds( | 802 duration = base::TimeDelta::FromMilliseconds( |
| 803 kDefaultVideoBufferDurationInMs); | 803 kDefaultVideoBufferDurationInMs); |
| 804 } else { | 804 } else { |
| 805 duration = base::TimeDelta::FromMilliseconds( | 805 duration = base::TimeDelta::FromMilliseconds( |
| 806 kDefaultAudioBufferDurationInMs); | 806 kDefaultAudioBufferDurationInMs); |
| 807 } | 807 } |
| 808 } | 808 } |
| 809 | 809 |
| 810 DCHECK(duration > base::TimeDelta()); | 810 DCHECK(duration > base::TimeDelta()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 WebMClusterParser::FindTextTrack(int track_num) { | 865 WebMClusterParser::FindTextTrack(int track_num) { |
| 866 const TextTrackMap::iterator it = text_track_map_.find(track_num); | 866 const TextTrackMap::iterator it = text_track_map_.find(track_num); |
| 867 | 867 |
| 868 if (it == text_track_map_.end()) | 868 if (it == text_track_map_.end()) |
| 869 return NULL; | 869 return NULL; |
| 870 | 870 |
| 871 return &it->second; | 871 return &it->second; |
| 872 } | 872 } |
| 873 | 873 |
| 874 } // namespace media | 874 } // namespace media |
| OLD | NEW |