1 /*****************************************************************************
2 * input.c: input thread
3 *****************************************************************************
4 * Copyright (C) 1998-2004 VideoLAN
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc/input.h>
33 #include <vlc/decoder.h>
36 #include "input_internal.h"
38 #include "stream_output.h"
39 #include "vlc_playlist.h"
40 #include "vlc_interface.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static int Run ( input_thread_t *p_input );
47 static int Init ( input_thread_t *p_input, vlc_bool_t b_quick );
48 static void Error( input_thread_t *p_input );
49 static void End ( input_thread_t *p_input );
51 static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t * );
52 static void ControlReduce( input_thread_t * );
53 static vlc_bool_t Control( input_thread_t *, int, vlc_value_t );
56 static int UpdateFromAccess( input_thread_t * );
57 static int UpdateFromDemux( input_thread_t * );
58 static int UpdateMeta( input_thread_t *, vlc_bool_t );
60 static void UpdateItemLength( input_thread_t *, int64_t i_length, vlc_bool_t );
62 static void ParseOption( input_thread_t *p_input, const char *psz_option );
64 static void DecodeUrl( char * );
65 static void MRLSplit( input_thread_t *, char *, char **, char **, char ** );
66 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
68 static input_source_t *InputSourceNew( input_thread_t *);
69 static int InputSourceInit( input_thread_t *, input_source_t *,
70 char *, char *psz_forced_demux,
72 static void InputSourceClean( input_thread_t *, input_source_t * );
74 static void SlaveDemux( input_thread_t *p_input );
75 static void SlaveSeek( input_thread_t *p_input );
77 static vlc_meta_t *InputMetaUser( input_thread_t *p_input );
79 /*****************************************************************************
80 * input_CreateThread: creates a new input thread
81 *****************************************************************************
82 * This function creates a new input, and returns a pointer
83 * to its description. On error, it returns NULL.
85 * Variables for _public_ use:
88 * - rate,rate-slower, rate-faster
89 * - position, position-offset
91 * - title,title-next,title-prev
92 * - chapter,chapter-next, chapter-prev
93 * - program, audio-es, video-es, spu-es
94 * - audio-delay, spu-delay
99 * - seekable (if you can seek, it doesn't say if 'bar display' has be shown or not, for that check position != 0.0)
100 * * For intf callback upon changes
102 * TODO explain when Callback is called
103 * TODO complete this list (?)
104 *****************************************************************************/
105 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
106 input_item_t *p_item )
109 input_thread_t *p_input; /* thread descriptor */
113 /* Allocate descriptor */
114 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
115 if( p_input == NULL )
117 msg_Err( p_parent, "out of memory" );
121 /* Init Common fields */
122 p_input->b_eof = VLC_FALSE;
123 p_input->b_can_pace_control = VLC_TRUE;
124 p_input->i_start = 0;
127 p_input->i_title = 0;
128 p_input->title = NULL;
129 p_input->i_title_offset = p_input->i_seekpoint_offset = 0;
130 p_input->i_state = INIT_S;
131 p_input->i_rate = INPUT_RATE_DEFAULT;
132 p_input->i_bookmark = 0;
133 p_input->bookmark = NULL;
134 p_input->p_meta = NULL;
135 p_input->p_es_out = NULL;
136 p_input->p_sout = NULL;
137 p_input->b_out_pace_control = VLC_FALSE;
138 p_input->i_pts_delay = 0;
140 /* Init Input fields */
141 p_input->input.p_item = p_item;
142 p_input->input.p_access = NULL;
143 p_input->input.p_stream = NULL;
144 p_input->input.p_demux = NULL;
145 p_input->input.b_title_demux = VLC_FALSE;
146 p_input->input.i_title = 0;
147 p_input->input.title = NULL;
148 p_input->input.i_title_offset = p_input->input.i_seekpoint_offset = 0;
149 p_input->input.b_can_pace_control = VLC_TRUE;
150 p_input->input.b_eof = VLC_FALSE;
151 p_input->input.i_cr_average = 0;
154 p_input->i_slave = 0;
155 p_input->slave = NULL;
157 /* Init control buffer */
158 vlc_mutex_init( p_input, &p_input->lock_control );
159 p_input->i_control = 0;
161 /* Parse input options */
162 vlc_mutex_lock( &p_item->lock );
163 for( i = 0; i < p_item->i_options; i++ )
165 ParseOption( p_input, p_item->ppsz_options[i] );
167 vlc_mutex_unlock( &p_item->lock );
169 /* Create Object Variables for private use only */
170 input_ConfigVarInit( p_input );
172 /* Create Objects variables for public Get and Set */
173 input_ControlVarInit( p_input );
174 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
177 var_Get( p_input, "bookmarks", &val );
180 /* FIXME: have a common cfg parsing routine used by sout and others */
181 char *psz_parser, *psz_start, *psz_end;
182 psz_parser = val.psz_string;
183 while( (psz_start = strchr( psz_parser, '{' ) ) )
185 seekpoint_t *p_seekpoint = vlc_seekpoint_New();
188 psz_end = strchr( psz_start, '}' );
189 if( !psz_end ) break;
190 psz_parser = psz_end + 1;
191 backup = *psz_parser;
195 while( (psz_end = strchr( psz_start, ',' ) ) )
198 if( !strncmp( psz_start, "name=", 5 ) )
200 p_seekpoint->psz_name = psz_start + 5;
202 else if( !strncmp( psz_start, "bytes=", 6 ) )
204 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
206 else if( !strncmp( psz_start, "time=", 5 ) )
208 p_seekpoint->i_time_offset = atoll(psz_start + 5) * 1000000;
210 psz_start = psz_end + 1;
212 msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
213 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
214 p_seekpoint->i_time_offset );
215 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
216 vlc_seekpoint_Delete( p_seekpoint );
217 *psz_parser = backup;
219 free( val.psz_string );
222 /* Now we can attach our new input */
223 vlc_object_attach( p_input, p_parent );
225 /* Create thread and wait for its readiness. */
226 if( vlc_thread_create( p_input, "input", Run,
227 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
229 msg_Err( p_input, "cannot create input thread" );
230 vlc_object_detach( p_input );
231 vlc_object_destroy( p_input );
238 /*****************************************************************************
239 * input_PreParse: Lightweight input for playlist item preparsing
240 *****************************************************************************/
241 int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
243 input_thread_t *p_input; /* thread descriptor */
246 /* Allocate descriptor */
247 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
248 if( p_input == NULL )
250 msg_Err( p_parent, "out of memory" );
254 /* Init Common fields */
255 p_input->b_eof = VLC_FALSE;
256 p_input->b_can_pace_control = VLC_TRUE;
257 p_input->i_start = 0;
260 p_input->i_title = 0;
261 p_input->title = NULL;
262 p_input->i_title_offset = p_input->i_seekpoint_offset = 0;
263 p_input->i_state = INIT_S;
264 p_input->i_rate = INPUT_RATE_DEFAULT;
265 p_input->i_bookmark = 0;
266 p_input->bookmark = NULL;
267 p_input->p_meta = NULL;
268 p_input->p_es_out = NULL;
269 p_input->p_sout = NULL;
270 p_input->b_out_pace_control = VLC_FALSE;
271 p_input->i_pts_delay = 0;
273 /* Init Input fields */
274 p_input->input.p_item = p_item;
275 p_input->input.p_access = NULL;
276 p_input->input.p_stream = NULL;
277 p_input->input.p_demux = NULL;
278 p_input->input.b_title_demux = VLC_FALSE;
279 p_input->input.i_title = 0;
280 p_input->input.title = NULL;
281 p_input->input.i_title_offset = p_input->input.i_seekpoint_offset = 0;
282 p_input->input.b_can_pace_control = VLC_TRUE;
283 p_input->input.b_eof = VLC_FALSE;
284 p_input->input.i_cr_average = 0;
287 p_input->i_slave = 0;
288 p_input->slave = NULL;
290 /* Init control buffer */
291 vlc_mutex_init( p_input, &p_input->lock_control );
292 p_input->i_control = 0;
294 /* Parse input options */
295 vlc_mutex_lock( &p_item->lock );
296 for( i = 0; i < p_item->i_options; i++ )
298 ParseOption( p_input, p_item->ppsz_options[i] );
300 vlc_mutex_unlock( &p_item->lock );
302 /* Create Object Variables for private use only */
303 input_ConfigVarInit( p_input );
304 input_ControlVarInit( p_input );
306 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
308 /* Now we can attach our new input */
309 vlc_object_attach( p_input, p_parent );
311 Init( p_input, VLC_TRUE );
313 /* Clean up master */
314 InputSourceClean( p_input, &p_input->input );
316 /* Kill access and demux */
317 if( p_input->input.p_access ) p_input->input.p_access->b_die = VLC_TRUE;
318 if( p_input->input.p_demux ) p_input->input.p_access->b_die = VLC_TRUE;
320 /* Unload all modules */
321 if( p_input->p_es_out ) input_EsOutDelete( p_input->p_es_out );
324 if( p_input->p_meta ) vlc_meta_Delete( p_input->p_meta );
326 vlc_object_detach( p_input );
327 vlc_object_destroy( p_input );
332 /*****************************************************************************
333 * input_StopThread: mark an input thread as zombie
334 *****************************************************************************
335 * This function should not return until the thread is effectively cancelled.
336 *****************************************************************************/
337 void input_StopThread( input_thread_t *p_input )
342 /* Set die for input */
343 p_input->b_die = VLC_TRUE;
345 /* We cannot touch p_input fields directly (we can from another thread),
346 * so use the vlc_object_find way, it's perfectly safe */
348 /* Set die for all access */
349 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );
350 for( i = 0; i < p_list->i_count; i++ )
352 p_list->p_values[i].p_object->b_die = VLC_TRUE;
354 vlc_list_release( p_list );
356 /* Set die for all stream */
357 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
358 for( i = 0; i < p_list->i_count; i++ )
360 p_list->p_values[i].p_object->b_die = VLC_TRUE;
362 vlc_list_release( p_list );
364 /* Set die for all demux */
365 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
366 for( i = 0; i < p_list->i_count; i++ )
368 p_list->p_values[i].p_object->b_die = VLC_TRUE;
370 vlc_list_release( p_list );
372 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
375 /*****************************************************************************
376 * input_DestroyThread: mark an input thread as zombie
377 *****************************************************************************
378 * This function should not return until the thread is effectively cancelled.
379 *****************************************************************************/
380 void input_DestroyThread( input_thread_t *p_input )
382 /* Join the thread */
383 vlc_thread_join( p_input );
385 /* Delete input lock (only after thread joined) */
386 vlc_mutex_destroy( &p_input->lock_control );
388 /* TODO: maybe input_DestroyThread should also delete p_input instead
389 * of the playlist but I'm not sure if it's possible */
392 /*****************************************************************************
393 * Run: main thread loop
394 *****************************************************************************
395 * Thread in charge of processing the network packets and demultiplexing.
398 * read subtitle support (XXX take care of spu-delay in the right way).
399 * multi-input support (XXX may be done with subs)
400 *****************************************************************************/
401 static int Run( input_thread_t *p_input )
403 int64_t i_intf_update = 0;
405 /* Signal that the thread is launched */
406 vlc_thread_ready( p_input );
408 if( Init( p_input, VLC_FALSE ) )
410 /* If we failed, wait before we are killed, and exit */
411 p_input->b_error = VLC_TRUE;
415 /* Tell we're dead */
416 p_input->b_dead = VLC_TRUE;
422 while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
424 vlc_bool_t b_force_update = VLC_FALSE;
430 if( p_input->i_state != PAUSE_S )
432 if( p_input->i_stop <= 0 || p_input->i_time < p_input->i_stop )
433 i_ret=p_input->input.p_demux->pf_demux(p_input->input.p_demux);
440 if( p_input->input.b_title_demux &&
441 p_input->input.p_demux->info.i_update )
443 i_ret = UpdateFromDemux( p_input );
444 b_force_update = VLC_TRUE;
446 else if( !p_input->input.b_title_demux &&
447 p_input->input.p_access &&
448 p_input->input.p_access->info.i_update )
450 i_ret = UpdateFromAccess( p_input );
451 b_force_update = VLC_TRUE;
455 if( i_ret == 0 ) /* EOF */
459 var_Get( p_input, "input-repeat", &repeat );
460 if( repeat.i_int == 0 )
462 /* End of file - we do not set b_die because only the
463 * playlist is allowed to do so. */
464 msg_Dbg( p_input, "EOF reached" );
465 p_input->input.b_eof = VLC_TRUE;
469 msg_Dbg( p_input, "repeating the same input (%d)",
471 if( repeat.i_int > 0 )
474 var_Set( p_input, "input-repeat", repeat );
477 /* Seek to start title/seekpoint */
478 val.i_int = p_input->input.i_title_start -
479 p_input->input.i_title_offset;
480 if( val.i_int < 0 || val.i_int >= p_input->input.i_title )
482 input_ControlPush( p_input,
483 INPUT_CONTROL_SET_TITLE, &val );
485 val.i_int = p_input->input.i_seekpoint_start -
486 p_input->input.i_seekpoint_offset;
487 if( val.i_int > 0 /* TODO: check upper boundary */ )
488 input_ControlPush( p_input,
489 INPUT_CONTROL_SET_SEEKPOINT, &val );
491 /* Seek to start position */
492 if( p_input->i_start > 0 )
494 val.i_time = p_input->i_start;
495 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
501 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
508 p_input->b_error = VLC_TRUE;
511 if( i_ret > 0 && p_input->i_slave > 0 )
513 SlaveDemux( p_input );
523 vlc_mutex_lock( &p_input->lock_control );
524 ControlReduce( p_input );
525 while( !ControlPopNoLock( p_input, &i_type, &val ) )
527 msg_Dbg( p_input, "control type=%d", i_type );
528 if( Control( p_input, i_type, val ) )
529 b_force_update = VLC_TRUE;
531 vlc_mutex_unlock( &p_input->lock_control );
533 if( b_force_update || i_intf_update < mdate() )
537 int64_t i_time, i_length;
538 /* update input status variables */
539 if( !demux2_Control( p_input->input.p_demux,
540 DEMUX_GET_POSITION, &f_pos ) )
542 val.f_float = (float)f_pos;
543 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
545 if( !demux2_Control( p_input->input.p_demux,
546 DEMUX_GET_TIME, &i_time ) )
548 p_input->i_time = i_time;
550 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
552 if( !demux2_Control( p_input->input.p_demux,
553 DEMUX_GET_LENGTH, &i_length ) )
556 var_Get( p_input, "length", &old_val );
557 val.i_time = i_length;
558 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
560 if( old_val.i_time != val.i_time )
562 UpdateItemLength( p_input, i_length, VLC_TRUE );
566 var_SetBool( p_input, "intf-change", VLC_TRUE );
567 i_intf_update = mdate() + I64C(150000);
571 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
573 /* We have finish to demux data but not to play them */
574 while( !p_input->b_die )
576 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
579 msg_Dbg( p_input, "waiting decoder fifos to empty" );
581 msleep( INPUT_IDLE_SLEEP );
584 /* We have finished */
585 p_input->b_eof = VLC_TRUE;
588 /* Wait we are asked to die */
589 if( !p_input->b_die )
601 static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
607 vlc_meta_t *p_meta, *p_meta_tmp;
611 /* Initialize optional stream output. (before access/demuxer) */
614 psz = var_GetString( p_input, "sout" );
617 p_input->p_sout = sout_NewInstance( p_input, psz );
618 if( p_input->p_sout == NULL )
620 msg_Err( p_input, "cannot start stream output instance, " \
630 p_input->p_es_out = input_EsOutNew( p_input );
631 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
632 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
634 if( InputSourceInit( p_input, &p_input->input,
635 p_input->input.p_item->psz_uri, NULL, b_quick ) )
640 /* Create global title (from master) */
643 p_input->i_title = p_input->input.i_title;
644 p_input->title = p_input->input.title;
645 p_input->i_title_offset = p_input->input.i_title_offset;
646 p_input->i_seekpoint_offset = p_input->input.i_seekpoint_offset;
647 if( p_input->i_title > 0 )
649 /* Setup variables */
650 input_ControlVarNavigation( p_input );
651 input_ControlVarTitle( p_input, 0 );
655 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
656 p_input->b_can_pause = p_input->input.b_can_pause;
659 if( p_input->i_pts_delay <= 0 )
660 p_input->i_pts_delay = DEFAULT_PTS_DELAY;
662 /* If the desynchronisation requested by the user is < 0, we need to
663 * cache more data. */
664 var_Get( p_input, "audio-desync", &val );
665 if( val.i_int < 0 ) p_input->i_pts_delay -= (val.i_int * 1000);
667 /* Update cr_average depending on the caching */
668 p_input->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000);
669 p_input->input.i_cr_average /= 10;
670 if( p_input->input.i_cr_average <= 0 ) p_input->input.i_cr_average = 1;
673 /* Load master infos */
675 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH,
676 &val.i_time ) && val.i_time > 0 )
678 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
679 UpdateItemLength( p_input, val.i_time, b_quick );
680 p_input->input.p_item->i_duration = val.i_time;
683 /* Start title/chapter */
686 val.i_int = p_input->input.i_title_start -
687 p_input->input.i_title_offset;
688 if( val.i_int > 0 && val.i_int < p_input->input.i_title )
689 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
690 val.i_int = p_input->input.i_seekpoint_start -
691 p_input->input.i_seekpoint_offset;
692 if( val.i_int > 0 /* TODO: check upper boundary */ )
693 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
697 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
699 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
702 if( p_input->i_start > 0 )
704 if( p_input->i_start >= val.i_time )
706 msg_Warn( p_input, "invalid start-time ignored" );
712 msg_Dbg( p_input, "starting at time: %ds",
713 (int)( p_input->i_start / I64C(1000000) ) );
715 s.i_time = p_input->i_start;
716 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
719 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
721 msg_Warn( p_input, "invalid stop-time ignored" );
727 /* Get fps and set it if not already set */
728 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
731 float f_requested_fps;
733 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
734 var_SetFloat( p_input, "sub-original-fps", f_fps );
736 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
737 if( f_requested_fps != f_fps )
739 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
741 var_SetFloat( p_input, "sub-fps", f_requested_fps );
745 i_delay = var_CreateGetInteger( p_input, "sub-delay" );
748 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
752 /* Look for and add subtitle files */
753 psz_subtitle = var_GetString( p_input, "sub-file" );
760 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
762 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
765 sub = InputSourceNew( p_input );
766 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle",
769 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
772 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list,
775 if( count.i_int == 0 )
777 /* if it was first one, there is disable too */
779 if( count.i_int < list.p_list->i_count )
781 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
782 &list.p_list->p_values[count.i_int] );
784 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list,
790 var_Get( p_input, "sub-autodetect-file", &val );
793 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
794 char **subs = subtitles_Detect( p_input, psz_autopath,
795 p_input->input.p_item->psz_uri );
798 for( i = 0; subs[i] != NULL; i++ )
800 if( strcmp( psz_subtitle, subs[i] ) )
802 sub = InputSourceNew( p_input );
803 if( !InputSourceInit( p_input, sub, subs[i], "subtitle",
806 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
812 free( psz_autopath );
814 free( psz_subtitle );
817 psz = var_GetString( p_input, "input-slave" );
821 input_source_t *slave;
824 while( *psz == ' ' || *psz == '#' )
828 if( ( psz_delim = strchr( psz, '#' ) ) )
837 msg_Dbg( p_input, "adding slave input '%s'", psz );
838 slave = InputSourceNew( p_input );
839 if( !InputSourceInit( p_input, slave, psz, NULL, VLC_FALSE ) )
841 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
846 if( psz ) free( psz );
850 p_input->i_start = 0;
851 p_input->i_start = 0;
857 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
858 i_es_out_mode = ES_OUT_MODE_AUTO;
860 if( p_input->p_sout )
862 var_Get( p_input, "sout-all", &val );
865 i_es_out_mode = ES_OUT_MODE_ALL;
870 var_Get( p_input, "programs", &val );
871 if ( val.p_list && val.p_list->i_count )
873 i_es_out_mode = ES_OUT_MODE_PARTIAL;
874 /* Note : we should remove the "program" callback. */
877 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
881 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
883 /* Inform the demuxer about waited group (needed only for DVB) */
884 if( i_es_out_mode == ES_OUT_MODE_ALL )
886 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
888 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
890 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1,
895 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP,
896 (int) var_GetInteger( p_input, "program" ), NULL );
899 if( p_input->p_sout )
901 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
903 p_input->b_out_pace_control = VLC_FALSE;
907 p_input->b_out_pace_control = VLC_TRUE;
909 msg_Dbg( p_input, "starting in %s mode",
910 p_input->b_out_pace_control ? "asynch" : "synch" );
914 /* Get meta data from users */
915 p_meta_tmp = InputMetaUser( p_input );
917 /* Get meta data from master input */
918 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_META, &p_meta ) )
926 else if( p_meta_tmp )
928 vlc_meta_Merge( p_meta, p_meta_tmp );
929 vlc_meta_Delete( p_meta_tmp );
932 /* Access_file does not give any meta, and there are no slave */
935 if( !p_input->input.p_access ||
936 access2_Control( p_input->input.p_access, ACCESS_GET_META,
944 else if( p_meta_tmp )
946 vlc_meta_Merge( p_meta, p_meta_tmp );
947 vlc_meta_Delete( p_meta_tmp );
950 /* Get meta data from slave input */
951 for( i = 0; i < p_input->i_slave; i++ )
953 vlc_meta_t *p_meta_slave;
955 if( !demux2_Control( p_input->slave[i]->p_demux,
956 DEMUX_GET_META, &p_meta_slave ) )
960 p_meta = p_meta_slave;
962 else if( p_meta_slave )
964 vlc_meta_Merge( p_meta, p_meta_slave );
965 vlc_meta_Delete( p_meta_slave );
969 if( p_input->slave[i]->p_access &&
970 !access2_Control( p_input->slave[i]->p_access,
971 ACCESS_GET_META, &p_meta_slave ) )
975 p_meta = p_meta_slave;
977 else if( p_meta_slave )
979 vlc_meta_Merge( p_meta, p_meta_slave );
980 vlc_meta_Delete( p_meta_slave );
986 p_input->p_meta = p_meta;
987 UpdateMeta( p_input, b_quick );
991 msg_Dbg( p_input, "`%s' sucessfully opened",
992 p_input->input.p_item->psz_uri );
996 /* Trigger intf update for this item */
997 /* Playlist has a callback on this variable and will forward
999 var_SetInteger( p_input, "item-change", p_input->input.p_item->i_id );
1001 /* initialization is complete */
1002 p_input->i_state = PLAYING_S;
1004 val.i_int = PLAYING_S;
1005 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1010 if( p_input->p_es_out )
1011 input_EsOutDelete( p_input->p_es_out );
1013 if( p_input->p_sout )
1014 sout_DeleteInstance( p_input->p_sout );
1016 /* Mark them deleted */
1017 p_input->input.p_demux = NULL;
1018 p_input->input.p_stream = NULL;
1019 p_input->input.p_access = NULL;
1020 p_input->p_es_out = NULL;
1021 p_input->p_sout = NULL;
1023 return VLC_EGENERIC;
1026 /*****************************************************************************
1027 * Error: RunThread() error loop
1028 *****************************************************************************
1029 * This function is called when an error occurred during thread main's loop.
1030 *****************************************************************************/
1031 static void Error( input_thread_t *p_input )
1033 while( !p_input->b_die )
1036 msleep( INPUT_IDLE_SLEEP );
1040 /*****************************************************************************
1041 * End: end the input thread
1042 *****************************************************************************/
1043 static void End( input_thread_t * p_input )
1048 msg_Dbg( p_input, "closing input" );
1050 /* We are at the end */
1051 p_input->i_state = END_S;
1054 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1056 /* Clean control variables */
1057 input_ControlVarClean( p_input );
1059 /* Clean up master */
1060 InputSourceClean( p_input, &p_input->input );
1063 for( i = 0; i < p_input->i_slave; i++ )
1065 InputSourceClean( p_input, p_input->slave[i] );
1066 free( p_input->slave[i] );
1068 if( p_input->slave ) free( p_input->slave );
1070 /* Unload all modules */
1071 if( p_input->p_es_out )
1072 input_EsOutDelete( p_input->p_es_out );
1074 /* Close optional stream output instance */
1075 if( p_input->p_sout )
1077 vlc_object_t *p_pl =
1078 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1081 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
1083 /* attach sout to the playlist */
1084 msg_Warn( p_input, "keeping sout" );
1085 vlc_object_detach( p_input->p_sout );
1086 vlc_object_attach( p_input->p_sout, p_pl );
1090 msg_Warn( p_input, "destroying sout" );
1091 sout_DeleteInstance( p_input->p_sout );
1094 vlc_object_release( p_pl );
1098 if( p_input->p_meta )
1099 vlc_meta_Delete( p_input->p_meta );
1101 /* Tell we're dead */
1102 p_input->b_dead = VLC_TRUE;
1105 /*****************************************************************************
1107 *****************************************************************************/
1108 static inline int ControlPopNoLock( input_thread_t *p_input,
1109 int *pi_type, vlc_value_t *p_val )
1111 if( p_input->i_control <= 0 )
1113 return VLC_EGENERIC;
1116 *pi_type = p_input->control[0].i_type;
1117 *p_val = p_input->control[0].val;
1119 p_input->i_control--;
1120 if( p_input->i_control > 0 )
1124 for( i = 0; i < p_input->i_control; i++ )
1126 p_input->control[i].i_type = p_input->control[i+1].i_type;
1127 p_input->control[i].val = p_input->control[i+1].val;
1134 static void ControlReduce( input_thread_t *p_input )
1137 for( i = 1; i < p_input->i_control; i++ )
1139 const int i_lt = p_input->control[i-1].i_type;
1140 const int i_ct = p_input->control[i].i_type;
1142 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1143 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
1147 ( i_ct == INPUT_CONTROL_SET_STATE ||
1148 i_ct == INPUT_CONTROL_SET_RATE ||
1149 i_ct == INPUT_CONTROL_SET_POSITION ||
1150 i_ct == INPUT_CONTROL_SET_TIME ||
1151 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1152 i_ct == INPUT_CONTROL_SET_TITLE ||
1153 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1154 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1157 // msg_Dbg( p_input, "merged at %d", i );
1158 /* Remove the i-1 */
1159 for( j = i; j < p_input->i_control; j++ )
1160 p_input->control[j-1] = p_input->control[j];
1161 p_input->i_control--;
1165 /* TODO but that's not that important
1166 - merge SET_X with SET_X_CMD
1167 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1168 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1175 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
1178 vlc_bool_t b_force_update = VLC_FALSE;
1182 case INPUT_CONTROL_SET_DIE:
1183 msg_Dbg( p_input, "control: stopping input" );
1184 /* Mark all submodules to die */
1185 if( p_input->input.p_access )
1186 p_input->input.p_access->b_die = VLC_TRUE;
1187 if( p_input->input.p_stream )
1188 p_input->input.p_stream->b_die = VLC_TRUE;
1189 p_input->input.p_demux->b_die = VLC_TRUE;
1191 p_input->b_die = VLC_TRUE;
1194 case INPUT_CONTROL_SET_POSITION:
1195 case INPUT_CONTROL_SET_POSITION_OFFSET:
1198 if( i_type == INPUT_CONTROL_SET_POSITION )
1200 f_pos = val.f_float;
1204 /* Should not fail */
1205 demux2_Control( p_input->input.p_demux,
1206 DEMUX_GET_POSITION, &f_pos );
1207 f_pos += val.f_float;
1209 if( f_pos < 0.0 ) f_pos = 0.0;
1210 if( f_pos > 1.0 ) f_pos = 1.0;
1211 /* Reset the decoders states and clock synch (before calling the demuxer */
1212 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1213 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1214 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
1217 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1218 "%2.1f%% failed", f_pos * 100 );
1222 if( p_input->i_slave > 0 )
1223 SlaveSeek( p_input );
1225 //input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1226 //es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1227 b_force_update = VLC_TRUE;
1232 case INPUT_CONTROL_SET_TIME:
1233 case INPUT_CONTROL_SET_TIME_OFFSET:
1238 if( i_type == INPUT_CONTROL_SET_TIME )
1240 i_time = val.i_time;
1244 /* Should not fail */
1245 demux2_Control( p_input->input.p_demux,
1246 DEMUX_GET_TIME, &i_time );
1247 i_time += val.i_time;
1249 if( i_time < 0 ) i_time = 0;
1251 /* Reset the decoders states and clock synch (before calling the demuxer */
1252 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1253 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1255 i_ret = demux2_Control( p_input->input.p_demux,
1256 DEMUX_SET_TIME, i_time );
1260 /* Emulate it with a SET_POS */
1262 demux2_Control( p_input->input.p_demux,
1263 DEMUX_GET_LENGTH, &i_length );
1266 double f_pos = (double)i_time / (double)i_length;
1267 i_ret = demux2_Control( p_input->input.p_demux,
1268 DEMUX_SET_POSITION, f_pos );
1273 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1274 " failed", i_time );
1278 if( p_input->i_slave > 0 )
1279 SlaveSeek( p_input );
1281 //input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1282 //es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1283 b_force_update = VLC_TRUE;
1288 case INPUT_CONTROL_SET_STATE:
1289 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1290 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1293 if( p_input->input.p_access )
1294 i_ret = access2_Control( p_input->input.p_access,
1295 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1297 i_ret = demux2_Control( p_input->input.p_demux,
1298 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1302 /* FIXME What to do ? */
1303 msg_Warn( p_input, "cannot unset pause -> EOF" );
1304 vlc_mutex_unlock( &p_input->lock_control );
1305 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1306 vlc_mutex_lock( &p_input->lock_control );
1309 b_force_update = VLC_TRUE;
1311 /* Switch to play */
1312 p_input->i_state = PLAYING_S;
1313 val.i_int = PLAYING_S;
1314 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1317 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1319 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1320 p_input->b_can_pause )
1323 if( p_input->input.p_access )
1324 i_ret = access2_Control( p_input->input.p_access,
1325 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1327 i_ret = demux2_Control( p_input->input.p_demux,
1328 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1330 b_force_update = VLC_TRUE;
1334 msg_Warn( p_input, "cannot set pause state" );
1335 val.i_int = p_input->i_state;
1339 val.i_int = PAUSE_S;
1342 /* Switch to new state */
1343 p_input->i_state = val.i_int;
1344 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1346 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1348 b_force_update = VLC_TRUE;
1350 /* Correct "state" value */
1351 val.i_int = p_input->i_state;
1352 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1354 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1356 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1360 case INPUT_CONTROL_SET_RATE:
1361 case INPUT_CONTROL_SET_RATE_SLOWER:
1362 case INPUT_CONTROL_SET_RATE_FASTER:
1366 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1367 i_rate = p_input->i_rate * 2;
1368 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1369 i_rate = p_input->i_rate / 2;
1373 if( i_rate < INPUT_RATE_MIN )
1375 msg_Dbg( p_input, "cannot set rate faster" );
1376 i_rate = INPUT_RATE_MIN;
1378 else if( i_rate > INPUT_RATE_MAX )
1380 msg_Dbg( p_input, "cannot set rate slower" );
1381 i_rate = INPUT_RATE_MAX;
1383 if( i_rate != INPUT_RATE_DEFAULT &&
1384 ( !p_input->b_can_pace_control ||
1385 ( p_input->p_sout && !p_input->b_out_pace_control ) ) )
1387 msg_Dbg( p_input, "cannot change rate" );
1388 i_rate = INPUT_RATE_DEFAULT;
1390 if( i_rate != p_input->i_rate )
1392 p_input->i_rate = i_rate;
1394 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1396 /* We haven't send data to decoder when rate != default */
1397 if( i_rate == INPUT_RATE_DEFAULT )
1398 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1401 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1403 b_force_update = VLC_TRUE;
1408 case INPUT_CONTROL_SET_PROGRAM:
1409 /* No need to force update, es_out does it if needed */
1410 es_out_Control( p_input->p_es_out,
1411 ES_OUT_SET_GROUP, val.i_int );
1413 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1417 case INPUT_CONTROL_SET_ES:
1418 /* No need to force update, es_out does it if needed */
1419 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1420 input_EsOutGetFromID( p_input->p_es_out,
1424 case INPUT_CONTROL_SET_AUDIO_DELAY:
1425 input_EsOutSetDelay( p_input->p_es_out,
1426 AUDIO_ES, val.i_time );
1427 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1430 case INPUT_CONTROL_SET_SPU_DELAY:
1431 input_EsOutSetDelay( p_input->p_es_out,
1432 SPU_ES, val.i_time );
1433 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1436 case INPUT_CONTROL_SET_TITLE:
1437 case INPUT_CONTROL_SET_TITLE_NEXT:
1438 case INPUT_CONTROL_SET_TITLE_PREV:
1439 if( p_input->input.b_title_demux &&
1440 p_input->input.i_title > 0 )
1443 /* FIXME handle demux title */
1444 demux_t *p_demux = p_input->input.p_demux;
1447 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1448 i_title = p_demux->info.i_title - 1;
1449 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1450 i_title = p_demux->info.i_title + 1;
1452 i_title = val.i_int;
1454 if( i_title >= 0 && i_title < p_input->input.i_title )
1456 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1458 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1459 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1461 input_ControlVarTitle( p_input, i_title );
1464 else if( p_input->input.i_title > 0 )
1466 access_t *p_access = p_input->input.p_access;
1469 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1470 i_title = p_access->info.i_title - 1;
1471 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1472 i_title = p_access->info.i_title + 1;
1474 i_title = val.i_int;
1476 if( i_title >= 0 && i_title < p_input->input.i_title )
1478 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1479 stream_AccessReset( p_input->input.p_stream );
1481 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1482 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1486 case INPUT_CONTROL_SET_SEEKPOINT:
1487 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1488 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1489 if( p_input->input.b_title_demux &&
1490 p_input->input.i_title > 0 )
1492 demux_t *p_demux = p_input->input.p_demux;
1494 mtime_t i_input_time;
1495 mtime_t i_seekpoint_time;
1497 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1499 i_seekpoint = p_demux->info.i_seekpoint;
1500 i_seekpoint_time = p_input->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1501 if ( i_seekpoint_time != -1 )
1503 demux2_Control( p_demux, INPUT_GET_TIME, &i_input_time );
1504 if ( i_input_time < i_seekpoint_time + 3000000 )
1510 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1511 i_seekpoint = p_demux->info.i_seekpoint + 1;
1513 i_seekpoint = val.i_int;
1515 if( i_seekpoint >= 0 && i_seekpoint <
1516 p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1518 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1520 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1521 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1524 else if( p_input->input.i_title > 0 )
1526 access_t *p_access = p_input->input.p_access;
1528 mtime_t i_input_time;
1529 mtime_t i_seekpoint_time;
1531 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1533 i_seekpoint = p_access->info.i_seekpoint;
1534 i_seekpoint_time = p_input->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1535 if ( i_seekpoint_time != -1 )
1537 access2_Control( p_access, INPUT_GET_TIME, &i_input_time );
1538 if ( i_input_time < i_seekpoint_time + 3000000 )
1544 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1545 i_seekpoint = p_access->info.i_seekpoint + 1;
1547 i_seekpoint = val.i_int;
1549 if( i_seekpoint >= 0 && i_seekpoint <
1550 p_input->input.title[p_access->info.i_title]->i_seekpoint )
1552 access2_Control( p_access, ACCESS_SET_SEEKPOINT, i_seekpoint );
1553 stream_AccessReset( p_input->input.p_stream );
1555 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1556 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1561 case INPUT_CONTROL_ADD_SLAVE:
1562 if( val.psz_string )
1564 input_source_t *slave = InputSourceNew( p_input );
1566 if( !InputSourceInit( p_input, slave, val.psz_string, NULL,
1569 vlc_meta_t *p_meta_new = NULL;
1574 msg_Dbg( p_input, "adding %s as slave on the fly",
1578 if( demux2_Control( p_input->input.p_demux,
1579 DEMUX_GET_TIME, &i_time ) )
1581 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1582 InputSourceClean( p_input, slave );
1586 if( demux2_Control( slave->p_demux,
1587 DEMUX_SET_TIME, i_time ) )
1589 msg_Err( p_input, "seek failed for new slave" );
1590 InputSourceClean( p_input, slave );
1596 /* Get meta (access and demux) */
1597 if( access2_Control( slave->p_access,
1598 ACCESS_GET_META, &p_meta_new ) )
1600 if( !demux2_Control( slave->p_demux,
1601 DEMUX_GET_META, &p_meta ) )
1605 vlc_meta_Merge( p_meta_new, p_meta );
1606 vlc_meta_Delete( p_meta );
1610 p_meta_new = p_meta;
1616 if( p_input->p_meta )
1618 vlc_meta_Merge( p_input->p_meta, p_meta_new );
1619 vlc_meta_Delete( p_meta_new );
1623 p_input->p_meta = p_meta_new;
1625 UpdateMeta( p_input, VLC_FALSE );
1628 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
1632 msg_Warn( p_input, "failed to add %s as slave",
1636 free( val.psz_string );
1640 case INPUT_CONTROL_SET_BOOKMARK:
1642 msg_Err( p_input, "not yet implemented" );
1646 return b_force_update;
1649 /*****************************************************************************
1651 *****************************************************************************/
1652 static int UpdateFromDemux( input_thread_t *p_input )
1654 demux_t *p_demux = p_input->input.p_demux;
1657 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1659 v.i_int = p_demux->info.i_title;
1660 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1662 input_ControlVarTitle( p_input, p_demux->info.i_title );
1664 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1666 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1668 v.i_int = p_demux->info.i_seekpoint;
1669 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1671 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1673 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1675 /* Hmmm only works with master input */
1676 if( p_input->input.p_demux == p_demux )
1678 int i_title_end = p_input->input.i_title_end -
1679 p_input->input.i_title_offset;
1680 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1681 p_input->input.i_seekpoint_offset;
1683 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
1685 if( p_demux->info.i_title > i_title_end ||
1686 ( p_demux->info.i_title == i_title_end &&
1687 p_demux->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1689 else if( i_seekpoint_end >=0 )
1691 if( p_demux->info.i_seekpoint > i_seekpoint_end ) return 0;
1693 else if( i_title_end >= 0 )
1695 if( p_demux->info.i_title > i_title_end ) return 0;
1702 /*****************************************************************************
1704 *****************************************************************************/
1705 static int UpdateFromAccess( input_thread_t *p_input )
1707 access_t *p_access = p_input->input.p_access;
1710 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1712 v.i_int = p_access->info.i_title;
1713 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1715 input_ControlVarTitle( p_input, p_access->info.i_title );
1717 stream_AccessUpdate( p_input->input.p_stream );
1719 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1721 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1723 v.i_int = p_access->info.i_seekpoint;
1724 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1726 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1728 if( p_access->info.i_update & INPUT_UPDATE_META )
1730 /* TODO maybe multi - access ? */
1732 if( !access2_Control( p_input->input.p_access,ACCESS_GET_META,&p_meta))
1734 if( p_input->p_meta )
1736 vlc_meta_Merge( p_input->p_meta, p_meta );
1737 vlc_meta_Delete( p_meta );
1741 p_input->p_meta = p_meta;
1744 UpdateMeta( p_input, VLC_FALSE );
1745 var_SetBool( p_input, "item-change", p_input->input.p_item->i_id );
1747 p_access->info.i_update &= ~INPUT_UPDATE_META;
1750 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1752 /* Hmmm only works with master input */
1753 if( p_input->input.p_access == p_access )
1755 int i_title_end = p_input->input.i_title_end -
1756 p_input->input.i_title_offset;
1757 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1758 p_input->input.i_seekpoint_offset;
1760 if( i_title_end >= 0 && i_seekpoint_end >=0 )
1762 if( p_access->info.i_title > i_title_end ||
1763 ( p_access->info.i_title == i_title_end &&
1764 p_access->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1766 else if( i_seekpoint_end >=0 )
1768 if( p_access->info.i_seekpoint > i_seekpoint_end ) return 0;
1770 else if( i_title_end >= 0 )
1772 if( p_access->info.i_title > i_title_end ) return 0;
1779 /*****************************************************************************
1781 *****************************************************************************/
1782 static int UpdateMeta( input_thread_t *p_input, vlc_bool_t b_quick )
1784 vlc_meta_t *p_meta = p_input->p_meta;
1787 if( !p_meta || p_meta->i_meta == 0 )
1790 if( !b_quick ) msg_Dbg( p_input, "meta information:" );
1791 for( i = 0; i < p_meta->i_meta; i++ )
1794 msg_Dbg( p_input, " - '%s' = '%s'",
1795 _(p_meta->name[i]), p_meta->value[i] );
1797 if( !strcmp(p_meta->name[i], VLC_META_TITLE) && p_meta->value[i] &&
1798 !p_input->input.p_item->b_fixed_name )
1799 input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
1801 if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
1802 input_Control( p_input, INPUT_ADD_INFO, _("General"),
1803 _("Author"), p_meta->value[i] );
1805 input_Control( p_input, INPUT_ADD_INFO, _("Meta-information"),
1806 _(p_meta->name[i]), "%s", p_meta->value[i] );
1809 for( i = 0; i < p_meta->i_track; i++ )
1811 vlc_meta_t *tk = p_meta->track[i];
1814 if( tk->i_meta > 0 )
1816 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
1818 msg_Dbg( p_input, " - track[%d]:", i );
1820 sprintf( psz_cat, "%s %d", _("Stream"), i );
1821 for( j = 0; j < tk->i_meta; j++ )
1823 msg_Dbg( p_input, " - '%s' = '%s'", _(tk->name[j]),
1826 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1827 _(tk->name[j]), "%s", tk->value[j] );
1832 if( p_input->p_sout && p_input->p_sout->p_meta == NULL )
1834 p_input->p_sout->p_meta = vlc_meta_Duplicate( p_meta );
1840 /*****************************************************************************
1842 *****************************************************************************/
1843 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length,
1844 vlc_bool_t b_quick )
1846 playlist_t *p_playlist;
1847 char psz_buffer[MSTRTIME_MAX_SIZE];
1849 vlc_mutex_lock( &p_input->input.p_item->lock );
1850 p_input->input.p_item->i_duration = i_length;
1851 vlc_mutex_unlock( &p_input->input.p_item->lock );
1853 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
1857 var_SetInteger( p_playlist, "item-change",
1858 p_input->input.p_item->i_id );
1859 vlc_object_release( p_playlist );
1862 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
1863 msecstotimestr( psz_buffer, i_length / 1000 ) );
1866 /*****************************************************************************
1868 *****************************************************************************/
1869 static input_source_t *InputSourceNew( input_thread_t *p_input )
1871 input_source_t *in = malloc( sizeof( input_source_t ) );
1874 in->p_access = NULL;
1875 in->p_stream = NULL;
1877 in->b_title_demux = VLC_FALSE;
1880 in->b_can_pace_control = VLC_TRUE;
1881 in->b_eof = VLC_FALSE;
1882 in->i_cr_average = 0;
1887 /*****************************************************************************
1889 *****************************************************************************/
1890 static int InputSourceInit( input_thread_t *p_input,
1891 input_source_t *in, char *psz_mrl,
1892 char *psz_forced_demux, vlc_bool_t b_quick )
1894 char *psz_dup = strdup( psz_mrl );
1903 MRLSplit( p_input, psz_dup, &psz_access, &psz_demux, &psz_path );
1905 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
1906 psz_mrl, psz_access, psz_demux, psz_path );
1908 /* Hack to allow udp://@:port syntax */
1910 (strncmp( psz_access, "udp", 3 ) &&
1911 strncmp( psz_access, "rtp", 3 )) )
1913 /* Find optional titles and seekpoints */
1914 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
1915 &in->i_seekpoint_start, &in->i_seekpoint_end );
1917 if( psz_forced_demux && *psz_forced_demux )
1918 psz_demux = psz_forced_demux;
1920 /* Try access_demux if no demux given */
1921 if( *psz_demux == '\0' )
1923 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
1924 NULL, p_input->p_es_out, VLC_FALSE );
1930 msg_Dbg( p_input, "trying to preparse %s", psz_path );
1931 psz_demux = strdup( "" );
1932 psz_access = strdup( "file" );
1937 int64_t i_pts_delay;
1939 /* Get infos from access_demux */
1940 demux2_Control( in->p_demux,
1941 DEMUX_GET_PTS_DELAY, &i_pts_delay );
1942 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
1944 in->b_title_demux = VLC_TRUE;
1945 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
1946 &in->title, &in->i_title,
1947 &in->i_title_offset, &in->i_seekpoint_offset ) )
1952 demux2_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
1953 &in->b_can_pace_control );
1954 demux2_Control( in->p_demux, DEMUX_CAN_PAUSE,
1958 demux2_Control( in->p_demux, DEMUX_CAN_SEEK,
1964 int64_t i_pts_delay;
1966 /* Now try a real access */
1967 in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path,
1970 /* Access failed, URL encoded ? */
1971 if( in->p_access == NULL && strchr( psz_path, '%' ) )
1973 DecodeUrl( psz_path );
1975 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
1976 psz_access, psz_demux, psz_path );
1978 in->p_access = access2_New( p_input,
1979 psz_access, psz_demux, psz_path,
1982 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
1983 * are forbidden in filenames on Win32. */
1985 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
1986 if( in->p_access == NULL &&
1987 *psz_access == '\0' && ( *psz_demux || *psz_path ) )
1990 psz_dup = strdup( psz_mrl );
1995 in->p_access = access2_New( p_input,
1996 psz_access, psz_demux, psz_path,
2001 if( in->p_access == NULL )
2003 msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
2007 /* Get infos from access */
2010 access2_Control( in->p_access,
2011 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2012 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2014 in->b_title_demux = VLC_FALSE;
2015 if( access2_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2016 &in->title, &in->i_title,
2017 &in->i_title_offset, &in->i_seekpoint_offset ) )
2023 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2024 &in->b_can_pace_control );
2025 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
2027 access2_Control( in->p_access, ACCESS_CAN_SEEK,
2029 var_Set( p_input, "seekable", val );
2032 /* Create the stream_t */
2033 in->p_stream = stream_AccessNew( in->p_access, b_quick );
2034 if( in->p_stream == NULL )
2036 msg_Warn( p_input, "cannot create a stream_t from access" );
2040 /* Open a demuxer */
2041 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2043 psz_demux = in->p_access->psz_demux;
2045 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2046 in->p_stream, p_input->p_es_out, b_quick );
2047 if( in->p_demux == NULL )
2049 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2050 psz_access, psz_demux, psz_path );
2054 /* TODO get title from demux */
2055 if( !b_quick && in->i_title <= 0 )
2057 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2058 &in->title, &in->i_title,
2059 &in->i_title_offset, &in->i_seekpoint_offset ))
2066 in->b_title_demux = VLC_TRUE;
2071 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2072 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2079 demux2_Delete( in->p_demux );
2082 stream_AccessDelete( in->p_stream );
2085 access2_Delete( in->p_access );
2088 return VLC_EGENERIC;
2091 /*****************************************************************************
2093 *****************************************************************************/
2094 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
2097 demux2_Delete( in->p_demux );
2100 stream_AccessDelete( in->p_stream );
2103 access2_Delete( in->p_access );
2105 if( in->i_title > 0 )
2108 for( i = 0; i < in->i_title; i++ )
2110 vlc_input_title_Delete( in->title[i] );
2116 static void SlaveDemux( input_thread_t *p_input )
2120 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2122 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2126 for( i = 0; i < p_input->i_slave; i++ )
2128 input_source_t *in = p_input->slave[i];
2134 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2139 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2141 msg_Err( p_input, "slave[%d] doesn't like "
2142 "DEMUX_GET_TIME -> EOF", i );
2147 if( i_stime >= i_time )
2150 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
2156 i_ret = in->p_demux->pf_demux( in->p_demux );
2161 msg_Dbg( p_input, "slave %d EOF", i );
2162 in->b_eof = VLC_TRUE;
2167 static void SlaveSeek( input_thread_t *p_input )
2172 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2174 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2178 for( i = 0; i < p_input->i_slave; i++ )
2180 input_source_t *in = p_input->slave[i];
2182 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2184 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2185 in->b_eof = VLC_TRUE;
2189 /*****************************************************************************
2191 *****************************************************************************/
2192 static vlc_meta_t *InputMetaUser( input_thread_t *p_input )
2197 if( ( p_meta = vlc_meta_New() ) == NULL )
2200 /* Get meta information from user */
2201 #define GET_META( c, s ) \
2202 var_Get( p_input, (s), &val ); \
2203 if( *val.psz_string ) \
2204 vlc_meta_Add( p_meta, c, val.psz_string ); \
2205 free( val.psz_string )
2207 GET_META( VLC_META_TITLE, "meta-title" );
2208 GET_META( VLC_META_AUTHOR, "meta-author" );
2209 GET_META( VLC_META_ARTIST, "meta-artist" );
2210 GET_META( VLC_META_GENRE, "meta-genre" );
2211 GET_META( VLC_META_COPYRIGHT, "meta-copyright" );
2212 GET_META( VLC_META_DESCRIPTION, "meta-description" );
2213 GET_META( VLC_META_DATE, "meta-date" );
2214 GET_META( VLC_META_URL, "meta-url" );
2220 /*****************************************************************************
2221 * DecodeUrl: decode a given encoded url
2222 *****************************************************************************/
2223 static void DecodeUrl( char *psz )
2225 char *dup = strdup( psz );
2243 *psz++ = strtol( val, NULL, 16 );
2245 else if( *p == '+' )
2259 /*****************************************************************************
2260 * ParseOption: parses the options for the input
2261 *****************************************************************************
2262 * This function parses the input (config) options and creates their associated
2264 * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
2265 * bar is the value of the option.
2266 *****************************************************************************/
2267 static void ParseOption( input_thread_t *p_input, const char *psz_option )
2269 char *psz_name = (char *)psz_option;
2270 char *psz_value = strchr( psz_option, '=' );
2271 int i_name_len, i_type;
2272 vlc_bool_t b_isno = VLC_FALSE;
2275 if( psz_value ) i_name_len = psz_value - psz_option;
2276 else i_name_len = strlen( psz_option );
2278 /* It's too much of an hassle to remove the ':' when we parse
2279 * the cmd line :) */
2280 if( i_name_len && *psz_name == ':' )
2286 if( i_name_len == 0 ) return;
2288 psz_name = strndup( psz_name, i_name_len );
2289 if( psz_value ) psz_value++;
2291 i_type = config_GetType( p_input, psz_name );
2293 if( !i_type && !psz_value )
2295 /* check for "no-foo" or "nofoo" */
2296 if( !strncmp( psz_name, "no-", 3 ) )
2298 memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
2300 else if( !strncmp( psz_name, "no", 2 ) )
2302 memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
2304 else goto cleanup; /* Option doesn't exist */
2307 i_type = config_GetType( p_input, psz_name );
2309 if( !i_type ) goto cleanup; /* Option doesn't exist */
2311 else if( !i_type ) goto cleanup; /* Option doesn't exist */
2313 if( ( i_type != VLC_VAR_BOOL ) &&
2314 ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */
2316 /* Create the variable in the input object.
2317 * Children of the input object will be able to retreive this value
2318 * thanks to the inheritance property of the object variables. */
2319 var_Create( p_input, psz_name, i_type );
2324 val.b_bool = !b_isno;
2327 case VLC_VAR_INTEGER:
2328 val.i_int = atoi( psz_value );
2332 val.f_float = atof( psz_value );
2335 case VLC_VAR_STRING:
2336 case VLC_VAR_MODULE:
2338 case VLC_VAR_DIRECTORY:
2339 val.psz_string = psz_value;
2347 var_Set( p_input, psz_name, val );
2349 msg_Dbg( p_input, "set input option: %s to %s", psz_name,
2350 psz_value ? psz_value : ( val.b_bool ? "true" : "false") );
2353 if( psz_name ) free( psz_name );
2357 /*****************************************************************************
2358 * MRLSplit: parse the access, demux and url part of the
2359 * Media Resource Locator.
2360 *****************************************************************************/
2361 static void MRLSplit( input_thread_t *p_input, char *psz_dup,
2362 char **ppsz_access, char **ppsz_demux, char **ppsz_path )
2364 char *psz_access = NULL;
2365 char *psz_demux = NULL;
2366 char *psz_path = NULL;
2367 char *psz, *psz_check;
2369 psz = strchr( psz_dup, ':' );
2371 /* '@' not allowed in access/demux part */
2372 psz_check = strchr( psz_dup, '@' );
2373 if( psz_check && psz_check < psz ) psz = 0;
2375 #if defined( WIN32 ) || defined( UNDER_CE )
2376 if( psz - psz_dup == 1 )
2378 msg_Warn( p_input, "drive letter %c: found in source", *psz_dup );
2387 if( psz[0] == '/' && psz[1] == '/' ) psz += 2;
2391 psz = strchr( psz_dup, '/' );
2398 psz_access = psz_dup;
2405 if( !psz_access ) *ppsz_access = "";
2406 else *ppsz_access = psz_access;
2408 if( !psz_demux ) *ppsz_demux = "";
2409 else *ppsz_demux = psz_demux;
2411 if( !psz_path ) *ppsz_path = "";
2412 else *ppsz_path = psz_path;
2415 /*****************************************************************************
2416 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
2419 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
2420 *****************************************************************************/
2421 static void MRLSections( input_thread_t *p_input, char *psz_source,
2422 int *pi_title_start, int *pi_title_end,
2423 int *pi_chapter_start, int *pi_chapter_end )
2425 char *psz, *psz_end, *psz_next, *psz_check;
2427 *pi_title_start = *pi_title_end = -1;
2428 *pi_chapter_start = *pi_chapter_end = -1;
2430 /* Start by parsing titles and chapters */
2431 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
2433 /* Check we are really dealing with a title/chapter section */
2434 psz_check = psz + 1;
2435 if( !*psz_check ) return;
2436 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2437 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
2438 if( *psz_check == ':' && ++psz_check )
2439 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2440 if( *psz_check != '-' && *psz_check ) return;
2441 if( *psz_check == '-' && ++psz_check )
2442 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2443 if( *psz_check != ':' && *psz_check ) return;
2444 if( *psz_check == ':' && ++psz_check )
2445 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2446 if( *psz_check ) return;
2448 /* Separate start and end */
2450 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
2452 /* Look for the start title */
2453 *pi_title_start = strtol( psz, &psz_next, 0 );
2454 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
2455 *pi_title_end = *pi_title_start;
2458 /* Look for the start chapter */
2460 *pi_chapter_start = strtol( psz, &psz_next, 0 );
2461 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
2462 *pi_chapter_end = *pi_chapter_start;
2466 /* Look for the end title */
2467 *pi_title_end = strtol( psz_end, &psz_next, 0 );
2468 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
2471 /* Look for the end chapter */
2472 if( *psz_end ) psz_end++;
2473 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
2474 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
2477 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
2478 psz_source, *pi_title_start, *pi_chapter_start,
2479 *pi_title_end, *pi_chapter_end );
2483 /***********************************************************************
2484 * Info management functions
2485 ***********************************************************************/
2486 char *vlc_input_item_GetInfo( input_item_t *p_i,
2487 const char *psz_cat,
2488 const char *psz_name )
2492 vlc_mutex_lock( &p_i->lock );
2494 for( i = 0 ; i< p_i->i_categories ; i++ )
2496 info_category_t *p_cat = p_i->pp_categories[i];
2498 if( !psz_cat || strcmp( p_cat->psz_name, psz_cat ) )
2501 for( j = 0; j < p_cat->i_infos ; j++ )
2503 if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
2505 vlc_mutex_unlock( &p_i->lock );
2506 return strdup( p_cat->pp_infos[j]->psz_value );
2510 vlc_mutex_unlock( &p_i->lock );
2511 return strdup( "" );
2514 int vlc_input_item_AddInfo( input_item_t *p_i,
2515 const char *psz_cat,
2516 const char *psz_name,
2517 const char *psz_format, ... )
2521 info_t *p_info = NULL;
2522 info_category_t *p_cat = NULL ;
2524 vlc_mutex_lock( &p_i->lock );
2526 for( i = 0 ; i < p_i->i_categories ; i ++ )
2528 if( !strcmp( p_i->pp_categories[i]->psz_name, psz_cat ) )
2530 p_cat = p_i->pp_categories[i];
2536 if( !(p_cat = (info_category_t *)malloc( sizeof(info_category_t) )) )
2538 vlc_mutex_unlock( &p_i->lock );
2539 return VLC_EGENERIC;
2541 p_cat->psz_name = strdup( psz_cat );
2543 p_cat->pp_infos = 0;
2544 INSERT_ELEM( p_i->pp_categories, p_i->i_categories, p_i->i_categories,
2548 for( i = 0; i< p_cat->i_infos; i++ )
2550 if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
2552 p_info = p_cat->pp_infos[i];
2559 if( ( p_info = (info_t *)malloc( sizeof( info_t ) ) ) == NULL )
2561 vlc_mutex_unlock( &p_i->lock );
2562 return VLC_EGENERIC;
2564 INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
2565 p_info->psz_name = strdup( psz_name );
2569 if( p_info->psz_value ) free( p_info->psz_value );
2572 va_start( args, psz_format );
2573 vasprintf( &p_info->psz_value, psz_format, args);
2576 vlc_mutex_unlock( &p_i->lock );