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

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

Issue 2996373002: Revert of Reimplement the builtin audio codec factories using the new stuff in api/ (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.cc
diff --git a/webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.cc b/webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b44268ab07d3e4b6be9a57464538d06cad4accfe
--- /dev/null
+++ b/webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.cc
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2017 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_encoder_factory_internal.h"
+
+#include <memory>
+#include <vector>
+
+#include "webrtc/common_types.h"
+#include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h"
+#include "webrtc/rtc_base/checks.h"
+#include "webrtc/rtc_base/logging.h"
+#include "webrtc/rtc_base/optional.h"
+#ifdef WEBRTC_CODEC_G722
+#include "webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.h"
+#endif
+#ifdef WEBRTC_CODEC_ILBC
+#include "webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h"
+#endif
+#ifdef WEBRTC_CODEC_ISACFX
+#include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_encoder_isacfix.h" // nogncheck
+#endif
+#ifdef WEBRTC_CODEC_ISAC
+#include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h" // nogncheck
+#endif
+#ifdef WEBRTC_CODEC_OPUS
+#include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h"
+#endif
+#include "webrtc/modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h"
+
+namespace webrtc {
+
+namespace {
+
+struct NamedEncoderFactory {
+ const char* name;
+ rtc::Optional<AudioCodecInfo> (*QueryAudioEncoder)(
+ const SdpAudioFormat& format);
+ std::unique_ptr<AudioEncoder> (
+ *MakeAudioEncoder)(int payload_type, const SdpAudioFormat& format);
+
+ template <typename T>
+ static NamedEncoderFactory ForEncoder() {
+ auto constructor = [](int payload_type, const SdpAudioFormat& format) {
+ auto opt_info = T::QueryAudioEncoder(format);
+ if (opt_info) {
+ return std::unique_ptr<AudioEncoder>(new T(payload_type, format));
+ }
+ return std::unique_ptr<AudioEncoder>();
+ };
+
+ return {T::GetPayloadName(), T::QueryAudioEncoder, constructor};
+ }
+};
+
+NamedEncoderFactory encoder_factories[] = {
+#ifdef WEBRTC_CODEC_G722
+ NamedEncoderFactory::ForEncoder<AudioEncoderG722Impl>(),
+#endif
+#ifdef WEBRTC_CODEC_ILBC
+ NamedEncoderFactory::ForEncoder<AudioEncoderIlbcImpl>(),
+#endif
+#if defined(WEBRTC_CODEC_ISACFX)
+ NamedEncoderFactory::ForEncoder<AudioEncoderIsacFixImpl>(),
+#elif defined(WEBRTC_CODEC_ISAC)
+ NamedEncoderFactory::ForEncoder<AudioEncoderIsacFloatImpl>(),
+#endif
+
+#ifdef WEBRTC_CODEC_OPUS
+ NamedEncoderFactory::ForEncoder<AudioEncoderOpus>(),
+#endif
+ NamedEncoderFactory::ForEncoder<AudioEncoderPcm16B>(),
+ NamedEncoderFactory::ForEncoder<AudioEncoderPcmA>(),
+ NamedEncoderFactory::ForEncoder<AudioEncoderPcmU>(),
+};
+} // namespace
+
+class BuiltinAudioEncoderFactory : public AudioEncoderFactory {
+ public:
+ std::vector<AudioCodecSpec> GetSupportedEncoders() override {
+ static const SdpAudioFormat desired_encoders[] = {
+ {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}},
+ {"ISAC", 16000, 1},
+ {"ISAC", 32000, 1},
+ {"G722", 8000, 1},
+ {"ILBC", 8000, 1},
+ {"PCMU", 8000, 1},
+ {"PCMA", 8000, 1},
+ };
+
+ // Initialize thread-safely, once, on first use.
+ static const std::vector<AudioCodecSpec> specs = [] {
+ std::vector<AudioCodecSpec> specs;
+ for (const auto& format : desired_encoders) {
+ for (const auto& ef : encoder_factories) {
+ if (STR_CASE_CMP(format.name.c_str(), ef.name) == 0) {
+ auto opt_info = ef.QueryAudioEncoder(format);
+ if (opt_info) {
+ specs.push_back({format, *opt_info});
+ }
+ }
+ }
+ }
+ return specs;
+ }();
+ return specs;
+ }
+
+ rtc::Optional<AudioCodecInfo> QueryAudioEncoder(
+ const SdpAudioFormat& format) override {
+ for (const auto& ef : encoder_factories) {
+ if (STR_CASE_CMP(format.name.c_str(), ef.name) == 0) {
+ return ef.QueryAudioEncoder(format);
+ }
+ }
+ return rtc::Optional<AudioCodecInfo>();
+ }
+
+ std::unique_ptr<AudioEncoder> MakeAudioEncoder(
+ int payload_type,
+ const SdpAudioFormat& format) override {
+ for (const auto& ef : encoder_factories) {
+ if (STR_CASE_CMP(format.name.c_str(), ef.name) == 0) {
+ return ef.MakeAudioEncoder(payload_type, format);
+ }
+ }
+ return nullptr;
+ }
+};
+
+rtc::scoped_refptr<AudioEncoderFactory>
+CreateBuiltinAudioEncoderFactoryInternal() {
+ return rtc::scoped_refptr<AudioEncoderFactory>(
+ new rtc::RefCountedObject<BuiltinAudioEncoderFactory>());
+}
+
+} // namespace webrtc
« no previous file with comments | « webrtc/modules/audio_coding/codecs/builtin_audio_encoder_factory_internal.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698