[vlc-commits] [Git][videolan/vlc][master] 6 commits: audiotrack: rework AudioTrack_GetChanOrder

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Oct 19 09:37:05 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
f31c9121 by Thomas Guillem at 2024-10-19T09:24:12+00:00
audiotrack: rework AudioTrack_GetChanOrder

- - - - -
12bcd6d0 by Thomas Guillem at 2024-10-19T09:24:12+00:00
android/audio: expose GetChanOrder

For other aout stream modules.

- - - - -
1be62395 by Thomas Guillem at 2024-10-19T09:24:12+00:00
aaudio: take android_audio_device_type into account

Force stereo is asked by the user.

- - - - -
ec2fa8ba by Thomas Guillem at 2024-10-19T09:24:12+00:00
aaudio: support chan ordering

- - - - -
1f7aed6e by Thomas Guillem at 2024-10-19T09:24:12+00:00
aaudio: rework AAUDIO_DLSYM

Add a paramater to tell if the symbol is mandatory.

- - - - -
20a3c8ed by Thomas Guillem at 2024-10-19T09:24:12+00:00
aaudio: add setChannelMask support

- - - - -


3 changed files:

- modules/audio_output/android/aaudio.c
- modules/audio_output/android/audiotrack.c
- modules/audio_output/android/device.h


Changes:

=====================================
modules/audio_output/android/aaudio.c
=====================================
@@ -81,6 +81,10 @@ struct sys
     /* Number of bytes to write before sending a timing report */
     size_t timing_report_delay_bytes;
     vlc_tick_t first_pts;
+
+    /* Channel reordering */
+    uint8_t chans_to_reorder;
+    uint8_t chan_table[AOUT_CHAN_MAX];
 };
 
 /* dlopen/dlsym symbols */
@@ -91,6 +95,7 @@ static struct {
     void                  (*AAudioStreamBuilder_setDeviceId)(AAudioStreamBuilder *, int32_t);
     void                  (*AAudioStreamBuilder_setFormat)(AAudioStreamBuilder *, aaudio_format_t);
     void                  (*AAudioStreamBuilder_setChannelCount)(AAudioStreamBuilder *, int32_t);
+    void                  (*AAudioStreamBuilder_setChannelMask)(AAudioStreamBuilder *, aaudio_channel_mask_t);
     void                  (*AAudioStreamBuilder_setDataCallback)(AAudioStreamBuilder *, AAudioStream_dataCallback, void *);
     void                  (*AAudioStreamBuilder_setErrorCallback)(AAudioStreamBuilder *, AAudioStream_errorCallback,  void *);
     void                  (*AAudioStreamBuilder_setPerformanceMode)(AAudioStreamBuilder *, aaudio_performance_mode_t);
@@ -142,10 +147,10 @@ LoadSymbols(aout_stream_t *stream)
         goto end;
     }
 
