2013-03-15 13:29:17 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/test/opus_test.h"
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2018-04-06 10:06:42 +02:00
|
|
|
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
2024-08-05 12:40:46 +02:00
|
|
|
#include "api/environment/environment_factory.h"
|
2024-09-27 07:18:06 +00:00
|
|
|
#include "api/neteq/default_neteq_factory.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/codecs/opus/opus_interface.h"
|
|
|
|
|
#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
|
|
|
|
|
#include "modules/audio_coding/test/TestStereo.h"
|
|
|
|
|
#include "test/gtest.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "test/testsupport/file_utils.h"
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2014-04-17 08:29:10 +00:00
|
|
|
OpusTest::OpusTest()
|
2024-09-13 13:46:56 +00:00
|
|
|
: neteq_(DefaultNetEqFactory().Create(CreateEnvironment(),
|
|
|
|
|
NetEq::Config(),
|
|
|
|
|
CreateBuiltinAudioDecoderFactory())),
|
2013-03-15 13:29:17 +00:00
|
|
|
channel_a2b_(NULL),
|
|
|
|
|
counter_(0),
|
|
|
|
|
payload_type_(255),
|
2014-04-17 08:29:10 +00:00
|
|
|
rtp_timestamp_(0) {}
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
OpusTest::~OpusTest() {
|
|
|
|
|
if (channel_a2b_ != NULL) {
|
|
|
|
|
delete channel_a2b_;
|
|
|
|
|
channel_a2b_ = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (opus_mono_encoder_ != NULL) {
|
|
|
|
|
WebRtcOpus_EncoderFree(opus_mono_encoder_);
|
|
|
|
|
opus_mono_encoder_ = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (opus_stereo_encoder_ != NULL) {
|
|
|
|
|
WebRtcOpus_EncoderFree(opus_stereo_encoder_);
|
|
|
|
|
opus_stereo_encoder_ = NULL;
|
|
|
|
|
}
|
2013-08-08 11:01:07 +00:00
|
|
|
if (opus_mono_decoder_ != NULL) {
|
|
|
|
|
WebRtcOpus_DecoderFree(opus_mono_decoder_);
|
|
|
|
|
opus_mono_decoder_ = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (opus_stereo_decoder_ != NULL) {
|
|
|
|
|
WebRtcOpus_DecoderFree(opus_stereo_decoder_);
|
|
|
|
|
opus_stereo_decoder_ = NULL;
|
|
|
|
|
}
|
2013-03-15 13:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpusTest::Perform() {
|
|
|
|
|
#ifndef WEBRTC_CODEC_OPUS
|
|
|
|
|
// Opus isn't defined, exit.
|
|
|
|
|
return;
|
|
|
|
|
#else
|
|
|
|
|
uint16_t frequency_hz;
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t audio_channels;
|
2013-03-15 13:29:17 +00:00
|
|
|
int16_t test_cntr = 0;
|
|
|
|
|
|
|
|
|
|
// Open both mono and stereo test files in 32 kHz.
|
|
|
|
|
const std::string file_name_stereo =
|
|
|
|
|
webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm");
|
|
|
|
|
const std::string file_name_mono =
|
|
|
|
|
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
|
|
|
|
|
frequency_hz = 32000;
|
|
|
|
|
in_file_stereo_.Open(file_name_stereo, frequency_hz, "rb");
|
|
|
|
|
in_file_stereo_.ReadStereo(true);
|
|
|
|
|
in_file_mono_.Open(file_name_mono, frequency_hz, "rb");
|
|
|
|
|
in_file_mono_.ReadStereo(false);
|
|
|
|
|
|
|
|
|
|
// Create Opus encoders for mono and stereo.
|
2019-05-21 11:50:32 +02:00
|
|
|
ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_mono_encoder_, 1, 0, 48000), -1);
|
|
|
|
|
ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_stereo_encoder_, 2, 1, 48000), -1);
|
2013-03-15 13:29:17 +00:00
|
|
|
|
2013-08-08 11:01:07 +00:00
|
|
|
// Create Opus decoders for mono and stereo for stand-alone testing of Opus.
|
2019-05-28 14:41:07 +02:00
|
|
|
ASSERT_GT(WebRtcOpus_DecoderCreate(&opus_mono_decoder_, 1, 48000), -1);
|
|
|
|
|
ASSERT_GT(WebRtcOpus_DecoderCreate(&opus_stereo_decoder_, 2, 48000), -1);
|
2015-08-27 15:22:11 +02:00
|
|
|
WebRtcOpus_DecoderInit(opus_mono_decoder_);
|
|
|
|
|
WebRtcOpus_DecoderInit(opus_stereo_decoder_);
|
2013-08-08 11:01:07 +00:00
|
|
|
|
2024-09-13 13:46:56 +00:00
|
|
|
ASSERT_TRUE(neteq_.get() != NULL);
|
|
|
|
|
neteq_->FlushBuffers();
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
// Register Opus stereo as receiving codec.
|
2018-12-05 10:30:25 +01:00
|
|
|
constexpr int kOpusPayloadType = 120;
|
|
|
|
|
const SdpAudioFormat kOpusFormatStereo("opus", 48000, 2, {{"stereo", "1"}});
|
|
|
|
|
payload_type_ = kOpusPayloadType;
|
2024-09-13 13:46:56 +00:00
|
|
|
neteq_->SetCodecs({{kOpusPayloadType, kOpusFormatStereo}});
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
// Create and connect the channel.
|
|
|
|
|
channel_a2b_ = new TestPackStereo;
|
2024-09-13 13:46:56 +00:00
|
|
|
channel_a2b_->RegisterReceiverNetEq(neteq_.get());
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Test Stereo.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
channel_a2b_->set_codec_mode(kStereo);
|
|
|
|
|
audio_channels = 2;
|
|
|
|
|
test_cntr++;
|
|
|
|
|
OpenOutFile(test_cntr);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 2.5 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 120);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 5 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 240);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 10 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 480);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 20 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 960);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 40 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 1920);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 60 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 2880);
|
|
|
|
|
|
|
|
|
|
out_file_.Close();
|
2013-08-08 11:01:07 +00:00
|
|
|
out_file_standalone_.Close();
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Test Opus stereo with packet-losses.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
test_cntr++;
|
|
|
|
|
OpenOutFile(test_cntr);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 20 ms frame size, 1% packet loss.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 960, 1);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 20 ms frame size, 5% packet loss.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 960, 5);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 20 ms frame size, 10% packet loss.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 960, 10);
|
|
|
|
|
|
|
|
|
|
out_file_.Close();
|
|
|
|
|
out_file_standalone_.Close();
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Test Mono.
|
|
|
|
|
//
|
|
|
|
|
channel_a2b_->set_codec_mode(kMono);
|
|
|
|
|
audio_channels = 1;
|
|
|
|
|
test_cntr++;
|
|
|
|
|
OpenOutFile(test_cntr);
|
|
|
|
|
|
|
|
|
|
// Register Opus mono as receiving codec.
|
2018-12-05 10:30:25 +01:00
|
|
|
const SdpAudioFormat kOpusFormatMono("opus", 48000, 2);
|
2024-09-13 13:46:56 +00:00
|
|
|
neteq_->SetCodecs({{kOpusPayloadType, kOpusFormatMono}});
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
// Run Opus with 2.5 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 32000, 120);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 5 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 32000, 240);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 10 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 32000, 480);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 20 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 32000, 960);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 40 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 32000, 1920);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 60 ms frame size.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 32000, 2880);
|
|
|
|
|
|
2013-08-08 11:01:07 +00:00
|
|
|
out_file_.Close();
|
|
|
|
|
out_file_standalone_.Close();
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Test Opus mono with packet-losses.
|
|
|
|
|
//
|
|
|
|
|
test_cntr++;
|
|
|
|
|
OpenOutFile(test_cntr);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 20 ms frame size, 1% packet loss.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 960, 1);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 20 ms frame size, 5% packet loss.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 960, 5);
|
|
|
|
|
|
|
|
|
|
// Run Opus with 20 ms frame size, 10% packet loss.
|
|
|
|
|
Run(channel_a2b_, audio_channels, 64000, 960, 10);
|
|
|
|
|
|
2013-03-15 13:29:17 +00:00
|
|
|
// Close the files.
|
|
|
|
|
in_file_stereo_.Close();
|
|
|
|
|
in_file_mono_.Close();
|
|
|
|
|
out_file_.Close();
|
2013-08-08 11:01:07 +00:00
|
|
|
out_file_standalone_.Close();
|
2013-03-15 13:29:17 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
void OpusTest::Run(TestPackStereo* channel,
|
|
|
|
|
size_t channels,
|
|
|
|
|
int bitrate,
|
|
|
|
|
size_t frame_length,
|
|
|
|
|
int percent_loss) {
|
2013-03-15 13:29:17 +00:00
|
|
|
AudioFrame audio_frame;
|
|
|
|
|
int32_t out_freq_hz_b = out_file_.SamplingFrequency();
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
const size_t kBufferSizeSamples = 480 * 12 * 2; // 120 ms stereo audio.
|
2014-04-24 19:05:33 +00:00
|
|
|
int16_t audio[kBufferSizeSamples];
|
|
|
|
|
int16_t out_audio[kBufferSizeSamples];
|
2013-08-08 11:01:07 +00:00
|
|
|
int16_t audio_type;
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
size_t written_samples = 0;
|
|
|
|
|
size_t read_samples = 0;
|
|
|
|
|
size_t decoded_samples = 0;
|
2014-07-18 21:11:27 +00:00
|
|
|
bool first_packet = true;
|
|
|
|
|
uint32_t start_time_stamp = 0;
|
2013-11-11 22:03:52 +00:00
|
|
|
|
2013-03-15 13:29:17 +00:00
|
|
|
channel->reset_payload_size();
|
2013-08-08 11:01:07 +00:00
|
|
|
counter_ = 0;
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
// Set encoder rate.
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_mono_encoder_, bitrate));
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_stereo_encoder_, bitrate));
|
|
|
|
|
|
2014-03-24 14:38:36 +00:00
|
|
|
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM)
|
|
|
|
|
// If we are on Android, iOS and/or ARM, use a lower complexity setting as
|
|
|
|
|
// default.
|
|
|
|
|
const int kOpusComplexity5 = 5;
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_mono_encoder_, kOpusComplexity5));
|
2018-06-19 15:03:05 +02:00
|
|
|
EXPECT_EQ(0,
|
|
|
|
|
WebRtcOpus_SetComplexity(opus_stereo_encoder_, kOpusComplexity5));
|
2014-03-24 14:38:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
2015-12-10 16:24:39 +01:00
|
|
|
// Fast-forward 1 second (100 blocks) since the files start with silence.
|
|
|
|
|
in_file_stereo_.FastForward(100);
|
|
|
|
|
in_file_mono_.FastForward(100);
|
|
|
|
|
|
|
|
|
|
// Limit the runtime to 1000 blocks of 10 ms each.
|
|
|
|
|
for (size_t audio_length = 0; audio_length < 1000; audio_length += 10) {
|
2013-08-08 11:01:07 +00:00
|
|
|
bool lost_packet = false;
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
// Get 10 msec of audio.
|
|
|
|
|
if (channels == 1) {
|
|
|
|
|
if (in_file_mono_.EndOfFile()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
in_file_mono_.Read10MsData(audio_frame);
|
|
|
|
|
} else {
|
|
|
|
|
if (in_file_stereo_.EndOfFile()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
in_file_stereo_.Read10MsData(audio_frame);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 11:01:07 +00:00
|
|
|
// If input audio is sampled at 32 kHz, resampling to 48 kHz is required.
|
2018-06-19 15:03:05 +02:00
|
|
|
EXPECT_EQ(480, resampler_.Resample10Msec(
|
|
|
|
|
audio_frame.data(), audio_frame.sample_rate_hz_, 48000,
|
|
|
|
|
channels, kBufferSizeSamples - written_samples,
|
|
|
|
|
&audio[written_samples]));
|
2013-03-15 13:29:17 +00:00
|
|
|
written_samples += 480 * channels;
|
|
|
|
|
|
|
|
|
|
// Sometimes we need to loop over the audio vector to produce the right
|
|
|
|
|
// number of packets.
|
2018-06-19 15:03:05 +02:00
|
|
|
size_t loop_encode =
|
|
|
|
|
(written_samples - read_samples) / (channels * frame_length);
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
if (loop_encode > 0) {
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
const size_t kMaxBytes = 1000; // Maximum number of bytes for one packet.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t bitstream_len_byte;
|
2013-03-15 13:29:17 +00:00
|
|
|
uint8_t bitstream[kMaxBytes];
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
for (size_t i = 0; i < loop_encode; i++) {
|
Reland "Upconvert various types to int.", misc. codecs portion.
This reverts portions of commit cb180976dd0e9672cde4523d87b5f4857478b5e9, which
reverted commit 83ad33a8aed1fb00e422b6abd33c3e8942821c24. Specifically, the
files in webrtc/modules/audio_coding/codecs/ that are not in ilbc/ or isac/, as
well as webrtc/modules/audio_coding/main/test/opus_test.cc, are relanded.
The original commit message is below:
Upconvert various types to int.
Per comments from HL/kwiberg on https://webrtc-codereview.appspot.com/42569004 , when there is existing usage of mixed types (int16_t, int, etc.), we'd prefer to standardize on larger types like int and phase out use of int16_t.
Specifically, "Using int16 just because we're sure all reasonable values will fit in 16 bits isn't usually meaningful in C."
This converts some existing uses of int16_t (and, in a few cases, other types such as uint16_t) to int (or, in a few places, int32_t). Other locations will be converted to size_t in a separate change.
BUG=none
TBR=kwiberg
Review URL: https://codereview.webrtc.org/1179093003
Cr-Commit-Position: refs/heads/master@{#9424}
2015-06-11 19:02:46 -07:00
|
|
|
int bitstream_len_byte_int = WebRtcOpus_Encode(
|
|
|
|
|
(channels == 1) ? opus_mono_encoder_ : opus_stereo_encoder_,
|
|
|
|
|
&audio[read_samples], frame_length, kMaxBytes, bitstream);
|
|
|
|
|
ASSERT_GE(bitstream_len_byte_int, 0);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
bitstream_len_byte = static_cast<size_t>(bitstream_len_byte_int);
|
2013-08-08 11:01:07 +00:00
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// Simulate packet loss by setting `packet_loss_` to "true" in
|
|
|
|
|
// `percent_loss` percent of the loops.
|
2013-08-08 11:01:07 +00:00
|
|
|
// TODO(tlegrand): Move handling of loss simulation to TestPackStereo.
|
|
|
|
|
if (percent_loss > 0) {
|
|
|
|
|
if (counter_ == floor((100 / percent_loss) + 0.5)) {
|
|
|
|
|
counter_ = 0;
|
|
|
|
|
lost_packet = true;
|
|
|
|
|
channel->set_lost_packet(true);
|
|
|
|
|
} else {
|
|
|
|
|
lost_packet = false;
|
|
|
|
|
channel->set_lost_packet(false);
|
|
|
|
|
}
|
|
|
|
|
counter_++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run stand-alone Opus decoder, or decode PLC.
|
|
|
|
|
if (channels == 1) {
|
|
|
|
|
if (!lost_packet) {
|
2014-12-04 12:14:12 +00:00
|
|
|
decoded_samples += WebRtcOpus_Decode(
|
2013-08-08 11:01:07 +00:00
|
|
|
opus_mono_decoder_, bitstream, bitstream_len_byte,
|
|
|
|
|
&out_audio[decoded_samples * channels], &audio_type);
|
|
|
|
|
} else {
|
2019-11-04 14:47:52 +01:00
|
|
|
// Call decoder PLC.
|
|
|
|
|
constexpr int kPlcDurationMs = 10;
|
|
|
|
|
constexpr int kPlcSamples = 48 * kPlcDurationMs;
|
|
|
|
|
size_t total_plc_samples = 0;
|
|
|
|
|
while (total_plc_samples < frame_length) {
|
|
|
|
|
int ret = WebRtcOpus_Decode(
|
|
|
|
|
opus_mono_decoder_, NULL, 0,
|
|
|
|
|
&out_audio[decoded_samples * channels], &audio_type);
|
|
|
|
|
EXPECT_EQ(ret, kPlcSamples);
|
|
|
|
|
decoded_samples += ret;
|
|
|
|
|
total_plc_samples += ret;
|
|
|
|
|
}
|
|
|
|
|
EXPECT_EQ(total_plc_samples, frame_length);
|
2013-08-08 11:01:07 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!lost_packet) {
|
2014-12-04 12:14:12 +00:00
|
|
|
decoded_samples += WebRtcOpus_Decode(
|
2013-08-08 11:01:07 +00:00
|
|
|
opus_stereo_decoder_, bitstream, bitstream_len_byte,
|
|
|
|
|
&out_audio[decoded_samples * channels], &audio_type);
|
|
|
|
|
} else {
|
2019-11-04 14:47:52 +01:00
|
|
|
// Call decoder PLC.
|
|
|
|
|
constexpr int kPlcDurationMs = 10;
|
|
|
|
|
constexpr int kPlcSamples = 48 * kPlcDurationMs;
|
|
|
|
|
size_t total_plc_samples = 0;
|
|
|
|
|
while (total_plc_samples < frame_length) {
|
|
|
|
|
int ret = WebRtcOpus_Decode(
|
|
|
|
|
opus_stereo_decoder_, NULL, 0,
|
|
|
|
|
&out_audio[decoded_samples * channels], &audio_type);
|
|
|
|
|
EXPECT_EQ(ret, kPlcSamples);
|
|
|
|
|
decoded_samples += ret;
|
|
|
|
|
total_plc_samples += ret;
|
|
|
|
|
}
|
|
|
|
|
EXPECT_EQ(total_plc_samples, frame_length);
|
2013-08-08 11:01:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send data to the channel. "channel" will handle the loss simulation.
|
2019-03-19 14:10:16 +01:00
|
|
|
channel->SendData(AudioFrameType::kAudioFrameSpeech, payload_type_,
|
2020-01-23 13:45:50 +01:00
|
|
|
rtp_timestamp_, bitstream, bitstream_len_byte, 0);
|
2014-07-18 21:11:27 +00:00
|
|
|
if (first_packet) {
|
|
|
|
|
first_packet = false;
|
|
|
|
|
start_time_stamp = rtp_timestamp_;
|
|
|
|
|
}
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
rtp_timestamp_ += static_cast<uint32_t>(frame_length);
|
2013-03-15 13:29:17 +00:00
|
|
|
read_samples += frame_length * channels;
|
|
|
|
|
}
|
|
|
|
|
if (read_samples == written_samples) {
|
|
|
|
|
read_samples = 0;
|
|
|
|
|
written_samples = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run received side of ACM.
|
2016-05-17 12:21:55 -07:00
|
|
|
bool muted;
|
2024-09-13 13:46:56 +00:00
|
|
|
ASSERT_EQ(NetEq::kOK, neteq_->GetAudio(&audio_frame, &muted));
|
|
|
|
|
ASSERT_TRUE(resampler_helper_.MaybeResample(out_freq_hz_b, &audio_frame));
|
2013-03-15 13:29:17 +00:00
|
|
|
|
|
|
|
|
// Write output speech to file.
|
|
|
|
|
out_file_.Write10MsData(
|
2017-06-12 12:45:32 -07:00
|
|
|
audio_frame.data(),
|
2013-03-15 13:29:17 +00:00
|
|
|
audio_frame.samples_per_channel_ * audio_frame.num_channels_);
|
2013-08-08 11:01:07 +00:00
|
|
|
|
|
|
|
|
// Write stand-alone speech to file.
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
out_file_standalone_.Write10MsData(out_audio, decoded_samples * channels);
|
2014-03-23 09:58:48 +00:00
|
|
|
|
2014-07-18 21:11:27 +00:00
|
|
|
if (audio_frame.timestamp_ > start_time_stamp) {
|
|
|
|
|
// Number of channels should be the same for both stand-alone and
|
|
|
|
|
// ACM-decoding.
|
|
|
|
|
EXPECT_EQ(audio_frame.num_channels_, channels);
|
|
|
|
|
}
|
2014-03-23 09:58:48 +00:00
|
|
|
|
2013-08-08 11:01:07 +00:00
|
|
|
decoded_samples = 0;
|
2013-03-15 13:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in_file_mono_.EndOfFile()) {
|
|
|
|
|
in_file_mono_.Rewind();
|
|
|
|
|
}
|
|
|
|
|
if (in_file_stereo_.EndOfFile()) {
|
|
|
|
|
in_file_stereo_.Rewind();
|
|
|
|
|
}
|
|
|
|
|
// Reset in case we ended with a lost packet.
|
|
|
|
|
channel->set_lost_packet(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpusTest::OpenOutFile(int test_number) {
|
|
|
|
|
std::string file_name;
|
|
|
|
|
std::stringstream file_stream;
|
2018-06-19 15:03:05 +02:00
|
|
|
file_stream << webrtc::test::OutputPath() << "opustest_out_" << test_number
|
|
|
|
|
<< ".pcm";
|
2013-03-15 13:29:17 +00:00
|
|
|
file_name = file_stream.str();
|
2014-07-18 21:11:27 +00:00
|
|
|
out_file_.Open(file_name, 48000, "wb");
|
2013-08-08 11:01:07 +00:00
|
|
|
file_stream.str("");
|
|
|
|
|
file_name = file_stream.str();
|
|
|
|
|
file_stream << webrtc::test::OutputPath() << "opusstandalone_out_"
|
2018-06-19 15:03:05 +02:00
|
|
|
<< test_number << ".pcm";
|
2013-08-08 11:01:07 +00:00
|
|
|
file_name = file_stream.str();
|
2014-07-18 21:11:27 +00:00
|
|
|
out_file_standalone_.Open(file_name, 48000, "wb");
|
2013-03-15 13:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|