Line data Source code
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 : #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_
12 : #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_
13 :
14 : #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h"
15 :
16 : #include "webrtc/base/checks.h"
17 :
18 : namespace webrtc {
19 :
20 : template <typename T>
21 0 : AudioDecoderIsacT<T>::AudioDecoderIsacT(int sample_rate_hz)
22 0 : : AudioDecoderIsacT(sample_rate_hz, nullptr) {}
23 :
24 : template <typename T>
25 0 : AudioDecoderIsacT<T>::AudioDecoderIsacT(
26 : int sample_rate_hz,
27 : const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo)
28 0 : : sample_rate_hz_(sample_rate_hz), bwinfo_(bwinfo) {
29 0 : RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000)
30 0 : << "Unsupported sample rate " << sample_rate_hz;
31 0 : RTC_CHECK_EQ(0, T::Create(&isac_state_));
32 0 : T::DecoderInit(isac_state_);
33 0 : if (bwinfo_) {
34 : IsacBandwidthInfo bi;
35 0 : T::GetBandwidthInfo(isac_state_, &bi);
36 0 : bwinfo_->Set(bi);
37 : }
38 0 : RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz_));
39 0 : }
40 :
41 : template <typename T>
42 0 : AudioDecoderIsacT<T>::~AudioDecoderIsacT() {
43 0 : RTC_CHECK_EQ(0, T::Free(isac_state_));
44 0 : }
45 :
46 : template <typename T>
47 0 : int AudioDecoderIsacT<T>::DecodeInternal(const uint8_t* encoded,
48 : size_t encoded_len,
49 : int sample_rate_hz,
50 : int16_t* decoded,
51 : SpeechType* speech_type) {
52 0 : RTC_CHECK_EQ(sample_rate_hz_, sample_rate_hz);
53 0 : int16_t temp_type = 1; // Default is speech.
54 : int ret =
55 0 : T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type);
56 0 : *speech_type = ConvertSpeechType(temp_type);
57 0 : return ret;
58 : }
59 :
60 : template <typename T>
61 0 : bool AudioDecoderIsacT<T>::HasDecodePlc() const {
62 0 : return false;
63 : }
64 :
65 : template <typename T>
66 0 : size_t AudioDecoderIsacT<T>::DecodePlc(size_t num_frames, int16_t* decoded) {
67 0 : return T::DecodePlc(isac_state_, decoded, num_frames);
68 : }
69 :
70 : template <typename T>
71 0 : void AudioDecoderIsacT<T>::Reset() {
72 0 : T::DecoderInit(isac_state_);
73 0 : }
74 :
75 : template <typename T>
76 0 : int AudioDecoderIsacT<T>::IncomingPacket(const uint8_t* payload,
77 : size_t payload_len,
78 : uint16_t rtp_sequence_number,
79 : uint32_t rtp_timestamp,
80 : uint32_t arrival_timestamp) {
81 0 : int ret = T::UpdateBwEstimate(isac_state_, payload, payload_len,
82 : rtp_sequence_number, rtp_timestamp,
83 0 : arrival_timestamp);
84 0 : if (bwinfo_) {
85 : IsacBandwidthInfo bwinfo;
86 0 : T::GetBandwidthInfo(isac_state_, &bwinfo);
87 0 : bwinfo_->Set(bwinfo);
88 : }
89 0 : return ret;
90 : }
91 :
92 : template <typename T>
93 0 : int AudioDecoderIsacT<T>::ErrorCode() {
94 0 : return T::GetErrorCode(isac_state_);
95 : }
96 :
97 : template <typename T>
98 0 : int AudioDecoderIsacT<T>::SampleRateHz() const {
99 0 : return sample_rate_hz_;
100 : }
101 :
102 : template <typename T>
103 0 : size_t AudioDecoderIsacT<T>::Channels() const {
104 0 : return 1;
105 : }
106 :
107 : } // namespace webrtc
108 :
109 : #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_DECODER_ISAC_T_IMPL_H_
|