From 92c0e2996361afc9922a2b84538f082f2c26354f Mon Sep 17 00:00:00 2001 From: "tina.legrand@webrtc.org" Date: Mon, 24 Mar 2014 14:38:36 +0000 Subject: [PATCH] Run Opus with lower complexity setting on Android, iOS and/or ARM This CL includes a call to Opus to set a lower complexity figure, if we are compiling for Android, iOS, or ARM (e.g. ChromeOS on ARM), where we know the devices are not powerful enough to run on higher complexity setting. BUG=3093 R=minyue@webrtc.org Review URL: https://webrtc-codereview.appspot.com/10489004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5760 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/audio_coding/main/acm2/acm_opus.cc | 14 ++++++++++++++ webrtc/modules/audio_coding/main/test/opus_test.cc | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/webrtc/modules/audio_coding/main/acm2/acm_opus.cc b/webrtc/modules/audio_coding/main/acm2/acm_opus.cc index c00a9203a9..5830f6b40d 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_opus.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_opus.cc @@ -140,6 +140,20 @@ int16_t ACMOpus::InternalInitEncoder(WebRtcACMCodecParams* codec_params) { // Store bitrate. bitrate_ = codec_params->codec_inst.rate; + // TODO(tlegrand): Remove this code when we have proper APIs to set the + // complexity at a higher level. +#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) + // If we are on Android, iOS and/or ARM, use a lower complexity setting as + // default, to save encoder complexity. + const int kOpusComplexity5 = 5; + WebRtcOpus_SetComplexity(encoder_inst_ptr_, kOpusComplexity5); + if (ret < 0) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, unique_id_, + "Setting complexity failed for Opus"); + return ret; + } +#endif + return 0; } diff --git a/webrtc/modules/audio_coding/main/test/opus_test.cc b/webrtc/modules/audio_coding/main/test/opus_test.cc index 5eec83b7f5..027aeb045c 100644 --- a/webrtc/modules/audio_coding/main/test/opus_test.cc +++ b/webrtc/modules/audio_coding/main/test/opus_test.cc @@ -227,6 +227,15 @@ void OpusTest::Run(TestPackStereo* channel, int channels, int bitrate, EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_mono_encoder_, bitrate)); EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_stereo_encoder_, bitrate)); +#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) + // If we are on Android, iOS and/or ARM, use a lower complexity setting as + // default. + const int kOpusComplexity5 = 5; + EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_mono_encoder_, kOpusComplexity5)); + EXPECT_EQ(0, WebRtcOpus_SetComplexity(opus_stereo_encoder_, + kOpusComplexity5)); +#endif + // Make sure the runtime is less than 60 seconds to pass Android test. for (size_t audio_length = 0; audio_length < 10000; audio_length += 10) { bool lost_packet = false;