| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/media_source_state.h" | 5 #include "media/filters/media_source_state.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/command_line.h" |
| 8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "media/base/media_switches.h" |
| 9 #include "media/base/media_track.h" | 12 #include "media/base/media_track.h" |
| 10 #include "media/base/media_tracks.h" | 13 #include "media/base/media_tracks.h" |
| 11 #include "media/filters/chunk_demuxer.h" | 14 #include "media/filters/chunk_demuxer.h" |
| 12 #include "media/filters/frame_processor.h" | 15 #include "media/filters/frame_processor.h" |
| 13 #include "media/filters/source_buffer_stream.h" | 16 #include "media/filters/source_buffer_stream.h" |
| 14 | 17 |
| 15 namespace media { | 18 namespace media { |
| 16 | 19 |
| 17 enum { | 20 enum { |
| 18 // Limits the number of MEDIA_LOG() calls warning the user that a muxed stream | 21 // Limits the number of MEDIA_LOG() calls warning the user that a muxed stream |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 if (audio_config.IsValidConfig()) { | 569 if (audio_config.IsValidConfig()) { |
| 567 if (!audio_) { | 570 if (!audio_) { |
| 568 media_log_->SetBooleanProperty("found_audio_stream", true); | 571 media_log_->SetBooleanProperty("found_audio_stream", true); |
| 569 } | 572 } |
| 570 if (!audio_ || | 573 if (!audio_ || |
| 571 audio_->audio_decoder_config().codec() != audio_config.codec()) { | 574 audio_->audio_decoder_config().codec() != audio_config.codec()) { |
| 572 media_log_->SetStringProperty("audio_codec_name", | 575 media_log_->SetStringProperty("audio_codec_name", |
| 573 GetCodecName(audio_config.codec())); | 576 GetCodecName(audio_config.codec())); |
| 574 } | 577 } |
| 575 | 578 |
| 579 bool audio_stream_just_created = false; |
| 576 if (!audio_) { | 580 if (!audio_) { |
| 577 audio_ = create_demuxer_stream_cb_.Run(DemuxerStream::AUDIO); | 581 audio_ = create_demuxer_stream_cb_.Run(DemuxerStream::AUDIO); |
| 578 | 582 |
| 579 if (!audio_) { | 583 if (!audio_) { |
| 580 DVLOG(1) << "Failed to create an audio stream."; | 584 DVLOG(1) << "Failed to create an audio stream."; |
| 581 return false; | 585 return false; |
| 582 } | 586 } |
| 587 audio_stream_just_created = true; |
| 583 | 588 |
| 584 if (!frame_processor_->AddTrack(FrameProcessor::kAudioTrackId, audio_)) { | 589 if (!frame_processor_->AddTrack(FrameProcessor::kAudioTrackId, audio_)) { |
| 585 DVLOG(1) << "Failed to add audio track to frame processor."; | 590 DVLOG(1) << "Failed to add audio track to frame processor."; |
| 586 return false; | 591 return false; |
| 587 } | 592 } |
| 588 } | 593 } |
| 589 | 594 |
| 590 frame_processor_->OnPossibleAudioConfigUpdate(audio_config); | 595 frame_processor_->OnPossibleAudioConfigUpdate(audio_config); |
| 591 success &= audio_->UpdateAudioConfig(audio_config, media_log_); | 596 success &= audio_->UpdateAudioConfig(audio_config, media_log_); |
| 597 |
| 598 if (audio_stream_just_created) { |
| 599 std::string audio_buf_limit_switch = |
| 600 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 601 switches::kMSEAudioBufferSizeLimit); |
| 602 unsigned audio_buf_size_limit = 0; |
| 603 if (base::StringToUint(audio_buf_limit_switch, &audio_buf_size_limit) && |
| 604 audio_buf_size_limit > 0) { |
| 605 MEDIA_LOG(INFO, media_log_) << "Custom audio SourceBuffer size limit=" |
| 606 << audio_buf_size_limit; |
| 607 audio_->SetStreamMemoryLimit(audio_buf_size_limit); |
| 608 } |
| 609 } |
| 592 } | 610 } |
| 593 | 611 |
| 594 if (video_config.IsValidConfig()) { | 612 if (video_config.IsValidConfig()) { |
| 595 if (!video_) { | 613 if (!video_) { |
| 596 media_log_->SetBooleanProperty("found_video_stream", true); | 614 media_log_->SetBooleanProperty("found_video_stream", true); |
| 597 } | 615 } |
| 598 if (!video_ || | 616 if (!video_ || |
| 599 video_->video_decoder_config().codec() != video_config.codec()) { | 617 video_->video_decoder_config().codec() != video_config.codec()) { |
| 600 media_log_->SetStringProperty("video_codec_name", | 618 media_log_->SetStringProperty("video_codec_name", |
| 601 GetCodecName(video_config.codec())); | 619 GetCodecName(video_config.codec())); |
| 602 } | 620 } |
| 603 | 621 |
| 622 bool video_stream_just_created = false; |
| 604 if (!video_) { | 623 if (!video_) { |
| 605 video_ = create_demuxer_stream_cb_.Run(DemuxerStream::VIDEO); | 624 video_ = create_demuxer_stream_cb_.Run(DemuxerStream::VIDEO); |
| 606 | 625 |
| 607 if (!video_) { | 626 if (!video_) { |
| 608 DVLOG(1) << "Failed to create a video stream."; | 627 DVLOG(1) << "Failed to create a video stream."; |
| 609 return false; | 628 return false; |
| 610 } | 629 } |
| 630 video_stream_just_created = true; |
| 611 | 631 |
| 612 if (!frame_processor_->AddTrack(FrameProcessor::kVideoTrackId, video_)) { | 632 if (!frame_processor_->AddTrack(FrameProcessor::kVideoTrackId, video_)) { |
| 613 DVLOG(1) << "Failed to add video track to frame processor."; | 633 DVLOG(1) << "Failed to add video track to frame processor."; |
| 614 return false; | 634 return false; |
| 615 } | 635 } |
| 616 } | 636 } |
| 617 | 637 |
| 618 success &= video_->UpdateVideoConfig(video_config, media_log_); | 638 success &= video_->UpdateVideoConfig(video_config, media_log_); |
| 639 |
| 640 if (video_stream_just_created) { |
| 641 std::string video_buf_limit_switch = |
| 642 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 643 switches::kMSEVideoBufferSizeLimit); |
| 644 unsigned video_buf_size_limit = 0; |
| 645 if (base::StringToUint(video_buf_limit_switch, &video_buf_size_limit) && |
| 646 video_buf_size_limit > 0) { |
| 647 MEDIA_LOG(INFO, media_log_) << "Custom video SourceBuffer size limit=" |
| 648 << video_buf_size_limit; |
| 649 video_->SetStreamMemoryLimit(video_buf_size_limit); |
| 650 } |
| 651 } |
| 619 } | 652 } |
| 620 | 653 |
| 621 typedef StreamParser::TextTrackConfigMap::const_iterator TextConfigItr; | 654 typedef StreamParser::TextTrackConfigMap::const_iterator TextConfigItr; |
| 622 if (text_stream_map_.empty()) { | 655 if (text_stream_map_.empty()) { |
| 623 for (TextConfigItr itr = text_configs.begin(); itr != text_configs.end(); | 656 for (TextConfigItr itr = text_configs.begin(); itr != text_configs.end(); |
| 624 ++itr) { | 657 ++itr) { |
| 625 ChunkDemuxerStream* const text_stream = | 658 ChunkDemuxerStream* const text_stream = |
| 626 create_demuxer_stream_cb_.Run(DemuxerStream::TEXT); | 659 create_demuxer_stream_cb_.Run(DemuxerStream::TEXT); |
| 627 if (!frame_processor_->AddTrack(itr->first, text_stream)) { | 660 if (!frame_processor_->AddTrack(itr->first, text_stream)) { |
| 628 success &= false; | 661 success &= false; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 825 |
| 793 void MediaSourceState::OnSourceInitDone( | 826 void MediaSourceState::OnSourceInitDone( |
| 794 const StreamParser::InitParameters& params) { | 827 const StreamParser::InitParameters& params) { |
| 795 DCHECK_EQ(state_, PENDING_PARSER_INIT); | 828 DCHECK_EQ(state_, PENDING_PARSER_INIT); |
| 796 state_ = PARSER_INITIALIZED; | 829 state_ = PARSER_INITIALIZED; |
| 797 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; | 830 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; |
| 798 base::ResetAndReturn(&init_cb_).Run(params); | 831 base::ResetAndReturn(&init_cb_).Run(params); |
| 799 } | 832 } |
| 800 | 833 |
| 801 } // namespace media | 834 } // namespace media |
| OLD | NEW |