From 2e03c6611927af6ed08cf967b95342744ff329b6 Mon Sep 17 00:00:00 2001 From: minyue Date: Wed, 1 Feb 2017 17:31:11 -0800 Subject: [PATCH] Adding build switch for Opus that supports 120ms ptime. BUG=webrtc:7097 TEST=Set "ptime=120", try WebRTC calls over custom build Chromium with and without Opus 120ms. Try both Chromium w <-> Chromium w and Chromium w <-> Chromium w/o Review-Url: https://codereview.webrtc.org/2668633004 Cr-Commit-Position: refs/heads/master@{#16408} --- webrtc/media/BUILD.gn | 6 ++++++ webrtc/media/engine/webrtcvoiceengine.cc | 5 +++++ webrtc/modules/audio_coding/BUILD.gn | 2 ++ webrtc/modules/audio_coding/acm2/acm_codec_database.cc | 4 ++++ webrtc/modules/audio_coding/audio_coding.gni | 5 +++++ webrtc/modules/audio_coding/codecs/opus/opus_interface.c | 5 +++++ webrtc/webrtc.gni | 4 ++++ 7 files changed, 31 insertions(+) diff --git a/webrtc/media/BUILD.gn b/webrtc/media/BUILD.gn index 06aed45662..c223068c20 100644 --- a/webrtc/media/BUILD.gn +++ b/webrtc/media/BUILD.gn @@ -161,6 +161,12 @@ rtc_static_library("rtc_media") { defines += [ "WEBRTC_INTELLIGIBILITY_ENHANCER=0" ] } + if (rtc_opus_support_120ms_ptime) { + defines += [ "WEBRTC_OPUS_SUPPORT_120MS_PTIME=1" ] + } else { + defines += [ "WEBRTC_OPUS_SUPPORT_120MS_PTIME=0" ] + } + include_dirs = [] if (rtc_build_libyuv) { deps += [ "$rtc_libyuv_dir" ] diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc index b9a725b0a0..1ed1e8b993 100644 --- a/webrtc/media/engine/webrtcvoiceengine.cc +++ b/webrtc/media/engine/webrtcvoiceengine.cc @@ -498,7 +498,12 @@ class WebRtcVoiceCodecs final { }; const WebRtcVoiceCodecs::CodecPref WebRtcVoiceCodecs::kCodecPrefs[14] = { +#if WEBRTC_OPUS_SUPPORT_120MS_PTIME + {kOpusCodecName, 48000, 2, 111, true, {10, 20, 40, 60, 120}, + kOpusMaxBitrateBps}, +#else {kOpusCodecName, 48000, 2, 111, true, {10, 20, 40, 60}, kOpusMaxBitrateBps}, +#endif {kIsacCodecName, 16000, 1, 103, true, {30, 60}, kIsacMaxBitrateBps}, {kIsacCodecName, 32000, 1, 104, true, {30}, kIsacMaxBitrateBps}, // G722 should be advertised as 8000 Hz because of the RFC "bug". diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn index 1d3c2d1016..59c166db99 100644 --- a/webrtc/modules/audio_coding/BUILD.gn +++ b/webrtc/modules/audio_coding/BUILD.gn @@ -872,6 +872,8 @@ rtc_source_set("webrtc_opus_c") { "codecs/opus/opus_interface.h", ] + defines = audio_coding_defines + if (rtc_build_opus) { public_deps = [ rtc_opus_dir, diff --git a/webrtc/modules/audio_coding/acm2/acm_codec_database.cc b/webrtc/modules/audio_coding/acm2/acm_codec_database.cc index 4f5b263c24..0fae75b91b 100644 --- a/webrtc/modules/audio_coding/acm2/acm_codec_database.cc +++ b/webrtc/modules/audio_coding/acm2/acm_codec_database.cc @@ -151,7 +151,11 @@ const ACMCodecDB::CodecSettings ACMCodecDB::codec_settings_[] = { // Opus supports frames shorter than 10ms, // but it doesn't help us to use them. // Mono and stereo. +#if WEBRTC_OPUS_SUPPORT_120MS_PTIME + {5, {480, 960, 1920, 2880, 5760}, 0, 2}, +#else {4, {480, 960, 1920, 2880}, 0, 2}, +#endif #endif // Comfort noise for three different sampling frequencies. {1, {240}, 240, 1}, diff --git a/webrtc/modules/audio_coding/audio_coding.gni b/webrtc/modules/audio_coding/audio_coding.gni index 0f3a75fbac..41dcf0044c 100644 --- a/webrtc/modules/audio_coding/audio_coding.gni +++ b/webrtc/modules/audio_coding/audio_coding.gni @@ -15,6 +15,11 @@ if (rtc_include_ilbc) { if (rtc_include_opus) { audio_codec_defines += [ "WEBRTC_CODEC_OPUS" ] } +if (rtc_opus_support_120ms_ptime) { + audio_codec_defines += [ "WEBRTC_OPUS_SUPPORT_120MS_PTIME=1" ] +} else { + audio_codec_defines += [ "WEBRTC_OPUS_SUPPORT_120MS_PTIME=0" ] +} if (!build_with_mozilla) { if (current_cpu == "arm") { audio_codec_defines += [ "WEBRTC_CODEC_ISACFX" ] diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c index e2b4fdbeee..d544d850a9 100644 --- a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c +++ b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c @@ -17,8 +17,13 @@ #include enum { +#if WEBRTC_OPUS_SUPPORT_120MS_PTIME + /* Maximum supported frame size in WebRTC is 120 ms. */ + kWebRtcOpusMaxEncodeFrameSizeMs = 120, +#else /* Maximum supported frame size in WebRTC is 60 ms. */ kWebRtcOpusMaxEncodeFrameSizeMs = 60, +#endif /* The format allows up to 120 ms frames. Since we don't control the other * side, we must allow for packets of that size. NetEq is currently limited diff --git a/webrtc/webrtc.gni b/webrtc/webrtc.gni index 53dcae2b7c..4c34eae192 100644 --- a/webrtc/webrtc.gni +++ b/webrtc/webrtc.gni @@ -17,6 +17,10 @@ declare_args() { # Disable this to avoid building the Opus audio codec. rtc_include_opus = true + # Enable this if the Opus version upon which WebRTC is built supports direct + # encoding of 120 ms packets. + rtc_opus_support_120ms_ptime = false + # Enable this to let the Opus audio codec change complexity on the fly. rtc_opus_variable_complexity = false