| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "webrtc/modules/audio_coding/test/utility.h" | 22 #include "webrtc/modules/audio_coding/test/utility.h" |
| 23 #include "webrtc/system_wrappers/include/trace.h" | 23 #include "webrtc/system_wrappers/include/trace.h" |
| 24 #include "webrtc/test/gtest.h" | 24 #include "webrtc/test/gtest.h" |
| 25 #include "webrtc/test/testsupport/fileutils.h" | 25 #include "webrtc/test/testsupport/fileutils.h" |
| 26 #include "webrtc/typedefs.h" | 26 #include "webrtc/typedefs.h" |
| 27 | 27 |
| 28 namespace webrtc { | 28 namespace webrtc { |
| 29 | 29 |
| 30 OpusTest::OpusTest() | 30 OpusTest::OpusTest() |
| 31 : acm_receiver_(AudioCodingModule::Create(0)), | 31 : acm_receiver_(AudioCodingModule::Create(0)), |
| 32 channel_a2b_(NULL), | 32 channel_a2b_(nullptr), |
| 33 counter_(0), | 33 counter_(0), |
| 34 payload_type_(255), | 34 payload_type_(255), |
| 35 rtp_timestamp_(0) {} | 35 rtp_timestamp_(0) {} |
| 36 | 36 |
| 37 OpusTest::~OpusTest() { | 37 OpusTest::~OpusTest() { |
| 38 if (channel_a2b_ != NULL) { | 38 if (channel_a2b_ != nullptr) { |
| 39 delete channel_a2b_; | 39 delete channel_a2b_; |
| 40 channel_a2b_ = NULL; | 40 channel_a2b_ = nullptr; |
| 41 } | 41 } |
| 42 if (opus_mono_encoder_ != NULL) { | 42 if (opus_mono_encoder_ != nullptr) { |
| 43 WebRtcOpus_EncoderFree(opus_mono_encoder_); | 43 WebRtcOpus_EncoderFree(opus_mono_encoder_); |
| 44 opus_mono_encoder_ = NULL; | 44 opus_mono_encoder_ = nullptr; |
| 45 } | 45 } |
| 46 if (opus_stereo_encoder_ != NULL) { | 46 if (opus_stereo_encoder_ != nullptr) { |
| 47 WebRtcOpus_EncoderFree(opus_stereo_encoder_); | 47 WebRtcOpus_EncoderFree(opus_stereo_encoder_); |
| 48 opus_stereo_encoder_ = NULL; | 48 opus_stereo_encoder_ = nullptr; |
| 49 } | 49 } |
| 50 if (opus_mono_decoder_ != NULL) { | 50 if (opus_mono_decoder_ != nullptr) { |
| 51 WebRtcOpus_DecoderFree(opus_mono_decoder_); | 51 WebRtcOpus_DecoderFree(opus_mono_decoder_); |
| 52 opus_mono_decoder_ = NULL; | 52 opus_mono_decoder_ = nullptr; |
| 53 } | 53 } |
| 54 if (opus_stereo_decoder_ != NULL) { | 54 if (opus_stereo_decoder_ != nullptr) { |
| 55 WebRtcOpus_DecoderFree(opus_stereo_decoder_); | 55 WebRtcOpus_DecoderFree(opus_stereo_decoder_); |
| 56 opus_stereo_decoder_ = NULL; | 56 opus_stereo_decoder_ = nullptr; |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 void OpusTest::Perform() { | 60 void OpusTest::Perform() { |
| 61 #ifndef WEBRTC_CODEC_OPUS | 61 #ifndef WEBRTC_CODEC_OPUS |
| 62 // Opus isn't defined, exit. | 62 // Opus isn't defined, exit. |
| 63 return; | 63 return; |
| 64 #else | 64 #else |
| 65 uint16_t frequency_hz; | 65 uint16_t frequency_hz; |
| 66 size_t audio_channels; | 66 size_t audio_channels; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 80 // Create Opus encoders for mono and stereo. | 80 // Create Opus encoders for mono and stereo. |
| 81 ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_mono_encoder_, 1, 0), -1); | 81 ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_mono_encoder_, 1, 0), -1); |
| 82 ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_stereo_encoder_, 2, 1), -1); | 82 ASSERT_GT(WebRtcOpus_EncoderCreate(&opus_stereo_encoder_, 2, 1), -1); |
| 83 | 83 |
| 84 // Create Opus decoders for mono and stereo for stand-alone testing of Opus. | 84 // Create Opus decoders for mono and stereo for stand-alone testing of Opus. |
| 85 ASSERT_GT(WebRtcOpus_DecoderCreate(&opus_mono_decoder_, 1), -1); | 85 ASSERT_GT(WebRtcOpus_DecoderCreate(&opus_mono_decoder_, 1), -1); |
| 86 ASSERT_GT(WebRtcOpus_DecoderCreate(&opus_stereo_decoder_, 2), -1); | 86 ASSERT_GT(WebRtcOpus_DecoderCreate(&opus_stereo_decoder_, 2), -1); |
| 87 WebRtcOpus_DecoderInit(opus_mono_decoder_); | 87 WebRtcOpus_DecoderInit(opus_mono_decoder_); |
| 88 WebRtcOpus_DecoderInit(opus_stereo_decoder_); | 88 WebRtcOpus_DecoderInit(opus_stereo_decoder_); |
| 89 | 89 |
| 90 ASSERT_TRUE(acm_receiver_.get() != NULL); | 90 ASSERT_TRUE(acm_receiver_.get() != nullptr); |
| 91 EXPECT_EQ(0, acm_receiver_->InitializeReceiver()); | 91 EXPECT_EQ(0, acm_receiver_->InitializeReceiver()); |
| 92 | 92 |
| 93 // Register Opus stereo as receiving codec. | 93 // Register Opus stereo as receiving codec. |
| 94 CodecInst opus_codec_param; | 94 CodecInst opus_codec_param; |
| 95 int codec_id = acm_receiver_->Codec("opus", 48000, 2); | 95 int codec_id = acm_receiver_->Codec("opus", 48000, 2); |
| 96 EXPECT_EQ(0, acm_receiver_->Codec(codec_id, &opus_codec_param)); | 96 EXPECT_EQ(0, acm_receiver_->Codec(codec_id, &opus_codec_param)); |
| 97 payload_type_ = opus_codec_param.pltype; | 97 payload_type_ = opus_codec_param.pltype; |
| 98 EXPECT_EQ(true, | 98 EXPECT_EQ(true, |
| 99 acm_receiver_->RegisterReceiveCodec( | 99 acm_receiver_->RegisterReceiveCodec( |
| 100 opus_codec_param.pltype, CodecInstToSdp(opus_codec_param))); | 100 opus_codec_param.pltype, CodecInstToSdp(opus_codec_param))); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 &out_audio[decoded_samples * channels], &audio_type); | 319 &out_audio[decoded_samples * channels], &audio_type); |
| 320 } else { | 320 } else { |
| 321 decoded_samples += WebRtcOpus_DecodePlc( | 321 decoded_samples += WebRtcOpus_DecodePlc( |
| 322 opus_stereo_decoder_, &out_audio[decoded_samples * channels], | 322 opus_stereo_decoder_, &out_audio[decoded_samples * channels], |
| 323 1); | 323 1); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 // Send data to the channel. "channel" will handle the loss simulation. | 327 // Send data to the channel. "channel" will handle the loss simulation. |
| 328 channel->SendData(kAudioFrameSpeech, payload_type_, rtp_timestamp_, | 328 channel->SendData(kAudioFrameSpeech, payload_type_, rtp_timestamp_, |
| 329 bitstream, bitstream_len_byte, NULL); | 329 bitstream, bitstream_len_byte, nullptr); |
| 330 if (first_packet) { | 330 if (first_packet) { |
| 331 first_packet = false; | 331 first_packet = false; |
| 332 start_time_stamp = rtp_timestamp_; | 332 start_time_stamp = rtp_timestamp_; |
| 333 } | 333 } |
| 334 rtp_timestamp_ += static_cast<uint32_t>(frame_length); | 334 rtp_timestamp_ += static_cast<uint32_t>(frame_length); |
| 335 read_samples += frame_length * channels; | 335 read_samples += frame_length * channels; |
| 336 } | 336 } |
| 337 if (read_samples == written_samples) { | 337 if (read_samples == written_samples) { |
| 338 read_samples = 0; | 338 read_samples = 0; |
| 339 written_samples = 0; | 339 written_samples = 0; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 out_file_.Open(file_name, 48000, "wb"); | 382 out_file_.Open(file_name, 48000, "wb"); |
| 383 file_stream.str(""); | 383 file_stream.str(""); |
| 384 file_name = file_stream.str(); | 384 file_name = file_stream.str(); |
| 385 file_stream << webrtc::test::OutputPath() << "opusstandalone_out_" | 385 file_stream << webrtc::test::OutputPath() << "opusstandalone_out_" |
| 386 << test_number << ".pcm"; | 386 << test_number << ".pcm"; |
| 387 file_name = file_stream.str(); | 387 file_name = file_stream.str(); |
| 388 out_file_standalone_.Open(file_name, 48000, "wb"); | 388 out_file_standalone_.Open(file_name, 48000, "wb"); |
| 389 } | 389 } |
| 390 | 390 |
| 391 } // namespace webrtc | 391 } // namespace webrtc |
| OLD | NEW |