OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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/base/media_tracks.h" | 5 #include "media/base/media_tracks.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "media/base/audio_decoder_config.h" | 8 #include "media/base/audio_decoder_config.h" |
9 #include "media/base/video_decoder_config.h" | 9 #include "media/base/video_decoder_config.h" |
10 | 10 |
11 namespace media { | 11 namespace media { |
12 | 12 |
13 MediaTracks::MediaTracks() {} | 13 MediaTracks::MediaTracks() {} |
14 | 14 |
15 MediaTracks::~MediaTracks() {} | 15 MediaTracks::~MediaTracks() {} |
16 | 16 |
17 void MediaTracks::AddAudioTrack(const AudioDecoderConfig& config, | 17 const MediaTrack* MediaTracks::AddAudioTrack(const AudioDecoderConfig& config, |
18 const std::string& id, | 18 const std::string& id, |
19 const std::string& kind, | 19 const std::string& kind, |
20 const std::string& label, | 20 const std::string& label, |
21 const std::string& language) { | 21 const std::string& language) { |
22 DCHECK(config.IsValidConfig()); | 22 DCHECK(config.IsValidConfig()); |
23 CHECK(audio_configs_.find(id) == audio_configs_.end()); | 23 CHECK(audio_configs_.find(id) == audio_configs_.end()); |
24 scoped_ptr<MediaTrack> track = make_scoped_ptr( | 24 scoped_ptr<MediaTrack> track = make_scoped_ptr( |
25 new MediaTrack(MediaTrack::Audio, id, kind, label, language)); | 25 new MediaTrack(MediaTrack::Audio, id, kind, label, language)); |
26 tracks_.push_back(std::move(track)); | 26 tracks_.push_back(std::move(track)); |
27 audio_configs_[id] = config; | 27 audio_configs_[id] = config; |
| 28 return tracks_.back().get(); |
28 } | 29 } |
29 | 30 |
30 void MediaTracks::AddVideoTrack(const VideoDecoderConfig& config, | 31 const MediaTrack* MediaTracks::AddVideoTrack(const VideoDecoderConfig& config, |
31 const std::string& id, | 32 const std::string& id, |
32 const std::string& kind, | 33 const std::string& kind, |
33 const std::string& label, | 34 const std::string& label, |
34 const std::string& language) { | 35 const std::string& language) { |
35 DCHECK(config.IsValidConfig()); | 36 DCHECK(config.IsValidConfig()); |
36 CHECK(video_configs_.find(id) == video_configs_.end()); | 37 CHECK(video_configs_.find(id) == video_configs_.end()); |
37 scoped_ptr<MediaTrack> track = make_scoped_ptr( | 38 scoped_ptr<MediaTrack> track = make_scoped_ptr( |
38 new MediaTrack(MediaTrack::Video, id, kind, label, language)); | 39 new MediaTrack(MediaTrack::Video, id, kind, label, language)); |
39 tracks_.push_back(std::move(track)); | 40 tracks_.push_back(std::move(track)); |
40 video_configs_[id] = config; | 41 video_configs_[id] = config; |
| 42 return tracks_.back().get(); |
| 43 } |
| 44 |
| 45 void MediaTracks::SetDemuxerStreamForMediaTrack(const MediaTrack* track, |
| 46 const DemuxerStream* stream) { |
| 47 DCHECK(track_to_demux_stream_map_.find(track) == |
| 48 track_to_demux_stream_map_.end()); |
| 49 |
| 50 bool track_found = false; |
| 51 for (const auto& t : tracks_) { |
| 52 if (t.get() == track) { |
| 53 track_found = true; |
| 54 break; |
| 55 } |
| 56 } |
| 57 CHECK(track_found); |
| 58 |
| 59 track_to_demux_stream_map_[track] = stream; |
| 60 } |
| 61 |
| 62 MediaTracks::TrackIdToDemuxStreamMap MediaTracks::OnTrackIdsAssigned( |
| 63 const std::vector<unsigned>& track_ids) const { |
| 64 TrackIdToDemuxStreamMap result; |
| 65 CHECK_EQ(tracks().size(), track_ids.size()); |
| 66 CHECK_EQ(track_to_demux_stream_map_.size(), tracks().size()); |
| 67 for (size_t i = 0; i < track_ids.size(); ++i) { |
| 68 const MediaTrack* track = tracks()[i].get(); |
| 69 DCHECK(track); |
| 70 const auto& it = track_to_demux_stream_map_.find(track); |
| 71 CHECK(it != track_to_demux_stream_map_.end()); |
| 72 DVLOG(3) << "OnTrackIdsAssigned track_id=" << track_ids[i] |
| 73 << " DemuxerStream=" << it->second; |
| 74 result[track_ids[i]] = it->second; |
| 75 } |
| 76 return result; |
41 } | 77 } |
42 | 78 |
43 const AudioDecoderConfig& MediaTracks::getAudioConfig( | 79 const AudioDecoderConfig& MediaTracks::getAudioConfig( |
44 const std::string& id) const { | 80 const std::string& id) const { |
45 auto it = audio_configs_.find(id); | 81 auto it = audio_configs_.find(id); |
46 if (it != audio_configs_.end()) | 82 if (it != audio_configs_.end()) |
47 return it->second; | 83 return it->second; |
48 static AudioDecoderConfig invalidConfig; | 84 static AudioDecoderConfig invalidConfig; |
49 return invalidConfig; | 85 return invalidConfig; |
50 } | 86 } |
(...skipping 21 matching lines...) Expand all Loading... |
72 for (const auto& track : tracks()) { | 108 for (const auto& track : tracks()) { |
73 if (track->type() == MediaTrack::Video) { | 109 if (track->type() == MediaTrack::Video) { |
74 return getVideoConfig(track->id()); | 110 return getVideoConfig(track->id()); |
75 } | 111 } |
76 } | 112 } |
77 static VideoDecoderConfig invalidConfig; | 113 static VideoDecoderConfig invalidConfig; |
78 return invalidConfig; | 114 return invalidConfig; |
79 } | 115 } |
80 | 116 |
81 } // namespace media | 117 } // namespace media |
OLD | NEW |