From 46d90dcd740d0f63e52ece2dc1a1d27c56e222a1 Mon Sep 17 00:00:00 2001 From: "tina.legrand@webrtc.org" Date: Fri, 1 Feb 2013 14:20:06 +0000 Subject: [PATCH] Adding three frame sizes to Opus Adding support for 10, 40 and 60 ms packet sizes for Opus. BUG=issue1015 Review URL: https://webrtc-codereview.appspot.com/1086004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3454 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/opus/opus_interface.c | 4 +- .../main/source/acm_codec_database.cc | 2 +- .../main/source/acm_common_defs.h | 4 +- .../audio_coding/main/source/acm_opus.cc | 3 +- .../audio_coding/main/test/TestAllCodecs.cc | 14 ++--- .../audio_coding/main/test/TestStereo.cc | 61 ++++++++++++------- 6 files changed, 52 insertions(+), 36 deletions(-) diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c index 2203fbd4ca..145d7bbaa3 100644 --- a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c +++ b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c @@ -19,8 +19,8 @@ #include "common_audio/signal_processing/include/signal_processing_library.h" enum { - /* We always produce 20ms frames. */ - kWebRtcOpusMaxEncodeFrameSizeMs = 20, + /* Maximum supported frame size in WebRTC is 60 ms. */ + kWebRtcOpusMaxEncodeFrameSizeMs = 60, /* The format allows up to 120ms frames. Since we * don't control the other side, we must allow diff --git a/webrtc/modules/audio_coding/main/source/acm_codec_database.cc b/webrtc/modules/audio_coding/main/source/acm_codec_database.cc index 9fc66ab1c6..fa7688f93c 100644 --- a/webrtc/modules/audio_coding/main/source/acm_codec_database.cc +++ b/webrtc/modules/audio_coding/main/source/acm_codec_database.cc @@ -286,7 +286,7 @@ const ACMCodecDB::CodecSettings ACMCodecDB::codec_settings_[] = { // Opus supports frames shorter than 10ms, // but it doesn't help us to use them. // Mono and stereo. - {1, {960}, 0, 2}, + {4, {480, 960, 1920, 2880}, 0, 2}, #endif #ifdef WEBRTC_CODEC_SPEEX {3, {160, 320, 480}, 0, 1}, diff --git a/webrtc/modules/audio_coding/main/source/acm_common_defs.h b/webrtc/modules/audio_coding/main/source/acm_common_defs.h index ac3f9b755f..61fe2794af 100644 --- a/webrtc/modules/audio_coding/main/source/acm_common_defs.h +++ b/webrtc/modules/audio_coding/main/source/acm_common_defs.h @@ -36,8 +36,8 @@ namespace webrtc { // 60 ms is the maximum block size we support. An extra 20 ms is considered // for safety if process() method is not called when it should be, i.e. we -// accept 20 ms of jitter. 80 ms @ 32 kHz (super wide-band) is 2560 samples. -#define AUDIO_BUFFER_SIZE_W16 2560 +// accept 20 ms of jitter. 80 ms @ 48 kHz (full-band) stereo is 7680 samples. +#define AUDIO_BUFFER_SIZE_W16 7680 // There is one timestamp per each 10 ms of audio // the audio buffer, at max, may contain 32 blocks of 10ms diff --git a/webrtc/modules/audio_coding/main/source/acm_opus.cc b/webrtc/modules/audio_coding/main/source/acm_opus.cc index 83c56940dc..5648ee3291 100644 --- a/webrtc/modules/audio_coding/main/source/acm_opus.cc +++ b/webrtc/modules/audio_coding/main/source/acm_opus.cc @@ -108,7 +108,8 @@ ACMOpus::ACMOpus(int16_t codec_id) bitrate_(20000), // Default bit-rate. channels_(1) { // Default mono codec_id_ = codec_id; - // Opus has internal DTX, but we dont use it for now. + + // Opus has internal DTX, but we don't use it for now. has_internal_dtx_ = false; if (codec_id_ != ACMCodecDB::kOpus) { diff --git a/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc b/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc index d4d74c2159..5a590535a4 100644 --- a/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc +++ b/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc @@ -624,19 +624,19 @@ void TestAllCodecs::Perform() { test_count_++; OpenOutFile(test_count_); char codec_opus[] = "OPUS"; - RegisterSendCodec('A', codec_opus, 48000, 6000, 960, -1); + RegisterSendCodec('A', codec_opus, 48000, 6000, 480, -1); Run(channel_a_to_b_); - RegisterSendCodec('A', codec_opus, 48000, 20000, 960, -1); + RegisterSendCodec('A', codec_opus, 48000, 20000, 480*2, -1); Run(channel_a_to_b_); - RegisterSendCodec('A', codec_opus, 48000, 32000, 960, -1); + RegisterSendCodec('A', codec_opus, 48000, 32000, 480*4, -1); Run(channel_a_to_b_); - RegisterSendCodec('A', codec_opus, 48000, 48000, 960, -1); + RegisterSendCodec('A', codec_opus, 48000, 48000, 480, -1); Run(channel_a_to_b_); - RegisterSendCodec('A', codec_opus, 48000, 64000, 960, -1); + RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, -1); Run(channel_a_to_b_); - RegisterSendCodec('A', codec_opus, 48000, 96000, 960, -1); + RegisterSendCodec('A', codec_opus, 48000, 96000, 480*6, -1); Run(channel_a_to_b_); - RegisterSendCodec('A', codec_opus, 48000, 500000, 960, -1); + RegisterSendCodec('A', codec_opus, 48000, 500000, 480*2, -1); Run(channel_a_to_b_); outfile_b_.Close(); #endif diff --git a/webrtc/modules/audio_coding/main/test/TestStereo.cc b/webrtc/modules/audio_coding/main/test/TestStereo.cc index 3a4b652375..52508e2a24 100644 --- a/webrtc/modules/audio_coding/main/test/TestStereo.cc +++ b/webrtc/modules/audio_coding/main/test/TestStereo.cc @@ -230,7 +230,7 @@ void TestStereo::Perform() { EXPECT_EQ(0, acm_a_->VAD(dtx, vad, vad_mode)); EXPECT_FALSE(dtx); EXPECT_FALSE(vad); - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("\n"); } @@ -243,7 +243,7 @@ void TestStereo::Perform() { // All codecs are tested for all allowed sampling frequencies, rates and // packet sizes. #ifdef WEBRTC_CODEC_G722 - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===========================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-stereo\n"); @@ -273,7 +273,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef WEBRTC_CODEC_PCM16 - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===========================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-stereo\n"); @@ -296,7 +296,7 @@ void TestStereo::Perform() { Run(channel_a2b_, audio_channels, codec_channels); out_file_.Close(); - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===========================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-stereo\n"); @@ -317,7 +317,7 @@ void TestStereo::Perform() { Run(channel_a2b_, audio_channels, codec_channels); out_file_.Close(); - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===========================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-stereo\n"); @@ -412,7 +412,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef WEBRTC_CODEC_CELT - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===========================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-stereo\n"); @@ -435,7 +435,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef WEBRTC_CODEC_OPUS - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===========================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-stereo\n"); @@ -445,11 +445,26 @@ void TestStereo::Perform() { codec_channels = 2; test_cntr_++; OpenOutFile(test_cntr_); + char codec_opus[] = "opus"; - RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels, + // Run Opus with 10 ms frame size. + RegisterSendCodec('A', codec_opus, 48000, 64000, 480, codec_channels, opus_pltype_); Run(channel_a2b_, audio_channels, codec_channels); - RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels, + // Run Opus with 20 ms frame size. + RegisterSendCodec('A', codec_opus, 48000, 64000, 480*2, codec_channels, + opus_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + // Run Opus with 40 ms frame size. + RegisterSendCodec('A', codec_opus, 48000, 64000, 480*4, codec_channels, + opus_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + // Run Opus with 60 ms frame size. + RegisterSendCodec('A', codec_opus, 48000, 64000, 480*6, codec_channels, + opus_pltype_); + Run(channel_a2b_, audio_channels, codec_channels); + // Run Opus with 20 ms frame size and different bitrates. + RegisterSendCodec('A', codec_opus, 48000, 40000, 960, codec_channels, opus_pltype_); Run(channel_a2b_, audio_channels, codec_channels); RegisterSendCodec('A', codec_opus, 48000, 510000, 960, codec_channels, @@ -464,7 +479,7 @@ void TestStereo::Perform() { codec_channels = 2; #ifdef WEBRTC_CODEC_G722 - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); @@ -478,7 +493,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef WEBRTC_CODEC_PCM16 - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); @@ -490,7 +505,7 @@ void TestStereo::Perform() { l16_8khz_pltype_); Run(channel_a2b_, audio_channels, codec_channels); out_file_.Close(); - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); @@ -501,7 +516,7 @@ void TestStereo::Perform() { l16_16khz_pltype_); Run(channel_a2b_, audio_channels, codec_channels); out_file_.Close(); - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); @@ -514,7 +529,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef PCMA_AND_PCMU - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); @@ -531,7 +546,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef WEBRTC_CODEC_CELT - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); @@ -545,7 +560,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef WEBRTC_CODEC_OPUS - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Mono-to-stereo\n"); @@ -574,7 +589,7 @@ void TestStereo::Perform() { #ifdef WEBRTC_CODEC_G722 // Run stereo audio and mono codec. - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); @@ -596,7 +611,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef WEBRTC_CODEC_PCM16 - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); @@ -607,7 +622,7 @@ void TestStereo::Perform() { l16_8khz_pltype_); Run(channel_a2b_, audio_channels, codec_channels); out_file_.Close(); - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); @@ -618,7 +633,7 @@ void TestStereo::Perform() { l16_16khz_pltype_); Run(channel_a2b_, audio_channels, codec_channels); out_file_.Close(); - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("==============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); @@ -631,7 +646,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef PCMA_AND_PCMU - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); @@ -647,7 +662,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef WEBRTC_CODEC_CELT - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n"); @@ -660,7 +675,7 @@ void TestStereo::Perform() { out_file_.Close(); #endif #ifdef WEBRTC_CODEC_OPUS - if(test_mode_ != 0) { + if (test_mode_ != 0) { printf("===============================================================\n"); printf("Test number: %d\n",test_cntr_ + 1); printf("Test type: Stereo-to-mono\n");