Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.cc

Issue 2516993002: Pass SdpAudioFormat through Channel, without converting to CodecInst (Closed)
Patch Set: Fix SetRecvCodecsAfterAddingStreams Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return Unique(new AudioDecoderG722); 101 return Unique(new AudioDecoderG722);
102 if (format.num_channels == 2) 102 if (format.num_channels == 2)
103 return Unique(new AudioDecoderG722Stereo); 103 return Unique(new AudioDecoderG722Stereo);
104 } 104 }
105 return Unique(nullptr); 105 return Unique(nullptr);
106 }}, 106 }},
107 #endif 107 #endif
108 #ifdef WEBRTC_CODEC_OPUS 108 #ifdef WEBRTC_CODEC_OPUS
109 {"opus", 109 {"opus",
110 [](const SdpAudioFormat& format) { 110 [](const SdpAudioFormat& format) {
111 rtc::Optional<int> num_channels = [&] { 111 const rtc::Optional<int> num_channels = [&] {
112 auto stereo = format.parameters.find("stereo"); 112 auto stereo = format.parameters.find("stereo");
113 if (stereo != format.parameters.end()) { 113 if (stereo != format.parameters.end()) {
114 if (stereo->second == "0") { 114 if (stereo->second == "0") {
115 return rtc::Optional<int>(1); 115 return rtc::Optional<int>(1);
116 } else if (stereo->second == "1") { 116 } else if (stereo->second == "1") {
117 return rtc::Optional<int>(2); 117 return rtc::Optional<int>(2);
118 } else {
119 return rtc::Optional<int>(); // Bad stereo parameter.
118 } 120 }
119 } 121 }
120 return rtc::Optional<int>(); 122 return rtc::Optional<int>(1); // Default to mono.
121 }(); 123 }();
122 return format.clockrate_hz == 48000 && format.num_channels == 2 && 124 return format.clockrate_hz == 48000 && format.num_channels == 2 &&
123 num_channels 125 num_channels
124 ? Unique(new AudioDecoderOpus(*num_channels)) 126 ? Unique(new AudioDecoderOpus(*num_channels))
125 : nullptr; 127 : nullptr;
126 }}, 128 }},
127 #endif 129 #endif
128 }; 130 };
129 131
130 class BuiltinAudioDecoderFactory : public AudioDecoderFactory { 132 class BuiltinAudioDecoderFactory : public AudioDecoderFactory {
131 public: 133 public:
132 std::vector<AudioCodecSpec> GetSupportedDecoders() override { 134 std::vector<AudioCodecSpec> GetSupportedDecoders() override {
133 static std::vector<AudioCodecSpec> specs = { 135 static std::vector<AudioCodecSpec> specs = {
134 #ifdef WEBRTC_CODEC_OPUS 136 #ifdef WEBRTC_CODEC_OPUS
135 { { "opus", 48000, 2, { 137 {{"opus",
136 {"minptime", "10" }, 138 48000,
137 {"useinbandfec", "1" } 139 2,
138 } 140 { {"minptime", "10"},
139 }, false 141 {"stereo", "0"},
140 }, 142 { "useinbandfec",
143 "1" } }},
144 false},
141 #endif 145 #endif
142 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) 146 #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
143 { { "isac", 16000, 1 }, true }, 147 {{"isac", 16000, 1}, true},
144 #endif 148 #endif
145 #if (defined(WEBRTC_CODEC_ISAC)) 149 #if (defined(WEBRTC_CODEC_ISAC))
146 { { "isac", 32000, 1 }, true }, 150 {{"isac", 32000, 1}, true},
147 #endif 151 #endif
148 #ifdef WEBRTC_CODEC_G722 152 #ifdef WEBRTC_CODEC_G722
149 { { "G722", 8000, 1 }, true }, 153 {{"G722", 8000, 1}, true},
150 #endif 154 #endif
151 #ifdef WEBRTC_CODEC_ILBC 155 #ifdef WEBRTC_CODEC_ILBC
152 { { "iLBC", 8000, 1 }, true }, 156 {{"iLBC", 8000, 1}, true},
153 #endif 157 #endif
154 { { "PCMU", 8000, 1 }, true }, 158 {{"PCMU", 8000, 1}, true},
155 { { "PCMA", 8000, 1 }, true } 159 {{"PCMA", 8000, 1}, true}
156 }; 160 };
157 161
158 return specs; 162 return specs;
159 } 163 }
160 164
165 bool IsSupportedDecoder(const SdpAudioFormat& format) override {
166 return static_cast<bool>(MakeAudioDecoder(format));
ossu 2016/12/12 13:24:46 I realize you want to land this one, and that this
kwiberg-webrtc 2016/12/14 13:09:36 Done (not exactly what you suggested, but somethin
ossu 2016/12/14 13:53:35 Alright! IsSupportedDecoder now behaves as I'd exp
167 }
168
161 std::unique_ptr<AudioDecoder> MakeAudioDecoder( 169 std::unique_ptr<AudioDecoder> MakeAudioDecoder(
162 const SdpAudioFormat& format) override { 170 const SdpAudioFormat& format) override {
163 for (const auto& dc : decoder_constructors) { 171 for (const auto& dc : decoder_constructors) {
164 if (STR_CASE_CMP(format.name.c_str(), dc.name) == 0) { 172 if (STR_CASE_CMP(format.name.c_str(), dc.name) == 0) {
165 std::unique_ptr<AudioDecoder> dec = dc.constructor(format); 173 std::unique_ptr<AudioDecoder> dec = dc.constructor(format);
166 if (dec) { 174 if (dec) {
167 const int expected_sample_rate_hz = 175 const int expected_sample_rate_hz =
168 STR_CASE_CMP(format.name.c_str(), "g722") == 0 176 STR_CASE_CMP(format.name.c_str(), "g722") == 0
169 ? 2 * format.clockrate_hz 177 ? 2 * format.clockrate_hz
170 : format.clockrate_hz; 178 : format.clockrate_hz;
171 RTC_CHECK_EQ(expected_sample_rate_hz, dec->SampleRateHz()); 179 RTC_CHECK_EQ(expected_sample_rate_hz, dec->SampleRateHz());
172 } 180 }
173 return dec; 181 return dec;
174 } 182 }
175 } 183 }
176 return nullptr; 184 return nullptr;
177 } 185 }
178 }; 186 };
179 187
180 } // namespace 188 } // namespace
181 189
182 rtc::scoped_refptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory() { 190 rtc::scoped_refptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory() {
183 return rtc::scoped_refptr<AudioDecoderFactory>( 191 return rtc::scoped_refptr<AudioDecoderFactory>(
184 new rtc::RefCountedObject<BuiltinAudioDecoderFactory>); 192 new rtc::RefCountedObject<BuiltinAudioDecoderFactory>);
185 } 193 }
186 194
187 } // namespace webrtc 195 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698