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 "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "media/base/audio_decoder_config.h" | 9 #include "media/base/audio_decoder_config.h" |
10 #include "media/base/video_decoder_config.h" | 10 #include "media/base/video_decoder_config.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 | 13 |
14 MediaTracks::MediaTracks() {} | 14 MediaTracks::MediaTracks() {} |
15 | 15 |
16 MediaTracks::~MediaTracks() {} | 16 MediaTracks::~MediaTracks() {} |
17 | 17 |
18 void MediaTracks::AddAudioTrack(const AudioDecoderConfig& config, | 18 MediaTrack* MediaTracks::AddAudioTrack( |
19 StreamParser::TrackId bytestream_track_id, | 19 const AudioDecoderConfig& config, |
20 const std::string& kind, | 20 StreamParser::TrackId bytestream_track_id, |
21 const std::string& label, | 21 const std::string& kind, |
22 const std::string& language) { | 22 const std::string& label, |
| 23 const std::string& language) { |
23 DCHECK(config.IsValidConfig()); | 24 DCHECK(config.IsValidConfig()); |
24 CHECK(audio_configs_.find(bytestream_track_id) == audio_configs_.end()); | 25 CHECK(audio_configs_.find(bytestream_track_id) == audio_configs_.end()); |
25 std::unique_ptr<MediaTrack> track = base::WrapUnique(new MediaTrack( | 26 std::unique_ptr<MediaTrack> track = base::WrapUnique(new MediaTrack( |
26 MediaTrack::Audio, bytestream_track_id, kind, label, language)); | 27 MediaTrack::Audio, bytestream_track_id, kind, label, language)); |
| 28 MediaTrack* track_ptr = track.get(); |
27 tracks_.push_back(std::move(track)); | 29 tracks_.push_back(std::move(track)); |
28 audio_configs_[bytestream_track_id] = config; | 30 audio_configs_[bytestream_track_id] = config; |
| 31 return track_ptr; |
29 } | 32 } |
30 | 33 |
31 void MediaTracks::AddVideoTrack(const VideoDecoderConfig& config, | 34 MediaTrack* MediaTracks::AddVideoTrack( |
32 StreamParser::TrackId bytestream_track_id, | 35 const VideoDecoderConfig& config, |
33 const std::string& kind, | 36 StreamParser::TrackId bytestream_track_id, |
34 const std::string& label, | 37 const std::string& kind, |
35 const std::string& language) { | 38 const std::string& label, |
| 39 const std::string& language) { |
36 DCHECK(config.IsValidConfig()); | 40 DCHECK(config.IsValidConfig()); |
37 CHECK(video_configs_.find(bytestream_track_id) == video_configs_.end()); | 41 CHECK(video_configs_.find(bytestream_track_id) == video_configs_.end()); |
38 std::unique_ptr<MediaTrack> track = base::WrapUnique(new MediaTrack( | 42 std::unique_ptr<MediaTrack> track = base::WrapUnique(new MediaTrack( |
39 MediaTrack::Video, bytestream_track_id, kind, label, language)); | 43 MediaTrack::Video, bytestream_track_id, kind, label, language)); |
| 44 MediaTrack* track_ptr = track.get(); |
40 tracks_.push_back(std::move(track)); | 45 tracks_.push_back(std::move(track)); |
41 video_configs_[bytestream_track_id] = config; | 46 video_configs_[bytestream_track_id] = config; |
| 47 return track_ptr; |
42 } | 48 } |
43 | 49 |
44 const AudioDecoderConfig& MediaTracks::getAudioConfig( | 50 const AudioDecoderConfig& MediaTracks::getAudioConfig( |
45 StreamParser::TrackId bytestream_track_id) const { | 51 StreamParser::TrackId bytestream_track_id) const { |
46 auto it = audio_configs_.find(bytestream_track_id); | 52 auto it = audio_configs_.find(bytestream_track_id); |
47 if (it != audio_configs_.end()) | 53 if (it != audio_configs_.end()) |
48 return it->second; | 54 return it->second; |
49 static AudioDecoderConfig invalidConfig; | 55 static AudioDecoderConfig invalidConfig; |
50 return invalidConfig; | 56 return invalidConfig; |
51 } | 57 } |
(...skipping 21 matching lines...) Expand all Loading... |
73 for (const auto& track : tracks()) { | 79 for (const auto& track : tracks()) { |
74 if (track->type() == MediaTrack::Video) { | 80 if (track->type() == MediaTrack::Video) { |
75 return getVideoConfig(track->bytestream_track_id()); | 81 return getVideoConfig(track->bytestream_track_id()); |
76 } | 82 } |
77 } | 83 } |
78 static VideoDecoderConfig invalidConfig; | 84 static VideoDecoderConfig invalidConfig; |
79 return invalidConfig; | 85 return invalidConfig; |
80 } | 86 } |
81 | 87 |
82 } // namespace media | 88 } // namespace media |
OLD | NEW |