Adding Opus frame length test
BUG=issue1015 Review URL: https://webrtc-codereview.appspot.com/1193005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3672 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
d613c207cc
commit
73222cff1a
@ -134,6 +134,7 @@
|
|||||||
'../test/dual_stream_unittest.cc',
|
'../test/dual_stream_unittest.cc',
|
||||||
'../test/EncodeDecodeTest.cc',
|
'../test/EncodeDecodeTest.cc',
|
||||||
'../test/iSACTest.cc',
|
'../test/iSACTest.cc',
|
||||||
|
'../test/opus_test.cc',
|
||||||
'../test/PCMFile.cc',
|
'../test/PCMFile.cc',
|
||||||
'../test/RTPFile.cc',
|
'../test/RTPFile.cc',
|
||||||
'../test/SpatialAudio.cc',
|
'../test/SpatialAudio.cc',
|
||||||
|
@ -8,25 +8,27 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "webrtc/modules/audio_coding/main/test/APITest.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
|
#include "webrtc/common_types.h"
|
||||||
#include "APITest.h"
|
#include "webrtc/engine_configurations.h"
|
||||||
#include "common_types.h"
|
#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
|
||||||
#include "engine_configurations.h"
|
#include "webrtc/modules/audio_coding/main/test/utility.h"
|
||||||
#include "event_wrapper.h"
|
#include "webrtc/system_wrappers/interface/event_wrapper.h"
|
||||||
#include "thread_wrapper.h"
|
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
|
||||||
#include "testsupport/fileutils.h"
|
#include "webrtc/system_wrappers/interface/tick_util.h"
|
||||||
#include "tick_util.h"
|
#include "webrtc/system_wrappers/interface/trace.h"
|
||||||
#include "trace.h"
|
#include "webrtc/test/testsupport/fileutils.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
@ -8,21 +8,22 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "EncodeDecodeTest.h"
|
#include "webrtc/modules/audio_coding/main/test/EncodeDecodeTest.h"
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
|
#include "webrtc/common_types.h"
|
||||||
#include "audio_coding_module.h"
|
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
|
||||||
#include "common_types.h"
|
#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
|
||||||
#include "testsupport/fileutils.h"
|
#include "webrtc/modules/audio_coding/main/test/utility.h"
|
||||||
#include "trace.h"
|
#include "webrtc/system_wrappers/interface/trace.h"
|
||||||
#include "utility.h"
|
#include "webrtc/test/testsupport/fileutils.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
@ -8,16 +8,17 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "TestVADDTX.h"
|
#include "webrtc/modules/audio_coding/main/test/TestVADDTX.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "audio_coding_module_typedefs.h"
|
#include "webrtc/common_types.h"
|
||||||
#include "common_types.h"
|
#include "webrtc/engine_configurations.h"
|
||||||
#include "engine_configurations.h"
|
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
|
||||||
#include "testsupport/fileutils.h"
|
#include "webrtc/modules/audio_coding/main/test/utility.h"
|
||||||
#include "trace.h"
|
#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
|
||||||
#include "utility.h"
|
#include "webrtc/test/testsupport/fileutils.h"
|
||||||
|
#include "webrtc/system_wrappers/interface/trace.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
@ -12,19 +12,19 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
|
||||||
#include "APITest.h"
|
#include "webrtc/modules/audio_coding/main/test/APITest.h"
|
||||||
#include "audio_coding_module.h"
|
#include "webrtc/modules/audio_coding/main/test/EncodeDecodeTest.h"
|
||||||
#include "EncodeDecodeTest.h"
|
#include "webrtc/modules/audio_coding/main/test/iSACTest.h"
|
||||||
#include "iSACTest.h"
|
#include "webrtc/modules/audio_coding/main/test/opus_test.h"
|
||||||
#include "TestAllCodecs.h"
|
#include "webrtc/modules/audio_coding/main/test/TestAllCodecs.h"
|
||||||
#include "TestFEC.h"
|
#include "webrtc/modules/audio_coding/main/test/TestFEC.h"
|
||||||
#include "TestStereo.h"
|
#include "webrtc/modules/audio_coding/main/test/TestStereo.h"
|
||||||
#include "testsupport/fileutils.h"
|
#include "webrtc/modules/audio_coding/main/test/TestVADDTX.h"
|
||||||
#include "TestVADDTX.h"
|
#include "webrtc/modules/audio_coding/main/test/TwoWayCommunication.h"
|
||||||
#include "trace.h"
|
#include "webrtc/system_wrappers/interface/trace.h"
|
||||||
#include "TwoWayCommunication.h"
|
#include "webrtc/test/testsupport/fileutils.h"
|
||||||
|
|
||||||
using webrtc::AudioCodingModule;
|
using webrtc::AudioCodingModule;
|
||||||
using webrtc::Trace;
|
using webrtc::Trace;
|
||||||
@ -128,6 +128,14 @@ TEST(AudioCodingModuleTest, TestAllCodecs) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
TEST(AudioCodingModuleTest, TestOpus) {
|
||||||
|
Trace::CreateTrace();
|
||||||
|
Trace::SetTraceFile((webrtc::test::OutputPath() +
|
||||||
|
"acm_opus_trace.txt").c_str());
|
||||||
|
webrtc::OpusTest().Perform();
|
||||||
|
Trace::ReturnTrace();
|
||||||
|
}
|
||||||
|
|
||||||
TEST(AudioCodingModuleTest, RunAllTests) {
|
TEST(AudioCodingModuleTest, RunAllTests) {
|
||||||
std::vector<ACMTest*> tests;
|
std::vector<ACMTest*> tests;
|
||||||
PopulateTests(&tests);
|
PopulateTests(&tests);
|
||||||
|
@ -16,16 +16,17 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "gflags/gflags.h"
|
#include "gflags/gflags.h"
|
||||||
#include "gtest/gtest.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
#include "testsupport/fileutils.h"
|
|
||||||
#include "webrtc/common_types.h"
|
#include "webrtc/common_types.h"
|
||||||
#include "webrtc/engine_configurations.h"
|
#include "webrtc/engine_configurations.h"
|
||||||
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
|
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
|
||||||
#include "webrtc/modules/audio_coding/main/test/Channel.h"
|
#include "webrtc/modules/audio_coding/main/test/Channel.h"
|
||||||
#include "webrtc/modules/audio_coding/main/test/PCMFile.h"
|
#include "webrtc/modules/audio_coding/main/test/PCMFile.h"
|
||||||
#include "webrtc/modules/audio_coding/main/test/utility.h"
|
#include "webrtc/modules/audio_coding/main/test/utility.h"
|
||||||
#include "webrtc/system_wrappers/interface/event_wrapper.h"
|
#include "webrtc/system_wrappers/interface/event_wrapper.h"
|
||||||
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
||||||
|
#include "webrtc/test/testsupport/fileutils.h"
|
||||||
|
|
||||||
DEFINE_string(codec, "isac", "Codec Name");
|
DEFINE_string(codec, "isac", "Codec Name");
|
||||||
DEFINE_int32(sample_rate_hz, 16000, "Sampling rate in Hertz.");
|
DEFINE_int32(sample_rate_hz, 16000, "Sampling rate in Hertz.");
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "webrtc/modules/audio_coding/main/test/iSACTest.h"
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -21,12 +23,12 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "event_wrapper.h"
|
#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
|
||||||
#include "iSACTest.h"
|
#include "webrtc/modules/audio_coding/main/test/utility.h"
|
||||||
#include "utility.h"
|
#include "webrtc/system_wrappers/interface/event_wrapper.h"
|
||||||
#include "trace.h"
|
#include "webrtc/system_wrappers/interface/tick_util.h"
|
||||||
#include "testsupport/fileutils.h"
|
#include "webrtc/system_wrappers/interface/trace.h"
|
||||||
#include "tick_util.h"
|
#include "webrtc/test/testsupport/fileutils.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
270
webrtc/modules/audio_coding/main/test/opus_test.cc
Normal file
270
webrtc/modules/audio_coding/main/test/opus_test.cc
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "webrtc/modules/audio_coding/main/test/opus_test.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
|
#include "webrtc/common_types.h"
|
||||||
|
#include "webrtc/engine_configurations.h"
|
||||||
|
#include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/source/acm_opus.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/test/TestStereo.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/test/utility.h"
|
||||||
|
#include "webrtc/system_wrappers/interface/trace.h"
|
||||||
|
#include "webrtc/test/testsupport/fileutils.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
OpusTest::OpusTest()
|
||||||
|
: acm_receiver_(NULL),
|
||||||
|
channel_a2b_(NULL),
|
||||||
|
counter_(0),
|
||||||
|
payload_type_(255),
|
||||||
|
rtp_timestamp_(0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
OpusTest::~OpusTest() {
|
||||||
|
if (acm_receiver_ != NULL) {
|
||||||
|
AudioCodingModule::Destroy(acm_receiver_);
|
||||||
|
acm_receiver_ = NULL;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpusTest::Perform() {
|
||||||
|
#ifndef WEBRTC_CODEC_OPUS
|
||||||
|
// Opus isn't defined, exit.
|
||||||
|
return;
|
||||||
|
#else
|
||||||
|
uint16_t frequency_hz;
|
||||||
|
int audio_channels;
|
||||||
|
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.
|
||||||
|
ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_mono_encoder_, 1), -1);
|
||||||
|
ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_stereo_encoder_, 2), -1);
|
||||||
|
|
||||||
|
// Create and initialize one ACM, to be used as receiver.
|
||||||
|
acm_receiver_ = AudioCodingModule::Create(0);
|
||||||
|
ASSERT_TRUE(acm_receiver_ != NULL);
|
||||||
|
EXPECT_EQ(0, acm_receiver_->InitializeReceiver());
|
||||||
|
|
||||||
|
// Register Opus stereo as receiving codec.
|
||||||
|
CodecInst opus_codec_param;
|
||||||
|
int codec_id = acm_receiver_->Codec("opus", 48000, 2);
|
||||||
|
EXPECT_EQ(0, acm_receiver_->Codec(codec_id, &opus_codec_param));
|
||||||
|
payload_type_ = opus_codec_param.pltype;
|
||||||
|
EXPECT_EQ(0, acm_receiver_->RegisterReceiveCodec(opus_codec_param));
|
||||||
|
|
||||||
|
// Create and connect the channel.
|
||||||
|
channel_a2b_ = new TestPackStereo;
|
||||||
|
channel_a2b_->RegisterReceiverACM(acm_receiver_);
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Test Mono.
|
||||||
|
//
|
||||||
|
channel_a2b_->set_codec_mode(kMono);
|
||||||
|
audio_channels = 1;
|
||||||
|
test_cntr++;
|
||||||
|
OpenOutFile(test_cntr);
|
||||||
|
|
||||||
|
// Register Opus mono as receiving codec.
|
||||||
|
opus_codec_param.channels = 1;
|
||||||
|
EXPECT_EQ(0, acm_receiver_->RegisterReceiveCodec(opus_codec_param));
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Close the files.
|
||||||
|
in_file_stereo_.Close();
|
||||||
|
in_file_mono_.Close();
|
||||||
|
out_file_.Close();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpusTest::Run(TestPackStereo* channel, int channels, int bitrate,
|
||||||
|
int frame_length, int percent_loss) {
|
||||||
|
AudioFrame audio_frame;
|
||||||
|
int32_t out_freq_hz_b = out_file_.SamplingFrequency();
|
||||||
|
int16_t audio[480 * 12 * 2]; // Can hold 120 ms stereo audio.
|
||||||
|
int written_samples = 0;
|
||||||
|
int read_samples = 0;
|
||||||
|
channel->reset_payload_size();
|
||||||
|
|
||||||
|
// Set encoder rate.
|
||||||
|
EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_mono_encoder_, bitrate));
|
||||||
|
EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_stereo_encoder_, bitrate));
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
// Simulate packet loss by setting |packet_loss_| to "true" in
|
||||||
|
// |percent_loss| percent of the loops.
|
||||||
|
// TODO(tlegrand): Move handling of loss simulation to TestPackStereo.
|
||||||
|
if (percent_loss > 0) {
|
||||||
|
if (counter_ == floor((100 / percent_loss) + 0.5)) {
|
||||||
|
counter_ = 0;
|
||||||
|
channel->set_lost_packet(true);
|
||||||
|
} else {
|
||||||
|
channel->set_lost_packet(false);
|
||||||
|
}
|
||||||
|
counter_++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input audio is sampled at 32 kHz, but Opus operates at 48 kHz.
|
||||||
|
// Resampling is required.
|
||||||
|
EXPECT_EQ(480, resampler_.Resample10Msec(audio_frame.data_, 32000,
|
||||||
|
&audio[written_samples], 48000,
|
||||||
|
channels));
|
||||||
|
written_samples += 480 * channels;
|
||||||
|
|
||||||
|
// Sometimes we need to loop over the audio vector to produce the right
|
||||||
|
// number of packets.
|
||||||
|
int loop_encode = (written_samples - read_samples) /
|
||||||
|
(channels * frame_length);
|
||||||
|
|
||||||
|
if (loop_encode > 0) {
|
||||||
|
const int kMaxBytes = 1000; // Maximum number of bytes for one packet.
|
||||||
|
int16_t bitstream_len_byte;
|
||||||
|
uint8_t bitstream[kMaxBytes];
|
||||||
|
for (int i = 0; i < loop_encode; i++) {
|
||||||
|
if (channels == 1) {
|
||||||
|
bitstream_len_byte = WebRtcOpus_Encode(
|
||||||
|
opus_mono_encoder_, &audio[read_samples],
|
||||||
|
frame_length, kMaxBytes, bitstream);
|
||||||
|
ASSERT_GT(bitstream_len_byte, -1);
|
||||||
|
} else {
|
||||||
|
bitstream_len_byte = WebRtcOpus_Encode(
|
||||||
|
opus_stereo_encoder_, &audio[read_samples],
|
||||||
|
frame_length, kMaxBytes, bitstream);
|
||||||
|
ASSERT_GT(bitstream_len_byte, -1);
|
||||||
|
}
|
||||||
|
channel->SendData(kAudioFrameSpeech, payload_type_, rtp_timestamp_,
|
||||||
|
bitstream, bitstream_len_byte, NULL);
|
||||||
|
rtp_timestamp_ += frame_length;
|
||||||
|
read_samples += frame_length * channels;
|
||||||
|
}
|
||||||
|
if (read_samples == written_samples) {
|
||||||
|
read_samples = 0;
|
||||||
|
written_samples = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run received side of ACM.
|
||||||
|
CHECK_ERROR(acm_receiver_->PlayoutData10Ms(out_freq_hz_b, &audio_frame));
|
||||||
|
|
||||||
|
// Write output speech to file.
|
||||||
|
out_file_.Write10MsData(
|
||||||
|
audio_frame.data_,
|
||||||
|
audio_frame.samples_per_channel_ * audio_frame.num_channels_);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
file_stream << webrtc::test::OutputPath() << "opustest_out_"
|
||||||
|
<< test_number << ".pcm";
|
||||||
|
file_name = file_stream.str();
|
||||||
|
out_file_.Open(file_name, 32000, "wb");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace webrtc
|
52
webrtc/modules/audio_coding/main/test/opus_test.h
Normal file
52
webrtc/modules/audio_coding/main/test/opus_test.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_OPUS_TEST_H_
|
||||||
|
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_OPUS_TEST_H_
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "webrtc/modules/audio_coding/main/source/acm_opus.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/source/acm_resampler.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/test/ACMTest.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/test/Channel.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/test/PCMFile.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/test/TestStereo.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
class OpusTest : public ACMTest {
|
||||||
|
public:
|
||||||
|
OpusTest();
|
||||||
|
~OpusTest();
|
||||||
|
|
||||||
|
void Perform();
|
||||||
|
private:
|
||||||
|
void Run(TestPackStereo* channel, int channels, int bitrate, int frame_length,
|
||||||
|
int percent_loss = 0);
|
||||||
|
|
||||||
|
void OpenOutFile(int test_number);
|
||||||
|
|
||||||
|
AudioCodingModule* acm_receiver_;
|
||||||
|
TestPackStereo* channel_a2b_;
|
||||||
|
PCMFile in_file_stereo_;
|
||||||
|
PCMFile in_file_mono_;
|
||||||
|
PCMFile out_file_;
|
||||||
|
int counter_;
|
||||||
|
uint8_t payload_type_;
|
||||||
|
int rtp_timestamp_;
|
||||||
|
ACMResampler resampler_;
|
||||||
|
WebRtcOpusEncInst* opus_mono_encoder_;
|
||||||
|
WebRtcOpusEncInst* opus_stereo_encoder_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_OPUS_TEST_H_
|
@ -14,9 +14,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "audio_coding_module.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
#include "common_types.h"
|
#include "webrtc/common_types.h"
|
||||||
#include "gtest/gtest.h"
|
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
|
||||||
|
#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
|
||||||
|
|
||||||
#define NUM_CODECS_WITH_FIXED_PAYLOAD_TYPE 13
|
#define NUM_CODECS_WITH_FIXED_PAYLOAD_TYPE 13
|
||||||
|
|
||||||
|
@ -8,11 +8,11 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ACM_TEST_UTILITY_H
|
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_
|
||||||
#define ACM_TEST_UTILITY_H
|
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_
|
||||||
|
|
||||||
#include "audio_coding_module.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
#include "gtest/gtest.h"
|
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
@ -55,17 +55,6 @@ namespace webrtc {
|
|||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
/* Exclude rarely-used stuff from Windows headers */
|
|
||||||
//#define WIN32_LEAN_AND_MEAN
|
|
||||||
/* OS-dependent case-insensitive string comparison */
|
|
||||||
#define STR_CASE_CMP(x,y) ::_stricmp(x,y)
|
|
||||||
#else
|
|
||||||
/* OS-dependent case-insensitive string comparison */
|
|
||||||
#define STR_CASE_CMP(x,y) ::strcasecmp(x,y)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define DESTROY_ACM(acm) \
|
#define DESTROY_ACM(acm) \
|
||||||
do { \
|
do { \
|
||||||
if(acm != NULL) { \
|
if(acm != NULL) { \
|
||||||
@ -192,4 +181,4 @@ private:
|
|||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // ACM_TEST_UTILITY_H
|
#endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_TEST_UTILITY_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user