Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(647)

Side by Side Diff: webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc

Issue 1864993002: Remove the deprecated EncodeInternal interface from AudioEncoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h" 11 #include "webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h"
12 12
13 #include <algorithm>
kwiberg-webrtc 2016/04/07 08:23:16 Why is this needed?
ossu 2016/04/07 08:52:53 It's for std::min and std::max. It's another lint
kwiberg-webrtc 2016/04/07 09:53:26 That would be ideal. (I won't insist, though, sinc
14
13 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
14 #include "webrtc/base/safe_conversions.h" 16 #include "webrtc/base/safe_conversions.h"
15 #include "webrtc/common_types.h" 17 #include "webrtc/common_types.h"
16 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h" 18 #include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h"
17 19
18 namespace webrtc { 20 namespace webrtc {
19 21
20 namespace { 22 namespace {
21 23
22 const int kSampleRateHz = 48000; 24 const int kSampleRateHz = 48000;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 RTC_CHECK(RecreateEncoderInstance(config)); 95 RTC_CHECK(RecreateEncoderInstance(config));
94 } 96 }
95 97
96 AudioEncoderOpus::AudioEncoderOpus(const CodecInst& codec_inst) 98 AudioEncoderOpus::AudioEncoderOpus(const CodecInst& codec_inst)
97 : AudioEncoderOpus(CreateConfig(codec_inst)) {} 99 : AudioEncoderOpus(CreateConfig(codec_inst)) {}
98 100
99 AudioEncoderOpus::~AudioEncoderOpus() { 101 AudioEncoderOpus::~AudioEncoderOpus() {
100 RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_)); 102 RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
101 } 103 }
102 104
103 size_t AudioEncoderOpus::MaxEncodedBytes() const {
104 // Calculate the number of bytes we expect the encoder to produce,
105 // then multiply by two to give a wide margin for error.
106 const size_t bytes_per_millisecond =
107 static_cast<size_t>(config_.bitrate_bps / (1000 * 8) + 1);
108 const size_t approx_encoded_bytes =
109 Num10msFramesPerPacket() * 10 * bytes_per_millisecond;
110 return 2 * approx_encoded_bytes;
111 }
112
113 int AudioEncoderOpus::SampleRateHz() const { 105 int AudioEncoderOpus::SampleRateHz() const {
114 return kSampleRateHz; 106 return kSampleRateHz;
115 } 107 }
116 108
117 size_t AudioEncoderOpus::NumChannels() const { 109 size_t AudioEncoderOpus::NumChannels() const {
118 return config_.num_channels; 110 return config_.num_channels;
119 } 111 }
120 112
121 size_t AudioEncoderOpus::Num10MsFramesInNextPacket() const { 113 size_t AudioEncoderOpus::Num10MsFramesInNextPacket() const {
122 return Num10msFramesPerPacket(); 114 return Num10msFramesPerPacket();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 216 }
225 217
226 size_t AudioEncoderOpus::Num10msFramesPerPacket() const { 218 size_t AudioEncoderOpus::Num10msFramesPerPacket() const {
227 return static_cast<size_t>(rtc::CheckedDivExact(config_.frame_size_ms, 10)); 219 return static_cast<size_t>(rtc::CheckedDivExact(config_.frame_size_ms, 10));
228 } 220 }
229 221
230 size_t AudioEncoderOpus::SamplesPer10msFrame() const { 222 size_t AudioEncoderOpus::SamplesPer10msFrame() const {
231 return rtc::CheckedDivExact(kSampleRateHz, 100) * config_.num_channels; 223 return rtc::CheckedDivExact(kSampleRateHz, 100) * config_.num_channels;
232 } 224 }
233 225
226 size_t AudioEncoderOpus::MaxEncodedBytes() const {
227 // Calculate the number of bytes we expect the encoder to produce,
228 // then multiply by two to give a wide margin for error.
229 const size_t bytes_per_millisecond =
230 static_cast<size_t>(config_.bitrate_bps / (1000 * 8) + 1);
231 const size_t approx_encoded_bytes =
232 Num10msFramesPerPacket() * 10 * bytes_per_millisecond;
233 return 2 * approx_encoded_bytes;
234 }
235
234 // If the given config is OK, recreate the Opus encoder instance with those 236 // If the given config is OK, recreate the Opus encoder instance with those
235 // settings, save the config, and return true. Otherwise, do nothing and return 237 // settings, save the config, and return true. Otherwise, do nothing and return
236 // false. 238 // false.
237 bool AudioEncoderOpus::RecreateEncoderInstance(const Config& config) { 239 bool AudioEncoderOpus::RecreateEncoderInstance(const Config& config) {
238 if (!config.IsOk()) 240 if (!config.IsOk())
239 return false; 241 return false;
240 if (inst_) 242 if (inst_)
241 RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_)); 243 RTC_CHECK_EQ(0, WebRtcOpus_EncoderFree(inst_));
242 input_buffer_.clear(); 244 input_buffer_.clear();
243 input_buffer_.reserve(Num10msFramesPerPacket() * SamplesPer10msFrame()); 245 input_buffer_.reserve(Num10msFramesPerPacket() * SamplesPer10msFrame());
(...skipping 14 matching lines...) Expand all
258 RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_)); 260 RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_));
259 } 261 }
260 RTC_CHECK_EQ(0, 262 RTC_CHECK_EQ(0,
261 WebRtcOpus_SetPacketLossRate( 263 WebRtcOpus_SetPacketLossRate(
262 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5))); 264 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5)));
263 config_ = config; 265 config_ = config;
264 return true; 266 return true;
265 } 267 }
266 268
267 } // namespace webrtc 269 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698