From 19881b06d63d89697bc9306fb808e62d8472568d Mon Sep 17 00:00:00 2001 From: roytam1 Date: Sat, 26 Aug 2023 00:45:03 +0800 Subject: [PATCH] ported from `custom` branch of UXP: - add configure option '--enable-int-audio-sample' for speed and audio driver compatibility, and fixups in exports and webrtc. (ef5e4f06) - cubeb: disable wasapi backend when '--enable-int-audio-sample' is specified, since it can handle float32 sample only in our current cubeb library. (0f1c046a) --- configure.in | 14 ++++++++++++++ layout/media/symbols.def.in | 17 ++++++++++++++++- media/libcubeb/src/moz.build | 7 +++++-- .../audio_coding/neteq/audio_classifier.cc | 4 ++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/configure.in b/configure.in index d548e2dcc..4dd63141c 100644 --- a/configure.in +++ b/configure.in @@ -5135,11 +5135,25 @@ AC_SUBST(MOZ_SCTP) AC_SUBST(MOZ_SRTP) AC_SUBST_LIST(MOZ_WEBRTC_X11_LIBS) +dnl ======================================================== +dnl Use integers over floats for audio +dnl ======================================================== + +MOZ_SAMPLE_USE_INT= dnl Use integers over floats for audio on B2G and Android dnl (regarless of the CPU architecture, because audio dnl backends for those platforms don't support floats. We also dnl use integers on ARM with other OS, because it's more efficient. if test "$OS_TARGET" = "Android" -o "$CPU_ARCH" = "arm"; then + MOZ_SAMPLE_USE_INT=1 +fi + +MOZ_ARG_ENABLE_BOOL(int-audio-sample, +[ --enable-int-audio-sample Use int audio output type instead of float type], + MOZ_SAMPLE_USE_INT=1, + MOZ_SAMPLE_USE_INT=) + +if test -n "$MOZ_SAMPLE_USE_INT"; then MOZ_SAMPLE_TYPE_S16=1 AC_DEFINE(MOZ_SAMPLE_TYPE_S16) AC_SUBST(MOZ_SAMPLE_TYPE_S16) diff --git a/layout/media/symbols.def.in b/layout/media/symbols.def.in index ec5f57d12..062ef187b 100644 --- a/layout/media/symbols.def.in +++ b/layout/media/symbols.def.in @@ -75,7 +75,7 @@ aom_codec_peek_stream_info aom_img_alloc aom_img_free #endif -#ifdef MOZ_VORBIS +#if defined(MOZ_VORBIS) || defined(MOZ_TREMOR) ogg_page_bos ogg_page_granulepos ogg_page_serialno @@ -96,19 +96,25 @@ ogg_sync_init ogg_sync_pageseek ogg_sync_reset ogg_sync_wrote +#ifdef MOZ_VORBIS vorbis_analysis vorbis_analysis_blockout vorbis_analysis_buffer vorbis_analysis_init vorbis_analysis_headerout vorbis_analysis_wrote +#endif vorbis_block_clear vorbis_block_init +#ifdef MOZ_VORBIS vorbis_comment_add_tag +#endif vorbis_comment_clear vorbis_comment_init vorbis_dsp_clear +#ifdef MOZ_VORBIS vorbis_encode_init_vbr +#endif vorbis_info_clear vorbis_info_init vorbis_packet_blocksize @@ -122,6 +128,7 @@ vorbis_synthesis_restart #endif moz_speex_resampler_init moz_speex_resampler_destroy +moz_speex_resampler_process_int moz_speex_resampler_process_float moz_speex_resampler_process_interleaved_float moz_speex_resampler_process_interleaved_int @@ -172,12 +179,16 @@ opus_decoder_destroy opus_decoder_ctl opus_decoder_get_nb_samples opus_decode +#ifdef MOZ_SAMPLE_TYPE_FLOAT32 opus_decode_float +#endif opus_get_version_string opus_multistream_decoder_create opus_multistream_decoder_ctl opus_multistream_decoder_destroy +#ifdef MOZ_SAMPLE_TYPE_FLOAT32 opus_multistream_decode_float +#endif opus_multistream_decode opus_packet_get_nb_frames opus_packet_get_samples_per_frame @@ -185,14 +196,18 @@ opus_encoder_create opus_encoder_destroy opus_encoder_ctl opus_encode +#ifdef MOZ_SAMPLE_TYPE_FLOAT32 opus_encode_float +#endif #ifdef MOZ_WEBRTC opus_custom_mode_create opus_packet_parse opus_packet_get_nb_channels downmix_int +#ifdef MOZ_SAMPLE_TYPE_FLOAT32 run_analysis #endif +#endif #ifndef MOZ_NATIVE_PNG MOZ_APNG_get_first_frame_is_hidden MOZ_APNG_get_next_frame_blend_op diff --git a/media/libcubeb/src/moz.build b/media/libcubeb/src/moz.build index ff001498e..f80fed2c3 100644 --- a/media/libcubeb/src/moz.build +++ b/media/libcubeb/src/moz.build @@ -44,11 +44,14 @@ if CONFIG['OS_TARGET'] == 'Darwin': if CONFIG['OS_TARGET'] == 'WINNT': SOURCES += [ 'cubeb_resampler.cpp', - 'cubeb_wasapi.cpp', 'cubeb_winmm.c', ] DEFINES['USE_WINMM'] = True - DEFINES['USE_WASAPI'] = True + if CONFIG['MOZ_SAMPLE_TYPE_FLOAT32']: + DEFINES['USE_WASAPI'] = True + SOURCES += [ + 'cubeb_wasapi.cpp', + ] if CONFIG['_MSC_VER']: CXXFLAGS += ['-wd4005'] # C4005: '_USE_MATH_DEFINES' : macro redefinition diff --git a/media/webrtc/trunk/webrtc/modules/audio_coding/neteq/audio_classifier.cc b/media/webrtc/trunk/webrtc/modules/audio_coding/neteq/audio_classifier.cc index cc4bc97c3..f3e3fb2f3 100644 --- a/media/webrtc/trunk/webrtc/modules/audio_coding/neteq/audio_classifier.cc +++ b/media/webrtc/trunk/webrtc/modules/audio_coding/neteq/audio_classifier.cc @@ -46,6 +46,7 @@ bool AudioClassifier::Analysis(const int16_t* input, // Only mono or stereo are allowed. assert(channels == 1 || channels == 2); +#ifndef MOZ_SAMPLE_TYPE_S16 // Call Opus' classifier, defined in // "third_party/opus/src/src/analysis.h", with lsb_depth = 16. // Also uses a down-mixing function downmix_int, defined in @@ -65,6 +66,9 @@ bool AudioClassifier::Analysis(const int16_t* input, &analysis_info_); music_probability_ = analysis_info_.music_prob; is_music_ = music_probability_ > kDefaultThreshold; +#else + is_music_ = false; +#endif return is_music_; }