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

Side by Side 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: review Created 4 years, 7 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) 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> Unique(AudioDecoder* d) {
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) {
55 return clockrate_hz == 8000 && num_channels >= 1
56 ? Unique(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 ? Unique(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 ? Unique(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 ? Unique(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 ? Unique(new AudioDecoderIsac)
86 : nullptr;
87 }},
88 #endif
89 {"l16",
90 [](int clockrate_hz, int num_channels) {
91 return num_channels >= 1 ? Unique(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 Unique(new AudioDecoderG722);
100 if (num_channels == 2)
101 return Unique(new AudioDecoderG722Stereo);
102 }
103 return Unique(nullptr);
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 ? Unique(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!";
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
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h ('k') | webrtc/modules/modules.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698