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

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

Issue 2997713002: 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 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_encoder_factory_inter nal.h"
12
13 #include <memory>
14 #include <vector>
15
16 #include "webrtc/common_types.h"
17 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h"
18 #include "webrtc/rtc_base/checks.h"
19 #include "webrtc/rtc_base/logging.h"
20 #include "webrtc/rtc_base/optional.h"
21 #ifdef WEBRTC_CODEC_G722
22 #include "webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.h"
23 #endif
24 #ifdef WEBRTC_CODEC_ILBC
25 #include "webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h"
26 #endif
27 #ifdef WEBRTC_CODEC_ISACFX
28 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_encoder_isac fix.h" // nogncheck
29 #endif
30 #ifdef WEBRTC_CODEC_ISAC
31 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isa c.h" // nogncheck
32 #endif
33 #ifdef WEBRTC_CODEC_OPUS
34 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h"
35 #endif
36 #include "webrtc/modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h"
37
38 namespace webrtc {
39
40 namespace {
41
42 struct NamedEncoderFactory {
43 const char* name;
44 rtc::Optional<AudioCodecInfo> (*QueryAudioEncoder)(
45 const SdpAudioFormat& format);
46 std::unique_ptr<AudioEncoder> (
47 *MakeAudioEncoder)(int payload_type, const SdpAudioFormat& format);
48
49 template <typename T>
50 static NamedEncoderFactory ForEncoder() {
51 auto constructor = [](int payload_type, const SdpAudioFormat& format) {
52 auto opt_info = T::QueryAudioEncoder(format);
53 if (opt_info) {
54 return std::unique_ptr<AudioEncoder>(new T(payload_type, format));
55 }
56 return std::unique_ptr<AudioEncoder>();
57 };
58
59 return {T::GetPayloadName(), T::QueryAudioEncoder, constructor};
60 }
61 };
62
63 NamedEncoderFactory encoder_factories[] = {
64 #ifdef WEBRTC_CODEC_G722
65 NamedEncoderFactory::ForEncoder<AudioEncoderG722Impl>(),
66 #endif
67 #ifdef WEBRTC_CODEC_ILBC
68 NamedEncoderFactory::ForEncoder<AudioEncoderIlbcImpl>(),
69 #endif
70 #if defined(WEBRTC_CODEC_ISACFX)
71 NamedEncoderFactory::ForEncoder<AudioEncoderIsacFixImpl>(),
72 #elif defined(WEBRTC_CODEC_ISAC)
73 NamedEncoderFactory::ForEncoder<AudioEncoderIsacFloatImpl>(),
74 #endif
75
76 #ifdef WEBRTC_CODEC_OPUS
77 NamedEncoderFactory::ForEncoder<AudioEncoderOpus>(),
78 #endif
79 NamedEncoderFactory::ForEncoder<AudioEncoderPcm16B>(),
80 NamedEncoderFactory::ForEncoder<AudioEncoderPcmA>(),
81 NamedEncoderFactory::ForEncoder<AudioEncoderPcmU>(),
82 };
83 } // namespace
84
85 class BuiltinAudioEncoderFactory : public AudioEncoderFactory {
86 public:
87 std::vector<AudioCodecSpec> GetSupportedEncoders() override {
88 static const SdpAudioFormat desired_encoders[] = {
89 {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}},
90 {"ISAC", 16000, 1},
91 {"ISAC", 32000, 1},
92 {"G722", 8000, 1},
93 {"ILBC", 8000, 1},
94 {"PCMU", 8000, 1},
95 {"PCMA", 8000, 1},
96 };
97
98 // Initialize thread-safely, once, on first use.
99 static const std::vector<AudioCodecSpec> specs = [] {
100 std::vector<AudioCodecSpec> specs;
101 for (const auto& format : desired_encoders) {
102 for (const auto& ef : encoder_factories) {
103 if (STR_CASE_CMP(format.name.c_str(), ef.name) == 0) {
104 auto opt_info = ef.QueryAudioEncoder(format);
105 if (opt_info) {
106 specs.push_back({format, *opt_info});
107 }
108 }
109 }
110 }
111 return specs;
112 }();
113 return specs;
114 }
115
116 rtc::Optional<AudioCodecInfo> QueryAudioEncoder(
117 const SdpAudioFormat& format) override {
118 for (const auto& ef : encoder_factories) {
119 if (STR_CASE_CMP(format.name.c_str(), ef.name) == 0) {
120 return ef.QueryAudioEncoder(format);
121 }
122 }
123 return rtc::Optional<AudioCodecInfo>();
124 }
125
126 std::unique_ptr<AudioEncoder> MakeAudioEncoder(
127 int payload_type,
128 const SdpAudioFormat& format) override {
129 for (const auto& ef : encoder_factories) {
130 if (STR_CASE_CMP(format.name.c_str(), ef.name) == 0) {
131 return ef.MakeAudioEncoder(payload_type, format);
132 }
133 }
134 return nullptr;
135 }
136 };
137
138 rtc::scoped_refptr<AudioEncoderFactory>
139 CreateBuiltinAudioEncoderFactoryInternal() {
140 return rtc::scoped_refptr<AudioEncoderFactory>(
141 new rtc::RefCountedObject<BuiltinAudioEncoderFactory>());
142 }
143
144 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698