| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 void MediaSourceState::SetGroupStartTimestampIfInSequenceMode( | 144 void MediaSourceState::SetGroupStartTimestampIfInSequenceMode( |
| 145 base::TimeDelta timestamp_offset) { | 145 base::TimeDelta timestamp_offset) { |
| 146 DCHECK(!parsing_media_segment_); | 146 DCHECK(!parsing_media_segment_); |
| 147 | 147 |
| 148 frame_processor_->SetGroupStartTimestampIfInSequenceMode(timestamp_offset); | 148 frame_processor_->SetGroupStartTimestampIfInSequenceMode(timestamp_offset); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void MediaSourceState::SetTracksWatcher( | 151 void MediaSourceState::SetTracksWatcher( |
| 152 const Demuxer::MediaTracksUpdatedCB& tracks_updated_cb) { | 152 const Demuxer::MediaTracksUpdatedCB& tracks_updated_cb) { |
| 153 DCHECK(init_segment_received_cb_.is_null()); | 153 DCHECK(init_segment_received_cb_.is_null()); |
| 154 DCHECK(!tracks_updated_cb.is_null()); |
| 154 init_segment_received_cb_ = tracks_updated_cb; | 155 init_segment_received_cb_ = tracks_updated_cb; |
| 155 DCHECK(!init_segment_received_cb_.is_null()); | |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool MediaSourceState::Append(const uint8_t* data, | 158 bool MediaSourceState::Append(const uint8_t* data, |
| 159 size_t length, | 159 size_t length, |
| 160 TimeDelta append_window_start, | 160 TimeDelta append_window_start, |
| 161 TimeDelta append_window_end, | 161 TimeDelta append_window_end, |
| 162 TimeDelta* timestamp_offset) { | 162 TimeDelta* timestamp_offset) { |
| 163 append_in_progress_ = true; | 163 append_in_progress_ = true; |
| 164 DCHECK(timestamp_offset); | 164 DCHECK(timestamp_offset); |
| 165 DCHECK(!timestamp_offset_during_append_); | 165 DCHECK(!timestamp_offset_during_append_); |
| (...skipping 307 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 std::unique_ptr<MediaTracks> tracks, | 479 std::unique_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 MediaTrack* audio_track = nullptr; |
| 485 const VideoDecoderConfig& video_config = media_tracks_->getFirstVideoConfig(); | 485 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->byteStreamTrackId()).IsValidConfig()) { |
| 491 audio_config = tracks->getAudioConfig(track->byteStreamTrackId()); |
| 492 audio_track = track.get(); |
| 493 } else if (!video_track && track->type() == MediaTrack::Video && |
| 494 tracks->getVideoConfig(track->byteStreamTrackId()) |
| 495 .IsValidConfig()) { |
| 496 video_config = tracks->getVideoConfig(track->byteStreamTrackId()); |
| 497 video_track = track.get(); |
| 498 } |
| 499 } |
| 486 | 500 |
| 487 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video << ", " | 501 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video << ", " |
| 488 << audio_config.IsValidConfig() << ", " | 502 << audio_config.IsValidConfig() << ", " |
| 489 << video_config.IsValidConfig() << ")"; | 503 << video_config.IsValidConfig() << ")"; |
| 490 // MSE spec allows new configs to be emitted only during Append, but not | 504 // MSE spec allows new configs to be emitted only during Append, but not |
| 491 // during Flush or parser reset operations. | 505 // during Flush or parser reset operations. |
| 492 CHECK(append_in_progress_); | 506 CHECK(append_in_progress_); |
| 493 | 507 |
| 494 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { | 508 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { |
| 495 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; | 509 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 << config_itr->first | 658 << config_itr->first |
| 645 << " does not match old one."; | 659 << " does not match old one."; |
| 646 break; | 660 break; |
| 647 } | 661 } |
| 648 } | 662 } |
| 649 } | 663 } |
| 650 } | 664 } |
| 651 | 665 |
| 652 frame_processor_->SetAllTrackBuffersNeedRandomAccessPoint(); | 666 frame_processor_->SetAllTrackBuffersNeedRandomAccessPoint(); |
| 653 | 667 |
| 668 if (audio_track) { |
| 669 DCHECK(audio_); |
| 670 audio_track->setId(audio_->media_track_id()); |
| 671 } |
| 672 if (video_track) { |
| 673 DCHECK(video_); |
| 674 video_track->setId(video_->media_track_id()); |
| 675 } |
| 676 |
| 654 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); | 677 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); |
| 655 if (success) { | 678 if (success) { |
| 656 if (state_ == PENDING_PARSER_CONFIG) | 679 if (state_ == PENDING_PARSER_CONFIG) |
| 657 state_ = PENDING_PARSER_INIT; | 680 state_ = PENDING_PARSER_INIT; |
| 658 DCHECK(!init_segment_received_cb_.is_null()); | 681 DCHECK(!init_segment_received_cb_.is_null()); |
| 659 init_segment_received_cb_.Run(std::move(media_tracks_)); | 682 init_segment_received_cb_.Run(std::move(tracks)); |
| 660 } | 683 } |
| 661 | 684 |
| 662 return success; | 685 return success; |
| 663 } | 686 } |
| 664 | 687 |
| 665 void MediaSourceState::OnNewMediaSegment() { | 688 void MediaSourceState::OnNewMediaSegment() { |
| 666 DVLOG(2) << "OnNewMediaSegment()"; | 689 DVLOG(2) << "OnNewMediaSegment()"; |
| 667 DCHECK_EQ(state_, PARSER_INITIALIZED); | 690 DCHECK_EQ(state_, PARSER_INITIALIZED); |
| 668 parsing_media_segment_ = true; | 691 parsing_media_segment_ = true; |
| 669 media_segment_contained_audio_frame_ = false; | 692 media_segment_contained_audio_frame_ = false; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 | 762 |
| 740 void MediaSourceState::OnSourceInitDone( | 763 void MediaSourceState::OnSourceInitDone( |
| 741 const StreamParser::InitParameters& params) { | 764 const StreamParser::InitParameters& params) { |
| 742 DCHECK_EQ(state_, PENDING_PARSER_INIT); | 765 DCHECK_EQ(state_, PENDING_PARSER_INIT); |
| 743 state_ = PARSER_INITIALIZED; | 766 state_ = PARSER_INITIALIZED; |
| 744 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; | 767 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; |
| 745 base::ResetAndReturn(&init_cb_).Run(params); | 768 base::ResetAndReturn(&init_cb_).Run(params); |
| 746 } | 769 } |
| 747 | 770 |
| 748 } // namespace media | 771 } // namespace media |
| OLD | NEW |