diff options
author | Chih-hung Hsieh <chh@google.com> | 2016-01-20 17:50:13 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-01-20 17:50:13 +0000 |
commit | b3cb8ab4ede8bb77f0bdef2715efc2c1e6267072 (patch) | |
tree | 28c4cf735dd5bd9cc8f1ccd06fff8a173b20d1cb /webrtc/modules/audio_coding/main/test/opus_test.cc | |
parent | a4acd9d6bc9b3b033d7d274316e75ee067df8d20 (diff) | |
parent | 9a337512d97e37afc142dee4fd50a41b741a87d2 (diff) | |
download | webrtc-b3cb8ab4ede8bb77f0bdef2715efc2c1e6267072.tar.gz |
Merge "Merge upstream SHA 04cb763"android-cts_7.1_r1android-cts-7.1_r9android-cts-7.1_r8android-cts-7.1_r7android-cts-7.1_r6android-cts-7.1_r5android-cts-7.1_r4android-cts-7.1_r3android-cts-7.1_r29android-cts-7.1_r28android-cts-7.1_r27android-cts-7.1_r26android-cts-7.1_r25android-cts-7.1_r24android-cts-7.1_r23android-cts-7.1_r22android-cts-7.1_r21android-cts-7.1_r20android-cts-7.1_r2android-cts-7.1_r19android-cts-7.1_r18android-cts-7.1_r17android-cts-7.1_r16android-cts-7.1_r15android-cts-7.1_r14android-cts-7.1_r13android-cts-7.1_r12android-cts-7.1_r11android-cts-7.1_r10android-cts-7.1_r1android-cts-7.0_r9android-cts-7.0_r8android-cts-7.0_r7android-cts-7.0_r6android-cts-7.0_r5android-cts-7.0_r4android-cts-7.0_r33android-cts-7.0_r32android-cts-7.0_r31android-cts-7.0_r30android-cts-7.0_r3android-cts-7.0_r29android-cts-7.0_r28android-cts-7.0_r27android-cts-7.0_r26android-cts-7.0_r25android-cts-7.0_r24android-cts-7.0_r23android-cts-7.0_r22android-cts-7.0_r21android-cts-7.0_r20android-cts-7.0_r2android-cts-7.0_r19android-cts-7.0_r18android-cts-7.0_r17android-cts-7.0_r16android-cts-7.0_r15android-cts-7.0_r14android-cts-7.0_r13android-cts-7.0_r12android-cts-7.0_r11android-cts-7.0_r10android-cts-7.0_r1android-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1android-7.1.1_r9android-7.1.1_r8android-7.1.1_r7android-7.1.1_r61android-7.1.1_r60android-7.1.1_r6android-7.1.1_r59android-7.1.1_r58android-7.1.1_r57android-7.1.1_r56android-7.1.1_r55android-7.1.1_r54android-7.1.1_r53android-7.1.1_r52android-7.1.1_r51android-7.1.1_r50android-7.1.1_r49android-7.1.1_r48android-7.1.1_r47android-7.1.1_r46android-7.1.1_r45android-7.1.1_r44android-7.1.1_r43android-7.1.1_r42android-7.1.1_r41android-7.1.1_r40android-7.1.1_r4android-7.1.1_r39android-7.1.1_r38android-7.1.1_r35android-7.1.1_r33android-7.1.1_r32android-7.1.1_r31android-7.1.1_r3android-7.1.1_r28android-7.1.1_r27android-7.1.1_r26android-7.1.1_r25android-7.1.1_r24android-7.1.1_r23android-7.1.1_r22android-7.1.1_r21android-7.1.1_r20android-7.1.1_r2android-7.1.1_r17android-7.1.1_r16android-7.1.1_r15android-7.1.1_r14android-7.1.1_r13android-7.1.1_r12android-7.1.1_r11android-7.1.1_r10android-7.1.1_r1android-7.1.0_r7android-7.1.0_r6android-7.1.0_r5android-7.1.0_r4android-7.1.0_r3android-7.1.0_r2android-7.1.0_r1android-7.0.0_r9android-7.0.0_r8android-7.0.0_r7android-7.0.0_r6android-7.0.0_r5android-7.0.0_r4android-7.0.0_r36android-7.0.0_r35android-7.0.0_r34android-7.0.0_r33android-7.0.0_r32android-7.0.0_r31android-7.0.0_r30android-7.0.0_r3android-7.0.0_r29android-7.0.0_r28android-7.0.0_r27android-7.0.0_r24android-7.0.0_r21android-7.0.0_r19android-7.0.0_r17android-7.0.0_r15android-7.0.0_r14android-7.0.0_r13android-7.0.0_r12android-7.0.0_r11android-7.0.0_r10android-7.0.0_r1nougat-releasenougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-devnougat-mr1.8-releasenougat-mr1.7-releasenougat-mr1.6-releasenougat-mr1.5-releasenougat-mr1.4-releasenougat-mr1.3-releasenougat-mr1.2-releasenougat-mr1.1-releasenougat-mr1-volantis-releasenougat-mr1-security-releasenougat-mr1-releasenougat-mr1-flounder-releasenougat-mr1-devnougat-mr1-cts-releasenougat-mr0.5-releasenougat-dr1-releasenougat-devnougat-cts-releasenougat-bugfix-release
am: 9a337512d9
* commit '9a337512d97e37afc142dee4fd50a41b741a87d2': (797 commits)
Add tests for verifying transport feedback for audio and video.
Eliminate defines in talk/
Revert of Update with new default boringssl no-aes cipher suites. Re-enable tests. (patchset #3 id:40001 of https://codereview.webrtc.org/1550773002/ )
Remove assert which was incorrectly added to TcpPort::OnSentPacket.
Reland Connect TurnPort and TCPPort to AsyncPacketSocket::SignalSentPacket.
Update with new default boringssl no-aes cipher suites. Re-enable tests.
Revert of Connect TurnPort and TCPPort to AsyncPacketSocket::SignalSentPacket. (patchset #3 id:40001 of https://codereview.webrtc.org/1577873003/ )
Re-land: "Use an explicit identifier in Config"
Connect TurnPort and TCPPort to AsyncPacketSocket::SignalSentPacket.
Revert of Delete remnants of non-square pixel support from cricket::VideoFrame. (patchset #1 id:1 of https://codereview.webrtc.org/1586613002/ )
Remove libfuzzer trybot from default trybot set.
Add ramp-up tests for transport sequence number with and w/o audio.
Delete remnants of non-square pixel support from cricket::VideoFrame.
Fix IPAddress::ToSensitiveString() to avoid dependency on inet_ntop().
Revert of Storing raw audio sink for default audio track. (patchset #7 id:120001 of https://codereview.chromium.org/1551813002/ )
Re-enable tests that failed under Linux_Msan.
Revert of Use an explicit identifier in Config (patchset #4 id:60001 of https://codereview.webrtc.org/1538643004/ )
Roll chromium_revision 346fea9..099be58 (369082:369139)
Disable WebRtcVideoChannel2BaseTest.SendManyResizeOnce for TSan
Add build_protobuf variable.
...
Diffstat (limited to 'webrtc/modules/audio_coding/main/test/opus_test.cc')
-rw-r--r-- | webrtc/modules/audio_coding/main/test/opus_test.cc | 381 |
1 files changed, 0 insertions, 381 deletions
diff --git a/webrtc/modules/audio_coding/main/test/opus_test.cc b/webrtc/modules/audio_coding/main/test/opus_test.cc deleted file mode 100644 index 00c66cb3aa..0000000000 --- a/webrtc/modules/audio_coding/main/test/opus_test.cc +++ /dev/null @@ -1,381 +0,0 @@ -/* - * 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 <assert.h> - -#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/include/opus_interface.h" -#include "webrtc/modules/audio_coding/main/include/audio_coding_module_typedefs.h" -#include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" -#include "webrtc/modules/audio_coding/main/test/TestStereo.h" -#include "webrtc/modules/audio_coding/main/test/utility.h" -#include "webrtc/system_wrappers/include/trace.h" -#include "webrtc/test/testsupport/fileutils.h" - -namespace webrtc { - -OpusTest::OpusTest() - : acm_receiver_(AudioCodingModule::Create(0)), - channel_a2b_(NULL), - counter_(0), - payload_type_(255), - rtp_timestamp_(0) {} - -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; - } - 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; - } -} - -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, 0), -1); - ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_stereo_encoder_, 2, 1), -1); - - // Create Opus decoders for mono and stereo for stand-alone testing of Opus. - ASSERT_GT(WebRtcOpus_DecoderCreate(&opus_mono_decoder_, 1), -1); - ASSERT_GT(WebRtcOpus_DecoderCreate(&opus_stereo_decoder_, 2), -1); - WebRtcOpus_DecoderInit(opus_mono_decoder_); - WebRtcOpus_DecoderInit(opus_stereo_decoder_); - - ASSERT_TRUE(acm_receiver_.get() != 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_.get()); - - // - // 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(); - 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(); - - // - // 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); - - 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); - - // Close the files. - in_file_stereo_.Close(); - in_file_mono_.Close(); - out_file_.Close(); - out_file_standalone_.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(); - const int kBufferSizeSamples = 480 * 12 * 2; // Can hold 120 ms stereo audio. - int16_t audio[kBufferSizeSamples]; - int16_t out_audio[kBufferSizeSamples]; - int16_t audio_type; - int written_samples = 0; - int read_samples = 0; - int decoded_samples = 0; - bool first_packet = true; - uint32_t start_time_stamp = 0; - - channel->reset_payload_size(); - counter_ = 0; - - // Set encoder rate. - EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_mono_encoder_, bitrate)); - EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_stereo_encoder_, bitrate)); - -#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)); - EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_stereo_encoder_, - kOpusComplexity5)); -#endif - - // Make sure the runtime is less than 60 seconds to pass Android test. - for (size_t audio_length = 0; audio_length < 10000; audio_length += 10) { - bool lost_packet = false; - - // 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); - } - - // If input audio is sampled at 32 kHz, resampling to 48 kHz is required. - EXPECT_EQ(480, - resampler_.Resample10Msec(audio_frame.data_, - audio_frame.sample_rate_hz_, - 48000, - channels, - kBufferSizeSamples - written_samples, - &audio[written_samples])); - 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. - size_t bitstream_len_byte; - uint8_t bitstream[kMaxBytes]; - for (int i = 0; i < loop_encode; i++) { - 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); - bitstream_len_byte = static_cast<size_t>(bitstream_len_byte_int); - - // 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; - 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) { - decoded_samples += WebRtcOpus_Decode( - opus_mono_decoder_, bitstream, bitstream_len_byte, - &out_audio[decoded_samples * channels], &audio_type); - } else { - decoded_samples += WebRtcOpus_DecodePlc( - opus_mono_decoder_, &out_audio[decoded_samples * channels], 1); - } - } else { - if (!lost_packet) { - decoded_samples += WebRtcOpus_Decode( - opus_stereo_decoder_, bitstream, bitstream_len_byte, - &out_audio[decoded_samples * channels], &audio_type); - } else { - decoded_samples += WebRtcOpus_DecodePlc( - opus_stereo_decoder_, &out_audio[decoded_samples * channels], - 1); - } - } - - // Send data to the channel. "channel" will handle the loss simulation. - channel->SendData(kAudioFrameSpeech, payload_type_, rtp_timestamp_, - bitstream, bitstream_len_byte, NULL); - if (first_packet) { - first_packet = false; - start_time_stamp = rtp_timestamp_; - } - 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. - ASSERT_EQ(0, 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_); - - // Write stand-alone speech to file. - out_file_standalone_.Write10MsData( - out_audio, static_cast<size_t>(decoded_samples) * channels); - - 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); - } - - decoded_samples = 0; - } - - 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, 48000, "wb"); - file_stream.str(""); - file_name = file_stream.str(); - file_stream << webrtc::test::OutputPath() << "opusstandalone_out_" - << test_number << ".pcm"; - file_name = file_stream.str(); - out_file_standalone_.Open(file_name, 48000, "wb"); -} - -} // namespace webrtc |