[vlc-devel] [PATCH 3/3] android/audio: add AAudio

Sean McGovern gseanmcg at gmail.com
Thu Dec 3 21:31:00 CET 2020


And then it is as simple as comparing the symbol to null.

-- Sean McGovern

On Thu., Dec. 3, 2020, 15:22 Sean McGovern, <gseanmcg at gmail.com> wrote:

> Hi Thomas,
>
> When you link, you should be able to mark the libaudio.so as a weak
> dependancy(sp?) as well.
>
> Can the linker for Android do this? I haven't checked.
>
> -- Sean McGovern
>
> On Thu., Dec. 3, 2020, 14:29 Thomas Guillem, <thomas at gllm.fr> wrote:
>
>> Hello,
>>
>> How do you do that? Knowing that libaaudio.so is not necessarily present.
>>
>> On Thu, Dec 3, 2020, at 18:28, Rémi Denis-Courmont wrote:
>> > Le torstaina 3. joulukuuta 2020, 19.16.04 EET Thomas Guillem a écrit :
>> > > https://developer.android.com/ndk/guides/audio/aaudio/aaudio
>> > >
>> > > AAudio is a native PCM-only audio API starting Android 8.0 (but
>> enabled
>> > > in VLC starting Android 9.0 due to some bugs).
>> > >
>> > > Having tested it with few device. The latency reported by this new
>> API is
>> > > correct and without any irregularity, contrary to the
>> > > AudioTrack.getTimeStamp() API that is very broken.
>> > >
>> > > Plus side, a huge gain of performance due to the absence of JNI
>> > > C->JAVA->C++. ---
>> > >  modules/audio_output/Makefile.am      |   1 +
>> > >  modules/audio_output/android/aaudio.c | 625
>> ++++++++++++++++++++++++++
>> > >  modules/audio_output/android/device.c |   5 +
>> > >  modules/audio_output/android/device.h |   3 +
>> > >  4 files changed, 634 insertions(+)
>> > >  create mode 100644 modules/audio_output/android/aaudio.c
>> > >
>> > > diff --git a/modules/audio_output/Makefile.am
>> > > b/modules/audio_output/Makefile.am index 35b11e7e3aa..f4d38d9ff68
>> 100644
>> > > --- a/modules/audio_output/Makefile.am
>> > > +++ b/modules/audio_output/Makefile.am
>> > > @@ -3,6 +3,7 @@ aout_LTLIBRARIES =
>> > >
>> > >  libandroid_audio_plugin_la_SOURCES =
>> audio_output/android/audiotrack.c \
>> > >     audio_output/android/opensles.c \
>> > > +   audio_output/android/aaudio.c \
>> > >     audio_output/android/device.c audio_output/android/device.h \
>> > >     video_output/android/utils.c video_output/android/utils.h
>> > >  libandroid_audio_plugin_la_LIBADD = $(LIBDL) $(LIBM)
>> > > diff --git a/modules/audio_output/android/aaudio.c
>> > > b/modules/audio_output/android/aaudio.c new file mode 100644
>> > > index 00000000000..15c3c193b3f
>> > > --- /dev/null
>> > > +++ b/modules/audio_output/android/aaudio.c
>> > > @@ -0,0 +1,625 @@
>> > >
>> +/**************************************************************************
>> > > *** + * aaudio.c: Android AAudio audio stream module
>> > > +
>> > >
>> ***************************************************************************
>> > > ** + * Copyright © 2018-2020 VLC authors, VideoLAN and VideoLabs
>> > > + *
>> > > + * Authors: Romain Vimont <rom1v at videolabs.io>
>> > > + *          Thomas Guillem <thomas at gllm.fr>
>> > > + *
>> > > + * This program is free software; you can redistribute it and/or
>> modify it
>> > > + * under the terms of the GNU Lesser General Public License as
>> published by
>> > > + * the Free Software Foundation; either version 2.1 of the License,
>> or + *
>> > > (at your option) any later version.
>> > > + *
>> > > + * This program is distributed in the hope that it will be useful,
>> > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> > > + * GNU Lesser General Public License for more details.
>> > > + *
>> > > + * You should have received a copy of the GNU Lesser General Public
>> License
>> > > + * along with this program; if not, write to the Free Software
>> Foundation,
>> > > + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
>> +
>> > >
>> ***************************************************************************
>> > > **/ +
>> > > +#ifdef HAVE_CONFIG_H
>> > > +# include "config.h"
>> > > +#endif
>> > > +
>> > > +#include <vlc_common.h>
>> > > +#include <vlc_plugin.h>
>> > > +#include <vlc_aout.h>
>> > > +#include <assert.h>
>> > > +#include <dlfcn.h>
>> > > +
>> > > +#include "device.h"
>> > > +
>> > > +#include <aaudio/AAudio.h>
>> > > +
>> > > +struct sys
>> > > +{
>> > > +    AAudioStream *as;
>> > > +
>> > > +    jobject dp;
>> > > +    float volume;
>> > > +    bool muted;
>> > > +
>> > > +    audio_sample_format_t fmt;
>> > > +    int64_t frames_written;
>> > > +    int64_t frames_flush_pos;
>> > > +    bool error;
>> > > +};
>> > > +
>> > > +/* dlopen/dlsym symbols */
>> > > +static struct {
>> > > +    void *handle;
>> > > +    aaudio_result_t
>>  (*AAudio_createStreamBuilder)(AAudioStreamBuilder
>> > > **); +    const char
>> > > *(*AAudio_convertResultToText)(aaudio_result_t); +    void
>>
>> > > (*AAudioStreamBuilder_setFormat)(AAudioStreamBuilder *,
>> aaudio_format_t); +
>> > >    void
>> > > (*AAudioStreamBuilder_setChannelCount)(AAudioStreamBuilder *,
>> int32_t); +
>> > >  void
>> > > (*AAudioStreamBuilder_setBufferCapacityInFrames)(AAudioStreamBuilder
>> *,
>> > > int32_t); +    void
>> > > (*AAudioStreamBuilder_setPerformanceMode)(AAudioStreamBuilder *,
>> > > aaudio_performance_mode_t); +    void
>> > > (*AAudioStreamBuilder_setSessionId)(AAudioStreamBuilder *,
>> > > aaudio_session_id_t); +    void
>> > > (*AAudioStreamBuilder_setUsage)(AAudioStreamBuilder *,
>> aaudio_usage_t); +
>> > >  aaudio_result_t
>> > > (*AAudioStreamBuilder_openStream)(AAudioStreamBuilder *, AAudioStream
>> **);
>> > > +    void
>> > > (*AAudioStreamBuilder_delete)(AAudioStreamBuilder *); +
>> aaudio_result_t
>> > >      (*AAudioStream_requestStart)(AAudioStream *); +
>> aaudio_result_t
>> > >   (*AAudioStream_requestStop)(AAudioStream *); +    aaudio_result_t
>>
>> > > (*AAudioStream_requestPause)(AAudioStream *); +    aaudio_result_t
>>
>> > > (*AAudioStream_requestFlush)(AAudioStream *); +    int32_t
>>
>> > > (*AAudioStream_getSampleRate)(AAudioStream *); +    aaudio_result_t
>>
>> > > (*AAudioStream_getTimestamp)(AAudioStream *, clockid_t, +
>>
>> > >                                     int64_t *framePosition, int64_t
>> > > *timeNanoseconds); +    aaudio_result_t
>> > > (*AAudioStream_write)(AAudioStream *, void *, int32_t numFrames,
>> int64_t
>> > > timeoutNanoseconds); +    aaudio_result_t
>> > > (*AAudioStream_close)(AAudioStream *);
>> > > +    aaudio_stream_state_t (*AAudioStream_getState)(AAudioStream *);
>> > > +    aaudio_result_t
>>  (*AAudioStream_waitForStateChange)(AAudioStream
>> > > *, aaudio_stream_state_t current_state, aaudio_stream_state_t
>> *nextState,
>> > > int64_t timeoutNanoseconds); +    aaudio_session_id_t
>> > > (*AAudioStream_getSessionId)(AAudioStream *); +} vt;
>> >
>> > Weak symbols would probably be a lot simpler than dlsym() calls here.
>> >
>> > --
>> > レミ・デニ-クールモン
>> > http://www.remlab.net/
>> >
>> >
>> >
>> > _______________________________________________
>> > vlc-devel mailing list
>> > To unsubscribe or modify your subscription options:
>> > https://mailman.videolan.org/listinfo/vlc-devel
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20201203/0895fba7/attachment.html>


More information about the vlc-devel mailing list