/*****************************************************************************
* jack.c: JACK audio input module
*****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2008 VLC authors and VideoLAN
* Copyright (C) 2007 Société des arts technologiques
* Copyright (C) 2007 Savoir-faire Linux
*
* Julien Plissonneau Duquene <... at savoirfairelinux.com>
* Pierre-Luc Beaudoin <pierre-luc.beaudoin at savoirfairelinux.com>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * 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 General Public License for more details.
+ * 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 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.
+ * 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.
*****************************************************************************/
/**
# include "config.h"
#endif
-#include <vlc/vlc.h>
+#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_input.h>
#include <vlc_demux.h>
-#include <vlc_vout.h>
-#include <vlc_codecs.h>
#include <vlc_url.h>
#include <vlc_strings.h>
#include <jack/jack.h>
#include <jack/ringbuffer.h>
-#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
-#define CACHING_TEXT N_("Caching value in ms")
-#define CACHING_LONGTEXT N_( \
- "Make VLC buffer audio data capturer from jack for the specified " \
- "length in milliseconds." )
#define PACE_TEXT N_( "Pace" )
#define PACE_LONGTEXT N_( \
"Read the audio stream at VLC pace rather than Jack pace." )
-#define AUTO_CONNECT_TEXT N_( "Auto Connection" )
+#define AUTO_CONNECT_TEXT N_( "Auto connection" )
#define AUTO_CONNECT_LONGTEXT N_( \
"Automatically connect VLC input ports to available output ports." )
-vlc_module_begin();
- set_description( N_("JACK audio input") );
- set_capability( "access_demux", 0 );
- set_shortname( N_( "JACK Input" ) );
- set_category( CAT_INPUT );
- set_subcategory( SUBCAT_INPUT_ACCESS );
+vlc_module_begin ()
+ set_description( N_("JACK audio input") )
+ set_capability( "access_demux", 0 )
+ set_shortname( N_( "JACK Input" ) )
+ set_category( CAT_INPUT )
+ set_subcategory( SUBCAT_INPUT_ACCESS )
- add_integer( "jack-input-caching", DEFAULT_PTS_DELAY / 1000, NULL,
- CACHING_TEXT, CACHING_LONGTEXT, true );
- add_bool( "jack-input-use-vlc-pace", false, NULL,
- PACE_TEXT, PACE_LONGTEXT, true );
- add_bool( "jack-input-auto-connect", false, NULL,
- PACE_TEXT, PACE_LONGTEXT, true );
+ add_bool( "jack-input-use-vlc-pace", false,
+ PACE_TEXT, PACE_LONGTEXT, true )
+ add_bool( "jack-input-auto-connect", false,
+ AUTO_CONNECT_TEXT, AUTO_CONNECT_LONGTEXT, false )
- add_shortcut( "jack" );
- set_callbacks( Open, Close );
-vlc_module_end();
+ add_shortcut( "jack" )
+ set_callbacks( Open, Close )
+vlc_module_end ()
/*****************************************************************************
* Local prototypes
/* Allocate structure */
p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
- if( p_sys == NULL )
- {
- msg_Err( p_demux, "out of memory, cannot allocate structure" );
+ if( !p_sys )
return VLC_ENOMEM;
- }
- memset( p_sys, 0, sizeof( demux_sys_t ) );
/* Parse MRL */
Parse( p_demux );
/* Create var */
- var_Create( p_demux, "jack-input-caching",
- VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_demux, "jack-input-use-vlc-pace",
VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_demux, "jack-input-auto-connect",
/* define name and connect to jack server */
char p_vlc_client_name[32];
sprintf( p_vlc_client_name, "vlc-input-%d", getpid() );
- p_sys->p_jack_client = jack_client_new( p_vlc_client_name );
+ p_sys->p_jack_client = jack_client_open( p_vlc_client_name, JackNullOption, NULL );
if( p_sys->p_jack_client == NULL )
{
msg_Err( p_demux, "failed to connect to JACK server" );
}
/* find some specifics ports if user entered a regexp */
- if( p_sys->psz_ports)
+ if( p_sys->psz_ports )
{
Port_finder( p_demux );
if( p_sys->i_channels == 0 )
p_sys->i_channels * sizeof( jack_port_t* ) );
if( p_sys->pp_jack_port_input == NULL )
{
- msg_Err( p_demux, "out of memory, cannot allocate input ports" );
+ jack_client_close( p_sys->p_jack_client );
+ free( p_sys );
return VLC_ENOMEM;
}
* sizeof( jack_default_audio_sample_t ) );
if( p_sys->p_jack_ringbuffer == NULL )
{
- msg_Err( p_demux, "out of memory, cannot allocate ringbuffer" );
+ free( p_sys->pp_jack_port_input );
+ jack_client_close( p_sys->p_jack_client );
+ free( p_sys );
return VLC_ENOMEM;
}
if( p_sys->pp_jack_port_input[i] == NULL )
{
msg_Err( p_demux, "failed to register a JACK port" );
- if( p_sys->p_jack_client) jack_client_close( p_sys->p_jack_client );
+ jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
free( p_sys->pp_jack_port_input );
- if( p_sys->p_jack_ringbuffer ) jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
- free( p_sys->pp_jack_buffer );
+ jack_client_close( p_sys->p_jack_client );
free( p_sys );
return VLC_EGENERIC;
}
* sizeof( jack_default_audio_sample_t * ) );
if( p_sys->pp_jack_buffer == NULL )
{
- msg_Err( p_demux, "out of memory, cannot allocate input buffer" );
+ for( i = 0; i < p_sys->i_channels; i++ )
+ jack_port_unregister( p_sys->p_jack_client, p_sys->pp_jack_port_input[i] );
+ jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
+ free( p_sys->pp_jack_port_input );
+ jack_client_close( p_sys->p_jack_client );
+ free( p_sys );
return VLC_ENOMEM;
}
if ( jack_activate( p_sys->p_jack_client ) )
{
msg_Err( p_demux, "failed to activate JACK client" );
- if( p_sys->p_jack_client) jack_client_close( p_sys->p_jack_client );
- free( p_sys->pp_jack_port_input );
- if( p_sys->p_jack_ringbuffer ) jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
free( p_sys->pp_jack_buffer );
+ for( i = 0; i < p_sys->i_channels; i++ )
+ jack_port_unregister( p_sys->p_jack_client, p_sys->pp_jack_port_input[i] );
+ jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
+ free( p_sys->pp_jack_port_input );
+ jack_client_close( p_sys->p_jack_client );
free( p_sys );
return VLC_EGENERIC;
}
jack_port_name( p_sys->pp_jack_port_input[i_input_ports] ) );
}
}
- free( pp_jack_port_output );
+ free( pp_jack_port_output );
}
/* info about jack server */
p_sys->jack_sample_size = sizeof( jack_default_audio_sample_t );
/* Define output format */
- es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'f','l','3','2' ) );
+ es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_FL32 );
fmt.audio.i_channels = p_sys->i_channels;
fmt.audio.i_rate = p_sys->jack_sample_rate;
fmt.audio.i_bitspersample = p_sys->jack_sample_size * 8;
case DEMUX_GET_PTS_DELAY:
pi64 = ( int64_t* )va_arg( args, int64_t * );
- *pi64 = ( int64_t )var_GetInteger( p_demux, "jack-input-caching" )
- * 1000;
+ *pi64 = INT64_C(1000) * var_InheritInteger( p_demux, "live-caching" );
return VLC_SUCCESS;
case DEMUX_GET_TIME:
}
}
- return 1;
+ return 0;
}
if( i_read < 100 ) /* avoid small read */
{ /* vlc has too much free time on its hands? */
+#undef msleep
+#warning Hmm.... looks wrong
msleep(1000);
return NULL;
}
}
else
{
- p_block = block_New( p_demux, i_read );
+ p_block = block_Alloc( i_read );
}
if( !p_block )
{
pp_jack_port_output = jack_get_ports( p_sys->p_jack_client,
psz_uri, NULL, JackPortIsOutput );
if( pp_jack_port_output == NULL )
- {
msg_Err( p_demux, "port(s) asked not found:%s", psz_uri );
- free( pp_jack_port_output );
- }
else
{
- while( pp_jack_port_output && pp_jack_port_output[i_out_ports] )
- {
+ while( pp_jack_port_output[i_out_ports] )
i_out_ports++;
- }
/* alloc an array to store all the matched ports */
- p_sys->pp_jack_port_table = realloc( p_sys->pp_jack_port_table,
+ p_sys->pp_jack_port_table = xrealloc( p_sys->pp_jack_port_table,
(i_out_ports * sizeof( char * ) + i_total_out_ports * sizeof( char * ) ) );
for(int i=0; i<i_out_ports;i++)
- {
p_sys->pp_jack_port_table[i_total_out_ports+i] = ( char * ) pp_jack_port_output[i];
- }
i_total_out_ports += i_out_ports;
+
+ free( pp_jack_port_output );
}
}
- free( pp_jack_port_output );
p_sys->i_match_ports = i_total_out_ports;
}
static void Parse( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
- char *psz_dup = strdup( p_demux->psz_path );
+ char *psz_dup = strdup( p_demux->psz_location );
char *psz_parser = psz_dup;
if( !strncmp( psz_parser, "channels=", strlen( "channels=" ) ) )
}
}
}
+
+ free( psz_dup );
}