[vlc-devel] [PATCH] auhal: add the "auhal-buffer-frame-size" option

Rémi Denis-Courmont remi at remlab.net
Tue Jul 21 17:53:57 CEST 2020


Hi,

As far as I understand the link, it is the application's responsibility, not the user's, to set that value optimally.

Le 21 juillet 2020 17:01:25 GMT+03:00, Thomas Guillem <thomas at gllm.fr> a écrit :
>This option can be used to change the I/O buffer size.
>
>cf.
>https://developer.apple.com/library/archive/technotes/tn2321/_index.html
>---
> modules/audio_output/audiounit_ios.m    |  2 +-
> modules/audio_output/auhal.c            |  8 ++++++++
> modules/audio_output/coreaudio_common.c | 16 +++++++++++++++-
> modules/audio_output/coreaudio_common.h |  2 +-
> 4 files changed, 25 insertions(+), 3 deletions(-)
>
>diff --git a/modules/audio_output/audiounit_ios.m
>b/modules/audio_output/audiounit_ios.m
>index e0547b514f0..6de6af0aec7 100644
>--- a/modules/audio_output/audiounit_ios.m
>+++ b/modules/audio_output/audiounit_ios.m
>@@ -536,7 +536,7 @@ Start(audio_output_t *p_aout, audio_sample_format_t
>*restrict fmt)
>         vlc_tick_from_sec([p_sys->avInstance outputLatency]);
>msg_Dbg(p_aout, "Current device has a latency of %lld us", latency_us);
> 
>-    ret = au_Initialize(p_aout, p_sys->au_unit, fmt, layout,
>latency_us, NULL);
>+    ret = au_Initialize(p_aout, p_sys->au_unit, fmt, layout,
>latency_us, 0, NULL);
>     if (ret != VLC_SUCCESS)
>         goto error;
> 
>diff --git a/modules/audio_output/auhal.c
>b/modules/audio_output/auhal.c
>index ab614c92a00..0bf3b2b809a 100644
>--- a/modules/audio_output/auhal.c
>+++ b/modules/audio_output/auhal.c
>@@ -46,6 +46,10 @@
> #define DEVICE_TEXT N_("Last audio device")
> #define DEVICE_LONGTEXT DEVICE_TEXT
> 
>+#define BUFFER_FRAME_SIZE_TEXT "Auhal I/O buffer size in frames"
>+#define BUFFER_FRAME_SIZE_LONGTEXT "A low value (16-32) reduces audio
>latency," \
>+    "a higher value (> 1024) improves power consumption"
>+
> static int      Open                    (vlc_object_t *);
> static void     Close                   (vlc_object_t *);
> 
>@@ -59,6 +63,8 @@ vlc_module_begin ()
>     add_integer("auhal-volume", AOUT_VOLUME_DEFAULT,
>                 VOLUME_TEXT, VOLUME_LONGTEXT, true)
>     change_integer_range(0, AOUT_VOLUME_MAX)
>+    add_integer("auhal-buffer-frame-size", 0 /* system default */,
>+                BUFFER_FRAME_SIZE_TEXT, BUFFER_FRAME_SIZE_LONGTEXT,
>true)
>add_string("auhal-audio-device", "", DEVICE_TEXT, DEVICE_LONGTEXT,
>true)
>     add_string("auhal-warned-devices", "", NULL, NULL, true)
>     change_private()
>@@ -1112,7 +1118,9 @@ StartAnalog(audio_output_t *p_aout,
>audio_sample_format_t *fmt)
> 
>     /* Do the last VLC aout setups */
>     bool warn_configuration;
>+
>     int ret = au_Initialize(p_aout, p_sys->au_unit, fmt, layout, 0,
>+                            var_InheritInteger(p_aout,
>"auhal-buffer-frame-size"),
>                             &warn_configuration);
>     if (ret != VLC_SUCCESS)
>         goto error;
>diff --git a/modules/audio_output/coreaudio_common.c
>b/modules/audio_output/coreaudio_common.c
>index 797c3e623d3..8d8be946edf 100644
>--- a/modules/audio_output/coreaudio_common.c
>+++ b/modules/audio_output/coreaudio_common.c
>@@ -840,7 +840,7 @@ SetupInputLayout(audio_output_t *p_aout, const
>audio_sample_format_t *fmt,
> int
>au_Initialize(audio_output_t *p_aout, AudioUnit au,
>audio_sample_format_t *fmt,
>      const AudioChannelLayout *outlayout, vlc_tick_t i_dev_latency_us,
>-              bool *warn_configuration)
>+              unsigned buffer_frame_size, bool *warn_configuration)
> {
>     int ret;
>     AudioChannelLayoutTag inlayout_tag;
>@@ -938,6 +938,20 @@ au_Initialize(audio_output_t *p_aout, AudioUnit
>au, audio_sample_format_t *fmt,
>         return VLC_EGENERIC;
>     }
> 
>+    if (buffer_frame_size > 0)
>+    {
>+        UInt32 buffer_size = buffer_frame_size;
>+        err = AudioUnitSetProperty(au,
>kAudioDevicePropertyBufferFrameSize,
>+                                   kAudioUnitScope_Output, 0,
>&buffer_size,
>+                                   sizeof(buffer_size));
>+        if (err != noErr)
>+        {
>+            ca_LogErr("failed to setup buffer frame size");
>+            return VLC_EGENERIC;
>+        }
>+    }
>+
>+
>     /* AU init */
>     err = AudioUnitInitialize(au);
> 
>diff --git a/modules/audio_output/coreaudio_common.h
>b/modules/audio_output/coreaudio_common.h
>index 4bd61394937..272399689f8 100644
>--- a/modules/audio_output/coreaudio_common.h
>+++ b/modules/audio_output/coreaudio_common.h
>@@ -111,6 +111,6 @@ AudioUnit au_NewOutputInstance(audio_output_t
>*p_aout, OSType comp_sub_type);
> int  au_Initialize(audio_output_t *p_aout, AudioUnit au,
>                    audio_sample_format_t *fmt,
>      const AudioChannelLayout *outlayout, vlc_tick_t i_dev_latency_us,
>-                   bool *warn_configuration);
>+                   unsigned buffer_frame_size, bool
>*warn_configuration);
> 
> void au_Uninitialize(audio_output_t *p_aout, AudioUnit au);
>-- 
>2.27.0
>
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

-- 
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200721/a1ee70c4/attachment.html>


More information about the vlc-devel mailing list