[vlc-devel] [PATCH 2/2] audiotrack: add java module

Thomas Guillem thomas at gllm.fr
Fri Feb 6 16:49:32 CET 2015



On Fri, Feb 6, 2015, at 16:15, Rémi Denis-Courmont wrote:
> Le 2015-02-06 18:03, Thomas Guillem a écrit :
> > This module is based on the old native audiotrack but use the public 
> > Java
> 
> use*s*
> 
> > AudioTrack API via JNI. All JNI operations are done in a separate 
> > thread in
> > order to avoid an overhead when attaching and detaching the current 
> > thread to
> 
> the overhead
> 
> > the Java VM.
> >
> > News since native audiotrack:
> >  - Flush discards audio immediatly (if not wait).
> 
> immediat*e*ly
> 
> >  - It adds support for float (for android 5.0 and after).
> 
> *A*ndroid, unless you are refering to a human-shaped robot.
> 

OK, fixed, thanks.

> >  - It can handle a mediaserver crash and restart (for android 5.0 and 
> > after).
> > ---
> >  modules/audio_output/audiotrack.c | 865
> > ++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 865 insertions(+)
> >  create mode 100644 modules/audio_output/audiotrack.c
> >
> > diff --git a/modules/audio_output/audiotrack.c
> > b/modules/audio_output/audiotrack.c
> > new file mode 100644
> > index 0000000..09ef3fb
> > --- /dev/null
> > +++ b/modules/audio_output/audiotrack.c
> > @@ -0,0 +1,865 @@
> > 
> > +/*****************************************************************************
> > + * audiotrack.c: Android Java AudioTrack audio output module
> > +
> > 
> > *****************************************************************************
> > + * Copyright © 2012-2015 VLC authors and VideoLAN
> > + *
> > + * Authors: Thomas Guillem <thomas at gllm.fr>
> > + *          Ming Hu <tewilove at gmail.com>
> > + *
> > + * 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 <assert.h>
> > +#include <jni.h>
> > +
> > +#include <vlc_common.h>
> > +#include <vlc_plugin.h>
> > +#include <vlc_aout.h>
> > +#include <vlc_threads.h>
> > +
> > +#include <dlfcn.h>
> > +#include <assert.h>
> > +
> > +static int  Open( vlc_object_t * );
> > +static void Close( vlc_object_t * );
> > +
> > +struct aout_sys_t {
> > +    /* sw gain */
> > +    float soft_gain;
> > +    bool soft_mute;
> > +
> > +    /* Owned by JNIThread */
> > +    jobject p_audiotrack; /* AudioTrack ref */
> > +    jbyteArray p_bytearray; /* ByteArray ref */
> > +    size_t i_bytearray_size; /* size of the ByteArray */
> > +    audio_sample_format_t fmt; /* fmt setup by Start */
> > +    uint32_t i_samples_written; /* samples written since start/flush 
> > */
> > +    uint32_t i_dsp_initial; /* initial delay of the dsp */
> > +    int i_bytes_per_frame; /* byte per frame */
> > +
> > +    /* JNIThread control */
> > +    vlc_mutex_t mutex;
> > +    vlc_cond_t cond;
> > +    vlc_thread_t thread;
> > +    bool b_thread_run; /* is thread alive */
> > +    struct thread_cmd *p_cmd; /* actual cmd process by JNIThread */
> > +};
> > +
> > +/* Soft volume helper */
> > +#include "audio_output/volume.h"
> > +
> > +vlc_module_begin ()
> > +    set_shortname( "AudioTrack" )
> > +    set_description( N_( "Android AudioTrack audio output" ) )
> > +    set_capability( "audio output", 180 )
> > +    set_category( CAT_AUDIO )
> > +    set_subcategory( SUBCAT_AUDIO_AOUT )
> > +    add_sw_gain()
> > +    add_shortcut( "audiotrack" )
> > +    set_callbacks( Open, Close )
> > +vlc_module_end ()
> > +
> > +struct thread_cmd {
> > +    enum {
> > +        CMD_START,
> > +        CMD_STOP,
> > +        CMD_PLAY,
> > +        CMD_PAUSE,
> > +        CMD_FLUSH,
> > +        CMD_TIME_GET,
> > +        CMD_DONE,
> > +    } id;
> > +    union {
> > +        struct {
> > +            audio_sample_format_t fmt;
> > +        } start;
> > +        struct {
> > +            block_t *p_buffer;
> > +        } play;
> > +        struct {
> > +            bool b_pause;
> > +            mtime_t i_date;
> > +        } pause;
> > +        struct {
> > +            bool b_wait;
> > +        } flush;
> > +    } in;
> > +    union {
> > +        struct {
> > +            int i_ret;
> > +            audio_sample_format_t fmt;
> > +        } start;
> > +        struct {
> > +            int i_ret;
> > +            mtime_t i_delay;
> > +        } time_get;
> > +    } out;
> > +};
> 
> With level triggers instead of edge triggers, you wouldn't need to 
> allocate messages, nor care about congestion control and flushing the 
> command queue.

You mean having only one struct thread_cmd in p_sys and sharing the same
struct for all commands ? For that, you have to be sure that each aout
callback are blocking and called from the same thread (which is the
case), right ? I thought about it, but for me it was clearer having one
struct thread_cmd per command.

> 
> YMMV.
> 
> -- 
> Rémi Denis-Courmont
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



More information about the vlc-devel mailing list