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