2014-03-07 11:49:11 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-14 01:10:03 -08:00
|
|
|
#include <memory>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/codecs/opus/opus_interface.h"
|
|
|
|
|
#include "test/gtest.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "test/testsupport/file_utils.h"
|
2014-03-07 11:49:11 +00:00
|
|
|
|
2017-10-23 23:33:04 +02:00
|
|
|
using std::get;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::tuple;
|
2014-03-07 11:49:11 +00:00
|
|
|
using ::testing::TestWithParam;
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// Define coding parameter as <channels, bit_rate, filename, extension>.
|
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
|
|
|
typedef tuple<size_t, int, string, string> coding_param;
|
2014-03-07 11:49:11 +00:00
|
|
|
typedef struct mode mode;
|
|
|
|
|
|
|
|
|
|
struct mode {
|
|
|
|
|
bool fec;
|
|
|
|
|
uint8_t target_packet_loss_rate;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const int kOpusBlockDurationMs = 20;
|
2014-07-18 21:11:27 +00:00
|
|
|
const int kOpusSamplingKhz = 48;
|
2014-03-07 11:49:11 +00:00
|
|
|
|
|
|
|
|
class OpusFecTest : public TestWithParam<coding_param> {
|
|
|
|
|
protected:
|
|
|
|
|
OpusFecTest();
|
|
|
|
|
|
2018-07-20 13:59:20 +02:00
|
|
|
void SetUp() override;
|
|
|
|
|
void TearDown() override;
|
2014-03-07 11:49:11 +00:00
|
|
|
|
|
|
|
|
virtual void EncodeABlock();
|
|
|
|
|
|
|
|
|
|
virtual void DecodeABlock(bool lost_previous, bool lost_current);
|
|
|
|
|
|
|
|
|
|
int block_duration_ms_;
|
2014-07-18 21:11:27 +00:00
|
|
|
int sampling_khz_;
|
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 block_length_sample_;
|
2014-03-07 11:49:11 +00:00
|
|
|
|
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 channels_;
|
2014-03-07 11:49:11 +00:00
|
|
|
int bit_rate_;
|
|
|
|
|
|
|
|
|
|
size_t data_pointer_;
|
|
|
|
|
size_t loop_length_samples_;
|
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 max_bytes_;
|
|
|
|
|
size_t encoded_bytes_;
|
2014-03-07 11:49:11 +00:00
|
|
|
|
|
|
|
|
WebRtcOpusEncInst* opus_encoder_;
|
|
|
|
|
WebRtcOpusDecInst* opus_decoder_;
|
|
|
|
|
|
|
|
|
|
string in_filename_;
|
|
|
|
|
|
2016-02-14 01:10:03 -08:00
|
|
|
std::unique_ptr<int16_t[]> in_data_;
|
|
|
|
|
std::unique_ptr<int16_t[]> out_data_;
|
|
|
|
|
std::unique_ptr<uint8_t[]> bit_stream_;
|
2014-03-07 11:49:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void OpusFecTest::SetUp() {
|
|
|
|
|
channels_ = get<0>(GetParam());
|
|
|
|
|
bit_rate_ = get<1>(GetParam());
|
2022-05-09 09:21:14 +02:00
|
|
|
printf("Coding %zu channel signal at %d bps.\n", channels_, bit_rate_);
|
2014-03-07 11:49:11 +00:00
|
|
|
|
|
|
|
|
in_filename_ = test::ResourcePath(get<2>(GetParam()), get<3>(GetParam()));
|
|
|
|
|
|
|
|
|
|
FILE* fp = fopen(in_filename_.c_str(), "rb");
|
|
|
|
|
ASSERT_FALSE(fp == NULL);
|
|
|
|
|
|
|
|
|
|
// Obtain file size.
|
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
|
loop_length_samples_ = ftell(fp) / sizeof(int16_t);
|
|
|
|
|
rewind(fp);
|
|
|
|
|
|
|
|
|
|
// Allocate memory to contain the whole file.
|
|
|
|
|
in_data_.reset(
|
2014-07-18 21:11:27 +00:00
|
|
|
new int16_t[loop_length_samples_ + block_length_sample_ * channels_]);
|
2014-03-07 11:49:11 +00:00
|
|
|
|
|
|
|
|
// Copy the file into the buffer.
|
|
|
|
|
ASSERT_EQ(fread(&in_data_[0], sizeof(int16_t), loop_length_samples_, fp),
|
|
|
|
|
loop_length_samples_);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
|
|
// The audio will be used in a looped manner. To ease the acquisition of an
|
|
|
|
|
// audio frame that crosses the end of the excerpt, we add an extra block
|
|
|
|
|
// length of samples to the end of the array, starting over again from the
|
|
|
|
|
// beginning of the array. Audio frames cross the end of the excerpt always
|
|
|
|
|
// appear as a continuum of memory.
|
|
|
|
|
memcpy(&in_data_[loop_length_samples_], &in_data_[0],
|
2014-07-18 21:11:27 +00:00
|
|
|
block_length_sample_ * channels_ * sizeof(int16_t));
|
2014-03-07 11:49:11 +00:00
|
|
|
|
|
|
|
|
// Maximum number of bytes in output bitstream.
|
2014-07-18 21:11:27 +00:00
|
|
|
max_bytes_ = block_length_sample_ * channels_ * sizeof(int16_t);
|
2014-03-07 11:49:11 +00:00
|
|
|
|
2014-07-18 21:11:27 +00:00
|
|
|
out_data_.reset(new int16_t[2 * block_length_sample_ * channels_]);
|
2014-03-07 11:49:11 +00:00
|
|
|
bit_stream_.reset(new uint8_t[max_bytes_]);
|
|
|
|
|
|
2015-01-20 16:01:50 +00:00
|
|
|
// If channels_ == 1, use Opus VOIP mode, otherwise, audio mode.
|
|
|
|
|
int app = channels_ == 1 ? 0 : 1;
|
|
|
|
|
|
2014-03-07 11:49:11 +00:00
|
|
|
// Create encoder memory.
|
2019-05-21 11:50:32 +02:00
|
|
|
EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_, channels_, app, 48000));
|
2019-05-28 14:41:07 +02:00
|
|
|
EXPECT_EQ(0, WebRtcOpus_DecoderCreate(&opus_decoder_, channels_, 48000));
|
2014-03-07 11:49:11 +00:00
|
|
|
// Set bitrate.
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_, bit_rate_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpusFecTest::TearDown() {
|
|
|
|
|
// Free memory.
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpusFecTest::OpusFecTest()
|
|
|
|
|
: block_duration_ms_(kOpusBlockDurationMs),
|
2014-07-18 21:11:27 +00:00
|
|
|
sampling_khz_(kOpusSamplingKhz),
|
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
|
|
|
block_length_sample_(
|
|
|
|
|
static_cast<size_t>(block_duration_ms_ * sampling_khz_)),
|
2014-03-07 11:49:11 +00:00
|
|
|
data_pointer_(0),
|
|
|
|
|
max_bytes_(0),
|
|
|
|
|
encoded_bytes_(0),
|
|
|
|
|
opus_encoder_(NULL),
|
|
|
|
|
opus_decoder_(NULL) {}
|
|
|
|
|
|
|
|
|
|
void OpusFecTest::EncodeABlock() {
|
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 value =
|
|
|
|
|
WebRtcOpus_Encode(opus_encoder_, &in_data_[data_pointer_],
|
|
|
|
|
block_length_sample_, max_bytes_, &bit_stream_[0]);
|
2014-03-07 11:49:11 +00:00
|
|
|
EXPECT_GT(value, 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
|
|
|
encoded_bytes_ = static_cast<size_t>(value);
|
2014-03-07 11:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpusFecTest::DecodeABlock(bool lost_previous, bool lost_current) {
|
|
|
|
|
int16_t audio_type;
|
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 value_1 = 0, value_2 = 0;
|
2014-03-07 11:49:11 +00:00
|
|
|
|
|
|
|
|
if (lost_previous) {
|
|
|
|
|
// Decode previous frame.
|
|
|
|
|
if (!lost_current &&
|
|
|
|
|
WebRtcOpus_PacketHasFec(&bit_stream_[0], encoded_bytes_) == 1) {
|
|
|
|
|
value_1 =
|
|
|
|
|
WebRtcOpus_DecodeFec(opus_decoder_, &bit_stream_[0], encoded_bytes_,
|
|
|
|
|
&out_data_[0], &audio_type);
|
|
|
|
|
} else {
|
2019-11-04 14:47:52 +01:00
|
|
|
// Call decoder PLC.
|
|
|
|
|
while (value_1 < static_cast<int>(block_length_sample_)) {
|
|
|
|
|
int ret = WebRtcOpus_Decode(opus_decoder_, NULL, 0, &out_data_[value_1],
|
|
|
|
|
&audio_type);
|
|
|
|
|
EXPECT_EQ(ret, sampling_khz_ * 10); // Should return 10 ms of samples.
|
|
|
|
|
value_1 += ret;
|
|
|
|
|
}
|
2014-03-07 11:49:11 +00:00
|
|
|
}
|
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
|
|
|
EXPECT_EQ(static_cast<int>(block_length_sample_), value_1);
|
2014-03-07 11:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lost_current) {
|
|
|
|
|
// Decode current frame.
|
2014-12-04 12:14:12 +00:00
|
|
|
value_2 = WebRtcOpus_Decode(opus_decoder_, &bit_stream_[0], encoded_bytes_,
|
|
|
|
|
&out_data_[value_1 * channels_], &audio_type);
|
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
|
|
|
EXPECT_EQ(static_cast<int>(block_length_sample_), value_2);
|
2014-03-07 11:49:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_P(OpusFecTest, RandomPacketLossTest) {
|
|
|
|
|
const int kDurationMs = 200000;
|
|
|
|
|
int time_now_ms, fec_frames;
|
|
|
|
|
int actual_packet_loss_rate;
|
|
|
|
|
bool lost_current, lost_previous;
|
|
|
|
|
mode mode_set[3] = {{true, 0}, {false, 0}, {true, 50}};
|
|
|
|
|
|
|
|
|
|
lost_current = false;
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
if (mode_set[i].fec) {
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_EnableFec(opus_encoder_));
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_SetPacketLossRate(
|
|
|
|
|
opus_encoder_, mode_set[i].target_packet_loss_rate));
|
|
|
|
|
printf("FEC is ON, target at packet loss rate %d percent.\n",
|
|
|
|
|
mode_set[i].target_packet_loss_rate);
|
|
|
|
|
} else {
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_DisableFec(opus_encoder_));
|
|
|
|
|
printf("FEC is OFF.\n");
|
|
|
|
|
}
|
|
|
|
|
// In this test, we let the target packet loss rate match the actual rate.
|
|
|
|
|
actual_packet_loss_rate = mode_set[i].target_packet_loss_rate;
|
|
|
|
|
// Run every mode a certain time.
|
|
|
|
|
time_now_ms = 0;
|
|
|
|
|
fec_frames = 0;
|
|
|
|
|
while (time_now_ms < kDurationMs) {
|
|
|
|
|
// Encode & decode.
|
|
|
|
|
EncodeABlock();
|
|
|
|
|
|
|
|
|
|
// Check if payload has FEC.
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
int fec = WebRtcOpus_PacketHasFec(&bit_stream_[0], encoded_bytes_);
|
2014-03-07 11:49:11 +00:00
|
|
|
|
|
|
|
|
// If FEC is disabled or the target packet loss rate is set to 0, there
|
|
|
|
|
// should be no FEC in the bit stream.
|
|
|
|
|
if (!mode_set[i].fec || mode_set[i].target_packet_loss_rate == 0) {
|
|
|
|
|
EXPECT_EQ(fec, 0);
|
|
|
|
|
} else if (fec == 1) {
|
|
|
|
|
fec_frames++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lost_previous = lost_current;
|
|
|
|
|
lost_current = rand() < actual_packet_loss_rate * (RAND_MAX / 100);
|
|
|
|
|
DecodeABlock(lost_previous, lost_current);
|
|
|
|
|
|
|
|
|
|
time_now_ms += block_duration_ms_;
|
|
|
|
|
|
2021-07-28 20:00:17 +02:00
|
|
|
// `data_pointer_` is incremented and wrapped across
|
|
|
|
|
// `loop_length_samples_`.
|
2014-07-18 21:11:27 +00:00
|
|
|
data_pointer_ = (data_pointer_ + block_length_sample_ * channels_) %
|
2014-03-07 11:49:11 +00:00
|
|
|
loop_length_samples_;
|
|
|
|
|
}
|
|
|
|
|
if (mode_set[i].fec) {
|
|
|
|
|
printf("%.2f percent frames has FEC.\n",
|
|
|
|
|
static_cast<float>(fec_frames) * block_duration_ms_ / 2000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-23 23:33:04 +02:00
|
|
|
const coding_param param_set[] = {
|
|
|
|
|
std::make_tuple(1,
|
|
|
|
|
64000,
|
|
|
|
|
string("audio_coding/testfile32kHz"),
|
|
|
|
|
string("pcm")),
|
|
|
|
|
std::make_tuple(1,
|
|
|
|
|
32000,
|
|
|
|
|
string("audio_coding/testfile32kHz"),
|
|
|
|
|
string("pcm")),
|
|
|
|
|
std::make_tuple(2,
|
|
|
|
|
64000,
|
|
|
|
|
string("audio_coding/teststereo32kHz"),
|
|
|
|
|
string("pcm"))};
|
2014-03-07 11:49:11 +00:00
|
|
|
|
|
|
|
|
// 64 kbps, stereo
|
2019-01-31 12:20:57 +01:00
|
|
|
INSTANTIATE_TEST_SUITE_P(AllTest, OpusFecTest, ::testing::ValuesIn(param_set));
|
2014-03-07 11:49:11 +00:00
|
|
|
|
|
|
|
|
} // namespace webrtc
|