1/*
2 *  Copyright (c) 2015 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_decoder_pcm16b.h"
12
13#include "webrtc/base/checks.h"
14#include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h"
15
16namespace webrtc {
17
18AudioDecoderPcm16B::AudioDecoderPcm16B(size_t num_channels)
19    : num_channels_(num_channels) {
20  RTC_DCHECK_GE(num_channels, 1u);
21}
22
23void AudioDecoderPcm16B::Reset() {}
24
25size_t AudioDecoderPcm16B::Channels() const {
26  return num_channels_;
27}
28
29int AudioDecoderPcm16B::DecodeInternal(const uint8_t* encoded,
30                                       size_t encoded_len,
31                                       int sample_rate_hz,
32                                       int16_t* decoded,
33                                       SpeechType* speech_type) {
34  RTC_DCHECK(sample_rate_hz == 8000 || sample_rate_hz == 16000 ||
35             sample_rate_hz == 32000 || sample_rate_hz == 48000)
36      << "Unsupported sample rate " << sample_rate_hz;
37  size_t ret = WebRtcPcm16b_Decode(encoded, encoded_len, decoded);
38  *speech_type = ConvertSpeechType(1);
39  return static_cast<int>(ret);
40}
41
42int AudioDecoderPcm16B::PacketDuration(const uint8_t* encoded,
43                                       size_t encoded_len) const {
44  // Two encoded byte per sample per channel.
45  return static_cast<int>(encoded_len / (2 * Channels()));
46}
47
48}  // namespace webrtc
49