OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chromecast/media/cma/base/decoder_config_adapter.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "media/base/channel_layout.h" | |
9 | |
10 namespace { | |
11 | |
12 // Maximum audio bytes per sample. | |
13 static int kMaxBytesPerSample = 4; | |
14 | |
15 // Maximum audio sampling rate. | |
16 static int kMaxSampleRate = 192000; | |
17 | |
18 } | |
19 | |
20 namespace chromecast { | |
21 namespace media { | |
22 | |
23 // static | |
24 Codec DecoderConfigAdapter::ToCodec(const ::media::AudioCodec audio_codec) { | |
25 switch (audio_codec) { | |
26 case ::media::kCodecAAC: | |
27 return kCodecAAC; | |
28 case ::media::kCodecMP3: | |
29 return kCodecMP3; | |
30 case ::media::kCodecPCM: | |
31 return kCodecPCM; | |
32 case ::media::kCodecPCM_S16BE: | |
33 return kCodecPCM_S16BE; | |
34 case ::media::kCodecVorbis: | |
35 return kCodecVorbis; | |
36 default: | |
37 NOTREACHED(); | |
gunsch
2015/04/17 01:38:51
NOTREACHED is generally considered fatal. Is there
erickung1
2015/04/29 08:52:20
Done. Idea is to notify that the codec is unsuppor
| |
38 break; | |
39 } | |
40 return kUnknownCodec; | |
41 } | |
42 | |
43 // static | |
44 Codec DecoderConfigAdapter::ToCodec(const ::media::VideoCodec video_codec) { | |
45 switch (video_codec) { | |
46 case ::media::kCodecH264: | |
47 return kCodecH264; | |
48 case ::media::kCodecVP8: | |
49 return kCodecVP8; | |
50 case ::media::kCodecVP9: | |
51 return kCodecVP9; | |
52 default: | |
53 NOTREACHED(); | |
54 break; | |
55 } | |
56 return kUnknownCodec; | |
57 } | |
58 | |
59 // static | |
60 Profile DecoderConfigAdapter::ToProfile( | |
61 const ::media::VideoCodecProfile codec_profile) { | |
62 switch(codec_profile) { | |
63 case ::media::H264PROFILE_BASELINE: | |
64 return kH264Baseline; | |
65 case ::media::H264PROFILE_MAIN: | |
66 return kH264Main; | |
67 case ::media::H264PROFILE_EXTENDED: | |
68 return kH264Extended; | |
69 case ::media::H264PROFILE_HIGH: | |
70 return kH264High; | |
71 case ::media::H264PROFILE_HIGH10PROFILE: | |
72 return kH264High10; | |
73 case ::media::H264PROFILE_HIGH422PROFILE: | |
74 return kH264High422; | |
75 case ::media::H264PROFILE_HIGH444PREDICTIVEPROFILE: | |
76 return kH264High444Predictive; | |
77 case ::media::H264PROFILE_SCALABLEBASELINE: | |
78 return kH264ScalabBaseline; | |
79 case ::media::H264PROFILE_SCALABLEHIGH: | |
80 return kH264ScalableHigh; | |
81 case ::media::H264PROFILE_STEREOHIGH: | |
82 return kH264Stereohigh; | |
83 case ::media::H264PROFILE_MULTIVIEWHIGH: | |
84 return kH264MultiviewHigh; | |
85 case ::media::VP8PROFILE_ANY: | |
86 return kVP8ProfileAny; | |
87 case ::media::VP9PROFILE_ANY: | |
88 return kVP9ProfileAny; | |
89 default: | |
90 NOTREACHED(); | |
91 } | |
92 return kCodecProfileUnknown; | |
93 } | |
94 | |
95 // static | |
96 DecoderConfig DecoderConfigAdapter::ToDecoderConfig( | |
97 const ::media::AudioDecoderConfig& config) { | |
98 DecoderConfig decoder_config; | |
99 if (!config.IsValidConfig()) { | |
100 return decoder_config; | |
gunsch
2015/04/17 02:21:26
I wonder if this would be an appropriate place to
erickung1
2015/04/29 08:52:20
The idea of this util function is to
1. convert f
| |
101 } | |
102 | |
103 decoder_config.codec = DecoderConfigAdapter::ToCodec(config.codec()); | |
104 decoder_config.profile = kCodecProfileUnknown; | |
105 decoder_config.bytes_per_channel = config.bytes_per_channel(); | |
106 decoder_config.channel_number = | |
107 ::media::ChannelLayoutToChannelCount(config.channel_layout()), | |
108 decoder_config.samples_per_second = config.samples_per_second(); | |
109 decoder_config.extra_data.assign( | |
110 config.extra_data(), config.extra_data() + config.extra_data_size()); | |
111 decoder_config.is_encrypted = config.is_encrypted(); | |
112 decoder_config.is_valid_config = | |
113 decoder_config.codec >= kAudioCodecMin && | |
114 decoder_config.codec <= kAudioCodecMax && | |
115 decoder_config.channel_number > 0 && | |
116 decoder_config.bytes_per_channel > 0 && | |
117 decoder_config.bytes_per_channel <= kMaxBytesPerSample && | |
118 decoder_config.samples_per_second > 0 && | |
119 decoder_config.samples_per_second <= kMaxSampleRate; | |
120 | |
121 return decoder_config; | |
122 } | |
123 | |
124 // static | |
125 DecoderConfig DecoderConfigAdapter::ToDecoderConfig( | |
126 const ::media::VideoDecoderConfig& config) { | |
127 DecoderConfig decoder_config; | |
128 if (!config.IsValidConfig()) { | |
129 return decoder_config; | |
130 } | |
131 | |
132 decoder_config.codec = DecoderConfigAdapter::ToCodec(config.codec()); | |
133 decoder_config.profile = DecoderConfigAdapter::ToProfile(config.profile()); | |
134 decoder_config.bytes_per_channel = -1; | |
135 decoder_config.channel_number = -1; | |
136 decoder_config.samples_per_second = -1; | |
137 decoder_config.extra_data.assign( | |
138 config.extra_data(), config.extra_data()+config.extra_data_size()); | |
139 decoder_config.is_encrypted = config.is_encrypted(); | |
140 decoder_config.is_valid_config = | |
141 decoder_config.codec >= kVideoCodecMin && | |
142 decoder_config.codec <= kVideoCodecMax;; | |
143 return decoder_config; | |
144 } | |
145 | |
146 } // namespace media | |
147 } // namespace chromecast | |
OLD | NEW |