[vlc-devel] [PATCH] audiotrack: add an option for maximum number of channels

Thomas Guillem thomas at gllm.fr
Tue Apr 7 19:00:55 CEST 2015


Android mediaserver crashes when you output 5.1 PCM @48kHz via Audiotrack with
a lot of QCOM devices due to a SIGSEGV in their resampler. It happens with
Samsung Galaxy Tab 3/4, Galaxy S4/S5 and many other devices.

Therefore, activate surround only via an extra option.
---
 modules/audio_output/audiotrack.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/modules/audio_output/audiotrack.c b/modules/audio_output/audiotrack.c
index bb79d46..7d4acf3 100644
--- a/modules/audio_output/audiotrack.c
+++ b/modules/audio_output/audiotrack.c
@@ -80,6 +80,10 @@ struct aout_sys_t {
 // TODO: activate getTimestamp for new android versions
 //#define AUDIOTRACK_USE_TIMESTAMP
 
+#define SURROUND_TEXT N_("Maximum number of channels")
+#define SURROUND_LONGTEXT N_("Set the maximum of channels")
+#define CFG_PREFIX "audiotrack-"
+
 vlc_module_begin ()
     set_shortname( "AudioTrack" )
     set_description( N_( "Android AudioTrack audio output" ) )
@@ -88,6 +92,8 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_AUDIO_AOUT )
     add_sw_gain()
     add_shortcut( "audiotrack" )
+    add_integer(CFG_PREFIX "maxchannels", 2,
+                SURROUND_TEXT, SURROUND_LONGTEXT, true)
     set_callbacks( Open, Close )
 vlc_module_end ()
 
@@ -631,9 +637,13 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
     aout_sys_t *p_sys = p_aout->sys;
     JNIEnv *env;
     jobject p_audiotrack = NULL;
-    int i_nb_channels, i_audiotrack_size, i_bytes_per_frame,
+    int i_nb_channels, i_max_channels, i_audiotrack_size, i_bytes_per_frame,
         i_native_rate;
     unsigned int i_rate;
+    bool b_spdif;
+
+    b_spdif = var_InheritBool( p_aout, "spdif" );
+    i_max_channels = var_InheritInteger( p_aout, CFG_PREFIX "maxchannels" );
 
     if( !( env = jni_get_env( THREAD_NAME ) ) )
         return VLC_EGENERIC;
@@ -664,8 +674,7 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
                 p_sys->fmt.i_format = VLC_CODEC_S16N;
             break;
         case VLC_CODEC_A52:
-            if( jfields.AudioFormat.has_ENCODING_AC3
-                && var_InheritBool( p_aout, "spdif" ) )
+            if( jfields.AudioFormat.has_ENCODING_AC3 && b_spdif )
                 p_sys->fmt.i_format = VLC_CODEC_SPDIFB;
             else if( jfields.AudioFormat.has_ENCODING_PCM_FLOAT )
                 p_sys->fmt.i_format = VLC_CODEC_FL32;
@@ -681,6 +690,8 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
      * Android will downmix to stereo if audio output doesn't handle 5.1 or 7.1
      */
     i_nb_channels = aout_FormatNbChannels( &p_sys->fmt );
+    if( p_sys->fmt.i_format != VLC_CODEC_SPDIFB )
+        i_nb_channels = __MIN( i_max_channels, i_nb_channels );
     if( i_nb_channels > 5 )
     {
         if( i_nb_channels > 7 && jfields.AudioFormat.has_CHANNEL_OUT_SIDE )
-- 
2.1.3




More information about the vlc-devel mailing list