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 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_ |
13 | 13 |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "webrtc/base/scoped_ptr.h" | |
17 #include "webrtc/base/thread_annotations.h" | |
18 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" | 16 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" |
19 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" | 17 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" |
| 18 #include "webrtc/modules/audio_coding/codecs/isac/locked_bandwidth_info.h" |
20 | 19 |
21 namespace webrtc { | 20 namespace webrtc { |
22 | 21 |
23 class CriticalSectionWrapper; | |
24 | |
25 template <typename T> | 22 template <typename T> |
26 class AudioEncoderDecoderIsacT : public AudioEncoder, public AudioDecoder { | 23 class AudioEncoderIsacT final : public AudioEncoder { |
27 public: | 24 public: |
28 // Allowed combinations of sample rate, frame size, and bit rate are | 25 // Allowed combinations of sample rate, frame size, and bit rate are |
29 // - 16000 Hz, 30 ms, 10000-32000 bps | 26 // - 16000 Hz, 30 ms, 10000-32000 bps |
30 // - 16000 Hz, 60 ms, 10000-32000 bps | 27 // - 16000 Hz, 60 ms, 10000-32000 bps |
31 // - 32000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support) | 28 // - 32000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support) |
32 // - 48000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support) | 29 // - 48000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support) |
33 struct Config { | 30 struct Config { |
34 Config(); | 31 Config(); |
35 bool IsOk() const; | 32 bool IsOk() const; |
36 | 33 |
| 34 LockedIsacBandwidthInfo* bwinfo; |
| 35 |
37 int payload_type; | 36 int payload_type; |
38 int sample_rate_hz; | 37 int sample_rate_hz; |
39 int frame_size_ms; | 38 int frame_size_ms; |
40 int bit_rate; // Limit on the short-term average bit rate, in bits/s. | 39 int bit_rate; // Limit on the short-term average bit rate, in bits/s. |
41 int max_payload_size_bytes; | 40 int max_payload_size_bytes; |
42 int max_bit_rate; | 41 int max_bit_rate; |
43 | 42 |
44 // If true, the encoder will dynamically adjust frame size and bit rate; | 43 // If true, the encoder will dynamically adjust frame size and bit rate; |
45 // the configured values are then merely the starting point. | 44 // the configured values are then merely the starting point. |
46 bool adaptive_mode; | 45 bool adaptive_mode; |
47 | 46 |
48 // In adaptive mode, prevent adaptive changes to the frame size. (Not used | 47 // In adaptive mode, prevent adaptive changes to the frame size. (Not used |
49 // in nonadaptive mode.) | 48 // in nonadaptive mode.) |
50 bool enforce_frame_size; | 49 bool enforce_frame_size; |
51 }; | 50 }; |
52 | 51 |
53 explicit AudioEncoderDecoderIsacT(const Config& config); | 52 explicit AudioEncoderIsacT(const Config& config); |
54 ~AudioEncoderDecoderIsacT() override; | 53 ~AudioEncoderIsacT() override; |
55 | 54 |
56 // AudioEncoder public methods. | |
57 int SampleRateHz() const override; | 55 int SampleRateHz() const override; |
58 int NumChannels() const override; | 56 int NumChannels() const override; |
59 size_t MaxEncodedBytes() const override; | 57 size_t MaxEncodedBytes() const override; |
60 int Num10MsFramesInNextPacket() const override; | 58 int Num10MsFramesInNextPacket() const override; |
61 int Max10MsFramesInAPacket() const override; | 59 int Max10MsFramesInAPacket() const override; |
62 int GetTargetBitrate() const override; | 60 int GetTargetBitrate() const override; |
| 61 EncodedInfo EncodeInternal(uint32_t rtp_timestamp, |
| 62 const int16_t* audio, |
| 63 size_t max_encoded_bytes, |
| 64 uint8_t* encoded) override; |
63 | 65 |
64 // AudioDecoder methods. | 66 private: |
| 67 // This value is taken from STREAM_SIZE_MAX_60 for iSAC float (60 ms) and |
| 68 // STREAM_MAXW16_60MS for iSAC fix (60 ms). |
| 69 static const size_t kSufficientEncodeBufferSizeBytes = 400; |
| 70 |
| 71 const int payload_type_; |
| 72 typename T::instance_type* isac_state_; |
| 73 LockedIsacBandwidthInfo* bwinfo_; |
| 74 |
| 75 // Have we accepted input but not yet emitted it in a packet? |
| 76 bool packet_in_progress_; |
| 77 |
| 78 // Timestamp of the first input of the currently in-progress packet. |
| 79 uint32_t packet_timestamp_; |
| 80 |
| 81 // Timestamp of the previously encoded packet. |
| 82 uint32_t last_encoded_timestamp_; |
| 83 |
| 84 const int target_bitrate_bps_; |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(AudioEncoderIsacT); |
| 87 }; |
| 88 |
| 89 template <typename T> |
| 90 class AudioDecoderIsacT final : public AudioDecoder { |
| 91 public: |
| 92 AudioDecoderIsacT(); |
| 93 explicit AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo); |
| 94 ~AudioDecoderIsacT() override; |
| 95 |
65 bool HasDecodePlc() const override; | 96 bool HasDecodePlc() const override; |
66 int DecodePlc(int num_frames, int16_t* decoded) override; | 97 int DecodePlc(int num_frames, int16_t* decoded) override; |
67 int Init() override; | 98 int Init() override; |
68 int IncomingPacket(const uint8_t* payload, | 99 int IncomingPacket(const uint8_t* payload, |
69 size_t payload_len, | 100 size_t payload_len, |
70 uint16_t rtp_sequence_number, | 101 uint16_t rtp_sequence_number, |
71 uint32_t rtp_timestamp, | 102 uint32_t rtp_timestamp, |
72 uint32_t arrival_timestamp) override; | 103 uint32_t arrival_timestamp) override; |
73 int ErrorCode() override; | 104 int ErrorCode() override; |
74 size_t Channels() const override { return 1; } | 105 size_t Channels() const override; |
75 | |
76 // AudioEncoder protected method. | |
77 EncodedInfo EncodeInternal(uint32_t rtp_timestamp, | |
78 const int16_t* audio, | |
79 size_t max_encoded_bytes, | |
80 uint8_t* encoded) override; | |
81 | |
82 // AudioDecoder protected method. | |
83 int DecodeInternal(const uint8_t* encoded, | 106 int DecodeInternal(const uint8_t* encoded, |
84 size_t encoded_len, | 107 size_t encoded_len, |
85 int sample_rate_hz, | 108 int sample_rate_hz, |
86 int16_t* decoded, | 109 int16_t* decoded, |
87 SpeechType* speech_type) override; | 110 SpeechType* speech_type) override; |
88 | 111 |
89 private: | 112 private: |
90 // This value is taken from STREAM_SIZE_MAX_60 for iSAC float (60 ms) and | 113 typename T::instance_type* isac_state_; |
91 // STREAM_MAXW16_60MS for iSAC fix (60 ms). | 114 LockedIsacBandwidthInfo* bwinfo_; |
92 static const size_t kSufficientEncodeBufferSizeBytes = 400; | 115 int decoder_sample_rate_hz_; |
93 | 116 |
94 const int payload_type_; | 117 DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacT); |
95 | |
96 // iSAC encoder/decoder state, guarded by a mutex to ensure that encode calls | |
97 // from one thread won't clash with decode calls from another thread. | |
98 // Note: PT_GUARDED_BY is disabled since it is not yet supported by clang. | |
99 const rtc::scoped_ptr<CriticalSectionWrapper> state_lock_; | |
100 typename T::instance_type* isac_state_ | |
101 GUARDED_BY(state_lock_) /* PT_GUARDED_BY(lock_)*/; | |
102 | |
103 int decoder_sample_rate_hz_ GUARDED_BY(state_lock_); | |
104 | |
105 // Must be acquired before state_lock_. | |
106 const rtc::scoped_ptr<CriticalSectionWrapper> lock_; | |
107 | |
108 // Have we accepted input but not yet emitted it in a packet? | |
109 bool packet_in_progress_ GUARDED_BY(lock_); | |
110 | |
111 // Timestamp of the first input of the currently in-progress packet. | |
112 uint32_t packet_timestamp_ GUARDED_BY(lock_); | |
113 | |
114 // Timestamp of the previously encoded packet. | |
115 uint32_t last_encoded_timestamp_ GUARDED_BY(lock_); | |
116 | |
117 const int target_bitrate_bps_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(AudioEncoderDecoderIsacT); | |
120 }; | |
121 | |
122 struct CodecInst; | |
123 | |
124 class AudioEncoderDecoderMutableIsac : public AudioEncoderMutable, | |
125 public AudioDecoder { | |
126 public: | |
127 virtual void UpdateSettings(const CodecInst& codec_inst) = 0; | |
128 }; | 118 }; |
129 | 119 |
130 } // namespace webrtc | 120 } // namespace webrtc |
131 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_ | 121 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_ |
OLD | NEW |