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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 } | 355 } |
356 } | 356 } |
357 | 357 |
358 bool SourceBufferStream::Append( | 358 bool SourceBufferStream::Append( |
359 const SourceBufferStream::BufferQueue& buffers) { | 359 const SourceBufferStream::BufferQueue& buffers) { |
360 DCHECK(!buffers.empty()); | 360 DCHECK(!buffers.empty()); |
361 DCHECK(media_segment_start_time_ != kNoTimestamp()); | 361 DCHECK(media_segment_start_time_ != kNoTimestamp()); |
362 | 362 |
363 // New media segments must begin with a keyframe. | 363 // New media segments must begin with a keyframe. |
364 if (new_media_segment_ && !buffers.front()->IsKeyframe()) { | 364 if (new_media_segment_ && !buffers.front()->IsKeyframe()) { |
365 MEDIA_LOG(log_cb_) <<"Media segment did not begin with keyframe."; | 365 MEDIA_LOG(log_cb_) << "Media segment did not begin with keyframe."; |
366 return false; | 366 return false; |
367 } | 367 } |
368 | 368 |
369 // Buffers within a media segment should be monotonically increasing. | 369 // Buffers within a media segment should be monotonically increasing. |
370 if (!IsMonotonicallyIncreasing(buffers)) { | 370 if (!IsMonotonicallyIncreasing(buffers)) { |
371 MEDIA_LOG(log_cb_) <<"Buffers were not monotonically increasing."; | 371 MEDIA_LOG(log_cb_) << "Buffers were not monotonically increasing."; |
372 return false; | 372 return false; |
373 } | 373 } |
374 | 374 |
375 if (media_segment_start_time_ < base::TimeDelta() || | 375 if (media_segment_start_time_ < base::TimeDelta() || |
376 buffers.front()->GetDecodeTimestamp() < base::TimeDelta()) { | 376 buffers.front()->GetDecodeTimestamp() < base::TimeDelta()) { |
377 MEDIA_LOG(log_cb_) | 377 MEDIA_LOG(log_cb_) |
378 << "Cannot append a media segment with negative timestamps."; | 378 << "Cannot append a media segment with negative timestamps."; |
379 return false; | 379 return false; |
380 } | 380 } |
381 | 381 |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 } | 922 } |
923 | 923 |
924 SourceBufferStream::Status SourceBufferStream::GetNextBuffer( | 924 SourceBufferStream::Status SourceBufferStream::GetNextBuffer( |
925 scoped_refptr<StreamParserBuffer>* out_buffer) { | 925 scoped_refptr<StreamParserBuffer>* out_buffer) { |
926 CHECK(!config_change_pending_); | 926 CHECK(!config_change_pending_); |
927 | 927 |
928 if (!track_buffer_.empty()) { | 928 if (!track_buffer_.empty()) { |
929 DCHECK(selected_range_); | 929 DCHECK(selected_range_); |
930 if (track_buffer_.front()->GetConfigId() != current_config_index_) { | 930 if (track_buffer_.front()->GetConfigId() != current_config_index_) { |
931 config_change_pending_ = true; | 931 config_change_pending_ = true; |
| 932 DVLOG(1) << "Config change (track buffer config ID does not match)."; |
932 return kConfigChange; | 933 return kConfigChange; |
933 } | 934 } |
934 | 935 |
935 *out_buffer = track_buffer_.front(); | 936 *out_buffer = track_buffer_.front(); |
936 track_buffer_.pop_front(); | 937 track_buffer_.pop_front(); |
937 return kSuccess; | 938 return kSuccess; |
938 } | 939 } |
939 | 940 |
940 if (!selected_range_ || !selected_range_->HasNextBuffer()) | 941 if (!selected_range_ || !selected_range_->HasNextBuffer()) |
941 return kNeedBuffer; | 942 return kNeedBuffer; |
942 | 943 |
943 if (selected_range_->GetNextConfigId() != current_config_index_) { | 944 if (selected_range_->GetNextConfigId() != current_config_index_) { |
944 config_change_pending_ = true; | 945 config_change_pending_ = true; |
| 946 DVLOG(1) << "Config change (selected range config ID does not match)."; |
945 return kConfigChange; | 947 return kConfigChange; |
946 } | 948 } |
947 | 949 |
948 CHECK(selected_range_->GetNextBuffer(out_buffer)); | 950 CHECK(selected_range_->GetNextBuffer(out_buffer)); |
949 return kSuccess; | 951 return kSuccess; |
950 } | 952 } |
951 | 953 |
952 base::TimeDelta SourceBufferStream::GetNextBufferTimestamp() { | 954 base::TimeDelta SourceBufferStream::GetNextBufferTimestamp() { |
953 if (!selected_range_) { | 955 if (!selected_range_) { |
954 DCHECK(track_buffer_.empty()); | 956 DCHECK(track_buffer_.empty()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 | 1034 |
1033 base::TimeDelta SourceBufferStream::GetMaxInterbufferDistance() const { | 1035 base::TimeDelta SourceBufferStream::GetMaxInterbufferDistance() const { |
1034 if (max_interbuffer_distance_ == kNoTimestamp()) | 1036 if (max_interbuffer_distance_ == kNoTimestamp()) |
1035 return base::TimeDelta::FromMilliseconds(kDefaultBufferDurationInMs); | 1037 return base::TimeDelta::FromMilliseconds(kDefaultBufferDurationInMs); |
1036 return max_interbuffer_distance_; | 1038 return max_interbuffer_distance_; |
1037 } | 1039 } |
1038 | 1040 |
1039 bool SourceBufferStream::UpdateAudioConfig(const AudioDecoderConfig& config) { | 1041 bool SourceBufferStream::UpdateAudioConfig(const AudioDecoderConfig& config) { |
1040 DCHECK(!audio_configs_.empty()); | 1042 DCHECK(!audio_configs_.empty()); |
1041 DCHECK(video_configs_.empty()); | 1043 DCHECK(video_configs_.empty()); |
| 1044 DVLOG(3) << "UpdateAudioConfig."; |
1042 | 1045 |
1043 if (audio_configs_[0]->codec() != config.codec()) { | 1046 if (audio_configs_[0]->codec() != config.codec()) { |
1044 MEDIA_LOG(log_cb_) << "Audio codec changes not allowed."; | 1047 MEDIA_LOG(log_cb_) << "Audio codec changes not allowed."; |
1045 return false; | 1048 return false; |
1046 } | 1049 } |
1047 | 1050 |
1048 if (audio_configs_[0]->samples_per_second() != config.samples_per_second()) { | 1051 if (audio_configs_[0]->samples_per_second() != config.samples_per_second()) { |
1049 MEDIA_LOG(log_cb_) << "Audio sample rate changes not allowed."; | 1052 MEDIA_LOG(log_cb_) << "Audio sample rate changes not allowed."; |
1050 return false; | 1053 return false; |
1051 } | 1054 } |
(...skipping 16 matching lines...) Expand all Loading... |
1068 // Check to see if the new config matches an existing one. | 1071 // Check to see if the new config matches an existing one. |
1069 for (size_t i = 0; i < audio_configs_.size(); ++i) { | 1072 for (size_t i = 0; i < audio_configs_.size(); ++i) { |
1070 if (config.Matches(*audio_configs_[i])) { | 1073 if (config.Matches(*audio_configs_[i])) { |
1071 append_config_index_ = i; | 1074 append_config_index_ = i; |
1072 return true; | 1075 return true; |
1073 } | 1076 } |
1074 } | 1077 } |
1075 | 1078 |
1076 // No matches found so let's add this one to the list. | 1079 // No matches found so let's add this one to the list. |
1077 append_config_index_ = audio_configs_.size(); | 1080 append_config_index_ = audio_configs_.size(); |
| 1081 DVLOG(2) << "New audio config - index: " << append_config_index_; |
1078 audio_configs_.resize(audio_configs_.size() + 1); | 1082 audio_configs_.resize(audio_configs_.size() + 1); |
1079 audio_configs_[append_config_index_] = new AudioDecoderConfig(); | 1083 audio_configs_[append_config_index_] = new AudioDecoderConfig(); |
1080 audio_configs_[append_config_index_]->CopyFrom(config); | 1084 audio_configs_[append_config_index_]->CopyFrom(config); |
1081 return true; | 1085 return true; |
1082 } | 1086 } |
1083 | 1087 |
1084 bool SourceBufferStream::UpdateVideoConfig(const VideoDecoderConfig& config) { | 1088 bool SourceBufferStream::UpdateVideoConfig(const VideoDecoderConfig& config) { |
1085 DCHECK(!video_configs_.empty()); | 1089 DCHECK(!video_configs_.empty()); |
1086 DCHECK(audio_configs_.empty()); | 1090 DCHECK(audio_configs_.empty()); |
| 1091 DVLOG(3) << "UpdateVideoConfig."; |
1087 | 1092 |
1088 if (video_configs_[0]->is_encrypted() != config.is_encrypted()) { | 1093 if (video_configs_[0]->is_encrypted() != config.is_encrypted()) { |
1089 MEDIA_LOG(log_cb_) <<"Video Encryption changes not allowed."; | 1094 MEDIA_LOG(log_cb_) << "Video Encryption changes not allowed."; |
1090 return false; | 1095 return false; |
1091 } | 1096 } |
1092 | 1097 |
1093 if (video_configs_[0]->codec() != config.codec()) { | 1098 if (video_configs_[0]->codec() != config.codec()) { |
1094 MEDIA_LOG(log_cb_) <<"Video codec changes not allowed."; | 1099 MEDIA_LOG(log_cb_) << "Video codec changes not allowed."; |
1095 return false; | 1100 return false; |
1096 } | 1101 } |
1097 | 1102 |
1098 if (video_configs_[0]->is_encrypted() != config.is_encrypted()) { | 1103 if (video_configs_[0]->is_encrypted() != config.is_encrypted()) { |
1099 MEDIA_LOG(log_cb_) << "Video encryption changes not allowed."; | 1104 MEDIA_LOG(log_cb_) << "Video encryption changes not allowed."; |
1100 return false; | 1105 return false; |
1101 } | 1106 } |
1102 | 1107 |
1103 // Check to see if the new config matches an existing one. | 1108 // Check to see if the new config matches an existing one. |
1104 for (size_t i = 0; i < video_configs_.size(); ++i) { | 1109 for (size_t i = 0; i < video_configs_.size(); ++i) { |
1105 if (config.Matches(*video_configs_[i])) { | 1110 if (config.Matches(*video_configs_[i])) { |
1106 append_config_index_ = i; | 1111 append_config_index_ = i; |
1107 return true; | 1112 return true; |
1108 } | 1113 } |
1109 } | 1114 } |
1110 | 1115 |
1111 // No matches found so let's add this one to the list. | 1116 // No matches found so let's add this one to the list. |
1112 append_config_index_ = video_configs_.size(); | 1117 append_config_index_ = video_configs_.size(); |
| 1118 DVLOG(2) << "New video config - index: " << append_config_index_; |
1113 video_configs_.resize(video_configs_.size() + 1); | 1119 video_configs_.resize(video_configs_.size() + 1); |
1114 video_configs_[append_config_index_] = new VideoDecoderConfig(); | 1120 video_configs_[append_config_index_] = new VideoDecoderConfig(); |
1115 video_configs_[append_config_index_]->CopyFrom(config); | 1121 video_configs_[append_config_index_]->CopyFrom(config); |
1116 return true; | 1122 return true; |
1117 } | 1123 } |
1118 | 1124 |
1119 void SourceBufferStream::CompleteConfigChange() { | 1125 void SourceBufferStream::CompleteConfigChange() { |
1120 config_change_pending_ = false; | 1126 config_change_pending_ = false; |
1121 | 1127 |
1122 if (!track_buffer_.empty()) { | 1128 if (!track_buffer_.empty()) { |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 return ComputeFudgeRoom(GetApproximateDuration()); | 1579 return ComputeFudgeRoom(GetApproximateDuration()); |
1574 } | 1580 } |
1575 | 1581 |
1576 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { | 1582 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { |
1577 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); | 1583 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); |
1578 DCHECK(max_interbuffer_distance != kNoTimestamp()); | 1584 DCHECK(max_interbuffer_distance != kNoTimestamp()); |
1579 return max_interbuffer_distance; | 1585 return max_interbuffer_distance; |
1580 } | 1586 } |
1581 | 1587 |
1582 } // namespace media | 1588 } // namespace media |
OLD | NEW |