OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/media/android/media_source_delegate.h" | 5 #include "content/renderer/media/android/media_source_delegate.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 | 340 |
341 DCHECK(type == DemuxerStream::AUDIO || type == DemuxerStream::VIDEO); | 341 DCHECK(type == DemuxerStream::AUDIO || type == DemuxerStream::VIDEO); |
342 // The access unit size should have been initialized properly at this stage. | 342 // The access unit size should have been initialized properly at this stage. |
343 DCHECK_GT(access_unit_size_, 0u); | 343 DCHECK_GT(access_unit_size_, 0u); |
344 scoped_ptr<DemuxerData> data(new DemuxerData()); | 344 scoped_ptr<DemuxerData> data(new DemuxerData()); |
345 data->type = type; | 345 data->type = type; |
346 data->access_units.resize(access_unit_size_); | 346 data->access_units.resize(access_unit_size_); |
347 ReadFromDemuxerStream(type, data.Pass(), 0); | 347 ReadFromDemuxerStream(type, data.Pass(), 0); |
348 } | 348 } |
349 | 349 |
350 void MediaSourceDelegate::ReadFromDemuxerStream(media::DemuxerStream::Type type, | 350 void MediaSourceDelegate::ReadFromDemuxerStream(media::DemuxerStream::Type type, |
wolenetz
2014/05/08 17:41:47
not lgtm: this mismatches declaration's retval. Wh
qinmin
2014/05/08 17:48:37
This should still be a void, accidentally changed
| |
351 scoped_ptr<DemuxerData> data, | 351 scoped_ptr<DemuxerData> data, |
352 size_t index) { | 352 size_t index) { |
353 DCHECK(media_loop_->BelongsToCurrentThread()); | 353 DCHECK(media_loop_->BelongsToCurrentThread()); |
354 // DemuxerStream::Read() always returns the read callback asynchronously. | 354 // DemuxerStream::Read() always returns the read callback asynchronously. |
355 DemuxerStream* stream = | 355 DemuxerStream* stream = |
356 (type == DemuxerStream::AUDIO) ? audio_stream_ : video_stream_; | 356 (type == DemuxerStream::AUDIO) ? audio_stream_ : video_stream_; |
357 stream->Read(base::Bind( | 357 stream->Read(base::Bind( |
358 &MediaSourceDelegate::OnBufferReady, | 358 &MediaSourceDelegate::OnBufferReady, |
359 media_weak_factory_.GetWeakPtr(), type, base::Passed(&data), index)); | 359 media_weak_factory_.GetWeakPtr(), type, base::Passed(&data), index)); |
360 } | 360 } |
(...skipping 30 matching lines...) Expand all Loading... | |
391 } | 391 } |
392 | 392 |
393 switch (status) { | 393 switch (status) { |
394 case DemuxerStream::kAborted: | 394 case DemuxerStream::kAborted: |
395 DVLOG(1) << __FUNCTION__ << " : Aborted"; | 395 DVLOG(1) << __FUNCTION__ << " : Aborted"; |
396 data->access_units[index].status = status; | 396 data->access_units[index].status = status; |
397 data->access_units.resize(index + 1); | 397 data->access_units.resize(index + 1); |
398 break; | 398 break; |
399 | 399 |
400 case DemuxerStream::kConfigChanged: | 400 case DemuxerStream::kConfigChanged: |
401 // In case of kConfigChanged, need to read decoder_config once | 401 CHECK((is_audio && audio_stream_) || (!is_audio && video_stream_)); |
402 // for the next reads. | 402 data->demuxer_configs.resize(1); |
403 // TODO(kjyoun): Investigate if we need to use this new config. See | 403 if (!GetDemuxerConfigFromStream(&data->demuxer_configs[0], is_audio)) { |
404 // http://crbug.com/255783 | 404 data->demuxer_configs.resize(0); |
405 if (is_audio) { | 405 } else if (!is_audio) { |
406 audio_stream_->audio_decoder_config(); | 406 gfx::Size size = data->demuxer_configs[0].video_size; |
407 } else { | |
408 gfx::Size size = video_stream_->video_decoder_config().coded_size(); | |
409 DVLOG(1) << "Video config is changed: " << size.width() << "x" | 407 DVLOG(1) << "Video config is changed: " << size.width() << "x" |
410 << size.height(); | 408 << size.height(); |
411 } | 409 } |
412 data->access_units[index].status = status; | 410 data->access_units[index].status = status; |
413 data->access_units.resize(index + 1); | 411 data->access_units.resize(index + 1); |
414 break; | 412 break; |
415 | 413 |
416 case DemuxerStream::kOk: | 414 case DemuxerStream::kOk: |
417 data->access_units[index].status = status; | 415 data->access_units[index].status = status; |
418 if (buffer->end_of_stream()) { | 416 if (buffer->end_of_stream()) { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 base::Bind(&MediaSourceDelegate::DeleteSelf, base::Unretained(this))); | 640 base::Bind(&MediaSourceDelegate::DeleteSelf, base::Unretained(this))); |
643 } | 641 } |
644 | 642 |
645 void MediaSourceDelegate::DeleteSelf() { | 643 void MediaSourceDelegate::DeleteSelf() { |
646 DCHECK(main_loop_->BelongsToCurrentThread()); | 644 DCHECK(main_loop_->BelongsToCurrentThread()); |
647 DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; | 645 DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; |
648 chunk_demuxer_.reset(); | 646 chunk_demuxer_.reset(); |
649 delete this; | 647 delete this; |
650 } | 648 } |
651 | 649 |
652 void MediaSourceDelegate::OnMediaConfigRequest() { | |
653 DCHECK(media_loop_->BelongsToCurrentThread()); | |
654 DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; | |
655 if (CanNotifyDemuxerReady()) | |
656 NotifyDemuxerReady(); | |
657 } | |
658 | |
659 bool MediaSourceDelegate::CanNotifyDemuxerReady() { | 650 bool MediaSourceDelegate::CanNotifyDemuxerReady() { |
660 DCHECK(media_loop_->BelongsToCurrentThread()); | 651 DCHECK(media_loop_->BelongsToCurrentThread()); |
661 return is_demuxer_ready_; | 652 return is_demuxer_ready_; |
662 } | 653 } |
663 | 654 |
664 void MediaSourceDelegate::NotifyDemuxerReady() { | 655 void MediaSourceDelegate::NotifyDemuxerReady() { |
665 DCHECK(media_loop_->BelongsToCurrentThread()); | 656 DCHECK(media_loop_->BelongsToCurrentThread()); |
666 DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; | 657 DVLOG(1) << __FUNCTION__ << " : " << demuxer_client_id_; |
667 DCHECK(CanNotifyDemuxerReady()); | 658 DCHECK(CanNotifyDemuxerReady()); |
668 | 659 |
669 scoped_ptr<DemuxerConfigs> configs(new DemuxerConfigs()); | 660 scoped_ptr<DemuxerConfigs> configs(new DemuxerConfigs()); |
670 if (audio_stream_) { | 661 GetDemuxerConfigFromStream(configs.get(), true); |
671 media::AudioDecoderConfig config = audio_stream_->audio_decoder_config(); | 662 GetDemuxerConfigFromStream(configs.get(), false); |
672 configs->audio_codec = config.codec(); | |
673 configs->audio_channels = | |
674 media::ChannelLayoutToChannelCount(config.channel_layout()); | |
675 configs->audio_sampling_rate = config.samples_per_second(); | |
676 configs->is_audio_encrypted = config.is_encrypted(); | |
677 configs->audio_extra_data = std::vector<uint8>( | |
678 config.extra_data(), config.extra_data() + config.extra_data_size()); | |
679 } | |
680 if (video_stream_) { | |
681 media::VideoDecoderConfig config = video_stream_->video_decoder_config(); | |
682 configs->video_codec = config.codec(); | |
683 configs->video_size = config.natural_size(); | |
684 configs->is_video_encrypted = config.is_encrypted(); | |
685 configs->video_extra_data = std::vector<uint8>( | |
686 config.extra_data(), config.extra_data() + config.extra_data_size()); | |
687 } | |
688 configs->duration = GetDuration(); | 663 configs->duration = GetDuration(); |
689 | 664 |
690 if (demuxer_client_) | 665 if (demuxer_client_) |
691 demuxer_client_->DemuxerReady(demuxer_client_id_, *configs); | 666 demuxer_client_->DemuxerReady(demuxer_client_id_, *configs); |
692 | 667 |
693 base::AutoLock auto_lock(is_video_encrypted_lock_); | 668 base::AutoLock auto_lock(is_video_encrypted_lock_); |
694 is_video_encrypted_ = configs->is_video_encrypted; | 669 is_video_encrypted_ = configs->is_video_encrypted; |
695 } | 670 } |
696 | 671 |
697 base::TimeDelta MediaSourceDelegate::GetDuration() const { | 672 base::TimeDelta MediaSourceDelegate::GetDuration() const { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 // |seek_time|. While possible that such data at and beyond the player's | 738 // |seek_time|. While possible that such data at and beyond the player's |
764 // current time have been garbage collected or removed by the web app, this is | 739 // current time have been garbage collected or removed by the web app, this is |
765 // unlikely. This may cause unexpected playback stall due to seek pending an | 740 // unlikely. This may cause unexpected playback stall due to seek pending an |
766 // append for a GOP prior to the last GOP demuxed. | 741 // append for a GOP prior to the last GOP demuxed. |
767 // TODO(wolenetz): Remove the possibility for this seek to cause unexpected | 742 // TODO(wolenetz): Remove the possibility for this seek to cause unexpected |
768 // player stall by replaying cached data since last keyframe in browser player | 743 // player stall by replaying cached data since last keyframe in browser player |
769 // rather than issuing browser seek. See http://crbug.com/304234. | 744 // rather than issuing browser seek. See http://crbug.com/304234. |
770 return seek_time; | 745 return seek_time; |
771 } | 746 } |
772 | 747 |
748 bool MediaSourceDelegate::GetDemuxerConfigFromStream( | |
749 media::DemuxerConfigs* configs, bool is_audio) { | |
750 DCHECK(media_loop_->BelongsToCurrentThread()); | |
751 if (!CanNotifyDemuxerReady()) | |
752 return false; | |
753 if (is_audio && audio_stream_) { | |
754 media::AudioDecoderConfig config = audio_stream_->audio_decoder_config(); | |
755 configs->audio_codec = config.codec(); | |
756 configs->audio_channels = | |
757 media::ChannelLayoutToChannelCount(config.channel_layout()); | |
758 configs->audio_sampling_rate = config.samples_per_second(); | |
759 configs->is_audio_encrypted = config.is_encrypted(); | |
760 configs->audio_extra_data = std::vector<uint8>( | |
761 config.extra_data(), config.extra_data() + config.extra_data_size()); | |
762 return true; | |
763 } | |
764 if (!is_audio && video_stream_) { | |
765 media::VideoDecoderConfig config = video_stream_->video_decoder_config(); | |
766 configs->video_codec = config.codec(); | |
767 configs->video_size = config.natural_size(); | |
768 configs->is_video_encrypted = config.is_encrypted(); | |
769 configs->video_extra_data = std::vector<uint8>( | |
770 config.extra_data(), config.extra_data() + config.extra_data_size()); | |
771 return true; | |
772 } | |
773 return false; | |
774 } | |
775 | |
773 } // namespace content | 776 } // namespace content |
OLD | NEW |