1 /*****************************************************************************
2 * input.c: input thread
3 *****************************************************************************
4 * Copyright (C) 1998-2004 the VideoLAN team
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 /* Remove 'Now playing' info as it is probably outdated */
222 input_Control( p_input, INPUT_DEL_INFO, _("Meta-information"),
223 VLC_META_NOW_PLAYING );
225 /* Now we can attach our new input */
226 vlc_object_attach( p_input, p_parent );
228 /* Create thread and wait for its readiness. */
229 if( vlc_thread_create( p_input, "input", Run,
230 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
232 msg_Err( p_input, "cannot create input thread" );
233 vlc_object_detach( p_input );
234 vlc_object_destroy( p_input );
241 /*****************************************************************************
242 * input_PreParse: Lightweight input for playlist item preparsing
243 *****************************************************************************/
244 int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
246 input_thread_t *p_input; /* thread descriptor */
249 /* Allocate descriptor */
250 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
251 if( p_input == NULL )
253 msg_Err( p_parent, "out of memory" );
257 /* Init Common fields */
258 p_input->b_eof = VLC_FALSE;
259 p_input->b_can_pace_control = VLC_TRUE;
260 p_input->i_start = 0;
263 p_input->i_title = 0;
264 p_input->title = NULL;
265 p_input->i_title_offset = p_input->i_seekpoint_offset = 0;
266 p_input->i_state = INIT_S;
267 p_input->i_rate = INPUT_RATE_DEFAULT;
268 p_input->i_bookmark = 0;
269 p_input->bookmark = NULL;
270 p_input->p_meta = NULL;
271 p_input->p_es_out = NULL;
272 p_input->p_sout = NULL;
273 p_input->b_out_pace_control = VLC_FALSE;
274 p_input->i_pts_delay = 0;
276 /* Init Input fields */
277 p_input->input.p_item = p_item;
278 p_input->input.p_access = NULL;
279 p_input->input.p_stream = NULL;
280 p_input->input.p_demux = NULL;
281 p_input->input.b_title_demux = VLC_FALSE;
282 p_input->input.i_title = 0;
283 p_input->input.title = NULL;
284 p_input->input.i_title_offset = p_input->input.i_seekpoint_offset = 0;
285 p_input->input.b_can_pace_control = VLC_TRUE;
286 p_input->input.b_eof = VLC_FALSE;
287 p_input->input.i_cr_average = 0;
290 p_input->i_slave = 0;
291 p_input->slave = NULL;
293 /* Init control buffer */
294 vlc_mutex_init( p_input, &p_input->lock_control );
295 p_input->i_control = 0;
297 /* Parse input options */
298 vlc_mutex_lock( &p_item->lock );
299 for( i = 0; i < p_item->i_options; i++ )
301 ParseOption( p_input, p_item->ppsz_options[i] );
303 vlc_mutex_unlock( &p_item->lock );
305 /* Create Object Variables for private use only */
306 input_ConfigVarInit( p_input );
307 input_ControlVarInit( p_input );
309 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
311 /* Now we can attach our new input */
312 vlc_object_attach( p_input, p_parent );
314 Init( p_input, VLC_TRUE );
316 /* Clean up master */
317 InputSourceClean( p_input, &p_input->input );
319 /* Kill access and demux */
320 if( p_input->input.p_access ) p_input->input.p_access->b_die = VLC_TRUE;
321 if( p_input->input.p_demux ) p_input->input.p_access->b_die = VLC_TRUE;
323 /* Unload all modules */
324 if( p_input->p_es_out ) input_EsOutDelete( p_input->p_es_out );
327 if( p_input->p_meta ) vlc_meta_Delete( p_input->p_meta );
329 vlc_object_detach( p_input );
330 vlc_object_destroy( p_input );
335 /*****************************************************************************
336 * input_StopThread: mark an input thread as zombie
337 *****************************************************************************
338 * This function should not return until the thread is effectively cancelled.
339 *****************************************************************************/
340 void input_StopThread( input_thread_t *p_input )
345 /* Set die for input */
346 p_input->b_die = VLC_TRUE;
348 /* We cannot touch p_input fields directly (we can from another thread),
349 * so use the vlc_object_find way, it's perfectly safe */
351 /* Set die for all access */
352 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );
353 for( i = 0; i < p_list->i_count; i++ )
355 p_list->p_values[i].p_object->b_die = VLC_TRUE;
357 vlc_list_release( p_list );
359 /* Set die for all stream */
360 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
361 for( i = 0; i < p_list->i_count; i++ )
363 p_list->p_values[i].p_object->b_die = VLC_TRUE;
365 vlc_list_release( p_list );
367 /* Set die for all demux */
368 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
369 for( i = 0; i < p_list->i_count; i++ )
371 p_list->p_values[i].p_object->b_die = VLC_TRUE;
373 vlc_list_release( p_list );
375 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
378 /*****************************************************************************
379 * input_DestroyThread: mark an input thread as zombie
380 *****************************************************************************
381 * This function should not return until the thread is effectively cancelled.
382 *****************************************************************************/
383 void input_DestroyThread( input_thread_t *p_input )
385 /* Join the thread */
386 vlc_thread_join( p_input );
388 /* Delete input lock (only after thread joined) */
389 vlc_mutex_destroy( &p_input->lock_control );
391 /* TODO: maybe input_DestroyThread should also delete p_input instead
392 * of the playlist but I'm not sure if it's possible */
395 /*****************************************************************************
396 * Run: main thread loop
397 *****************************************************************************
398 * Thread in charge of processing the network packets and demultiplexing.
401 * read subtitle support (XXX take care of spu-delay in the right way).
402 * multi-input support (XXX may be done with subs)
403 *****************************************************************************/
404 static int Run( input_thread_t *p_input )
406 int64_t i_intf_update = 0;
408 /* Signal that the thread is launched */
409 vlc_thread_ready( p_input );
411 if( Init( p_input, VLC_FALSE ) )
413 /* If we failed, wait before we are killed, and exit */
414 p_input->b_error = VLC_TRUE;
418 /* Tell we're dead */
419 p_input->b_dead = VLC_TRUE;
425 while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
427 vlc_bool_t b_force_update = VLC_FALSE;
433 if( p_input->i_state != PAUSE_S )
435 if( p_input->i_stop <= 0 || p_input->i_time < p_input->i_stop )
436 i_ret=p_input->input.p_demux->pf_demux(p_input->input.p_demux);
443 if( p_input->input.b_title_demux &&
444 p_input->input.p_demux->info.i_update )
446 i_ret = UpdateFromDemux( p_input );
447 b_force_update = VLC_TRUE;
449 else if( !p_input->input.b_title_demux &&
450 p_input->input.p_access &&
451 p_input->input.p_access->info.i_update )
453 i_ret = UpdateFromAccess( p_input );
454 b_force_update = VLC_TRUE;
458 if( i_ret == 0 ) /* EOF */
462 var_Get( p_input, "input-repeat", &repeat );
463 if( repeat.i_int == 0 )
465 /* End of file - we do not set b_die because only the
466 * playlist is allowed to do so. */
467 msg_Dbg( p_input, "EOF reached" );
468 p_input->input.b_eof = VLC_TRUE;
472 msg_Dbg( p_input, "repeating the same input (%d)",
474 if( repeat.i_int > 0 )
477 var_Set( p_input, "input-repeat", repeat );
480 /* Seek to start title/seekpoint */
481 val.i_int = p_input->input.i_title_start -
482 p_input->input.i_title_offset;
483 if( val.i_int < 0 || val.i_int >= p_input->input.i_title )
485 input_ControlPush( p_input,
486 INPUT_CONTROL_SET_TITLE, &val );
488 val.i_int = p_input->input.i_seekpoint_start -
489 p_input->input.i_seekpoint_offset;
490 if( val.i_int > 0 /* TODO: check upper boundary */ )
491 input_ControlPush( p_input,
492 INPUT_CONTROL_SET_SEEKPOINT, &val );
494 /* Seek to start position */
495 if( p_input->i_start > 0 )
497 val.i_time = p_input->i_start;
498 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
504 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
511 p_input->b_error = VLC_TRUE;
514 if( i_ret > 0 && p_input->i_slave > 0 )
516 SlaveDemux( p_input );
526 vlc_mutex_lock( &p_input->lock_control );
527 ControlReduce( p_input );
528 while( !ControlPopNoLock( p_input, &i_type, &val ) )
530 msg_Dbg( p_input, "control type=%d", i_type );
531 if( Control( p_input, i_type, val ) )
532 b_force_update = VLC_TRUE;
534 vlc_mutex_unlock( &p_input->lock_control );
536 if( b_force_update || i_intf_update < mdate() )
540 int64_t i_time, i_length;
541 /* update input status variables */
542 if( !demux2_Control( p_input->input.p_demux,
543 DEMUX_GET_POSITION, &f_pos ) )
545 val.f_float = (float)f_pos;
546 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
548 if( !demux2_Control( p_input->input.p_demux,
549 DEMUX_GET_TIME, &i_time ) )
551 p_input->i_time = i_time;
553 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
555 if( !demux2_Control( p_input->input.p_demux,
556 DEMUX_GET_LENGTH, &i_length ) )
559 var_Get( p_input, "length", &old_val );
560 val.i_time = i_length;
561 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
563 if( old_val.i_time != val.i_time )
565 UpdateItemLength( p_input, i_length, VLC_TRUE );
569 var_SetBool( p_input, "intf-change", VLC_TRUE );
570 i_intf_update = mdate() + I64C(150000);
574 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
576 /* We have finish to demux data but not to play them */
577 while( !p_input->b_die )
579 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
582 msg_Dbg( p_input, "waiting decoder fifos to empty" );
584 msleep( INPUT_IDLE_SLEEP );
587 /* We have finished */
588 p_input->b_eof = VLC_TRUE;
591 /* Wait we are asked to die */
592 if( !p_input->b_die )
604 static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
610 vlc_meta_t *p_meta, *p_meta_tmp;
614 /* Initialize optional stream output. (before access/demuxer)
615 * XXX: we add a special case if the uri starts by vlc.
616 * else 'vlc in.file --sout "" vlc:quit' cannot work (the output will
617 * be destroyed in case of a file).
618 * (this will break playing of file starting by 'vlc:' but I don't
619 * want to add more logic, just force file by file:// or code it ;)
623 psz = var_GetString( p_input, "sout" );
624 if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
626 p_input->p_sout = sout_NewInstance( p_input, psz );
627 if( p_input->p_sout == NULL )
629 msg_Err( p_input, "cannot start stream output instance, " \
639 p_input->p_es_out = input_EsOutNew( p_input );
640 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
641 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
643 if( InputSourceInit( p_input, &p_input->input,
644 p_input->input.p_item->psz_uri, NULL, b_quick ) )
649 /* Create global title (from master) */
652 p_input->i_title = p_input->input.i_title;
653 p_input->title = p_input->input.title;
654 p_input->i_title_offset = p_input->input.i_title_offset;
655 p_input->i_seekpoint_offset = p_input->input.i_seekpoint_offset;
656 if( p_input->i_title > 0 )
658 /* Setup variables */
659 input_ControlVarNavigation( p_input );
660 input_ControlVarTitle( p_input, 0 );
664 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
665 p_input->b_can_pause = p_input->input.b_can_pause;
668 if( p_input->i_pts_delay < 0 )
669 p_input->i_pts_delay = 0;
671 /* If the desynchronisation requested by the user is < 0, we need to
672 * cache more data. */
673 var_Get( p_input, "audio-desync", &val );
674 if( val.i_int < 0 ) p_input->i_pts_delay -= (val.i_int * 1000);
676 /* Update cr_average depending on the caching */
677 p_input->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000);
678 p_input->input.i_cr_average /= 10;
679 if( p_input->input.i_cr_average < 10 ) p_input->input.i_cr_average = 10;
682 /* Load master infos */
684 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH,
685 &val.i_time ) && val.i_time > 0 )
687 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
688 UpdateItemLength( p_input, val.i_time, b_quick );
689 p_input->input.p_item->i_duration = val.i_time;
692 /* Start title/chapter */
695 val.i_int = p_input->input.i_title_start -
696 p_input->input.i_title_offset;
697 if( val.i_int > 0 && val.i_int < p_input->input.i_title )
698 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
699 val.i_int = p_input->input.i_seekpoint_start -
700 p_input->input.i_seekpoint_offset;
701 if( val.i_int > 0 /* TODO: check upper boundary */ )
702 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
706 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
708 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
711 if( p_input->i_start > 0 )
713 if( p_input->i_start >= val.i_time )
715 msg_Warn( p_input, "invalid start-time ignored" );
721 msg_Dbg( p_input, "starting at time: %ds",
722 (int)( p_input->i_start / I64C(1000000) ) );
724 s.i_time = p_input->i_start;
725 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
728 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
730 msg_Warn( p_input, "invalid stop-time ignored" );
736 /* Get fps and set it if not already set */
737 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
740 float f_requested_fps;
742 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
743 var_SetFloat( p_input, "sub-original-fps", f_fps );
745 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
746 if( f_requested_fps != f_fps )
748 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
750 var_SetFloat( p_input, "sub-fps", f_requested_fps );
754 i_delay = var_CreateGetInteger( p_input, "sub-delay" );
757 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
761 /* Look for and add subtitle files */
762 psz_subtitle = var_GetString( p_input, "sub-file" );
769 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
771 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
774 sub = InputSourceNew( p_input );
775 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle",
778 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
781 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list,
784 if( count.i_int == 0 )
786 /* if it was first one, there is disable too */
788 if( count.i_int < list.p_list->i_count )
790 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
791 &list.p_list->p_values[count.i_int] );
793 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list,
799 var_Get( p_input, "sub-autodetect-file", &val );
802 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
803 char **subs = subtitles_Detect( p_input, psz_autopath,
804 p_input->input.p_item->psz_uri );
807 for( i = 0; subs[i] != NULL; i++ )
809 if( strcmp( psz_subtitle, subs[i] ) )
811 sub = InputSourceNew( p_input );
812 if( !InputSourceInit( p_input, sub, subs[i], "subtitle",
815 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
821 free( psz_autopath );
823 free( psz_subtitle );
826 psz = var_GetString( p_input, "input-slave" );
830 input_source_t *slave;
833 while( *psz == ' ' || *psz == '#' )
837 if( ( psz_delim = strchr( psz, '#' ) ) )
846 msg_Dbg( p_input, "adding slave input '%s'", psz );
847 slave = InputSourceNew( p_input );
848 if( !InputSourceInit( p_input, slave, psz, NULL, VLC_FALSE ) )
850 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
855 if( psz ) free( psz );
859 p_input->i_start = 0;
860 p_input->i_start = 0;
866 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
867 i_es_out_mode = ES_OUT_MODE_AUTO;
869 if( p_input->p_sout )
871 var_Get( p_input, "sout-all", &val );
874 i_es_out_mode = ES_OUT_MODE_ALL;
879 var_Get( p_input, "programs", &val );
880 if ( val.p_list && val.p_list->i_count )
882 i_es_out_mode = ES_OUT_MODE_PARTIAL;
883 /* Note : we should remove the "program" callback. */
886 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
890 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
892 /* Inform the demuxer about waited group (needed only for DVB) */
893 if( i_es_out_mode == ES_OUT_MODE_ALL )
895 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
897 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
899 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1,
904 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP,
905 (int) var_GetInteger( p_input, "program" ), NULL );
908 if( p_input->p_sout )
910 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
912 p_input->b_out_pace_control = VLC_FALSE;
916 p_input->b_out_pace_control = VLC_TRUE;
919 if( p_input->b_can_pace_control && p_input->b_out_pace_control )
921 /* We don't want a high input priority here or we'll
922 * end-up sucking up all the CPU time */
923 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
926 msg_Dbg( p_input, "starting in %s mode",
927 p_input->b_out_pace_control ? "asynch" : "synch" );
931 /* Get meta data from users */
932 p_meta_tmp = InputMetaUser( p_input );
934 /* Get meta data from master input */
935 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_META, &p_meta ) )
943 else if( p_meta_tmp )
945 vlc_meta_Merge( p_meta, p_meta_tmp );
946 vlc_meta_Delete( p_meta_tmp );
949 /* Access_file does not give any meta, and there are no slave */
952 if( !p_input->input.p_access ||
953 access2_Control( p_input->input.p_access, ACCESS_GET_META,
961 else if( p_meta_tmp )
963 vlc_meta_Merge( p_meta, p_meta_tmp );
964 vlc_meta_Delete( p_meta_tmp );
967 /* Get meta data from slave input */
968 for( i = 0; i < p_input->i_slave; i++ )
970 vlc_meta_t *p_meta_slave;
972 if( !demux2_Control( p_input->slave[i]->p_demux,
973 DEMUX_GET_META, &p_meta_slave ) )
977 p_meta = p_meta_slave;
979 else if( p_meta_slave )
981 vlc_meta_Merge( p_meta, p_meta_slave );
982 vlc_meta_Delete( p_meta_slave );
986 if( p_input->slave[i]->p_access &&
987 !access2_Control( p_input->slave[i]->p_access,
988 ACCESS_GET_META, &p_meta_slave ) )
992 p_meta = p_meta_slave;
994 else if( p_meta_slave )
996 vlc_meta_Merge( p_meta, p_meta_slave );
997 vlc_meta_Delete( p_meta_slave );
1003 p_input->p_meta = p_meta;
1004 UpdateMeta( p_input, b_quick );
1008 msg_Dbg( p_input, "`%s' successfully opened",
1009 p_input->input.p_item->psz_uri );
1013 /* Trigger intf update for this item */
1014 /* Playlist has a callback on this variable and will forward
1016 var_SetInteger( p_input, "item-change", p_input->input.p_item->i_id );
1018 /* initialization is complete */
1019 p_input->i_state = PLAYING_S;
1021 val.i_int = PLAYING_S;
1022 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1027 if( p_input->p_es_out )
1028 input_EsOutDelete( p_input->p_es_out );
1030 if( p_input->p_sout )
1031 sout_DeleteInstance( p_input->p_sout );
1033 /* Mark them deleted */
1034 p_input->input.p_demux = NULL;
1035 p_input->input.p_stream = NULL;
1036 p_input->input.p_access = NULL;
1037 p_input->p_es_out = NULL;
1038 p_input->p_sout = NULL;
1040 return VLC_EGENERIC;
1043 /*****************************************************************************
1044 * Error: RunThread() error loop
1045 *****************************************************************************
1046 * This function is called when an error occurred during thread main's loop.
1047 *****************************************************************************/
1048 static void Error( input_thread_t *p_input )
1050 while( !p_input->b_die )
1053 msleep( INPUT_IDLE_SLEEP );
1057 /*****************************************************************************
1058 * End: end the input thread
1059 *****************************************************************************/
1060 static void End( input_thread_t * p_input )
1065 msg_Dbg( p_input, "closing input" );
1067 /* We are at the end */
1068 p_input->i_state = END_S;
1071 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1073 /* Clean control variables */
1074 input_ControlVarClean( p_input );
1076 /* Clean up master */
1077 InputSourceClean( p_input, &p_input->input );
1080 for( i = 0; i < p_input->i_slave; i++ )
1082 InputSourceClean( p_input, p_input->slave[i] );
1083 free( p_input->slave[i] );
1085 if( p_input->slave ) free( p_input->slave );
1087 /* Unload all modules */
1088 if( p_input->p_es_out )
1089 input_EsOutDelete( p_input->p_es_out );
1091 /* Close optional stream output instance */
1092 if( p_input->p_sout )
1094 vlc_object_t *p_pl =
1095 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1098 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
1100 /* attach sout to the playlist */
1101 msg_Warn( p_input, "keeping sout" );
1102 vlc_object_detach( p_input->p_sout );
1103 vlc_object_attach( p_input->p_sout, p_pl );
1107 msg_Warn( p_input, "destroying sout" );
1108 sout_DeleteInstance( p_input->p_sout );
1111 vlc_object_release( p_pl );
1115 if( p_input->p_meta )
1116 vlc_meta_Delete( p_input->p_meta );
1118 /* Tell we're dead */
1119 p_input->b_dead = VLC_TRUE;
1122 /*****************************************************************************
1124 *****************************************************************************/
1125 static inline int ControlPopNoLock( input_thread_t *p_input,
1126 int *pi_type, vlc_value_t *p_val )
1128 if( p_input->i_control <= 0 )
1130 return VLC_EGENERIC;
1133 *pi_type = p_input->control[0].i_type;
1134 *p_val = p_input->control[0].val;
1136 p_input->i_control--;
1137 if( p_input->i_control > 0 )
1141 for( i = 0; i < p_input->i_control; i++ )
1143 p_input->control[i].i_type = p_input->control[i+1].i_type;
1144 p_input->control[i].val = p_input->control[i+1].val;
1151 static void ControlReduce( input_thread_t *p_input )
1154 for( i = 1; i < p_input->i_control; i++ )
1156 const int i_lt = p_input->control[i-1].i_type;
1157 const int i_ct = p_input->control[i].i_type;
1159 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1160 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
1164 ( i_ct == INPUT_CONTROL_SET_STATE ||
1165 i_ct == INPUT_CONTROL_SET_RATE ||
1166 i_ct == INPUT_CONTROL_SET_POSITION ||
1167 i_ct == INPUT_CONTROL_SET_TIME ||
1168 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1169 i_ct == INPUT_CONTROL_SET_TITLE ||
1170 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1171 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1174 // msg_Dbg( p_input, "merged at %d", i );
1175 /* Remove the i-1 */
1176 for( j = i; j < p_input->i_control; j++ )
1177 p_input->control[j-1] = p_input->control[j];
1178 p_input->i_control--;
1182 /* TODO but that's not that important
1183 - merge SET_X with SET_X_CMD
1184 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1185 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1192 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
1195 vlc_bool_t b_force_update = VLC_FALSE;
1199 case INPUT_CONTROL_SET_DIE:
1200 msg_Dbg( p_input, "control: stopping input" );
1201 /* Mark all submodules to die */
1202 if( p_input->input.p_access )
1203 p_input->input.p_access->b_die = VLC_TRUE;
1204 if( p_input->input.p_stream )
1205 p_input->input.p_stream->b_die = VLC_TRUE;
1206 p_input->input.p_demux->b_die = VLC_TRUE;
1208 p_input->b_die = VLC_TRUE;
1211 case INPUT_CONTROL_SET_POSITION:
1212 case INPUT_CONTROL_SET_POSITION_OFFSET:
1215 if( i_type == INPUT_CONTROL_SET_POSITION )
1217 f_pos = val.f_float;
1221 /* Should not fail */
1222 demux2_Control( p_input->input.p_demux,
1223 DEMUX_GET_POSITION, &f_pos );
1224 f_pos += val.f_float;
1226 if( f_pos < 0.0 ) f_pos = 0.0;
1227 if( f_pos > 1.0 ) f_pos = 1.0;
1228 /* Reset the decoders states and clock synch (before calling the demuxer */
1229 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1230 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1231 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
1234 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1235 "%2.1f%% failed", f_pos * 100 );
1239 if( p_input->i_slave > 0 )
1240 SlaveSeek( p_input );
1242 //input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1243 //es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1244 b_force_update = VLC_TRUE;
1249 case INPUT_CONTROL_SET_TIME:
1250 case INPUT_CONTROL_SET_TIME_OFFSET:
1255 if( i_type == INPUT_CONTROL_SET_TIME )
1257 i_time = val.i_time;
1261 /* Should not fail */
1262 demux2_Control( p_input->input.p_demux,
1263 DEMUX_GET_TIME, &i_time );
1264 i_time += val.i_time;
1266 if( i_time < 0 ) i_time = 0;
1268 /* Reset the decoders states and clock synch (before calling the demuxer */
1269 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1270 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1272 i_ret = demux2_Control( p_input->input.p_demux,
1273 DEMUX_SET_TIME, i_time );
1277 /* Emulate it with a SET_POS */
1279 demux2_Control( p_input->input.p_demux,
1280 DEMUX_GET_LENGTH, &i_length );
1283 double f_pos = (double)i_time / (double)i_length;
1284 i_ret = demux2_Control( p_input->input.p_demux,
1285 DEMUX_SET_POSITION, f_pos );
1290 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1291 " failed", i_time );
1295 if( p_input->i_slave > 0 )
1296 SlaveSeek( p_input );
1298 //input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1299 //es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1300 b_force_update = VLC_TRUE;
1305 case INPUT_CONTROL_SET_STATE:
1306 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1307 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1310 if( p_input->input.p_access )
1311 i_ret = access2_Control( p_input->input.p_access,
1312 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1314 i_ret = demux2_Control( p_input->input.p_demux,
1315 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1319 /* FIXME What to do ? */
1320 msg_Warn( p_input, "cannot unset pause -> EOF" );
1321 vlc_mutex_unlock( &p_input->lock_control );
1322 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1323 vlc_mutex_lock( &p_input->lock_control );
1326 b_force_update = VLC_TRUE;
1328 /* Switch to play */
1329 p_input->i_state = PLAYING_S;
1330 val.i_int = PLAYING_S;
1331 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1334 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1336 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1337 p_input->b_can_pause )
1340 if( p_input->input.p_access )
1341 i_ret = access2_Control( p_input->input.p_access,
1342 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1344 i_ret = demux2_Control( p_input->input.p_demux,
1345 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1347 b_force_update = VLC_TRUE;
1351 msg_Warn( p_input, "cannot set pause state" );
1352 val.i_int = p_input->i_state;
1356 val.i_int = PAUSE_S;
1359 /* Switch to new state */
1360 p_input->i_state = val.i_int;
1361 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1363 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1365 b_force_update = VLC_TRUE;
1367 /* Correct "state" value */
1368 val.i_int = p_input->i_state;
1369 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1371 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1373 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1377 case INPUT_CONTROL_SET_RATE:
1378 case INPUT_CONTROL_SET_RATE_SLOWER:
1379 case INPUT_CONTROL_SET_RATE_FASTER:
1383 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1384 i_rate = p_input->i_rate * 2;
1385 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1386 i_rate = p_input->i_rate / 2;
1390 if( i_rate < INPUT_RATE_MIN )
1392 msg_Dbg( p_input, "cannot set rate faster" );
1393 i_rate = INPUT_RATE_MIN;
1395 else if( i_rate > INPUT_RATE_MAX )
1397 msg_Dbg( p_input, "cannot set rate slower" );
1398 i_rate = INPUT_RATE_MAX;
1400 if( i_rate != INPUT_RATE_DEFAULT &&
1401 ( !p_input->b_can_pace_control ||
1402 ( p_input->p_sout && !p_input->b_out_pace_control ) ) )
1404 msg_Dbg( p_input, "cannot change rate" );
1405 i_rate = INPUT_RATE_DEFAULT;
1407 if( i_rate != p_input->i_rate )
1409 p_input->i_rate = i_rate;
1411 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1413 /* We haven't send data to decoder when rate != default */
1414 if( i_rate == INPUT_RATE_DEFAULT )
1415 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1418 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1420 b_force_update = VLC_TRUE;
1425 case INPUT_CONTROL_SET_PROGRAM:
1426 /* No need to force update, es_out does it if needed */
1427 es_out_Control( p_input->p_es_out,
1428 ES_OUT_SET_GROUP, val.i_int );
1430 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1434 case INPUT_CONTROL_SET_ES:
1435 /* No need to force update, es_out does it if needed */
1436 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1437 input_EsOutGetFromID( p_input->p_es_out,
1441 case INPUT_CONTROL_SET_AUDIO_DELAY:
1442 input_EsOutSetDelay( p_input->p_es_out,
1443 AUDIO_ES, val.i_time );
1444 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1447 case INPUT_CONTROL_SET_SPU_DELAY:
1448 input_EsOutSetDelay( p_input->p_es_out,
1449 SPU_ES, val.i_time );
1450 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1453 case INPUT_CONTROL_SET_TITLE:
1454 case INPUT_CONTROL_SET_TITLE_NEXT:
1455 case INPUT_CONTROL_SET_TITLE_PREV:
1456 if( p_input->input.b_title_demux &&
1457 p_input->input.i_title > 0 )
1460 /* FIXME handle demux title */
1461 demux_t *p_demux = p_input->input.p_demux;
1464 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1465 i_title = p_demux->info.i_title - 1;
1466 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1467 i_title = p_demux->info.i_title + 1;
1469 i_title = val.i_int;
1471 if( i_title >= 0 && i_title < p_input->input.i_title )
1473 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1475 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1476 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1478 input_ControlVarTitle( p_input, i_title );
1481 else if( p_input->input.i_title > 0 )
1483 access_t *p_access = p_input->input.p_access;
1486 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1487 i_title = p_access->info.i_title - 1;
1488 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1489 i_title = p_access->info.i_title + 1;
1491 i_title = val.i_int;
1493 if( i_title >= 0 && i_title < p_input->input.i_title )
1495 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1496 stream_AccessReset( p_input->input.p_stream );
1498 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1499 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1503 case INPUT_CONTROL_SET_SEEKPOINT:
1504 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1505 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1506 if( p_input->input.b_title_demux &&
1507 p_input->input.i_title > 0 )
1509 demux_t *p_demux = p_input->input.p_demux;
1511 int64_t i_input_time;
1512 int64_t i_seekpoint_time;
1514 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1516 i_seekpoint = p_demux->info.i_seekpoint;
1517 i_seekpoint_time = p_input->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1518 if( i_seekpoint_time >= 0 &&
1519 !demux2_Control( p_demux,
1520 DEMUX_GET_TIME, &i_input_time ) )
1522 if ( i_input_time < i_seekpoint_time + 3000000 )
1528 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1529 i_seekpoint = p_demux->info.i_seekpoint + 1;
1531 i_seekpoint = val.i_int;
1533 if( i_seekpoint >= 0 && i_seekpoint <
1534 p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1536 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1538 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1539 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1542 else if( p_input->input.i_title > 0 )
1544 demux_t *p_demux = p_input->input.p_demux;
1545 access_t *p_access = p_input->input.p_access;
1547 int64_t i_input_time;
1548 int64_t i_seekpoint_time;
1550 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1552 i_seekpoint = p_access->info.i_seekpoint;
1553 i_seekpoint_time = p_input->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1554 if( i_seekpoint_time >= 0 &&
1555 demux2_Control( p_demux,
1556 DEMUX_GET_TIME, &i_input_time ) )
1558 if ( i_input_time < i_seekpoint_time + 3000000 )
1564 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1565 i_seekpoint = p_access->info.i_seekpoint + 1;
1567 i_seekpoint = val.i_int;
1569 if( i_seekpoint >= 0 && i_seekpoint <
1570 p_input->input.title[p_access->info.i_title]->i_seekpoint )
1572 access2_Control( p_access, ACCESS_SET_SEEKPOINT, i_seekpoint );
1573 stream_AccessReset( p_input->input.p_stream );
1575 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1576 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1581 case INPUT_CONTROL_ADD_SLAVE:
1582 if( val.psz_string )
1584 input_source_t *slave = InputSourceNew( p_input );
1586 if( !InputSourceInit( p_input, slave, val.psz_string, NULL,
1589 vlc_meta_t *p_meta_new = NULL;
1594 msg_Dbg( p_input, "adding %s as slave on the fly",
1598 if( demux2_Control( p_input->input.p_demux,
1599 DEMUX_GET_TIME, &i_time ) )
1601 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1602 InputSourceClean( p_input, slave );
1606 if( demux2_Control( slave->p_demux,
1607 DEMUX_SET_TIME, i_time ) )
1609 msg_Err( p_input, "seek failed for new slave" );
1610 InputSourceClean( p_input, slave );
1616 /* Get meta (access and demux) */
1617 if( access2_Control( slave->p_access,
1618 ACCESS_GET_META, &p_meta_new ) )
1620 if( !demux2_Control( slave->p_demux,
1621 DEMUX_GET_META, &p_meta ) )
1625 vlc_meta_Merge( p_meta_new, p_meta );
1626 vlc_meta_Delete( p_meta );
1630 p_meta_new = p_meta;
1636 if( p_input->p_meta )
1638 vlc_meta_Merge( p_input->p_meta, p_meta_new );
1639 vlc_meta_Delete( p_meta_new );
1643 p_input->p_meta = p_meta_new;
1645 UpdateMeta( p_input, VLC_FALSE );
1648 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
1652 msg_Warn( p_input, "failed to add %s as slave",
1656 free( val.psz_string );
1660 case INPUT_CONTROL_SET_BOOKMARK:
1662 msg_Err( p_input, "not yet implemented" );
1666 return b_force_update;
1669 /*****************************************************************************
1671 *****************************************************************************/
1672 static int UpdateFromDemux( input_thread_t *p_input )
1674 demux_t *p_demux = p_input->input.p_demux;
1677 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1679 v.i_int = p_demux->info.i_title;
1680 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1682 input_ControlVarTitle( p_input, p_demux->info.i_title );
1684 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1686 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1688 v.i_int = p_demux->info.i_seekpoint;
1689 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1691 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1693 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1695 /* Hmmm only works with master input */
1696 if( p_input->input.p_demux == p_demux )
1698 int i_title_end = p_input->input.i_title_end -
1699 p_input->input.i_title_offset;
1700 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1701 p_input->input.i_seekpoint_offset;
1703 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
1705 if( p_demux->info.i_title > i_title_end ||
1706 ( p_demux->info.i_title == i_title_end &&
1707 p_demux->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1709 else if( i_seekpoint_end >=0 )
1711 if( p_demux->info.i_seekpoint > i_seekpoint_end ) return 0;
1713 else if( i_title_end >= 0 )
1715 if( p_demux->info.i_title > i_title_end ) return 0;
1722 /*****************************************************************************
1724 *****************************************************************************/
1725 static int UpdateFromAccess( input_thread_t *p_input )
1727 access_t *p_access = p_input->input.p_access;
1730 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1732 v.i_int = p_access->info.i_title;
1733 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1735 input_ControlVarTitle( p_input, p_access->info.i_title );
1737 stream_AccessUpdate( p_input->input.p_stream );
1739 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1741 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1743 v.i_int = p_access->info.i_seekpoint;
1744 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1746 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1748 if( p_access->info.i_update & INPUT_UPDATE_META )
1750 /* TODO maybe multi - access ? */
1752 if( !access2_Control( p_input->input.p_access,ACCESS_GET_META,&p_meta))
1754 if( p_input->p_meta )
1756 vlc_meta_Merge( p_input->p_meta, p_meta );
1757 vlc_meta_Delete( p_meta );
1761 p_input->p_meta = p_meta;
1764 UpdateMeta( p_input, VLC_FALSE );
1765 var_SetBool( p_input, "item-change", p_input->input.p_item->i_id );
1767 p_access->info.i_update &= ~INPUT_UPDATE_META;
1770 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1772 /* Hmmm only works with master input */
1773 if( p_input->input.p_access == p_access )
1775 int i_title_end = p_input->input.i_title_end -
1776 p_input->input.i_title_offset;
1777 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1778 p_input->input.i_seekpoint_offset;
1780 if( i_title_end >= 0 && i_seekpoint_end >=0 )
1782 if( p_access->info.i_title > i_title_end ||
1783 ( p_access->info.i_title == i_title_end &&
1784 p_access->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1786 else if( i_seekpoint_end >=0 )
1788 if( p_access->info.i_seekpoint > i_seekpoint_end ) return 0;
1790 else if( i_title_end >= 0 )
1792 if( p_access->info.i_title > i_title_end ) return 0;
1799 /*****************************************************************************
1801 *****************************************************************************/
1802 static int UpdateMeta( input_thread_t *p_input, vlc_bool_t b_quick )
1804 vlc_meta_t *p_meta = p_input->p_meta;
1807 if( !p_meta || p_meta->i_meta == 0 )
1810 if( !b_quick ) msg_Dbg( p_input, "meta information:" );
1811 for( i = 0; i < p_meta->i_meta; i++ )
1814 msg_Dbg( p_input, " - '%s' = '%s'",
1815 _(p_meta->name[i]), p_meta->value[i] );
1817 if( !strcmp(p_meta->name[i], VLC_META_TITLE) && p_meta->value[i] &&
1818 !p_input->input.p_item->b_fixed_name )
1819 input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
1821 if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
1822 input_Control( p_input, INPUT_ADD_INFO, _("General"),
1823 _("Author"), p_meta->value[i] );
1825 input_Control( p_input, INPUT_ADD_INFO, _("Meta-information"),
1826 _(p_meta->name[i]), "%s", p_meta->value[i] );
1829 for( i = 0; i < p_meta->i_track; i++ )
1831 vlc_meta_t *tk = p_meta->track[i];
1834 if( tk->i_meta > 0 )
1836 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
1838 msg_Dbg( p_input, " - track[%d]:", i );
1840 sprintf( psz_cat, "%s %d", _("Stream"), i );
1841 for( j = 0; j < tk->i_meta; j++ )
1843 msg_Dbg( p_input, " - '%s' = '%s'", _(tk->name[j]),
1846 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1847 _(tk->name[j]), "%s", tk->value[j] );
1852 if( p_input->p_sout && p_input->p_sout->p_meta == NULL )
1854 p_input->p_sout->p_meta = vlc_meta_Duplicate( p_meta );
1860 /*****************************************************************************
1862 *****************************************************************************/
1863 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length,
1864 vlc_bool_t b_quick )
1866 playlist_t *p_playlist;
1867 char psz_buffer[MSTRTIME_MAX_SIZE];
1869 vlc_mutex_lock( &p_input->input.p_item->lock );
1870 p_input->input.p_item->i_duration = i_length;
1871 vlc_mutex_unlock( &p_input->input.p_item->lock );
1873 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
1877 var_SetInteger( p_playlist, "item-change",
1878 p_input->input.p_item->i_id );
1879 vlc_object_release( p_playlist );
1882 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
1883 msecstotimestr( psz_buffer, i_length / 1000 ) );
1886 /*****************************************************************************
1888 *****************************************************************************/
1889 static input_source_t *InputSourceNew( input_thread_t *p_input )
1891 input_source_t *in = malloc( sizeof( input_source_t ) );
1894 in->p_access = NULL;
1895 in->p_stream = NULL;
1897 in->b_title_demux = VLC_FALSE;
1900 in->b_can_pace_control = VLC_TRUE;
1901 in->b_eof = VLC_FALSE;
1902 in->i_cr_average = 0;
1907 /*****************************************************************************
1909 *****************************************************************************/
1910 static int InputSourceInit( input_thread_t *p_input,
1911 input_source_t *in, char *psz_mrl,
1912 char *psz_forced_demux, vlc_bool_t b_quick )
1914 char *psz_dup = strdup( psz_mrl );
1925 MRLSplit( VLC_OBJECT(p_input), psz_dup,
1926 &psz_access, &psz_demux, &psz_path );
1928 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
1929 psz_mrl, psz_access, psz_demux, psz_path );
1931 /* Hack to allow udp://@:port syntax */
1933 (strncmp( psz_access, "udp", 3 ) &&
1934 strncmp( psz_access, "rtp", 3 )) )
1936 /* Find optional titles and seekpoints */
1937 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
1938 &in->i_seekpoint_start, &in->i_seekpoint_end );
1940 if( psz_forced_demux && *psz_forced_demux )
1941 psz_demux = psz_forced_demux;
1943 /* Try access_demux if no demux given */
1944 if( *psz_demux == '\0' )
1946 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
1947 NULL, p_input->p_es_out, VLC_FALSE );
1953 msg_Dbg( p_input, "trying to preparse %s", psz_path );
1954 psz_demux = strdup( "" );
1955 psz_access = strdup( "file" );
1960 int64_t i_pts_delay;
1962 /* Get infos from access_demux */
1963 demux2_Control( in->p_demux,
1964 DEMUX_GET_PTS_DELAY, &i_pts_delay );
1965 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
1967 in->b_title_demux = VLC_TRUE;
1968 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
1969 &in->title, &in->i_title,
1970 &in->i_title_offset, &in->i_seekpoint_offset ) )
1975 demux2_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
1976 &in->b_can_pace_control );
1977 demux2_Control( in->p_demux, DEMUX_CAN_PAUSE,
1981 demux2_Control( in->p_demux, DEMUX_CAN_SEEK,
1987 int64_t i_pts_delay;
1989 /* Now try a real access */
1990 in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path,
1993 /* Access failed, URL encoded ? */
1994 if( in->p_access == NULL && strchr( psz_path, '%' ) )
1996 DecodeUrl( psz_path );
1998 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
1999 psz_access, psz_demux, psz_path );
2001 in->p_access = access2_New( p_input,
2002 psz_access, psz_demux, psz_path,
2005 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
2006 * are forbidden in filenames on Win32. */
2008 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
2009 if( in->p_access == NULL &&
2010 *psz_access == '\0' && ( *psz_demux || *psz_path ) )
2013 psz_dup = strdup( psz_mrl );
2018 in->p_access = access2_New( p_input,
2019 psz_access, psz_demux, psz_path,
2024 if( in->p_access == NULL )
2026 msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
2031 psz_tmp = psz = var_GetString( p_input, "access-filter" );
2032 while( psz && *psz )
2034 access_t *p_access = in->p_access;
2035 char *end = strchr( psz, ':' );
2040 in->p_access = access2_FilterNew( in->p_access, psz );
2041 if( in->p_access == NULL )
2043 in->p_access = p_access;
2044 msg_Warn( p_input, "failed to insert access filter %s",
2052 /* Get infos from access */
2055 access2_Control( in->p_access,
2056 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2057 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2059 in->b_title_demux = VLC_FALSE;
2060 if( access2_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2061 &in->title, &in->i_title,
2062 &in->i_title_offset, &in->i_seekpoint_offset ) )
2068 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2069 &in->b_can_pace_control );
2070 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
2072 access2_Control( in->p_access, ACCESS_CAN_SEEK,
2074 var_Set( p_input, "seekable", val );
2077 /* Create the stream_t */
2078 in->p_stream = stream_AccessNew( in->p_access, b_quick );
2079 if( in->p_stream == NULL )
2081 msg_Warn( p_input, "cannot create a stream_t from access" );
2085 /* Open a demuxer */
2086 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2088 psz_demux = in->p_access->psz_demux;
2090 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2091 in->p_stream, p_input->p_es_out, b_quick );
2092 if( in->p_demux == NULL )
2094 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2095 psz_access, psz_demux, psz_path );
2099 /* TODO get title from demux */
2100 if( !b_quick && in->i_title <= 0 )
2102 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2103 &in->title, &in->i_title,
2104 &in->i_title_offset, &in->i_seekpoint_offset ))
2111 in->b_title_demux = VLC_TRUE;
2116 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2117 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2124 demux2_Delete( in->p_demux );
2127 stream_Delete( in->p_stream );
2130 access2_Delete( in->p_access );
2133 return VLC_EGENERIC;
2136 /*****************************************************************************
2138 *****************************************************************************/
2139 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
2142 demux2_Delete( in->p_demux );
2145 stream_Delete( in->p_stream );
2148 access2_Delete( in->p_access );
2150 if( in->i_title > 0 )
2153 for( i = 0; i < in->i_title; i++ )
2155 vlc_input_title_Delete( in->title[i] );
2161 static void SlaveDemux( input_thread_t *p_input )
2165 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2167 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2171 for( i = 0; i < p_input->i_slave; i++ )
2173 input_source_t *in = p_input->slave[i];
2179 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2184 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2186 msg_Err( p_input, "slave[%d] doesn't like "
2187 "DEMUX_GET_TIME -> EOF", i );
2192 if( i_stime >= i_time )
2195 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
2201 i_ret = in->p_demux->pf_demux( in->p_demux );
2206 msg_Dbg( p_input, "slave %d EOF", i );
2207 in->b_eof = VLC_TRUE;
2212 static void SlaveSeek( input_thread_t *p_input )
2217 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2219 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2223 for( i = 0; i < p_input->i_slave; i++ )
2225 input_source_t *in = p_input->slave[i];
2227 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2229 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2230 in->b_eof = VLC_TRUE;
2234 /*****************************************************************************
2236 *****************************************************************************/
2237 static vlc_meta_t *InputMetaUser( input_thread_t *p_input )
2242 if( ( p_meta = vlc_meta_New() ) == NULL )
2245 /* Get meta information from user */
2246 #define GET_META( c, s ) \
2247 var_Get( p_input, (s), &val ); \
2248 if( *val.psz_string ) \
2249 vlc_meta_Add( p_meta, c, val.psz_string ); \
2250 free( val.psz_string )
2252 GET_META( VLC_META_TITLE, "meta-title" );
2253 GET_META( VLC_META_AUTHOR, "meta-author" );
2254 GET_META( VLC_META_ARTIST, "meta-artist" );
2255 GET_META( VLC_META_GENRE, "meta-genre" );
2256 GET_META( VLC_META_COPYRIGHT, "meta-copyright" );
2257 GET_META( VLC_META_DESCRIPTION, "meta-description" );
2258 GET_META( VLC_META_DATE, "meta-date" );
2259 GET_META( VLC_META_URL, "meta-url" );
2265 /*****************************************************************************
2266 * DecodeUrl: decode a given encoded url
2267 *****************************************************************************/
2268 static void DecodeUrl( char *psz )
2270 char *dup = strdup( psz );
2288 *psz++ = strtol( val, NULL, 16 );
2290 else if( *p == '+' )
2304 /*****************************************************************************
2305 * ParseOption: parses the options for the input
2306 *****************************************************************************
2307 * This function parses the input (config) options and creates their associated
2309 * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
2310 * bar is the value of the option.
2311 *****************************************************************************/
2312 static void ParseOption( input_thread_t *p_input, const char *psz_option )
2314 char *psz_name = (char *)psz_option;
2315 char *psz_value = strchr( psz_option, '=' );
2316 int i_name_len, i_type;
2317 vlc_bool_t b_isno = VLC_FALSE;
2320 if( psz_value ) i_name_len = psz_value - psz_option;
2321 else i_name_len = strlen( psz_option );
2323 /* It's too much of an hassle to remove the ':' when we parse
2324 * the cmd line :) */
2325 if( i_name_len && *psz_name == ':' )
2331 if( i_name_len == 0 ) return;
2333 psz_name = strndup( psz_name, i_name_len );
2334 if( psz_value ) psz_value++;
2336 i_type = config_GetType( p_input, psz_name );
2338 if( !i_type && !psz_value )
2340 /* check for "no-foo" or "nofoo" */
2341 if( !strncmp( psz_name, "no-", 3 ) )
2343 memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
2345 else if( !strncmp( psz_name, "no", 2 ) )
2347 memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
2349 else goto cleanup; /* Option doesn't exist */
2352 i_type = config_GetType( p_input, psz_name );
2354 if( !i_type ) goto cleanup; /* Option doesn't exist */
2356 else if( !i_type ) goto cleanup; /* Option doesn't exist */
2358 if( ( i_type != VLC_VAR_BOOL ) &&
2359 ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */
2361 /* Create the variable in the input object.
2362 * Children of the input object will be able to retreive this value
2363 * thanks to the inheritance property of the object variables. */
2364 var_Create( p_input, psz_name, i_type );
2369 val.b_bool = !b_isno;
2372 case VLC_VAR_INTEGER:
2373 val.i_int = atoi( psz_value );
2377 val.f_float = atof( psz_value );
2380 case VLC_VAR_STRING:
2381 case VLC_VAR_MODULE:
2383 case VLC_VAR_DIRECTORY:
2384 val.psz_string = psz_value;
2392 var_Set( p_input, psz_name, val );
2394 msg_Dbg( p_input, "set input option: %s to %s", psz_name,
2395 psz_value ? psz_value : ( val.b_bool ? "true" : "false") );
2398 if( psz_name ) free( psz_name );
2402 /*****************************************************************************
2403 * MRLSplit: parse the access, demux and url part of the
2404 * Media Resource Locator.
2405 *****************************************************************************/
2406 void MRLSplit( vlc_object_t *p_input, char *psz_dup,
2407 char **ppsz_access, char **ppsz_demux, char **ppsz_path )
2409 char *psz_access = NULL;
2410 char *psz_demux = NULL;
2411 char *psz_path = NULL;
2412 char *psz, *psz_check;
2414 psz = strchr( psz_dup, ':' );
2416 /* '@' not allowed in access/demux part */
2417 psz_check = strchr( psz_dup, '@' );
2418 if( psz_check && psz_check < psz ) psz = 0;
2420 #if defined( WIN32 ) || defined( UNDER_CE )
2421 if( psz - psz_dup == 1 )
2423 msg_Warn( p_input, "drive letter %c: found in source", *psz_dup );
2432 if( psz[0] == '/' && psz[1] == '/' ) psz += 2;
2436 psz = strchr( psz_dup, '/' );
2443 psz_access = psz_dup;
2450 if( !psz_access ) *ppsz_access = "";
2451 else *ppsz_access = psz_access;
2453 if( !psz_demux ) *ppsz_demux = "";
2454 else *ppsz_demux = psz_demux;
2456 if( !psz_path ) *ppsz_path = "";
2457 else *ppsz_path = psz_path;
2460 /*****************************************************************************
2461 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
2464 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
2465 *****************************************************************************/
2466 static void MRLSections( input_thread_t *p_input, char *psz_source,
2467 int *pi_title_start, int *pi_title_end,
2468 int *pi_chapter_start, int *pi_chapter_end )
2470 char *psz, *psz_end, *psz_next, *psz_check;
2472 *pi_title_start = *pi_title_end = -1;
2473 *pi_chapter_start = *pi_chapter_end = -1;
2475 /* Start by parsing titles and chapters */
2476 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
2478 /* Check we are really dealing with a title/chapter section */
2479 psz_check = psz + 1;
2480 if( !*psz_check ) return;
2481 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2482 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
2483 if( *psz_check == ':' && ++psz_check )
2484 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2485 if( *psz_check != '-' && *psz_check ) return;
2486 if( *psz_check == '-' && ++psz_check )
2487 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2488 if( *psz_check != ':' && *psz_check ) return;
2489 if( *psz_check == ':' && ++psz_check )
2490 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2491 if( *psz_check ) return;
2493 /* Separate start and end */
2495 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
2497 /* Look for the start title */
2498 *pi_title_start = strtol( psz, &psz_next, 0 );
2499 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
2500 *pi_title_end = *pi_title_start;
2503 /* Look for the start chapter */
2505 *pi_chapter_start = strtol( psz, &psz_next, 0 );
2506 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
2507 *pi_chapter_end = *pi_chapter_start;
2511 /* Look for the end title */
2512 *pi_title_end = strtol( psz_end, &psz_next, 0 );
2513 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
2516 /* Look for the end chapter */
2517 if( *psz_end ) psz_end++;
2518 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
2519 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
2522 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
2523 psz_source, *pi_title_start, *pi_chapter_start,
2524 *pi_title_end, *pi_chapter_end );
2528 /***********************************************************************
2529 * Info management functions
2530 ***********************************************************************/
2532 * Get a info item from a given category in a given input item.
2534 * \param p_i The input item to get info from
2535 * \param psz_cat String representing the category for the info
2536 * \param psz_name String representing the name of the desired info
2537 * \return A pointer to the string with the given info if found, or an
2538 * empty string otherwise. The caller should free the returned
2541 char *vlc_input_item_GetInfo( input_item_t *p_i,
2542 const char *psz_cat,
2543 const char *psz_name )
2547 vlc_mutex_lock( &p_i->lock );
2549 for( i = 0 ; i< p_i->i_categories ; i++ )
2551 info_category_t *p_cat = p_i->pp_categories[i];
2553 if( !psz_cat || strcmp( p_cat->psz_name, psz_cat ) )
2556 for( j = 0; j < p_cat->i_infos ; j++ )
2558 if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
2560 char *psz_ret = strdup( p_cat->pp_infos[j]->psz_value );
2561 vlc_mutex_unlock( &p_i->lock );
2566 vlc_mutex_unlock( &p_i->lock );
2567 return strdup( "" );
2570 int vlc_input_item_AddInfo( input_item_t *p_i,
2571 const char *psz_cat,
2572 const char *psz_name,
2573 const char *psz_format, ... )
2577 info_t *p_info = NULL;
2578 info_category_t *p_cat = NULL ;
2580 vlc_mutex_lock( &p_i->lock );
2582 for( i = 0 ; i < p_i->i_categories ; i ++ )
2584 if( !strcmp( p_i->pp_categories[i]->psz_name, psz_cat ) )
2586 p_cat = p_i->pp_categories[i];
2592 if( !(p_cat = (info_category_t *)malloc( sizeof(info_category_t) )) )
2594 vlc_mutex_unlock( &p_i->lock );
2595 return VLC_EGENERIC;
2597 p_cat->psz_name = strdup( psz_cat );
2599 p_cat->pp_infos = 0;
2600 INSERT_ELEM( p_i->pp_categories, p_i->i_categories, p_i->i_categories,
2604 for( i = 0; i< p_cat->i_infos; i++ )
2606 if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
2608 p_info = p_cat->pp_infos[i];
2615 if( ( p_info = (info_t *)malloc( sizeof( info_t ) ) ) == NULL )
2617 vlc_mutex_unlock( &p_i->lock );
2618 return VLC_EGENERIC;
2620 INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
2621 p_info->psz_name = strdup( psz_name );
2625 if( p_info->psz_value ) free( p_info->psz_value );
2628 va_start( args, psz_format );
2629 vasprintf( &p_info->psz_value, psz_format, args);
2632 vlc_mutex_unlock( &p_i->lock );