Opus mono/stereo on the same payloadtype, and fix of memory bug
During call setup Opus should always be signaled as a 48000 Hz stereo codec, not depending on what we plan to send, or how we plan to decode received packets.
The previous implementation had different payload types for mono and stereo, which breaks the proposed standard.
While working on this CL I ran in to the problem reported earlier, that we could get a crash related to deleting decoder memory. This should now be solved in Patch Set 3.
BUG=issue1013, issue1112
Review URL: https://webrtc-codereview.appspot.com/933022
git-svn-id: http://webrtc.googlecode.com/svn/trunk@3177 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc b/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc
index 89a9829..d4d74c2 100644
--- a/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc
+++ b/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc
@@ -147,6 +147,9 @@
CodecInst my_codec_param;
for (uint8_t n = 0; n < num_encoders; n++) {
acm_b_->Codec(n, my_codec_param);
+ if (!strcmp(my_codec_param.plname, "opus")) {
+ my_codec_param.channels = 1;
+ }
acm_b_->RegisterReceiveCodec(my_codec_param);
}
@@ -635,6 +638,7 @@
Run(channel_a_to_b_);
RegisterSendCodec('A', codec_opus, 48000, 500000, 960, -1);
Run(channel_a_to_b_);
+ outfile_b_.Close();
#endif
if (test_mode_ != 0) {
printf("===============================================================\n");
diff --git a/webrtc/modules/audio_coding/main/test/TestStereo.cc b/webrtc/modules/audio_coding/main/test/TestStereo.cc
index 97d6c2e..3a4b652 100644
--- a/webrtc/modules/audio_coding/main/test/TestStereo.cc
+++ b/webrtc/modules/audio_coding/main/test/TestStereo.cc
@@ -550,12 +550,18 @@
printf("Test number: %d\n",test_cntr_ + 1);
printf("Test type: Mono-to-stereo\n");
}
+
+ // Keep encode and decode in stereo.
test_cntr_++;
channel_a2b_->set_codec_mode(kStereo);
OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_opus, 48000, 64000, 960, codec_channels,
opus_pltype_);
Run(channel_a2b_, audio_channels, codec_channels);
+
+ // Encode in mono, decode in stereo mode.
+ RegisterSendCodec('A', codec_opus, 48000, 64000, 960, 1, opus_pltype_);
+ Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
#endif
@@ -661,10 +667,63 @@
}
test_cntr_++;
OpenOutFile(test_cntr_);
+ // Encode and decode in mono.
RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels,
opus_pltype_);
+ CodecInst opus_codec_param;
+ for (WebRtc_UWord8 n = 0; n < num_encoders; n++) {
+ EXPECT_EQ(0, acm_b_->Codec(n, opus_codec_param));
+ if (!strcmp(opus_codec_param.plname, "opus")) {
+ opus_codec_param.channels = 1;
+ EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
+ break;
+ }
+ }
+ Run(channel_a2b_, audio_channels, codec_channels);
+
+ // Encode in stereo, decode in mono.
+ RegisterSendCodec('A', codec_opus, 48000, 32000, 960, 2, opus_pltype_);
+ Run(channel_a2b_, audio_channels, codec_channels);
+
+ out_file_.Close();
+
+ // Test switching between decoding mono and stereo for Opus.
+
+ // Decode in mono.
+ test_cntr_++;
+ OpenOutFile(test_cntr_);
+ if (test_mode_ != 0) {
+ // Print out codec and settings
+ printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
+ " Decode: mono\n", test_cntr_);
+ }
Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close();
+ // Decode in stereo.
+ test_cntr_++;
+ OpenOutFile(test_cntr_);
+ if (test_mode_ != 0) {
+ // Print out codec and settings
+ printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
+ " Decode: stereo\n", test_cntr_);
+ }
+ opus_codec_param.channels = 2;
+ EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
+ Run(channel_a2b_, audio_channels, 2);
+ out_file_.Close();
+ // Decode in mono.
+ test_cntr_++;
+ OpenOutFile(test_cntr_);
+ if (test_mode_ != 0) {
+ // Print out codec and settings
+ printf("Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
+ " Decode: mono\n", test_cntr_);
+ }
+ opus_codec_param.channels = 1;
+ EXPECT_EQ(0, acm_b_->RegisterReceiveCodec(opus_codec_param));
+ Run(channel_a2b_, audio_channels, codec_channels);
+ out_file_.Close();
+
#endif
// Print out which codecs were tested, and which were not, in the run.
@@ -680,6 +739,9 @@
#ifdef WEBRTC_CODEC_CELT
printf(" CELT\n");
#endif
+#ifdef WEBRTC_CODEC_OPUS
+ printf(" Opus\n");
+#endif
printf("\nTo complete the test, listen to the %d number of output "
"files.\n",
test_cntr_);
diff --git a/webrtc/modules/audio_coding/main/test/TestVADDTX.cc b/webrtc/modules/audio_coding/main/test/TestVADDTX.cc
index fcca374..567903b 100644
--- a/webrtc/modules/audio_coding/main/test/TestVADDTX.cc
+++ b/webrtc/modules/audio_coding/main/test/TestVADDTX.cc
@@ -83,6 +83,10 @@
{
printf("%s\n", myCodecParam.plname);
}
+ if (!strcmp(myCodecParam.plname, "opus")) {
+ // Use mono decoding for Opus in the VAD/DTX test.
+ myCodecParam.channels = 1;
+ }
_acmB->RegisterReceiveCodec(myCodecParam);
}
@@ -337,6 +341,8 @@
}
}
+ // We only allow VAD/DTX when sending mono.
+ myCodecParam.channels = 1;
CHECK_ERROR(myACM->RegisterSendCodec(myCodecParam));
// initialization was succesful