1 /*****************************************************************************
2 * item.c: input_item management
3 *****************************************************************************
4 * Copyright (C) 1998-2004 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
29 #include <vlc_common.h>
31 #include "vlc_playlist.h"
32 #include "vlc_interface.h"
36 static int GuessType( const input_item_t *p_item );
38 /** Stuff moved out of vlc_input.h -- FIXME: should probably not be inline
40 static inline void input_item_Init( vlc_object_t *p_o, input_item_t *p_i )
42 memset( p_i, 0, sizeof(input_item_t) );
46 TAB_INIT( p_i->i_es, p_i->es );
47 TAB_INIT( p_i->i_options, p_i->ppsz_options );
48 p_i->optflagv = NULL, p_i->optflagc = 0;
49 TAB_INIT( p_i->i_categories, p_i->pp_categories );
50 TAB_INIT( p_i->i_epg, p_i->pp_epg );
52 p_i->i_type = ITEM_TYPE_UNKNOWN;
53 p_i->b_fixed_name = true;
58 vlc_mutex_init( &p_i->lock );
59 vlc_event_manager_t * p_em = &p_i->event_manager;
60 vlc_event_manager_init( p_em, p_i, p_o );
61 vlc_event_manager_register_event_type( p_em, vlc_InputItemMetaChanged );
62 vlc_event_manager_register_event_type( p_em, vlc_InputItemSubItemAdded );
63 vlc_event_manager_register_event_type( p_em, vlc_InputItemDurationChanged );
64 vlc_event_manager_register_event_type( p_em, vlc_InputItemPreparsedChanged );
65 vlc_event_manager_register_event_type( p_em, vlc_InputItemNameChanged );
66 vlc_event_manager_register_event_type( p_em, vlc_InputItemInfoChanged );
67 vlc_event_manager_register_event_type( p_em, vlc_InputItemErrorWhenReadingChanged );
70 static inline void input_item_Clean( input_item_t *p_i )
74 vlc_event_manager_fini( &p_i->event_manager );
76 free( p_i->psz_name );
80 vlc_mutex_destroy( &p_i->p_stats->lock );
85 vlc_meta_Delete( p_i->p_meta );
87 for( i = 0; i < p_i->i_options; i++ )
88 free( p_i->ppsz_options[i] );
89 TAB_CLEAN( p_i->i_options, p_i->ppsz_options );
92 for( i = 0; i < p_i->i_es; i++ )
94 es_format_Clean( p_i->es[i] );
97 TAB_CLEAN( p_i->i_es, p_i->es );
99 for( i = 0; i < p_i->i_epg; i++ )
100 vlc_epg_Delete( p_i->pp_epg[i] );
101 TAB_CLEAN( p_i->i_epg, p_i->pp_epg );
103 for( i = 0; i < p_i->i_categories; i++ )
105 info_category_t *p_category = p_i->pp_categories[i];
108 for( j = 0; j < p_category->i_infos; j++ )
110 struct info_t *p_info = p_category->pp_infos[j];
112 free( p_info->psz_name);
113 free( p_info->psz_value );
116 TAB_CLEAN( p_category->i_infos, p_category->pp_infos );
118 free( p_category->psz_name );
121 TAB_CLEAN( p_i->i_categories, p_i->pp_categories );
123 vlc_mutex_destroy( &p_i->lock );
125 void input_item_SetErrorWhenReading( input_item_t *p_i, bool b_error )
129 vlc_mutex_lock( &p_i->lock );
131 b_changed = p_i->b_error_when_reading != b_error;
132 p_i->b_error_when_reading = b_error;
134 vlc_mutex_unlock( &p_i->lock );
140 event.type = vlc_InputItemErrorWhenReadingChanged;
141 event.u.input_item_error_when_reading_changed.new_value = b_error;
142 vlc_event_send( &p_i->event_manager, &event );
145 void input_item_SetPreparsed( input_item_t *p_i, bool b_preparsed )
147 bool b_send_event = false;
149 vlc_mutex_lock( &p_i->lock );
152 p_i->p_meta = vlc_meta_New();
154 int status = vlc_meta_GetStatus(p_i->p_meta);
157 new_status = status | ITEM_PREPARSED;
159 new_status = status & ~ITEM_PREPARSED;
160 if( status != new_status )
162 vlc_meta_SetStatus(p_i->p_meta, new_status);
166 vlc_mutex_unlock( &p_i->lock );
171 event.type = vlc_InputItemPreparsedChanged;
172 event.u.input_item_preparsed_changed.new_status = new_status;
173 vlc_event_send( &p_i->event_manager, &event );
177 void input_item_SetArtNotFound( input_item_t *p_i, bool b_not_found )
179 vlc_mutex_lock( &p_i->lock );
182 p_i->p_meta = vlc_meta_New();
184 int status = vlc_meta_GetStatus(p_i->p_meta);
187 status |= ITEM_ART_NOTFOUND;
189 status &= ~ITEM_ART_NOTFOUND;
191 vlc_meta_SetStatus(p_i->p_meta, status);
193 vlc_mutex_unlock( &p_i->lock );
196 void input_item_SetArtFetched( input_item_t *p_i, bool b_art_fetched )
198 vlc_mutex_lock( &p_i->lock );
201 p_i->p_meta = vlc_meta_New();
203 int status = vlc_meta_GetStatus(p_i->p_meta);
206 status |= ITEM_ART_FETCHED;
208 status &= ~ITEM_ART_FETCHED;
210 vlc_meta_SetStatus(p_i->p_meta, status);
212 vlc_mutex_unlock( &p_i->lock );
215 void input_item_SetMeta( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz_val )
219 vlc_mutex_lock( &p_i->lock );
221 p_i->p_meta = vlc_meta_New();
222 vlc_meta_Set( p_i->p_meta, meta_type, psz_val );
223 vlc_mutex_unlock( &p_i->lock );
225 /* Notify interested third parties */
226 event.type = vlc_InputItemMetaChanged;
227 event.u.input_item_meta_changed.meta_type = meta_type;
228 vlc_event_send( &p_i->event_manager, &event );
231 /* FIXME GRRRRRRRRRR args should be in the reverse order to be
232 * consistant with (nearly?) all or copy funcs */
233 void input_item_CopyOptions( input_item_t *p_parent,
234 input_item_t *p_child )
236 vlc_mutex_lock( &p_parent->lock );
238 for( int i = 0 ; i< p_parent->i_options; i++ )
240 if( !strcmp( p_parent->ppsz_options[i], "meta-file" ) )
243 input_item_AddOption( p_child,
244 p_parent->ppsz_options[i],
245 p_parent->optflagv[i] );
248 vlc_mutex_unlock( &p_parent->lock );
251 /* This won't hold the item, but can tell to interested third parties
252 * Like the playlist, that there is a new sub item. With this design
253 * It is not the input item's responsability to keep all the ref of
254 * the input item children. */
255 void input_item_AddSubItem( input_item_t *p_parent, input_item_t *p_child )
257 vlc_mutex_lock( &p_parent->lock );
259 p_parent->i_type = ITEM_TYPE_PLAYLIST;
261 vlc_mutex_unlock( &p_parent->lock );
263 /* Notify interested third parties */
266 event.type = vlc_InputItemSubItemAdded;
267 event.u.input_item_subitem_added.p_new_child = p_child;
268 vlc_event_send( &p_parent->event_manager, &event );
271 bool input_item_HasErrorWhenReading( input_item_t *p_item )
273 vlc_mutex_lock( &p_item->lock );
275 bool b_error = p_item->b_error_when_reading;
277 vlc_mutex_unlock( &p_item->lock );
282 bool input_item_MetaMatch( input_item_t *p_i,
283 vlc_meta_type_t meta_type, const char *psz )
285 vlc_mutex_lock( &p_i->lock );
289 vlc_mutex_unlock( &p_i->lock );
292 const char *psz_meta = vlc_meta_Get( p_i->p_meta, meta_type );
293 bool b_ret = psz_meta && strcasestr( psz_meta, psz );
295 vlc_mutex_unlock( &p_i->lock );
300 char *input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
302 vlc_mutex_lock( &p_i->lock );
306 vlc_mutex_unlock( &p_i->lock );
311 if( vlc_meta_Get( p_i->p_meta, meta_type ) )
312 psz = strdup( vlc_meta_Get( p_i->p_meta, meta_type ) );
314 vlc_mutex_unlock( &p_i->lock );
318 /* Get the title of a given item or fallback to the name if the title is empty */
319 char *input_item_GetTitleFbName( input_item_t *p_item )
322 vlc_mutex_lock( &p_item->lock );
324 if( !p_item->p_meta )
326 psz_ret = p_item->psz_name ? strdup( p_item->psz_name ) : NULL;
327 vlc_mutex_unlock( &p_item->lock );
331 const char *psz_title = vlc_meta_Get( p_item->p_meta, vlc_meta_Title );
332 if( !EMPTY_STR( psz_title ) )
333 psz_ret = strdup( psz_title );
335 psz_ret = p_item->psz_name ? strdup( p_item->psz_name ) : NULL;
337 vlc_mutex_unlock( &p_item->lock );
341 char *input_item_GetName( input_item_t *p_item )
343 vlc_mutex_lock( &p_item->lock );
345 char *psz_name = p_item->psz_name ? strdup( p_item->psz_name ) : NULL;
347 vlc_mutex_unlock( &p_item->lock );
350 void input_item_SetName( input_item_t *p_item, const char *psz_name )
352 vlc_mutex_lock( &p_item->lock );
354 free( p_item->psz_name );
355 p_item->psz_name = strdup( psz_name );
357 vlc_mutex_unlock( &p_item->lock );
360 char *input_item_GetURI( input_item_t *p_i )
362 vlc_mutex_lock( &p_i->lock );
364 char *psz_s = p_i->psz_uri ? strdup( p_i->psz_uri ) : NULL;
366 vlc_mutex_unlock( &p_i->lock );
369 void input_item_SetURI( input_item_t *p_i, const char *psz_uri )
371 vlc_mutex_lock( &p_i->lock );
373 if( !strstr( psz_uri, "://" ) || strstr( psz_uri, " " ) || strstr( psz_uri, "\"" ) )
374 fprintf( stderr, "input_item_SetURI() was likely called with a path. FIXME\n" );
377 free( p_i->psz_uri );
378 p_i->psz_uri = strdup( psz_uri );
380 p_i->i_type = GuessType( p_i );
385 if( p_i->i_type == ITEM_TYPE_FILE || p_i->i_type == ITEM_TYPE_DIRECTORY )
387 const char *psz_filename = strrchr( p_i->psz_uri, '/' );
389 if( psz_filename && *psz_filename == '/' )
391 if( psz_filename && *psz_filename )
392 p_i->psz_name = strdup( psz_filename );
394 /* Make the name more readable */
396 decode_URI( p_i->psz_name );
399 { /* Strip login and password from title */
403 vlc_UrlParse( &url, psz_uri, 0 );
404 if( url.psz_protocol )
407 r=asprintf( &p_i->psz_name, "%s://%s:%d%s", url.psz_protocol,
408 url.psz_host, url.i_port,
409 url.psz_path ? url.psz_path : "" );
411 r=asprintf( &p_i->psz_name, "%s://%s%s", url.psz_protocol,
412 url.psz_host ? url.psz_host : "",
413 url.psz_path ? url.psz_path : "" );
418 r=asprintf( &p_i->psz_name, "%s:%d%s", url.psz_host, url.i_port,
419 url.psz_path ? url.psz_path : "" );
421 r=asprintf( &p_i->psz_name, "%s%s", url.psz_host,
422 url.psz_path ? url.psz_path : "" );
424 vlc_UrlClean( &url );
426 p_i->psz_name=NULL; /* recover from undefined value */
429 vlc_mutex_unlock( &p_i->lock );
432 mtime_t input_item_GetDuration( input_item_t *p_i )
434 vlc_mutex_lock( &p_i->lock );
436 mtime_t i_duration = p_i->i_duration;
438 vlc_mutex_unlock( &p_i->lock );
442 void input_item_SetDuration( input_item_t *p_i, mtime_t i_duration )
444 bool b_send_event = false;
446 vlc_mutex_lock( &p_i->lock );
447 if( p_i->i_duration != i_duration )
449 p_i->i_duration = i_duration;
452 vlc_mutex_unlock( &p_i->lock );
458 event.type = vlc_InputItemDurationChanged;
459 event.u.input_item_duration_changed.new_duration = i_duration;
460 vlc_event_send( &p_i->event_manager, &event );
465 bool input_item_IsPreparsed( input_item_t *p_item )
467 vlc_mutex_lock( &p_item->lock );
468 bool b_preparsed = p_item->p_meta ? ( vlc_meta_GetStatus(p_item->p_meta) & ITEM_PREPARSED ) != 0 : false;
469 vlc_mutex_unlock( &p_item->lock );
474 bool input_item_IsArtFetched( input_item_t *p_item )
476 vlc_mutex_lock( &p_item->lock );
477 bool b_fetched = p_item->p_meta ? ( vlc_meta_GetStatus(p_item->p_meta) & ITEM_ART_FETCHED ) != 0 : false;
478 vlc_mutex_unlock( &p_item->lock );
483 static void input_item_Destroy ( gc_object_t *p_gc )
485 input_item_t *p_item = vlc_priv( p_gc, input_item_t );
487 input_item_Clean( p_item );
491 int input_item_AddOption( input_item_t *p_input, const char *psz_option,
494 int err = VLC_SUCCESS;
496 if( psz_option == NULL )
499 vlc_mutex_lock( &p_input->lock );
500 if (flags & VLC_INPUT_OPTION_UNIQUE)
502 for (int i = 0 ; i < p_input->i_options; i++)
503 if( !strcmp( p_input->ppsz_options[i], psz_option ) )
507 uint8_t *flagv = realloc (p_input->optflagv, p_input->optflagc + 1);
513 p_input->optflagv = flagv;
514 flagv[p_input->optflagc++] = flags;
516 INSERT_ELEM( p_input->ppsz_options, p_input->i_options,
517 p_input->i_options, strdup( psz_option ) );
519 vlc_mutex_unlock( &p_input->lock );
524 * Get a info item from a given category in a given input item.
526 * \param p_i The input item to get info from
527 * \param psz_cat String representing the category for the info
528 * \param psz_name String representing the name of the desired info
529 * \return A pointer to the string with the given info if found, or an
530 * empty string otherwise. The caller should free the returned
533 char *input_item_GetInfo( input_item_t *p_i,
535 const char *psz_name )
537 vlc_mutex_lock( &p_i->lock );
539 for( int i = 0; i< p_i->i_categories; i++ )
541 const info_category_t *p_cat = p_i->pp_categories[i];
543 if( !psz_cat || strcmp( p_cat->psz_name, psz_cat ) )
546 for( int j = 0; j < p_cat->i_infos; j++ )
548 if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
550 char *psz_ret = strdup( p_cat->pp_infos[j]->psz_value );
551 vlc_mutex_unlock( &p_i->lock );
556 vlc_mutex_unlock( &p_i->lock );
560 static int InputItemVaAddInfo( input_item_t *p_i,
562 const char *psz_name,
563 const char *psz_format, va_list args )
566 info_t *p_info = NULL;
567 info_category_t *p_cat = NULL ;
569 vlc_assert_locked( &p_i->lock );
571 for( i = 0 ; i < p_i->i_categories ; i ++ )
573 if( !strcmp( p_i->pp_categories[i]->psz_name, psz_cat ) )
575 p_cat = p_i->pp_categories[i];
581 if( !(p_cat = malloc( sizeof(*p_cat) )) )
584 p_cat->psz_name = strdup( psz_cat );
587 INSERT_ELEM( p_i->pp_categories, p_i->i_categories, p_i->i_categories,
591 for( i = 0; i< p_cat->i_infos; i++ )
593 if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
595 p_info = p_cat->pp_infos[i];
602 if( ( p_info = malloc( sizeof( *p_info ) ) ) == NULL )
605 INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
606 p_info->psz_name = strdup( psz_name );
610 free( p_info->psz_value );
613 if( vasprintf( &p_info->psz_value, psz_format, args ) == -1 )
614 p_info->psz_value = NULL;
616 return p_info->psz_value ? VLC_SUCCESS : VLC_ENOMEM;
619 static int InputItemAddInfo( input_item_t *p_i,
621 const char *psz_name,
622 const char *psz_format, ... )
626 va_start( args, psz_format );
627 const int i_ret = InputItemVaAddInfo( p_i, psz_cat, psz_name, psz_format, args );
633 int input_item_AddInfo( input_item_t *p_i,
635 const char *psz_name,
636 const char *psz_format, ... )
640 vlc_mutex_lock( &p_i->lock );
642 va_start( args, psz_format );
643 const int i_ret = InputItemVaAddInfo( p_i, psz_cat, psz_name, psz_format, args );
646 vlc_mutex_unlock( &p_i->lock );
653 event.type = vlc_InputItemInfoChanged;
654 vlc_event_send( &p_i->event_manager, &event );
659 int input_item_DelInfo( input_item_t *p_i,
661 const char *psz_name )
663 info_category_t *p_cat = NULL;
667 vlc_mutex_lock( &p_i->lock );
668 for( i_cat = 0; i_cat < p_i->i_categories; i_cat++ )
670 if( !strcmp( p_i->pp_categories[i_cat]->psz_name,
673 p_cat = p_i->pp_categories[i_cat];
679 vlc_mutex_unlock( &p_i->lock );
685 /* Remove a specific info */
686 for( i = 0; i < p_cat->i_infos; i++ )
688 if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
690 free( p_cat->pp_infos[i]->psz_name );
691 free( p_cat->pp_infos[i]->psz_value );
692 free( p_cat->pp_infos[i] );
693 REMOVE_ELEM( p_cat->pp_infos, p_cat->i_infos, i );
697 if( i >= p_cat->i_infos )
699 vlc_mutex_unlock( &p_i->lock );
705 /* Remove the complete categorie */
706 for( i = 0; i < p_cat->i_infos; i++ )
708 free( p_cat->pp_infos[i]->psz_name );
709 free( p_cat->pp_infos[i]->psz_value );
710 free( p_cat->pp_infos[i] );
712 free( p_cat->pp_infos );
713 REMOVE_ELEM( p_i->pp_categories, p_i->i_categories, i_cat );
717 free( p_cat->psz_name );
719 vlc_mutex_unlock( &p_i->lock );
723 event.type = vlc_InputItemInfoChanged;
724 vlc_event_send( &p_i->event_manager, &event );
730 void input_item_SetEpg( input_item_t *p_item, const vlc_epg_t *p_update )
732 vlc_mutex_lock( &p_item->lock );
735 vlc_epg_t *p_epg = NULL;
736 for( int i = 0; i < p_item->i_epg; i++ )
738 vlc_epg_t *p_tmp = p_item->pp_epg[i];
740 if( (p_tmp->psz_name == NULL) != (p_update->psz_name == NULL) )
742 if( p_tmp->psz_name && p_update->psz_name && strcmp(p_tmp->psz_name, p_update->psz_name) )
752 p_epg = vlc_epg_New( p_update->psz_name );
754 TAB_APPEND( p_item->i_epg, p_item->pp_epg, p_epg );
757 vlc_epg_Merge( p_epg, p_update );
759 vlc_mutex_unlock( &p_item->lock );
763 if( asprintf( &psz_epg, "EPG %s", p_epg->psz_name ? p_epg->psz_name : "unknown" ) < 0 )
766 input_item_DelInfo( p_item, psz_epg, NULL );
768 vlc_mutex_lock( &p_item->lock );
769 for( int i = 0; i < p_epg->i_event; i++ )
771 const vlc_epg_event_t *p_evt = p_epg->pp_event[i];
772 time_t t_start = (time_t)p_evt->i_start;
776 localtime_r( &t_start, &tm_start );
778 snprintf( psz_start, sizeof(psz_start), "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
779 1900 + tm_start.tm_year, 1 + tm_start.tm_mon, tm_start.tm_mday,
780 tm_start.tm_hour, tm_start.tm_min, tm_start.tm_sec );
781 if( p_evt->psz_short_description || p_evt->psz_description )
782 InputItemAddInfo( p_item, psz_epg, psz_start, "%s (%2.2d:%2.2d) - %s %s",
784 p_evt->i_duration/60/60, (p_evt->i_duration/60)%60,
785 p_evt->psz_short_description ? p_evt->psz_short_description : "" ,
786 p_evt->psz_description ? p_evt->psz_description : "" );
788 InputItemAddInfo( p_item, psz_epg, psz_start, "%s (%2.2d:%2.2d)",
790 p_evt->i_duration/60/60, (p_evt->i_duration/60)%60 );
792 vlc_mutex_unlock( &p_item->lock );
797 if( p_epg->i_event > 0 )
799 vlc_event_t event = { .type = vlc_InputItemInfoChanged, };
800 vlc_event_send( &p_item->event_manager, &event );
804 void input_item_SetEpgOffline( input_item_t *p_item )
806 vlc_mutex_lock( &p_item->lock );
807 for( int i = 0; i < p_item->i_epg; i++ )
808 vlc_epg_SetCurrent( p_item->pp_epg[i], -1 );
809 vlc_mutex_unlock( &p_item->lock );
812 vlc_mutex_lock( &p_item->lock );
813 const int i_epg_info = p_item->i_epg;
814 char *ppsz_epg_info[i_epg_info];
815 for( int i = 0; i < p_item->i_epg; i++ )
817 const vlc_epg_t *p_epg = p_item->pp_epg[i];
818 if( asprintf( &ppsz_epg_info[i], "EPG %s", p_epg->psz_name ? p_epg->psz_name : "unknown" ) < 0 )
819 ppsz_epg_info[i] = NULL;
821 vlc_mutex_unlock( &p_item->lock );
823 for( int i = 0; i < i_epg_info; i++ )
825 if( !ppsz_epg_info[i] )
827 input_item_DelInfo( p_item, ppsz_epg_info[i], NULL );
828 free( ppsz_epg_info[i] );
832 vlc_event_t event = { .type = vlc_InputItemInfoChanged, };
833 vlc_event_send( &p_item->event_manager, &event );
837 input_item_t *__input_item_NewExt( vlc_object_t *p_obj, const char *psz_uri,
838 const char *psz_name,
840 const char *const *ppsz_options,
841 unsigned i_option_flags,
844 return input_item_NewWithType( p_obj, psz_uri, psz_name,
845 i_options, ppsz_options, i_option_flags,
846 i_duration, ITEM_TYPE_UNKNOWN );
850 input_item_t *input_item_NewWithType( vlc_object_t *p_obj, const char *psz_uri,
851 const char *psz_name,
853 const char *const *ppsz_options,
854 unsigned i_option_flags,
858 libvlc_priv_t *priv = libvlc_priv (p_obj->p_libvlc);
859 static vlc_mutex_t input_id_lock = VLC_STATIC_MUTEX;
861 input_item_t* p_input = malloc( sizeof(input_item_t ) );
865 input_item_Init( p_obj, p_input );
866 vlc_gc_init( p_input, input_item_Destroy );
868 vlc_mutex_lock( &input_id_lock );
869 p_input->i_id = ++priv->i_last_input_id;
870 vlc_mutex_unlock( &input_id_lock );
872 p_input->b_fixed_name = false;
874 p_input->i_type = i_type;
875 p_input->b_prefers_tree = false;
878 input_item_SetURI( p_input, psz_uri );
880 if( i_type != ITEM_TYPE_UNKNOWN )
881 p_input->i_type = i_type;
884 input_item_SetName( p_input, psz_name );
886 p_input->i_duration = i_duration;
888 for( int i = 0; i < i_options; i++ )
889 input_item_AddOption( p_input, ppsz_options[i], i_option_flags );
893 struct item_type_entry
895 const char psz_scheme[7];
899 static int typecmp( const void *key, const void *entry )
901 const struct item_type_entry *type = entry;
902 const char *uri = key, *scheme = type->psz_scheme;
904 return strncmp( uri, scheme, strlen( scheme ) );
907 /* Guess the type of the item using the beginning of the mrl */
908 static int GuessType( const input_item_t *p_item )
910 static const struct item_type_entry tab[] =
911 { /* /!\ Alphabetical order /!\ */
912 /* Short match work, not just exact match */
913 { "alsa", ITEM_TYPE_CARD },
914 { "atsc", ITEM_TYPE_CARD },
915 { "bd", ITEM_TYPE_DISC },
916 { "cable", ITEM_TYPE_CARD },
917 { "cdda", ITEM_TYPE_CDDA },
918 { "dc1394", ITEM_TYPE_CARD },
919 { "dccp", ITEM_TYPE_NET },
920 { "dir", ITEM_TYPE_DIRECTORY },
921 { "dshow", ITEM_TYPE_CARD },
922 { "dv", ITEM_TYPE_CARD },
923 { "dvb", ITEM_TYPE_CARD },
924 { "dvd", ITEM_TYPE_DISC },
925 { "ftp", ITEM_TYPE_NET },
926 { "http", ITEM_TYPE_NET },
927 { "icyx", ITEM_TYPE_NET },
928 { "itpc", ITEM_TYPE_NET },
929 { "jack", ITEM_TYPE_CARD },
930 { "live", ITEM_TYPE_NET }, /* livedotcom */
931 { "mms", ITEM_TYPE_NET },
932 { "mtp", ITEM_TYPE_DISC },
933 { "ofdm", ITEM_TYPE_CARD },
934 { "oss", ITEM_TYPE_CARD },
935 { "pnm", ITEM_TYPE_NET },
936 { "pvr", ITEM_TYPE_CARD },
937 { "qam", ITEM_TYPE_CARD },
938 { "qpsk", ITEM_TYPE_CARD },
939 { "qtcapt", ITEM_TYPE_CARD }, /* qtcapture */
940 { "raw139", ITEM_TYPE_CARD }, /* raw1394 */
941 { "rt", ITEM_TYPE_NET }, /* rtp, rtsp, rtmp */
942 { "satell", ITEM_TYPE_CARD }, /* sattelite */
943 { "screen", ITEM_TYPE_CARD },
944 { "sdp", ITEM_TYPE_NET },
945 { "smb", ITEM_TYPE_NET },
946 { "svcd", ITEM_TYPE_DISC },
947 { "tcp", ITEM_TYPE_NET },
948 { "terres", ITEM_TYPE_CARD }, /* terrestrial */
949 { "udp", ITEM_TYPE_NET }, /* udplite too */
950 { "unsv", ITEM_TYPE_NET },
951 { "usdigi", ITEM_TYPE_CARD }, /* usdigital */
952 { "v4l", ITEM_TYPE_CARD },
953 { "vcd", ITEM_TYPE_DISC },
954 { "window", ITEM_TYPE_CARD },
956 const struct item_type_entry *e;
958 if( !strstr( p_item->psz_uri, "://" ) )
959 return ITEM_TYPE_FILE;
961 e = bsearch( p_item->psz_uri, tab, sizeof( tab ) / sizeof( tab[0] ),
962 sizeof( tab[0] ), typecmp );
963 return e ? e->i_type : ITEM_TYPE_FILE;