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 #include "webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.h" | 11 #include "webrtc/modules/audio_coding/codecs/cng/audio_encoder_cng.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <memory> | |
14 #include <limits> | 15 #include <limits> |
15 | 16 |
16 namespace webrtc { | 17 namespace webrtc { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 const int kMaxFrameSizeMs = 60; | 21 const int kMaxFrameSizeMs = 60; |
21 | 22 |
22 rtc::scoped_ptr<CNG_enc_inst, CngInstDeleter> CreateCngInst( | 23 std::unique_ptr<CNG_enc_inst, CngInstDeleter> CreateCngInst( |
23 int sample_rate_hz, | 24 int sample_rate_hz, |
24 int sid_frame_interval_ms, | 25 int sid_frame_interval_ms, |
25 int num_cng_coefficients) { | 26 int num_cng_coefficients) { |
26 rtc::scoped_ptr<CNG_enc_inst, CngInstDeleter> cng_inst; | 27 CNG_enc_inst* ci; |
27 RTC_CHECK_EQ(0, WebRtcCng_CreateEnc(cng_inst.accept())); | 28 RTC_CHECK_EQ(0, WebRtcCng_CreateEnc(&ci)); |
tommi
2016/02/14 09:08:37
I wish unique_ptr had better support for accepting
kwiberg-webrtc
2016/02/14 13:07:43
Yes, but this may very well be deliberate: any pla
| |
29 std::unique_ptr<CNG_enc_inst, CngInstDeleter> cng_inst(ci); | |
28 RTC_CHECK_EQ(0, | 30 RTC_CHECK_EQ(0, |
29 WebRtcCng_InitEnc(cng_inst.get(), sample_rate_hz, | 31 WebRtcCng_InitEnc(cng_inst.get(), sample_rate_hz, |
30 sid_frame_interval_ms, num_cng_coefficients)); | 32 sid_frame_interval_ms, num_cng_coefficients)); |
31 return cng_inst; | 33 return cng_inst; |
32 } | 34 } |
33 | 35 |
34 } // namespace | 36 } // namespace |
35 | 37 |
36 bool AudioEncoderCng::Config::IsOk() const { | 38 bool AudioEncoderCng::Config::IsOk() const { |
37 if (num_channels != 1) | 39 if (num_channels != 1) |
(...skipping 10 matching lines...) Expand all Loading... | |
48 return false; | 50 return false; |
49 return true; | 51 return true; |
50 } | 52 } |
51 | 53 |
52 AudioEncoderCng::AudioEncoderCng(const Config& config) | 54 AudioEncoderCng::AudioEncoderCng(const Config& config) |
53 : speech_encoder_(config.speech_encoder), | 55 : speech_encoder_(config.speech_encoder), |
54 cng_payload_type_(config.payload_type), | 56 cng_payload_type_(config.payload_type), |
55 num_cng_coefficients_(config.num_cng_coefficients), | 57 num_cng_coefficients_(config.num_cng_coefficients), |
56 sid_frame_interval_ms_(config.sid_frame_interval_ms), | 58 sid_frame_interval_ms_(config.sid_frame_interval_ms), |
57 last_frame_active_(true), | 59 last_frame_active_(true), |
58 vad_(config.vad ? rtc_make_scoped_ptr(config.vad) | 60 vad_(config.vad ? std::unique_ptr<Vad>(config.vad) |
59 : CreateVad(config.vad_mode)) { | 61 : CreateVad(config.vad_mode)) { |
60 RTC_CHECK(config.IsOk()) << "Invalid configuration."; | 62 RTC_CHECK(config.IsOk()) << "Invalid configuration."; |
61 cng_inst_ = CreateCngInst(SampleRateHz(), sid_frame_interval_ms_, | 63 cng_inst_ = CreateCngInst(SampleRateHz(), sid_frame_interval_ms_, |
62 num_cng_coefficients_); | 64 num_cng_coefficients_); |
63 } | 65 } |
64 | 66 |
65 AudioEncoderCng::~AudioEncoderCng() = default; | 67 AudioEncoderCng::~AudioEncoderCng() = default; |
66 | 68 |
67 size_t AudioEncoderCng::MaxEncodedBytes() const { | 69 size_t AudioEncoderCng::MaxEncodedBytes() const { |
68 const size_t max_encoded_bytes_active = speech_encoder_->MaxEncodedBytes(); | 70 const size_t max_encoded_bytes_active = speech_encoder_->MaxEncodedBytes(); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 } | 257 } |
256 } | 258 } |
257 return info; | 259 return info; |
258 } | 260 } |
259 | 261 |
260 size_t AudioEncoderCng::SamplesPer10msFrame() const { | 262 size_t AudioEncoderCng::SamplesPer10msFrame() const { |
261 return rtc::CheckedDivExact(10 * SampleRateHz(), 1000); | 263 return rtc::CheckedDivExact(10 * SampleRateHz(), 1000); |
262 } | 264 } |
263 | 265 |
264 } // namespace webrtc | 266 } // namespace webrtc |
OLD | NEW |