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

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

Issue 10828425: Add support for config changes during playback to FFmpegVideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add config_change_pending_ initializers to constructors. 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
« no previous file with comments | « media/filters/source_buffer_stream.h ('k') | media/filters/source_buffer_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 config_change_pending_(false) {
286 audio_configs_[0]->CopyFrom(audio_config); 284 DCHECK(audio_config.IsValidConfig());
285 audio_configs_.push_back(new AudioDecoderConfig());
286 audio_configs_.back()->CopyFrom(audio_config);
287 } 287 }
288 288
289 SourceBufferStream::SourceBufferStream(const VideoDecoderConfig& video_config) 289 SourceBufferStream::SourceBufferStream(const VideoDecoderConfig& video_config)
290 : current_config_index_(0), 290 : current_config_index_(0),
291 append_config_index_(0), 291 append_config_index_(0),
292 audio_configs_(0),
293 video_configs_(1),
294 stream_start_time_(kNoTimestamp()), 292 stream_start_time_(kNoTimestamp()),
295 seek_pending_(false), 293 seek_pending_(false),
296 seek_buffer_timestamp_(kNoTimestamp()), 294 seek_buffer_timestamp_(kNoTimestamp()),
297 selected_range_(NULL), 295 selected_range_(NULL),
298 media_segment_start_time_(kNoTimestamp()), 296 media_segment_start_time_(kNoTimestamp()),
299 range_for_next_append_(ranges_.end()), 297 range_for_next_append_(ranges_.end()),
300 new_media_segment_(false), 298 new_media_segment_(false),
301 last_buffer_timestamp_(kNoTimestamp()), 299 last_buffer_timestamp_(kNoTimestamp()),
302 max_interbuffer_distance_(kNoTimestamp()), 300 max_interbuffer_distance_(kNoTimestamp()),
303 memory_limit_(kDefaultVideoMemoryLimit) { 301 memory_limit_(kDefaultVideoMemoryLimit),
304 video_configs_[0] = new VideoDecoderConfig(); 302 config_change_pending_(false) {
305 video_configs_[0]->CopyFrom(video_config); 303 DCHECK(video_config.IsValidConfig());
304 video_configs_.push_back(new VideoDecoderConfig());
305 video_configs_.back()->CopyFrom(video_config);
306 } 306 }
307 307
308 SourceBufferStream::~SourceBufferStream() { 308 SourceBufferStream::~SourceBufferStream() {
309 while (!ranges_.empty()) { 309 while (!ranges_.empty()) {
310 delete ranges_.front(); 310 delete ranges_.front();
311 ranges_.pop_front(); 311 ranges_.pop_front();
312 } 312 }
313 313
314 STLDeleteElements(&audio_configs_); 314 STLDeleteElements(&audio_configs_);
315 STLDeleteElements(&video_configs_); 315 STLDeleteElements(&video_configs_);
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 delete *next_range_itr; 729 delete *next_range_itr;
730 ranges_.erase(next_range_itr); 730 ranges_.erase(next_range_itr);
731 } 731 }
732 } 732 }
733 733
734 void SourceBufferStream::Seek(base::TimeDelta timestamp) { 734 void SourceBufferStream::Seek(base::TimeDelta timestamp) {
735 DCHECK(stream_start_time_ != kNoTimestamp()); 735 DCHECK(stream_start_time_ != kNoTimestamp());
736 DCHECK(timestamp >= stream_start_time_); 736 DCHECK(timestamp >= stream_start_time_);
737 SetSelectedRange(NULL); 737 SetSelectedRange(NULL);
738 track_buffer_.clear(); 738 track_buffer_.clear();
739 config_change_pending_ = false;
739 740
740 if (ShouldSeekToStartOfBuffered(timestamp)) { 741 if (ShouldSeekToStartOfBuffered(timestamp)) {
741 SetSelectedRange(ranges_.front()); 742 SetSelectedRange(ranges_.front());
742 ranges_.front()->SeekToStart(); 743 ranges_.front()->SeekToStart();
743 seek_pending_ = false; 744 seek_pending_ = false;
744 return; 745 return;
745 } 746 }
746 747
747 seek_buffer_timestamp_ = timestamp; 748 seek_buffer_timestamp_ = timestamp;
748 seek_pending_ = true; 749 seek_pending_ = true;
(...skipping 11 matching lines...) Expand all
760 selected_range_->Seek(timestamp); 761 selected_range_->Seek(timestamp);
761 seek_pending_ = false; 762 seek_pending_ = false;
762 } 763 }
763 764
764 bool SourceBufferStream::IsSeekPending() const { 765 bool SourceBufferStream::IsSeekPending() const {
765 return seek_pending_; 766 return seek_pending_;
766 } 767 }
767 768
768 SourceBufferStream::Status SourceBufferStream::GetNextBuffer( 769 SourceBufferStream::Status SourceBufferStream::GetNextBuffer(
769 scoped_refptr<StreamParserBuffer>* out_buffer) { 770 scoped_refptr<StreamParserBuffer>* out_buffer) {
771 CHECK(!config_change_pending_);
772
770 if (!track_buffer_.empty()) { 773 if (!track_buffer_.empty()) {
771 if (track_buffer_.front()->GetConfigId() != current_config_index_) 774 if (track_buffer_.front()->GetConfigId() != current_config_index_) {
775 config_change_pending_ = true;
772 return kConfigChange; 776 return kConfigChange;
777 }
773 778
774 *out_buffer = track_buffer_.front(); 779 *out_buffer = track_buffer_.front();
775 track_buffer_.pop_front(); 780 track_buffer_.pop_front();
776 return kSuccess; 781 return kSuccess;
777 } 782 }
778 783
779 if (!selected_range_ || !selected_range_->HasNextBuffer()) 784 if (!selected_range_ || !selected_range_->HasNextBuffer())
780 return kNeedBuffer; 785 return kNeedBuffer;
781 786
782 if (selected_range_->GetNextConfigId() != current_config_index_) 787 if (selected_range_->GetNextConfigId() != current_config_index_) {
788 config_change_pending_ = true;
783 return kConfigChange; 789 return kConfigChange;
790 }
784 791
785 CHECK(selected_range_->GetNextBuffer(out_buffer)); 792 CHECK(selected_range_->GetNextBuffer(out_buffer));
786 return kSuccess; 793 return kSuccess;
787 } 794 }
788 795
789 base::TimeDelta SourceBufferStream::GetNextBufferTimestamp() { 796 base::TimeDelta SourceBufferStream::GetNextBufferTimestamp() {
790 if (!selected_range_) 797 if (!selected_range_)
791 return kNoTimestamp(); 798 return kNoTimestamp();
792 799
793 DCHECK(selected_range_->HasNextBufferPosition()); 800 DCHECK(selected_range_->HasNextBufferPosition());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 ranges.Add((*itr)->GetStartTimestamp(), (*itr)->GetBufferedEndTimestamp()); 852 ranges.Add((*itr)->GetStartTimestamp(), (*itr)->GetBufferedEndTimestamp());
846 } 853 }
847 return ranges; 854 return ranges;
848 } 855 }
849 856
850 bool SourceBufferStream::IsEndSelected() const { 857 bool SourceBufferStream::IsEndSelected() const {
851 return ranges_.empty() || selected_range_ == ranges_.back(); 858 return ranges_.empty() || selected_range_ == ranges_.back();
852 } 859 }
853 860
854 const AudioDecoderConfig& SourceBufferStream::GetCurrentAudioDecoderConfig() { 861 const AudioDecoderConfig& SourceBufferStream::GetCurrentAudioDecoderConfig() {
855 CompleteConfigChange(); 862 if (config_change_pending_)
863 CompleteConfigChange();
856 return *audio_configs_[current_config_index_]; 864 return *audio_configs_[current_config_index_];
857 } 865 }
858 866
859 const VideoDecoderConfig& SourceBufferStream::GetCurrentVideoDecoderConfig() { 867 const VideoDecoderConfig& SourceBufferStream::GetCurrentVideoDecoderConfig() {
860 CompleteConfigChange(); 868 if (config_change_pending_)
869 CompleteConfigChange();
861 return *video_configs_[current_config_index_]; 870 return *video_configs_[current_config_index_];
862 } 871 }
863 872
864 base::TimeDelta SourceBufferStream::GetMaxInterbufferDistance() const { 873 base::TimeDelta SourceBufferStream::GetMaxInterbufferDistance() const {
865 if (max_interbuffer_distance_ == kNoTimestamp()) 874 if (max_interbuffer_distance_ == kNoTimestamp())
866 return base::TimeDelta::FromMilliseconds(kDefaultBufferDurationInMs); 875 return base::TimeDelta::FromMilliseconds(kDefaultBufferDurationInMs);
867 return max_interbuffer_distance_; 876 return max_interbuffer_distance_;
868 } 877 }
869 878
870 bool SourceBufferStream::UpdateAudioConfig(const AudioDecoderConfig& config) { 879 bool SourceBufferStream::UpdateAudioConfig(const AudioDecoderConfig& config) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 935
927 // No matches found so let's add this one to the list. 936 // No matches found so let's add this one to the list.
928 append_config_index_ = video_configs_.size(); 937 append_config_index_ = video_configs_.size();
929 video_configs_.resize(video_configs_.size() + 1); 938 video_configs_.resize(video_configs_.size() + 1);
930 video_configs_[append_config_index_] = new VideoDecoderConfig(); 939 video_configs_[append_config_index_] = new VideoDecoderConfig();
931 video_configs_[append_config_index_]->CopyFrom(config); 940 video_configs_[append_config_index_]->CopyFrom(config);
932 return true; 941 return true;
933 } 942 }
934 943
935 void SourceBufferStream::CompleteConfigChange() { 944 void SourceBufferStream::CompleteConfigChange() {
945 config_change_pending_ = false;
946
936 if (!track_buffer_.empty()) { 947 if (!track_buffer_.empty()) {
937 current_config_index_ = track_buffer_.front()->GetConfigId(); 948 current_config_index_ = track_buffer_.front()->GetConfigId();
938 return; 949 return;
939 } 950 }
940 951
941 if (!selected_range_ || !selected_range_->HasNextBuffer()) 952 if (selected_range_ && selected_range_->HasNextBuffer())
942 return; 953 current_config_index_ = selected_range_->GetNextConfigId();
943
944 current_config_index_ = selected_range_->GetNextConfigId();
945 } 954 }
946 955
947 SourceBufferRange::SourceBufferRange( 956 SourceBufferRange::SourceBufferRange(
948 const BufferQueue& new_buffers, base::TimeDelta media_segment_start_time, 957 const BufferQueue& new_buffers, base::TimeDelta media_segment_start_time,
949 const InterbufferDistanceCB& interbuffer_distance_cb) 958 const InterbufferDistanceCB& interbuffer_distance_cb)
950 : next_buffer_index_(-1), 959 : next_buffer_index_(-1),
951 waiting_for_keyframe_(false), 960 waiting_for_keyframe_(false),
952 next_keyframe_timestamp_(kNoTimestamp()), 961 next_keyframe_timestamp_(kNoTimestamp()),
953 media_segment_start_time_(media_segment_start_time), 962 media_segment_start_time_(media_segment_start_time),
954 interbuffer_distance_cb_(interbuffer_distance_cb), 963 interbuffer_distance_cb_(interbuffer_distance_cb),
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 return 2 * GetApproximateDuration(); 1387 return 2 * GetApproximateDuration();
1379 } 1388 }
1380 1389
1381 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { 1390 base::TimeDelta SourceBufferRange::GetApproximateDuration() const {
1382 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); 1391 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run();
1383 DCHECK(max_interbuffer_distance != kNoTimestamp()); 1392 DCHECK(max_interbuffer_distance != kNoTimestamp());
1384 return max_interbuffer_distance; 1393 return max_interbuffer_distance;
1385 } 1394 }
1386 1395
1387 } // namespace media 1396 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/source_buffer_stream.h ('k') | media/filters/source_buffer_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698