OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" | |
12 | |
13 #include <vector> | |
14 | |
15 #include "webrtc/base/checks.h" | |
16 #include "webrtc/common_types.h" | |
17 #include "webrtc/modules/audio_coding/codecs/cng/webrtc_cng.h" | |
18 #include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h" | |
19 #ifdef WEBRTC_CODEC_G722 | |
20 #include "webrtc/modules/audio_coding/codecs/g722/audio_decoder_g722.h" | |
21 #endif | |
22 #ifdef WEBRTC_CODEC_ILBC | |
23 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h" | |
24 #endif | |
25 #ifdef WEBRTC_CODEC_ISACFX | |
26 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_decoder_isac fix.h" | |
27 #endif | |
28 #ifdef WEBRTC_CODEC_ISAC | |
29 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isa c.h" | |
30 #endif | |
31 #ifdef WEBRTC_CODEC_OPUS | |
32 #include "webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.h" | |
33 #endif | |
34 #include "webrtc/modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.h" | |
35 | |
36 namespace webrtc { | |
37 | |
38 namespace { | |
39 | |
40 struct NamedDecoderConstructor { | |
41 const char* name; | |
42 std::unique_ptr<AudioDecoder> (*constructor)(int clockrate_hz, | |
43 int num_channels); | |
44 }; | |
45 | |
46 std::unique_ptr<AudioDecoder> Uniq(AudioDecoder* d) { | |
hlundin-webrtc
2016/04/27 14:35:56
Did you mean to name it Unique, or were you paying
the sun
2016/04/27 20:34:15
I think the name is confusing because of that conn
kwiberg-webrtc
2016/04/28 12:35:52
I was initially going to name it U, but I foresaw
the sun
2016/04/28 13:02:42
Ok, (2) makes it make sense.
| |
47 return std::unique_ptr<AudioDecoder>(d); | |
48 } | |
49 | |
50 // TODO(kwiberg): These factory functions should probably be moved to each | |
51 // decoder. | |
52 NamedDecoderConstructor decoder_constructors[] = { | |
53 {"pcmu", | |
54 [](int clockrate_hz, int num_channels) { | |
the sun
2016/04/27 20:34:14
nit: Indent 1 looks weird - did git cl format do t
kwiberg-webrtc
2016/04/28 12:35:52
Yes. And it's not weird; it's how multiline array
| |
55 return clockrate_hz == 8000 && num_channels >= 1 | |
56 ? Uniq(new AudioDecoderPcmU(num_channels)) | |
57 : nullptr; | |
58 }}, | |
59 {"pcma", | |
60 [](int clockrate_hz, int num_channels) { | |
61 return clockrate_hz == 8000 && num_channels >= 1 | |
62 ? Uniq(new AudioDecoderPcmA(num_channels)) | |
63 : nullptr; | |
64 }}, | |
65 #ifdef WEBRTC_CODEC_ILBC | |
66 {"ilbc", | |
67 [](int clockrate_hz, int num_channels) { | |
68 return clockrate_hz == 8000 && num_channels == 1 | |
69 ? Uniq(new AudioDecoderIlbc) | |
70 : nullptr; | |
71 }}, | |
72 #endif | |
73 #if defined(WEBRTC_CODEC_ISACFX) | |
74 {"isac", | |
75 [](int clockrate_hz, int num_channels) { | |
76 return clockrate_hz == 16000 && num_channels == 1 | |
77 ? Uniq(new AudioDecoderIsacFix) | |
78 : nullptr; | |
79 }}, | |
80 #elif defined(WEBRTC_CODEC_ISAC) | |
81 {"isac", | |
82 [](int clockrate_hz, int num_channels) { | |
83 return (clockrate_hz == 16000 || clockrate_hz == 32000) && | |
84 num_channels == 1 | |
85 ? Uniq(new AudioDecoderIsac) | |
86 : nullptr; | |
87 }}, | |
88 #endif | |
89 {"l16", | |
90 [](int clockrate_hz, int num_channels) { | |
the sun
2016/04/27 20:34:15
L16 isn't supported in WVoE. See: https://code.goo
ossu
2016/04/28 08:35:54
Good to know, however isn't this just a straight
kwiberg-webrtc
2016/04/28 12:35:52
Interesting. But ossu@ is right, I've just tried t
the sun
2016/04/28 13:02:42
Ok, so once we are more comfortable with the struc
kwiberg-webrtc
2016/04/28 19:35:22
Yes, once we inject the factory from all the way o
| |
91 return num_channels >= 1 ? Uniq(new AudioDecoderPcm16B(num_channels)) | |
92 : nullptr; | |
93 }}, | |
94 #ifdef WEBRTC_CODEC_G722 | |
95 {"g722", | |
96 [](int clockrate_hz, int num_channels) { | |
97 if (clockrate_hz == 8000) { | |
98 if (num_channels == 1) | |
99 return Uniq(new AudioDecoderG722); | |
100 if (num_channels == 2) | |
101 return Uniq(new AudioDecoderG722Stereo); | |
102 } | |
103 return Uniq(nullptr); | |
hlundin-webrtc
2016/04/27 14:35:56
Why Uniq(nullptr) here, but not in other places?
kwiberg-webrtc
2016/04/28 12:35:52
Because the other places all use ?: with nullptr a
| |
104 }}, | |
105 #endif | |
106 #ifdef WEBRTC_CODEC_OPUS | |
107 {"opus", | |
108 [](int clockrate_hz, int num_channels) { | |
109 return clockrate_hz == 48000 && (num_channels == 1 || num_channels == 2) | |
110 ? Uniq(new AudioDecoderOpus(num_channels)) | |
111 : nullptr; | |
112 }}, | |
113 #endif | |
114 }; | |
115 | |
116 class BuiltinAudioDecoderFactory : public AudioDecoderFactory { | |
117 public: | |
118 std::vector<SdpAudioFormat> GetSupportedFormats() override { | |
119 FATAL() << "Not implemented yet!"; | |
the sun
2016/04/27 20:34:15
We should implement this already now, as it forces
kwiberg-webrtc
2016/04/28 12:35:52
Are you sure? I could implement it, but since no o
the sun
2016/04/28 13:02:42
Nah, you're right, leaving it out makes sense from
| |
120 } | |
121 | |
122 std::unique_ptr<AudioDecoder> MakeAudioDecoder( | |
123 const SdpAudioFormat& format) override { | |
124 for (const auto& dc : decoder_constructors) { | |
125 if (STR_CASE_CMP(format.name.c_str(), dc.name) == 0) { | |
126 return std::unique_ptr<AudioDecoder>( | |
127 dc.constructor(format.clockrate_hz, format.num_channels)); | |
128 } | |
129 } | |
130 return nullptr; | |
131 } | |
132 }; | |
133 | |
134 } // namespace | |
135 | |
136 std::unique_ptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory() { | |
137 return std::unique_ptr<AudioDecoderFactory>(new BuiltinAudioDecoderFactory); | |
138 } | |
139 | |
140 } // namespace webrtc | |
OLD | NEW |