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