 Chromium Code Reviews
 Chromium Code Reviews Issue 2050043002:
  Generate and assign media track ids in demuxers.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@use-streamparser-trackid
    
  
    Issue 2050043002:
  Generate and assign media track ids in demuxers.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@use-streamparser-trackid| 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 // NOTE: We are intentionally not checking the text tracks | 466 // NOTE: We are intentionally not checking the text tracks | 
| 467 // because text tracks are discontinuous and may not have data | 467 // because text tracks are discontinuous and may not have data | 
| 468 // for the seek position. This is ok and playback should not be | 468 // for the seek position. This is ok and playback should not be | 
| 469 // stalled because we don't have cues. If cues, with timestamps after | 469 // stalled because we don't have cues. If cues, with timestamps after | 
| 470 // the seek time, eventually arrive they will be delivered properly | 470 // the seek time, eventually arrive they will be delivered properly | 
| 471 // in response to ChunkDemuxerStream::Read() calls. | 471 // in response to ChunkDemuxerStream::Read() calls. | 
| 472 | 472 | 
| 473 return false; | 473 return false; | 
| 474 } | 474 } | 
| 475 | 475 | 
| 476 bool MediaSourceState::OnNewConfigs( | 476 bool MediaSourceState::OnNewConfigs( | 
| 
xhwang
2016/06/10 17:06:54
nit: This function alone is >200 lines :) It'd be
 
servolk
2016/06/10 22:05:25
Agree, it looks like it should be relatively trivi
 | |
| 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 | 483 | 
| 484 media_tracks_ = std::move(tracks); | 484 MediaTrack* audio_track = nullptr; | 
| 485 const AudioDecoderConfig& audio_config = media_tracks_->getFirstAudioConfig(); | 485 MediaTrack* video_track = nullptr; | 
| 486 const VideoDecoderConfig& video_config = media_tracks_->getFirstVideoConfig(); | 486 AudioDecoderConfig audio_config; | 
| 487 VideoDecoderConfig video_config; | |
| 488 for (const auto& track : tracks->tracks()) { | |
| 
xhwang
2016/06/10 17:06:54
So if we have multiple audio (or video) tracks, we
 | |
| 489 const auto& track_id = track->bytestream_track_id(); | |
| 
xhwang
2016/06/10 17:06:54
nit: It's really hard to follow that whether a |tr
 | |
| 490 if (!audio_track && track->type() == MediaTrack::Audio && | |
| 491 tracks->getAudioConfig(track_id).IsValidConfig()) { | |
| 492 audio_config = tracks->getAudioConfig(track_id); | |
| 493 audio_track = track.get(); | |
| 494 } else if (!video_track && track->type() == MediaTrack::Video && | |
| 495 tracks->getVideoConfig(track_id).IsValidConfig()) { | |
| 496 video_config = tracks->getVideoConfig(track_id); | |
| 497 video_track = track.get(); | |
| 498 } | |
| 499 } | |
| 487 | 500 | 
| 488 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video << ", " | 501 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video << ", " | 
| 489 << audio_config.IsValidConfig() << ", " | 502 << audio_config.IsValidConfig() << ", " | 
| 490 << video_config.IsValidConfig() << ")"; | 503 << video_config.IsValidConfig() << ")"; | 
| 491 // 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 | 
| 492 // during Flush or parser reset operations. | 505 // during Flush or parser reset operations. | 
| 493 CHECK(append_in_progress_); | 506 CHECK(append_in_progress_); | 
| 494 | 507 | 
| 495 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { | 508 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { | 
| 496 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... | |
| 645 << config_itr->first | 658 << config_itr->first | 
| 646 << " does not match old one."; | 659 << " does not match old one."; | 
| 647 break; | 660 break; | 
| 648 } | 661 } | 
| 649 } | 662 } | 
| 650 } | 663 } | 
| 651 } | 664 } | 
| 652 | 665 | 
| 653 frame_processor_->SetAllTrackBuffersNeedRandomAccessPoint(); | 666 frame_processor_->SetAllTrackBuffersNeedRandomAccessPoint(); | 
| 654 | 667 | 
| 668 if (audio_track) { | |
| 669 DCHECK(audio_); | |
| 670 audio_track->set_id(audio_->media_track_id()); | |
| 671 } | |
| 672 if (video_track) { | |
| 673 DCHECK(video_); | |
| 674 video_track->set_id(video_->media_track_id()); | |
| 675 } | |
| 676 | |
| 655 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); | 677 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); | 
| 656 if (success) { | 678 if (success) { | 
| 657 if (state_ == PENDING_PARSER_CONFIG) | 679 if (state_ == PENDING_PARSER_CONFIG) | 
| 658 state_ = PENDING_PARSER_INIT; | 680 state_ = PENDING_PARSER_INIT; | 
| 659 DCHECK(!init_segment_received_cb_.is_null()); | 681 DCHECK(!init_segment_received_cb_.is_null()); | 
| 660 init_segment_received_cb_.Run(std::move(media_tracks_)); | 682 init_segment_received_cb_.Run(std::move(tracks)); | 
| 661 } | 683 } | 
| 662 | 684 | 
| 663 return success; | 685 return success; | 
| 664 } | 686 } | 
| 665 | 687 | 
| 666 void MediaSourceState::OnNewMediaSegment() { | 688 void MediaSourceState::OnNewMediaSegment() { | 
| 667 DVLOG(2) << "OnNewMediaSegment()"; | 689 DVLOG(2) << "OnNewMediaSegment()"; | 
| 668 DCHECK_EQ(state_, PARSER_INITIALIZED); | 690 DCHECK_EQ(state_, PARSER_INITIALIZED); | 
| 669 parsing_media_segment_ = true; | 691 parsing_media_segment_ = true; | 
| 670 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... | |
| 740 | 762 | 
| 741 void MediaSourceState::OnSourceInitDone( | 763 void MediaSourceState::OnSourceInitDone( | 
| 742 const StreamParser::InitParameters& params) { | 764 const StreamParser::InitParameters& params) { | 
| 743 DCHECK_EQ(state_, PENDING_PARSER_INIT); | 765 DCHECK_EQ(state_, PENDING_PARSER_INIT); | 
| 744 state_ = PARSER_INITIALIZED; | 766 state_ = PARSER_INITIALIZED; | 
| 745 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; | 767 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; | 
| 746 base::ResetAndReturn(&init_cb_).Run(params); | 768 base::ResetAndReturn(&init_cb_).Run(params); | 
| 747 } | 769 } | 
| 748 | 770 | 
| 749 } // namespace media | 771 } // namespace media | 
| OLD | NEW |