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

Unified Diff: webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.cc

Issue 1917163002: New interface (AudioDecoderFactory), with an implementation (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.cc
diff --git a/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.cc b/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e88adc7a33ced7d7bf8d1e75c0682ba3bd6fa9f5
--- /dev/null
+++ b/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.cc
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h"
+
+#include <vector>
+
+#include "webrtc/base/checks.h"
+#include "webrtc/common_types.h"
+#include "webrtc/modules/audio_coding/codecs/cng/webrtc_cng.h"
+#include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h"
+#ifdef WEBRTC_CODEC_G722
+#include "webrtc/modules/audio_coding/codecs/g722/audio_decoder_g722.h"
+#endif
+#ifdef WEBRTC_CODEC_ILBC
+#include "webrtc/modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h"
+#endif
+#ifdef WEBRTC_CODEC_ISACFX
+#include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_decoder_isacfix.h"
+#endif
+#ifdef WEBRTC_CODEC_ISAC
+#include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h"
+#endif
+#ifdef WEBRTC_CODEC_OPUS
+#include "webrtc/modules/audio_coding/codecs/opus/audio_decoder_opus.h"
+#endif
+#include "webrtc/modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.h"
+
+namespace webrtc {
+
+namespace {
+
+struct NamedDecoderConstructor {
+ const char* name;
+ std::unique_ptr<AudioDecoder> (*constructor)(int clockrate_hz,
+ int num_channels);
+};
+
+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.
+ return std::unique_ptr<AudioDecoder>(d);
+}
+
+// TODO(kwiberg): These factory functions should probably be moved to each
+// decoder.
+NamedDecoderConstructor decoder_constructors[] = {
+ {"pcmu",
+ [](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
+ return clockrate_hz == 8000 && num_channels >= 1
+ ? Uniq(new AudioDecoderPcmU(num_channels))
+ : nullptr;
+ }},
+ {"pcma",
+ [](int clockrate_hz, int num_channels) {
+ return clockrate_hz == 8000 && num_channels >= 1
+ ? Uniq(new AudioDecoderPcmA(num_channels))
+ : nullptr;
+ }},
+#ifdef WEBRTC_CODEC_ILBC
+ {"ilbc",
+ [](int clockrate_hz, int num_channels) {
+ return clockrate_hz == 8000 && num_channels == 1
+ ? Uniq(new AudioDecoderIlbc)
+ : nullptr;
+ }},
+#endif
+#if defined(WEBRTC_CODEC_ISACFX)
+ {"isac",
+ [](int clockrate_hz, int num_channels) {
+ return clockrate_hz == 16000 && num_channels == 1
+ ? Uniq(new AudioDecoderIsacFix)
+ : nullptr;
+ }},
+#elif defined(WEBRTC_CODEC_ISAC)
+ {"isac",
+ [](int clockrate_hz, int num_channels) {
+ return (clockrate_hz == 16000 || clockrate_hz == 32000) &&
+ num_channels == 1
+ ? Uniq(new AudioDecoderIsac)
+ : nullptr;
+ }},
+#endif
+ {"l16",
+ [](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
+ return num_channels >= 1 ? Uniq(new AudioDecoderPcm16B(num_channels))
+ : nullptr;
+ }},
+#ifdef WEBRTC_CODEC_G722
+ {"g722",
+ [](int clockrate_hz, int num_channels) {
+ if (clockrate_hz == 8000) {
+ if (num_channels == 1)
+ return Uniq(new AudioDecoderG722);
+ if (num_channels == 2)
+ return Uniq(new AudioDecoderG722Stereo);
+ }
+ 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
+ }},
+#endif
+#ifdef WEBRTC_CODEC_OPUS
+ {"opus",
+ [](int clockrate_hz, int num_channels) {
+ return clockrate_hz == 48000 && (num_channels == 1 || num_channels == 2)
+ ? Uniq(new AudioDecoderOpus(num_channels))
+ : nullptr;
+ }},
+#endif
+};
+
+class BuiltinAudioDecoderFactory : public AudioDecoderFactory {
+ public:
+ std::vector<SdpAudioFormat> GetSupportedFormats() override {
+ 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
+ }
+
+ std::unique_ptr<AudioDecoder> MakeAudioDecoder(
+ const SdpAudioFormat& format) override {
+ for (const auto& dc : decoder_constructors) {
+ if (STR_CASE_CMP(format.name.c_str(), dc.name) == 0) {
+ return std::unique_ptr<AudioDecoder>(
+ dc.constructor(format.clockrate_hz, format.num_channels));
+ }
+ }
+ return nullptr;
+ }
+};
+
+} // namespace
+
+std::unique_ptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory() {
+ return std::unique_ptr<AudioDecoderFactory>(new BuiltinAudioDecoderFactory);
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698