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 MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
67 static input_source_t *InputSourceNew( input_thread_t *);
68 static int InputSourceInit( input_thread_t *, input_source_t *,
69 char *, char *psz_forced_demux,
71 static void InputSourceClean( input_thread_t *, input_source_t * );
73 static void SlaveDemux( input_thread_t *p_input );
74 static void SlaveSeek( input_thread_t *p_input );
76 static vlc_meta_t *InputMetaUser( input_thread_t *p_input );
78 /*****************************************************************************
79 * input_CreateThread: creates a new input thread
80 *****************************************************************************
81 * This function creates a new input, and returns a pointer
82 * to its description. On error, it returns NULL.
84 * Variables for _public_ use:
87 * - rate,rate-slower, rate-faster
88 * - position, position-offset
90 * - title,title-next,title-prev
91 * - chapter,chapter-next, chapter-prev
92 * - program, audio-es, video-es, spu-es
93 * - audio-delay, spu-delay
98 * - seekable (if you can seek, it doesn't say if 'bar display' has be shown or not, for that check position != 0.0)
99 * * For intf callback upon changes
101 * TODO explain when Callback is called
102 * TODO complete this list (?)
103 *****************************************************************************/
104 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
105 input_item_t *p_item )
108 input_thread_t *p_input; /* thread descriptor */
112 /* Allocate descriptor */
113 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
114 if( p_input == NULL )
116 msg_Err( p_parent, "out of memory" );
120 /* Init Common fields */
121 p_input->b_eof = VLC_FALSE;
122 p_input->b_can_pace_control = VLC_TRUE;
123 p_input->i_start = 0;
126 p_input->i_title = 0;
127 p_input->title = NULL;
128 p_input->i_title_offset = p_input->i_seekpoint_offset = 0;
129 p_input->i_state = INIT_S;
130 p_input->i_rate = INPUT_RATE_DEFAULT;
131 p_input->i_bookmark = 0;
132 p_input->bookmark = NULL;
133 p_input->p_meta = NULL;
134 p_input->p_es_out = NULL;
135 p_input->p_sout = NULL;
136 p_input->b_out_pace_control = VLC_FALSE;
137 p_input->i_pts_delay = 0;
139 /* Init Input fields */
140 p_input->input.p_item = p_item;
141 p_input->input.p_access = NULL;
142 p_input->input.p_stream = NULL;
143 p_input->input.p_demux = NULL;
144 p_input->input.b_title_demux = VLC_FALSE;
145 p_input->input.i_title = 0;
146 p_input->input.title = NULL;
147 p_input->input.i_title_offset = p_input->input.i_seekpoint_offset = 0;
148 p_input->input.b_can_pace_control = VLC_TRUE;
149 p_input->input.b_eof = VLC_FALSE;
150 p_input->input.i_cr_average = 0;
153 p_input->i_slave = 0;
154 p_input->slave = NULL;
156 /* Init control buffer */
157 vlc_mutex_init( p_input, &p_input->lock_control );
158 p_input->i_control = 0;
160 /* Parse input options */
161 vlc_mutex_lock( &p_item->lock );
162 for( i = 0; i < p_item->i_options; i++ )
164 ParseOption( p_input, p_item->ppsz_options[i] );
166 vlc_mutex_unlock( &p_item->lock );
168 /* Create Object Variables for private use only */
169 input_ConfigVarInit( p_input );
171 /* Create Objects variables for public Get and Set */
172 input_ControlVarInit( p_input );
173 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
176 var_Get( p_input, "bookmarks", &val );
179 /* FIXME: have a common cfg parsing routine used by sout and others */
180 char *psz_parser, *psz_start, *psz_end;
181 psz_parser = val.psz_string;
182 while( (psz_start = strchr( psz_parser, '{' ) ) )
184 seekpoint_t *p_seekpoint = vlc_seekpoint_New();
187 psz_end = strchr( psz_start, '}' );
188 if( !psz_end ) break;
189 psz_parser = psz_end + 1;
190 backup = *psz_parser;
194 while( (psz_end = strchr( psz_start, ',' ) ) )
197 if( !strncmp( psz_start, "name=", 5 ) )
199 p_seekpoint->psz_name = psz_start + 5;
201 else if( !strncmp( psz_start, "bytes=", 6 ) )
203 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
205 else if( !strncmp( psz_start, "time=", 5 ) )
207 p_seekpoint->i_time_offset = atoll(psz_start + 5) * 1000000;
209 psz_start = psz_end + 1;
211 msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
212 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
213 p_seekpoint->i_time_offset );
214 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
215 vlc_seekpoint_Delete( p_seekpoint );
216 *psz_parser = backup;
218 free( val.psz_string );
221 /* Now we can attach our new input */
222 vlc_object_attach( p_input, p_parent );
224 /* Create thread and wait for its readiness. */
225 if( vlc_thread_create( p_input, "input", Run,
226 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
228 msg_Err( p_input, "cannot create input thread" );
229 vlc_object_detach( p_input );
230 vlc_object_destroy( p_input );
237 /*****************************************************************************
238 * input_PreParse: Lightweight input for playlist item preparsing
239 *****************************************************************************/
240 int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
242 input_thread_t *p_input; /* thread descriptor */
245 /* Allocate descriptor */
246 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
247 if( p_input == NULL )
249 msg_Err( p_parent, "out of memory" );
253 /* Init Common fields */
254 p_input->b_eof = VLC_FALSE;
255 p_input->b_can_pace_control = VLC_TRUE;
256 p_input->i_start = 0;
259 p_input->i_title = 0;
260 p_input->title = NULL;
261 p_input->i_title_offset = p_input->i_seekpoint_offset = 0;
262 p_input->i_state = INIT_S;
263 p_input->i_rate = INPUT_RATE_DEFAULT;
264 p_input->i_bookmark = 0;
265 p_input->bookmark = NULL;
266 p_input->p_meta = NULL;
267 p_input->p_es_out = NULL;
268 p_input->p_sout = NULL;
269 p_input->b_out_pace_control = VLC_FALSE;
270 p_input->i_pts_delay = 0;
272 /* Init Input fields */
273 p_input->input.p_item = p_item;
274 p_input->input.p_access = NULL;
275 p_input->input.p_stream = NULL;
276 p_input->input.p_demux = NULL;
277 p_input->input.b_title_demux = VLC_FALSE;
278 p_input->input.i_title = 0;
279 p_input->input.title = NULL;
280 p_input->input.i_title_offset = p_input->input.i_seekpoint_offset = 0;
281 p_input->input.b_can_pace_control = VLC_TRUE;
282 p_input->input.b_eof = VLC_FALSE;
283 p_input->input.i_cr_average = 0;
286 p_input->i_slave = 0;
287 p_input->slave = NULL;
289 /* Init control buffer */
290 vlc_mutex_init( p_input, &p_input->lock_control );
291 p_input->i_control = 0;
293 /* Parse input options */
294 vlc_mutex_lock( &p_item->lock );
295 for( i = 0; i < p_item->i_options; i++ )
297 ParseOption( p_input, p_item->ppsz_options[i] );
299 vlc_mutex_unlock( &p_item->lock );
301 /* Create Object Variables for private use only */
302 input_ConfigVarInit( p_input );
303 input_ControlVarInit( p_input );
305 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
307 /* Now we can attach our new input */
308 vlc_object_attach( p_input, p_parent );
310 Init( p_input, VLC_TRUE );
312 /* Clean up master */
313 InputSourceClean( p_input, &p_input->input );
315 /* Kill access and demux */
316 if( p_input->input.p_access ) p_input->input.p_access->b_die = VLC_TRUE;
317 if( p_input->input.p_demux ) p_input->input.p_access->b_die = VLC_TRUE;
319 /* Unload all modules */
320 if( p_input->p_es_out ) input_EsOutDelete( p_input->p_es_out );
323 if( p_input->p_meta ) vlc_meta_Delete( p_input->p_meta );
325 vlc_object_detach( p_input );
326 vlc_object_destroy( p_input );
331 /*****************************************************************************
332 * input_StopThread: mark an input thread as zombie
333 *****************************************************************************
334 * This function should not return until the thread is effectively cancelled.
335 *****************************************************************************/
336 void input_StopThread( input_thread_t *p_input )
341 /* Set die for input */
342 p_input->b_die = VLC_TRUE;
344 /* We cannot touch p_input fields directly (we can from another thread),
345 * so use the vlc_object_find way, it's perfectly safe */
347 /* Set die for all access */
348 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );
349 for( i = 0; i < p_list->i_count; i++ )
351 p_list->p_values[i].p_object->b_die = VLC_TRUE;
353 vlc_list_release( p_list );
355 /* Set die for all stream */
356 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
357 for( i = 0; i < p_list->i_count; i++ )
359 p_list->p_values[i].p_object->b_die = VLC_TRUE;
361 vlc_list_release( p_list );
363 /* Set die for all demux */
364 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
365 for( i = 0; i < p_list->i_count; i++ )
367 p_list->p_values[i].p_object->b_die = VLC_TRUE;
369 vlc_list_release( p_list );
371 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
374 /*****************************************************************************
375 * input_DestroyThread: mark an input thread as zombie
376 *****************************************************************************
377 * This function should not return until the thread is effectively cancelled.
378 *****************************************************************************/
379 void input_DestroyThread( input_thread_t *p_input )
381 /* Join the thread */
382 vlc_thread_join( p_input );
384 /* Delete input lock (only after thread joined) */
385 vlc_mutex_destroy( &p_input->lock_control );
387 /* TODO: maybe input_DestroyThread should also delete p_input instead
388 * of the playlist but I'm not sure if it's possible */
391 /*****************************************************************************
392 * Run: main thread loop
393 *****************************************************************************
394 * Thread in charge of processing the network packets and demultiplexing.
397 * read subtitle support (XXX take care of spu-delay in the right way).
398 * multi-input support (XXX may be done with subs)
399 *****************************************************************************/
400 static int Run( input_thread_t *p_input )
402 int64_t i_intf_update = 0;
404 /* Signal that the thread is launched */
405 vlc_thread_ready( p_input );
407 if( Init( p_input, VLC_FALSE ) )
409 /* If we failed, wait before we are killed, and exit */
410 p_input->b_error = VLC_TRUE;
414 /* Tell we're dead */
415 p_input->b_dead = VLC_TRUE;
421 while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
423 vlc_bool_t b_force_update = VLC_FALSE;
429 if( p_input->i_state != PAUSE_S )
431 if( p_input->i_stop <= 0 || p_input->i_time < p_input->i_stop )
432 i_ret=p_input->input.p_demux->pf_demux(p_input->input.p_demux);
439 if( p_input->input.b_title_demux &&
440 p_input->input.p_demux->info.i_update )
442 i_ret = UpdateFromDemux( p_input );
443 b_force_update = VLC_TRUE;
445 else if( !p_input->input.b_title_demux &&
446 p_input->input.p_access &&
447 p_input->input.p_access->info.i_update )
449 i_ret = UpdateFromAccess( p_input );
450 b_force_update = VLC_TRUE;
454 if( i_ret == 0 ) /* EOF */
458 var_Get( p_input, "input-repeat", &repeat );
459 if( repeat.i_int == 0 )
461 /* End of file - we do not set b_die because only the
462 * playlist is allowed to do so. */
463 msg_Dbg( p_input, "EOF reached" );
464 p_input->input.b_eof = VLC_TRUE;
468 msg_Dbg( p_input, "repeating the same input (%d)",
470 if( repeat.i_int > 0 )
473 var_Set( p_input, "input-repeat", repeat );
476 /* Seek to start title/seekpoint */
477 val.i_int = p_input->input.i_title_start -
478 p_input->input.i_title_offset;
479 if( val.i_int < 0 || val.i_int >= p_input->input.i_title )
481 input_ControlPush( p_input,
482 INPUT_CONTROL_SET_TITLE, &val );
484 val.i_int = p_input->input.i_seekpoint_start -
485 p_input->input.i_seekpoint_offset;
486 if( val.i_int > 0 /* TODO: check upper boundary */ )
487 input_ControlPush( p_input,
488 INPUT_CONTROL_SET_SEEKPOINT, &val );
490 /* Seek to start position */
491 if( p_input->i_start > 0 )
493 val.i_time = p_input->i_start;
494 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
500 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
507 p_input->b_error = VLC_TRUE;
510 if( i_ret > 0 && p_input->i_slave > 0 )
512 SlaveDemux( p_input );
522 vlc_mutex_lock( &p_input->lock_control );
523 ControlReduce( p_input );
524 while( !ControlPopNoLock( p_input, &i_type, &val ) )
526 msg_Dbg( p_input, "control type=%d", i_type );
527 if( Control( p_input, i_type, val ) )
528 b_force_update = VLC_TRUE;
530 vlc_mutex_unlock( &p_input->lock_control );
532 if( b_force_update || i_intf_update < mdate() )
536 int64_t i_time, i_length;
537 /* update input status variables */
538 if( !demux2_Control( p_input->input.p_demux,
539 DEMUX_GET_POSITION, &f_pos ) )
541 val.f_float = (float)f_pos;
542 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
544 if( !demux2_Control( p_input->input.p_demux,
545 DEMUX_GET_TIME, &i_time ) )
547 p_input->i_time = i_time;
549 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
551 if( !demux2_Control( p_input->input.p_demux,
552 DEMUX_GET_LENGTH, &i_length ) )
555 var_Get( p_input, "length", &old_val );
556 val.i_time = i_length;
557 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
559 if( old_val.i_time != val.i_time )
561 UpdateItemLength( p_input, i_length, VLC_TRUE );
565 var_SetBool( p_input, "intf-change", VLC_TRUE );
566 i_intf_update = mdate() + I64C(150000);
570 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
572 /* We have finish to demux data but not to play them */
573 while( !p_input->b_die )
575 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
578 msg_Dbg( p_input, "waiting decoder fifos to empty" );
580 msleep( INPUT_IDLE_SLEEP );
583 /* We have finished */
584 p_input->b_eof = VLC_TRUE;
587 /* Wait we are asked to die */
588 if( !p_input->b_die )
600 static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
606 vlc_meta_t *p_meta, *p_meta_tmp;
610 /* Initialize optional stream output. (before access/demuxer)
611 * XXX: we add a special case if the uri starts by vlc.
612 * else 'vlc in.file --sout "" vlc:quit' cannot work (the output will
613 * be destroyed in case of a file).
614 * (this will break playing of file starting by 'vlc:' but I don't
615 * want to add more logic, just force file by file:// or code it ;)
619 psz = var_GetString( p_input, "sout" );
620 if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
622 p_input->p_sout = sout_NewInstance( p_input, psz );
623 if( p_input->p_sout == NULL )
625 msg_Err( p_input, "cannot start stream output instance, " \
635 p_input->p_es_out = input_EsOutNew( p_input );
636 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
637 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
639 if( InputSourceInit( p_input, &p_input->input,
640 p_input->input.p_item->psz_uri, NULL, b_quick ) )
645 /* Create global title (from master) */
648 p_input->i_title = p_input->input.i_title;
649 p_input->title = p_input->input.title;
650 p_input->i_title_offset = p_input->input.i_title_offset;
651 p_input->i_seekpoint_offset = p_input->input.i_seekpoint_offset;
652 if( p_input->i_title > 0 )
654 /* Setup variables */
655 input_ControlVarNavigation( p_input );
656 input_ControlVarTitle( p_input, 0 );
660 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
661 p_input->b_can_pause = p_input->input.b_can_pause;
664 if( p_input->i_pts_delay <= 0 )
665 p_input->i_pts_delay = DEFAULT_PTS_DELAY;
667 /* If the desynchronisation requested by the user is < 0, we need to
668 * cache more data. */
669 var_Get( p_input, "audio-desync", &val );
670 if( val.i_int < 0 ) p_input->i_pts_delay -= (val.i_int * 1000);
672 /* Update cr_average depending on the caching */
673 p_input->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000);
674 p_input->input.i_cr_average /= 10;
675 if( p_input->input.i_cr_average <= 0 ) p_input->input.i_cr_average = 1;
678 /* Load master infos */
680 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH,
681 &val.i_time ) && val.i_time > 0 )
683 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
684 UpdateItemLength( p_input, val.i_time, b_quick );
685 p_input->input.p_item->i_duration = val.i_time;
688 /* Start title/chapter */
691 val.i_int = p_input->input.i_title_start -
692 p_input->input.i_title_offset;
693 if( val.i_int > 0 && val.i_int < p_input->input.i_title )
694 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
695 val.i_int = p_input->input.i_seekpoint_start -
696 p_input->input.i_seekpoint_offset;
697 if( val.i_int > 0 /* TODO: check upper boundary */ )
698 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
702 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
704 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
707 if( p_input->i_start > 0 )
709 if( p_input->i_start >= val.i_time )
711 msg_Warn( p_input, "invalid start-time ignored" );
717 msg_Dbg( p_input, "starting at time: %ds",
718 (int)( p_input->i_start / I64C(1000000) ) );
720 s.i_time = p_input->i_start;
721 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
724 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
726 msg_Warn( p_input, "invalid stop-time ignored" );
732 /* Get fps and set it if not already set */
733 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
736 float f_requested_fps;
738 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
739 var_SetFloat( p_input, "sub-original-fps", f_fps );
741 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
742 if( f_requested_fps != f_fps )
744 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
746 var_SetFloat( p_input, "sub-fps", f_requested_fps );
750 i_delay = var_CreateGetInteger( p_input, "sub-delay" );
753 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
757 /* Look for and add subtitle files */
758 psz_subtitle = var_GetString( p_input, "sub-file" );
765 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
767 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
770 sub = InputSourceNew( p_input );
771 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle",
774 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
777 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list,
780 if( count.i_int == 0 )
782 /* if it was first one, there is disable too */
784 if( count.i_int < list.p_list->i_count )
786 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
787 &list.p_list->p_values[count.i_int] );
789 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list,
795 var_Get( p_input, "sub-autodetect-file", &val );
798 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
799 char **subs = subtitles_Detect( p_input, psz_autopath,
800 p_input->input.p_item->psz_uri );
803 for( i = 0; subs[i] != NULL; i++ )
805 if( strcmp( psz_subtitle, subs[i] ) )
807 sub = InputSourceNew( p_input );
808 if( !InputSourceInit( p_input, sub, subs[i], "subtitle",
811 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
817 free( psz_autopath );
819 free( psz_subtitle );
822 psz = var_GetString( p_input, "input-slave" );
826 input_source_t *slave;
829 while( *psz == ' ' || *psz == '#' )
833 if( ( psz_delim = strchr( psz, '#' ) ) )
842 msg_Dbg( p_input, "adding slave input '%s'", psz );
843 slave = InputSourceNew( p_input );
844 if( !InputSourceInit( p_input, slave, psz, NULL, VLC_FALSE ) )
846 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
851 if( psz ) free( psz );
855 p_input->i_start = 0;
856 p_input->i_start = 0;
862 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
863 i_es_out_mode = ES_OUT_MODE_AUTO;
865 if( p_input->p_sout )
867 var_Get( p_input, "sout-all", &val );
870 i_es_out_mode = ES_OUT_MODE_ALL;
875 var_Get( p_input, "programs", &val );
876 if ( val.p_list && val.p_list->i_count )
878 i_es_out_mode = ES_OUT_MODE_PARTIAL;
879 /* Note : we should remove the "program" callback. */
882 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
886 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
888 /* Inform the demuxer about waited group (needed only for DVB) */
889 if( i_es_out_mode == ES_OUT_MODE_ALL )
891 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
893 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
895 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1,
900 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP,
901 (int) var_GetInteger( p_input, "program" ), NULL );
904 if( p_input->p_sout )
906 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
908 p_input->b_out_pace_control = VLC_FALSE;
912 p_input->b_out_pace_control = VLC_TRUE;
915 if( p_input->b_can_pace_control && p_input->b_out_pace_control )
917 /* We don't want a high input priority here or we'll
918 * end-up sucking up all the CPU time */
919 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
922 msg_Dbg( p_input, "starting in %s mode",
923 p_input->b_out_pace_control ? "asynch" : "synch" );
927 /* Get meta data from users */
928 p_meta_tmp = InputMetaUser( p_input );
930 /* Get meta data from master input */
931 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_META, &p_meta ) )
939 else if( p_meta_tmp )
941 vlc_meta_Merge( p_meta, p_meta_tmp );
942 vlc_meta_Delete( p_meta_tmp );
945 /* Access_file does not give any meta, and there are no slave */
948 if( !p_input->input.p_access ||
949 access2_Control( p_input->input.p_access, ACCESS_GET_META,
957 else if( p_meta_tmp )
959 vlc_meta_Merge( p_meta, p_meta_tmp );
960 vlc_meta_Delete( p_meta_tmp );
963 /* Get meta data from slave input */
964 for( i = 0; i < p_input->i_slave; i++ )
966 vlc_meta_t *p_meta_slave;
968 if( !demux2_Control( p_input->slave[i]->p_demux,
969 DEMUX_GET_META, &p_meta_slave ) )
973 p_meta = p_meta_slave;
975 else if( p_meta_slave )
977 vlc_meta_Merge( p_meta, p_meta_slave );
978 vlc_meta_Delete( p_meta_slave );
982 if( p_input->slave[i]->p_access &&
983 !access2_Control( p_input->slave[i]->p_access,
984 ACCESS_GET_META, &p_meta_slave ) )
988 p_meta = p_meta_slave;
990 else if( p_meta_slave )
992 vlc_meta_Merge( p_meta, p_meta_slave );
993 vlc_meta_Delete( p_meta_slave );
999 p_input->p_meta = p_meta;
1000 UpdateMeta( p_input, b_quick );
1004 msg_Dbg( p_input, "`%s' successfully opened",
1005 p_input->input.p_item->psz_uri );
1009 /* Trigger intf update for this item */
1010 /* Playlist has a callback on this variable and will forward
1012 var_SetInteger( p_input, "item-change", p_input->input.p_item->i_id );
1014 /* initialization is complete */
1015 p_input->i_state = PLAYING_S;
1017 val.i_int = PLAYING_S;
1018 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1023 if( p_input->p_es_out )
1024 input_EsOutDelete( p_input->p_es_out );
1026 if( p_input->p_sout )
1027 sout_DeleteInstance( p_input->p_sout );
1029 /* Mark them deleted */
1030 p_input->input.p_demux = NULL;
1031 p_input->input.p_stream = NULL;
1032 p_input->input.p_access = NULL;
1033 p_input->p_es_out = NULL;
1034 p_input->p_sout = NULL;
1036 return VLC_EGENERIC;
1039 /*****************************************************************************
1040 * Error: RunThread() error loop
1041 *****************************************************************************
1042 * This function is called when an error occurred during thread main's loop.
1043 *****************************************************************************/
1044 static void Error( input_thread_t *p_input )
1046 while( !p_input->b_die )
1049 msleep( INPUT_IDLE_SLEEP );
1053 /*****************************************************************************
1054 * End: end the input thread
1055 *****************************************************************************/
1056 static void End( input_thread_t * p_input )
1061 msg_Dbg( p_input, "closing input" );
1063 /* We are at the end */
1064 p_input->i_state = END_S;
1067 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1069 /* Clean control variables */
1070 input_ControlVarClean( p_input );
1072 /* Clean up master */
1073 InputSourceClean( p_input, &p_input->input );
1076 for( i = 0; i < p_input->i_slave; i++ )
1078 InputSourceClean( p_input, p_input->slave[i] );
1079 free( p_input->slave[i] );
1081 if( p_input->slave ) free( p_input->slave );
1083 /* Unload all modules */
1084 if( p_input->p_es_out )
1085 input_EsOutDelete( p_input->p_es_out );
1087 /* Close optional stream output instance */
1088 if( p_input->p_sout )
1090 vlc_object_t *p_pl =
1091 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1094 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
1096 /* attach sout to the playlist */
1097 msg_Warn( p_input, "keeping sout" );
1098 vlc_object_detach( p_input->p_sout );
1099 vlc_object_attach( p_input->p_sout, p_pl );
1103 msg_Warn( p_input, "destroying sout" );
1104 sout_DeleteInstance( p_input->p_sout );
1107 vlc_object_release( p_pl );
1111 if( p_input->p_meta )
1112 vlc_meta_Delete( p_input->p_meta );
1114 /* Tell we're dead */
1115 p_input->b_dead = VLC_TRUE;
1118 /*****************************************************************************
1120 *****************************************************************************/
1121 static inline int ControlPopNoLock( input_thread_t *p_input,
1122 int *pi_type, vlc_value_t *p_val )
1124 if( p_input->i_control <= 0 )
1126 return VLC_EGENERIC;
1129 *pi_type = p_input->control[0].i_type;
1130 *p_val = p_input->control[0].val;
1132 p_input->i_control--;
1133 if( p_input->i_control > 0 )
1137 for( i = 0; i < p_input->i_control; i++ )
1139 p_input->control[i].i_type = p_input->control[i+1].i_type;
1140 p_input->control[i].val = p_input->control[i+1].val;
1147 static void ControlReduce( input_thread_t *p_input )
1150 for( i = 1; i < p_input->i_control; i++ )
1152 const int i_lt = p_input->control[i-1].i_type;
1153 const int i_ct = p_input->control[i].i_type;
1155 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1156 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
1160 ( i_ct == INPUT_CONTROL_SET_STATE ||
1161 i_ct == INPUT_CONTROL_SET_RATE ||
1162 i_ct == INPUT_CONTROL_SET_POSITION ||
1163 i_ct == INPUT_CONTROL_SET_TIME ||
1164 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1165 i_ct == INPUT_CONTROL_SET_TITLE ||
1166 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1167 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1170 // msg_Dbg( p_input, "merged at %d", i );
1171 /* Remove the i-1 */
1172 for( j = i; j < p_input->i_control; j++ )
1173 p_input->control[j-1] = p_input->control[j];
1174 p_input->i_control--;
1178 /* TODO but that's not that important
1179 - merge SET_X with SET_X_CMD
1180 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1181 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1188 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
1191 vlc_bool_t b_force_update = VLC_FALSE;
1195 case INPUT_CONTROL_SET_DIE:
1196 msg_Dbg( p_input, "control: stopping input" );
1197 /* Mark all submodules to die */
1198 if( p_input->input.p_access )
1199 p_input->input.p_access->b_die = VLC_TRUE;
1200 if( p_input->input.p_stream )
1201 p_input->input.p_stream->b_die = VLC_TRUE;
1202 p_input->input.p_demux->b_die = VLC_TRUE;
1204 p_input->b_die = VLC_TRUE;
1207 case INPUT_CONTROL_SET_POSITION:
1208 case INPUT_CONTROL_SET_POSITION_OFFSET:
1211 if( i_type == INPUT_CONTROL_SET_POSITION )
1213 f_pos = val.f_float;
1217 /* Should not fail */
1218 demux2_Control( p_input->input.p_demux,
1219 DEMUX_GET_POSITION, &f_pos );
1220 f_pos += val.f_float;
1222 if( f_pos < 0.0 ) f_pos = 0.0;
1223 if( f_pos > 1.0 ) f_pos = 1.0;
1224 /* Reset the decoders states and clock synch (before calling the demuxer */
1225 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1226 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1227 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
1230 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1231 "%2.1f%% failed", f_pos * 100 );
1235 if( p_input->i_slave > 0 )
1236 SlaveSeek( p_input );
1238 //input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1239 //es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1240 b_force_update = VLC_TRUE;
1245 case INPUT_CONTROL_SET_TIME:
1246 case INPUT_CONTROL_SET_TIME_OFFSET:
1251 if( i_type == INPUT_CONTROL_SET_TIME )
1253 i_time = val.i_time;
1257 /* Should not fail */
1258 demux2_Control( p_input->input.p_demux,
1259 DEMUX_GET_TIME, &i_time );
1260 i_time += val.i_time;
1262 if( i_time < 0 ) i_time = 0;
1264 /* Reset the decoders states and clock synch (before calling the demuxer */
1265 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1266 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1268 i_ret = demux2_Control( p_input->input.p_demux,
1269 DEMUX_SET_TIME, i_time );
1273 /* Emulate it with a SET_POS */
1275 demux2_Control( p_input->input.p_demux,
1276 DEMUX_GET_LENGTH, &i_length );
1279 double f_pos = (double)i_time / (double)i_length;
1280 i_ret = demux2_Control( p_input->input.p_demux,
1281 DEMUX_SET_POSITION, f_pos );
1286 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1287 " failed", i_time );
1291 if( p_input->i_slave > 0 )
1292 SlaveSeek( p_input );
1294 //input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1295 //es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1296 b_force_update = VLC_TRUE;
1301 case INPUT_CONTROL_SET_STATE:
1302 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1303 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1306 if( p_input->input.p_access )
1307 i_ret = access2_Control( p_input->input.p_access,
1308 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1310 i_ret = demux2_Control( p_input->input.p_demux,
1311 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1315 /* FIXME What to do ? */
1316 msg_Warn( p_input, "cannot unset pause -> EOF" );
1317 vlc_mutex_unlock( &p_input->lock_control );
1318 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1319 vlc_mutex_lock( &p_input->lock_control );
1322 b_force_update = VLC_TRUE;
1324 /* Switch to play */
1325 p_input->i_state = PLAYING_S;
1326 val.i_int = PLAYING_S;
1327 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1330 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1332 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1333 p_input->b_can_pause )
1336 if( p_input->input.p_access )
1337 i_ret = access2_Control( p_input->input.p_access,
1338 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1340 i_ret = demux2_Control( p_input->input.p_demux,
1341 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1343 b_force_update = VLC_TRUE;
1347 msg_Warn( p_input, "cannot set pause state" );
1348 val.i_int = p_input->i_state;
1352 val.i_int = PAUSE_S;
1355 /* Switch to new state */
1356 p_input->i_state = val.i_int;
1357 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1359 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1361 b_force_update = VLC_TRUE;
1363 /* Correct "state" value */
1364 val.i_int = p_input->i_state;
1365 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1367 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1369 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1373 case INPUT_CONTROL_SET_RATE:
1374 case INPUT_CONTROL_SET_RATE_SLOWER:
1375 case INPUT_CONTROL_SET_RATE_FASTER:
1379 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1380 i_rate = p_input->i_rate * 2;
1381 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1382 i_rate = p_input->i_rate / 2;
1386 if( i_rate < INPUT_RATE_MIN )
1388 msg_Dbg( p_input, "cannot set rate faster" );
1389 i_rate = INPUT_RATE_MIN;
1391 else if( i_rate > INPUT_RATE_MAX )
1393 msg_Dbg( p_input, "cannot set rate slower" );
1394 i_rate = INPUT_RATE_MAX;
1396 if( i_rate != INPUT_RATE_DEFAULT &&
1397 ( !p_input->b_can_pace_control ||
1398 ( p_input->p_sout && !p_input->b_out_pace_control ) ) )
1400 msg_Dbg( p_input, "cannot change rate" );
1401 i_rate = INPUT_RATE_DEFAULT;
1403 if( i_rate != p_input->i_rate )
1405 p_input->i_rate = i_rate;
1407 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1409 /* We haven't send data to decoder when rate != default */
1410 if( i_rate == INPUT_RATE_DEFAULT )
1411 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1414 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1416 b_force_update = VLC_TRUE;
1421 case INPUT_CONTROL_SET_PROGRAM:
1422 /* No need to force update, es_out does it if needed */
1423 es_out_Control( p_input->p_es_out,
1424 ES_OUT_SET_GROUP, val.i_int );
1426 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1430 case INPUT_CONTROL_SET_ES:
1431 /* No need to force update, es_out does it if needed */
1432 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1433 input_EsOutGetFromID( p_input->p_es_out,
1437 case INPUT_CONTROL_SET_AUDIO_DELAY:
1438 input_EsOutSetDelay( p_input->p_es_out,
1439 AUDIO_ES, val.i_time );
1440 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1443 case INPUT_CONTROL_SET_SPU_DELAY:
1444 input_EsOutSetDelay( p_input->p_es_out,
1445 SPU_ES, val.i_time );
1446 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1449 case INPUT_CONTROL_SET_TITLE:
1450 case INPUT_CONTROL_SET_TITLE_NEXT:
1451 case INPUT_CONTROL_SET_TITLE_PREV:
1452 if( p_input->input.b_title_demux &&
1453 p_input->input.i_title > 0 )
1456 /* FIXME handle demux title */
1457 demux_t *p_demux = p_input->input.p_demux;
1460 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1461 i_title = p_demux->info.i_title - 1;
1462 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1463 i_title = p_demux->info.i_title + 1;
1465 i_title = val.i_int;
1467 if( i_title >= 0 && i_title < p_input->input.i_title )
1469 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1471 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1472 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1474 input_ControlVarTitle( p_input, i_title );
1477 else if( p_input->input.i_title > 0 )
1479 access_t *p_access = p_input->input.p_access;
1482 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1483 i_title = p_access->info.i_title - 1;
1484 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1485 i_title = p_access->info.i_title + 1;
1487 i_title = val.i_int;
1489 if( i_title >= 0 && i_title < p_input->input.i_title )
1491 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1492 stream_AccessReset( p_input->input.p_stream );
1494 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1495 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1499 case INPUT_CONTROL_SET_SEEKPOINT:
1500 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1501 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1502 if( p_input->input.b_title_demux &&
1503 p_input->input.i_title > 0 )
1505 demux_t *p_demux = p_input->input.p_demux;
1507 int64_t i_input_time;
1508 int64_t i_seekpoint_time;
1510 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1512 i_seekpoint = p_demux->info.i_seekpoint;
1513 i_seekpoint_time = p_input->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1514 if( i_seekpoint_time >= 0 &&
1515 !demux2_Control( p_demux,
1516 DEMUX_GET_TIME, &i_input_time ) )
1518 if ( i_input_time < i_seekpoint_time + 3000000 )
1524 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1525 i_seekpoint = p_demux->info.i_seekpoint + 1;
1527 i_seekpoint = val.i_int;
1529 if( i_seekpoint >= 0 && i_seekpoint <
1530 p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1532 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1534 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1535 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1538 else if( p_input->input.i_title > 0 )
1540 demux_t *p_demux = p_input->input.p_demux;
1541 access_t *p_access = p_input->input.p_access;
1543 int64_t i_input_time;
1544 int64_t i_seekpoint_time;
1546 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1548 i_seekpoint = p_access->info.i_seekpoint;
1549 i_seekpoint_time = p_input->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1550 if( i_seekpoint_time >= 0 &&
1551 demux2_Control( p_demux,
1552 DEMUX_GET_TIME, &i_input_time ) )
1554 if ( i_input_time < i_seekpoint_time + 3000000 )
1560 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1561 i_seekpoint = p_access->info.i_seekpoint + 1;
1563 i_seekpoint = val.i_int;
1565 if( i_seekpoint >= 0 && i_seekpoint <
1566 p_input->input.title[p_access->info.i_title]->i_seekpoint )
1568 access2_Control( p_access, ACCESS_SET_SEEKPOINT, i_seekpoint );
1569 stream_AccessReset( p_input->input.p_stream );
1571 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1572 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1577 case INPUT_CONTROL_ADD_SLAVE:
1578 if( val.psz_string )
1580 input_source_t *slave = InputSourceNew( p_input );
1582 if( !InputSourceInit( p_input, slave, val.psz_string, NULL,
1585 vlc_meta_t *p_meta_new = NULL;
1590 msg_Dbg( p_input, "adding %s as slave on the fly",
1594 if( demux2_Control( p_input->input.p_demux,
1595 DEMUX_GET_TIME, &i_time ) )
1597 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1598 InputSourceClean( p_input, slave );
1602 if( demux2_Control( slave->p_demux,
1603 DEMUX_SET_TIME, i_time ) )
1605 msg_Err( p_input, "seek failed for new slave" );
1606 InputSourceClean( p_input, slave );
1612 /* Get meta (access and demux) */
1613 if( access2_Control( slave->p_access,
1614 ACCESS_GET_META, &p_meta_new ) )
1616 if( !demux2_Control( slave->p_demux,
1617 DEMUX_GET_META, &p_meta ) )
1621 vlc_meta_Merge( p_meta_new, p_meta );
1622 vlc_meta_Delete( p_meta );
1626 p_meta_new = p_meta;
1632 if( p_input->p_meta )
1634 vlc_meta_Merge( p_input->p_meta, p_meta_new );
1635 vlc_meta_Delete( p_meta_new );
1639 p_input->p_meta = p_meta_new;
1641 UpdateMeta( p_input, VLC_FALSE );
1644 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
1648 msg_Warn( p_input, "failed to add %s as slave",
1652 free( val.psz_string );
1656 case INPUT_CONTROL_SET_BOOKMARK:
1658 msg_Err( p_input, "not yet implemented" );
1662 return b_force_update;
1665 /*****************************************************************************
1667 *****************************************************************************/
1668 static int UpdateFromDemux( input_thread_t *p_input )
1670 demux_t *p_demux = p_input->input.p_demux;
1673 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1675 v.i_int = p_demux->info.i_title;
1676 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1678 input_ControlVarTitle( p_input, p_demux->info.i_title );
1680 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1682 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1684 v.i_int = p_demux->info.i_seekpoint;
1685 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1687 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1689 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1691 /* Hmmm only works with master input */
1692 if( p_input->input.p_demux == p_demux )
1694 int i_title_end = p_input->input.i_title_end -
1695 p_input->input.i_title_offset;
1696 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1697 p_input->input.i_seekpoint_offset;
1699 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
1701 if( p_demux->info.i_title > i_title_end ||
1702 ( p_demux->info.i_title == i_title_end &&
1703 p_demux->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1705 else if( i_seekpoint_end >=0 )
1707 if( p_demux->info.i_seekpoint > i_seekpoint_end ) return 0;
1709 else if( i_title_end >= 0 )
1711 if( p_demux->info.i_title > i_title_end ) return 0;
1718 /*****************************************************************************
1720 *****************************************************************************/
1721 static int UpdateFromAccess( input_thread_t *p_input )
1723 access_t *p_access = p_input->input.p_access;
1726 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1728 v.i_int = p_access->info.i_title;
1729 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1731 input_ControlVarTitle( p_input, p_access->info.i_title );
1733 stream_AccessUpdate( p_input->input.p_stream );
1735 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1737 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1739 v.i_int = p_access->info.i_seekpoint;
1740 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1742 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1744 if( p_access->info.i_update & INPUT_UPDATE_META )
1746 /* TODO maybe multi - access ? */
1748 if( !access2_Control( p_input->input.p_access,ACCESS_GET_META,&p_meta))
1750 if( p_input->p_meta )
1752 vlc_meta_Merge( p_input->p_meta, p_meta );
1753 vlc_meta_Delete( p_meta );
1757 p_input->p_meta = p_meta;
1760 UpdateMeta( p_input, VLC_FALSE );
1761 var_SetBool( p_input, "item-change", p_input->input.p_item->i_id );
1763 p_access->info.i_update &= ~INPUT_UPDATE_META;
1766 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1768 /* Hmmm only works with master input */
1769 if( p_input->input.p_access == p_access )
1771 int i_title_end = p_input->input.i_title_end -
1772 p_input->input.i_title_offset;
1773 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1774 p_input->input.i_seekpoint_offset;
1776 if( i_title_end >= 0 && i_seekpoint_end >=0 )
1778 if( p_access->info.i_title > i_title_end ||
1779 ( p_access->info.i_title == i_title_end &&
1780 p_access->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1782 else if( i_seekpoint_end >=0 )
1784 if( p_access->info.i_seekpoint > i_seekpoint_end ) return 0;
1786 else if( i_title_end >= 0 )
1788 if( p_access->info.i_title > i_title_end ) return 0;
1795 /*****************************************************************************
1797 *****************************************************************************/
1798 static int UpdateMeta( input_thread_t *p_input, vlc_bool_t b_quick )
1800 vlc_meta_t *p_meta = p_input->p_meta;
1803 if( !p_meta || p_meta->i_meta == 0 )
1806 if( !b_quick ) msg_Dbg( p_input, "meta information:" );
1807 for( i = 0; i < p_meta->i_meta; i++ )
1810 msg_Dbg( p_input, " - '%s' = '%s'",
1811 _(p_meta->name[i]), p_meta->value[i] );
1813 if( !strcmp(p_meta->name[i], VLC_META_TITLE) && p_meta->value[i] &&
1814 !p_input->input.p_item->b_fixed_name )
1815 input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
1817 if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
1818 input_Control( p_input, INPUT_ADD_INFO, _("General"),
1819 _("Author"), p_meta->value[i] );
1821 input_Control( p_input, INPUT_ADD_INFO, _("Meta-information"),
1822 _(p_meta->name[i]), "%s", p_meta->value[i] );
1825 for( i = 0; i < p_meta->i_track; i++ )
1827 vlc_meta_t *tk = p_meta->track[i];
1830 if( tk->i_meta > 0 )
1832 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
1834 msg_Dbg( p_input, " - track[%d]:", i );
1836 sprintf( psz_cat, "%s %d", _("Stream"), i );
1837 for( j = 0; j < tk->i_meta; j++ )
1839 msg_Dbg( p_input, " - '%s' = '%s'", _(tk->name[j]),
1842 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1843 _(tk->name[j]), "%s", tk->value[j] );
1848 if( p_input->p_sout && p_input->p_sout->p_meta == NULL )
1850 p_input->p_sout->p_meta = vlc_meta_Duplicate( p_meta );
1856 /*****************************************************************************
1858 *****************************************************************************/
1859 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length,
1860 vlc_bool_t b_quick )
1862 playlist_t *p_playlist;
1863 char psz_buffer[MSTRTIME_MAX_SIZE];
1865 vlc_mutex_lock( &p_input->input.p_item->lock );
1866 p_input->input.p_item->i_duration = i_length;
1867 vlc_mutex_unlock( &p_input->input.p_item->lock );
1869 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
1873 var_SetInteger( p_playlist, "item-change",
1874 p_input->input.p_item->i_id );
1875 vlc_object_release( p_playlist );
1878 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
1879 msecstotimestr( psz_buffer, i_length / 1000 ) );
1882 /*****************************************************************************
1884 *****************************************************************************/
1885 static input_source_t *InputSourceNew( input_thread_t *p_input )
1887 input_source_t *in = malloc( sizeof( input_source_t ) );
1890 in->p_access = NULL;
1891 in->p_stream = NULL;
1893 in->b_title_demux = VLC_FALSE;
1896 in->b_can_pace_control = VLC_TRUE;
1897 in->b_eof = VLC_FALSE;
1898 in->i_cr_average = 0;
1903 /*****************************************************************************
1905 *****************************************************************************/
1906 static int InputSourceInit( input_thread_t *p_input,
1907 input_source_t *in, char *psz_mrl,
1908 char *psz_forced_demux, vlc_bool_t b_quick )
1910 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 );
2025 psz = var_GetString( p_input, "access-filter" );
2028 access_t *p_access = in->p_access;
2030 /* TODO support chained access-filter */
2031 in->p_access = access2_FilterNew( in->p_access, psz );
2032 if( in->p_access == NULL )
2034 in->p_access = p_access;
2035 msg_Warn( p_input, "failed to insert access filter %s",
2041 /* Get infos from access */
2044 access2_Control( in->p_access,
2045 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2046 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2048 in->b_title_demux = VLC_FALSE;
2049 if( access2_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2050 &in->title, &in->i_title,
2051 &in->i_title_offset, &in->i_seekpoint_offset ) )
2057 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2058 &in->b_can_pace_control );
2059 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
2061 access2_Control( in->p_access, ACCESS_CAN_SEEK,
2063 var_Set( p_input, "seekable", val );
2066 /* Create the stream_t */
2067 in->p_stream = stream_AccessNew( in->p_access, b_quick );
2068 if( in->p_stream == NULL )
2070 msg_Warn( p_input, "cannot create a stream_t from access" );
2074 /* Open a demuxer */
2075 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2077 psz_demux = in->p_access->psz_demux;
2079 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2080 in->p_stream, p_input->p_es_out, b_quick );
2081 if( in->p_demux == NULL )
2083 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2084 psz_access, psz_demux, psz_path );
2088 /* TODO get title from demux */
2089 if( !b_quick && in->i_title <= 0 )
2091 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2092 &in->title, &in->i_title,
2093 &in->i_title_offset, &in->i_seekpoint_offset ))
2100 in->b_title_demux = VLC_TRUE;
2105 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2106 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2113 demux2_Delete( in->p_demux );
2116 stream_Delete( in->p_stream );
2119 access2_Delete( in->p_access );
2122 return VLC_EGENERIC;
2125 /*****************************************************************************
2127 *****************************************************************************/
2128 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
2131 demux2_Delete( in->p_demux );
2134 stream_Delete( in->p_stream );
2137 access2_Delete( in->p_access );
2139 if( in->i_title > 0 )
2142 for( i = 0; i < in->i_title; i++ )
2144 vlc_input_title_Delete( in->title[i] );
2150 static void SlaveDemux( input_thread_t *p_input )
2154 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2156 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2160 for( i = 0; i < p_input->i_slave; i++ )
2162 input_source_t *in = p_input->slave[i];
2168 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2173 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2175 msg_Err( p_input, "slave[%d] doesn't like "
2176 "DEMUX_GET_TIME -> EOF", i );
2181 if( i_stime >= i_time )
2184 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
2190 i_ret = in->p_demux->pf_demux( in->p_demux );
2195 msg_Dbg( p_input, "slave %d EOF", i );
2196 in->b_eof = VLC_TRUE;
2201 static void SlaveSeek( input_thread_t *p_input )
2206 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2208 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2212 for( i = 0; i < p_input->i_slave; i++ )
2214 input_source_t *in = p_input->slave[i];
2216 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2218 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2219 in->b_eof = VLC_TRUE;
2223 /*****************************************************************************
2225 *****************************************************************************/
2226 static vlc_meta_t *InputMetaUser( input_thread_t *p_input )
2231 if( ( p_meta = vlc_meta_New() ) == NULL )
2234 /* Get meta information from user */
2235 #define GET_META( c, s ) \
2236 var_Get( p_input, (s), &val ); \
2237 if( *val.psz_string ) \
2238 vlc_meta_Add( p_meta, c, val.psz_string ); \
2239 free( val.psz_string )
2241 GET_META( VLC_META_TITLE, "meta-title" );
2242 GET_META( VLC_META_AUTHOR, "meta-author" );
2243 GET_META( VLC_META_ARTIST, "meta-artist" );
2244 GET_META( VLC_META_GENRE, "meta-genre" );
2245 GET_META( VLC_META_COPYRIGHT, "meta-copyright" );
2246 GET_META( VLC_META_DESCRIPTION, "meta-description" );
2247 GET_META( VLC_META_DATE, "meta-date" );
2248 GET_META( VLC_META_URL, "meta-url" );
2254 /*****************************************************************************
2255 * DecodeUrl: decode a given encoded url
2256 *****************************************************************************/
2257 static void DecodeUrl( char *psz )
2259 char *dup = strdup( psz );
2277 *psz++ = strtol( val, NULL, 16 );
2279 else if( *p == '+' )
2293 /*****************************************************************************
2294 * ParseOption: parses the options for the input
2295 *****************************************************************************
2296 * This function parses the input (config) options and creates their associated
2298 * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
2299 * bar is the value of the option.
2300 *****************************************************************************/
2301 static void ParseOption( input_thread_t *p_input, const char *psz_option )
2303 char *psz_name = (char *)psz_option;
2304 char *psz_value = strchr( psz_option, '=' );
2305 int i_name_len, i_type;
2306 vlc_bool_t b_isno = VLC_FALSE;
2309 if( psz_value ) i_name_len = psz_value - psz_option;
2310 else i_name_len = strlen( psz_option );
2312 /* It's too much of an hassle to remove the ':' when we parse
2313 * the cmd line :) */
2314 if( i_name_len && *psz_name == ':' )
2320 if( i_name_len == 0 ) return;
2322 psz_name = strndup( psz_name, i_name_len );
2323 if( psz_value ) psz_value++;
2325 i_type = config_GetType( p_input, psz_name );
2327 if( !i_type && !psz_value )
2329 /* check for "no-foo" or "nofoo" */
2330 if( !strncmp( psz_name, "no-", 3 ) )
2332 memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
2334 else if( !strncmp( psz_name, "no", 2 ) )
2336 memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
2338 else goto cleanup; /* Option doesn't exist */
2341 i_type = config_GetType( p_input, psz_name );
2343 if( !i_type ) goto cleanup; /* Option doesn't exist */
2345 else if( !i_type ) goto cleanup; /* Option doesn't exist */
2347 if( ( i_type != VLC_VAR_BOOL ) &&
2348 ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */
2350 /* Create the variable in the input object.
2351 * Children of the input object will be able to retreive this value
2352 * thanks to the inheritance property of the object variables. */
2353 var_Create( p_input, psz_name, i_type );
2358 val.b_bool = !b_isno;
2361 case VLC_VAR_INTEGER:
2362 val.i_int = atoi( psz_value );
2366 val.f_float = atof( psz_value );
2369 case VLC_VAR_STRING:
2370 case VLC_VAR_MODULE:
2372 case VLC_VAR_DIRECTORY:
2373 val.psz_string = psz_value;
2381 var_Set( p_input, psz_name, val );
2383 msg_Dbg( p_input, "set input option: %s to %s", psz_name,
2384 psz_value ? psz_value : ( val.b_bool ? "true" : "false") );
2387 if( psz_name ) free( psz_name );
2391 /*****************************************************************************
2392 * MRLSplit: parse the access, demux and url part of the
2393 * Media Resource Locator.
2394 *****************************************************************************/
2395 void MRLSplit( vlc_object_t *p_input, char *psz_dup,
2396 char **ppsz_access, char **ppsz_demux, char **ppsz_path )
2398 char *psz_access = NULL;
2399 char *psz_demux = NULL;
2400 char *psz_path = NULL;
2401 char *psz, *psz_check;
2403 psz = strchr( psz_dup, ':' );
2405 /* '@' not allowed in access/demux part */
2406 psz_check = strchr( psz_dup, '@' );
2407 if( psz_check && psz_check < psz ) psz = 0;
2409 #if defined( WIN32 ) || defined( UNDER_CE )
2410 if( psz - psz_dup == 1 )
2412 msg_Warn( p_input, "drive letter %c: found in source", *psz_dup );
2421 if( psz[0] == '/' && psz[1] == '/' ) psz += 2;
2425 psz = strchr( psz_dup, '/' );
2432 psz_access = psz_dup;
2439 if( !psz_access ) *ppsz_access = "";
2440 else *ppsz_access = psz_access;
2442 if( !psz_demux ) *ppsz_demux = "";
2443 else *ppsz_demux = psz_demux;
2445 if( !psz_path ) *ppsz_path = "";
2446 else *ppsz_path = psz_path;
2449 /*****************************************************************************
2450 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
2453 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
2454 *****************************************************************************/
2455 static void MRLSections( input_thread_t *p_input, char *psz_source,
2456 int *pi_title_start, int *pi_title_end,
2457 int *pi_chapter_start, int *pi_chapter_end )
2459 char *psz, *psz_end, *psz_next, *psz_check;
2461 *pi_title_start = *pi_title_end = -1;
2462 *pi_chapter_start = *pi_chapter_end = -1;
2464 /* Start by parsing titles and chapters */
2465 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
2467 /* Check we are really dealing with a title/chapter section */
2468 psz_check = psz + 1;
2469 if( !*psz_check ) return;
2470 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2471 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
2472 if( *psz_check == ':' && ++psz_check )
2473 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2474 if( *psz_check != '-' && *psz_check ) return;
2475 if( *psz_check == '-' && ++psz_check )
2476 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2477 if( *psz_check != ':' && *psz_check ) return;
2478 if( *psz_check == ':' && ++psz_check )
2479 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2480 if( *psz_check ) return;
2482 /* Separate start and end */
2484 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
2486 /* Look for the start title */
2487 *pi_title_start = strtol( psz, &psz_next, 0 );
2488 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
2489 *pi_title_end = *pi_title_start;
2492 /* Look for the start chapter */
2494 *pi_chapter_start = strtol( psz, &psz_next, 0 );
2495 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
2496 *pi_chapter_end = *pi_chapter_start;
2500 /* Look for the end title */
2501 *pi_title_end = strtol( psz_end, &psz_next, 0 );
2502 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
2505 /* Look for the end chapter */
2506 if( *psz_end ) psz_end++;
2507 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
2508 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
2511 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
2512 psz_source, *pi_title_start, *pi_chapter_start,
2513 *pi_title_end, *pi_chapter_end );
2517 /***********************************************************************
2518 * Info management functions
2519 ***********************************************************************/
2521 * Get a info item from a given category in a given input item.
2523 * \param p_i The input item to get info from
2524 * \param psz_cat String representing the category for the info
2525 * \param psz_name String representing the name of the desired info
2526 * \return A pointer to the string with the given info if found, or an
2527 * empty string otherwise. The caller should free the returned
2530 char *vlc_input_item_GetInfo( input_item_t *p_i,
2531 const char *psz_cat,
2532 const char *psz_name )
2536 vlc_mutex_lock( &p_i->lock );
2538 for( i = 0 ; i< p_i->i_categories ; i++ )
2540 info_category_t *p_cat = p_i->pp_categories[i];
2542 if( !psz_cat || strcmp( p_cat->psz_name, psz_cat ) )
2545 for( j = 0; j < p_cat->i_infos ; j++ )
2547 if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
2549 char *psz_ret = strdup( p_cat->pp_infos[j]->psz_value );
2550 vlc_mutex_unlock( &p_i->lock );
2555 vlc_mutex_unlock( &p_i->lock );
2556 return strdup( "" );
2559 int vlc_input_item_AddInfo( input_item_t *p_i,
2560 const char *psz_cat,
2561 const char *psz_name,
2562 const char *psz_format, ... )
2566 info_t *p_info = NULL;
2567 info_category_t *p_cat = NULL ;
2569 vlc_mutex_lock( &p_i->lock );
2571 for( i = 0 ; i < p_i->i_categories ; i ++ )
2573 if( !strcmp( p_i->pp_categories[i]->psz_name, psz_cat ) )
2575 p_cat = p_i->pp_categories[i];
2581 if( !(p_cat = (info_category_t *)malloc( sizeof(info_category_t) )) )
2583 vlc_mutex_unlock( &p_i->lock );
2584 return VLC_EGENERIC;
2586 p_cat->psz_name = strdup( psz_cat );
2588 p_cat->pp_infos = 0;
2589 INSERT_ELEM( p_i->pp_categories, p_i->i_categories, p_i->i_categories,
2593 for( i = 0; i< p_cat->i_infos; i++ )
2595 if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
2597 p_info = p_cat->pp_infos[i];
2604 if( ( p_info = (info_t *)malloc( sizeof( info_t ) ) ) == NULL )
2606 vlc_mutex_unlock( &p_i->lock );
2607 return VLC_EGENERIC;
2609 INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
2610 p_info->psz_name = strdup( psz_name );
2614 if( p_info->psz_value ) free( p_info->psz_value );
2617 va_start( args, psz_format );
2618 vasprintf( &p_info->psz_value, psz_format, args);
2621 vlc_mutex_unlock( &p_i->lock );