OLD | NEW |
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 std::unique_ptr<AudioDecoder> Unique(AudioDecoder* d) { | 46 std::unique_ptr<AudioDecoder> Unique(AudioDecoder* d) { |
47 return std::unique_ptr<AudioDecoder>(d); | 47 return std::unique_ptr<AudioDecoder>(d); |
48 } | 48 } |
49 | 49 |
50 // TODO(kwiberg): These factory functions should probably be moved to each | 50 // TODO(kwiberg): These factory functions should probably be moved to each |
51 // decoder. | 51 // decoder. |
52 NamedDecoderConstructor decoder_constructors[] = { | 52 NamedDecoderConstructor decoder_constructors[] = { |
53 {"pcmu", | 53 {"pcmu", |
54 [](const SdpAudioFormat& format) { | 54 [](const SdpAudioFormat& format) { |
55 return format.clockrate_hz == 8000 && format.num_channels >= 1 | 55 return format.clockrate_hz == 8000 && format.num_channels >= 1 |
56 ? Unique(new AudioDecoderPcmU(format.num_channels)) | 56 ? Unique(new AudioDecoderPcmU(format.clockrate_hz, |
| 57 format.num_channels)) |
57 : nullptr; | 58 : nullptr; |
58 }}, | 59 }}, |
59 {"pcma", | 60 {"pcma", |
60 [](const SdpAudioFormat& format) { | 61 [](const SdpAudioFormat& format) { |
61 return format.clockrate_hz == 8000 && format.num_channels >= 1 | 62 return format.clockrate_hz == 8000 && format.num_channels >= 1 |
62 ? Unique(new AudioDecoderPcmA(format.num_channels)) | 63 ? Unique(new AudioDecoderPcmA(format.clockrate_hz, |
| 64 format.num_channels)) |
63 : nullptr; | 65 : nullptr; |
64 }}, | 66 }}, |
65 #ifdef WEBRTC_CODEC_ILBC | 67 #ifdef WEBRTC_CODEC_ILBC |
66 {"ilbc", | 68 {"ilbc", |
67 [](const SdpAudioFormat& format) { | 69 [](const SdpAudioFormat& format) { |
68 return format.clockrate_hz == 8000 && format.num_channels == 1 | 70 return format.clockrate_hz == 8000 && format.num_channels == 1 |
69 ? Unique(new AudioDecoderIlbc) | 71 ? Unique(new AudioDecoderIlbc) |
70 : nullptr; | 72 : nullptr; |
71 }}, | 73 }}, |
72 #endif | 74 #endif |
73 #if defined(WEBRTC_CODEC_ISACFX) | 75 #if defined(WEBRTC_CODEC_ISACFX) |
74 {"isac", | 76 {"isac", |
75 [](const SdpAudioFormat& format) { | 77 [](const SdpAudioFormat& format) { |
76 return format.clockrate_hz == 16000 && format.num_channels == 1 | 78 return format.clockrate_hz == 16000 && format.num_channels == 1 |
77 ? Unique(new AudioDecoderIsacFix) | 79 ? Unique(new AudioDecoderIsacFix(format.clockrate_hz)) |
78 : nullptr; | 80 : nullptr; |
79 }}, | 81 }}, |
80 #elif defined(WEBRTC_CODEC_ISAC) | 82 #elif defined(WEBRTC_CODEC_ISAC) |
81 {"isac", | 83 {"isac", |
82 [](const SdpAudioFormat& format) { | 84 [](const SdpAudioFormat& format) { |
83 return (format.clockrate_hz == 16000 || format.clockrate_hz == 32000) && | 85 return (format.clockrate_hz == 16000 || format.clockrate_hz == 32000) && |
84 format.num_channels == 1 | 86 format.num_channels == 1 |
85 ? Unique(new AudioDecoderIsac) | 87 ? Unique(new AudioDecoderIsac(format.clockrate_hz)) |
86 : nullptr; | 88 : nullptr; |
87 }}, | 89 }}, |
88 #endif | 90 #endif |
89 {"l16", | 91 {"l16", |
90 [](const SdpAudioFormat& format) { | 92 [](const SdpAudioFormat& format) { |
91 return format.num_channels >= 1 | 93 return format.num_channels >= 1 |
92 ? Unique(new AudioDecoderPcm16B(format.num_channels)) | 94 ? Unique(new AudioDecoderPcm16B(format.clockrate_hz, |
| 95 format.num_channels)) |
93 : nullptr; | 96 : nullptr; |
94 }}, | 97 }}, |
95 #ifdef WEBRTC_CODEC_G722 | 98 #ifdef WEBRTC_CODEC_G722 |
96 {"g722", | 99 {"g722", |
97 [](const SdpAudioFormat& format) { | 100 [](const SdpAudioFormat& format) { |
98 if (format.clockrate_hz == 8000) { | 101 if (format.clockrate_hz == 8000) { |
99 if (format.num_channels == 1) | 102 if (format.num_channels == 1) |
100 return Unique(new AudioDecoderG722); | 103 return Unique(new AudioDecoderG722); |
101 if (format.num_channels == 2) | 104 if (format.num_channels == 2) |
102 return Unique(new AudioDecoderG722Stereo); | 105 return Unique(new AudioDecoderG722Stereo); |
(...skipping 26 matching lines...) Expand all Loading... |
129 class BuiltinAudioDecoderFactory : public AudioDecoderFactory { | 132 class BuiltinAudioDecoderFactory : public AudioDecoderFactory { |
130 public: | 133 public: |
131 std::vector<SdpAudioFormat> GetSupportedFormats() override { | 134 std::vector<SdpAudioFormat> GetSupportedFormats() override { |
132 FATAL() << "Not implemented yet!"; | 135 FATAL() << "Not implemented yet!"; |
133 } | 136 } |
134 | 137 |
135 std::unique_ptr<AudioDecoder> MakeAudioDecoder( | 138 std::unique_ptr<AudioDecoder> MakeAudioDecoder( |
136 const SdpAudioFormat& format) override { | 139 const SdpAudioFormat& format) override { |
137 for (const auto& dc : decoder_constructors) { | 140 for (const auto& dc : decoder_constructors) { |
138 if (STR_CASE_CMP(format.name.c_str(), dc.name) == 0) { | 141 if (STR_CASE_CMP(format.name.c_str(), dc.name) == 0) { |
139 return std::unique_ptr<AudioDecoder>(dc.constructor(format)); | 142 std::unique_ptr<AudioDecoder> dec = dc.constructor(format); |
| 143 if (dec) { |
| 144 const int expected_sample_rate_hz = |
| 145 STR_CASE_CMP(format.name.c_str(), "g722") == 0 |
| 146 ? 2 * format.clockrate_hz |
| 147 : format.clockrate_hz; |
| 148 RTC_CHECK_EQ(expected_sample_rate_hz, dec->SampleRateHz()); |
| 149 } |
| 150 return dec; |
140 } | 151 } |
141 } | 152 } |
142 return nullptr; | 153 return nullptr; |
143 } | 154 } |
144 }; | 155 }; |
145 | 156 |
146 } // namespace | 157 } // namespace |
147 | 158 |
148 rtc::scoped_refptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory() { | 159 rtc::scoped_refptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory() { |
149 return rtc::scoped_refptr<AudioDecoderFactory>( | 160 return rtc::scoped_refptr<AudioDecoderFactory>( |
150 new rtc::RefCountedObject<BuiltinAudioDecoderFactory>); | 161 new rtc::RefCountedObject<BuiltinAudioDecoderFactory>); |
151 } | 162 } |
152 | 163 |
153 } // namespace webrtc | 164 } // namespace webrtc |
OLD | NEW |