| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "media/base/media_track.h" | 9 #include "media/base/media_track.h" |
| 10 #include "media/base/media_tracks.h" | 10 #include "media/base/media_tracks.h" |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 } | 474 } |
| 475 | 475 |
| 476 bool MediaSourceState::OnNewConfigs( | 476 bool MediaSourceState::OnNewConfigs( |
| 477 bool allow_audio, | 477 bool allow_audio, |
| 478 bool allow_video, | 478 bool allow_video, |
| 479 scoped_ptr<MediaTracks> tracks, | 479 scoped_ptr<MediaTracks> tracks, |
| 480 const StreamParser::TextTrackConfigMap& text_configs) { | 480 const StreamParser::TextTrackConfigMap& text_configs) { |
| 481 DCHECK_GE(state_, PENDING_PARSER_CONFIG); | 481 DCHECK_GE(state_, PENDING_PARSER_CONFIG); |
| 482 DCHECK(tracks.get()); | 482 DCHECK(tracks.get()); |
| 483 media_tracks_ = std::move(tracks); | 483 media_tracks_ = std::move(tracks); |
| 484 const AudioDecoderConfig& audio_config = media_tracks_->getFirstAudioConfig(); | 484 |
| 485 const VideoDecoderConfig& video_config = media_tracks_->getFirstVideoConfig(); | 485 MediaTracks::TrackToDemuxStreamMap track_to_demux_stream_map; |
| 486 const MediaTrack* audio_track = nullptr; |
| 487 const MediaTrack* video_track = nullptr; |
| 488 AudioDecoderConfig audio_config; |
| 489 VideoDecoderConfig video_config; |
| 490 for (const auto& track : media_tracks_->tracks()) { |
| 491 if (!audio_track && track->type() == MediaTrack::Audio && |
| 492 media_tracks_->getAudioConfig(track->id()).IsValidConfig()) { |
| 493 audio_config = media_tracks_->getAudioConfig(track->id()); |
| 494 audio_track = track.get(); |
| 495 } else if (!video_track && track->type() == MediaTrack::Video && |
| 496 media_tracks_->getVideoConfig(track->id()).IsValidConfig()) { |
| 497 video_config = media_tracks_->getVideoConfig(track->id()); |
| 498 video_track = track.get(); |
| 499 } |
| 500 } |
| 486 | 501 |
| 487 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video << ", " | 502 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video << ", " |
| 488 << audio_config.IsValidConfig() << ", " | 503 << audio_config.IsValidConfig() << ", " |
| 489 << video_config.IsValidConfig() << ")"; | 504 << video_config.IsValidConfig() << ")"; |
| 490 // MSE spec allows new configs to be emitted only during Append, but not | 505 // MSE spec allows new configs to be emitted only during Append, but not |
| 491 // during Flush or parser reset operations. | 506 // during Flush or parser reset operations. |
| 492 CHECK(append_in_progress_); | 507 CHECK(append_in_progress_); |
| 493 | 508 |
| 494 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { | 509 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { |
| 495 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; | 510 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 523 if (!audio_) { | 538 if (!audio_) { |
| 524 media_log_->SetBooleanProperty("found_audio_stream", true); | 539 media_log_->SetBooleanProperty("found_audio_stream", true); |
| 525 } | 540 } |
| 526 if (!audio_ || | 541 if (!audio_ || |
| 527 audio_->audio_decoder_config().codec() != audio_config.codec()) { | 542 audio_->audio_decoder_config().codec() != audio_config.codec()) { |
| 528 media_log_->SetStringProperty("audio_codec_name", | 543 media_log_->SetStringProperty("audio_codec_name", |
| 529 GetCodecName(audio_config.codec())); | 544 GetCodecName(audio_config.codec())); |
| 530 } | 545 } |
| 531 | 546 |
| 532 if (!audio_) { | 547 if (!audio_) { |
| 533 audio_ = create_demuxer_stream_cb_.Run(DemuxerStream::AUDIO); | 548 DCHECK(audio_track); |
| 549 audio_ = create_demuxer_stream_cb_.Run(*audio_track); |
| 534 | 550 |
| 535 if (!audio_) { | 551 if (!audio_) { |
| 536 DVLOG(1) << "Failed to create an audio stream."; | 552 DVLOG(1) << "Failed to create an audio stream."; |
| 537 return false; | 553 return false; |
| 538 } | 554 } |
| 539 | 555 |
| 540 if (!frame_processor_->AddTrack(FrameProcessor::kAudioTrackId, audio_)) { | 556 if (!frame_processor_->AddTrack(FrameProcessor::kAudioTrackId, audio_)) { |
| 541 DVLOG(1) << "Failed to add audio track to frame processor."; | 557 DVLOG(1) << "Failed to add audio track to frame processor."; |
| 542 return false; | 558 return false; |
| 543 } | 559 } |
| 544 } | 560 } |
| 545 | 561 |
| 546 frame_processor_->OnPossibleAudioConfigUpdate(audio_config); | 562 frame_processor_->OnPossibleAudioConfigUpdate(audio_config); |
| 547 success &= audio_->UpdateAudioConfig(audio_config, media_log_); | 563 success &= audio_->UpdateAudioConfig(audio_config, media_log_); |
| 548 } | 564 } |
| 549 | 565 |
| 550 if (video_config.IsValidConfig()) { | 566 if (video_config.IsValidConfig()) { |
| 551 if (!video_) { | 567 if (!video_) { |
| 552 media_log_->SetBooleanProperty("found_video_stream", true); | 568 media_log_->SetBooleanProperty("found_video_stream", true); |
| 553 } | 569 } |
| 554 if (!video_ || | 570 if (!video_ || |
| 555 video_->video_decoder_config().codec() != video_config.codec()) { | 571 video_->video_decoder_config().codec() != video_config.codec()) { |
| 556 media_log_->SetStringProperty("video_codec_name", | 572 media_log_->SetStringProperty("video_codec_name", |
| 557 GetCodecName(video_config.codec())); | 573 GetCodecName(video_config.codec())); |
| 558 } | 574 } |
| 559 | 575 |
| 560 if (!video_) { | 576 if (!video_) { |
| 561 video_ = create_demuxer_stream_cb_.Run(DemuxerStream::VIDEO); | 577 DCHECK(video_track); |
| 578 video_ = create_demuxer_stream_cb_.Run(*video_track); |
| 562 | 579 |
| 563 if (!video_) { | 580 if (!video_) { |
| 564 DVLOG(1) << "Failed to create a video stream."; | 581 DVLOG(1) << "Failed to create a video stream."; |
| 565 return false; | 582 return false; |
| 566 } | 583 } |
| 567 | 584 |
| 568 if (!frame_processor_->AddTrack(FrameProcessor::kVideoTrackId, video_)) { | 585 if (!frame_processor_->AddTrack(FrameProcessor::kVideoTrackId, video_)) { |
| 569 DVLOG(1) << "Failed to add video track to frame processor."; | 586 DVLOG(1) << "Failed to add video track to frame processor."; |
| 570 return false; | 587 return false; |
| 571 } | 588 } |
| 572 } | 589 } |
| 573 | 590 |
| 574 success &= video_->UpdateVideoConfig(video_config, media_log_); | 591 success &= video_->UpdateVideoConfig(video_config, media_log_); |
| 575 } | 592 } |
| 576 | 593 |
| 577 typedef StreamParser::TextTrackConfigMap::const_iterator TextConfigItr; | 594 typedef StreamParser::TextTrackConfigMap::const_iterator TextConfigItr; |
| 578 if (text_stream_map_.empty()) { | 595 if (text_stream_map_.empty()) { |
| 579 for (TextConfigItr itr = text_configs.begin(); itr != text_configs.end(); | 596 for (TextConfigItr itr = text_configs.begin(); itr != text_configs.end(); |
| 580 ++itr) { | 597 ++itr) { |
| 598 // TODO(servolk): Look into unifying text tracks code path with audio and |
| 599 // video track code paths. |
| 600 MediaTrack dummy_text_track(MediaTrack::Text, "", "", "", ""); |
| 581 ChunkDemuxerStream* const text_stream = | 601 ChunkDemuxerStream* const text_stream = |
| 582 create_demuxer_stream_cb_.Run(DemuxerStream::TEXT); | 602 create_demuxer_stream_cb_.Run(dummy_text_track); |
| 583 if (!frame_processor_->AddTrack(itr->first, text_stream)) { | 603 if (!frame_processor_->AddTrack(itr->first, text_stream)) { |
| 584 success &= false; | 604 success &= false; |
| 585 MEDIA_LOG(ERROR, media_log_) << "Failed to add text track ID " | 605 MEDIA_LOG(ERROR, media_log_) << "Failed to add text track ID " |
| 586 << itr->first << " to frame processor."; | 606 << itr->first << " to frame processor."; |
| 587 break; | 607 break; |
| 588 } | 608 } |
| 589 text_stream->UpdateTextConfig(itr->second, media_log_); | 609 text_stream->UpdateTextConfig(itr->second, media_log_); |
| 590 text_stream_map_[itr->first] = text_stream; | 610 text_stream_map_[itr->first] = text_stream; |
| 591 new_text_track_cb_.Run(text_stream, itr->second); | 611 new_text_track_cb_.Run(text_stream, itr->second); |
| 592 } | 612 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 << config_itr->first | 664 << config_itr->first |
| 645 << " does not match old one."; | 665 << " does not match old one."; |
| 646 break; | 666 break; |
| 647 } | 667 } |
| 648 } | 668 } |
| 649 } | 669 } |
| 650 } | 670 } |
| 651 | 671 |
| 652 frame_processor_->SetAllTrackBuffersNeedRandomAccessPoint(); | 672 frame_processor_->SetAllTrackBuffersNeedRandomAccessPoint(); |
| 653 | 673 |
| 674 if (audio_track) { |
| 675 DCHECK(audio_); |
| 676 track_to_demux_stream_map[audio_track] = audio_; |
| 677 } |
| 678 if (video_track) { |
| 679 DCHECK(video_); |
| 680 track_to_demux_stream_map[video_track] = video_; |
| 681 } |
| 682 media_tracks_->set_track_to_demux_stream_map(track_to_demux_stream_map); |
| 683 |
| 654 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); | 684 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); |
| 655 if (success) { | 685 if (success) { |
| 656 if (state_ == PENDING_PARSER_CONFIG) | 686 if (state_ == PENDING_PARSER_CONFIG) |
| 657 state_ = PENDING_PARSER_INIT; | 687 state_ = PENDING_PARSER_INIT; |
| 658 DCHECK(!init_segment_received_cb_.is_null()); | 688 DCHECK(!init_segment_received_cb_.is_null()); |
| 659 init_segment_received_cb_.Run(std::move(media_tracks_)); | 689 init_segment_received_cb_.Run(std::move(media_tracks_)); |
| 660 } | 690 } |
| 661 | 691 |
| 662 return success; | 692 return success; |
| 663 } | 693 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 | 769 |
| 740 void MediaSourceState::OnSourceInitDone( | 770 void MediaSourceState::OnSourceInitDone( |
| 741 const StreamParser::InitParameters& params) { | 771 const StreamParser::InitParameters& params) { |
| 742 DCHECK_EQ(state_, PENDING_PARSER_INIT); | 772 DCHECK_EQ(state_, PENDING_PARSER_INIT); |
| 743 state_ = PARSER_INITIALIZED; | 773 state_ = PARSER_INITIALIZED; |
| 744 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; | 774 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; |
| 745 base::ResetAndReturn(&init_cb_).Run(params); | 775 base::ResetAndReturn(&init_cb_).Run(params); |
| 746 } | 776 } |
| 747 | 777 |
| 748 } // namespace media | 778 } // namespace media |
| OLD | NEW |