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/modules/audio_coding/codecs/audio_decoder.h" | 16 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" |
17 #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" | 18 #include "webrtc/modules/audio_coding/codecs/isac/locked_bandwidth_info.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 | 21 |
| 22 struct CodecInst; |
| 23 |
22 template <typename T> | 24 template <typename T> |
23 class AudioEncoderIsacT final : public AudioEncoder { | 25 class AudioEncoderIsacT final : public AudioEncoder { |
24 public: | 26 public: |
25 // Allowed combinations of sample rate, frame size, and bit rate are | 27 // Allowed combinations of sample rate, frame size, and bit rate are |
26 // - 16000 Hz, 30 ms, 10000-32000 bps | 28 // - 16000 Hz, 30 ms, 10000-32000 bps |
27 // - 16000 Hz, 60 ms, 10000-32000 bps | 29 // - 16000 Hz, 60 ms, 10000-32000 bps |
28 // - 32000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support) | 30 // - 32000 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) | 31 // - 48000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support) |
30 struct Config { | 32 struct Config { |
31 Config(); | |
32 bool IsOk() const; | 33 bool IsOk() const; |
33 | 34 |
34 LockedIsacBandwidthInfo* bwinfo; | 35 LockedIsacBandwidthInfo* bwinfo = nullptr; |
35 | 36 |
36 int payload_type; | 37 int payload_type = 103; |
37 int sample_rate_hz; | 38 int sample_rate_hz = 16000; |
38 int frame_size_ms; | 39 int frame_size_ms = 30; |
39 int bit_rate; // Limit on the short-term average bit rate, in bits/s. | 40 int bit_rate = kDefaultBitRate; // Limit on the short-term average bit |
40 int max_payload_size_bytes; | 41 // rate, in bits/s. |
41 int max_bit_rate; | 42 int max_payload_size_bytes = -1; |
| 43 int max_bit_rate = -1; |
42 | 44 |
43 // If true, the encoder will dynamically adjust frame size and bit rate; | 45 // If true, the encoder will dynamically adjust frame size and bit rate; |
44 // the configured values are then merely the starting point. | 46 // the configured values are then merely the starting point. |
45 bool adaptive_mode; | 47 bool adaptive_mode = false; |
46 | 48 |
47 // In adaptive mode, prevent adaptive changes to the frame size. (Not used | 49 // In adaptive mode, prevent adaptive changes to the frame size. (Not used |
48 // in nonadaptive mode.) | 50 // in nonadaptive mode.) |
49 bool enforce_frame_size; | 51 bool enforce_frame_size = false; |
50 }; | 52 }; |
51 | 53 |
52 explicit AudioEncoderIsacT(const Config& config); | 54 explicit AudioEncoderIsacT(const Config& config); |
| 55 explicit AudioEncoderIsacT(const CodecInst& codec_inst, |
| 56 LockedIsacBandwidthInfo* bwinfo); |
53 ~AudioEncoderIsacT() override; | 57 ~AudioEncoderIsacT() override; |
54 | 58 |
| 59 size_t MaxEncodedBytes() const override; |
55 int SampleRateHz() const override; | 60 int SampleRateHz() const override; |
56 int NumChannels() const override; | 61 int NumChannels() const override; |
57 size_t MaxEncodedBytes() const override; | |
58 size_t Num10MsFramesInNextPacket() const override; | 62 size_t Num10MsFramesInNextPacket() const override; |
59 size_t Max10MsFramesInAPacket() const override; | 63 size_t Max10MsFramesInAPacket() const override; |
60 int GetTargetBitrate() const override; | 64 int GetTargetBitrate() const override; |
61 EncodedInfo EncodeInternal(uint32_t rtp_timestamp, | 65 EncodedInfo EncodeInternal(uint32_t rtp_timestamp, |
62 const int16_t* audio, | 66 const int16_t* audio, |
63 size_t max_encoded_bytes, | 67 size_t max_encoded_bytes, |
64 uint8_t* encoded) override; | 68 uint8_t* encoded) override; |
| 69 void Reset() override; |
| 70 void SetMaxPayloadSize(int max_payload_size_bytes) override; |
| 71 void SetMaxBitrate(int max_rate_bps) override; |
65 | 72 |
66 private: | 73 private: |
67 // This value is taken from STREAM_SIZE_MAX_60 for iSAC float (60 ms) and | 74 // This value is taken from STREAM_SIZE_MAX_60 for iSAC float (60 ms) and |
68 // STREAM_MAXW16_60MS for iSAC fix (60 ms). | 75 // STREAM_MAXW16_60MS for iSAC fix (60 ms). |
69 static const size_t kSufficientEncodeBufferSizeBytes = 400; | 76 static const size_t kSufficientEncodeBufferSizeBytes = 400; |
70 | 77 |
71 const int payload_type_; | 78 static const int kDefaultBitRate = 32000; |
72 typename T::instance_type* isac_state_; | 79 |
73 LockedIsacBandwidthInfo* bwinfo_; | 80 // Recreate the iSAC encoder instance with the given settings, and save them. |
| 81 void RecreateEncoderInstance(const Config& config); |
| 82 |
| 83 Config config_; |
| 84 typename T::instance_type* isac_state_ = nullptr; |
| 85 LockedIsacBandwidthInfo* bwinfo_ = nullptr; |
74 | 86 |
75 // Have we accepted input but not yet emitted it in a packet? | 87 // Have we accepted input but not yet emitted it in a packet? |
76 bool packet_in_progress_; | 88 bool packet_in_progress_ = false; |
77 | 89 |
78 // Timestamp of the first input of the currently in-progress packet. | 90 // Timestamp of the first input of the currently in-progress packet. |
79 uint32_t packet_timestamp_; | 91 uint32_t packet_timestamp_; |
80 | 92 |
81 // Timestamp of the previously encoded packet. | 93 // Timestamp of the previously encoded packet. |
82 uint32_t last_encoded_timestamp_; | 94 uint32_t last_encoded_timestamp_; |
83 | 95 |
84 const int target_bitrate_bps_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(AudioEncoderIsacT); | 96 DISALLOW_COPY_AND_ASSIGN(AudioEncoderIsacT); |
87 }; | 97 }; |
88 | 98 |
89 template <typename T> | 99 template <typename T> |
90 class AudioDecoderIsacT final : public AudioDecoder { | 100 class AudioDecoderIsacT final : public AudioDecoder { |
91 public: | 101 public: |
92 AudioDecoderIsacT(); | 102 AudioDecoderIsacT(); |
93 explicit AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo); | 103 explicit AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo); |
94 ~AudioDecoderIsacT() override; | 104 ~AudioDecoderIsacT() override; |
95 | 105 |
(...skipping 16 matching lines...) Expand all Loading... |
112 private: | 122 private: |
113 typename T::instance_type* isac_state_; | 123 typename T::instance_type* isac_state_; |
114 LockedIsacBandwidthInfo* bwinfo_; | 124 LockedIsacBandwidthInfo* bwinfo_; |
115 int decoder_sample_rate_hz_; | 125 int decoder_sample_rate_hz_; |
116 | 126 |
117 DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacT); | 127 DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacT); |
118 }; | 128 }; |
119 | 129 |
120 } // namespace webrtc | 130 } // namespace webrtc |
121 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_ | 131 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_ |
OLD | NEW |