-#define AAUDIO_DLSYM(name) \
+#define AAUDIO_DLSYM(name, critical) \
     do { \
         void *sym = dlsym(vt.handle, #name); \
-        if (unlikely(!sym)) { \
+        if (unlikely(!sym) && critical) { \
             msg_Err(stream, "Failed to load symbol "#name); \
             init_state = 0; \
             goto end; \
@@ -153,30 +158,31 @@ LoadSymbols(aout_stream_t *stream)
         *(void **) &vt.name = sym; \
     } while(0)
 
-    AAUDIO_DLSYM(AAudio_createStreamBuilder);
-    AAUDIO_DLSYM(AAudio_convertResultToText);
-    AAUDIO_DLSYM(AAudioStreamBuilder_setChannelCount);
-    AAUDIO_DLSYM(AAudioStreamBuilder_setDeviceId);
-    AAUDIO_DLSYM(AAudioStreamBuilder_setFormat);
-    AAUDIO_DLSYM(AAudioStreamBuilder_setDataCallback);
-    AAUDIO_DLSYM(AAudioStreamBuilder_setErrorCallback);
-    AAUDIO_DLSYM(AAudioStreamBuilder_setPerformanceMode);
-    AAUDIO_DLSYM(AAudioStreamBuilder_setSessionId);
-    AAUDIO_DLSYM(AAudioStreamBuilder_setUsage);
-    AAUDIO_DLSYM(AAudioStreamBuilder_openStream);
-    AAUDIO_DLSYM(AAudioStreamBuilder_delete);
-    AAUDIO_DLSYM(AAudioStream_requestStart);
-    AAUDIO_DLSYM(AAudioStream_requestStop);
-    AAUDIO_DLSYM(AAudioStream_requestPause);
-    AAUDIO_DLSYM(AAudioStream_requestFlush);
-    AAUDIO_DLSYM(AAudioStream_getDeviceId);
-    AAUDIO_DLSYM(AAudioStream_getSampleRate);
-    AAUDIO_DLSYM(AAudioStream_getTimestamp);
-    AAUDIO_DLSYM(AAudioStream_write);
-    AAUDIO_DLSYM(AAudioStream_close);
-    AAUDIO_DLSYM(AAudioStream_getState);
-    AAUDIO_DLSYM(AAudioStream_waitForStateChange);
-    AAUDIO_DLSYM(AAudioStream_getSessionId);
+    AAUDIO_DLSYM(AAudio_createStreamBuilder, true);
+    AAUDIO_DLSYM(AAudio_convertResultToText, true);
+    AAUDIO_DLSYM(AAudioStreamBuilder_setChannelCount, true);
+    AAUDIO_DLSYM(AAudioStreamBuilder_setChannelMask, false);
+    AAUDIO_DLSYM(AAudioStreamBuilder_setDeviceId, true);
+    AAUDIO_DLSYM(AAudioStreamBuilder_setFormat, true);
+    AAUDIO_DLSYM(AAudioStreamBuilder_setDataCallback, true);
+    AAUDIO_DLSYM(AAudioStreamBuilder_setErrorCallback, true);
+    AAUDIO_DLSYM(AAudioStreamBuilder_setPerformanceMode, true);
+    AAUDIO_DLSYM(AAudioStreamBuilder_setSessionId, true);
+    AAUDIO_DLSYM(AAudioStreamBuilder_setUsage, true);
+    AAUDIO_DLSYM(AAudioStreamBuilder_openStream, true);
+    AAUDIO_DLSYM(AAudioStreamBuilder_delete, true);
+    AAUDIO_DLSYM(AAudioStream_requestStart, true);
+    AAUDIO_DLSYM(AAudioStream_requestStop, true);
+    AAUDIO_DLSYM(AAudioStream_requestPause, true);
+    AAUDIO_DLSYM(AAudioStream_requestFlush, true);
+    AAUDIO_DLSYM(AAudioStream_getDeviceId, true);
+    AAUDIO_DLSYM(AAudioStream_getSampleRate, true);
+    AAUDIO_DLSYM(AAudioStream_getTimestamp, true);
+    AAUDIO_DLSYM(AAudioStream_write, true);
+    AAUDIO_DLSYM(AAudioStream_close, true);
+    AAUDIO_DLSYM(AAudioStream_getState, true);
+    AAUDIO_DLSYM(AAudioStream_waitForStateChange, true);
+    AAUDIO_DLSYM(AAudioStream_getSessionId, true);
 #undef AAUDIO_DLSYM
 
     init_state = 1;
@@ -506,6 +512,31 @@ CloseAAudioStream(aout_stream_t *stream)
     sys->as = NULL;
 }
 
+static aaudio_channel_mask_t
+VLCMaskToAaudio(uint16_t vlc_mask)
+{
+    aaudio_channel_mask_t mask = 0;
+    if (vlc_mask & AOUT_CHAN_CENTER)
+        mask |= AAUDIO_CHANNEL_FRONT_CENTER;
+    if (vlc_mask & AOUT_CHAN_LEFT)
+        mask |= AAUDIO_CHANNEL_FRONT_LEFT;
+    if (vlc_mask & AOUT_CHAN_RIGHT)
+        mask |= AAUDIO_CHANNEL_FRONT_RIGHT;
+    if (vlc_mask & AOUT_CHAN_REARCENTER)
+        mask |= AAUDIO_CHANNEL_BACK_CENTER;
+    if (vlc_mask & AOUT_CHAN_REARLEFT)
+        mask |= AAUDIO_CHANNEL_BACK_LEFT;
+    if (vlc_mask & AOUT_CHAN_REARRIGHT)
+        mask |= AAUDIO_CHANNEL_BACK_RIGHT;
+    if (vlc_mask & AOUT_CHAN_MIDDLELEFT)
+        mask |= AAUDIO_CHANNEL_SIDE_LEFT;
+    if (vlc_mask & AOUT_CHAN_MIDDLERIGHT)
+        mask |= AAUDIO_CHANNEL_SIDE_RIGHT;
+    if (vlc_mask & AOUT_CHAN_LFE)
+        mask |= AAUDIO_CHANNEL_LOW_FREQUENCY;
+    return mask;
+}
+
 static int
 OpenAAudioStream(aout_stream_t *stream)
 {
@@ -521,7 +552,23 @@ OpenAAudioStream(aout_stream_t *stream)
     }
 
     vt.AAudioStreamBuilder_setFormat(builder, sys->cfg.format);
-    vt.AAudioStreamBuilder_setChannelCount(builder, sys->fmt.i_channels);
+
+    uint32_t chans_out[AOUT_CHAN_MAX];
+    AndroidDevice_GetChanOrder(sys->fmt.i_physical_channels, chans_out,
+                               AOUT_CHAN_MAX );
+    sys->chans_to_reorder =
+        aout_CheckChannelReorder(NULL, chans_out,
+                                 sys->fmt.i_physical_channels,
+                                 sys->chan_table );
+
+    if (vt.AAudioStreamBuilder_setChannelMask != NULL)
+    {
+        aaudio_channel_mask_t mask =
+            VLCMaskToAaudio(sys->fmt.i_physical_channels);
+        vt.AAudioStreamBuilder_setChannelMask(builder, mask);
+    }
+    else
+        vt.AAudioStreamBuilder_setChannelCount(builder, sys->fmt.i_channels);
 
     /* Setup the session-id */
     vt.AAudioStreamBuilder_setSessionId(builder, sys->cfg.session_id);
@@ -571,6 +618,22 @@ PrepareAudioFormat(aout_stream_t *stream, audio_sample_format_t *fmt)
     if (sys->cfg.session_id == 0)
         sys->cfg.session_id = AAUDIO_SESSION_ID_ALLOCATE;
 
+    if (vt.AAudioStreamBuilder_setChannelMask == NULL)
+    {
+        /* Without the proper setChannelMask API, support only mono, stereo,
+         * 5.1 and 7.1 */
+        unsigned channels = aout_FormatNbChannels( &sys->fmt );
+        if (channels > 7)
+            sys->fmt.i_physical_channels = AOUT_CHANS_7_1;
+        else if (channels > 5)
+            sys->fmt.i_physical_channels = AOUT_CHANS_5_1;
+        else if (channels == 1)
+            sys->fmt.i_physical_channels = AOUT_CHAN_LEFT;
+        else
+            sys->fmt.i_physical_channels = AOUT_CHANS_STEREO;
+        aout_FormatPrepare(fmt);
+    }
+
     if (fmt->i_format == VLC_CODEC_S16N)
         sys->cfg.format = AAUDIO_FORMAT_PCM_I16;
     else
@@ -616,6 +679,11 @@ Play(aout_stream_t *stream, vlc_frame_t *frame, vlc_tick_t date)
 
     assert(sys->as);
 
+    if (sys->chans_to_reorder > 0)
+       aout_ChannelReorder(frame->p_buffer, frame->i_buffer,
+                           sys->chans_to_reorder, sys->chan_table,
+                           sys->fmt.i_format );
+
     vlc_mutex_lock(&sys->lock);
 
     if (!sys->started)
@@ -816,14 +884,18 @@ static int
 Start(aout_stream_t *stream, audio_sample_format_t *fmt,
       enum android_audio_device_type adev)
 {
-    (void) adev;
-
     if (!AOUT_FMT_LINEAR(fmt))
         return VLC_EGENERIC;
 
     if (LoadSymbols(stream) != VLC_SUCCESS)
         return VLC_EGENERIC;
 
+    if (adev == ANDROID_AUDIO_DEVICE_STEREO)
+    {
+        fmt->i_physical_channels = AOUT_CHANS_STEREO;
+        aout_FormatPrepare(fmt);
+    }
+
     struct sys *sys = stream->sys = malloc(sizeof(*sys));
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;


=====================================
modules/audio_output/android/audiotrack.c
=====================================
@@ -598,41 +598,6 @@ AudioTrack_GetLatencyUs( JNIEnv *env, aout_stream_t *stream )
     return 0;
 }
 
-static void
-AudioTrack_GetChanOrder( uint16_t i_physical_channels, uint32_t p_chans_out[] )
-{
-#define HAS_CHAN( x ) ( ( i_physical_channels & (x) ) == (x) )
-    /* samples will be in the following order: FL FR FC LFE BL BR BC SL SR */
-    int i = 0;
-
-    if( HAS_CHAN( AOUT_CHAN_LEFT ) )
-        p_chans_out[i++] = AOUT_CHAN_LEFT;
-    if( HAS_CHAN( AOUT_CHAN_RIGHT ) )
-        p_chans_out[i++] = AOUT_CHAN_RIGHT;
-
-    if( HAS_CHAN( AOUT_CHAN_CENTER ) )
-        p_chans_out[i++] = AOUT_CHAN_CENTER;
-
-    if( HAS_CHAN( AOUT_CHAN_LFE ) )
-        p_chans_out[i++] = AOUT_CHAN_LFE;
-
-    if( HAS_CHAN( AOUT_CHAN_REARLEFT ) )
-        p_chans_out[i++] = AOUT_CHAN_REARLEFT;
-    if( HAS_CHAN( AOUT_CHAN_REARRIGHT ) )
-        p_chans_out[i++] = AOUT_CHAN_REARRIGHT;
-
-    if( HAS_CHAN( AOUT_CHAN_REARCENTER ) )
-        p_chans_out[i++] = AOUT_CHAN_REARCENTER;
-
-    if( HAS_CHAN( AOUT_CHAN_MIDDLELEFT ) )
-        p_chans_out[i++] = AOUT_CHAN_MIDDLELEFT;
-    if( HAS_CHAN( AOUT_CHAN_MIDDLERIGHT ) )
-        p_chans_out[i++] = AOUT_CHAN_MIDDLERIGHT;
-
-    assert( i <= AOUT_CHAN_MAX );
-#undef HAS_CHAN
-}
-
 struct role {
     char vlc[16];
 };
@@ -1757,8 +1722,8 @@ StartPCM( JNIEnv *env, aout_stream_t *stream, unsigned i_max_channels )
         return i_ret;
 
     uint32_t p_chans_out[AOUT_CHAN_MAX];
-    memset( p_chans_out, 0, sizeof(p_chans_out) );
-    AudioTrack_GetChanOrder( p_sys->fmt.i_physical_channels, p_chans_out );
+    AndroidDevice_GetChanOrder( p_sys->fmt.i_physical_channels, p_chans_out,
+                                AOUT_CHAN_MAX );
     p_sys->i_chans_to_reorder =
         aout_CheckChannelReorder( NULL, p_chans_out,
                                   p_sys->fmt.i_physical_channels,


=====================================
modules/audio_output/android/device.h
=====================================
@@ -32,6 +32,45 @@ enum android_audio_device_type
 };
 #define ANDROID_AUDIO_DEVICE_MAX_CHANNELS 8
 
+static inline void
+AndroidDevice_GetChanOrder( uint16_t i_physical_channels, uint32_t p_chans_out[],
+                            size_t chan_out_max )
+{
+    assert( chan_out_max >= AOUT_CHAN_MAX);
+    memset( p_chans_out, 0, chan_out_max * sizeof(uint32_t) );
+
+#define HAS_CHAN( x ) ( ( i_physical_channels & (x) ) == (x) )
+    /* samples will be in the following order: FL FR FC LFE BL BR BC SL SR */
+    int i = 0;
+
+    if( HAS_CHAN( AOUT_CHAN_LEFT ) )
+        p_chans_out[i++] = AOUT_CHAN_LEFT;
+    if( HAS_CHAN( AOUT_CHAN_RIGHT ) )
+        p_chans_out[i++] = AOUT_CHAN_RIGHT;
+
+    if( HAS_CHAN( AOUT_CHAN_CENTER ) )
+        p_chans_out[i++] = AOUT_CHAN_CENTER;
+
+    if( HAS_CHAN( AOUT_CHAN_LFE ) )
+        p_chans_out[i++] = AOUT_CHAN_LFE;
+
+    if( HAS_CHAN( AOUT_CHAN_REARLEFT ) )
+        p_chans_out[i++] = AOUT_CHAN_REARLEFT;
+    if( HAS_CHAN( AOUT_CHAN_REARRIGHT ) )
+        p_chans_out[i++] = AOUT_CHAN_REARRIGHT;
+
+    if( HAS_CHAN( AOUT_CHAN_REARCENTER ) )
+        p_chans_out[i++] = AOUT_CHAN_REARCENTER;
+
+    if( HAS_CHAN( AOUT_CHAN_MIDDLELEFT ) )
+        p_chans_out[i++] = AOUT_CHAN_MIDDLELEFT;
+    if( HAS_CHAN( AOUT_CHAN_MIDDLERIGHT ) )
+        p_chans_out[i++] = AOUT_CHAN_MIDDLERIGHT;
+
+    assert( i <= AOUT_CHAN_MAX );
+#undef HAS_CHAN
+}
+
 struct aout_stream
 {
     struct vlc_object_t obj;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/59d62be92cb0ade3a66e04d0f82f7a22ed9f3893...20a3c8ed72ea499a4fd9d01bfa1455b7ae9ff122

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/59d62be92cb0ade3a66e04d0f82f7a22ed9f3893...20a3c8ed72ea499a4fd9d01bfa1455b7ae9ff122
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list