blob: 8a5bb6a2a31a1e557e21439a0fccef5dfe03bc9a [file] [log] [blame]
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
kwiberg91d97562016-02-14 01:10:03 -080010
11#include <memory>
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +000012#include <string>
13
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/audio_coding/codecs/opus/opus_inst.h"
15#include "modules/audio_coding/codecs/opus/opus_interface.h"
16#include "modules/audio_coding/neteq/tools/audio_loop.h"
17#include "rtc_base/checks.h"
Karl Wiberge40468b2017-11-22 10:42:26 +010018#include "rtc_base/numerics/safe_conversions.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "test/testsupport/file_utils.h"
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +000021
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +000022namespace webrtc {
23
Alex Loiko50b8c392019-04-03 15:12:01 +020024namespace {
25// Equivalent to SDP params
26// {{"channel_mapping", "0,1,2,3"}, {"coupled_streams", "2"}}.
27constexpr unsigned char kQuadChannelMapping[] = {0, 1, 2, 3};
Alex Loikoe5b94162019-04-08 17:19:41 +020028constexpr int kQuadTotalStreams = 2;
Alex Loiko50b8c392019-04-03 15:12:01 +020029constexpr int kQuadCoupledStreams = 2;
30
31constexpr unsigned char kStereoChannelMapping[] = {0, 1};
Alex Loikoe5b94162019-04-08 17:19:41 +020032constexpr int kStereoTotalStreams = 1;
Alex Loiko50b8c392019-04-03 15:12:01 +020033constexpr int kStereoCoupledStreams = 1;
34
35constexpr unsigned char kMonoChannelMapping[] = {0};
Alex Loikoe5b94162019-04-08 17:19:41 +020036constexpr int kMonoTotalStreams = 1;
Alex Loiko50b8c392019-04-03 15:12:01 +020037constexpr int kMonoCoupledStreams = 0;
38
39void CreateSingleOrMultiStreamEncoder(WebRtcOpusEncInst** opus_encoder,
40 int channels,
41 int application,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +020042 bool use_multistream,
43 int encoder_sample_rate_hz) {
44 EXPECT_TRUE(channels == 1 || channels == 2 || use_multistream);
45 if (use_multistream) {
46 EXPECT_EQ(encoder_sample_rate_hz, 48000);
47 if (channels == 1) {
48 EXPECT_EQ(0, WebRtcOpus_MultistreamEncoderCreate(
49 opus_encoder, channels, application, kMonoTotalStreams,
50 kMonoCoupledStreams, kMonoChannelMapping));
51 } else if (channels == 2) {
52 EXPECT_EQ(0, WebRtcOpus_MultistreamEncoderCreate(
53 opus_encoder, channels, application, kStereoTotalStreams,
54 kStereoCoupledStreams, kStereoChannelMapping));
55 } else if (channels == 4) {
56 EXPECT_EQ(0, WebRtcOpus_MultistreamEncoderCreate(
57 opus_encoder, channels, application, kQuadTotalStreams,
58 kQuadCoupledStreams, kQuadChannelMapping));
59 } else {
60 EXPECT_TRUE(false) << channels;
61 }
Alex Loiko50b8c392019-04-03 15:12:01 +020062 } else {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +020063 EXPECT_EQ(0, WebRtcOpus_EncoderCreate(opus_encoder, channels, application,
64 encoder_sample_rate_hz));
Alex Loiko50b8c392019-04-03 15:12:01 +020065 }
66}
67
68void CreateSingleOrMultiStreamDecoder(WebRtcOpusDecInst** opus_decoder,
69 int channels,
Karl Wiberga1d1a1e2019-05-28 14:41:07 +020070 bool use_multistream,
71 int decoder_sample_rate_hz) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +020072 EXPECT_TRUE(channels == 1 || channels == 2 || use_multistream);
73 if (use_multistream) {
Karl Wiberga1d1a1e2019-05-28 14:41:07 +020074 EXPECT_EQ(decoder_sample_rate_hz, 48000);
Karl Wiberg7e7c5c32019-05-21 11:50:32 +020075 if (channels == 1) {
76 EXPECT_EQ(0, WebRtcOpus_MultistreamDecoderCreate(
77 opus_decoder, channels, kMonoTotalStreams,
78 kMonoCoupledStreams, kMonoChannelMapping));
79 } else if (channels == 2) {
80 EXPECT_EQ(0, WebRtcOpus_MultistreamDecoderCreate(
81 opus_decoder, channels, kStereoTotalStreams,
82 kStereoCoupledStreams, kStereoChannelMapping));
83 } else if (channels == 4) {
84 EXPECT_EQ(0, WebRtcOpus_MultistreamDecoderCreate(
85 opus_decoder, channels, kQuadTotalStreams,
86 kQuadCoupledStreams, kQuadChannelMapping));
87 } else {
88 EXPECT_TRUE(false) << channels;
89 }
Alex Loiko50b8c392019-04-03 15:12:01 +020090 } else {
Karl Wiberga1d1a1e2019-05-28 14:41:07 +020091 EXPECT_EQ(0, WebRtcOpus_DecoderCreate(opus_decoder, channels,
92 decoder_sample_rate_hz));
Alex Loiko50b8c392019-04-03 15:12:01 +020093 }
94}
Karl Wiberg7e7c5c32019-05-21 11:50:32 +020095
Karl Wiberga1d1a1e2019-05-28 14:41:07 +020096int SamplesPerChannel(int sample_rate_hz, int duration_ms) {
97 const int samples_per_ms = rtc::CheckedDivExact(sample_rate_hz, 1000);
98 return samples_per_ms * duration_ms;
99}
100
Alex Loiko50b8c392019-04-03 15:12:01 +0200101} // namespace
102
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000103using test::AudioLoop;
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000104using ::testing::TestWithParam;
105using ::testing::Values;
106using ::testing::Combine;
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000107
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000108// Maximum number of bytes in output bitstream.
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100109const size_t kMaxBytes = 2000;
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000110
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200111class OpusTest
112 : public TestWithParam<::testing::tuple<size_t, int, bool, int, int>> {
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000113 protected:
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200114 OpusTest() = default;
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000115
minyue3cea2562015-11-10 03:49:26 -0800116 void TestDtxEffect(bool dtx, int block_length_ms);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000117
soren28dc2852017-04-06 05:48:36 -0700118 void TestCbrEffect(bool dtx, int block_length_ms);
119
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000120 // Prepare |speech_data_| for encoding, read from a hard-coded file.
121 // After preparation, |speech_data_.GetNextBlock()| returns a pointer to a
122 // block of |block_length_ms| milliseconds. The data is looped every
123 // |loop_length_ms| milliseconds.
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200124 void PrepareSpeechData(int block_length_ms, int loop_length_ms);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000125
126 int EncodeDecode(WebRtcOpusEncInst* encoder,
kwiberg288886b2015-11-06 01:21:35 -0800127 rtc::ArrayView<const int16_t> input_audio,
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000128 WebRtcOpusDecInst* decoder,
129 int16_t* output_audio,
130 int16_t* audio_type);
minyue@webrtc.org0040a6e2014-08-04 14:41:57 +0000131
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000132 void SetMaxPlaybackRate(WebRtcOpusEncInst* encoder,
Yves Gerey665174f2018-06-19 15:03:05 +0200133 opus_int32 expect,
134 int32_t set);
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000135
Yves Gerey665174f2018-06-19 15:03:05 +0200136 void CheckAudioBounded(const int16_t* audio,
137 size_t samples,
138 size_t channels,
minyue3cea2562015-11-10 03:49:26 -0800139 uint16_t bound) const;
140
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200141 WebRtcOpusEncInst* opus_encoder_ = nullptr;
142 WebRtcOpusDecInst* opus_decoder_ = nullptr;
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000143 AudioLoop speech_data_;
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000144 uint8_t bitstream_[kMaxBytes];
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200145 size_t encoded_bytes_ = 0;
146 const size_t channels_{std::get<0>(GetParam())};
147 const int application_{std::get<1>(GetParam())};
148 const bool use_multistream_{std::get<2>(GetParam())};
149 const int encoder_sample_rate_hz_{std::get<3>(GetParam())};
150 const int decoder_sample_rate_hz_{std::get<4>(GetParam())};
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000151};
152
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200153// Singlestream: Try all combinations.
154INSTANTIATE_TEST_SUITE_P(Singlestream,
155 OpusTest,
156 testing::Combine(testing::Values(1, 2),
157 testing::Values(0, 1),
158 testing::Values(false),
159 testing::Values(16000, 48000),
160 testing::Values(16000, 48000)));
161
162// Multistream: Some representative cases (only 48 kHz for now).
163INSTANTIATE_TEST_SUITE_P(
164 Multistream,
165 OpusTest,
166 testing::Values(std::make_tuple(1, 0, true, 48000, 48000),
167 std::make_tuple(2, 1, true, 48000, 48000),
168 std::make_tuple(4, 0, true, 48000, 48000),
169 std::make_tuple(4, 1, true, 48000, 48000)));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000170
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200171void OpusTest::PrepareSpeechData(int block_length_ms, int loop_length_ms) {
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100172 std::map<int, std::string> channel_to_basename = {
173 {1, "audio_coding/testfile32kHz"},
174 {2, "audio_coding/teststereo32kHz"},
175 {4, "audio_coding/speech_4_channels_48k_one_second"}};
176 std::map<int, std::string> channel_to_suffix = {
177 {1, "pcm"}, {2, "pcm"}, {4, "wav"}};
Yves Gerey665174f2018-06-19 15:03:05 +0200178 const std::string file_name = webrtc::test::ResourcePath(
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200179 channel_to_basename[channels_], channel_to_suffix[channels_]);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000180 if (loop_length_ms < block_length_ms) {
181 loop_length_ms = block_length_ms;
182 }
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200183 const int sample_rate_khz =
184 rtc::CheckedDivExact(encoder_sample_rate_hz_, 1000);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000185 EXPECT_TRUE(speech_data_.Init(file_name,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200186 loop_length_ms * sample_rate_khz * channels_,
187 block_length_ms * sample_rate_khz * channels_));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000188}
189
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000190void OpusTest::SetMaxPlaybackRate(WebRtcOpusEncInst* encoder,
191 opus_int32 expect,
192 int32_t set) {
minyue@webrtc.org0040a6e2014-08-04 14:41:57 +0000193 opus_int32 bandwidth;
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000194 EXPECT_EQ(0, WebRtcOpus_SetMaxPlaybackRate(opus_encoder_, set));
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100195 EXPECT_EQ(0, WebRtcOpus_GetMaxPlaybackRate(opus_encoder_, &bandwidth));
minyue@webrtc.org0040a6e2014-08-04 14:41:57 +0000196 EXPECT_EQ(expect, bandwidth);
197}
198
Yves Gerey665174f2018-06-19 15:03:05 +0200199void OpusTest::CheckAudioBounded(const int16_t* audio,
200 size_t samples,
201 size_t channels,
202 uint16_t bound) const {
minyue3cea2562015-11-10 03:49:26 -0800203 for (size_t i = 0; i < samples; ++i) {
Peter Kasting69558702016-01-12 16:26:35 -0800204 for (size_t c = 0; c < channels; ++c) {
minyue3cea2562015-11-10 03:49:26 -0800205 ASSERT_GE(audio[i * channels + c], -bound);
206 ASSERT_LE(audio[i * channels + c], bound);
207 }
208 }
209}
210
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000211int OpusTest::EncodeDecode(WebRtcOpusEncInst* encoder,
kwiberg288886b2015-11-06 01:21:35 -0800212 rtc::ArrayView<const int16_t> input_audio,
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000213 WebRtcOpusDecInst* decoder,
214 int16_t* output_audio,
215 int16_t* audio_type) {
Yves Gerey665174f2018-06-19 15:03:05 +0200216 int encoded_bytes_int =
217 WebRtcOpus_Encode(encoder, input_audio.data(),
218 rtc::CheckedDivExact(input_audio.size(), channels_),
219 kMaxBytes, bitstream_);
Peter Kastingdce40cf2015-08-24 14:52:23 -0700220 EXPECT_GE(encoded_bytes_int, 0);
221 encoded_bytes_ = static_cast<size_t>(encoded_bytes_int);
minyuel6d92bf52015-09-23 15:20:39 +0200222 int est_len = WebRtcOpus_DurationEst(decoder, bitstream_, encoded_bytes_);
Yves Gerey665174f2018-06-19 15:03:05 +0200223 int act_len = WebRtcOpus_Decode(decoder, bitstream_, encoded_bytes_,
224 output_audio, audio_type);
minyuel6d92bf52015-09-23 15:20:39 +0200225 EXPECT_EQ(est_len, act_len);
226 return act_len;
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000227}
228
229// Test if encoder/decoder can enter DTX mode properly and do not enter DTX when
230// they should not. This test is signal dependent.
minyue3cea2562015-11-10 03:49:26 -0800231void OpusTest::TestDtxEffect(bool dtx, int block_length_ms) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200232 PrepareSpeechData(block_length_ms, 2000);
233 const size_t input_samples =
234 rtc::CheckedDivExact(encoder_sample_rate_hz_, 1000) * block_length_ms;
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200235 const size_t output_samples =
236 rtc::CheckedDivExact(decoder_sample_rate_hz_, 1000) * block_length_ms;
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000237
238 // Create encoder memory.
Alex Loiko50b8c392019-04-03 15:12:01 +0200239 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200240 use_multistream_, encoder_sample_rate_hz_);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200241 CreateSingleOrMultiStreamDecoder(&opus_decoder_, channels_, use_multistream_,
242 decoder_sample_rate_hz_);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000243
244 // Set bitrate.
Yves Gerey665174f2018-06-19 15:03:05 +0200245 EXPECT_EQ(
246 0, WebRtcOpus_SetBitRate(opus_encoder_, channels_ == 1 ? 32000 : 64000));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000247
248 // Set input audio as silence.
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200249 std::vector<int16_t> silence(input_samples * channels_, 0);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000250
251 // Setting DTX.
Yves Gerey665174f2018-06-19 15:03:05 +0200252 EXPECT_EQ(0, dtx ? WebRtcOpus_EnableDtx(opus_encoder_)
253 : WebRtcOpus_DisableDtx(opus_encoder_));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000254
255 int16_t audio_type;
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200256 int16_t* output_data_decode = new int16_t[output_samples * channels_];
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000257
258 for (int i = 0; i < 100; ++i) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200259 EXPECT_EQ(output_samples,
260 static_cast<size_t>(EncodeDecode(
261 opus_encoder_, speech_data_.GetNextBlock(), opus_decoder_,
262 output_data_decode, &audio_type)));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000263 // If not DTX, it should never enter DTX mode. If DTX, we do not care since
264 // whether it enters DTX depends on the signal type.
265 if (!dtx) {
Peter Kastingdce40cf2015-08-24 14:52:23 -0700266 EXPECT_GT(encoded_bytes_, 1U);
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000267 EXPECT_EQ(0, opus_encoder_->in_dtx_mode);
268 EXPECT_EQ(0, opus_decoder_->in_dtx_mode);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000269 EXPECT_EQ(0, audio_type); // Speech.
270 }
271 }
272
273 // We input some silent segments. In DTX mode, the encoder will stop sending.
274 // However, DTX may happen after a while.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000275 for (int i = 0; i < 30; ++i) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200276 EXPECT_EQ(output_samples, static_cast<size_t>(EncodeDecode(
277 opus_encoder_, silence, opus_decoder_,
278 output_data_decode, &audio_type)));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000279 if (!dtx) {
Peter Kastingdce40cf2015-08-24 14:52:23 -0700280 EXPECT_GT(encoded_bytes_, 1U);
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000281 EXPECT_EQ(0, opus_encoder_->in_dtx_mode);
282 EXPECT_EQ(0, opus_decoder_->in_dtx_mode);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000283 EXPECT_EQ(0, audio_type); // Speech.
Peter Kasting728d9032015-06-11 14:31:38 -0700284 } else if (encoded_bytes_ == 1) {
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000285 EXPECT_EQ(1, opus_encoder_->in_dtx_mode);
286 EXPECT_EQ(1, opus_decoder_->in_dtx_mode);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000287 EXPECT_EQ(2, audio_type); // Comfort noise.
288 break;
289 }
290 }
291
Minyue Li092041c2015-05-11 12:19:35 +0200292 // When Opus is in DTX, it wakes up in a regular basis. It sends two packets,
293 // one with an arbitrary size and the other of 1-byte, then stops sending for
minyue3cea2562015-11-10 03:49:26 -0800294 // a certain number of frames.
295
296 // |max_dtx_frames| is the maximum number of frames Opus can stay in DTX.
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200297 // TODO(kwiberg): Why does this number depend on the encoding sample rate?
298 const int max_dtx_frames =
299 (encoder_sample_rate_hz_ == 16000 ? 800 : 400) / block_length_ms + 1;
minyue3cea2562015-11-10 03:49:26 -0800300
301 // We run |kRunTimeMs| milliseconds of pure silence.
minyue58e08cb2016-02-24 03:49:19 -0800302 const int kRunTimeMs = 4500;
minyue3cea2562015-11-10 03:49:26 -0800303
304 // We check that, after a |kCheckTimeMs| milliseconds (given that the CNG in
305 // Opus needs time to adapt), the absolute values of DTX decoded signal are
306 // bounded by |kOutputValueBound|.
minyue58e08cb2016-02-24 03:49:19 -0800307 const int kCheckTimeMs = 4000;
minyue3cea2562015-11-10 03:49:26 -0800308
309#if defined(OPUS_FIXED_POINT)
minyuel7e937e92016-02-29 10:24:15 +0100310 // Fixed-point Opus generates a random (comfort) noise, which has a less
311 // predictable value bound than its floating-point Opus. This value depends on
312 // input signal, and the time window for checking the output values (between
313 // |kCheckTimeMs| and |kRunTimeMs|).
314 const uint16_t kOutputValueBound = 30;
315
minyue3cea2562015-11-10 03:49:26 -0800316#else
minyue58e08cb2016-02-24 03:49:19 -0800317 const uint16_t kOutputValueBound = 2;
minyue3cea2562015-11-10 03:49:26 -0800318#endif
319
320 int time = 0;
321 while (time < kRunTimeMs) {
322 // DTX mode is maintained for maximum |max_dtx_frames| frames.
323 int i = 0;
324 for (; i < max_dtx_frames; ++i) {
325 time += block_length_ms;
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200326 EXPECT_EQ(output_samples, static_cast<size_t>(EncodeDecode(
327 opus_encoder_, silence, opus_decoder_,
328 output_data_decode, &audio_type)));
Minyue Li092041c2015-05-11 12:19:35 +0200329 if (dtx) {
minyue3cea2562015-11-10 03:49:26 -0800330 if (encoded_bytes_ > 1)
331 break;
Peter Kastingdce40cf2015-08-24 14:52:23 -0700332 EXPECT_EQ(0U, encoded_bytes_) // Send 0 byte.
Minyue Li092041c2015-05-11 12:19:35 +0200333 << "Opus should have entered DTX mode.";
334 EXPECT_EQ(1, opus_encoder_->in_dtx_mode);
335 EXPECT_EQ(1, opus_decoder_->in_dtx_mode);
336 EXPECT_EQ(2, audio_type); // Comfort noise.
minyue3cea2562015-11-10 03:49:26 -0800337 if (time >= kCheckTimeMs) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200338 CheckAudioBounded(output_data_decode, output_samples, channels_,
minyue3cea2562015-11-10 03:49:26 -0800339 kOutputValueBound);
340 }
Minyue Li092041c2015-05-11 12:19:35 +0200341 } else {
Peter Kastingdce40cf2015-08-24 14:52:23 -0700342 EXPECT_GT(encoded_bytes_, 1U);
Minyue Li092041c2015-05-11 12:19:35 +0200343 EXPECT_EQ(0, opus_encoder_->in_dtx_mode);
344 EXPECT_EQ(0, opus_decoder_->in_dtx_mode);
345 EXPECT_EQ(0, audio_type); // Speech.
346 }
347 }
348
minyue3cea2562015-11-10 03:49:26 -0800349 if (dtx) {
350 // With DTX, Opus must stop transmission for some time.
351 EXPECT_GT(i, 1);
352 }
Minyue Li092041c2015-05-11 12:19:35 +0200353
minyue3cea2562015-11-10 03:49:26 -0800354 // We expect a normal payload.
Minyue Li092041c2015-05-11 12:19:35 +0200355 EXPECT_EQ(0, opus_encoder_->in_dtx_mode);
356 EXPECT_EQ(0, opus_decoder_->in_dtx_mode);
357 EXPECT_EQ(0, audio_type); // Speech.
358
359 // Enters DTX again immediately.
minyue3cea2562015-11-10 03:49:26 -0800360 time += block_length_ms;
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200361 EXPECT_EQ(output_samples, static_cast<size_t>(EncodeDecode(
362 opus_encoder_, silence, opus_decoder_,
363 output_data_decode, &audio_type)));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000364 if (dtx) {
Peter Kastingdce40cf2015-08-24 14:52:23 -0700365 EXPECT_EQ(1U, encoded_bytes_); // Send 1 byte.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000366 EXPECT_EQ(1, opus_encoder_->in_dtx_mode);
367 EXPECT_EQ(1, opus_decoder_->in_dtx_mode);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000368 EXPECT_EQ(2, audio_type); // Comfort noise.
minyue3cea2562015-11-10 03:49:26 -0800369 if (time >= kCheckTimeMs) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200370 CheckAudioBounded(output_data_decode, output_samples, channels_,
minyue3cea2562015-11-10 03:49:26 -0800371 kOutputValueBound);
372 }
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000373 } else {
Peter Kastingdce40cf2015-08-24 14:52:23 -0700374 EXPECT_GT(encoded_bytes_, 1U);
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000375 EXPECT_EQ(0, opus_encoder_->in_dtx_mode);
376 EXPECT_EQ(0, opus_decoder_->in_dtx_mode);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000377 EXPECT_EQ(0, audio_type); // Speech.
378 }
379 }
380
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000381 silence[0] = 10000;
382 if (dtx) {
383 // Verify that encoder/decoder can jump out from DTX mode.
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200384 EXPECT_EQ(output_samples, static_cast<size_t>(EncodeDecode(
385 opus_encoder_, silence, opus_decoder_,
386 output_data_decode, &audio_type)));
Peter Kastingdce40cf2015-08-24 14:52:23 -0700387 EXPECT_GT(encoded_bytes_, 1U);
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000388 EXPECT_EQ(0, opus_encoder_->in_dtx_mode);
389 EXPECT_EQ(0, opus_decoder_->in_dtx_mode);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000390 EXPECT_EQ(0, audio_type); // Speech.
391 }
392
393 // Free memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000394 delete[] output_data_decode;
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000395 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
396 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000397}
398
soren28dc2852017-04-06 05:48:36 -0700399// Test if CBR does what we expect.
400void OpusTest::TestCbrEffect(bool cbr, int block_length_ms) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200401 PrepareSpeechData(block_length_ms, 2000);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200402 const size_t output_samples =
403 rtc::CheckedDivExact(decoder_sample_rate_hz_, 1000) * block_length_ms;
soren28dc2852017-04-06 05:48:36 -0700404
405 int32_t max_pkt_size_diff = 0;
406 int32_t prev_pkt_size = 0;
407
408 // Create encoder memory.
Alex Loiko50b8c392019-04-03 15:12:01 +0200409 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200410 use_multistream_, encoder_sample_rate_hz_);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200411 CreateSingleOrMultiStreamDecoder(&opus_decoder_, channels_, use_multistream_,
412 decoder_sample_rate_hz_);
soren28dc2852017-04-06 05:48:36 -0700413
414 // Set bitrate.
415 EXPECT_EQ(
416 0, WebRtcOpus_SetBitRate(opus_encoder_, channels_ == 1 ? 32000 : 64000));
417
418 // Setting CBR.
419 EXPECT_EQ(0, cbr ? WebRtcOpus_EnableCbr(opus_encoder_)
420 : WebRtcOpus_DisableCbr(opus_encoder_));
421
422 int16_t audio_type;
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200423 std::vector<int16_t> audio_out(output_samples * channels_);
soren28dc2852017-04-06 05:48:36 -0700424 for (int i = 0; i < 100; ++i) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200425 EXPECT_EQ(output_samples,
426 static_cast<size_t>(
427 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(),
428 opus_decoder_, audio_out.data(), &audio_type)));
soren28dc2852017-04-06 05:48:36 -0700429
430 if (prev_pkt_size > 0) {
431 int32_t diff = std::abs((int32_t)encoded_bytes_ - prev_pkt_size);
432 max_pkt_size_diff = std::max(max_pkt_size_diff, diff);
433 }
Mirko Bonadei737e0732017-10-19 09:00:17 +0200434 prev_pkt_size = rtc::checked_cast<int32_t>(encoded_bytes_);
soren28dc2852017-04-06 05:48:36 -0700435 }
436
437 if (cbr) {
438 EXPECT_EQ(max_pkt_size_diff, 0);
439 } else {
440 EXPECT_GT(max_pkt_size_diff, 0);
441 }
442
443 // Free memory.
444 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
445 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
446}
447
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000448// Test failing Create.
henrika1d34fe92015-06-16 10:04:20 +0200449TEST(OpusTest, OpusCreateFail) {
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000450 WebRtcOpusEncInst* opus_encoder;
451 WebRtcOpusDecInst* opus_decoder;
452
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000453 // Test to see that an invalid pointer is caught.
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200454 EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(NULL, 1, 0, 48000));
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000455 // Invalid channel number.
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200456 EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(&opus_encoder, 257, 0, 48000));
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000457 // Invalid applciation mode.
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200458 EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(&opus_encoder, 1, 2, 48000));
459 // Invalid sample rate.
460 EXPECT_EQ(-1, WebRtcOpus_EncoderCreate(&opus_encoder, 1, 0, 12345));
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000461
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200462 EXPECT_EQ(-1, WebRtcOpus_DecoderCreate(NULL, 1, 48000));
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000463 // Invalid channel number.
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200464 EXPECT_EQ(-1, WebRtcOpus_DecoderCreate(&opus_decoder, 257, 48000));
465 // Invalid sample rate.
466 EXPECT_EQ(-1, WebRtcOpus_DecoderCreate(&opus_decoder, 1, 12345));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000467}
468
469// Test failing Free.
henrika1d34fe92015-06-16 10:04:20 +0200470TEST(OpusTest, OpusFreeFail) {
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000471 // Test to see that an invalid pointer is caught.
472 EXPECT_EQ(-1, WebRtcOpus_EncoderFree(NULL));
473 EXPECT_EQ(-1, WebRtcOpus_DecoderFree(NULL));
474}
475
476// Test normal Create and Free.
henrika1d34fe92015-06-16 10:04:20 +0200477TEST_P(OpusTest, OpusCreateFree) {
Alex Loiko50b8c392019-04-03 15:12:01 +0200478 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200479 use_multistream_, encoder_sample_rate_hz_);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200480 CreateSingleOrMultiStreamDecoder(&opus_decoder_, channels_, use_multistream_,
481 decoder_sample_rate_hz_);
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000482 EXPECT_TRUE(opus_encoder_ != NULL);
483 EXPECT_TRUE(opus_decoder_ != NULL);
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000484 // Free encoder and decoder memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000485 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
486 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000487}
488
Alex Loiko50b8c392019-04-03 15:12:01 +0200489#define ENCODER_CTL(inst, vargs) \
490 inst->encoder \
491 ? opus_encoder_ctl(inst->encoder, vargs) \
492 : opus_multistream_encoder_ctl(inst->multistream_encoder, vargs)
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100493
henrika1d34fe92015-06-16 10:04:20 +0200494TEST_P(OpusTest, OpusEncodeDecode) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200495 PrepareSpeechData(20, 20);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000496
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000497 // Create encoder memory.
Alex Loiko50b8c392019-04-03 15:12:01 +0200498 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200499 use_multistream_, encoder_sample_rate_hz_);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200500 CreateSingleOrMultiStreamDecoder(&opus_decoder_, channels_, use_multistream_,
501 decoder_sample_rate_hz_);
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000502
503 // Set bitrate.
Yves Gerey665174f2018-06-19 15:03:05 +0200504 EXPECT_EQ(
505 0, WebRtcOpus_SetBitRate(opus_encoder_, channels_ == 1 ? 32000 : 64000));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000506
507 // Check number of channels for decoder.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000508 EXPECT_EQ(channels_, WebRtcOpus_DecoderChannels(opus_decoder_));
509
510 // Check application mode.
511 opus_int32 app;
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100512 ENCODER_CTL(opus_encoder_, OPUS_GET_APPLICATION(&app));
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000513 EXPECT_EQ(application_ == 0 ? OPUS_APPLICATION_VOIP : OPUS_APPLICATION_AUDIO,
514 app);
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000515
516 // Encode & decode.
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000517 int16_t audio_type;
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200518 const int decode_samples_per_channel =
519 SamplesPerChannel(decoder_sample_rate_hz_, /*ms=*/20);
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200520 int16_t* output_data_decode =
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200521 new int16_t[decode_samples_per_channel * channels_];
522 EXPECT_EQ(decode_samples_per_channel,
523 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(),
524 opus_decoder_, output_data_decode, &audio_type));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000525
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000526 // Free memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000527 delete[] output_data_decode;
528 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
529 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000530}
531
henrika1d34fe92015-06-16 10:04:20 +0200532TEST_P(OpusTest, OpusSetBitRate) {
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000533 // Test without creating encoder memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000534 EXPECT_EQ(-1, WebRtcOpus_SetBitRate(opus_encoder_, 60000));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000535
536 // Create encoder memory, try with different bitrates.
Alex Loiko50b8c392019-04-03 15:12:01 +0200537 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200538 use_multistream_, encoder_sample_rate_hz_);
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000539 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_, 30000));
540 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_, 60000));
541 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_, 300000));
542 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_, 600000));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000543
544 // Free memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000545 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000546}
547
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000548TEST_P(OpusTest, OpusSetComplexity) {
minyue@webrtc.org04546882014-03-07 08:55:48 +0000549 // Test without creating encoder memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000550 EXPECT_EQ(-1, WebRtcOpus_SetComplexity(opus_encoder_, 9));
minyue@webrtc.org04546882014-03-07 08:55:48 +0000551
552 // Create encoder memory, try with different complexities.
Alex Loiko50b8c392019-04-03 15:12:01 +0200553 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200554 use_multistream_, encoder_sample_rate_hz_);
minyue@webrtc.org04546882014-03-07 08:55:48 +0000555
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000556 EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_encoder_, 0));
557 EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_encoder_, 10));
558 EXPECT_EQ(-1, WebRtcOpus_SetComplexity(opus_encoder_, 11));
minyue@webrtc.org04546882014-03-07 08:55:48 +0000559
560 // Free memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000561 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
minyue@webrtc.org04546882014-03-07 08:55:48 +0000562}
563
Alex Luebseeb27652017-11-20 11:13:56 -0800564TEST_P(OpusTest, OpusSetBandwidth) {
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100565 if (channels_ > 2) {
566 // TODO(webrtc:10217): investigate why multi-stream Opus reports
567 // narrowband when it's configured with FULLBAND.
568 return;
569 }
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200570 PrepareSpeechData(20, 20);
Alex Luebseeb27652017-11-20 11:13:56 -0800571
572 int16_t audio_type;
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200573 const int decode_samples_per_channel =
574 SamplesPerChannel(decoder_sample_rate_hz_, /*ms=*/20);
Alex Luebseeb27652017-11-20 11:13:56 -0800575 std::unique_ptr<int16_t[]> output_data_decode(
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200576 new int16_t[decode_samples_per_channel * channels_]());
Alex Luebseeb27652017-11-20 11:13:56 -0800577
578 // Test without creating encoder memory.
579 EXPECT_EQ(-1,
580 WebRtcOpus_SetBandwidth(opus_encoder_, OPUS_BANDWIDTH_NARROWBAND));
581 EXPECT_EQ(-1, WebRtcOpus_GetBandwidth(opus_encoder_));
582
583 // Create encoder memory, try with different bandwidths.
Alex Loiko50b8c392019-04-03 15:12:01 +0200584 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200585 use_multistream_, encoder_sample_rate_hz_);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200586 CreateSingleOrMultiStreamDecoder(&opus_decoder_, channels_, use_multistream_,
587 decoder_sample_rate_hz_);
Alex Luebseeb27652017-11-20 11:13:56 -0800588
589 EXPECT_EQ(-1, WebRtcOpus_SetBandwidth(opus_encoder_,
590 OPUS_BANDWIDTH_NARROWBAND - 1));
591 EXPECT_EQ(0,
592 WebRtcOpus_SetBandwidth(opus_encoder_, OPUS_BANDWIDTH_NARROWBAND));
593 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(), opus_decoder_,
594 output_data_decode.get(), &audio_type);
595 EXPECT_EQ(OPUS_BANDWIDTH_NARROWBAND, WebRtcOpus_GetBandwidth(opus_encoder_));
596 EXPECT_EQ(0, WebRtcOpus_SetBandwidth(opus_encoder_, OPUS_BANDWIDTH_FULLBAND));
597 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(), opus_decoder_,
598 output_data_decode.get(), &audio_type);
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200599 EXPECT_EQ(encoder_sample_rate_hz_ == 16000 ? OPUS_BANDWIDTH_WIDEBAND
600 : OPUS_BANDWIDTH_FULLBAND,
601 WebRtcOpus_GetBandwidth(opus_encoder_));
Alex Luebseeb27652017-11-20 11:13:56 -0800602 EXPECT_EQ(
603 -1, WebRtcOpus_SetBandwidth(opus_encoder_, OPUS_BANDWIDTH_FULLBAND + 1));
604 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(), opus_decoder_,
605 output_data_decode.get(), &audio_type);
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200606 EXPECT_EQ(encoder_sample_rate_hz_ == 16000 ? OPUS_BANDWIDTH_WIDEBAND
607 : OPUS_BANDWIDTH_FULLBAND,
608 WebRtcOpus_GetBandwidth(opus_encoder_));
Alex Luebseeb27652017-11-20 11:13:56 -0800609
610 // Free memory.
611 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
612 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
613}
614
minyuec8299f92016-09-27 02:08:47 -0700615TEST_P(OpusTest, OpusForceChannels) {
616 // Test without creating encoder memory.
617 EXPECT_EQ(-1, WebRtcOpus_SetForceChannels(opus_encoder_, 1));
618
Alex Loiko50b8c392019-04-03 15:12:01 +0200619 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200620 use_multistream_, encoder_sample_rate_hz_);
Alex Loiko50b8c392019-04-03 15:12:01 +0200621 ASSERT_NE(nullptr, opus_encoder_);
minyuec8299f92016-09-27 02:08:47 -0700622
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100623 if (channels_ >= 2) {
minyuec8299f92016-09-27 02:08:47 -0700624 EXPECT_EQ(-1, WebRtcOpus_SetForceChannels(opus_encoder_, 3));
625 EXPECT_EQ(0, WebRtcOpus_SetForceChannels(opus_encoder_, 2));
626 EXPECT_EQ(0, WebRtcOpus_SetForceChannels(opus_encoder_, 1));
627 EXPECT_EQ(0, WebRtcOpus_SetForceChannels(opus_encoder_, 0));
628 } else {
629 EXPECT_EQ(-1, WebRtcOpus_SetForceChannels(opus_encoder_, 2));
630 EXPECT_EQ(0, WebRtcOpus_SetForceChannels(opus_encoder_, 1));
631 EXPECT_EQ(0, WebRtcOpus_SetForceChannels(opus_encoder_, 0));
632 }
633
634 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
635}
636
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000637// Encode and decode one frame, initialize the decoder and
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000638// decode once more.
henrika1d34fe92015-06-16 10:04:20 +0200639TEST_P(OpusTest, OpusDecodeInit) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200640 PrepareSpeechData(20, 20);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000641
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000642 // Create encoder memory.
Alex Loiko50b8c392019-04-03 15:12:01 +0200643 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200644 use_multistream_, encoder_sample_rate_hz_);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200645 CreateSingleOrMultiStreamDecoder(&opus_decoder_, channels_, use_multistream_,
646 decoder_sample_rate_hz_);
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000647
648 // Encode & decode.
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000649 int16_t audio_type;
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200650 const int decode_samples_per_channel =
651 SamplesPerChannel(decoder_sample_rate_hz_, /*ms=*/20);
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200652 int16_t* output_data_decode =
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200653 new int16_t[decode_samples_per_channel * channels_];
654 EXPECT_EQ(decode_samples_per_channel,
655 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(),
656 opus_decoder_, output_data_decode, &audio_type));
minyue@webrtc.org52bc4f42014-12-04 11:00:50 +0000657
Karl Wiberg43766482015-08-27 15:22:11 +0200658 WebRtcOpus_DecoderInit(opus_decoder_);
minyue@webrtc.org52bc4f42014-12-04 11:00:50 +0000659
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200660 EXPECT_EQ(decode_samples_per_channel,
661 WebRtcOpus_Decode(opus_decoder_, bitstream_, encoded_bytes_,
662 output_data_decode, &audio_type));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000663
664 // Free memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000665 delete[] output_data_decode;
666 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
667 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000668}
669
henrika1d34fe92015-06-16 10:04:20 +0200670TEST_P(OpusTest, OpusEnableDisableFec) {
minyue@webrtc.org46509c82014-03-07 11:49:11 +0000671 // Test without creating encoder memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000672 EXPECT_EQ(-1, WebRtcOpus_EnableFec(opus_encoder_));
673 EXPECT_EQ(-1, WebRtcOpus_DisableFec(opus_encoder_));
minyue@webrtc.org46509c82014-03-07 11:49:11 +0000674
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000675 // Create encoder memory.
Alex Loiko50b8c392019-04-03 15:12:01 +0200676 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200677 use_multistream_, encoder_sample_rate_hz_);
minyue@webrtc.org46509c82014-03-07 11:49:11 +0000678
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000679 EXPECT_EQ(0, WebRtcOpus_EnableFec(opus_encoder_));
680 EXPECT_EQ(0, WebRtcOpus_DisableFec(opus_encoder_));
minyue@webrtc.org46509c82014-03-07 11:49:11 +0000681
682 // Free memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000683 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
minyue@webrtc.org46509c82014-03-07 11:49:11 +0000684}
685
henrika1d34fe92015-06-16 10:04:20 +0200686TEST_P(OpusTest, OpusEnableDisableDtx) {
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000687 // Test without creating encoder memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000688 EXPECT_EQ(-1, WebRtcOpus_EnableDtx(opus_encoder_));
689 EXPECT_EQ(-1, WebRtcOpus_DisableDtx(opus_encoder_));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000690
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000691 // Create encoder memory.
Alex Loiko50b8c392019-04-03 15:12:01 +0200692 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200693 use_multistream_, encoder_sample_rate_hz_);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000694
695 opus_int32 dtx;
696
697 // DTX is off by default.
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100698 ENCODER_CTL(opus_encoder_, OPUS_GET_DTX(&dtx));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000699 EXPECT_EQ(0, dtx);
700
701 // Test to enable DTX.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000702 EXPECT_EQ(0, WebRtcOpus_EnableDtx(opus_encoder_));
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100703 ENCODER_CTL(opus_encoder_, OPUS_GET_DTX(&dtx));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000704 EXPECT_EQ(1, dtx);
705
706 // Test to disable DTX.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000707 EXPECT_EQ(0, WebRtcOpus_DisableDtx(opus_encoder_));
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100708 ENCODER_CTL(opus_encoder_, OPUS_GET_DTX(&dtx));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000709 EXPECT_EQ(0, dtx);
710
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000711 // Free memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000712 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000713}
714
henrika1d34fe92015-06-16 10:04:20 +0200715TEST_P(OpusTest, OpusDtxOff) {
minyue3cea2562015-11-10 03:49:26 -0800716 TestDtxEffect(false, 10);
717 TestDtxEffect(false, 20);
718 TestDtxEffect(false, 40);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000719}
720
henrika1d34fe92015-06-16 10:04:20 +0200721TEST_P(OpusTest, OpusDtxOn) {
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100722 if (channels_ > 2) {
723 // TODO(webrtc:10218): adapt the test to the sizes and order of multi-stream
724 // DTX packets.
725 return;
726 }
minyue3cea2562015-11-10 03:49:26 -0800727 TestDtxEffect(true, 10);
728 TestDtxEffect(true, 20);
729 TestDtxEffect(true, 40);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000730}
731
soren28dc2852017-04-06 05:48:36 -0700732TEST_P(OpusTest, OpusCbrOff) {
733 TestCbrEffect(false, 10);
734 TestCbrEffect(false, 20);
735 TestCbrEffect(false, 40);
736}
737
738TEST_P(OpusTest, OpusCbrOn) {
739 TestCbrEffect(true, 10);
740 TestCbrEffect(true, 20);
741 TestCbrEffect(true, 40);
742}
743
henrika1d34fe92015-06-16 10:04:20 +0200744TEST_P(OpusTest, OpusSetPacketLossRate) {
minyue@webrtc.org46509c82014-03-07 11:49:11 +0000745 // Test without creating encoder memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000746 EXPECT_EQ(-1, WebRtcOpus_SetPacketLossRate(opus_encoder_, 50));
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000747
tina.legrand@webrtc.orgbd21fb52013-08-08 11:01:07 +0000748 // Create encoder memory.
Alex Loiko50b8c392019-04-03 15:12:01 +0200749 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200750 use_multistream_, encoder_sample_rate_hz_);
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000751
752 EXPECT_EQ(0, WebRtcOpus_SetPacketLossRate(opus_encoder_, 50));
753 EXPECT_EQ(-1, WebRtcOpus_SetPacketLossRate(opus_encoder_, -1));
754 EXPECT_EQ(-1, WebRtcOpus_SetPacketLossRate(opus_encoder_, 101));
755
756 // Free memory.
757 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
758}
759
henrika1d34fe92015-06-16 10:04:20 +0200760TEST_P(OpusTest, OpusSetMaxPlaybackRate) {
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000761 // Test without creating encoder memory.
762 EXPECT_EQ(-1, WebRtcOpus_SetMaxPlaybackRate(opus_encoder_, 20000));
763
764 // Create encoder memory.
Alex Loiko50b8c392019-04-03 15:12:01 +0200765 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200766 use_multistream_, encoder_sample_rate_hz_);
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000767
768 SetMaxPlaybackRate(opus_encoder_, OPUS_BANDWIDTH_FULLBAND, 48000);
769 SetMaxPlaybackRate(opus_encoder_, OPUS_BANDWIDTH_FULLBAND, 24001);
770 SetMaxPlaybackRate(opus_encoder_, OPUS_BANDWIDTH_SUPERWIDEBAND, 24000);
771 SetMaxPlaybackRate(opus_encoder_, OPUS_BANDWIDTH_SUPERWIDEBAND, 16001);
772 SetMaxPlaybackRate(opus_encoder_, OPUS_BANDWIDTH_WIDEBAND, 16000);
773 SetMaxPlaybackRate(opus_encoder_, OPUS_BANDWIDTH_WIDEBAND, 12001);
774 SetMaxPlaybackRate(opus_encoder_, OPUS_BANDWIDTH_MEDIUMBAND, 12000);
775 SetMaxPlaybackRate(opus_encoder_, OPUS_BANDWIDTH_MEDIUMBAND, 8001);
776 SetMaxPlaybackRate(opus_encoder_, OPUS_BANDWIDTH_NARROWBAND, 8000);
777 SetMaxPlaybackRate(opus_encoder_, OPUS_BANDWIDTH_NARROWBAND, 4000);
778
779 // Free memory.
780 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
781}
782
783// Test PLC.
henrika1d34fe92015-06-16 10:04:20 +0200784TEST_P(OpusTest, OpusDecodePlc) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200785 PrepareSpeechData(20, 20);
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000786
787 // Create encoder memory.
Alex Loiko50b8c392019-04-03 15:12:01 +0200788 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200789 use_multistream_, encoder_sample_rate_hz_);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200790 CreateSingleOrMultiStreamDecoder(&opus_decoder_, channels_, use_multistream_,
791 decoder_sample_rate_hz_);
tina.legrand@webrtc.orgbd21fb52013-08-08 11:01:07 +0000792
793 // Set bitrate.
Yves Gerey665174f2018-06-19 15:03:05 +0200794 EXPECT_EQ(
795 0, WebRtcOpus_SetBitRate(opus_encoder_, channels_ == 1 ? 32000 : 64000));
tina.legrand@webrtc.orgbd21fb52013-08-08 11:01:07 +0000796
797 // Check number of channels for decoder.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000798 EXPECT_EQ(channels_, WebRtcOpus_DecoderChannels(opus_decoder_));
tina.legrand@webrtc.orgbd21fb52013-08-08 11:01:07 +0000799
800 // Encode & decode.
tina.legrand@webrtc.orgbd21fb52013-08-08 11:01:07 +0000801 int16_t audio_type;
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200802 const int decode_samples_per_channel =
803 SamplesPerChannel(decoder_sample_rate_hz_, /*ms=*/20);
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200804 int16_t* output_data_decode =
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200805 new int16_t[decode_samples_per_channel * channels_];
806 EXPECT_EQ(decode_samples_per_channel,
807 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(),
808 opus_decoder_, output_data_decode, &audio_type));
tina.legrand@webrtc.orgbd21fb52013-08-08 11:01:07 +0000809
minyue@webrtc.org33ccdfa2014-12-04 12:14:12 +0000810 // Call decoder PLC.
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200811 int16_t* plc_buffer = new int16_t[decode_samples_per_channel * channels_];
812 EXPECT_EQ(decode_samples_per_channel,
813 WebRtcOpus_DecodePlc(opus_decoder_, plc_buffer, 1));
tina.legrand@webrtc.orgbd21fb52013-08-08 11:01:07 +0000814
815 // Free memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000816 delete[] plc_buffer;
817 delete[] output_data_decode;
818 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
819 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000820}
821
822// Duration estimation.
henrika1d34fe92015-06-16 10:04:20 +0200823TEST_P(OpusTest, OpusDurationEstimation) {
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200824 PrepareSpeechData(20, 20);
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000825
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000826 // Create.
Alex Loiko50b8c392019-04-03 15:12:01 +0200827 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200828 use_multistream_, encoder_sample_rate_hz_);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200829 CreateSingleOrMultiStreamDecoder(&opus_decoder_, channels_, use_multistream_,
830 decoder_sample_rate_hz_);
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000831
minyue@webrtc.org0ca768b2014-12-11 16:09:35 +0000832 // 10 ms. We use only first 10 ms of a 20 ms block.
kwiberg288886b2015-11-06 01:21:35 -0800833 auto speech_block = speech_data_.GetNextBlock();
834 int encoded_bytes_int = WebRtcOpus_Encode(
835 opus_encoder_, speech_block.data(),
Yves Gerey665174f2018-06-19 15:03:05 +0200836 rtc::CheckedDivExact(speech_block.size(), 2 * channels_), kMaxBytes,
837 bitstream_);
Peter Kastingdce40cf2015-08-24 14:52:23 -0700838 EXPECT_GE(encoded_bytes_int, 0);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200839 EXPECT_EQ(SamplesPerChannel(decoder_sample_rate_hz_, /*ms=*/10),
840 WebRtcOpus_DurationEst(opus_decoder_, bitstream_,
841 static_cast<size_t>(encoded_bytes_int)));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000842
843 // 20 ms
kwiberg288886b2015-11-06 01:21:35 -0800844 speech_block = speech_data_.GetNextBlock();
Yves Gerey665174f2018-06-19 15:03:05 +0200845 encoded_bytes_int =
846 WebRtcOpus_Encode(opus_encoder_, speech_block.data(),
847 rtc::CheckedDivExact(speech_block.size(), channels_),
848 kMaxBytes, bitstream_);
Peter Kastingdce40cf2015-08-24 14:52:23 -0700849 EXPECT_GE(encoded_bytes_int, 0);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200850 EXPECT_EQ(SamplesPerChannel(decoder_sample_rate_hz_, /*ms=*/20),
851 WebRtcOpus_DurationEst(opus_decoder_, bitstream_,
852 static_cast<size_t>(encoded_bytes_int)));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000853
854 // Free memory.
minyue@webrtc.org7dba7862015-01-20 16:01:50 +0000855 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
856 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000857}
858
henrika1d34fe92015-06-16 10:04:20 +0200859TEST_P(OpusTest, OpusDecodeRepacketized) {
Alex Loiko7a3e43a2019-01-29 12:27:08 +0100860 if (channels_ > 2) {
861 // As per the Opus documentation
862 // https://mf4.xiph.org/jenkins/view/opus/job/opus/ws/doc/html/group__opus__repacketizer.html#details,
863 // multiple streams are not supported.
864 return;
865 }
minyuea613eb62017-03-14 14:33:30 -0700866 constexpr size_t kPackets = 6;
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +0000867
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200868 PrepareSpeechData(20, 20 * kPackets);
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +0000869
870 // Create encoder memory.
Alex Loiko50b8c392019-04-03 15:12:01 +0200871 CreateSingleOrMultiStreamEncoder(&opus_encoder_, channels_, application_,
Karl Wiberg7e7c5c32019-05-21 11:50:32 +0200872 use_multistream_, encoder_sample_rate_hz_);
Alex Loiko50b8c392019-04-03 15:12:01 +0200873 ASSERT_NE(nullptr, opus_encoder_);
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200874 CreateSingleOrMultiStreamDecoder(&opus_decoder_, channels_, use_multistream_,
875 decoder_sample_rate_hz_);
Alex Loiko50b8c392019-04-03 15:12:01 +0200876 ASSERT_NE(nullptr, opus_decoder_);
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +0000877
878 // Set bitrate.
Yves Gerey665174f2018-06-19 15:03:05 +0200879 EXPECT_EQ(
880 0, WebRtcOpus_SetBitRate(opus_encoder_, channels_ == 1 ? 32000 : 64000));
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +0000881
882 // Check number of channels for decoder.
883 EXPECT_EQ(channels_, WebRtcOpus_DecoderChannels(opus_decoder_));
884
885 // Encode & decode.
886 int16_t audio_type;
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200887 const int decode_samples_per_channel =
888 SamplesPerChannel(decoder_sample_rate_hz_, /*ms=*/20);
kwiberg91d97562016-02-14 01:10:03 -0800889 std::unique_ptr<int16_t[]> output_data_decode(
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200890 new int16_t[kPackets * decode_samples_per_channel * channels_]);
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +0000891 OpusRepacketizer* rp = opus_repacketizer_create();
892
minyuea613eb62017-03-14 14:33:30 -0700893 size_t num_packets = 0;
894 constexpr size_t kMaxCycles = 100;
895 for (size_t idx = 0; idx < kMaxCycles; ++idx) {
kwiberg288886b2015-11-06 01:21:35 -0800896 auto speech_block = speech_data_.GetNextBlock();
897 encoded_bytes_ =
898 WebRtcOpus_Encode(opus_encoder_, speech_block.data(),
Peter Kasting69558702016-01-12 16:26:35 -0800899 rtc::CheckedDivExact(speech_block.size(), channels_),
kwiberg288886b2015-11-06 01:21:35 -0800900 kMaxBytes, bitstream_);
Yves Gerey665174f2018-06-19 15:03:05 +0200901 if (opus_repacketizer_cat(rp, bitstream_,
902 rtc::checked_cast<opus_int32>(encoded_bytes_)) ==
903 OPUS_OK) {
minyuea613eb62017-03-14 14:33:30 -0700904 ++num_packets;
905 if (num_packets == kPackets) {
906 break;
907 }
908 } else {
909 // Opus repacketizer cannot guarantee a success. We try again if it fails.
910 opus_repacketizer_init(rp);
911 num_packets = 0;
912 }
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +0000913 }
minyuea613eb62017-03-14 14:33:30 -0700914 EXPECT_EQ(kPackets, num_packets);
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +0000915
916 encoded_bytes_ = opus_repacketizer_out(rp, bitstream_, kMaxBytes);
917
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200918 EXPECT_EQ(decode_samples_per_channel * kPackets,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700919 static_cast<size_t>(WebRtcOpus_DurationEst(
920 opus_decoder_, bitstream_, encoded_bytes_)));
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +0000921
Karl Wiberga1d1a1e2019-05-28 14:41:07 +0200922 EXPECT_EQ(decode_samples_per_channel * kPackets,
Yves Gerey665174f2018-06-19 15:03:05 +0200923 static_cast<size_t>(
924 WebRtcOpus_Decode(opus_decoder_, bitstream_, encoded_bytes_,
925 output_data_decode.get(), &audio_type)));
minyue@webrtc.org7f7d7e32015-03-16 12:30:37 +0000926
927 // Free memory.
928 opus_repacketizer_destroy(rp);
929 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
930 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
931}
932
tina.legrand@webrtc.orgdb11fab2013-04-17 10:39:41 +0000933} // namespace webrtc