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 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 bool cbr_enabled = false; | 62 bool cbr_enabled = false; |
63 int max_playback_rate_hz = 48000; | 63 int max_playback_rate_hz = 48000; |
64 int complexity = kDefaultComplexity; | 64 int complexity = kDefaultComplexity; |
65 // This value may change in the struct's constructor. | 65 // This value may change in the struct's constructor. |
66 int low_rate_complexity = kDefaultComplexity; | 66 int low_rate_complexity = kDefaultComplexity; |
67 // low_rate_complexity is used when the bitrate is below this threshold. | 67 // low_rate_complexity is used when the bitrate is below this threshold. |
68 int complexity_threshold_bps = 12500; | 68 int complexity_threshold_bps = 12500; |
69 int complexity_threshold_window_bps = 1500; | 69 int complexity_threshold_window_bps = 1500; |
70 bool dtx_enabled = false; | 70 bool dtx_enabled = false; |
71 std::vector<int> supported_frame_lengths_ms; | 71 std::vector<int> supported_frame_lengths_ms; |
72 const Clock* clock = Clock::GetRealTimeClock(); | |
73 int uplink_bandwidth_update_interval_ms = 200; | 72 int uplink_bandwidth_update_interval_ms = 200; |
74 | 73 |
75 private: | 74 private: |
76 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) | 75 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) |
77 // If we are on Android, iOS and/or ARM, use a lower complexity setting as | 76 // If we are on Android, iOS and/or ARM, use a lower complexity setting as |
78 // default, to save encoder complexity. | 77 // default, to save encoder complexity. |
79 static const int kDefaultComplexity = 5; | 78 static const int kDefaultComplexity = 5; |
80 #else | 79 #else |
81 static const int kDefaultComplexity = 9; | 80 static const int kDefaultComplexity = 9; |
82 #endif | 81 #endif |
83 }; | 82 }; |
84 | 83 |
85 static Config CreateConfig(int payload_type, const SdpAudioFormat& format); | 84 static Config CreateConfig(int payload_type, const SdpAudioFormat& format); |
86 static Config CreateConfig(const CodecInst& codec_inst); | 85 static Config CreateConfig(const CodecInst& codec_inst); |
87 | 86 |
88 using AudioNetworkAdaptorCreator = | 87 using AudioNetworkAdaptorCreator = |
89 std::function<std::unique_ptr<AudioNetworkAdaptor>(const std::string&, | 88 std::function<std::unique_ptr<AudioNetworkAdaptor>(const std::string&, |
90 RtcEventLog*, | 89 RtcEventLog*)>; |
91 const Clock*)>; | |
92 AudioEncoderOpus( | 90 AudioEncoderOpus( |
93 const Config& config, | 91 const Config& config, |
94 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator = nullptr, | 92 AudioNetworkAdaptorCreator&& audio_network_adaptor_creator = nullptr, |
95 std::unique_ptr<SmoothingFilter> bitrate_smoother = nullptr); | 93 std::unique_ptr<SmoothingFilter> bitrate_smoother = nullptr); |
96 | 94 |
97 explicit AudioEncoderOpus(const CodecInst& codec_inst); | 95 explicit AudioEncoderOpus(const CodecInst& codec_inst); |
98 AudioEncoderOpus(int payload_type, const SdpAudioFormat& format); | 96 AudioEncoderOpus(int payload_type, const SdpAudioFormat& format); |
99 ~AudioEncoderOpus() override; | 97 ~AudioEncoderOpus() override; |
100 | 98 |
101 // Static interface for use by BuiltinAudioEncoderFactory. | 99 // Static interface for use by BuiltinAudioEncoderFactory. |
(...skipping 12 matching lines...) Expand all Loading... |
114 | 112 |
115 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice | 113 // Set Opus DTX. Once enabled, Opus stops transmission, when it detects voice |
116 // being inactive. During that, it still sends 2 packets (one for content, one | 114 // being inactive. During that, it still sends 2 packets (one for content, one |
117 // for signaling) about every 400 ms. | 115 // for signaling) about every 400 ms. |
118 bool SetDtx(bool enable) override; | 116 bool SetDtx(bool enable) override; |
119 bool GetDtx() const override; | 117 bool GetDtx() const override; |
120 | 118 |
121 bool SetApplication(Application application) override; | 119 bool SetApplication(Application application) override; |
122 void SetMaxPlaybackRate(int frequency_hz) override; | 120 void SetMaxPlaybackRate(int frequency_hz) override; |
123 bool EnableAudioNetworkAdaptor(const std::string& config_string, | 121 bool EnableAudioNetworkAdaptor(const std::string& config_string, |
124 RtcEventLog* event_log, | 122 RtcEventLog* event_log) override; |
125 const Clock* clock) override; | |
126 void DisableAudioNetworkAdaptor() override; | 123 void DisableAudioNetworkAdaptor() override; |
127 void OnReceivedUplinkPacketLossFraction( | 124 void OnReceivedUplinkPacketLossFraction( |
128 float uplink_packet_loss_fraction) override; | 125 float uplink_packet_loss_fraction) override; |
129 void OnReceivedUplinkRecoverablePacketLossFraction( | 126 void OnReceivedUplinkRecoverablePacketLossFraction( |
130 float uplink_recoverable_packet_loss_fraction) override; | 127 float uplink_recoverable_packet_loss_fraction) override; |
131 void OnReceivedUplinkBandwidth( | 128 void OnReceivedUplinkBandwidth( |
132 int target_audio_bitrate_bps, | 129 int target_audio_bitrate_bps, |
133 rtc::Optional<int64_t> probing_interval_ms) override; | 130 rtc::Optional<int64_t> probing_interval_ms) override; |
134 void OnReceivedRtt(int rtt_ms) override; | 131 void OnReceivedRtt(int rtt_ms) override; |
135 void OnReceivedOverhead(size_t overhead_bytes_per_packet) override; | 132 void OnReceivedOverhead(size_t overhead_bytes_per_packet) override; |
(...skipping 26 matching lines...) Expand all Loading... |
162 void SetNumChannelsToEncode(size_t num_channels_to_encode); | 159 void SetNumChannelsToEncode(size_t num_channels_to_encode); |
163 void SetProjectedPacketLossRate(float fraction); | 160 void SetProjectedPacketLossRate(float fraction); |
164 | 161 |
165 // TODO(minyue): remove "override" when we can deprecate | 162 // TODO(minyue): remove "override" when we can deprecate |
166 // |AudioEncoder::SetTargetBitrate|. | 163 // |AudioEncoder::SetTargetBitrate|. |
167 void SetTargetBitrate(int target_bps) override; | 164 void SetTargetBitrate(int target_bps) override; |
168 | 165 |
169 void ApplyAudioNetworkAdaptor(); | 166 void ApplyAudioNetworkAdaptor(); |
170 std::unique_ptr<AudioNetworkAdaptor> DefaultAudioNetworkAdaptorCreator( | 167 std::unique_ptr<AudioNetworkAdaptor> DefaultAudioNetworkAdaptorCreator( |
171 const ProtoString& config_string, | 168 const ProtoString& config_string, |
172 RtcEventLog* event_log, | 169 RtcEventLog* event_log) const; |
173 const Clock* clock) const; | |
174 | 170 |
175 void MaybeUpdateUplinkBandwidth(); | 171 void MaybeUpdateUplinkBandwidth(); |
176 | 172 |
177 Config config_; | 173 Config config_; |
178 const bool send_side_bwe_with_overhead_; | 174 const bool send_side_bwe_with_overhead_; |
179 float packet_loss_rate_; | 175 float packet_loss_rate_; |
180 std::vector<int16_t> input_buffer_; | 176 std::vector<int16_t> input_buffer_; |
181 OpusEncInst* inst_; | 177 OpusEncInst* inst_; |
182 uint32_t first_timestamp_in_buffer_; | 178 uint32_t first_timestamp_in_buffer_; |
183 size_t num_channels_to_encode_; | 179 size_t num_channels_to_encode_; |
184 int next_frame_length_ms_; | 180 int next_frame_length_ms_; |
185 int complexity_; | 181 int complexity_; |
186 std::unique_ptr<PacketLossFractionSmoother> packet_loss_fraction_smoother_; | 182 std::unique_ptr<PacketLossFractionSmoother> packet_loss_fraction_smoother_; |
187 AudioNetworkAdaptorCreator audio_network_adaptor_creator_; | 183 AudioNetworkAdaptorCreator audio_network_adaptor_creator_; |
188 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor_; | 184 std::unique_ptr<AudioNetworkAdaptor> audio_network_adaptor_; |
189 rtc::Optional<size_t> overhead_bytes_per_packet_; | 185 rtc::Optional<size_t> overhead_bytes_per_packet_; |
190 const std::unique_ptr<SmoothingFilter> bitrate_smoother_; | 186 const std::unique_ptr<SmoothingFilter> bitrate_smoother_; |
191 rtc::Optional<int64_t> bitrate_smoother_last_update_time_; | 187 rtc::Optional<int64_t> bitrate_smoother_last_update_time_; |
192 | 188 |
193 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); | 189 RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpus); |
194 }; | 190 }; |
195 | 191 |
196 } // namespace webrtc | 192 } // namespace webrtc |
197 | 193 |
198 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ | 194 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ |
OLD | NEW |