| OLD | NEW |
| 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 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" | 11 #include "webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.h" |
| 12 | 12 |
| 13 #include <limits> | 13 #include <limits> |
| 14 | 14 |
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/string_to_number.h" |
| 16 #include "webrtc/common_types.h" | 17 #include "webrtc/common_types.h" |
| 17 #include "webrtc/modules/audio_coding/codecs/g711/g711_interface.h" | 18 #include "webrtc/modules/audio_coding/codecs/g711/g711_interface.h" |
| 18 | 19 |
| 19 namespace webrtc { | 20 namespace webrtc { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 template <typename T> | 24 template <typename T> |
| 24 typename T::Config CreateConfig(const CodecInst& codec_inst) { | 25 typename T::Config CreateConfig(const CodecInst& codec_inst) { |
| 25 typename T::Config config; | 26 typename T::Config config; |
| 26 config.frame_size_ms = codec_inst.pacsize / 8; | 27 config.frame_size_ms = codec_inst.pacsize / 8; |
| 27 config.num_channels = codec_inst.channels; | 28 config.num_channels = codec_inst.channels; |
| 28 config.payload_type = codec_inst.pltype; | 29 config.payload_type = codec_inst.pltype; |
| 29 return config; | 30 return config; |
| 30 } | 31 } |
| 31 | 32 |
| 33 template <typename T> |
| 34 typename T::Config CreateConfig(int payload_type, |
| 35 const SdpAudioFormat& format) { |
| 36 typename T::Config config; |
| 37 config.frame_size_ms = 20; |
| 38 auto ptime_iter = format.parameters.find("ptime"); |
| 39 if (ptime_iter != format.parameters.end()) { |
| 40 auto ptime = rtc::StringToNumber<int>(ptime_iter->second); |
| 41 if (ptime && *ptime > 0) { |
| 42 config.frame_size_ms = *ptime; |
| 43 } |
| 44 } |
| 45 config.num_channels = format.num_channels; |
| 46 config.payload_type = payload_type; |
| 47 return config; |
| 48 } |
| 49 |
| 50 template <typename T> |
| 51 rtc::Optional<AudioCodecInfo> QueryAudioEncoderImpl( |
| 52 const SdpAudioFormat& format) { |
| 53 if (STR_CASE_CMP(format.name.c_str(), T::GetPayloadName()) == 0 && |
| 54 format.clockrate_hz == 8000 && format.num_channels >= 1 && |
| 55 CreateConfig<T>(0, format).IsOk()) { |
| 56 return rtc::Optional<AudioCodecInfo>({8000, format.num_channels, 64000}); |
| 57 } |
| 58 return rtc::Optional<AudioCodecInfo>(); |
| 59 } |
| 60 |
| 32 } // namespace | 61 } // namespace |
| 33 | 62 |
| 34 bool AudioEncoderPcm::Config::IsOk() const { | 63 bool AudioEncoderPcm::Config::IsOk() const { |
| 35 return (frame_size_ms % 10 == 0) && (num_channels >= 1); | 64 return (frame_size_ms % 10 == 0) && (num_channels >= 1); |
| 36 } | 65 } |
| 37 | 66 |
| 38 AudioEncoderPcm::AudioEncoderPcm(const Config& config, int sample_rate_hz) | 67 AudioEncoderPcm::AudioEncoderPcm(const Config& config, int sample_rate_hz) |
| 39 : sample_rate_hz_(sample_rate_hz), | 68 : sample_rate_hz_(sample_rate_hz), |
| 40 num_channels_(config.num_channels), | 69 num_channels_(config.num_channels), |
| 41 payload_type_(config.payload_type), | 70 payload_type_(config.payload_type), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 return info; | 129 return info; |
| 101 } | 130 } |
| 102 | 131 |
| 103 void AudioEncoderPcm::Reset() { | 132 void AudioEncoderPcm::Reset() { |
| 104 speech_buffer_.clear(); | 133 speech_buffer_.clear(); |
| 105 } | 134 } |
| 106 | 135 |
| 107 AudioEncoderPcmA::AudioEncoderPcmA(const CodecInst& codec_inst) | 136 AudioEncoderPcmA::AudioEncoderPcmA(const CodecInst& codec_inst) |
| 108 : AudioEncoderPcmA(CreateConfig<AudioEncoderPcmA>(codec_inst)) {} | 137 : AudioEncoderPcmA(CreateConfig<AudioEncoderPcmA>(codec_inst)) {} |
| 109 | 138 |
| 139 AudioEncoderPcmA::AudioEncoderPcmA(int payload_type, |
| 140 const SdpAudioFormat& format) |
| 141 : AudioEncoderPcmA(CreateConfig<AudioEncoderPcmA>(payload_type, format)) {} |
| 142 |
| 143 rtc::Optional<AudioCodecInfo> AudioEncoderPcmA::QueryAudioEncoder( |
| 144 const SdpAudioFormat& format) { |
| 145 return QueryAudioEncoderImpl<AudioEncoderPcmA>(format); |
| 146 } |
| 147 |
| 110 size_t AudioEncoderPcmA::EncodeCall(const int16_t* audio, | 148 size_t AudioEncoderPcmA::EncodeCall(const int16_t* audio, |
| 111 size_t input_len, | 149 size_t input_len, |
| 112 uint8_t* encoded) { | 150 uint8_t* encoded) { |
| 113 return WebRtcG711_EncodeA(audio, input_len, encoded); | 151 return WebRtcG711_EncodeA(audio, input_len, encoded); |
| 114 } | 152 } |
| 115 | 153 |
| 116 size_t AudioEncoderPcmA::BytesPerSample() const { | 154 size_t AudioEncoderPcmA::BytesPerSample() const { |
| 117 return 1; | 155 return 1; |
| 118 } | 156 } |
| 119 | 157 |
| 120 AudioEncoder::CodecType AudioEncoderPcmA::GetCodecType() const { | 158 AudioEncoder::CodecType AudioEncoderPcmA::GetCodecType() const { |
| 121 return AudioEncoder::CodecType::kPcmA; | 159 return AudioEncoder::CodecType::kPcmA; |
| 122 } | 160 } |
| 123 | 161 |
| 124 AudioEncoderPcmU::AudioEncoderPcmU(const CodecInst& codec_inst) | 162 AudioEncoderPcmU::AudioEncoderPcmU(const CodecInst& codec_inst) |
| 125 : AudioEncoderPcmU(CreateConfig<AudioEncoderPcmU>(codec_inst)) {} | 163 : AudioEncoderPcmU(CreateConfig<AudioEncoderPcmU>(codec_inst)) {} |
| 126 | 164 |
| 165 AudioEncoderPcmU::AudioEncoderPcmU(int payload_type, |
| 166 const SdpAudioFormat& format) |
| 167 : AudioEncoderPcmU(CreateConfig<AudioEncoderPcmU>(payload_type, format)) {} |
| 168 |
| 169 rtc::Optional<AudioCodecInfo> AudioEncoderPcmU::QueryAudioEncoder( |
| 170 const SdpAudioFormat& format) { |
| 171 return QueryAudioEncoderImpl<AudioEncoderPcmU>(format); |
| 172 } |
| 173 |
| 127 size_t AudioEncoderPcmU::EncodeCall(const int16_t* audio, | 174 size_t AudioEncoderPcmU::EncodeCall(const int16_t* audio, |
| 128 size_t input_len, | 175 size_t input_len, |
| 129 uint8_t* encoded) { | 176 uint8_t* encoded) { |
| 130 return WebRtcG711_EncodeU(audio, input_len, encoded); | 177 return WebRtcG711_EncodeU(audio, input_len, encoded); |
| 131 } | 178 } |
| 132 | 179 |
| 133 size_t AudioEncoderPcmU::BytesPerSample() const { | 180 size_t AudioEncoderPcmU::BytesPerSample() const { |
| 134 return 1; | 181 return 1; |
| 135 } | 182 } |
| 136 | 183 |
| 137 AudioEncoder::CodecType AudioEncoderPcmU::GetCodecType() const { | 184 AudioEncoder::CodecType AudioEncoderPcmU::GetCodecType() const { |
| 138 return AudioEncoder::CodecType::kPcmU; | 185 return AudioEncoder::CodecType::kPcmU; |
| 139 } | 186 } |
| 140 | 187 |
| 141 } // namespace webrtc | 188 } // namespace webrtc |
| OLD | NEW |