X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faudio_output%2Fjack.c;h=63c750473777ed82d1ba92ca23ab6ffef06ea261;hb=bc76f50aa6f0f19e05470b7a3935fd629a969152;hp=c5d87122a1f27014f33879c2dddb4e6b2b72dff8;hpb=df61d33b06e2b3cbbe746b2f5a9bea5b370c24ff;p=vlc diff --git a/modules/audio_output/jack.c b/modules/audio_output/jack.c index c5d87122a1..63c7504737 100644 --- a/modules/audio_output/jack.c +++ b/modules/audio_output/jack.c @@ -34,7 +34,8 @@ # include "config.h" #endif -#include +#include +#include #include #include @@ -53,6 +54,7 @@ struct aout_sys_t jack_port_t **p_jack_ports; jack_sample_t **p_jack_buffers; unsigned int i_channels; + jack_nframes_t latency; }; /***************************************************************************** @@ -62,6 +64,7 @@ static int Open ( vlc_object_t * ); static void Close ( vlc_object_t * ); static void Play ( aout_instance_t * ); static int Process ( jack_nframes_t i_frames, void *p_arg ); +static int GraphChange ( void *p_arg ); #define AUTO_CONNECT_OPTION "jack-auto-connect" #define AUTO_CONNECT_TEXT N_("Automatically connect to writable clients") @@ -78,18 +81,18 @@ static int Process ( jack_nframes_t i_frames, void *p_arg ); /***************************************************************************** * Module descriptor *****************************************************************************/ -vlc_module_begin(); - set_shortname( "JACK" ); - set_description( _("JACK audio output") ); - set_capability( "audio output", 100 ); - set_category( CAT_AUDIO ); - set_subcategory( SUBCAT_AUDIO_AOUT ); - add_bool( AUTO_CONNECT_OPTION, 0, NULL, AUTO_CONNECT_TEXT, - AUTO_CONNECT_LONGTEXT, true ); +vlc_module_begin () + set_shortname( "JACK" ) + set_description( N_("JACK audio output") ) + set_capability( "audio output", 100 ) + set_category( CAT_AUDIO ) + set_subcategory( SUBCAT_AUDIO_AOUT ) + add_bool( AUTO_CONNECT_OPTION, false, NULL, AUTO_CONNECT_TEXT, + AUTO_CONNECT_LONGTEXT, true ) add_string( CONNECT_REGEX_OPTION, NULL, NULL, CONNECT_REGEX_TEXT, - CONNECT_REGEX_LONGTEXT, true ); - set_callbacks( Open, Close ); -vlc_module_end(); + CONNECT_REGEX_LONGTEXT, true ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * Open: create a JACK client @@ -107,16 +110,18 @@ static int Open( vlc_object_t *p_this ) p_sys = calloc( 1, sizeof( aout_sys_t ) ); if( p_sys == NULL ) { - msg_Err( p_aout, "out of memory" ); status = VLC_ENOMEM; goto error_out; } p_aout->output.p_sys = p_sys; + p_sys->latency = 0; /* Connect to the JACK server */ snprintf( psz_name, sizeof(psz_name), "vlc_%d", getpid()); psz_name[sizeof(psz_name) - 1] = '\0'; - p_sys->p_jack_client = jack_client_new( psz_name ); + p_sys->p_jack_client = jack_client_open( psz_name, + JackNullOption | JackNoStartServer, + NULL ); if( p_sys->p_jack_client == NULL ) { msg_Err( p_aout, "failed to connect to JACK server" ); @@ -126,12 +131,13 @@ static int Open( vlc_object_t *p_this ) /* Set the process callback */ jack_set_process_callback( p_sys->p_jack_client, Process, p_aout ); + jack_set_graph_order_callback ( p_sys->p_jack_client, GraphChange, p_aout ); p_aout->output.pf_play = Play; aout_VolumeSoftInit( p_aout ); /* JACK only supports fl32 format */ - p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2'); + p_aout->output.output.i_format = VLC_CODEC_FL32; // TODO add buffer size callback p_aout->output.i_nb_samples = jack_get_buffer_size( p_sys->p_jack_client ); p_aout->output.output.i_rate = jack_get_sample_rate( p_sys->p_jack_client ); @@ -142,7 +148,6 @@ static int Open( vlc_object_t *p_this ) sizeof(jack_port_t *) ); if( p_sys->p_jack_ports == NULL ) { - msg_Err( p_aout, "out of memory" ); status = VLC_ENOMEM; goto error_out; } @@ -151,7 +156,6 @@ static int Open( vlc_object_t *p_this ) sizeof(jack_sample_t *) ); if( p_sys->p_jack_buffers == NULL ) { - msg_Err( p_aout, "out of memory" ); status = VLC_ENOMEM; goto error_out; } @@ -189,6 +193,7 @@ static int Open( vlc_object_t *p_this ) const char **pp_in_ports = jack_get_ports( p_sys->p_jack_client, psz_regex, NULL, JackPortIsInput ); + free( psz_regex ); /* Count the number of returned ports */ i_in_ports = 0; while( pp_in_ports && pp_in_ports[i_in_ports] ) @@ -248,8 +253,15 @@ int Process( jack_nframes_t i_frames, void *p_arg ) struct aout_sys_t *p_sys = p_aout->output.p_sys; jack_sample_t *p_src = NULL; + jack_nframes_t dframes = p_sys->latency + - jack_frames_since_cycle_start( p_sys->p_jack_client ); + + jack_time_t dtime = dframes * 1000 * 1000 / jack_get_sample_rate( p_sys->p_jack_client ); + mtime_t play_date = mdate() + (mtime_t) ( dtime ); + /* Get the next audio data buffer */ - aout_buffer_t *p_buffer = aout_FifoPop( p_aout, &p_aout->output.fifo ); + aout_buffer_t *p_buffer = aout_OutputNextBuffer( p_aout, play_date, false ); + if( p_buffer != NULL ) { p_src = (jack_sample_t *)p_buffer->p_buffer; @@ -291,13 +303,38 @@ int Process( jack_nframes_t i_frames, void *p_arg ) return 0; } +/***************************************************************************** + * GraphChange: callback when JACK reorders it's process graph. + We update latency information. + *****************************************************************************/ + +static int GraphChange( void *p_arg ) +{ + aout_instance_t *p_aout = (aout_instance_t*) p_arg; + struct aout_sys_t *p_sys = p_aout->output.p_sys; + unsigned int i; + jack_nframes_t port_latency; + + p_sys->latency = 0; + + for( i = 0; i < p_sys->i_channels; ++i ) + { + port_latency = jack_port_get_total_latency( p_sys->p_jack_client, + p_sys->p_jack_ports[i] ); + p_sys->latency = __MAX( p_sys->latency, port_latency ); + } + + msg_Dbg(p_aout, "JACK graph reordered. Our maximum latency=%d.", p_sys->latency); + + return 0; +} /***************************************************************************** * Play: nothing to do *****************************************************************************/ static void Play( aout_instance_t *p_aout ) { - aout_FifoFirstDate( p_aout, &p_aout->output.fifo ); + VLC_UNUSED( p_aout ); } /*****************************************************************************