Line data Source code
1 : /*
2 : * Copyright (c) 2014 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/pcm16b/audio_encoder_pcm16b.h"
12 :
13 : #include "webrtc/base/checks.h"
14 : #include "webrtc/common_types.h"
15 : #include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h"
16 :
17 : namespace webrtc {
18 :
19 0 : size_t AudioEncoderPcm16B::EncodeCall(const int16_t* audio,
20 : size_t input_len,
21 : uint8_t* encoded) {
22 0 : return WebRtcPcm16b_Encode(audio, input_len, encoded);
23 : }
24 :
25 0 : size_t AudioEncoderPcm16B::BytesPerSample() const {
26 0 : return 2;
27 : }
28 :
29 0 : AudioEncoder::CodecType AudioEncoderPcm16B::GetCodecType() const {
30 0 : return CodecType::kOther;
31 : }
32 :
33 : namespace {
34 0 : AudioEncoderPcm16B::Config CreateConfig(const CodecInst& codec_inst) {
35 0 : AudioEncoderPcm16B::Config config;
36 0 : config.num_channels = codec_inst.channels;
37 0 : config.sample_rate_hz = codec_inst.plfreq;
38 0 : config.frame_size_ms = rtc::CheckedDivExact(
39 0 : codec_inst.pacsize, rtc::CheckedDivExact(config.sample_rate_hz, 1000));
40 0 : config.payload_type = codec_inst.pltype;
41 0 : return config;
42 : }
43 : } // namespace
44 :
45 0 : bool AudioEncoderPcm16B::Config::IsOk() const {
46 0 : if ((sample_rate_hz != 8000) && (sample_rate_hz != 16000) &&
47 0 : (sample_rate_hz != 32000) && (sample_rate_hz != 48000))
48 0 : return false;
49 0 : return AudioEncoderPcm::Config::IsOk();
50 : }
51 :
52 0 : AudioEncoderPcm16B::AudioEncoderPcm16B(const CodecInst& codec_inst)
53 0 : : AudioEncoderPcm16B(CreateConfig(codec_inst)) {}
54 :
55 : } // namespace webrtc
|