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/pcm16b/audio_encoder_pcm16b.h" | 11 #include "webrtc/modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/string_to_number.h" |
14 #include "webrtc/common_types.h" | 15 #include "webrtc/common_types.h" |
15 #include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h" | 16 #include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h" |
16 | 17 |
17 namespace webrtc { | 18 namespace webrtc { |
18 | 19 |
19 size_t AudioEncoderPcm16B::EncodeCall(const int16_t* audio, | 20 size_t AudioEncoderPcm16B::EncodeCall(const int16_t* audio, |
20 size_t input_len, | 21 size_t input_len, |
21 uint8_t* encoded) { | 22 uint8_t* encoded) { |
22 return WebRtcPcm16b_Encode(audio, input_len, encoded); | 23 return WebRtcPcm16b_Encode(audio, input_len, encoded); |
23 } | 24 } |
24 | 25 |
25 size_t AudioEncoderPcm16B::BytesPerSample() const { | 26 size_t AudioEncoderPcm16B::BytesPerSample() const { |
26 return 2; | 27 return 2; |
27 } | 28 } |
28 | 29 |
29 AudioEncoder::CodecType AudioEncoderPcm16B::GetCodecType() const { | 30 AudioEncoder::CodecType AudioEncoderPcm16B::GetCodecType() const { |
30 return CodecType::kOther; | 31 return CodecType::kOther; |
31 } | 32 } |
32 | 33 |
33 namespace { | 34 namespace { |
34 AudioEncoderPcm16B::Config CreateConfig(const CodecInst& codec_inst) { | 35 AudioEncoderPcm16B::Config CreateConfig(const CodecInst& codec_inst) { |
35 AudioEncoderPcm16B::Config config; | 36 AudioEncoderPcm16B::Config config; |
36 config.num_channels = codec_inst.channels; | 37 config.num_channels = codec_inst.channels; |
37 config.sample_rate_hz = codec_inst.plfreq; | 38 config.sample_rate_hz = codec_inst.plfreq; |
38 config.frame_size_ms = rtc::CheckedDivExact( | 39 config.frame_size_ms = rtc::CheckedDivExact( |
39 codec_inst.pacsize, rtc::CheckedDivExact(config.sample_rate_hz, 1000)); | 40 codec_inst.pacsize, rtc::CheckedDivExact(config.sample_rate_hz, 1000)); |
40 config.payload_type = codec_inst.pltype; | 41 config.payload_type = codec_inst.pltype; |
41 return config; | 42 return config; |
42 } | 43 } |
| 44 |
| 45 AudioEncoderPcm16B::Config CreateConfig(int payload_type, |
| 46 const SdpAudioFormat& format) { |
| 47 AudioEncoderPcm16B::Config config; |
| 48 config.num_channels = format.num_channels; |
| 49 config.sample_rate_hz = format.clockrate_hz; |
| 50 config.frame_size_ms = 10; |
| 51 auto ptime_iter = format.parameters.find("ptime"); |
| 52 if (ptime_iter != format.parameters.end()) { |
| 53 auto ptime = rtc::StringToNumber<int>(ptime_iter->second); |
| 54 if (ptime && *ptime > 0) { |
| 55 config.frame_size_ms = *ptime; |
| 56 } |
| 57 } |
| 58 config.payload_type = payload_type; |
| 59 return config; |
| 60 } |
43 } // namespace | 61 } // namespace |
44 | 62 |
45 bool AudioEncoderPcm16B::Config::IsOk() const { | 63 bool AudioEncoderPcm16B::Config::IsOk() const { |
46 if ((sample_rate_hz != 8000) && (sample_rate_hz != 16000) && | 64 if ((sample_rate_hz != 8000) && (sample_rate_hz != 16000) && |
47 (sample_rate_hz != 32000) && (sample_rate_hz != 48000)) | 65 (sample_rate_hz != 32000) && (sample_rate_hz != 48000)) |
48 return false; | 66 return false; |
49 return AudioEncoderPcm::Config::IsOk(); | 67 return AudioEncoderPcm::Config::IsOk(); |
50 } | 68 } |
51 | 69 |
52 AudioEncoderPcm16B::AudioEncoderPcm16B(const CodecInst& codec_inst) | 70 AudioEncoderPcm16B::AudioEncoderPcm16B(const CodecInst& codec_inst) |
53 : AudioEncoderPcm16B(CreateConfig(codec_inst)) {} | 71 : AudioEncoderPcm16B(CreateConfig(codec_inst)) {} |
54 | 72 |
| 73 AudioEncoderPcm16B::AudioEncoderPcm16B(int payload_type, |
| 74 const SdpAudioFormat& format) |
| 75 : AudioEncoderPcm16B(CreateConfig(payload_type, format)) {} |
| 76 |
| 77 rtc::Optional<AudioFormatInfo> AudioEncoderPcm16B::QueryAudioFormat( |
| 78 const SdpAudioFormat& format) { |
| 79 if (STR_CASE_CMP(format.name.c_str(), GetPayloadName()) == 0 && |
| 80 format.num_channels >= 1) { |
| 81 Config config = CreateConfig(0, format); |
| 82 if (config.IsOk()) { |
| 83 return rtc::Optional<AudioFormatInfo>( |
| 84 {config.sample_rate_hz, config.num_channels, |
| 85 config.sample_rate_hz * 2 * config.num_channels}); |
| 86 } |
| 87 } |
| 88 return rtc::Optional<AudioFormatInfo>(); |
| 89 } |
| 90 |
55 } // namespace webrtc | 91 } // namespace webrtc |
OLD | NEW |