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_OPUS_AUDIO_ENCODER_OPUS_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ |
13 | 13 |
14 #include <functional> | 14 #include <functional> |
15 #include <memory> | 15 #include <memory> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "webrtc/base/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
20 #include "webrtc/base/optional.h" | 20 #include "webrtc/base/optional.h" |
21 #include "webrtc/common_audio/smoothing_filter.h" | |
21 #include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_networ k_adaptor.h" | 22 #include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_networ k_adaptor.h" |
22 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" | 23 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" |
23 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" | 24 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" |
24 | 25 |
25 namespace webrtc { | 26 namespace webrtc { |
26 | 27 |
27 struct CodecInst; | 28 struct CodecInst; |
28 | 29 |
29 class AudioEncoderOpus final : public AudioEncoder { | 30 class AudioEncoderOpus final : public AudioEncoder { |
30 public: | 31 public: |
(...skipping 25 matching lines...) Expand all Loading... | |
56 int max_playback_rate_hz = 48000; | 57 int max_playback_rate_hz = 48000; |
57 int complexity = kDefaultComplexity; | 58 int complexity = kDefaultComplexity; |
58 // This value may change in the struct's constructor. | 59 // This value may change in the struct's constructor. |
59 int low_rate_complexity = kDefaultComplexity; | 60 int low_rate_complexity = kDefaultComplexity; |
60 // low_rate_complexity is used when the bitrate is below this threshold. | 61 // low_rate_complexity is used when the bitrate is below this threshold. |
61 int complexity_threshold_bps = 12500; | 62 int complexity_threshold_bps = 12500; |
62 int complexity_threshold_window_bps = 1500; | 63 int complexity_threshold_window_bps = 1500; |
63 bool dtx_enabled = false; | 64 bool dtx_enabled = false; |
64 std::vector<int> supported_frame_lengths_ms; | 65 std::vector<int> supported_frame_lengths_ms; |
65 const Clock* clock = nullptr; | 66 const Clock* clock = nullptr; |
67 int update_uplink_bandwidth_interval_ms = 200; | |
66 | 68 |
67 private: | 69 private: |
68 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) | 70 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) |
69 // If we are on Android, iOS and/or ARM, use a lower complexity setting as | 71 // If we are on Android, iOS and/or ARM, use a lower complexity setting as |
70 // default, to save encoder complexity. | 72 // default, to save encoder complexity. |
71 static const int kDefaultComplexity = 5; | 73 static const int kDefaultComplexity = 5; |
72 #else | 74 #else |
73 static const int kDefaultComplexity = 9; | 75 static const int kDefaultComplexity = 9; |
74 #endif | 76 #endif |
75 }; | 77 }; |
76 | 78 |
77 using AudioNetworkAdaptorCreator = | 79 using AudioNetworkAdaptorCreator = |
78 std::function<std::unique_ptr<AudioNetworkAdaptor>(const std::string&, | 80 std::function<std::unique_ptr<AudioNetworkAdaptor>(const std::string&, |
79 const Clock*)>; | 81 const Clock*)>; |
80 AudioEncoderOpus( | 82 AudioEncoderOpus( |
81 const Config& config, | 83 const Config& config, |
82 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator = nullptr); | 84 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator = nullptr, |
85 std::unique_ptr<SmoothingFilter> bitrate_smoother = nullptr); | |
83 | 86 |
84 explicit AudioEncoderOpus(const CodecInst& codec_inst); | 87 explicit AudioEncoderOpus(const CodecInst& codec_inst); |
85 | 88 |
86 ~AudioEncoderOpus() override; | 89 ~AudioEncoderOpus() override; |
87 | 90 |
88 int SampleRateHz() const override; | 91 int SampleRateHz() const override; |
89 size_t NumChannels() const override; | 92 size_t NumChannels() const override; |
90 size_t Num10MsFramesInNextPacket() const override; | 93 size_t Num10MsFramesInNextPacket() const override; |
91 size_t Max10MsFramesInAPacket() const override; | 94 size_t Max10MsFramesInAPacket() const override; |
92 int GetTargetBitrate() const override; | 95 int GetTargetBitrate() const override; |
93 | 96 |
94 void Reset() override; | 97 void Reset() override; |
95 bool SetFec(bool enable) override; | 98 bool SetFec(bool enable) override; |
96 | 99 |
97 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice | 100 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice |
98 // being inactive. During that, it still sends 2 packets (one for content, one | 101 // being inactive. During that, it still sends 2 packets (one for content, one |
99 // for signaling) about every 400 ms. | 102 // for signaling) about every 400 ms. |
100 bool SetDtx(bool enable) override; | 103 bool SetDtx(bool enable) override; |
101 bool GetDtx() const override; | 104 bool GetDtx() const override; |
102 | 105 |
103 bool SetApplication(Application application) override; | 106 bool SetApplication(Application application) override; |
104 void SetMaxPlaybackRate(int frequency_hz) override; | 107 void SetMaxPlaybackRate(int frequency_hz) override; |
105 bool EnableAudioNetworkAdaptor(const std::string& config_string, | 108 bool EnableAudioNetworkAdaptor(const std::string& config_string, |
106 const Clock* clock) override; | 109 const Clock* clock) override; |
107 void DisableAudioNetworkAdaptor() override; | 110 void DisableAudioNetworkAdaptor() override; |
108 void OnReceivedUplinkBandwidth(int uplink_bandwidth_bps) override; | |
109 void OnReceivedUplinkPacketLossFraction( | 111 void OnReceivedUplinkPacketLossFraction( |
110 float uplink_packet_loss_fraction) override; | 112 float uplink_packet_loss_fraction) override; |
111 void OnReceivedTargetAudioBitrate(int target_audio_bitrate_bps) override; | 113 void OnReceivedTargetAudioBitrate( |
114 int target_audio_bitrate_bps, | |
115 rtc::Optional<int64_t> probing_interval_ms) override; | |
112 void OnReceivedRtt(int rtt_ms) override; | 116 void OnReceivedRtt(int rtt_ms) override; |
113 void OnReceivedOverhead(size_t overhead_bytes_per_packet) override; | 117 void OnReceivedOverhead(size_t overhead_bytes_per_packet) override; |
114 void SetReceiverFrameLengthRange(int min_frame_length_ms, | 118 void SetReceiverFrameLengthRange(int min_frame_length_ms, |
115 int max_frame_length_ms) override; | 119 int max_frame_length_ms) override; |
116 rtc::ArrayView<const int> supported_frame_lengths_ms() const { | 120 rtc::ArrayView<const int> supported_frame_lengths_ms() const { |
117 return config_.supported_frame_lengths_ms; | 121 return config_.supported_frame_lengths_ms; |
118 } | 122 } |
119 | 123 |
120 // Getters for testing. | 124 // Getters for testing. |
121 float packet_loss_rate() const { return packet_loss_rate_; } | 125 float packet_loss_rate() const { return packet_loss_rate_; } |
(...skipping 20 matching lines...) Expand all Loading... | |
142 | 146 |
143 // TODO(minyue): remove "override" when we can deprecate | 147 // TODO(minyue): remove "override" when we can deprecate |
144 // |AudioEncoder::SetTargetBitrate|. | 148 // |AudioEncoder::SetTargetBitrate|. |
145 void SetTargetBitrate(int target_bps) override; | 149 void SetTargetBitrate(int target_bps) override; |
146 | 150 |
147 void ApplyAudioNetworkAdaptor(); | 151 void ApplyAudioNetworkAdaptor(); |
148 std::unique_ptr<AudioNetworkAdaptor> DefaultAudioNetworkAdaptorCreator( | 152 std::unique_ptr<AudioNetworkAdaptor> DefaultAudioNetworkAdaptorCreator( |
149 const std::string& config_string, | 153 const std::string& config_string, |
150 const Clock* clock) const; | 154 const Clock* clock) const; |
151 | 155 |
156 void MayUpdateUplinkBandwidth(); | |
157 | |
152 Config config_; | 158 Config config_; |
153 float packet_loss_rate_; | 159 float packet_loss_rate_; |
154 std::vector<int16_t> input_buffer_; | 160 std::vector<int16_t> input_buffer_; |
155 OpusEncInst* inst_; | 161 OpusEncInst* inst_; |
156 uint32_t first_timestamp_in_buffer_; | 162 uint32_t first_timestamp_in_buffer_; |
157 size_t num_channels_to_encode_; | 163 size_t num_channels_to_encode_; |
158 int next_frame_length_ms_; | 164 int next_frame_length_ms_; |
159 int complexity_; | 165 int complexity_; |
160 std::unique_ptr<PacketLossFractionSmoother> packet_loss_fraction_smoother_; | 166 std::unique_ptr<PacketLossFractionSmoother> packet_loss_fraction_smoother_; |
161 AudioNetworkAdaptorCreator audio_network_adaptor_creator_; | 167 AudioNetworkAdaptorCreator audio_network_adaptor_creator_; |
162 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor_; | 168 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor_; |
163 rtc::Optional<size_t> overhead_bytes_per_packet_; | 169 rtc::Optional<size_t> overhead_bytes_per_packet_; |
170 const std::unique_ptr<SmoothingFilter> bitrate_smoother_; | |
171 rtc::Optional<int64_t> last_smoothed_bandwith_update_; | |
minyue-webrtc
2016/12/22 14:51:26
bitrate_smoother_last_update_time_
michaelt
2016/12/22 15:10:10
Done.
| |
164 | 172 |
165 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); | 173 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); |
166 }; | 174 }; |
167 | 175 |
168 } // namespace webrtc | 176 } // namespace webrtc |
169 | 177 |
170 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ | 178 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ |
OLD | NEW |