Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: media/filters/source_buffer_stream.cc

Issue 10836304: Add support for config changes during playback to FFmpegVideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added WebM config change test so we get coverage on Chromium bots that don't have MP4 enabled. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // 12MB: approximately 5 minutes of 320Kbps content. 263 // 12MB: approximately 5 minutes of 320Kbps content.
264 // 150MB: approximately 5 minutes of 4Mbps content. 264 // 150MB: approximately 5 minutes of 4Mbps content.
265 static int kDefaultAudioMemoryLimit = 12 * 1024 * 1024; 265 static int kDefaultAudioMemoryLimit = 12 * 1024 * 1024;
266 static int kDefaultVideoMemoryLimit = 150 * 1024 * 1024; 266 static int kDefaultVideoMemoryLimit = 150 * 1024 * 1024;
267 267
268 namespace media { 268 namespace media {
269 269
270 SourceBufferStream::SourceBufferStream(const AudioDecoderConfig& audio_config) 270 SourceBufferStream::SourceBufferStream(const AudioDecoderConfig& audio_config)
271 : current_config_index_(0), 271 : current_config_index_(0),
272 append_config_index_(0), 272 append_config_index_(0),
273 audio_configs_(1),
274 video_configs_(0),
275 stream_start_time_(kNoTimestamp()), 273 stream_start_time_(kNoTimestamp()),
276 seek_pending_(false), 274 seek_pending_(false),
277 seek_buffer_timestamp_(kNoTimestamp()), 275 seek_buffer_timestamp_(kNoTimestamp()),
278 selected_range_(NULL), 276 selected_range_(NULL),
279 media_segment_start_time_(kNoTimestamp()), 277 media_segment_start_time_(kNoTimestamp()),
280 range_for_next_append_(ranges_.end()), 278 range_for_next_append_(ranges_.end()),
281 new_media_segment_(false), 279 new_media_segment_(false),
282 last_buffer_timestamp_(kNoTimestamp()), 280 last_buffer_timestamp_(kNoTimestamp()),
283 max_interbuffer_distance_(kNoTimestamp()), 281 max_interbuffer_distance_(kNoTimestamp()),
284 memory_limit_(kDefaultAudioMemoryLimit) { 282 memory_limit_(kDefaultAudioMemoryLimit) {
285 audio_configs_[0] = new AudioDecoderConfig(); 283 DCHECK(audio_config.IsValidConfig());
286 audio_configs_[0]->CopyFrom(audio_config); 284 audio_configs_.push_back(new AudioDecoderConfig());
285 audio_configs_.back()->CopyFrom(audio_config);
287 } 286 }
288 287
289 SourceBufferStream::SourceBufferStream(const VideoDecoderConfig& video_config) 288 SourceBufferStream::SourceBufferStream(const VideoDecoderConfig& video_config)
290 : current_config_index_(0), 289 : current_config_index_(0),
291 append_config_index_(0), 290 append_config_index_(0),
292 audio_configs_(0),
293 video_configs_(1),
294 stream_start_time_(kNoTimestamp()), 291 stream_start_time_(kNoTimestamp()),
295 seek_pending_(false), 292 seek_pending_(false),
296 seek_buffer_timestamp_(kNoTimestamp()), 293 seek_buffer_timestamp_(kNoTimestamp()),
297 selected_range_(NULL), 294 selected_range_(NULL),
298 media_segment_start_time_(kNoTimestamp()), 295 media_segment_start_time_(kNoTimestamp()),
299 range_for_next_append_(ranges_.end()), 296 range_for_next_append_(ranges_.end()),
300 new_media_segment_(false), 297 new_media_segment_(false),
301 last_buffer_timestamp_(kNoTimestamp()), 298 last_buffer_timestamp_(kNoTimestamp()),
302 max_interbuffer_distance_(kNoTimestamp()), 299 max_interbuffer_distance_(kNoTimestamp()),
303 memory_limit_(kDefaultVideoMemoryLimit) { 300 memory_limit_(kDefaultVideoMemoryLimit) {
304 video_configs_[0] = new VideoDecoderConfig(); 301 DCHECK(video_config.IsValidConfig());
305 video_configs_[0]->CopyFrom(video_config); 302 video_configs_.push_back(new VideoDecoderConfig());
303 video_configs_.back()->CopyFrom(video_config);
306 } 304 }
307 305
308 SourceBufferStream::~SourceBufferStream() { 306 SourceBufferStream::~SourceBufferStream() {
309 while (!ranges_.empty()) { 307 while (!ranges_.empty()) {
310 delete ranges_.front(); 308 delete ranges_.front();
311 ranges_.pop_front(); 309 ranges_.pop_front();
312 } 310 }
313 311
314 STLDeleteElements(&audio_configs_); 312 STLDeleteElements(&audio_configs_);
315 STLDeleteElements(&video_configs_); 313 STLDeleteElements(&video_configs_);
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 delete *next_range_itr; 727 delete *next_range_itr;
730 ranges_.erase(next_range_itr); 728 ranges_.erase(next_range_itr);
731 } 729 }
732 } 730 }
733 731
734 void SourceBufferStream::Seek(base::TimeDelta timestamp) { 732 void SourceBufferStream::Seek(base::TimeDelta timestamp) {
735 DCHECK(stream_start_time_ != kNoTimestamp()); 733 DCHECK(stream_start_time_ != kNoTimestamp());
736 DCHECK(timestamp >= stream_start_time_); 734 DCHECK(timestamp >= stream_start_time_);
737 SetSelectedRange(NULL); 735 SetSelectedRange(NULL);
738 track_buffer_.clear(); 736 track_buffer_.clear();
737 config_change_pending_ = false;
739 738
740 if (ShouldSeekToStartOfBuffered(timestamp)) { 739 if (ShouldSeekToStartOfBuffered(timestamp)) {
741 SetSelectedRange(ranges_.front()); 740 SetSelectedRange(ranges_.front());
742 ranges_.front()->SeekToStart(); 741 ranges_.front()->SeekToStart();
743 seek_pending_ = false; 742 seek_pending_ = false;
744 return; 743 return;
745 } 744 }
746 745
747 seek_buffer_timestamp_ = timestamp; 746 seek_buffer_timestamp_ = timestamp;
748 seek_pending_ = true; 747 seek_pending_ = true;
(...skipping 11 matching lines...) Expand all
760 selected_range_->Seek(timestamp); 759 selected_range_->Seek(timestamp);
761 seek_pending_ = false; 760 seek_pending_ = false;
762 } 761 }
763 762
764 bool SourceBufferStream::IsSeekPending() const { 763 bool SourceBufferStream::IsSeekPending() const {
765 return seek_pending_; 764 return seek_pending_;
766 } 765 }
767 766
768 SourceBufferStream::Status SourceBufferStream::GetNextBuffer( 767 SourceBufferStream::Status SourceBufferStream::GetNextBuffer(
769 scoped_refptr<StreamParserBuffer>* out_buffer) { 768 scoped_refptr<StreamParserBuffer>* out_buffer) {
769 CHECK(!config_change_pending_);
770
770 if (!track_buffer_.empty()) { 771 if (!track_buffer_.empty()) {
771 if (track_buffer_.front()->GetConfigId() != current_config_index_) 772 if (track_buffer_.front()->GetConfigId() != current_config_index_) {
773 config_change_pending_ = true;
772 return kConfigChange; 774 return kConfigChange;
775 }
773 776
774 *out_buffer = track_buffer_.front(); 777 *out_buffer = track_buffer_.front();
775 track_buffer_.pop_front(); 778 track_buffer_.pop_front();
776 return kSuccess; 779 return kSuccess;
777 } 780 }
778 781
779 if (!selected_range_ || !selected_range_->HasNextBuffer()) 782 if (!selected_range_ || !selected_range_->HasNextBuffer())
780 return kNeedBuffer; 783 return kNeedBuffer;
781 784
782 if (selected_range_->GetNextConfigId() != current_config_index_) 785 if (selected_range_->GetNextConfigId() != current_config_index_) {
786 config_change_pending_ = true;
783 return kConfigChange; 787 return kConfigChange;
788 }
784 789
785 CHECK(selected_range_->GetNextBuffer(out_buffer)); 790 CHECK(selected_range_->GetNextBuffer(out_buffer));
786 return kSuccess; 791 return kSuccess;
787 } 792 }
788 793
789 base::TimeDelta SourceBufferStream::GetNextBufferTimestamp() { 794 base::TimeDelta SourceBufferStream::GetNextBufferTimestamp() {
790 if (!selected_range_) 795 if (!selected_range_)
791 return kNoTimestamp(); 796 return kNoTimestamp();
792 797
793 DCHECK(selected_range_->HasNextBufferPosition()); 798 DCHECK(selected_range_->HasNextBufferPosition());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 ranges.Add((*itr)->GetStartTimestamp(), (*itr)->GetBufferedEndTimestamp()); 850 ranges.Add((*itr)->GetStartTimestamp(), (*itr)->GetBufferedEndTimestamp());
846 } 851 }
847 return ranges; 852 return ranges;
848 } 853 }
849 854
850 bool SourceBufferStream::IsEndSelected() const { 855 bool SourceBufferStream::IsEndSelected() const {
851 return ranges_.empty() || selected_range_ == ranges_.back(); 856 return ranges_.empty() || selected_range_ == ranges_.back();
852 } 857 }
853 858
854 const AudioDecoderConfig& SourceBufferStream::GetCurrentAudioDecoderConfig() { 859 const AudioDecoderConfig& SourceBufferStream::GetCurrentAudioDecoderConfig() {
855 CompleteConfigChange(); 860 if (config_change_pending_)
861 CompleteConfigChange();
856 return *audio_configs_[current_config_index_]; 862 return *audio_configs_[current_config_index_];
857 } 863 }
858 864
859 const VideoDecoderConfig& SourceBufferStream::GetCurrentVideoDecoderConfig() { 865 const VideoDecoderConfig& SourceBufferStream::GetCurrentVideoDecoderConfig() {
860 CompleteConfigChange(); 866 if (config_change_pending_)
867 CompleteConfigChange();
861 return *video_configs_[current_config_index_]; 868 return *video_configs_[current_config_index_];
862 } 869 }
863 870
864 base::TimeDelta SourceBufferStream::GetMaxInterbufferDistance() const { 871 base::TimeDelta SourceBufferStream::GetMaxInterbufferDistance() const {
865 if (max_interbuffer_distance_ == kNoTimestamp()) 872 if (max_interbuffer_distance_ == kNoTimestamp())
866 return base::TimeDelta::FromMilliseconds(kDefaultBufferDurationInMs); 873 return base::TimeDelta::FromMilliseconds(kDefaultBufferDurationInMs);
867 return max_interbuffer_distance_; 874 return max_interbuffer_distance_;
868 } 875 }
869 876
870 bool SourceBufferStream::UpdateAudioConfig(const AudioDecoderConfig& config) { 877 bool SourceBufferStream::UpdateAudioConfig(const AudioDecoderConfig& config) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 933
927 // No matches found so let's add this one to the list. 934 // No matches found so let's add this one to the list.
928 append_config_index_ = video_configs_.size(); 935 append_config_index_ = video_configs_.size();
929 video_configs_.resize(video_configs_.size() + 1); 936 video_configs_.resize(video_configs_.size() + 1);
930 video_configs_[append_config_index_] = new VideoDecoderConfig(); 937 video_configs_[append_config_index_] = new VideoDecoderConfig();
931 video_configs_[append_config_index_]->CopyFrom(config); 938 video_configs_[append_config_index_]->CopyFrom(config);
932 return true; 939 return true;
933 } 940 }
934 941
935 void SourceBufferStream::CompleteConfigChange() { 942 void SourceBufferStream::CompleteConfigChange() {
943 config_change_pending_ = false;
944
936 if (!track_buffer_.empty()) { 945 if (!track_buffer_.empty()) {
937 current_config_index_ = track_buffer_.front()->GetConfigId(); 946 current_config_index_ = track_buffer_.front()->GetConfigId();
938 return; 947 return;
939 } 948 }
940 949
941 if (!selected_range_ || !selected_range_->HasNextBuffer()) 950 if (selected_range_ && selected_range_->HasNextBuffer())
942 return; 951 current_config_index_ = selected_range_->GetNextConfigId();
943
944 current_config_index_ = selected_range_->GetNextConfigId();
945 } 952 }
946 953
947 SourceBufferRange::SourceBufferRange( 954 SourceBufferRange::SourceBufferRange(
948 const BufferQueue& new_buffers, base::TimeDelta media_segment_start_time, 955 const BufferQueue& new_buffers, base::TimeDelta media_segment_start_time,
949 const InterbufferDistanceCB& interbuffer_distance_cb) 956 const InterbufferDistanceCB& interbuffer_distance_cb)
950 : next_buffer_index_(-1), 957 : next_buffer_index_(-1),
951 waiting_for_keyframe_(false), 958 waiting_for_keyframe_(false),
952 next_keyframe_timestamp_(kNoTimestamp()), 959 next_keyframe_timestamp_(kNoTimestamp()),
953 media_segment_start_time_(media_segment_start_time), 960 media_segment_start_time_(media_segment_start_time),
954 interbuffer_distance_cb_(interbuffer_distance_cb), 961 interbuffer_distance_cb_(interbuffer_distance_cb),
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 return 2 * GetApproximateDuration(); 1385 return 2 * GetApproximateDuration();
1379 } 1386 }
1380 1387
1381 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { 1388 base::TimeDelta SourceBufferRange::GetApproximateDuration() const {
1382 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); 1389 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run();
1383 DCHECK(max_interbuffer_distance != kNoTimestamp()); 1390 DCHECK(max_interbuffer_distance != kNoTimestamp());
1384 return max_interbuffer_distance; 1391 return max_interbuffer_distance;
1385 } 1392 }
1386 1393
1387 } // namespace media 1394 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698