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

Side by Side Diff: webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h

Issue 2695243005: Injectable audio encoders: BuiltinAudioEncoderFactory (Closed)
Patch Set: Created 3 years, 10 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
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_
13 13
14 #include "webrtc/base/checks.h" 14 #include "webrtc/base/checks.h"
15 #include "webrtc/base/string_to_number.h"
15 #include "webrtc/common_types.h" 16 #include "webrtc/common_types.h"
16 17
17 namespace webrtc { 18 namespace webrtc {
18 19
19 template <typename T> 20 template <typename T>
20 typename AudioEncoderIsacT<T>::Config CreateIsacConfig( 21 typename AudioEncoderIsacT<T>::Config CreateIsacConfig(
21 const CodecInst& codec_inst, 22 const CodecInst& codec_inst,
22 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) { 23 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) {
23 typename AudioEncoderIsacT<T>::Config config; 24 typename AudioEncoderIsacT<T>::Config config;
24 config.bwinfo = bwinfo; 25 config.bwinfo = bwinfo;
25 config.payload_type = codec_inst.pltype; 26 config.payload_type = codec_inst.pltype;
26 config.sample_rate_hz = codec_inst.plfreq; 27 config.sample_rate_hz = codec_inst.plfreq;
27 config.frame_size_ms = 28 config.frame_size_ms =
28 rtc::CheckedDivExact(1000 * codec_inst.pacsize, config.sample_rate_hz); 29 rtc::CheckedDivExact(1000 * codec_inst.pacsize, config.sample_rate_hz);
29 config.adaptive_mode = (codec_inst.rate == -1); 30 config.adaptive_mode = (codec_inst.rate == -1);
30 if (codec_inst.rate != -1) 31 if (codec_inst.rate != -1)
31 config.bit_rate = codec_inst.rate; 32 config.bit_rate = codec_inst.rate;
32 return config; 33 return config;
33 } 34 }
34 35
35 template <typename T> 36 template <typename T>
37 typename AudioEncoderIsacT<T>::Config CreateIsacConfig(
38 int payload_type,
39 const SdpAudioFormat& format) {
40 typename AudioEncoderIsacT<T>::Config config;
41 config.payload_type = payload_type;
42 config.sample_rate_hz = format.clockrate_hz;
43
44 auto ptime_iter = format.parameters.find("ptime");
45 if (ptime_iter != format.parameters.end()) {
46 auto ptime = rtc::StringToNumber<int>(ptime_iter->second);
47 if (ptime && *ptime > 0) {
48 config.frame_size_ms = *ptime;
49 }
50 }
51
52 // TODO(ossu): These values are taken from ACMCodecDB. At this
53 // point, adaptive mode is not used by WebRTC.
54 config.bit_rate = (format.clockrate_hz == 32000) ? 56000 : 32000;
55 return config;
56 }
57
58 template <typename T>
36 bool AudioEncoderIsacT<T>::Config::IsOk() const { 59 bool AudioEncoderIsacT<T>::Config::IsOk() const {
37 if (max_bit_rate < 32000 && max_bit_rate != -1) 60 if (max_bit_rate < 32000 && max_bit_rate != -1)
38 return false; 61 return false;
39 if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) 62 if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1)
40 return false; 63 return false;
41 if (adaptive_mode && !bwinfo) 64 if (adaptive_mode && !bwinfo)
42 return false; 65 return false;
43 switch (sample_rate_hz) { 66 switch (sample_rate_hz) {
44 case 16000: 67 case 16000:
45 if (max_bit_rate > 53400) 68 if (max_bit_rate > 53400)
(...skipping 20 matching lines...) Expand all
66 RecreateEncoderInstance(config); 89 RecreateEncoderInstance(config);
67 } 90 }
68 91
69 template <typename T> 92 template <typename T>
70 AudioEncoderIsacT<T>::AudioEncoderIsacT( 93 AudioEncoderIsacT<T>::AudioEncoderIsacT(
71 const CodecInst& codec_inst, 94 const CodecInst& codec_inst,
72 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) 95 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo)
73 : AudioEncoderIsacT(CreateIsacConfig<T>(codec_inst, bwinfo)) {} 96 : AudioEncoderIsacT(CreateIsacConfig<T>(codec_inst, bwinfo)) {}
74 97
75 template <typename T> 98 template <typename T>
99 AudioEncoderIsacT<T>::AudioEncoderIsacT(int payload_type,
100 const SdpAudioFormat& format)
101 : AudioEncoderIsacT(CreateIsacConfig<T>(payload_type, format)) {}
102
103 template <typename T>
104 rtc::Optional<AudioFormatInfo> AudioEncoderIsacT<T>::QueryAudioFormat(
105 const SdpAudioFormat& format) {
106 if (STR_CASE_CMP(format.name.c_str(), GetPayloadName()) == 0) {
107 Config config = CreateIsacConfig<T>(0, format);
108 if (config.IsOk()) {
109 return rtc::Optional<AudioFormatInfo>({
110 config.sample_rate_hz, 1, config.bit_rate, 10000,
111 (config.sample_rate_hz == 16000) ? 32000 : 56000});
112 }
113 }
114 return rtc::Optional<AudioFormatInfo>();
115 }
116
117 template <typename T>
76 AudioEncoderIsacT<T>::~AudioEncoderIsacT() { 118 AudioEncoderIsacT<T>::~AudioEncoderIsacT() {
77 RTC_CHECK_EQ(0, T::Free(isac_state_)); 119 RTC_CHECK_EQ(0, T::Free(isac_state_));
78 } 120 }
79 121
80 template <typename T> 122 template <typename T>
81 int AudioEncoderIsacT<T>::SampleRateHz() const { 123 int AudioEncoderIsacT<T>::SampleRateHz() const {
82 return T::EncSampRate(isac_state_); 124 return T::EncSampRate(isac_state_);
83 } 125 }
84 126
85 template <typename T> 127 template <typename T>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // we get an encoding that isn't bit-for-bit identical with what a combined 222 // we get an encoding that isn't bit-for-bit identical with what a combined
181 // encoder+decoder object produces. 223 // encoder+decoder object produces.
182 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); 224 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz));
183 225
184 config_ = config; 226 config_ = config;
185 } 227 }
186 228
187 } // namespace webrtc 229 } // namespace webrtc
188 230
189 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ 231 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698