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
diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c
index 2203fbd..145d7bb 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 9fc66ab..fa7688f 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 @@
// 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 ac3f9b7..61fe279 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 @@
// 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 83c5694..5648ee3 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 @@
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 d4d74c2..5a59053 100644
--- a/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc
+++ b/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc
@@ -624,19 +624,19 @@
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 3a4b652..52508e2 100644
--- a/webrtc/modules/audio_coding/main/test/TestStereo.cc
+++ b/webrtc/modules/audio_coding/main/test/TestStereo.cc
@@ -230,7 +230,7 @@
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 @@
// 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
#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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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");