| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
#ifdef HAVE_CONFIG_H |
|---|
| 37 |
# include "config.h" |
|---|
| 38 |
#endif |
|---|
| 39 |
|
|---|
| 40 |
#include <vlc_common.h> |
|---|
| 41 |
#include <vlc_plugin.h> |
|---|
| 42 |
#include <vlc_input.h> |
|---|
| 43 |
#include <vlc_demux.h> |
|---|
| 44 |
#include <vlc_vout.h> |
|---|
| 45 |
#include <vlc_codecs.h> |
|---|
| 46 |
#include <vlc_url.h> |
|---|
| 47 |
#include <vlc_strings.h> |
|---|
| 48 |
|
|---|
| 49 |
#include <jack/jack.h> |
|---|
| 50 |
#include <jack/ringbuffer.h> |
|---|
| 51 |
|
|---|
| 52 |
#include <errno.h> |
|---|
| 53 |
#include <sys/types.h> |
|---|
| 54 |
#include <unistd.h> |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
static int Open ( vlc_object_t * ); |
|---|
| 60 |
static void Close( vlc_object_t * ); |
|---|
| 61 |
|
|---|
| 62 |
#define CACHING_TEXT N_("Caching value in ms") |
|---|
| 63 |
#define CACHING_LONGTEXT N_( \ |
|---|
| 64 |
"Make VLC buffer audio data captured from jack for the specified " \ |
|---|
| 65 |
"length in milliseconds." ) |
|---|
| 66 |
#define PACE_TEXT N_( "Pace" ) |
|---|
| 67 |
#define PACE_LONGTEXT N_( \ |
|---|
| 68 |
"Read the audio stream at VLC pace rather than Jack pace." ) |
|---|
| 69 |
#define AUTO_CONNECT_TEXT N_( "Auto Connection" ) |
|---|
| 70 |
#define AUTO_CONNECT_LONGTEXT N_( \ |
|---|
| 71 |
"Automatically connect VLC input ports to available output ports." ) |
|---|
| 72 |
|
|---|
| 73 |
vlc_module_begin(); |
|---|
| 74 |
set_description( N_("JACK audio input") ); |
|---|
| 75 |
set_capability( "access_demux", 0 ); |
|---|
| 76 |
set_shortname( N_( "JACK Input" ) ); |
|---|
| 77 |
set_category( CAT_INPUT ); |
|---|
| 78 |
set_subcategory( SUBCAT_INPUT_ACCESS ); |
|---|
| 79 |
|
|---|
| 80 |
add_integer( "jack-input-caching", DEFAULT_PTS_DELAY / 1000, NULL, |
|---|
| 81 |
CACHING_TEXT, CACHING_LONGTEXT, true ); |
|---|
| 82 |
add_bool( "jack-input-use-vlc-pace", false, NULL, |
|---|
| 83 |
PACE_TEXT, PACE_LONGTEXT, true ); |
|---|
| 84 |
add_bool( "jack-input-auto-connect", false, NULL, |
|---|
| 85 |
AUTO_CONNECT_TEXT, AUTO_CONNECT_LONGTEXT, true ); |
|---|
| 86 |
|
|---|
| 87 |
add_shortcut( "jack" ); |
|---|
| 88 |
set_callbacks( Open, Close ); |
|---|
| 89 |
vlc_module_end(); |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
struct demux_sys_t |
|---|
| 96 |
{ |
|---|
| 97 |
|
|---|
| 98 |
vlc_fourcc_t i_acodec_raw; |
|---|
| 99 |
unsigned int i_channels; |
|---|
| 100 |
int i_sample_rate; |
|---|
| 101 |
int i_audio_max_frame_size; |
|---|
| 102 |
int i_frequency; |
|---|
| 103 |
block_t *p_block_audio; |
|---|
| 104 |
es_out_id_t *p_es_audio; |
|---|
| 105 |
date_t pts; |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
jack_client_t *p_jack_client; |
|---|
| 109 |
jack_port_t **pp_jack_port_input; |
|---|
| 110 |
jack_default_audio_sample_t **pp_jack_buffer; |
|---|
| 111 |
jack_ringbuffer_t *p_jack_ringbuffer; |
|---|
| 112 |
jack_nframes_t jack_buffer_size; |
|---|
| 113 |
jack_nframes_t jack_sample_rate; |
|---|
| 114 |
size_t jack_sample_size; |
|---|
| 115 |
char *psz_ports; |
|---|
| 116 |
char **pp_jack_port_table; |
|---|
| 117 |
char i_match_ports; |
|---|
| 118 |
}; |
|---|
| 119 |
|
|---|
| 120 |
static int Demux( demux_t * ); |
|---|
| 121 |
static int Control( demux_t *p_demux, int i_query, va_list args ); |
|---|
| 122 |
|
|---|
| 123 |
static void Parse ( demux_t * ); |
|---|
| 124 |
static void Port_finder( demux_t * ); |
|---|
| 125 |
static int Process( jack_nframes_t i_frames, void *p_arg ); |
|---|
| 126 |
|
|---|
| 127 |
static block_t *GrabJack( demux_t * ); |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
static int Open( vlc_object_t *p_this ) |
|---|
| 133 |
{ |
|---|
| 134 |
unsigned int i; |
|---|
| 135 |
demux_t *p_demux = ( demux_t* )p_this; |
|---|
| 136 |
demux_sys_t *p_sys; |
|---|
| 137 |
es_format_t fmt; |
|---|
| 138 |
int i_out_ports = 0; |
|---|
| 139 |
|
|---|
| 140 |
p_demux->pf_demux = Demux; |
|---|
| 141 |
p_demux->pf_control = Control; |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) ); |
|---|
| 145 |
if( p_sys == NULL ) |
|---|
| 146 |
return VLC_ENOMEM; |
|---|
| 147 |
memset( p_sys, 0, sizeof( demux_sys_t ) ); |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
Parse( p_demux ); |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
var_Create( p_demux, "jack-input-caching", |
|---|
| 154 |
VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); |
|---|
| 155 |
var_Create( p_demux, "jack-input-use-vlc-pace", |
|---|
| 156 |
VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); |
|---|
| 157 |
var_Create( p_demux, "jack-input-auto-connect", |
|---|
| 158 |
VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
char p_vlc_client_name[32]; |
|---|
| 163 |
sprintf( p_vlc_client_name, "vlc-input-%d", getpid() ); |
|---|
| 164 |
p_sys->p_jack_client = jack_client_new( p_vlc_client_name ); |
|---|
| 165 |
if( p_sys->p_jack_client == NULL ) |
|---|
| 166 |
{ |
|---|
| 167 |
msg_Err( p_demux, "failed to connect to JACK server" ); |
|---|
| 168 |
free( p_sys ); |
|---|
| 169 |
return VLC_EGENERIC; |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
if( p_sys->psz_ports) |
|---|
| 174 |
{ |
|---|
| 175 |
Port_finder( p_demux ); |
|---|
| 176 |
if( p_sys->i_channels == 0 ) |
|---|
| 177 |
{ |
|---|
| 178 |
p_sys->i_channels = p_sys->i_match_ports; |
|---|
| 179 |
} |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
if( p_sys->i_channels == 0 ) p_sys->i_channels = 2 ; |
|---|
| 184 |
p_sys->pp_jack_port_input = malloc( |
|---|
| 185 |
p_sys->i_channels * sizeof( jack_port_t* ) ); |
|---|
| 186 |
if( p_sys->pp_jack_port_input == NULL ) |
|---|
| 187 |
{ |
|---|
| 188 |
jack_client_close( p_sys->p_jack_client ); |
|---|
| 189 |
free( p_sys ); |
|---|
| 190 |
return VLC_ENOMEM; |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
p_sys->p_jack_ringbuffer = jack_ringbuffer_create( p_sys->i_channels |
|---|
| 197 |
* jack_get_sample_rate( p_sys->p_jack_client ) |
|---|
| 198 |
* sizeof( jack_default_audio_sample_t ) ); |
|---|
| 199 |
if( p_sys->p_jack_ringbuffer == NULL ) |
|---|
| 200 |
{ |
|---|
| 201 |
free( p_sys->pp_jack_port_input ); |
|---|
| 202 |
jack_client_close( p_sys->p_jack_client ); |
|---|
| 203 |
free( p_sys ); |
|---|
| 204 |
return VLC_ENOMEM; |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
for( i = 0; i < p_sys->i_channels; i++ ) |
|---|
| 209 |
{ |
|---|
| 210 |
char p_input_name[32]; |
|---|
| 211 |
snprintf( p_input_name, 32, "vlc_in_%d", i+1 ); |
|---|
| 212 |
p_sys->pp_jack_port_input[i] = jack_port_register( |
|---|
| 213 |
p_sys->p_jack_client, p_input_name, JACK_DEFAULT_AUDIO_TYPE, |
|---|
| 214 |
JackPortIsInput, 0 ); |
|---|
| 215 |
if( p_sys->pp_jack_port_input[i] == NULL ) |
|---|
| 216 |
{ |
|---|
| 217 |
msg_Err( p_demux, "failed to register a JACK port" ); |
|---|
| 218 |
jack_ringbuffer_free( p_sys->p_jack_ringbuffer ); |
|---|
| 219 |
free( p_sys->pp_jack_port_input ); |
|---|
| 220 |
jack_client_close( p_sys->p_jack_client ); |
|---|
| 221 |
free( p_sys ); |
|---|
| 222 |
return VLC_EGENERIC; |
|---|
| 223 |
} |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
p_sys->pp_jack_buffer = malloc ( p_sys->i_channels |
|---|
| 228 |
* sizeof( jack_default_audio_sample_t * ) ); |
|---|
| 229 |
if( p_sys->pp_jack_buffer == NULL ) |
|---|
| 230 |
{ |
|---|
| 231 |
for( i = 0; i < p_sys->i_channels; i++ ) |
|---|
| 232 |
jack_port_unregister( p_sys->p_jack_client, p_sys->pp_jack_port_input[i] ); |
|---|
| 233 |
jack_ringbuffer_free( p_sys->p_jack_ringbuffer ); |
|---|
| 234 |
free( p_sys->pp_jack_port_input ); |
|---|
| 235 |
jack_client_close( p_sys->p_jack_client ); |
|---|
| 236 |
free( p_sys ); |
|---|
| 237 |
return VLC_ENOMEM; |
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
jack_set_process_callback( p_sys->p_jack_client, Process, p_demux ); |
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
if ( jack_activate( p_sys->p_jack_client ) ) |
|---|
| 245 |
{ |
|---|
| 246 |
msg_Err( p_demux, "failed to activate JACK client" ); |
|---|
| 247 |
free( p_sys->pp_jack_buffer ); |
|---|
| 248 |
for( i = 0; i < p_sys->i_channels; i++ ) |
|---|
| 249 |
jack_port_unregister( p_sys->p_jack_client, p_sys->pp_jack_port_input[i] ); |
|---|
| 250 |
jack_ringbuffer_free( p_sys->p_jack_ringbuffer ); |
|---|
| 251 |
free( p_sys->pp_jack_port_input ); |
|---|
| 252 |
jack_client_close( p_sys->p_jack_client ); |
|---|
| 253 |
free( p_sys ); |
|---|
| 254 |
return VLC_EGENERIC; |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
if( p_sys->psz_ports ) |
|---|
| 260 |
{ |
|---|
| 261 |
int i_input_ports; |
|---|
| 262 |
int j; |
|---|
| 263 |
|
|---|
| 264 |
if( p_sys->i_match_ports > 0 ) |
|---|
| 265 |
{ |
|---|
| 266 |
for( j = 0; j < p_sys->i_match_ports; j++ ) |
|---|
| 267 |
{ |
|---|
| 268 |
i_input_ports = j % p_sys->i_channels; |
|---|
| 269 |
jack_connect( p_sys->p_jack_client, p_sys->pp_jack_port_table[j], |
|---|
| 270 |
jack_port_name( p_sys->pp_jack_port_input[i_input_ports] ) ); |
|---|
| 271 |
} |
|---|
| 272 |
} |
|---|
| 273 |
} |
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
if( var_GetBool( p_demux, "jack-input-auto-connect" ) && !p_sys->psz_ports ) |
|---|
| 277 |
{ |
|---|
| 278 |
int i_input_ports; |
|---|
| 279 |
int j; |
|---|
| 280 |
const char **pp_jack_port_output; |
|---|
| 281 |
|
|---|
| 282 |
pp_jack_port_output = jack_get_ports( p_sys->p_jack_client, NULL, NULL, JackPortIsOutput ); |
|---|
| 283 |
|
|---|
| 284 |
while( pp_jack_port_output && pp_jack_port_output[i_out_ports] ) |
|---|
| 285 |
{ |
|---|
| 286 |
i_out_ports++; |
|---|
| 287 |
} |
|---|
| 288 |
if( i_out_ports > 0 ) |
|---|
| 289 |
{ |
|---|
| 290 |
for( j = 0; j < i_out_ports; j++ ) |
|---|
| 291 |
{ |
|---|
| 292 |
i_input_ports = j % p_sys->i_channels; |
|---|
| 293 |
jack_connect( p_sys->p_jack_client, pp_jack_port_output[j], |
|---|
| 294 |
jack_port_name( p_sys->pp_jack_port_input[i_input_ports] ) ); |
|---|
| 295 |
} |
|---|
| 296 |
} |
|---|
| 297 |
free( pp_jack_port_output ); |
|---|
| 298 |
} |
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
p_sys->jack_buffer_size = jack_get_buffer_size( p_sys->p_jack_client ); |
|---|
| 303 |
|
|---|
| 304 |
p_sys->jack_sample_rate = jack_get_sample_rate( p_sys->p_jack_client ); |
|---|
| 305 |
|
|---|
| 306 |
p_sys->jack_sample_size = sizeof( jack_default_audio_sample_t ); |
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'f','l','3','2' ) ); |
|---|
| 310 |
fmt.audio.i_channels = p_sys->i_channels; |
|---|
| 311 |
fmt.audio.i_rate = p_sys->jack_sample_rate; |
|---|
| 312 |
fmt.audio.i_bitspersample = p_sys->jack_sample_size * 8; |
|---|
| 313 |
fmt.audio.i_blockalign = fmt.audio.i_bitspersample / 8; |
|---|
| 314 |
fmt.i_bitrate = fmt.audio.i_rate * fmt.audio.i_bitspersample |
|---|
| 315 |
* fmt.audio.i_channels; |
|---|
| 316 |
|
|---|
| 317 |
p_sys->p_es_audio = es_out_Add( p_demux->out, &fmt ); |
|---|
| 318 |
date_Init( &p_sys->pts, fmt.audio.i_rate, 1 ); |
|---|
| 319 |
date_Set( &p_sys->pts, 1 ); |
|---|
| 320 |
|
|---|
| 321 |
return VLC_SUCCESS; |
|---|
| 322 |
} |
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
static void Close( vlc_object_t *p_this ) |
|---|
| 329 |
{ |
|---|
| 330 |
demux_t *p_demux = ( demux_t* )p_this; |
|---|
| 331 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 332 |
|
|---|
| 333 |
msg_Dbg( p_demux,"Module unloaded" ); |
|---|
| 334 |
if( p_sys->p_block_audio ) block_Release( p_sys->p_block_audio ); |
|---|
| 335 |
if( p_sys->p_jack_client ) jack_client_close( p_sys->p_jack_client ); |
|---|
| 336 |
if( p_sys->p_jack_ringbuffer ) jack_ringbuffer_free( p_sys->p_jack_ringbuffer ); |
|---|
| 337 |
free( p_sys->pp_jack_port_input ); |
|---|
| 338 |
free( p_sys->pp_jack_buffer ); |
|---|
| 339 |
free( p_sys->pp_jack_port_table ); |
|---|
| 340 |
free( p_sys ); |
|---|
| 341 |
} |
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
static int Control( demux_t *p_demux, int i_query, va_list args ) |
|---|
| 348 |
{ |
|---|
| 349 |
bool *pb; |
|---|
| 350 |
int64_t *pi64; |
|---|
| 351 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 352 |
|
|---|
| 353 |
switch( i_query ) |
|---|
| 354 |
{ |
|---|
| 355 |
|
|---|
| 356 |
case DEMUX_CAN_PAUSE: |
|---|
| 357 |
case DEMUX_CAN_SEEK: |
|---|
| 358 |
pb = (bool *)va_arg( args, bool * ); |
|---|
| 359 |
*pb = true; |
|---|
| 360 |
return VLC_SUCCESS; |
|---|
| 361 |
|
|---|
| 362 |
case DEMUX_SET_PAUSE_STATE: |
|---|
| 363 |
return VLC_SUCCESS; |
|---|
| 364 |
case DEMUX_CAN_CONTROL_PACE: |
|---|
| 365 |
pb = ( bool* )va_arg( args, bool * ); |
|---|
| 366 |
*pb = var_GetBool( p_demux, "jack-input-use-vlc-pace" ); |
|---|
| 367 |
return VLC_SUCCESS; |
|---|
| 368 |
|
|---|
| 369 |
case DEMUX_GET_PTS_DELAY: |
|---|
| 370 |
pi64 = ( int64_t* )va_arg( args, int64_t * ); |
|---|
| 371 |
*pi64 = ( int64_t )var_GetInteger( p_demux, "jack-input-caching" ) |
|---|
| 372 |
* 1000; |
|---|
| 373 |
return VLC_SUCCESS; |
|---|
| 374 |
|
|---|
| 375 |
case DEMUX_GET_TIME: |
|---|
| 376 |
pi64 = ( int64_t* )va_arg( args, int64_t * ); |
|---|
| 377 |
*pi64 = date_Get(&p_sys->pts); |
|---|
| 378 |
return VLC_SUCCESS; |
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
default: |
|---|
| 382 |
return VLC_EGENERIC; |
|---|
| 383 |
} |
|---|
| 384 |
|
|---|
| 385 |
return VLC_EGENERIC; |
|---|
| 386 |
} |
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
static int Demux( demux_t *p_demux ) |
|---|
| 393 |
{ |
|---|
| 394 |
|
|---|
| 395 |
demux_sys_t *p_sys; |
|---|
| 396 |
es_out_id_t *p_es; |
|---|
| 397 |
block_t *p_block; |
|---|
| 398 |
|
|---|
| 399 |
p_sys = p_demux->p_sys; |
|---|
| 400 |
p_es = p_sys->p_es_audio; |
|---|
| 401 |
p_block = GrabJack( p_demux ); |
|---|
| 402 |
|
|---|
| 403 |
if( p_block ) |
|---|
| 404 |
{ |
|---|
| 405 |
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts ); |
|---|
| 406 |
es_out_Send( p_demux->out, p_es, p_block ); |
|---|
| 407 |
} |
|---|
| 408 |
|
|---|
| 409 |
return 1; |
|---|
| 410 |
} |
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
int Process( jack_nframes_t i_frames, void *p_arg ) |
|---|
| 417 |
{ |
|---|
| 418 |
demux_t *p_demux = ( demux_t* )p_arg; |
|---|
| 419 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 420 |
unsigned int i, j; |
|---|
| 421 |
size_t i_write; |
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
for ( i = 0; i < p_sys->i_channels ; i++ ) |
|---|
| 425 |
{ |
|---|
| 426 |
p_sys->pp_jack_buffer[i] = jack_port_get_buffer( |
|---|
| 427 |
p_sys->pp_jack_port_input[i], i_frames ); |
|---|
| 428 |
} |
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
for( j = 0; j < i_frames; j++ ) |
|---|
| 432 |
{ |
|---|
| 433 |
for( i = 0; i <p_sys->i_channels; i++ ) |
|---|
| 434 |
{ |
|---|
| 435 |
if( jack_ringbuffer_write_space( p_sys->p_jack_ringbuffer ) < |
|---|
| 436 |
p_sys->jack_sample_size ) { |
|---|
| 437 |
msg_Err( p_demux, "buffer overflow"); |
|---|
| 438 |
return 0; |
|---|
| 439 |
} |
|---|
| 440 |
i_write = jack_ringbuffer_write( p_sys->p_jack_ringbuffer, |
|---|
| 441 |
( char * ) (p_sys->pp_jack_buffer[i]+j), |
|---|
| 442 |
p_sys->jack_sample_size ); |
|---|
| 443 |
if (i_write != p_sys->jack_sample_size ) { |
|---|
| 444 |
msg_Warn( p_demux, "error writing on ring buffer"); |
|---|
| 445 |
} |
|---|
| 446 |
} |
|---|
| 447 |
} |
|---|
| 448 |
|
|---|
| 449 |
return 1; |
|---|
| 450 |
} |
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
static block_t *GrabJack( demux_t *p_demux ) |
|---|
| 457 |
{ |
|---|
| 458 |
size_t i_read; |
|---|
| 459 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 460 |
block_t *p_block; |
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
i_read = jack_ringbuffer_read_space( p_sys->p_jack_ringbuffer ); |
|---|
| 464 |
|
|---|
| 465 |
if( i_read < 100 ) |
|---|
| 466 |
{ |
|---|
| 467 |
msleep(1000); |
|---|
| 468 |
return NULL; |
|---|
| 469 |
} |
|---|
| 470 |
|
|---|
| 471 |
if( p_sys->p_block_audio ) |
|---|
| 472 |
{ |
|---|
| 473 |
p_block = p_sys->p_block_audio; |
|---|
| 474 |
} |
|---|
| 475 |
else |
|---|
| 476 |
{ |
|---|
| 477 |
p_block = block_New( p_demux, i_read ); |
|---|
| 478 |
} |
|---|
| 479 |
if( !p_block ) |
|---|
| 480 |
{ |
|---|
| 481 |
msg_Warn( p_demux, "cannot get block" ); |
|---|
| 482 |
return 0; |
|---|
| 483 |
} |
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
i_read >>= 1; |
|---|
| 487 |
i_read--; |
|---|
| 488 |
i_read |= i_read >> 1; |
|---|
| 489 |
i_read |= i_read >> 2; |
|---|
| 490 |
i_read |= i_read >> 4; |
|---|
| 491 |
i_read |= i_read >> 8; |
|---|
| 492 |
i_read |= i_read >> 16; |
|---|
| 493 |
i_read++; |
|---|
| 494 |
|
|---|
| 495 |
i_read = jack_ringbuffer_read( p_sys->p_jack_ringbuffer, ( char * ) p_block->p_buffer, i_read ); |
|---|
| 496 |
|
|---|
| 497 |
p_block->i_dts = p_block->i_pts = date_Increment( &p_sys->pts, |
|---|
| 498 |
i_read/(p_sys->i_channels * p_sys->jack_sample_size) ); |
|---|
| 499 |
|
|---|
| 500 |
p_sys->p_block_audio = p_block; |
|---|
| 501 |
p_block->i_buffer = i_read; |
|---|
| 502 |
p_sys->p_block_audio = 0; |
|---|
| 503 |
|
|---|
| 504 |
return p_block; |
|---|
| 505 |
} |
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
static void Port_finder( demux_t *p_demux ) |
|---|
| 512 |
{ |
|---|
| 513 |
|
|---|
| 514 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 515 |
char *psz_expr = p_sys->psz_ports; |
|---|
| 516 |
char *token = NULL; |
|---|
| 517 |
char *state = NULL; |
|---|
| 518 |
char *psz_uri = NULL; |
|---|
| 519 |
const char **pp_jack_port_output = NULL; |
|---|
| 520 |
int i_out_ports = 0; |
|---|
| 521 |
int i_total_out_ports =0; |
|---|
| 522 |
p_sys->pp_jack_port_table = NULL; |
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
for( token = strtok_r( psz_expr, ",", &state ); token; |
|---|
| 526 |
token = strtok_r( NULL, ",", &state ) ) |
|---|
| 527 |
{ |
|---|
| 528 |
psz_uri = decode_URI_duplicate( token ); |
|---|
| 529 |
|
|---|
| 530 |
pp_jack_port_output = jack_get_ports( p_sys->p_jack_client, |
|---|
| 531 |
psz_uri, NULL, JackPortIsOutput ); |
|---|
| 532 |
if( pp_jack_port_output == NULL ) |
|---|
| 533 |
{ |
|---|
| 534 |
msg_Err( p_demux, "port(s) asked not found:%s", psz_uri ); |
|---|
| 535 |
free( pp_jack_port_output ); |
|---|
| 536 |
} |
|---|
| 537 |
else |
|---|
| 538 |
{ |
|---|
| 539 |
while( pp_jack_port_output && pp_jack_port_output[i_out_ports] ) |
|---|
| 540 |
{ |
|---|
| 541 |
i_out_ports++; |
|---|
| 542 |
} |
|---|
| 543 |
|
|---|
| 544 |
p_sys->pp_jack_port_table = realloc( p_sys->pp_jack_port_table, |
|---|
| 545 |
(i_out_ports * sizeof( char * ) + i_total_out_ports * sizeof( char * ) ) ); |
|---|
| 546 |
|
|---|
| 547 |
for(int i=0; i<i_out_ports;i++) |
|---|
| 548 |
{ |
|---|
| 549 |
p_sys->pp_jack_port_table[i_total_out_ports+i] = ( char * ) pp_jack_port_output[i]; |
|---|
| 550 |
} |
|---|
| 551 |
|
|---|
| 552 |
i_total_out_ports += i_out_ports; |
|---|
| 553 |
} |
|---|
| 554 |
} |
|---|
| 555 |
|
|---|
| 556 |
free( pp_jack_port_output ); |
|---|
| 557 |
p_sys->i_match_ports = i_total_out_ports; |
|---|
| 558 |
} |
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
|
|---|
| 563 |
|
|---|
| 564 |
static void Parse( demux_t *p_demux ) |
|---|
| 565 |
{ |
|---|
| 566 |
demux_sys_t *p_sys = p_demux->p_sys; |
|---|
| 567 |
char *psz_dup = strdup( p_demux->psz_path ); |
|---|
| 568 |
char *psz_parser = psz_dup; |
|---|
| 569 |
|
|---|
| 570 |
if( !strncmp( psz_parser, "channels=", strlen( "channels=" ) ) ) |
|---|
| 571 |
{ |
|---|
| 572 |
p_sys->i_channels = abs( strtol( psz_parser + strlen( "channels=" ), |
|---|
| 573 |
&psz_parser, 0 ) ); |
|---|
| 574 |
} |
|---|
| 575 |
else if( !strncmp( psz_parser, "ports=", strlen( "ports=" ) ) ) |
|---|
| 576 |
{ |
|---|
| 577 |
int i_len; |
|---|
| 578 |
psz_parser += strlen( "ports=" ); |
|---|
| 579 |
if( strchr( psz_parser, ':' ) ) |
|---|
| 580 |
{ |
|---|
| 581 |
i_len = strchr( psz_parser, ':' ) - psz_parser; |
|---|
| 582 |
} |
|---|
| 583 |
else |
|---|
| 584 |
{ |
|---|
| 585 |
i_len = strlen( psz_parser ); |
|---|
| 586 |
} |
|---|
| 587 |
p_sys->psz_ports = strndup( psz_parser, i_len ); |
|---|
| 588 |
psz_parser += i_len; |
|---|
| 589 |
} |
|---|
| 590 |
else |
|---|
| 591 |
{ |
|---|
| 592 |
msg_Warn( p_demux, "unknown option" ); |
|---|
| 593 |
} |
|---|
| 594 |
|
|---|
| 595 |
while( *psz_parser && *psz_parser != ':' ) |
|---|
| 596 |
{ |
|---|
| 597 |
psz_parser++; |
|---|
| 598 |
} |
|---|
| 599 |
|
|---|
| 600 |
if( *psz_parser == ':' ) |
|---|
| 601 |
{ |
|---|
| 602 |
for( ;; ) |
|---|
| 603 |
{ |
|---|
| 604 |
*psz_parser++ = '\0'; |
|---|
| 605 |
if( !strncmp( psz_parser, "channels=", strlen( "channels=" ) ) ) |
|---|
| 606 |
{ |
|---|
| 607 |
p_sys->i_channels = abs( strtol( |
|---|
| 608 |
psz_parser + strlen( "channels=" ), &psz_parser, 0 ) ); |
|---|
| 609 |
} |
|---|
| 610 |
else if( !strncmp( psz_parser, "ports=", strlen( "ports=" ) ) ) |
|---|
| 611 |
{ |
|---|
| 612 |
int i_len; |
|---|
| 613 |
psz_parser += strlen( "ports=" ); |
|---|
| 614 |
if( strchr( psz_parser, ':' ) ) |
|---|
| 615 |
{ |
|---|
| 616 |
i_len = strchr( psz_parser, ':' ) - psz_parser; |
|---|
| 617 |
} |
|---|
| 618 |
else |
|---|
| 619 |
{ |
|---|
| 620 |
i_len = strlen( psz_parser ); |
|---|
| 621 |
} |
|---|
| 622 |
p_sys->psz_ports = strndup( psz_parser, i_len ); |
|---|
| 623 |
psz_parser += i_len; |
|---|
| 624 |
} |
|---|
| 625 |
else |
|---|
| 626 |
{ |
|---|
| 627 |
msg_Warn( p_demux, "unknown option" ); |
|---|
| 628 |
} |
|---|
| 629 |
while( *psz_parser && *psz_parser != ':' ) |
|---|
| 630 |
{ |
|---|
| 631 |
psz_parser++; |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
if( *psz_parser == '\0' ) |
|---|
| 635 |
{ |
|---|
| 636 |
break; |
|---|
| 637 |
} |
|---|
| 638 |
} |
|---|
| 639 |
} |
|---|
| 640 |
} |
|---|
| 641 |
|
|---|