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(const AudioDecoderConfig& config, |
19 StreamParser::TrackId byteStreamTrackId, | 19 StreamParser::TrackId byteStreamTrackId, |
20 const std::string& kind, | 20 const std::string& kind, |
21 const std::string& label, | 21 const std::string& label, |
22 const std::string& language) { | 22 const std::string& language) { |
23 DCHECK(config.IsValidConfig()); | 23 DCHECK(config.IsValidConfig()); |
24 CHECK(audio_configs_.find(byteStreamTrackId) == audio_configs_.end()); | 24 CHECK(audio_configs_.find(byteStreamTrackId) == audio_configs_.end()); |
25 std::unique_ptr<MediaTrack> track = base::WrapUnique(new MediaTrack( | 25 std::unique_ptr<MediaTrack> track = base::WrapUnique(new MediaTrack( |
26 MediaTrack::Audio, byteStreamTrackId, kind, label, language)); | 26 MediaTrack::Audio, byteStreamTrackId, kind, label, language)); |
27 tracks_.push_back(std::move(track)); | 27 tracks_.push_back(std::move(track)); |
28 audio_configs_[byteStreamTrackId] = config; | 28 audio_configs_[byteStreamTrackId] = config; |
29 return tracks_.back().get(); | |
29 } | 30 } |
30 | 31 |
31 void MediaTracks::AddVideoTrack(const VideoDecoderConfig& config, | 32 MediaTrack* MediaTracks::AddVideoTrack(const VideoDecoderConfig& config, |
32 StreamParser::TrackId byteStreamTrackId, | 33 StreamParser::TrackId byteStreamTrackId, |
33 const std::string& kind, | 34 const std::string& kind, |
34 const std::string& label, | 35 const std::string& label, |
35 const std::string& language) { | 36 const std::string& language) { |
36 DCHECK(config.IsValidConfig()); | 37 DCHECK(config.IsValidConfig()); |
37 CHECK(video_configs_.find(byteStreamTrackId) == video_configs_.end()); | 38 CHECK(video_configs_.find(byteStreamTrackId) == video_configs_.end()); |
38 std::unique_ptr<MediaTrack> track = base::WrapUnique(new MediaTrack( | 39 std::unique_ptr<MediaTrack> track = base::WrapUnique(new MediaTrack( |
39 MediaTrack::Video, byteStreamTrackId, kind, label, language)); | 40 MediaTrack::Video, byteStreamTrackId, kind, label, language)); |
40 tracks_.push_back(std::move(track)); | 41 tracks_.push_back(std::move(track)); |
41 video_configs_[byteStreamTrackId] = config; | 42 video_configs_[byteStreamTrackId] = config; |
43 return tracks_.back().get(); | |
xhwang
2016/06/09 06:06:02
nit: You can store a raw pointer of track.get() ab
servolk
2016/06/09 19:14:46
Done.
| |
42 } | 44 } |
43 | 45 |
44 const AudioDecoderConfig& MediaTracks::getAudioConfig( | 46 const AudioDecoderConfig& MediaTracks::getAudioConfig( |
45 StreamParser::TrackId byteStreamTrackId) const { | 47 StreamParser::TrackId byteStreamTrackId) const { |
46 auto it = audio_configs_.find(byteStreamTrackId); | 48 auto it = audio_configs_.find(byteStreamTrackId); |
47 if (it != audio_configs_.end()) | 49 if (it != audio_configs_.end()) |
48 return it->second; | 50 return it->second; |
49 static AudioDecoderConfig invalidConfig; | 51 static AudioDecoderConfig invalidConfig; |
50 return invalidConfig; | 52 return invalidConfig; |
51 } | 53 } |
(...skipping 21 matching lines...) Expand all Loading... | |
73 for (const auto& track : tracks()) { | 75 for (const auto& track : tracks()) { |
74 if (track->type() == MediaTrack::Video) { | 76 if (track->type() == MediaTrack::Video) { |
75 return getVideoConfig(track->byteStreamTrackId()); | 77 return getVideoConfig(track->byteStreamTrackId()); |
76 } | 78 } |
77 } | 79 } |
78 static VideoDecoderConfig invalidConfig; | 80 static VideoDecoderConfig invalidConfig; |
79 return invalidConfig; | 81 return invalidConfig; |
80 } | 82 } |
81 | 83 |
82 } // namespace media | 84 } // namespace media |
OLD | NEW |