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)
612 * XXX: we add a special case if the uri starts by vlc.
613 * else 'vlc in.file --sout "" vlc:quit' cannot work (the output will
614 * be destroyed in case of a file).
615 * (this will break playing of file starting by 'vlc:' but I don't
616 * want to add more logic, just force file by file:// or code it ;)
620 psz = var_GetString( p_input, "sout" );
621 if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
623 p_input->p_sout = sout_NewInstance( p_input, psz );
624 if( p_input->p_sout == NULL )
626 msg_Err( p_input, "cannot start stream output instance, " \
636 p_input->p_es_out = input_EsOutNew( p_input );
637 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
638 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
640 if( InputSourceInit( p_input, &p_input->input,
641 p_input->input.p_item->psz_uri, NULL, b_quick ) )
646 /* Create global title (from master) */
649 p_input->i_title = p_input->input.i_title;
650 p_input->title = p_input->input.title;
651 p_input->i_title_offset = p_input->input.i_title_offset;
652 p_input->i_seekpoint_offset = p_input->input.i_seekpoint_offset;
653 if( p_input->i_title > 0 )
655 /* Setup variables */
656 input_ControlVarNavigation( p_input );
657 input_ControlVarTitle( p_input, 0 );
661 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
662 p_input->b_can_pause = p_input->input.b_can_pause;
665 if( p_input->i_pts_delay <= 0 )
666 p_input->i_pts_delay = DEFAULT_PTS_DELAY;
668 /* If the desynchronisation requested by the user is < 0, we need to
669 * cache more data. */
670 var_Get( p_input, "audio-desync", &val );
671 if( val.i_int < 0 ) p_input->i_pts_delay -= (val.i_int * 1000);
673 /* Update cr_average depending on the caching */
674 p_input->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000);
675 p_input->input.i_cr_average /= 10;
676 if( p_input->input.i_cr_average <= 0 ) p_input->input.i_cr_average = 1;
679 /* Load master infos */
681 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH,
682 &val.i_time ) && val.i_time > 0 )
684 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
685 UpdateItemLength( p_input, val.i_time, b_quick );
686 p_input->input.p_item->i_duration = val.i_time;
689 /* Start title/chapter */
692 val.i_int = p_input->input.i_title_start -
693 p_input->input.i_title_offset;
694 if( val.i_int > 0 && val.i_int < p_input->input.i_title )
695 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
696 val.i_int = p_input->input.i_seekpoint_start -
697 p_input->input.i_seekpoint_offset;
698 if( val.i_int > 0 /* TODO: check upper boundary */ )
699 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
703 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
705 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
708 if( p_input->i_start > 0 )
710 if( p_input->i_start >= val.i_time )
712 msg_Warn( p_input, "invalid start-time ignored" );
718 msg_Dbg( p_input, "starting at time: %ds",
719 (int)( p_input->i_start / I64C(1000000) ) );
721 s.i_time = p_input->i_start;
722 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
725 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
727 msg_Warn( p_input, "invalid stop-time ignored" );
733 /* Get fps and set it if not already set */
734 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
737 float f_requested_fps;
739 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
740 var_SetFloat( p_input, "sub-original-fps", f_fps );
742 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
743 if( f_requested_fps != f_fps )
745 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
747 var_SetFloat( p_input, "sub-fps", f_requested_fps );
751 i_delay = var_CreateGetInteger( p_input, "sub-delay" );
754 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
758 /* Look for and add subtitle files */
759 psz_subtitle = var_GetString( p_input, "sub-file" );
766 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
768 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
771 sub = InputSourceNew( p_input );
772 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle",
775 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
778 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list,
781 if( count.i_int == 0 )
783 /* if it was first one, there is disable too */
785 if( count.i_int < list.p_list->i_count )
787 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
788 &list.p_list->p_values[count.i_int] );
790 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list,
796 var_Get( p_input, "sub-autodetect-file", &val );
799 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
800 char **subs = subtitles_Detect( p_input, psz_autopath,
801 p_input->input.p_item->psz_uri );
804 for( i = 0; subs[i] != NULL; i++ )
806 if( strcmp( psz_subtitle, subs[i] ) )
808 sub = InputSourceNew( p_input );
809 if( !InputSourceInit( p_input, sub, subs[i], "subtitle",
812 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
818 free( psz_autopath );
820 free( psz_subtitle );
823 psz = var_GetString( p_input, "input-slave" );
827 input_source_t *slave;
830 while( *psz == ' ' || *psz == '#' )
834 if( ( psz_delim = strchr( psz, '#' ) ) )
843 msg_Dbg( p_input, "adding slave input '%s'", psz );
844 slave = InputSourceNew( p_input );
845 if( !InputSourceInit( p_input, slave, psz, NULL, VLC_FALSE ) )
847 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
852 if( psz ) free( psz );
856 p_input->i_start = 0;
857 p_input->i_start = 0;
863 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
864 i_es_out_mode = ES_OUT_MODE_AUTO;
866 if( p_input->p_sout )
868 var_Get( p_input, "sout-all", &val );
871 i_es_out_mode = ES_OUT_MODE_ALL;
876 var_Get( p_input, "programs", &val );
877 if ( val.p_list && val.p_list->i_count )
879 i_es_out_mode = ES_OUT_MODE_PARTIAL;
880 /* Note : we should remove the "program" callback. */
883 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
887 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
889 /* Inform the demuxer about waited group (needed only for DVB) */
890 if( i_es_out_mode == ES_OUT_MODE_ALL )
892 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
894 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
896 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1,
901 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP,
902 (int) var_GetInteger( p_input, "program" ), NULL );
905 if( p_input->p_sout )
907 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
909 p_input->b_out_pace_control = VLC_FALSE;
913 p_input->b_out_pace_control = VLC_TRUE;
916 if( p_input->b_can_pace_control && p_input->b_out_pace_control )
918 /* We don't want a high input priority here or we'll
919 * end-up sucking up all the CPU time */
920 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
923 msg_Dbg( p_input, "starting in %s mode",
924 p_input->b_out_pace_control ? "asynch" : "synch" );
928 /* Get meta data from users */
929 p_meta_tmp = InputMetaUser( p_input );
931 /* Get meta data from master input */
932 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_META, &p_meta ) )
940 else if( p_meta_tmp )
942 vlc_meta_Merge( p_meta, p_meta_tmp );
943 vlc_meta_Delete( p_meta_tmp );
946 /* Access_file does not give any meta, and there are no slave */
949 if( !p_input->input.p_access ||
950 access2_Control( p_input->input.p_access, ACCESS_GET_META,
958 else if( p_meta_tmp )
960 vlc_meta_Merge( p_meta, p_meta_tmp );
961 vlc_meta_Delete( p_meta_tmp );
964 /* Get meta data from slave input */
965 for( i = 0; i < p_input->i_slave; i++ )
967 vlc_meta_t *p_meta_slave;
969 if( !demux2_Control( p_input->slave[i]->p_demux,
970 DEMUX_GET_META, &p_meta_slave ) )
974 p_meta = p_meta_slave;
976 else if( p_meta_slave )
978 vlc_meta_Merge( p_meta, p_meta_slave );
979 vlc_meta_Delete( p_meta_slave );
983 if( p_input->slave[i]->p_access &&
984 !access2_Control( p_input->slave[i]->p_access,
985 ACCESS_GET_META, &p_meta_slave ) )
989 p_meta = p_meta_slave;
991 else if( p_meta_slave )
993 vlc_meta_Merge( p_meta, p_meta_slave );
994 vlc_meta_Delete( p_meta_slave );
1000 p_input->p_meta = p_meta;
1001 UpdateMeta( p_input, b_quick );
1005 msg_Dbg( p_input, "`%s' sucessfully opened",
1006 p_input->input.p_item->psz_uri );
1010 /* Trigger intf update for this item */
1011 /* Playlist has a callback on this variable and will forward
1013 var_SetInteger( p_input, "item-change", p_input->input.p_item->i_id );
1015 /* initialization is complete */
1016 p_input->i_state = PLAYING_S;
1018 val.i_int = PLAYING_S;
1019 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1024 if( p_input->p_es_out )
1025 input_EsOutDelete( p_input->p_es_out );
1027 if( p_input->p_sout )
1028 sout_DeleteInstance( p_input->p_sout );
1030 /* Mark them deleted */
1031 p_input->input.p_demux = NULL;
1032 p_input->input.p_stream = NULL;
1033 p_input->input.p_access = NULL;
1034 p_input->p_es_out = NULL;
1035 p_input->p_sout = NULL;
1037 return VLC_EGENERIC;
1040 /*****************************************************************************
1041 * Error: RunThread() error loop
1042 *****************************************************************************
1043 * This function is called when an error occurred during thread main's loop.
1044 *****************************************************************************/
1045 static void Error( input_thread_t *p_input )
1047 while( !p_input->b_die )
1050 msleep( INPUT_IDLE_SLEEP );
1054 /*****************************************************************************
1055 * End: end the input thread
1056 *****************************************************************************/
1057 static void End( input_thread_t * p_input )
1062 msg_Dbg( p_input, "closing input" );
1064 /* We are at the end */
1065 p_input->i_state = END_S;
1068 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1070 /* Clean control variables */
1071 input_ControlVarClean( p_input );
1073 /* Clean up master */
1074 InputSourceClean( p_input, &p_input->input );
1077 for( i = 0; i < p_input->i_slave; i++ )
1079 InputSourceClean( p_input, p_input->slave[i] );
1080 free( p_input->slave[i] );
1082 if( p_input->slave ) free( p_input->slave );
1084 /* Unload all modules */
1085 if( p_input->p_es_out )
1086 input_EsOutDelete( p_input->p_es_out );
1088 /* Close optional stream output instance */
1089 if( p_input->p_sout )
1091 vlc_object_t *p_pl =
1092 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1095 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
1097 /* attach sout to the playlist */
1098 msg_Warn( p_input, "keeping sout" );
1099 vlc_object_detach( p_input->p_sout );
1100 vlc_object_attach( p_input->p_sout, p_pl );
1104 msg_Warn( p_input, "destroying sout" );
1105 sout_DeleteInstance( p_input->p_sout );
1108 vlc_object_release( p_pl );
1112 if( p_input->p_meta )
1113 vlc_meta_Delete( p_input->p_meta );
1115 /* Tell we're dead */
1116 p_input->b_dead = VLC_TRUE;
1119 /*****************************************************************************
1121 *****************************************************************************/
1122 static inline int ControlPopNoLock( input_thread_t *p_input,
1123 int *pi_type, vlc_value_t *p_val )
1125 if( p_input->i_control <= 0 )
1127 return VLC_EGENERIC;
1130 *pi_type = p_input->control[0].i_type;
1131 *p_val = p_input->control[0].val;
1133 p_input->i_control--;
1134 if( p_input->i_control > 0 )
1138 for( i = 0; i < p_input->i_control; i++ )
1140 p_input->control[i].i_type = p_input->control[i+1].i_type;
1141 p_input->control[i].val = p_input->control[i+1].val;
1148 static void ControlReduce( input_thread_t *p_input )
1151 for( i = 1; i < p_input->i_control; i++ )
1153 const int i_lt = p_input->control[i-1].i_type;
1154 const int i_ct = p_input->control[i].i_type;
1156 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1157 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
1161 ( i_ct == INPUT_CONTROL_SET_STATE ||
1162 i_ct == INPUT_CONTROL_SET_RATE ||
1163 i_ct == INPUT_CONTROL_SET_POSITION ||
1164 i_ct == INPUT_CONTROL_SET_TIME ||
1165 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1166 i_ct == INPUT_CONTROL_SET_TITLE ||
1167 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1168 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1171 // msg_Dbg( p_input, "merged at %d", i );
1172 /* Remove the i-1 */
1173 for( j = i; j < p_input->i_control; j++ )
1174 p_input->control[j-1] = p_input->control[j];
1175 p_input->i_control--;
1179 /* TODO but that's not that important
1180 - merge SET_X with SET_X_CMD
1181 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1182 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1189 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
1192 vlc_bool_t b_force_update = VLC_FALSE;
1196 case INPUT_CONTROL_SET_DIE:
1197 msg_Dbg( p_input, "control: stopping input" );
1198 /* Mark all submodules to die */
1199 if( p_input->input.p_access )
1200 p_input->input.p_access->b_die = VLC_TRUE;
1201 if( p_input->input.p_stream )
1202 p_input->input.p_stream->b_die = VLC_TRUE;
1203 p_input->input.p_demux->b_die = VLC_TRUE;
1205 p_input->b_die = VLC_TRUE;
1208 case INPUT_CONTROL_SET_POSITION:
1209 case INPUT_CONTROL_SET_POSITION_OFFSET:
1212 if( i_type == INPUT_CONTROL_SET_POSITION )
1214 f_pos = val.f_float;
1218 /* Should not fail */
1219 demux2_Control( p_input->input.p_demux,
1220 DEMUX_GET_POSITION, &f_pos );
1221 f_pos += val.f_float;
1223 if( f_pos < 0.0 ) f_pos = 0.0;
1224 if( f_pos > 1.0 ) f_pos = 1.0;
1225 /* Reset the decoders states and clock synch (before calling the demuxer */
1226 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1227 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1228 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
1231 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1232 "%2.1f%% failed", f_pos * 100 );
1236 if( p_input->i_slave > 0 )
1237 SlaveSeek( p_input );
1239 //input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1240 //es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1241 b_force_update = VLC_TRUE;
1246 case INPUT_CONTROL_SET_TIME:
1247 case INPUT_CONTROL_SET_TIME_OFFSET:
1252 if( i_type == INPUT_CONTROL_SET_TIME )
1254 i_time = val.i_time;
1258 /* Should not fail */
1259 demux2_Control( p_input->input.p_demux,
1260 DEMUX_GET_TIME, &i_time );
1261 i_time += val.i_time;
1263 if( i_time < 0 ) i_time = 0;
1265 /* Reset the decoders states and clock synch (before calling the demuxer */
1266 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1267 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1269 i_ret = demux2_Control( p_input->input.p_demux,
1270 DEMUX_SET_TIME, i_time );
1274 /* Emulate it with a SET_POS */
1276 demux2_Control( p_input->input.p_demux,
1277 DEMUX_GET_LENGTH, &i_length );
1280 double f_pos = (double)i_time / (double)i_length;
1281 i_ret = demux2_Control( p_input->input.p_demux,
1282 DEMUX_SET_POSITION, f_pos );
1287 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1288 " failed", i_time );
1292 if( p_input->i_slave > 0 )
1293 SlaveSeek( p_input );
1295 //input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1296 //es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1297 b_force_update = VLC_TRUE;
1302 case INPUT_CONTROL_SET_STATE:
1303 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1304 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1307 if( p_input->input.p_access )
1308 i_ret = access2_Control( p_input->input.p_access,
1309 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1311 i_ret = demux2_Control( p_input->input.p_demux,
1312 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1316 /* FIXME What to do ? */
1317 msg_Warn( p_input, "cannot unset pause -> EOF" );
1318 vlc_mutex_unlock( &p_input->lock_control );
1319 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1320 vlc_mutex_lock( &p_input->lock_control );
1323 b_force_update = VLC_TRUE;
1325 /* Switch to play */
1326 p_input->i_state = PLAYING_S;
1327 val.i_int = PLAYING_S;
1328 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1331 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1333 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1334 p_input->b_can_pause )
1337 if( p_input->input.p_access )
1338 i_ret = access2_Control( p_input->input.p_access,
1339 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1341 i_ret = demux2_Control( p_input->input.p_demux,
1342 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1344 b_force_update = VLC_TRUE;
1348 msg_Warn( p_input, "cannot set pause state" );
1349 val.i_int = p_input->i_state;
1353 val.i_int = PAUSE_S;
1356 /* Switch to new state */
1357 p_input->i_state = val.i_int;
1358 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1360 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1362 b_force_update = VLC_TRUE;
1364 /* Correct "state" value */
1365 val.i_int = p_input->i_state;
1366 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1368 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1370 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1374 case INPUT_CONTROL_SET_RATE:
1375 case INPUT_CONTROL_SET_RATE_SLOWER:
1376 case INPUT_CONTROL_SET_RATE_FASTER:
1380 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1381 i_rate = p_input->i_rate * 2;
1382 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1383 i_rate = p_input->i_rate / 2;
1387 if( i_rate < INPUT_RATE_MIN )
1389 msg_Dbg( p_input, "cannot set rate faster" );
1390 i_rate = INPUT_RATE_MIN;
1392 else if( i_rate > INPUT_RATE_MAX )
1394 msg_Dbg( p_input, "cannot set rate slower" );
1395 i_rate = INPUT_RATE_MAX;
1397 if( i_rate != INPUT_RATE_DEFAULT &&
1398 ( !p_input->b_can_pace_control ||
1399 ( p_input->p_sout && !p_input->b_out_pace_control ) ) )
1401 msg_Dbg( p_input, "cannot change rate" );
1402 i_rate = INPUT_RATE_DEFAULT;
1404 if( i_rate != p_input->i_rate )
1406 p_input->i_rate = i_rate;
1408 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1410 /* We haven't send data to decoder when rate != default */
1411 if( i_rate == INPUT_RATE_DEFAULT )
1412 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1415 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1417 b_force_update = VLC_TRUE;
1422 case INPUT_CONTROL_SET_PROGRAM:
1423 /* No need to force update, es_out does it if needed */
1424 es_out_Control( p_input->p_es_out,
1425 ES_OUT_SET_GROUP, val.i_int );
1427 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1431 case INPUT_CONTROL_SET_ES:
1432 /* No need to force update, es_out does it if needed */
1433 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1434 input_EsOutGetFromID( p_input->p_es_out,
1438 case INPUT_CONTROL_SET_AUDIO_DELAY:
1439 input_EsOutSetDelay( p_input->p_es_out,
1440 AUDIO_ES, val.i_time );
1441 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1444 case INPUT_CONTROL_SET_SPU_DELAY:
1445 input_EsOutSetDelay( p_input->p_es_out,
1446 SPU_ES, val.i_time );
1447 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1450 case INPUT_CONTROL_SET_TITLE:
1451 case INPUT_CONTROL_SET_TITLE_NEXT:
1452 case INPUT_CONTROL_SET_TITLE_PREV:
1453 if( p_input->input.b_title_demux &&
1454 p_input->input.i_title > 0 )
1457 /* FIXME handle demux title */
1458 demux_t *p_demux = p_input->input.p_demux;
1461 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1462 i_title = p_demux->info.i_title - 1;
1463 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1464 i_title = p_demux->info.i_title + 1;
1466 i_title = val.i_int;
1468 if( i_title >= 0 && i_title < p_input->input.i_title )
1470 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1472 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1473 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1475 input_ControlVarTitle( p_input, i_title );
1478 else if( p_input->input.i_title > 0 )
1480 access_t *p_access = p_input->input.p_access;
1483 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1484 i_title = p_access->info.i_title - 1;
1485 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1486 i_title = p_access->info.i_title + 1;
1488 i_title = val.i_int;
1490 if( i_title >= 0 && i_title < p_input->input.i_title )
1492 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1493 stream_AccessReset( p_input->input.p_stream );
1495 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1496 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1500 case INPUT_CONTROL_SET_SEEKPOINT:
1501 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1502 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1503 if( p_input->input.b_title_demux &&
1504 p_input->input.i_title > 0 )
1506 demux_t *p_demux = p_input->input.p_demux;
1508 int64_t i_input_time;
1509 int64_t i_seekpoint_time;
1511 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1513 i_seekpoint = p_demux->info.i_seekpoint;
1514 i_seekpoint_time = p_input->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1515 if( i_seekpoint_time >= 0 &&
1516 !demux2_Control( p_demux,
1517 DEMUX_GET_TIME, &i_input_time ) )
1519 if ( i_input_time < i_seekpoint_time + 3000000 )
1525 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1526 i_seekpoint = p_demux->info.i_seekpoint + 1;
1528 i_seekpoint = val.i_int;
1530 if( i_seekpoint >= 0 && i_seekpoint <
1531 p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1533 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1535 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1536 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1539 else if( p_input->input.i_title > 0 )
1541 demux_t *p_demux = p_input->input.p_demux;
1542 access_t *p_access = p_input->input.p_access;
1544 int64_t i_input_time;
1545 int64_t i_seekpoint_time;
1547 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1549 i_seekpoint = p_access->info.i_seekpoint;
1550 i_seekpoint_time = p_input->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1551 if( i_seekpoint_time >= 0 &&
1552 demux2_Control( p_demux,
1553 DEMUX_GET_TIME, &i_input_time ) )
1555 if ( i_input_time < i_seekpoint_time + 3000000 )
1561 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1562 i_seekpoint = p_access->info.i_seekpoint + 1;
1564 i_seekpoint = val.i_int;
1566 if( i_seekpoint >= 0 && i_seekpoint <
1567 p_input->input.title[p_access->info.i_title]->i_seekpoint )
1569 access2_Control( p_access, ACCESS_SET_SEEKPOINT, i_seekpoint );
1570 stream_AccessReset( p_input->input.p_stream );
1572 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1573 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1578 case INPUT_CONTROL_ADD_SLAVE:
1579 if( val.psz_string )
1581 input_source_t *slave = InputSourceNew( p_input );
1583 if( !InputSourceInit( p_input, slave, val.psz_string, NULL,
1586 vlc_meta_t *p_meta_new = NULL;
1591 msg_Dbg( p_input, "adding %s as slave on the fly",
1595 if( demux2_Control( p_input->input.p_demux,
1596 DEMUX_GET_TIME, &i_time ) )
1598 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1599 InputSourceClean( p_input, slave );
1603 if( demux2_Control( slave->p_demux,
1604 DEMUX_SET_TIME, i_time ) )
1606 msg_Err( p_input, "seek failed for new slave" );
1607 InputSourceClean( p_input, slave );
1613 /* Get meta (access and demux) */
1614 if( access2_Control( slave->p_access,
1615 ACCESS_GET_META, &p_meta_new ) )
1617 if( !demux2_Control( slave->p_demux,
1618 DEMUX_GET_META, &p_meta ) )
1622 vlc_meta_Merge( p_meta_new, p_meta );
1623 vlc_meta_Delete( p_meta );
1627 p_meta_new = p_meta;
1633 if( p_input->p_meta )
1635 vlc_meta_Merge( p_input->p_meta, p_meta_new );
1636 vlc_meta_Delete( p_meta_new );
1640 p_input->p_meta = p_meta_new;
1642 UpdateMeta( p_input, VLC_FALSE );
1645 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
1649 msg_Warn( p_input, "failed to add %s as slave",
1653 free( val.psz_string );
1657 case INPUT_CONTROL_SET_BOOKMARK:
1659 msg_Err( p_input, "not yet implemented" );
1663 return b_force_update;
1666 /*****************************************************************************
1668 *****************************************************************************/
1669 static int UpdateFromDemux( input_thread_t *p_input )
1671 demux_t *p_demux = p_input->input.p_demux;
1674 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1676 v.i_int = p_demux->info.i_title;
1677 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1679 input_ControlVarTitle( p_input, p_demux->info.i_title );
1681 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1683 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1685 v.i_int = p_demux->info.i_seekpoint;
1686 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1688 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1690 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1692 /* Hmmm only works with master input */
1693 if( p_input->input.p_demux == p_demux )
1695 int i_title_end = p_input->input.i_title_end -
1696 p_input->input.i_title_offset;
1697 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1698 p_input->input.i_seekpoint_offset;
1700 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
1702 if( p_demux->info.i_title > i_title_end ||
1703 ( p_demux->info.i_title == i_title_end &&
1704 p_demux->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1706 else if( i_seekpoint_end >=0 )
1708 if( p_demux->info.i_seekpoint > i_seekpoint_end ) return 0;
1710 else if( i_title_end >= 0 )
1712 if( p_demux->info.i_title > i_title_end ) return 0;
1719 /*****************************************************************************
1721 *****************************************************************************/
1722 static int UpdateFromAccess( input_thread_t *p_input )
1724 access_t *p_access = p_input->input.p_access;
1727 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1729 v.i_int = p_access->info.i_title;
1730 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1732 input_ControlVarTitle( p_input, p_access->info.i_title );
1734 stream_AccessUpdate( p_input->input.p_stream );
1736 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1738 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1740 v.i_int = p_access->info.i_seekpoint;
1741 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1743 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1745 if( p_access->info.i_update & INPUT_UPDATE_META )
1747 /* TODO maybe multi - access ? */
1749 if( !access2_Control( p_input->input.p_access,ACCESS_GET_META,&p_meta))
1751 if( p_input->p_meta )
1753 vlc_meta_Merge( p_input->p_meta, p_meta );
1754 vlc_meta_Delete( p_meta );
1758 p_input->p_meta = p_meta;
1761 UpdateMeta( p_input, VLC_FALSE );
1762 var_SetBool( p_input, "item-change", p_input->input.p_item->i_id );
1764 p_access->info.i_update &= ~INPUT_UPDATE_META;
1767 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1769 /* Hmmm only works with master input */
1770 if( p_input->input.p_access == p_access )
1772 int i_title_end = p_input->input.i_title_end -
1773 p_input->input.i_title_offset;
1774 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1775 p_input->input.i_seekpoint_offset;
1777 if( i_title_end >= 0 && i_seekpoint_end >=0 )
1779 if( p_access->info.i_title > i_title_end ||
1780 ( p_access->info.i_title == i_title_end &&
1781 p_access->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1783 else if( i_seekpoint_end >=0 )
1785 if( p_access->info.i_seekpoint > i_seekpoint_end ) return 0;
1787 else if( i_title_end >= 0 )
1789 if( p_access->info.i_title > i_title_end ) return 0;
1796 /*****************************************************************************
1798 *****************************************************************************/
1799 static int UpdateMeta( input_thread_t *p_input, vlc_bool_t b_quick )
1801 vlc_meta_t *p_meta = p_input->p_meta;
1804 if( !p_meta || p_meta->i_meta == 0 )
1807 if( !b_quick ) msg_Dbg( p_input, "meta information:" );
1808 for( i = 0; i < p_meta->i_meta; i++ )
1811 msg_Dbg( p_input, " - '%s' = '%s'",
1812 _(p_meta->name[i]), p_meta->value[i] );
1814 if( !strcmp(p_meta->name[i], VLC_META_TITLE) && p_meta->value[i] &&
1815 !p_input->input.p_item->b_fixed_name )
1816 input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
1818 if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
1819 input_Control( p_input, INPUT_ADD_INFO, _("General"),
1820 _("Author"), p_meta->value[i] );
1822 input_Control( p_input, INPUT_ADD_INFO, _("Meta-information"),
1823 _(p_meta->name[i]), "%s", p_meta->value[i] );
1826 for( i = 0; i < p_meta->i_track; i++ )
1828 vlc_meta_t *tk = p_meta->track[i];
1831 if( tk->i_meta > 0 )
1833 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
1835 msg_Dbg( p_input, " - track[%d]:", i );
1837 sprintf( psz_cat, "%s %d", _("Stream"), i );
1838 for( j = 0; j < tk->i_meta; j++ )
1840 msg_Dbg( p_input, " - '%s' = '%s'", _(tk->name[j]),
1843 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1844 _(tk->name[j]), "%s", tk->value[j] );
1849 if( p_input->p_sout && p_input->p_sout->p_meta == NULL )
1851 p_input->p_sout->p_meta = vlc_meta_Duplicate( p_meta );
1857 /*****************************************************************************
1859 *****************************************************************************/
1860 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length,
1861 vlc_bool_t b_quick )
1863 playlist_t *p_playlist;
1864 char psz_buffer[MSTRTIME_MAX_SIZE];
1866 vlc_mutex_lock( &p_input->input.p_item->lock );
1867 p_input->input.p_item->i_duration = i_length;
1868 vlc_mutex_unlock( &p_input->input.p_item->lock );
1870 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
1874 var_SetInteger( p_playlist, "item-change",
1875 p_input->input.p_item->i_id );
1876 vlc_object_release( p_playlist );
1879 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
1880 msecstotimestr( psz_buffer, i_length / 1000 ) );
1883 /*****************************************************************************
1885 *****************************************************************************/
1886 static input_source_t *InputSourceNew( input_thread_t *p_input )
1888 input_source_t *in = malloc( sizeof( input_source_t ) );
1891 in->p_access = NULL;
1892 in->p_stream = NULL;
1894 in->b_title_demux = VLC_FALSE;
1897 in->b_can_pace_control = VLC_TRUE;
1898 in->b_eof = VLC_FALSE;
1899 in->i_cr_average = 0;
1904 /*****************************************************************************
1906 *****************************************************************************/
1907 static int InputSourceInit( input_thread_t *p_input,
1908 input_source_t *in, char *psz_mrl,
1909 char *psz_forced_demux, vlc_bool_t b_quick )
1911 char *psz_dup = strdup( psz_mrl );
1920 MRLSplit( p_input, psz_dup, &psz_access, &psz_demux, &psz_path );
1922 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
1923 psz_mrl, psz_access, psz_demux, psz_path );
1925 /* Hack to allow udp://@:port syntax */
1927 (strncmp( psz_access, "udp", 3 ) &&
1928 strncmp( psz_access, "rtp", 3 )) )
1930 /* Find optional titles and seekpoints */
1931 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
1932 &in->i_seekpoint_start, &in->i_seekpoint_end );
1934 if( psz_forced_demux && *psz_forced_demux )
1935 psz_demux = psz_forced_demux;
1937 /* Try access_demux if no demux given */
1938 if( *psz_demux == '\0' )
1940 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
1941 NULL, p_input->p_es_out, VLC_FALSE );
1947 msg_Dbg( p_input, "trying to preparse %s", psz_path );
1948 psz_demux = strdup( "" );
1949 psz_access = strdup( "file" );
1954 int64_t i_pts_delay;
1956 /* Get infos from access_demux */
1957 demux2_Control( in->p_demux,
1958 DEMUX_GET_PTS_DELAY, &i_pts_delay );
1959 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
1961 in->b_title_demux = VLC_TRUE;
1962 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
1963 &in->title, &in->i_title,
1964 &in->i_title_offset, &in->i_seekpoint_offset ) )
1969 demux2_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
1970 &in->b_can_pace_control );
1971 demux2_Control( in->p_demux, DEMUX_CAN_PAUSE,
1975 demux2_Control( in->p_demux, DEMUX_CAN_SEEK,
1981 int64_t i_pts_delay;
1983 /* Now try a real access */
1984 in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path,
1987 /* Access failed, URL encoded ? */
1988 if( in->p_access == NULL && strchr( psz_path, '%' ) )
1990 DecodeUrl( psz_path );
1992 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
1993 psz_access, psz_demux, psz_path );
1995 in->p_access = access2_New( p_input,
1996 psz_access, psz_demux, psz_path,
1999 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
2000 * are forbidden in filenames on Win32. */
2002 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
2003 if( in->p_access == NULL &&
2004 *psz_access == '\0' && ( *psz_demux || *psz_path ) )
2007 psz_dup = strdup( psz_mrl );
2012 in->p_access = access2_New( p_input,
2013 psz_access, psz_demux, psz_path,
2018 if( in->p_access == NULL )
2020 msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
2024 /* Get infos from access */
2027 access2_Control( in->p_access,
2028 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2029 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2031 in->b_title_demux = VLC_FALSE;
2032 if( access2_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2033 &in->title, &in->i_title,
2034 &in->i_title_offset, &in->i_seekpoint_offset ) )
2040 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2041 &in->b_can_pace_control );
2042 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
2044 access2_Control( in->p_access, ACCESS_CAN_SEEK,
2046 var_Set( p_input, "seekable", val );
2049 /* Create the stream_t */
2050 in->p_stream = stream_AccessNew( in->p_access, b_quick );
2051 if( in->p_stream == NULL )
2053 msg_Warn( p_input, "cannot create a stream_t from access" );
2057 /* Open a demuxer */
2058 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2060 psz_demux = in->p_access->psz_demux;
2062 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2063 in->p_stream, p_input->p_es_out, b_quick );
2064 if( in->p_demux == NULL )
2066 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2067 psz_access, psz_demux, psz_path );
2071 /* TODO get title from demux */
2072 if( !b_quick && in->i_title <= 0 )
2074 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2075 &in->title, &in->i_title,
2076 &in->i_title_offset, &in->i_seekpoint_offset ))
2083 in->b_title_demux = VLC_TRUE;
2088 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2089 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2096 demux2_Delete( in->p_demux );
2099 stream_AccessDelete( in->p_stream );
2102 access2_Delete( in->p_access );
2105 return VLC_EGENERIC;
2108 /*****************************************************************************
2110 *****************************************************************************/
2111 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
2114 demux2_Delete( in->p_demux );
2117 stream_AccessDelete( in->p_stream );
2120 access2_Delete( in->p_access );
2122 if( in->i_title > 0 )
2125 for( i = 0; i < in->i_title; i++ )
2127 vlc_input_title_Delete( in->title[i] );
2133 static void SlaveDemux( input_thread_t *p_input )
2137 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2139 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2143 for( i = 0; i < p_input->i_slave; i++ )
2145 input_source_t *in = p_input->slave[i];
2151 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2156 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2158 msg_Err( p_input, "slave[%d] doesn't like "
2159 "DEMUX_GET_TIME -> EOF", i );
2164 if( i_stime >= i_time )
2167 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
2173 i_ret = in->p_demux->pf_demux( in->p_demux );
2178 msg_Dbg( p_input, "slave %d EOF", i );
2179 in->b_eof = VLC_TRUE;
2184 static void SlaveSeek( input_thread_t *p_input )
2189 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2191 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2195 for( i = 0; i < p_input->i_slave; i++ )
2197 input_source_t *in = p_input->slave[i];
2199 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2201 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2202 in->b_eof = VLC_TRUE;
2206 /*****************************************************************************
2208 *****************************************************************************/
2209 static vlc_meta_t *InputMetaUser( input_thread_t *p_input )
2214 if( ( p_meta = vlc_meta_New() ) == NULL )
2217 /* Get meta information from user */
2218 #define GET_META( c, s ) \
2219 var_Get( p_input, (s), &val ); \
2220 if( *val.psz_string ) \
2221 vlc_meta_Add( p_meta, c, val.psz_string ); \
2222 free( val.psz_string )
2224 GET_META( VLC_META_TITLE, "meta-title" );
2225 GET_META( VLC_META_AUTHOR, "meta-author" );
2226 GET_META( VLC_META_ARTIST, "meta-artist" );
2227 GET_META( VLC_META_GENRE, "meta-genre" );
2228 GET_META( VLC_META_COPYRIGHT, "meta-copyright" );
2229 GET_META( VLC_META_DESCRIPTION, "meta-description" );
2230 GET_META( VLC_META_DATE, "meta-date" );
2231 GET_META( VLC_META_URL, "meta-url" );
2237 /*****************************************************************************
2238 * DecodeUrl: decode a given encoded url
2239 *****************************************************************************/
2240 static void DecodeUrl( char *psz )
2242 char *dup = strdup( psz );
2260 *psz++ = strtol( val, NULL, 16 );
2262 else if( *p == '+' )
2276 /*****************************************************************************
2277 * ParseOption: parses the options for the input
2278 *****************************************************************************
2279 * This function parses the input (config) options and creates their associated
2281 * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
2282 * bar is the value of the option.
2283 *****************************************************************************/
2284 static void ParseOption( input_thread_t *p_input, const char *psz_option )
2286 char *psz_name = (char *)psz_option;
2287 char *psz_value = strchr( psz_option, '=' );
2288 int i_name_len, i_type;
2289 vlc_bool_t b_isno = VLC_FALSE;
2292 if( psz_value ) i_name_len = psz_value - psz_option;
2293 else i_name_len = strlen( psz_option );
2295 /* It's too much of an hassle to remove the ':' when we parse
2296 * the cmd line :) */
2297 if( i_name_len && *psz_name == ':' )
2303 if( i_name_len == 0 ) return;
2305 psz_name = strndup( psz_name, i_name_len );
2306 if( psz_value ) psz_value++;
2308 i_type = config_GetType( p_input, psz_name );
2310 if( !i_type && !psz_value )
2312 /* check for "no-foo" or "nofoo" */
2313 if( !strncmp( psz_name, "no-", 3 ) )
2315 memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
2317 else if( !strncmp( psz_name, "no", 2 ) )
2319 memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
2321 else goto cleanup; /* Option doesn't exist */
2324 i_type = config_GetType( p_input, psz_name );
2326 if( !i_type ) goto cleanup; /* Option doesn't exist */
2328 else if( !i_type ) goto cleanup; /* Option doesn't exist */
2330 if( ( i_type != VLC_VAR_BOOL ) &&
2331 ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */
2333 /* Create the variable in the input object.
2334 * Children of the input object will be able to retreive this value
2335 * thanks to the inheritance property of the object variables. */
2336 var_Create( p_input, psz_name, i_type );
2341 val.b_bool = !b_isno;
2344 case VLC_VAR_INTEGER:
2345 val.i_int = atoi( psz_value );
2349 val.f_float = atof( psz_value );
2352 case VLC_VAR_STRING:
2353 case VLC_VAR_MODULE:
2355 case VLC_VAR_DIRECTORY:
2356 val.psz_string = psz_value;
2364 var_Set( p_input, psz_name, val );
2366 msg_Dbg( p_input, "set input option: %s to %s", psz_name,
2367 psz_value ? psz_value : ( val.b_bool ? "true" : "false") );
2370 if( psz_name ) free( psz_name );
2374 /*****************************************************************************
2375 * MRLSplit: parse the access, demux and url part of the
2376 * Media Resource Locator.
2377 *****************************************************************************/
2378 static void MRLSplit( input_thread_t *p_input, char *psz_dup,
2379 char **ppsz_access, char **ppsz_demux, char **ppsz_path )
2381 char *psz_access = NULL;
2382 char *psz_demux = NULL;
2383 char *psz_path = NULL;
2384 char *psz, *psz_check;
2386 psz = strchr( psz_dup, ':' );
2388 /* '@' not allowed in access/demux part */
2389 psz_check = strchr( psz_dup, '@' );
2390 if( psz_check && psz_check < psz ) psz = 0;
2392 #if defined( WIN32 ) || defined( UNDER_CE )
2393 if( psz - psz_dup == 1 )
2395 msg_Warn( p_input, "drive letter %c: found in source", *psz_dup );
2404 if( psz[0] == '/' && psz[1] == '/' ) psz += 2;
2408 psz = strchr( psz_dup, '/' );
2415 psz_access = psz_dup;
2422 if( !psz_access ) *ppsz_access = "";
2423 else *ppsz_access = psz_access;
2425 if( !psz_demux ) *ppsz_demux = "";
2426 else *ppsz_demux = psz_demux;
2428 if( !psz_path ) *ppsz_path = "";
2429 else *ppsz_path = psz_path;
2432 /*****************************************************************************
2433 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
2436 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
2437 *****************************************************************************/
2438 static void MRLSections( input_thread_t *p_input, char *psz_source,
2439 int *pi_title_start, int *pi_title_end,
2440 int *pi_chapter_start, int *pi_chapter_end )
2442 char *psz, *psz_end, *psz_next, *psz_check;
2444 *pi_title_start = *pi_title_end = -1;
2445 *pi_chapter_start = *pi_chapter_end = -1;
2447 /* Start by parsing titles and chapters */
2448 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
2450 /* Check we are really dealing with a title/chapter section */
2451 psz_check = psz + 1;
2452 if( !*psz_check ) return;
2453 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2454 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
2455 if( *psz_check == ':' && ++psz_check )
2456 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2457 if( *psz_check != '-' && *psz_check ) return;
2458 if( *psz_check == '-' && ++psz_check )
2459 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2460 if( *psz_check != ':' && *psz_check ) return;
2461 if( *psz_check == ':' && ++psz_check )
2462 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2463 if( *psz_check ) return;
2465 /* Separate start and end */
2467 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
2469 /* Look for the start title */
2470 *pi_title_start = strtol( psz, &psz_next, 0 );
2471 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
2472 *pi_title_end = *pi_title_start;
2475 /* Look for the start chapter */
2477 *pi_chapter_start = strtol( psz, &psz_next, 0 );
2478 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
2479 *pi_chapter_end = *pi_chapter_start;
2483 /* Look for the end title */
2484 *pi_title_end = strtol( psz_end, &psz_next, 0 );
2485 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
2488 /* Look for the end chapter */
2489 if( *psz_end ) psz_end++;
2490 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
2491 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
2494 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
2495 psz_source, *pi_title_start, *pi_chapter_start,
2496 *pi_title_end, *pi_chapter_end );
2500 /***********************************************************************
2501 * Info management functions
2502 ***********************************************************************/
2503 char *vlc_input_item_GetInfo( input_item_t *p_i,
2504 const char *psz_cat,
2505 const char *psz_name )
2509 vlc_mutex_lock( &p_i->lock );
2511 for( i = 0 ; i< p_i->i_categories ; i++ )
2513 info_category_t *p_cat = p_i->pp_categories[i];
2515 if( !psz_cat || strcmp( p_cat->psz_name, psz_cat ) )
2518 for( j = 0; j < p_cat->i_infos ; j++ )
2520 if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
2522 vlc_mutex_unlock( &p_i->lock );
2523 return strdup( p_cat->pp_infos[j]->psz_value );
2527 vlc_mutex_unlock( &p_i->lock );
2528 return strdup( "" );
2531 int vlc_input_item_AddInfo( input_item_t *p_i,
2532 const char *psz_cat,
2533 const char *psz_name,
2534 const char *psz_format, ... )
2538 info_t *p_info = NULL;
2539 info_category_t *p_cat = NULL ;
2541 vlc_mutex_lock( &p_i->lock );
2543 for( i = 0 ; i < p_i->i_categories ; i ++ )
2545 if( !strcmp( p_i->pp_categories[i]->psz_name, psz_cat ) )
2547 p_cat = p_i->pp_categories[i];
2553 if( !(p_cat = (info_category_t *)malloc( sizeof(info_category_t) )) )
2555 vlc_mutex_unlock( &p_i->lock );
2556 return VLC_EGENERIC;
2558 p_cat->psz_name = strdup( psz_cat );
2560 p_cat->pp_infos = 0;
2561 INSERT_ELEM( p_i->pp_categories, p_i->i_categories, p_i->i_categories,
2565 for( i = 0; i< p_cat->i_infos; i++ )
2567 if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
2569 p_info = p_cat->pp_infos[i];
2576 if( ( p_info = (info_t *)malloc( sizeof( info_t ) ) ) == NULL )
2578 vlc_mutex_unlock( &p_i->lock );
2579 return VLC_EGENERIC;
2581 INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
2582 p_info->psz_name = strdup( psz_name );
2586 if( p_info->psz_value ) free( p_info->psz_value );
2589 va_start( args, psz_format );
2590 vasprintf( &p_info->psz_value, psz_format, args);
2593 vlc_mutex_unlock( &p_i->lock );