From 65d61c39248f8c79a1ef28def88fe1f7b06e6a8c Mon Sep 17 00:00:00 2001 From: "tina.legrand@webrtc.org" Date: Thu, 5 Jun 2014 13:42:51 +0000 Subject: [PATCH] Opus send rate overflows if over 65 kbps The member holding the send rate for Opus had too low resolution for rates above ~65 kbps. I've added a test that checks if the average rate in a Opus test is in the right range. The test fails before my fix, and now passes. BUG=3267 R=henrik.lundin@webrtc.org, kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/12579004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6344 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../modules/audio_coding/main/acm2/acm_opus.h | 2 +- .../audio_coding/main/test/TestStereo.cc | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/webrtc/modules/audio_coding/main/acm2/acm_opus.h b/webrtc/modules/audio_coding/main/acm2/acm_opus.h index 7963ee9bb..07ce07216 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_opus.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_opus.h @@ -47,7 +47,7 @@ class ACMOpus : public ACMGenericCodec { WebRtcOpusEncInst* encoder_inst_ptr_; uint16_t sample_freq_; - uint16_t bitrate_; + int32_t bitrate_; int channels_; bool fec_enabled_; diff --git a/webrtc/modules/audio_coding/main/test/TestStereo.cc b/webrtc/modules/audio_coding/main/test/TestStereo.cc index f05896773..00c3631f4 100644 --- a/webrtc/modules/audio_coding/main/test/TestStereo.cc +++ b/webrtc/modules/audio_coding/main/test/TestStereo.cc @@ -807,6 +807,8 @@ void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels, uint32_t time_stamp_diff; channel->reset_payload_size(); int error_count = 0; + int variable_bytes = 0; + int variable_packets = 0; while (1) { // Simulate packet loss by setting |packet_loss_| to "true" in @@ -838,11 +840,16 @@ void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels, // Run sender side of ACM EXPECT_GT(acm_a_->Process(), -1); - // Verify that the received packet size matches the settings + // Verify that the received packet size matches the settings. rec_size = channel->payload_size(); if ((0 < rec_size) & (rec_size < 65535)) { - // Opus is variable rate, skip this test. - if (strcmp(send_codec_name_, "opus")) { + if (strcmp(send_codec_name_, "opus") == 0) { + // Opus is a variable rate codec, hence calculate the average packet + // size, and later make sure the average is in the right range. + variable_bytes += rec_size; + variable_packets++; + } else { + // For fixed rate codecs, check that packet size is correct. if ((rec_size != pack_size_bytes_ * out_channels) && (pack_size_bytes_ < 65535)) { error_count++; @@ -866,6 +873,13 @@ void TestStereo::Run(TestPackStereo* channel, int in_channels, int out_channels, EXPECT_EQ(0, error_count); + // Check that packet size is in the right range for variable rate codecs, + // such as Opus. + if (variable_packets > 0) { + variable_bytes /= variable_packets; + EXPECT_NEAR(variable_bytes, pack_size_bytes_, 3); + } + if (in_file_mono_->EndOfFile()) { in_file_mono_->Rewind(); }