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();
156 i_new_status = p_i->p_meta->i_status | ITEM_PREPARSED;
158 i_new_status = p_i->p_meta->i_status & ~ITEM_PREPARSED;
159 if( p_i->p_meta->i_status != i_new_status )
161 p_i->p_meta->i_status = i_new_status;
165 vlc_mutex_unlock( &p_i->lock );
170 event.type = vlc_InputItemPreparsedChanged;
171 event.u.input_item_preparsed_changed.new_status = i_new_status;
172 vlc_event_send( &p_i->event_manager, &event );
175 void input_item_SetArtNotFound( input_item_t *p_i, bool b_not_found )
177 vlc_mutex_lock( &p_i->lock );
180 p_i->p_meta = vlc_meta_New();
183 p_i->p_meta->i_status |= ITEM_ART_NOTFOUND;
185 p_i->p_meta->i_status &= ~ITEM_ART_NOTFOUND;
187 vlc_mutex_unlock( &p_i->lock );
189 void input_item_SetArtFetched( input_item_t *p_i, bool b_art_fetched )
191 vlc_mutex_lock( &p_i->lock );
194 p_i->p_meta = vlc_meta_New();
197 p_i->p_meta->i_status |= ITEM_ART_FETCHED;
199 p_i->p_meta->i_status &= ~ITEM_ART_FETCHED;
201 vlc_mutex_unlock( &p_i->lock );
204 void input_item_SetMeta( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz_val )
208 vlc_mutex_lock( &p_i->lock );
210 p_i->p_meta = vlc_meta_New();
211 vlc_meta_Set( p_i->p_meta, meta_type, psz_val );
212 vlc_mutex_unlock( &p_i->lock );
214 /* Notify interested third parties */
215 event.type = vlc_InputItemMetaChanged;
216 event.u.input_item_meta_changed.meta_type = meta_type;
217 vlc_event_send( &p_i->event_manager, &event );
220 /* FIXME GRRRRRRRRRR args should be in the reverse order to be
221 * consistant with (nearly?) all or copy funcs */
222 void input_item_CopyOptions( input_item_t *p_parent,
223 input_item_t *p_child )
225 vlc_mutex_lock( &p_parent->lock );
227 for( int i = 0 ; i< p_parent->i_options; i++ )
229 if( !strcmp( p_parent->ppsz_options[i], "meta-file" ) )
232 input_item_AddOption( p_child,
233 p_parent->ppsz_options[i],
234 p_parent->optflagv[i] );
237 vlc_mutex_unlock( &p_parent->lock );
240 /* This won't hold the item, but can tell to interested third parties
241 * Like the playlist, that there is a new sub item. With this design
242 * It is not the input item's responsability to keep all the ref of
243 * the input item children. */
244 void input_item_AddSubItem( input_item_t *p_parent, input_item_t *p_child )
246 vlc_mutex_lock( &p_parent->lock );
248 p_parent->i_type = ITEM_TYPE_PLAYLIST;
250 vlc_mutex_unlock( &p_parent->lock );
252 /* Notify interested third parties */
255 event.type = vlc_InputItemSubItemAdded;
256 event.u.input_item_subitem_added.p_new_child = p_child;
257 vlc_event_send( &p_parent->event_manager, &event );
260 bool input_item_HasErrorWhenReading( input_item_t *p_item )
262 vlc_mutex_lock( &p_item->lock );
264 bool b_error = p_item->b_error_when_reading;
266 vlc_mutex_unlock( &p_item->lock );
271 bool input_item_MetaMatch( input_item_t *p_i,
272 vlc_meta_type_t meta_type, const char *psz )
274 vlc_mutex_lock( &p_i->lock );
278 vlc_mutex_unlock( &p_i->lock );
281 const char *psz_meta = vlc_meta_Get( p_i->p_meta, meta_type );
282 bool b_ret = psz_meta && strcasestr( psz_meta, psz );
284 vlc_mutex_unlock( &p_i->lock );
289 char *input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
291 vlc_mutex_lock( &p_i->lock );
295 vlc_mutex_unlock( &p_i->lock );
300 if( vlc_meta_Get( p_i->p_meta, meta_type ) )
301 psz = strdup( vlc_meta_Get( p_i->p_meta, meta_type ) );
303 vlc_mutex_unlock( &p_i->lock );
307 /* Get the title of a given item or fallback to the name if the title is empty */
308 char *input_item_GetTitleFbName( input_item_t *p_item )
311 vlc_mutex_lock( &p_item->lock );
313 if( !p_item->p_meta )
315 psz_ret = p_item->psz_name ? strdup( p_item->psz_name ) : NULL;
316 vlc_mutex_unlock( &p_item->lock );
320 const char *psz_title = vlc_meta_Get( p_item->p_meta, vlc_meta_Title );
321 if( !EMPTY_STR( psz_title ) )
322 psz_ret = strdup( psz_title );
324 psz_ret = p_item->psz_name ? strdup( p_item->psz_name ) : NULL;
326 vlc_mutex_unlock( &p_item->lock );
330 char *input_item_GetName( input_item_t *p_item )
332 vlc_mutex_lock( &p_item->lock );
334 char *psz_name = p_item->psz_name ? strdup( p_item->psz_name ) : NULL;
336 vlc_mutex_unlock( &p_item->lock );
339 void input_item_SetName( input_item_t *p_item, const char *psz_name )
341 vlc_mutex_lock( &p_item->lock );
343 free( p_item->psz_name );
344 p_item->psz_name = strdup( psz_name );
346 vlc_mutex_unlock( &p_item->lock );
349 char *input_item_GetURI( input_item_t *p_i )
351 vlc_mutex_lock( &p_i->lock );
353 char *psz_s = p_i->psz_uri ? strdup( p_i->psz_uri ) : NULL;
355 vlc_mutex_unlock( &p_i->lock );
358 void input_item_SetURI( input_item_t *p_i, const char *psz_uri )
360 vlc_mutex_lock( &p_i->lock );
362 if( !strstr( psz_uri, "://" ) || strstr( psz_uri, " " ) || strstr( psz_uri, "\"" ) )
363 fprintf( stderr, "input_item_SetURI() was likely called with a path. FIXME\n" );
366 free( p_i->psz_uri );
367 p_i->psz_uri = strdup( psz_uri );
369 p_i->i_type = GuessType( p_i );
374 if( p_i->i_type == ITEM_TYPE_FILE || p_i->i_type == ITEM_TYPE_DIRECTORY )
376 const char *psz_filename = strrchr( p_i->psz_uri, '/' );
378 if( psz_filename && *psz_filename == '/' )
380 if( psz_filename && *psz_filename )
381 p_i->psz_name = strdup( psz_filename );
383 /* Make the name more readable */
385 decode_URI( p_i->psz_name );
388 { /* Strip login and password from title */
392 vlc_UrlParse( &url, psz_uri, 0 );
393 if( url.psz_protocol )
396 r=asprintf( &p_i->psz_name, "%s://%s:%d%s", url.psz_protocol,
397 url.psz_host, url.i_port,
398 url.psz_path ? url.psz_path : "" );
400 r=asprintf( &p_i->psz_name, "%s://%s%s", url.psz_protocol,
401 url.psz_host ? url.psz_host : "",
402 url.psz_path ? url.psz_path : "" );
407 r=asprintf( &p_i->psz_name, "%s:%d%s", url.psz_host, url.i_port,
408 url.psz_path ? url.psz_path : "" );
410 r=asprintf( &p_i->psz_name, "%s%s", url.psz_host,
411 url.psz_path ? url.psz_path : "" );
413 vlc_UrlClean( &url );
415 p_i->psz_name=NULL; /* recover from undefined value */
418 vlc_mutex_unlock( &p_i->lock );
421 mtime_t input_item_GetDuration( input_item_t *p_i )
423 vlc_mutex_lock( &p_i->lock );
425 mtime_t i_duration = p_i->i_duration;
427 vlc_mutex_unlock( &p_i->lock );
431 void input_item_SetDuration( input_item_t *p_i, mtime_t i_duration )
433 bool b_send_event = false;
435 vlc_mutex_lock( &p_i->lock );
436 if( p_i->i_duration != i_duration )
438 p_i->i_duration = i_duration;
441 vlc_mutex_unlock( &p_i->lock );
447 event.type = vlc_InputItemDurationChanged;
448 event.u.input_item_duration_changed.new_duration = i_duration;
449 vlc_event_send( &p_i->event_manager, &event );
454 bool input_item_IsPreparsed( input_item_t *p_item )
456 vlc_mutex_lock( &p_item->lock );
457 bool b_preparsed = p_item->p_meta ? ( p_item->p_meta->i_status & ITEM_PREPARSED ) != 0 : false;
458 vlc_mutex_unlock( &p_item->lock );
463 bool input_item_IsArtFetched( input_item_t *p_item )
465 vlc_mutex_lock( &p_item->lock );
466 bool b_fetched = p_item->p_meta ? ( p_item->p_meta->i_status & ITEM_ART_FETCHED ) != 0 : false;
467 vlc_mutex_unlock( &p_item->lock );
472 static void input_item_Destroy ( gc_object_t *p_gc )
474 input_item_t *p_item = vlc_priv( p_gc, input_item_t );
476 input_item_Clean( p_item );
480 int input_item_AddOption( input_item_t *p_input, const char *psz_option,
483 int err = VLC_SUCCESS;
485 if( psz_option == NULL )
488 vlc_mutex_lock( &p_input->lock );
489 if (flags & VLC_INPUT_OPTION_UNIQUE)
491 for (int i = 0 ; i < p_input->i_options; i++)
492 if( !strcmp( p_input->ppsz_options[i], psz_option ) )
496 uint8_t *flagv = realloc (p_input->optflagv, p_input->optflagc + 1);
502 p_input->optflagv = flagv;
503 flagv[p_input->optflagc++] = flags;
505 INSERT_ELEM( p_input->ppsz_options, p_input->i_options,
506 p_input->i_options, strdup( psz_option ) );
508 vlc_mutex_unlock( &p_input->lock );
513 * Get a info item from a given category in a given input item.
515 * \param p_i The input item to get info from
516 * \param psz_cat String representing the category for the info
517 * \param psz_name String representing the name of the desired info
518 * \return A pointer to the string with the given info if found, or an
519 * empty string otherwise. The caller should free the returned
522 char *input_item_GetInfo( input_item_t *p_i,
524 const char *psz_name )
526 vlc_mutex_lock( &p_i->lock );
528 for( int i = 0; i< p_i->i_categories; i++ )
530 const info_category_t *p_cat = p_i->pp_categories[i];
532 if( !psz_cat || strcmp( p_cat->psz_name, psz_cat ) )
535 for( int j = 0; j < p_cat->i_infos; j++ )
537 if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
539 char *psz_ret = strdup( p_cat->pp_infos[j]->psz_value );
540 vlc_mutex_unlock( &p_i->lock );
545 vlc_mutex_unlock( &p_i->lock );
549 static int InputItemVaAddInfo( input_item_t *p_i,
551 const char *psz_name,
552 const char *psz_format, va_list args )
555 info_t *p_info = NULL;
556 info_category_t *p_cat = NULL ;
558 vlc_assert_locked( &p_i->lock );
560 for( i = 0 ; i < p_i->i_categories ; i ++ )
562 if( !strcmp( p_i->pp_categories[i]->psz_name, psz_cat ) )
564 p_cat = p_i->pp_categories[i];
570 if( !(p_cat = malloc( sizeof(*p_cat) )) )
573 p_cat->psz_name = strdup( psz_cat );
576 INSERT_ELEM( p_i->pp_categories, p_i->i_categories, p_i->i_categories,
580 for( i = 0; i< p_cat->i_infos; i++ )
582 if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
584 p_info = p_cat->pp_infos[i];
591 if( ( p_info = malloc( sizeof( *p_info ) ) ) == NULL )
594 INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
595 p_info->psz_name = strdup( psz_name );
599 free( p_info->psz_value );
602 if( vasprintf( &p_info->psz_value, psz_format, args ) == -1 )
603 p_info->psz_value = NULL;
605 return p_info->psz_value ? VLC_SUCCESS : VLC_ENOMEM;
608 static int InputItemAddInfo( input_item_t *p_i,
610 const char *psz_name,
611 const char *psz_format, ... )
615 va_start( args, psz_format );
616 const int i_ret = InputItemVaAddInfo( p_i, psz_cat, psz_name, psz_format, args );
622 int input_item_AddInfo( input_item_t *p_i,
624 const char *psz_name,
625 const char *psz_format, ... )
629 vlc_mutex_lock( &p_i->lock );
631 va_start( args, psz_format );
632 const int i_ret = InputItemVaAddInfo( p_i, psz_cat, psz_name, psz_format, args );
635 vlc_mutex_unlock( &p_i->lock );
642 event.type = vlc_InputItemInfoChanged;
643 vlc_event_send( &p_i->event_manager, &event );
648 int input_item_DelInfo( input_item_t *p_i,
650 const char *psz_name )
652 info_category_t *p_cat = NULL;
656 vlc_mutex_lock( &p_i->lock );
657 for( i_cat = 0; i_cat < p_i->i_categories; i_cat++ )
659 if( !strcmp( p_i->pp_categories[i_cat]->psz_name,
662 p_cat = p_i->pp_categories[i_cat];
668 vlc_mutex_unlock( &p_i->lock );
674 /* Remove a specific info */
675 for( i = 0; i < p_cat->i_infos; i++ )
677 if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
679 free( p_cat->pp_infos[i]->psz_name );
680 free( p_cat->pp_infos[i]->psz_value );
681 free( p_cat->pp_infos[i] );
682 REMOVE_ELEM( p_cat->pp_infos, p_cat->i_infos, i );
686 if( i >= p_cat->i_infos )
688 vlc_mutex_unlock( &p_i->lock );
694 /* Remove the complete categorie */
695 for( i = 0; i < p_cat->i_infos; i++ )
697 free( p_cat->pp_infos[i]->psz_name );
698 free( p_cat->pp_infos[i]->psz_value );
699 free( p_cat->pp_infos[i] );
701 free( p_cat->pp_infos );
702 REMOVE_ELEM( p_i->pp_categories, p_i->i_categories, i_cat );
706 free( p_cat->psz_name );
708 vlc_mutex_unlock( &p_i->lock );
712 event.type = vlc_InputItemInfoChanged;
713 vlc_event_send( &p_i->event_manager, &event );
719 void input_item_SetEpg( input_item_t *p_item, const vlc_epg_t *p_update )
721 vlc_mutex_lock( &p_item->lock );
724 vlc_epg_t *p_epg = NULL;
725 for( int i = 0; i < p_item->i_epg; i++ )
727 vlc_epg_t *p_tmp = p_item->pp_epg[i];
729 if( (p_tmp->psz_name == NULL) != (p_update->psz_name == NULL) )
731 if( p_tmp->psz_name && p_update->psz_name && strcmp(p_tmp->psz_name, p_update->psz_name) )
741 p_epg = vlc_epg_New( p_update->psz_name );
743 TAB_APPEND( p_item->i_epg, p_item->pp_epg, p_epg );
746 vlc_epg_Merge( p_epg, p_update );
748 vlc_mutex_unlock( &p_item->lock );
752 if( asprintf( &psz_epg, "EPG %s", p_epg->psz_name ? p_epg->psz_name : "unknown" ) < 0 )
755 input_item_DelInfo( p_item, psz_epg, NULL );
757 vlc_mutex_lock( &p_item->lock );
758 for( int i = 0; i < p_epg->i_event; i++ )
760 const vlc_epg_event_t *p_evt = p_epg->pp_event[i];
761 time_t t_start = (time_t)p_evt->i_start;
765 localtime_r( &t_start, &tm_start );
767 snprintf( psz_start, sizeof(psz_start), "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
768 1900 + tm_start.tm_year, 1 + tm_start.tm_mon, tm_start.tm_mday,
769 tm_start.tm_hour, tm_start.tm_min, tm_start.tm_sec );
770 if( p_evt->psz_short_description || p_evt->psz_description )
771 InputItemAddInfo( p_item, psz_epg, psz_start, "%s (%2.2d:%2.2d) - %s %s",
773 p_evt->i_duration/60/60, (p_evt->i_duration/60)%60,
774 p_evt->psz_short_description ? p_evt->psz_short_description : "" ,
775 p_evt->psz_description ? p_evt->psz_description : "" );
777 InputItemAddInfo( p_item, psz_epg, psz_start, "%s (%2.2d:%2.2d)",
779 p_evt->i_duration/60/60, (p_evt->i_duration/60)%60 );
781 vlc_mutex_unlock( &p_item->lock );
786 if( p_epg->i_event > 0 )
788 vlc_event_t event = { .type = vlc_InputItemInfoChanged, };
789 vlc_event_send( &p_item->event_manager, &event );
793 void input_item_SetEpgOffline( input_item_t *p_item )
795 vlc_mutex_lock( &p_item->lock );
796 for( int i = 0; i < p_item->i_epg; i++ )
797 vlc_epg_SetCurrent( p_item->pp_epg[i], -1 );
798 vlc_mutex_unlock( &p_item->lock );
801 vlc_mutex_lock( &p_item->lock );
802 const int i_epg_info = p_item->i_epg;
803 char *ppsz_epg_info[i_epg_info];
804 for( int i = 0; i < p_item->i_epg; i++ )
806 const vlc_epg_t *p_epg = p_item->pp_epg[i];
807 if( asprintf( &ppsz_epg_info[i], "EPG %s", p_epg->psz_name ? p_epg->psz_name : "unknown" ) < 0 )
808 ppsz_epg_info[i] = NULL;
810 vlc_mutex_unlock( &p_item->lock );
812 for( int i = 0; i < i_epg_info; i++ )
814 if( !ppsz_epg_info[i] )
816 input_item_DelInfo( p_item, ppsz_epg_info[i], NULL );
817 free( ppsz_epg_info[i] );
821 vlc_event_t event = { .type = vlc_InputItemInfoChanged, };
822 vlc_event_send( &p_item->event_manager, &event );
826 input_item_t *__input_item_NewExt( vlc_object_t *p_obj, const char *psz_uri,
827 const char *psz_name,
829 const char *const *ppsz_options,
830 unsigned i_option_flags,
833 return input_item_NewWithType( p_obj, psz_uri, psz_name,
834 i_options, ppsz_options, i_option_flags,
835 i_duration, ITEM_TYPE_UNKNOWN );
839 input_item_t *input_item_NewWithType( vlc_object_t *p_obj, const char *psz_uri,
840 const char *psz_name,
842 const char *const *ppsz_options,
843 unsigned i_option_flags,
847 libvlc_priv_t *priv = libvlc_priv (p_obj->p_libvlc);
848 static vlc_mutex_t input_id_lock = VLC_STATIC_MUTEX;
850 input_item_t* p_input = malloc( sizeof(input_item_t ) );
854 input_item_Init( p_obj, p_input );
855 vlc_gc_init( p_input, input_item_Destroy );
857 vlc_mutex_lock( &input_id_lock );
858 p_input->i_id = ++priv->i_last_input_id;
859 vlc_mutex_unlock( &input_id_lock );
861 p_input->b_fixed_name = false;
863 p_input->i_type = i_type;
864 p_input->b_prefers_tree = false;
867 input_item_SetURI( p_input, psz_uri );
869 if( i_type != ITEM_TYPE_UNKNOWN )
870 p_input->i_type = i_type;
873 input_item_SetName( p_input, psz_name );
875 p_input->i_duration = i_duration;
877 for( int i = 0; i < i_options; i++ )
878 input_item_AddOption( p_input, ppsz_options[i], i_option_flags );
882 struct item_type_entry
884 const char psz_scheme[7];
888 static int typecmp( const void *key, const void *entry )
890 const struct item_type_entry *type = entry;
891 const char *uri = key, *scheme = type->psz_scheme;
893 return strncmp( uri, scheme, strlen( scheme ) );
896 /* Guess the type of the item using the beginning of the mrl */
897 static int GuessType( const input_item_t *p_item )
899 static const struct item_type_entry tab[] =
900 { /* /!\ Alphabetical order /!\ */
901 /* Short match work, not just exact match */
902 { "alsa", ITEM_TYPE_CARD },
903 { "atsc", ITEM_TYPE_CARD },
904 { "bd", ITEM_TYPE_DISC },
905 { "cable", ITEM_TYPE_CARD },
906 { "cdda", ITEM_TYPE_CDDA },
907 { "dc1394", ITEM_TYPE_CARD },
908 { "dccp", ITEM_TYPE_NET },
909 { "dir", ITEM_TYPE_DIRECTORY },
910 { "dshow", ITEM_TYPE_CARD },
911 { "dv", ITEM_TYPE_CARD },
912 { "dvb", ITEM_TYPE_CARD },
913 { "dvd", ITEM_TYPE_DISC },
914 { "ftp", ITEM_TYPE_NET },
915 { "http", ITEM_TYPE_NET },
916 { "icyx", ITEM_TYPE_NET },
917 { "itpc", ITEM_TYPE_NET },
918 { "jack", ITEM_TYPE_CARD },
919 { "live", ITEM_TYPE_NET }, /* livedotcom */
920 { "mms", ITEM_TYPE_NET },
921 { "mtp", ITEM_TYPE_DISC },
922 { "ofdm", ITEM_TYPE_CARD },
923 { "oss", ITEM_TYPE_CARD },
924 { "pnm", ITEM_TYPE_NET },
925 { "pvr", ITEM_TYPE_CARD },
926 { "qam", ITEM_TYPE_CARD },
927 { "qpsk", ITEM_TYPE_CARD },
928 { "qtcapt", ITEM_TYPE_CARD }, /* qtcapture */
929 { "raw139", ITEM_TYPE_CARD }, /* raw1394 */
930 { "rt", ITEM_TYPE_NET }, /* rtp, rtsp, rtmp */
931 { "satell", ITEM_TYPE_CARD }, /* sattelite */
932 { "screen", ITEM_TYPE_CARD },
933 { "sdp", ITEM_TYPE_NET },
934 { "smb", ITEM_TYPE_NET },
935 { "svcd", ITEM_TYPE_DISC },
936 { "tcp", ITEM_TYPE_NET },
937 { "terres", ITEM_TYPE_CARD }, /* terrestrial */
938 { "udp", ITEM_TYPE_NET }, /* udplite too */
939 { "unsv", ITEM_TYPE_NET },
940 { "usdigi", ITEM_TYPE_CARD }, /* usdigital */
941 { "v4l", ITEM_TYPE_CARD },
942 { "vcd", ITEM_TYPE_DISC },
943 { "window", ITEM_TYPE_CARD },
945 const struct item_type_entry *e;
947 if( !strstr( p_item->psz_uri, "://" ) )
948 return ITEM_TYPE_FILE;
950 e = bsearch( p_item->psz_uri, tab, sizeof( tab ) / sizeof( tab[0] ),
951 sizeof( tab[0] ), typecmp );
952 return e ? e->i_type : ITEM_TYPE_FILE;