]> git.sesse.net Git - vlc/blob - src/input/item.c
Clean up input_item_t functions and usages.
[vlc] / src / input / item.c
1 /*****************************************************************************
2  * item.c: input_item management
3  *****************************************************************************
4  * Copyright (C) 1998-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27 #include <assert.h>
28
29 #include <vlc_common.h>
30 #include "vlc_playlist.h"
31 #include "vlc_interface.h"
32
33 #include "input_internal.h"
34
35 static void GuessType( input_item_t *p_item );
36
37 /** Stuff moved out of vlc_input.h -- FIXME: should probably not be inline
38  * anyway. */
39 static inline void input_item_Init( vlc_object_t *p_o, input_item_t *p_i )
40 {
41     memset( p_i, 0, sizeof(input_item_t) );
42
43     p_i->psz_name = NULL;
44     p_i->psz_uri = NULL;
45     TAB_INIT( p_i->i_es, p_i->es );
46     TAB_INIT( p_i->i_options, p_i->ppsz_options );
47     p_i->optflagv = NULL, p_i->optflagc = 0;
48     TAB_INIT( p_i->i_categories, p_i->pp_categories );
49
50     p_i->i_type = ITEM_TYPE_UNKNOWN;
51     p_i->b_fixed_name = true;
52
53     p_i->p_stats = NULL;
54     p_i->p_meta = NULL;
55
56     vlc_mutex_init( &p_i->lock );
57     vlc_event_manager_t * p_em = &p_i->event_manager;
58     vlc_event_manager_init( p_em, p_i, p_o );
59     vlc_event_manager_register_event_type( p_em, vlc_InputItemMetaChanged );
60     vlc_event_manager_register_event_type( p_em, vlc_InputItemSubItemAdded );
61     vlc_event_manager_register_event_type( p_em, vlc_InputItemDurationChanged );
62     vlc_event_manager_register_event_type( p_em, vlc_InputItemPreparsedChanged );
63     vlc_event_manager_register_event_type( p_em, vlc_InputItemNameChanged );
64     vlc_event_manager_register_event_type( p_em, vlc_InputItemInfoChanged );
65     vlc_event_manager_register_event_type( p_em, vlc_InputItemErrorWhenReadingChanged );
66 }
67
68 static inline void input_item_Clean( input_item_t *p_i )
69 {
70     int i;
71
72     vlc_event_manager_fini( &p_i->event_manager );
73
74     free( p_i->psz_name );
75     free( p_i->psz_uri );
76     if( p_i->p_stats )
77     {
78         vlc_mutex_destroy( &p_i->p_stats->lock );
79         free( p_i->p_stats );
80     }
81
82     if( p_i->p_meta )
83         vlc_meta_Delete( p_i->p_meta );
84
85     for( i = 0; i < p_i->i_options; i++ )
86         free( p_i->ppsz_options[i] );
87     TAB_CLEAN( p_i->i_options, p_i->ppsz_options );
88     free( p_i->optflagv);
89
90     for( i = 0; i < p_i->i_es; i++ )
91     {
92         es_format_Clean( p_i->es[i] );
93         free( p_i->es[i] );
94     }
95     TAB_CLEAN( p_i->i_es, p_i->es );
96
97     for( i = 0; i < p_i->i_categories; i++ )
98     {
99         info_category_t *p_category = p_i->pp_categories[i];
100         int j;
101
102         for( j = 0; j < p_category->i_infos; j++ )
103         {
104             struct info_t *p_info = p_category->pp_infos[j];
105
106             free( p_info->psz_name);
107             free( p_info->psz_value );
108             free( p_info );
109         }
110         TAB_CLEAN( p_category->i_infos, p_category->pp_infos );
111
112         free( p_category->psz_name );
113         free( p_category );
114     }
115     TAB_CLEAN( p_i->i_categories, p_i->pp_categories );
116
117     vlc_mutex_destroy( &p_i->lock );
118 }
119 void input_item_SetErrorWhenReading( input_item_t *p_i, bool b_error )
120 {
121     bool b_changed;
122
123     vlc_mutex_lock( &p_i->lock );
124
125     b_changed = p_i->b_error_when_reading != b_error;
126     p_i->b_error_when_reading = b_error;
127
128     vlc_mutex_unlock( &p_i->lock );
129
130     if( b_changed )
131     {
132         vlc_event_t event;
133
134         event.type = vlc_InputItemErrorWhenReadingChanged;
135         event.u.input_item_error_when_reading_changed.new_value = b_error;
136         vlc_event_send( &p_i->event_manager, &event );
137     }
138 }
139 void input_item_SetPreparsed( input_item_t *p_i, bool b_preparsed )
140 {
141     bool b_send_event = false;
142
143     vlc_mutex_lock( &p_i->lock );
144
145     if( !p_i->p_meta )
146         p_i->p_meta = vlc_meta_New();
147
148     int i_new_status;
149     if( b_preparsed )
150         i_new_status = p_i->p_meta->i_status | ITEM_PREPARSED;
151     else
152         i_new_status = p_i->p_meta->i_status & ~ITEM_PREPARSED;
153     if( p_i->p_meta->i_status != i_new_status )
154     {
155         p_i->p_meta->i_status = i_new_status;
156         b_send_event = true;
157     }
158
159     vlc_mutex_unlock( &p_i->lock );
160
161     if( b_send_event )
162     {
163         vlc_event_t event;
164         event.type = vlc_InputItemPreparsedChanged;
165         event.u.input_item_preparsed_changed.new_status = i_new_status;
166         vlc_event_send( &p_i->event_manager, &event );
167     }
168 }
169 void input_item_SetArtNotFound( input_item_t *p_i, bool b_not_found )
170 {
171     vlc_mutex_lock( &p_i->lock );
172
173     if( !p_i->p_meta )
174         p_i->p_meta = vlc_meta_New();
175
176     if( b_not_found )
177         p_i->p_meta->i_status |= ITEM_ART_NOTFOUND;
178     else
179         p_i->p_meta->i_status &= ~ITEM_ART_NOTFOUND;
180
181     vlc_mutex_unlock( &p_i->lock );
182 }
183 void input_item_SetArtFetched( input_item_t *p_i, bool b_art_fetched )
184 {
185     vlc_mutex_lock( &p_i->lock );
186
187     if( !p_i->p_meta )
188         p_i->p_meta = vlc_meta_New();
189
190     if( b_art_fetched )
191         p_i->p_meta->i_status |= ITEM_ART_FETCHED;
192     else
193         p_i->p_meta->i_status &= ~ITEM_ART_FETCHED;
194
195     vlc_mutex_unlock( &p_i->lock );
196 }
197
198 void input_item_SetMeta( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz_val )
199 {
200     vlc_event_t event;
201
202     vlc_mutex_lock( &p_i->lock );
203     if( !p_i->p_meta )
204         p_i->p_meta = vlc_meta_New();
205     vlc_meta_Set( p_i->p_meta, meta_type, psz_val );
206     vlc_mutex_unlock( &p_i->lock );
207
208     /* Notify interested third parties */
209     event.type = vlc_InputItemMetaChanged;
210     event.u.input_item_meta_changed.meta_type = meta_type;
211     vlc_event_send( &p_i->event_manager, &event );
212 }
213
214 /**
215  * Get the item from an input thread
216  * FIXME it does not increase ref count of the item.
217  * if it is used after p_input is destroyed nothing prevent it from
218  * being freed.
219  */
220 input_item_t *input_GetItem( input_thread_t *p_input )
221 {
222     assert( p_input && p_input->p );
223     return p_input->p->input.p_item;
224 }
225
226 /* FIXME GRRRRRRRRRR args should be in the reverse order to be 
227  * consistant with (nearly?) all or copy funcs */
228 void input_item_CopyOptions( input_item_t *p_parent,
229                              input_item_t *p_child )
230 {
231     vlc_mutex_lock( &p_parent->lock );
232
233     for( int i = 0 ; i< p_parent->i_options; i++ )
234     {
235         if( !strcmp( p_parent->ppsz_options[i], "meta-file" ) )
236             continue;
237
238         input_item_AddOpt( p_child,
239                            p_parent->ppsz_options[i],
240                            p_parent->optflagv[i] );
241     }
242
243     vlc_mutex_unlock( &p_parent->lock );
244 }
245
246 /* This won't hold the item, but can tell to interested third parties
247  * Like the playlist, that there is a new sub item. With this design
248  * It is not the input item's responsability to keep all the ref of
249  * the input item children. */
250 void input_item_AddSubItem( input_item_t *p_parent, input_item_t *p_child )
251 {
252     vlc_mutex_lock( &p_parent->lock );
253
254     p_parent->i_type = ITEM_TYPE_PLAYLIST;
255
256     vlc_mutex_unlock( &p_parent->lock );
257
258     /* Notify interested third parties */
259     vlc_event_t event;
260
261     event.type = vlc_InputItemSubItemAdded;
262     event.u.input_item_subitem_added.p_new_child = p_child;
263     vlc_event_send( &p_parent->event_manager, &event );
264 }
265
266 int input_item_AddOption( input_item_t *p_item, const char *psz_option )
267 {
268     return input_item_AddOpt( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED );
269 }
270
271 bool input_item_HasErrorWhenReading( input_item_t *p_item )
272 {
273     vlc_mutex_lock( &p_item->lock );
274
275     bool b_error = p_item->b_error_when_reading;
276
277     vlc_mutex_unlock( &p_item->lock );
278
279     return b_error;
280 }
281
282 bool input_item_MetaMatch( input_item_t *p_i,
283                            vlc_meta_type_t meta_type, const char *psz )
284 {
285     vlc_mutex_lock( &p_i->lock );
286
287     if( !p_i->p_meta )
288     {
289         vlc_mutex_unlock( &p_i->lock );
290         return false;
291     }
292     const char *psz_meta = vlc_meta_Get( p_i->p_meta, meta_type );
293     bool b_ret = psz_meta && strcasestr( psz_meta, psz );
294
295     vlc_mutex_unlock( &p_i->lock );
296
297     return b_ret;
298 }
299
300 char *input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
301 {
302     vlc_mutex_lock( &p_i->lock );
303
304     if( !p_i->p_meta )
305     {
306         vlc_mutex_unlock( &p_i->lock );
307         return NULL;
308     }
309
310     char *psz = NULL;
311     if( vlc_meta_Get( p_i->p_meta, meta_type ) )
312         psz = strdup( vlc_meta_Get( p_i->p_meta, meta_type ) );
313
314     vlc_mutex_unlock( &p_i->lock );
315     return psz;
316 }
317
318 char *input_item_GetName( input_item_t *p_item )
319 {
320     vlc_mutex_lock( &p_item->lock );
321
322     char *psz_name = p_item->psz_name ? strdup( p_item->psz_name ) : NULL;
323
324     vlc_mutex_unlock( &p_item->lock );
325     return psz_name;
326 }
327 void input_item_SetName( input_item_t *p_item, const char *psz_name )
328 {
329     vlc_mutex_lock( &p_item->lock );
330
331     free( p_item->psz_name );
332     p_item->psz_name = strdup( psz_name );
333
334     vlc_mutex_unlock( &p_item->lock );
335 }
336
337 char *input_item_GetURI( input_item_t *p_i )
338 {
339     vlc_mutex_lock( &p_i->lock );
340
341     char *psz_s = p_i->psz_uri ? strdup( p_i->psz_uri ) : NULL;
342
343     vlc_mutex_unlock( &p_i->lock );
344     return psz_s;
345 }
346 void input_item_SetURI( input_item_t *p_i, char *psz_uri )
347 {
348     vlc_mutex_lock( &p_i->lock );
349
350     free( p_i->psz_uri );
351     p_i->psz_uri = strdup( psz_uri );
352
353     vlc_mutex_unlock( &p_i->lock );
354 }
355
356 mtime_t input_item_GetDuration( input_item_t *p_i )
357 {
358     vlc_mutex_lock( &p_i->lock );
359
360     mtime_t i_duration = p_i->i_duration;
361
362     vlc_mutex_unlock( &p_i->lock );
363     return i_duration;
364 }
365
366 void input_item_SetDuration( input_item_t *p_i, mtime_t i_duration )
367 {
368     bool b_send_event = false;
369
370     vlc_mutex_lock( &p_i->lock );
371     if( p_i->i_duration != i_duration )
372     {
373         p_i->i_duration = i_duration;
374         b_send_event = true;
375     }
376     vlc_mutex_unlock( &p_i->lock );
377
378     if( b_send_event )
379     {
380         vlc_event_t event;
381
382         event.type = vlc_InputItemDurationChanged;
383         event.u.input_item_duration_changed.new_duration = i_duration;
384         vlc_event_send( &p_i->event_manager, &event );
385     }
386 }
387
388
389 bool input_item_IsPreparsed( input_item_t *p_item )
390 {
391     vlc_mutex_lock( &p_item->lock );
392     bool b_preparsed = p_item->p_meta ? ( p_item->p_meta->i_status & ITEM_PREPARSED ) != 0 : false;
393     vlc_mutex_unlock( &p_item->lock );
394
395     return b_preparsed;
396 }
397
398 bool input_item_IsArtFetched( input_item_t *p_item )
399 {
400     vlc_mutex_lock( &p_item->lock );
401     bool b_fetched = p_item->p_meta ? ( p_item->p_meta->i_status & ITEM_ART_FETCHED ) != 0 : false;
402     vlc_mutex_unlock( &p_item->lock );
403
404     return b_fetched;
405 }
406
407 /**
408  * Get a info item from a given category in a given input item.
409  *
410  * \param p_i The input item to get info from
411  * \param psz_cat String representing the category for the info
412  * \param psz_name String representing the name of the desired info
413  * \return A pointer to the string with the given info if found, or an
414  *         empty string otherwise. The caller should free the returned
415  *         pointer.
416  */
417 char *input_item_GetInfo( input_item_t *p_i,
418                           const char *psz_cat,
419                           const char *psz_name )
420 {
421     vlc_mutex_lock( &p_i->lock );
422
423     for( int i = 0; i< p_i->i_categories; i++ )
424     {
425         const info_category_t *p_cat = p_i->pp_categories[i];
426
427         if( !psz_cat || strcmp( p_cat->psz_name, psz_cat ) )
428             continue;
429
430         for( int j = 0; j < p_cat->i_infos; j++ )
431         {
432             if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
433             {
434                 char *psz_ret = strdup( p_cat->pp_infos[j]->psz_value );
435                 vlc_mutex_unlock( &p_i->lock );
436                 return psz_ret;
437             }
438         }
439     }
440     vlc_mutex_unlock( &p_i->lock );
441     return strdup( "" );
442 }
443
444 static void input_item_Destroy ( gc_object_t *p_gc )
445 {
446     input_item_t *p_item = vlc_priv( p_gc, input_item_t );
447
448     input_item_Clean( p_item );
449     free( p_item );
450 }
451
452 int input_item_AddOpt( input_item_t *p_input, const char *psz_option,
453                       unsigned flags )
454 {
455     int err = VLC_SUCCESS;
456
457     if( psz_option == NULL )
458         return VLC_EGENERIC;
459
460     vlc_mutex_lock( &p_input->lock );
461     if (flags & VLC_INPUT_OPTION_UNIQUE)
462     {
463         for (int i = 0 ; i < p_input->i_options; i++)
464             if( !strcmp( p_input->ppsz_options[i], psz_option ) )
465                 goto out;
466     }
467
468     uint8_t *flagv = realloc (p_input->optflagv, p_input->optflagc + 1);
469     if (flagv == NULL)
470     {
471         err = VLC_ENOMEM;
472         goto out;
473     }
474     p_input->optflagv = flagv;
475     flagv[p_input->optflagc++] = flags;
476
477     INSERT_ELEM( p_input->ppsz_options, p_input->i_options,
478                  p_input->i_options, strdup( psz_option ) );
479 out:
480     vlc_mutex_unlock( &p_input->lock );
481     return err;
482 }
483
484 int input_item_AddInfo( input_item_t *p_i,
485                         const char *psz_cat,
486                         const char *psz_name,
487                         const char *psz_format, ... )
488 {
489     va_list args;
490     int i;
491     info_t *p_info = NULL;
492     info_category_t *p_cat = NULL ;
493
494     vlc_mutex_lock( &p_i->lock );
495
496     for( i = 0 ; i < p_i->i_categories ; i ++ )
497     {
498         if( !strcmp( p_i->pp_categories[i]->psz_name, psz_cat ) )
499         {
500             p_cat = p_i->pp_categories[i];
501             break;
502         }
503     }
504     if( !p_cat )
505     {
506         if( !(p_cat = (info_category_t *)malloc( sizeof(info_category_t) )) )
507         {
508             vlc_mutex_unlock( &p_i->lock );
509             return VLC_ENOMEM;
510         }
511         p_cat->psz_name = strdup( psz_cat );
512         p_cat->i_infos = 0;
513         p_cat->pp_infos = 0;
514         INSERT_ELEM( p_i->pp_categories, p_i->i_categories, p_i->i_categories,
515                      p_cat );
516     }
517
518     for( i = 0; i< p_cat->i_infos; i++ )
519     {
520         if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
521         {
522             p_info = p_cat->pp_infos[i];
523             break;
524         }
525     }
526
527     if( !p_info )
528     {
529         if( ( p_info = (info_t *)malloc( sizeof( info_t ) ) ) == NULL )
530         {
531             vlc_mutex_unlock( &p_i->lock );
532             return VLC_ENOMEM;
533         }
534         INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
535         p_info->psz_name = strdup( psz_name );
536     }
537     else
538     {
539         free( p_info->psz_value );
540     }
541
542     va_start( args, psz_format );
543     if( vasprintf( &p_info->psz_value, psz_format, args) == -1 )
544         p_info->psz_value = NULL;
545     va_end( args );
546
547     vlc_mutex_unlock( &p_i->lock );
548
549     if( p_info->psz_value )
550     {
551         vlc_event_t event;
552
553         event.type = vlc_InputItemInfoChanged;
554         vlc_event_send( &p_i->event_manager, &event );
555     }
556     return p_info->psz_value ? VLC_SUCCESS : VLC_ENOMEM;
557 }
558 int input_item_DelInfo( input_item_t *p_i,
559                         const char *psz_cat,
560                         const char *psz_name )
561 {
562     info_category_t *p_cat = NULL;
563     int i_cat;
564     int i;
565
566     vlc_mutex_lock( &p_i->lock );
567     for( i_cat = 0; i_cat < p_i->i_categories; i_cat++ )
568     {
569         if( !strcmp( p_i->pp_categories[i_cat]->psz_name,
570                      psz_cat ) )
571         {
572             p_cat = p_i->pp_categories[i_cat];
573             break;
574         }
575     }
576     if( p_cat == NULL )
577     {
578         vlc_mutex_unlock( &p_i->lock );
579         return VLC_EGENERIC;
580     }
581
582     if( psz_name )
583     {
584         /* Remove a specific info */
585         for( i = 0; i < p_cat->i_infos; i++ )
586         {
587             if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
588             {
589                 free( p_cat->pp_infos[i]->psz_name );
590                 if( p_cat->pp_infos[i]->psz_value )
591                     free( p_cat->pp_infos[i]->psz_value );
592                 free( p_cat->pp_infos[i] );
593                 REMOVE_ELEM( p_cat->pp_infos, p_cat->i_infos, i );
594                 break;
595             }
596         }
597         if( i >= p_cat->i_infos )
598         {
599             vlc_mutex_unlock( &p_i->lock );
600             return VLC_EGENERIC;
601         }
602     }
603     else
604     {
605         /* Remove the complete categorie */
606         for( i = 0; i < p_cat->i_infos; i++ )
607         {
608             free( p_cat->pp_infos[i]->psz_name );
609             if( p_cat->pp_infos[i]->psz_value )
610                 free( p_cat->pp_infos[i]->psz_value );
611             free( p_cat->pp_infos[i] );
612         }
613         if( p_cat->pp_infos )
614             free( p_cat->pp_infos );
615         REMOVE_ELEM( p_i->pp_categories, p_i->i_categories, i_cat );
616     }
617     vlc_mutex_unlock( &p_i->lock );
618
619
620     vlc_event_t event;
621     event.type = vlc_InputItemInfoChanged;
622     vlc_event_send( &p_i->event_manager, &event );
623
624     return VLC_SUCCESS;
625 }
626
627
628 input_item_t *__input_item_NewExt( vlc_object_t *p_obj, const char *psz_uri,
629                                   const char *psz_name,
630                                   int i_options,
631                                   const char *const *ppsz_options,
632                                   mtime_t i_duration )
633 {
634     return input_item_NewWithType( p_obj, psz_uri, psz_name,
635                                   i_options, ppsz_options,
636                                   i_duration, ITEM_TYPE_UNKNOWN );
637 }
638
639
640 input_item_t *input_item_NewWithType( vlc_object_t *p_obj, const char *psz_uri,
641                                 const char *psz_name,
642                                 int i_options,
643                                 const char *const *ppsz_options,
644                                 mtime_t i_duration,
645                                 int i_type )
646 {
647     libvlc_priv_t *priv = libvlc_priv (p_obj->p_libvlc);
648
649     input_item_t* p_input = malloc( sizeof(input_item_t ) );
650     if( !p_input )
651         return NULL;
652
653     input_item_Init( p_obj, p_input );
654     vlc_gc_init( p_input, input_item_Destroy );
655
656     vlc_object_lock( p_obj->p_libvlc );
657     p_input->i_id = ++priv->i_last_input_id;
658     vlc_object_unlock( p_obj->p_libvlc );
659
660     p_input->b_fixed_name = false;
661
662     if( psz_uri )
663         p_input->psz_uri = strdup( psz_uri );
664     else
665         p_input->psz_uri = NULL;
666
667     p_input->i_type = i_type;
668     p_input->b_prefers_tree = false;
669
670     if( p_input->i_type == ITEM_TYPE_UNKNOWN )
671         GuessType( p_input );
672
673     if( psz_name != NULL )
674         p_input->psz_name = strdup( psz_name );
675     else if( p_input->i_type == ITEM_TYPE_FILE && p_input->psz_uri )
676     {
677         const char *psz_filename = strrchr( p_input->psz_uri, DIR_SEP_CHAR );
678         if( psz_filename && *psz_filename == DIR_SEP_CHAR )
679             psz_filename++;
680         p_input->psz_name = strdup( psz_filename && *psz_filename
681                                     ? psz_filename : p_input->psz_uri );
682     }
683     else
684         p_input->psz_name = p_input->psz_uri ? strdup( p_input->psz_uri ) : NULL;
685
686     p_input->i_duration = i_duration;
687
688     for( int i = 0; i < i_options; i++ )
689         input_item_AddOption( p_input, ppsz_options[i] );
690     return p_input;
691 }
692
693 /* Guess the type of the item using the beginning of the mrl */
694 static void GuessType( input_item_t *p_item)
695 {
696     int i;
697     static struct { const char *psz_search; int i_type; }  types_array[] =
698     {
699         { "http", ITEM_TYPE_NET },
700         { "dvd", ITEM_TYPE_DISC },
701         { "cdda", ITEM_TYPE_CDDA },
702         { "mms", ITEM_TYPE_NET },
703         { "rtsp", ITEM_TYPE_NET },
704         { "udp", ITEM_TYPE_NET },
705         { "rtp", ITEM_TYPE_NET },
706         { "vcd", ITEM_TYPE_DISC },
707         { "v4l", ITEM_TYPE_CARD },
708         { "dshow", ITEM_TYPE_CARD },
709         { "pvr", ITEM_TYPE_CARD },
710         { "dvb", ITEM_TYPE_CARD },
711         { "qpsk", ITEM_TYPE_CARD },
712         { "sdp", ITEM_TYPE_NET },
713         { NULL, 0 }
714     };
715
716     if( !p_item->psz_uri )
717     {
718         p_item->i_type = ITEM_TYPE_FILE;
719         return;
720     }
721
722     for( i = 0; types_array[i].psz_search != NULL; i++ )
723     {
724         if( !strncmp( p_item->psz_uri, types_array[i].psz_search,
725                       strlen( types_array[i].psz_search ) ) )
726         {
727             p_item->i_type = types_array[i].i_type;
728             return;
729         }
730     }
731     p_item->i_type = ITEM_TYPE_FILE;
732 }