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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 return false; | 470 return false; |
471 } | 471 } |
472 | 472 |
473 bool MediaSourceState::OnNewConfigs( | 473 bool MediaSourceState::OnNewConfigs( |
474 bool allow_audio, | 474 bool allow_audio, |
475 bool allow_video, | 475 bool allow_video, |
476 scoped_ptr<MediaTracks> tracks, | 476 scoped_ptr<MediaTracks> tracks, |
477 const StreamParser::TextTrackConfigMap& text_configs) { | 477 const StreamParser::TextTrackConfigMap& text_configs) { |
478 DCHECK(tracks.get()); | 478 DCHECK(tracks.get()); |
479 media_tracks_ = std::move(tracks); | 479 media_tracks_ = std::move(tracks); |
480 const AudioDecoderConfig& audio_config = media_tracks_->getFirstAudioConfig(); | 480 |
481 const VideoDecoderConfig& video_config = media_tracks_->getFirstVideoConfig(); | 481 const MediaTrack* audio_track = nullptr; |
| 482 const MediaTrack* video_track = nullptr; |
| 483 AudioDecoderConfig audio_config; |
| 484 VideoDecoderConfig video_config; |
| 485 for (const auto& track : media_tracks_->tracks()) { |
| 486 if (!audio_track && track->type() == MediaTrack::Audio && |
| 487 media_tracks_->getAudioConfig(track->id()).IsValidConfig()) { |
| 488 audio_config = media_tracks_->getAudioConfig(track->id()); |
| 489 audio_track = track.get(); |
| 490 } else if (!video_track && track->type() == MediaTrack::Video && |
| 491 media_tracks_->getVideoConfig(track->id()).IsValidConfig()) { |
| 492 video_config = media_tracks_->getVideoConfig(track->id()); |
| 493 video_track = track.get(); |
| 494 } |
| 495 } |
482 | 496 |
483 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video << ", " | 497 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video << ", " |
484 << audio_config.IsValidConfig() << ", " | 498 << audio_config.IsValidConfig() << ", " |
485 << video_config.IsValidConfig() << ")"; | 499 << video_config.IsValidConfig() << ")"; |
486 // MSE spec allows new configs to be emitted only during Append, but not | 500 // MSE spec allows new configs to be emitted only during Append, but not |
487 // during Flush or parser reset operations. | 501 // during Flush or parser reset operations. |
488 CHECK(append_in_progress_); | 502 CHECK(append_in_progress_); |
489 | 503 |
490 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { | 504 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { |
491 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; | 505 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; |
(...skipping 27 matching lines...) Expand all Loading... |
519 if (!audio_) { | 533 if (!audio_) { |
520 media_log_->SetBooleanProperty("found_audio_stream", true); | 534 media_log_->SetBooleanProperty("found_audio_stream", true); |
521 } | 535 } |
522 if (!audio_ || | 536 if (!audio_ || |
523 audio_->audio_decoder_config().codec() != audio_config.codec()) { | 537 audio_->audio_decoder_config().codec() != audio_config.codec()) { |
524 media_log_->SetStringProperty("audio_codec_name", | 538 media_log_->SetStringProperty("audio_codec_name", |
525 GetCodecName(audio_config.codec())); | 539 GetCodecName(audio_config.codec())); |
526 } | 540 } |
527 | 541 |
528 if (!audio_) { | 542 if (!audio_) { |
529 audio_ = create_demuxer_stream_cb_.Run(DemuxerStream::AUDIO); | 543 DCHECK(audio_track); |
| 544 audio_ = create_demuxer_stream_cb_.Run(*audio_track); |
530 | 545 |
531 if (!audio_) { | 546 if (!audio_) { |
532 DVLOG(1) << "Failed to create an audio stream."; | 547 DVLOG(1) << "Failed to create an audio stream."; |
533 return false; | 548 return false; |
534 } | 549 } |
535 | 550 |
536 if (!frame_processor_->AddTrack(FrameProcessor::kAudioTrackId, audio_)) { | 551 if (!frame_processor_->AddTrack(FrameProcessor::kAudioTrackId, audio_)) { |
537 DVLOG(1) << "Failed to add audio track to frame processor."; | 552 DVLOG(1) << "Failed to add audio track to frame processor."; |
538 return false; | 553 return false; |
539 } | 554 } |
540 } | 555 } |
541 | 556 |
542 frame_processor_->OnPossibleAudioConfigUpdate(audio_config); | 557 frame_processor_->OnPossibleAudioConfigUpdate(audio_config); |
543 success &= audio_->UpdateAudioConfig(audio_config, media_log_); | 558 success &= audio_->UpdateAudioConfig(audio_config, media_log_); |
544 } | 559 } |
545 | 560 |
546 if (video_config.IsValidConfig()) { | 561 if (video_config.IsValidConfig()) { |
547 if (!video_) { | 562 if (!video_) { |
548 media_log_->SetBooleanProperty("found_video_stream", true); | 563 media_log_->SetBooleanProperty("found_video_stream", true); |
549 } | 564 } |
550 if (!video_ || | 565 if (!video_ || |
551 video_->video_decoder_config().codec() != video_config.codec()) { | 566 video_->video_decoder_config().codec() != video_config.codec()) { |
552 media_log_->SetStringProperty("video_codec_name", | 567 media_log_->SetStringProperty("video_codec_name", |
553 GetCodecName(video_config.codec())); | 568 GetCodecName(video_config.codec())); |
554 } | 569 } |
555 | 570 |
556 if (!video_) { | 571 if (!video_) { |
557 video_ = create_demuxer_stream_cb_.Run(DemuxerStream::VIDEO); | 572 DCHECK(video_track); |
| 573 video_ = create_demuxer_stream_cb_.Run(*video_track); |
558 | 574 |
559 if (!video_) { | 575 if (!video_) { |
560 DVLOG(1) << "Failed to create a video stream."; | 576 DVLOG(1) << "Failed to create a video stream."; |
561 return false; | 577 return false; |
562 } | 578 } |
563 | 579 |
564 if (!frame_processor_->AddTrack(FrameProcessor::kVideoTrackId, video_)) { | 580 if (!frame_processor_->AddTrack(FrameProcessor::kVideoTrackId, video_)) { |
565 DVLOG(1) << "Failed to add video track to frame processor."; | 581 DVLOG(1) << "Failed to add video track to frame processor."; |
566 return false; | 582 return false; |
567 } | 583 } |
568 } | 584 } |
569 | 585 |
570 success &= video_->UpdateVideoConfig(video_config, media_log_); | 586 success &= video_->UpdateVideoConfig(video_config, media_log_); |
571 } | 587 } |
572 | 588 |
573 typedef StreamParser::TextTrackConfigMap::const_iterator TextConfigItr; | 589 typedef StreamParser::TextTrackConfigMap::const_iterator TextConfigItr; |
574 if (text_stream_map_.empty()) { | 590 if (text_stream_map_.empty()) { |
575 for (TextConfigItr itr = text_configs.begin(); itr != text_configs.end(); | 591 for (TextConfigItr itr = text_configs.begin(); itr != text_configs.end(); |
576 ++itr) { | 592 ++itr) { |
| 593 // TODO(servolk): Look into unifying text tracks code path with audio and |
| 594 // video track code paths. |
| 595 MediaTrack dummy_text_track(MediaTrack::Text, "", "", "", ""); |
577 ChunkDemuxerStream* const text_stream = | 596 ChunkDemuxerStream* const text_stream = |
578 create_demuxer_stream_cb_.Run(DemuxerStream::TEXT); | 597 create_demuxer_stream_cb_.Run(dummy_text_track); |
579 if (!frame_processor_->AddTrack(itr->first, text_stream)) { | 598 if (!frame_processor_->AddTrack(itr->first, text_stream)) { |
580 success &= false; | 599 success &= false; |
581 MEDIA_LOG(ERROR, media_log_) << "Failed to add text track ID " | 600 MEDIA_LOG(ERROR, media_log_) << "Failed to add text track ID " |
582 << itr->first << " to frame processor."; | 601 << itr->first << " to frame processor."; |
583 break; | 602 break; |
584 } | 603 } |
585 text_stream->UpdateTextConfig(itr->second, media_log_); | 604 text_stream->UpdateTextConfig(itr->second, media_log_); |
586 text_stream_map_[itr->first] = text_stream; | 605 text_stream_map_[itr->first] = text_stream; |
587 new_text_track_cb_.Run(text_stream, itr->second); | 606 new_text_track_cb_.Run(text_stream, itr->second); |
588 } | 607 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 return true; | 747 return true; |
729 } | 748 } |
730 | 749 |
731 void MediaSourceState::OnSourceInitDone( | 750 void MediaSourceState::OnSourceInitDone( |
732 const StreamParser::InitParameters& params) { | 751 const StreamParser::InitParameters& params) { |
733 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; | 752 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; |
734 base::ResetAndReturn(&init_cb_).Run(params); | 753 base::ResetAndReturn(&init_cb_).Run(params); |
735 } | 754 } |
736 | 755 |
737 } // namespace media | 756 } // namespace media |
OLD | NEW |