2014-03-07 08:55:48 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/codecs/opus/opus_interface.h"
|
|
|
|
|
#include "modules/audio_coding/codecs/tools/audio_codec_speed_test.h"
|
2014-03-07 08:55:48 +00:00
|
|
|
|
2014-06-02 15:22:33 +00:00
|
|
|
using ::std::string;
|
2014-03-07 08:55:48 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
static const int kOpusBlockDurationMs = 20;
|
2014-07-18 21:11:27 +00:00
|
|
|
static const int kOpusSamplingKhz = 48;
|
2014-03-07 08:55:48 +00:00
|
|
|
|
|
|
|
|
class OpusSpeedTest : public AudioCodecSpeedTest {
|
|
|
|
|
protected:
|
|
|
|
|
OpusSpeedTest();
|
2015-03-04 12:58:35 +00:00
|
|
|
void SetUp() override;
|
|
|
|
|
void TearDown() override;
|
2016-04-29 06:09:15 -07:00
|
|
|
float EncodeABlock(int16_t* in_data, uint8_t* bit_stream,
|
|
|
|
|
size_t max_bytes, size_t* encoded_bytes) override;
|
|
|
|
|
float DecodeABlock(const uint8_t* bit_stream, size_t encoded_bytes,
|
|
|
|
|
int16_t* out_data) override;
|
2014-03-07 08:55:48 +00:00
|
|
|
WebRtcOpusEncInst* opus_encoder_;
|
|
|
|
|
WebRtcOpusDecInst* opus_decoder_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
OpusSpeedTest::OpusSpeedTest()
|
|
|
|
|
: AudioCodecSpeedTest(kOpusBlockDurationMs,
|
2014-07-18 21:11:27 +00:00
|
|
|
kOpusSamplingKhz,
|
|
|
|
|
kOpusSamplingKhz),
|
2014-03-07 08:55:48 +00:00
|
|
|
opus_encoder_(NULL),
|
|
|
|
|
opus_decoder_(NULL) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpusSpeedTest::SetUp() {
|
|
|
|
|
AudioCodecSpeedTest::SetUp();
|
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 08:55:48 +00:00
|
|
|
/* Create encoder memory. */
|
2015-01-20 16:01:50 +00:00
|
|
|
EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_, channels_, app));
|
2014-03-07 08:55:48 +00:00
|
|
|
EXPECT_EQ(0, WebRtcOpus_DecoderCreate(&opus_decoder_, channels_));
|
|
|
|
|
/* Set bitrate. */
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_, bit_rate_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpusSpeedTest::TearDown() {
|
|
|
|
|
AudioCodecSpeedTest::TearDown();
|
|
|
|
|
/* Free memory. */
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_));
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float OpusSpeedTest::EncodeABlock(int16_t* in_data, uint8_t* bit_stream,
|
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 08:55:48 +00:00
|
|
|
clock_t clocks = clock();
|
|
|
|
|
int value = WebRtcOpus_Encode(opus_encoder_, in_data,
|
|
|
|
|
input_length_sample_, max_bytes,
|
|
|
|
|
bit_stream);
|
|
|
|
|
clocks = clock() - clocks;
|
|
|
|
|
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 08:55:48 +00:00
|
|
|
return 1000.0 * clocks / CLOCKS_PER_SEC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float OpusSpeedTest::DecodeABlock(const uint8_t* bit_stream,
|
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 encoded_bytes, int16_t* out_data) {
|
2014-03-07 08:55:48 +00:00
|
|
|
int value;
|
|
|
|
|
int16_t audio_type;
|
|
|
|
|
clock_t clocks = clock();
|
2014-12-04 12:14:12 +00:00
|
|
|
value = WebRtcOpus_Decode(opus_decoder_, bit_stream, encoded_bytes, out_data,
|
|
|
|
|
&audio_type);
|
2014-03-07 08:55:48 +00:00
|
|
|
clocks = clock() - clocks;
|
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
|
|
|
EXPECT_EQ(output_length_sample_, static_cast<size_t>(value));
|
2014-03-07 08:55:48 +00:00
|
|
|
return 1000.0 * clocks / CLOCKS_PER_SEC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define ADD_TEST(complexity) \
|
|
|
|
|
TEST_P(OpusSpeedTest, OpusSetComplexityTest##complexity) { \
|
|
|
|
|
/* Test audio length in second. */ \
|
|
|
|
|
size_t kDurationSec = 400; \
|
|
|
|
|
/* Set complexity. */ \
|
|
|
|
|
printf("Setting complexity to %d ...\n", complexity); \
|
|
|
|
|
EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_encoder_, complexity)); \
|
|
|
|
|
EncodeDecode(kDurationSec); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ADD_TEST(10);
|
|
|
|
|
ADD_TEST(9);
|
|
|
|
|
ADD_TEST(8);
|
|
|
|
|
ADD_TEST(7);
|
|
|
|
|
ADD_TEST(6);
|
|
|
|
|
ADD_TEST(5);
|
|
|
|
|
ADD_TEST(4);
|
|
|
|
|
ADD_TEST(3);
|
|
|
|
|
ADD_TEST(2);
|
|
|
|
|
ADD_TEST(1);
|
|
|
|
|
ADD_TEST(0);
|
|
|
|
|
|
|
|
|
|
// List all test cases: (channel, bit rat, filename, extension).
|
2017-10-23 23:33:04 +02:00
|
|
|
const coding_param param_set[] = {
|
|
|
|
|
std::make_tuple(1,
|
|
|
|
|
64000,
|
|
|
|
|
string("audio_coding/speech_mono_32_48kHz"),
|
|
|
|
|
string("pcm"),
|
|
|
|
|
true),
|
|
|
|
|
std::make_tuple(1,
|
|
|
|
|
32000,
|
|
|
|
|
string("audio_coding/speech_mono_32_48kHz"),
|
|
|
|
|
string("pcm"),
|
|
|
|
|
true),
|
|
|
|
|
std::make_tuple(2,
|
|
|
|
|
64000,
|
|
|
|
|
string("audio_coding/music_stereo_48kHz"),
|
|
|
|
|
string("pcm"),
|
|
|
|
|
true)};
|
2014-03-07 08:55:48 +00:00
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(AllTest, OpusSpeedTest,
|
2014-08-16 18:49:55 +00:00
|
|
|
::testing::ValuesIn(param_set));
|
2014-03-07 08:55:48 +00:00
|
|
|
|
|
|
|
|
} // namespace webrtc
|