]> git.sesse.net Git - vlc/blob - src/control/media.c
libvlc_event_manager: remove exceptions
[vlc] / src / control / media.c
1 /*****************************************************************************
2  * media.c: Libvlc API media descripor management
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Pierre d'Herbemont <pdherbemont@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
28 #include <assert.h>
29
30 #include <vlc/libvlc.h>
31 #include <vlc/libvlc_media.h>
32 #include <vlc/libvlc_media_list.h> // For the subitems, here for convenience
33 #include <vlc/libvlc_events.h>
34
35 #include <vlc_common.h>
36 #include <vlc_input.h>
37 #include <vlc_meta.h>
38 #include <vlc_playlist.h> /* For the preparser */
39
40 #include "libvlc.h"
41
42 #include "libvlc_internal.h"
43 #include "media_internal.h"
44
45 static const vlc_meta_type_t libvlc_to_vlc_meta[] =
46 {
47     [libvlc_meta_Title]        = vlc_meta_Title,
48     [libvlc_meta_Artist]       = vlc_meta_Artist,
49     [libvlc_meta_Genre]        = vlc_meta_Genre,
50     [libvlc_meta_Copyright]    = vlc_meta_Copyright,
51     [libvlc_meta_Album]        = vlc_meta_Album,
52     [libvlc_meta_TrackNumber]  = vlc_meta_TrackNumber,
53     [libvlc_meta_Description]  = vlc_meta_Description,
54     [libvlc_meta_Rating]       = vlc_meta_Rating,
55     [libvlc_meta_Date]         = vlc_meta_Date,
56     [libvlc_meta_Setting]      = vlc_meta_Setting,
57     [libvlc_meta_URL]          = vlc_meta_URL,
58     [libvlc_meta_Language]     = vlc_meta_Language,
59     [libvlc_meta_NowPlaying]   = vlc_meta_NowPlaying,
60     [libvlc_meta_Publisher]    = vlc_meta_Publisher,
61     [libvlc_meta_EncodedBy]    = vlc_meta_EncodedBy,
62     [libvlc_meta_ArtworkURL]   = vlc_meta_ArtworkURL,
63     [libvlc_meta_TrackID]      = vlc_meta_TrackID
64 };
65
66 static const libvlc_meta_t vlc_to_libvlc_meta[] =
67 {
68     [vlc_meta_Title]        = libvlc_meta_Title,
69     [vlc_meta_Artist]       = libvlc_meta_Artist,
70     [vlc_meta_Genre]        = libvlc_meta_Genre,
71     [vlc_meta_Copyright]    = libvlc_meta_Copyright,
72     [vlc_meta_Album]        = libvlc_meta_Album,
73     [vlc_meta_TrackNumber]  = libvlc_meta_TrackNumber,
74     [vlc_meta_Description]  = libvlc_meta_Description,
75     [vlc_meta_Rating]       = libvlc_meta_Rating,
76     [vlc_meta_Date]         = libvlc_meta_Date,
77     [vlc_meta_Setting]      = libvlc_meta_Setting,
78     [vlc_meta_URL]          = libvlc_meta_URL,
79     [vlc_meta_Language]     = libvlc_meta_Language,
80     [vlc_meta_NowPlaying]   = libvlc_meta_NowPlaying,
81     [vlc_meta_Publisher]    = libvlc_meta_Publisher,
82     [vlc_meta_EncodedBy]    = libvlc_meta_EncodedBy,
83     [vlc_meta_ArtworkURL]   = libvlc_meta_ArtworkURL,
84     [vlc_meta_TrackID]      = libvlc_meta_TrackID
85 };
86
87 /**************************************************************************
88  * input_item_subitem_added (Private) (vlc event Callback)
89  **************************************************************************/
90 static void input_item_subitem_added( const vlc_event_t *p_event,
91                                        void * user_data )
92 {
93     libvlc_media_t * p_md = user_data;
94     libvlc_media_t * p_md_child;
95     libvlc_event_t event;
96
97     p_md_child = libvlc_media_new_from_input_item(
98                 p_md->p_libvlc_instance,
99                 p_event->u.input_item_subitem_added.p_new_child, NULL );
100
101     /* Add this to our media list */
102     if( !p_md->p_subitems )
103     {
104         p_md->p_subitems = libvlc_media_list_new( p_md->p_libvlc_instance, NULL );
105         libvlc_media_list_set_media( p_md->p_subitems, p_md );
106     }
107     if( p_md->p_subitems )
108     {
109         libvlc_media_list_add_media( p_md->p_subitems, p_md_child, NULL );
110     }
111
112     /* Construct the event */
113     event.type = libvlc_MediaSubItemAdded;
114     event.u.media_subitem_added.new_child = p_md_child;
115
116     /* Send the event */
117     libvlc_event_send( p_md->p_event_manager, &event );
118     libvlc_media_release( p_md_child );
119 }
120
121 /**************************************************************************
122  * input_item_meta_changed (Private) (vlc event Callback)
123  **************************************************************************/
124 static void input_item_meta_changed( const vlc_event_t *p_event,
125                                      void * user_data )
126 {
127     libvlc_media_t * p_md = user_data;
128     libvlc_event_t event;
129
130     /* Construct the event */
131     event.type = libvlc_MediaMetaChanged;
132     event.u.media_meta_changed.meta_type =
133         vlc_to_libvlc_meta[p_event->u.input_item_meta_changed.meta_type];
134
135     /* Send the event */
136     libvlc_event_send( p_md->p_event_manager, &event );
137 }
138
139 /**************************************************************************
140  * input_item_duration_changed (Private) (vlc event Callback)
141  **************************************************************************/
142 static void input_item_duration_changed( const vlc_event_t *p_event,
143                                          void * user_data )
144 {
145     libvlc_media_t * p_md = user_data;
146     libvlc_event_t event;
147
148     /* Construct the event */
149     event.type = libvlc_MediaDurationChanged;
150     event.u.media_duration_changed.new_duration =
151         from_mtime(p_event->u.input_item_duration_changed.new_duration);
152
153     /* Send the event */
154     libvlc_event_send( p_md->p_event_manager, &event );
155 }
156
157 /**************************************************************************
158  * input_item_preparsed_changed (Private) (vlc event Callback)
159  **************************************************************************/
160 static void input_item_preparsed_changed( const vlc_event_t *p_event,
161                                           void * user_data )
162 {
163     libvlc_media_t * p_md = user_data;
164     libvlc_event_t event;
165
166     /* Construct the event */
167     event.type = libvlc_MediaPreparsedChanged;
168     event.u.media_preparsed_changed.new_status = 
169         p_event->u.input_item_preparsed_changed.new_status;
170
171     /* Send the event */
172     libvlc_event_send( p_md->p_event_manager, &event );
173 }
174
175 /**************************************************************************
176  * Install event handler (Private)
177  **************************************************************************/
178 static void install_input_item_observer( libvlc_media_t *p_md )
179 {
180     vlc_event_attach( &p_md->p_input_item->event_manager,
181                       vlc_InputItemSubItemAdded,
182                       input_item_subitem_added,
183                       p_md );
184     vlc_event_attach( &p_md->p_input_item->event_manager,
185                       vlc_InputItemMetaChanged,
186                       input_item_meta_changed,
187                       p_md );
188     vlc_event_attach( &p_md->p_input_item->event_manager,
189                       vlc_InputItemDurationChanged,
190                       input_item_duration_changed,
191                       p_md );
192     vlc_event_attach( &p_md->p_input_item->event_manager,
193                       vlc_InputItemPreparsedChanged,
194                       input_item_preparsed_changed,
195                       p_md );
196 }
197
198 /**************************************************************************
199  * Uninstall event handler (Private)
200  **************************************************************************/
201 static void uninstall_input_item_observer( libvlc_media_t *p_md )
202 {
203     vlc_event_detach( &p_md->p_input_item->event_manager,
204                       vlc_InputItemSubItemAdded,
205                       input_item_subitem_added,
206                       p_md );
207     vlc_event_detach( &p_md->p_input_item->event_manager,
208                       vlc_InputItemMetaChanged,
209                       input_item_meta_changed,
210                       p_md );
211     vlc_event_detach( &p_md->p_input_item->event_manager,
212                       vlc_InputItemDurationChanged,
213                       input_item_duration_changed,
214                       p_md );
215     vlc_event_detach( &p_md->p_input_item->event_manager,
216                       vlc_InputItemPreparsedChanged,
217                       input_item_preparsed_changed,
218                       p_md );
219 }
220
221 /**************************************************************************
222  * Preparse if not already done (Private)
223  **************************************************************************/
224 static void preparse_if_needed( libvlc_media_t *p_md )
225 {
226     /* XXX: need some locking here */
227     if (!p_md->b_preparsed)
228     {
229         playlist_PreparseEnqueue(
230                 libvlc_priv (p_md->p_libvlc_instance->p_libvlc_int)->p_playlist,
231                 p_md->p_input_item, pl_Unlocked );
232         p_md->b_preparsed = true;
233     }
234 }
235
236 /**************************************************************************
237  * Create a new media descriptor object from an input_item
238  * (libvlc internal)
239  * That's the generic constructor
240  **************************************************************************/
241 libvlc_media_t * libvlc_media_new_from_input_item(
242                                    libvlc_instance_t *p_instance,
243                                    input_item_t *p_input_item,
244                                    libvlc_exception_t *p_e )
245 {
246     libvlc_media_t * p_md;
247
248     if (!p_input_item)
249     {
250         libvlc_exception_raise( p_e );
251         libvlc_printerr( "No input item given" );
252         return NULL;
253     }
254
255     p_md = calloc( 1, sizeof(libvlc_media_t) );
256     if( !p_md )
257     {
258         libvlc_exception_raise( p_e );
259         libvlc_printerr( "Not enough memory" );
260         return NULL;
261     }
262
263     p_md->p_libvlc_instance = p_instance;
264     p_md->p_input_item      = p_input_item;
265     p_md->i_refcount        = 1;
266
267     p_md->state = libvlc_NothingSpecial;
268
269     /* A media descriptor can be a playlist. When you open a playlist
270      * It can give a bunch of item to read. */
271     p_md->p_subitems        = NULL;
272
273     p_md->p_event_manager = libvlc_event_manager_new( p_md, p_instance );
274     if( unlikely(p_md->p_event_manager == NULL) )
275     {
276         free(p_md);
277         return NULL;
278     }
279     libvlc_event_manager_register_event_type( p_md->p_event_manager,
280         libvlc_MediaMetaChanged );
281     libvlc_event_manager_register_event_type( p_md->p_event_manager,
282         libvlc_MediaSubItemAdded );
283     libvlc_event_manager_register_event_type( p_md->p_event_manager,
284         libvlc_MediaFreed );
285     libvlc_event_manager_register_event_type( p_md->p_event_manager,
286         libvlc_MediaDurationChanged );
287     libvlc_event_manager_register_event_type( p_md->p_event_manager,
288         libvlc_MediaStateChanged );
289
290     vlc_gc_incref( p_md->p_input_item );
291
292     install_input_item_observer( p_md );
293
294     return p_md;
295 }
296
297 /**************************************************************************
298  * Create a new media descriptor object
299  **************************************************************************/
300 libvlc_media_t * libvlc_media_new(
301                                    libvlc_instance_t *p_instance,
302                                    const char * psz_mrl,
303                                    libvlc_exception_t *p_e )
304 {
305     input_item_t * p_input_item;
306     libvlc_media_t * p_md;
307
308     p_input_item = input_item_New( p_instance->p_libvlc_int, psz_mrl, NULL );
309
310     if (!p_input_item)
311     {
312         libvlc_exception_raise( p_e );
313         libvlc_printerr( "Not enough memory" );
314         return NULL;
315     }
316
317     p_md = libvlc_media_new_from_input_item( p_instance,
318                 p_input_item, p_e );
319
320     /* The p_input_item is retained in libvlc_media_new_from_input_item */
321     vlc_gc_decref( p_input_item );
322
323     return p_md;
324 }
325
326 /**************************************************************************
327  * Create a new media descriptor object
328  **************************************************************************/
329 libvlc_media_t * libvlc_media_new_as_node(
330                                    libvlc_instance_t *p_instance,
331                                    const char * psz_name,
332                                    libvlc_exception_t *p_e )
333 {
334     input_item_t * p_input_item;
335     libvlc_media_t * p_md;
336
337     p_input_item = input_item_New( p_instance->p_libvlc_int, "vlc://nop", psz_name );
338
339     if (!p_input_item)
340     {
341         libvlc_exception_raise( p_e );
342         libvlc_printerr( "Not enough memory" );
343         return NULL;
344     }
345
346     p_md = libvlc_media_new_from_input_item( p_instance,
347                 p_input_item, p_e );
348
349     p_md->p_subitems = libvlc_media_list_new( p_md->p_libvlc_instance, NULL );
350
351     return p_md;
352 }
353
354 /**************************************************************************
355  * Add an option to the media descriptor,
356  * that will be used to determine how the media_player will read the
357  * media. This allow to use VLC advanced reading/streaming
358  * options in a per-media basis
359  *
360  * The options are detailled in vlc --long-help, for instance "--sout-all"
361  **************************************************************************/
362 void libvlc_media_add_option(
363                                    libvlc_media_t * p_md,
364                                    const char * psz_option )
365 {
366     input_item_AddOption( p_md->p_input_item, psz_option,
367                           VLC_INPUT_OPTION_UNIQUE|VLC_INPUT_OPTION_TRUSTED );
368 }
369
370 /**************************************************************************
371  * Same as libvlc_media_add_option but with configurable flags.
372  **************************************************************************/
373 void libvlc_media_add_option_flag(
374                                    libvlc_media_t * p_md,
375                                    const char * ppsz_option,
376                                    libvlc_media_option_t i_flags )
377 {
378     input_item_AddOption( p_md->p_input_item, ppsz_option,
379                           i_flags );
380 }
381
382 /**************************************************************************
383  * Delete a media descriptor object
384  **************************************************************************/
385 void libvlc_media_release( libvlc_media_t *p_md )
386 {
387     if (!p_md)
388         return;
389
390     p_md->i_refcount--;
391
392     if( p_md->i_refcount > 0 )
393         return;
394
395     if( p_md->p_subitems )
396         libvlc_media_list_release( p_md->p_subitems );
397
398     uninstall_input_item_observer( p_md );
399     vlc_gc_decref( p_md->p_input_item );
400
401     /* Construct the event */
402     libvlc_event_t event;
403     event.type = libvlc_MediaFreed;
404     event.u.media_freed.md = p_md;
405
406     /* Send the event */
407     libvlc_event_send( p_md->p_event_manager, &event );
408
409     libvlc_event_manager_release( p_md->p_event_manager );
410
411     free( p_md );
412 }
413
414 /**************************************************************************
415  * Retain a media descriptor object
416  **************************************************************************/
417 void libvlc_media_retain( libvlc_media_t *p_md )
418 {
419     assert (p_md);
420     p_md->i_refcount++;
421 }
422
423 /**************************************************************************
424  * Duplicate a media descriptor object
425  **************************************************************************/
426 libvlc_media_t *
427 libvlc_media_duplicate( libvlc_media_t *p_md_orig )
428 {
429     return libvlc_media_new_from_input_item(
430         p_md_orig->p_libvlc_instance, p_md_orig->p_input_item, NULL );
431 }
432
433 /**************************************************************************
434  * Get mrl from a media descriptor object
435  **************************************************************************/
436 char *
437 libvlc_media_get_mrl( libvlc_media_t * p_md )
438 {
439     assert( p_md );
440     return input_item_GetURI( p_md->p_input_item );
441 }
442
443 /**************************************************************************
444  * Getter for meta information
445  **************************************************************************/
446
447 char *libvlc_media_get_meta( libvlc_media_t *p_md, libvlc_meta_t e_meta )
448 {
449     char * psz_meta;
450
451     assert( p_md );
452     /* XXX: locking */
453
454     preparse_if_needed( p_md );
455
456     psz_meta = input_item_GetMeta( p_md->p_input_item,
457                                    libvlc_to_vlc_meta[e_meta] );
458
459     if( e_meta == libvlc_meta_ArtworkURL && !psz_meta && !p_md->has_asked_art )
460     {
461         p_md->has_asked_art = true;
462         playlist_AskForArtEnqueue(
463                 libvlc_priv(p_md->p_libvlc_instance->p_libvlc_int)->p_playlist,
464                 p_md->p_input_item, pl_Unlocked );
465     }
466
467     /* Should be integrated in core */
468     if( !psz_meta && e_meta == libvlc_meta_Title && p_md->p_input_item->psz_name )
469     {
470         free( psz_meta );
471         return strdup( p_md->p_input_item->psz_name );
472     }
473
474     return psz_meta;
475 }
476
477 /**************************************************************************
478  * Setter for meta information
479  **************************************************************************/
480
481 void libvlc_media_set_meta( libvlc_media_t *p_md, libvlc_meta_t e_meta, const char *psz_value )
482 {
483     assert( p_md );
484     input_item_SetMeta( p_md->p_input_item, libvlc_to_vlc_meta[e_meta], psz_value );
485 }
486
487 int libvlc_media_save_meta( libvlc_media_t *p_md )
488 {
489     assert( p_md );
490     vlc_object_t *p_obj = VLC_OBJECT(libvlc_priv(
491                             p_md->p_libvlc_instance->p_libvlc_int)->p_playlist);
492     return input_item_WriteMeta( p_obj, p_md->p_input_item ) == VLC_SUCCESS;
493 }
494
495 /**************************************************************************
496  * Getter for state information
497  * Can be error, playing, buffering, NothingSpecial.
498  **************************************************************************/
499
500 libvlc_state_t
501 libvlc_media_get_state( libvlc_media_t *p_md )
502 {
503     assert( p_md );
504     return p_md->state;
505 }
506
507 /**************************************************************************
508  * Setter for state information (LibVLC Internal)
509  **************************************************************************/
510
511 void
512 libvlc_media_set_state( libvlc_media_t *p_md,
513                                    libvlc_state_t state )
514 {
515     libvlc_event_t event;
516
517     p_md->state = state;
518
519     /* Construct the event */
520     event.type = libvlc_MediaStateChanged;
521     event.u.media_state_changed.new_state = state;
522
523     /* Send the event */
524     libvlc_event_send( p_md->p_event_manager, &event );
525 }
526
527 /**************************************************************************
528  * subitems
529  **************************************************************************/
530 libvlc_media_list_t *
531 libvlc_media_subitems( libvlc_media_t * p_md )
532 {
533     if( p_md->p_subitems )
534         libvlc_media_list_retain( p_md->p_subitems );
535     return p_md->p_subitems;
536 }
537
538 /**************************************************************************
539  * Getter for statistics information
540  **************************************************************************/
541 int libvlc_media_get_stats( libvlc_media_t *p_md,
542                             libvlc_media_stats_t *p_stats )
543 {
544     if( !p_md->p_input_item )
545         return false;
546
547     input_stats_t *p_itm_stats = p_md->p_input_item->p_stats;
548     vlc_mutex_lock( &p_itm_stats->lock );
549     p_stats->i_read_bytes = p_itm_stats->i_read_bytes;
550     p_stats->f_input_bitrate = p_itm_stats->f_input_bitrate;
551
552     p_stats->i_demux_read_bytes = p_itm_stats->i_demux_read_bytes;
553     p_stats->f_demux_bitrate = p_itm_stats->f_demux_bitrate;
554     p_stats->i_demux_corrupted = p_itm_stats->i_demux_corrupted;
555     p_stats->i_demux_discontinuity = p_itm_stats->i_demux_discontinuity;
556
557     p_stats->i_decoded_video = p_itm_stats->i_decoded_video;
558     p_stats->i_decoded_audio = p_itm_stats->i_decoded_audio;
559
560     p_stats->i_displayed_pictures = p_itm_stats->i_displayed_pictures;
561     p_stats->i_lost_pictures = p_itm_stats->i_lost_pictures;
562
563     p_stats->i_played_abuffers = p_itm_stats->i_played_abuffers;
564     p_stats->i_lost_abuffers = p_itm_stats->i_lost_abuffers;
565
566     p_stats->i_sent_packets = p_itm_stats->i_sent_packets;
567     p_stats->i_sent_bytes = p_itm_stats->i_sent_bytes;
568     p_stats->f_send_bitrate = p_itm_stats->f_send_bitrate;
569     vlc_mutex_unlock( &p_itm_stats->lock );
570     return true;
571 }
572
573 /**************************************************************************
574  * event_manager
575  **************************************************************************/
576 libvlc_event_manager_t *
577 libvlc_media_event_manager( libvlc_media_t * p_md )
578 {
579     assert( p_md );
580
581     return p_md->p_event_manager;
582 }
583
584 /**************************************************************************
585  * Get duration of media object (in ms)
586  **************************************************************************/
587 int64_t
588 libvlc_media_get_duration( libvlc_media_t * p_md, libvlc_exception_t *p_e )
589 {
590     assert( p_md );
591
592     if( !p_md->p_input_item )
593     {
594         libvlc_exception_raise( p_e );
595         libvlc_printerr( "No input item" );
596         return -1;
597     }
598
599     preparse_if_needed( p_md );
600
601     if (!input_item_IsPreparsed( p_md->p_input_item ))
602         return -1;
603
604     return from_mtime(input_item_GetDuration( p_md->p_input_item ));
605 }
606
607 /**************************************************************************
608  * Get preparsed status for media object.
609  **************************************************************************/
610 int
611 libvlc_media_is_preparsed( libvlc_media_t * p_md )
612 {
613     assert( p_md );
614
615     if( !p_md->p_input_item )
616         return false;
617
618     return input_item_IsPreparsed( p_md->p_input_item );
619 }
620
621 /**************************************************************************
622  * Sets media descriptor's user_data. user_data is specialized data 
623  * accessed by the host application, VLC.framework uses it as a pointer to 
624  * an native object that references a libvlc_media_t pointer
625  **************************************************************************/
626 void 
627 libvlc_media_set_user_data( libvlc_media_t * p_md, void * p_new_user_data )
628 {
629     assert( p_md );
630     p_md->p_user_data = p_new_user_data;
631 }
632
633 /**************************************************************************
634  * Get media descriptor's user_data. user_data is specialized data 
635  * accessed by the host application, VLC.framework uses it as a pointer to 
636  * an native object that references a libvlc_media_t pointer
637  **************************************************************************/
638 void *
639 libvlc_media_get_user_data( libvlc_media_t * p_md )
640 {
641     assert( p_md );
642     return p_md->p_user_data;
643 }
644
645 /**************************************************************************
646  * Get media descriptor's elementary streams description
647  **************************************************************************/
648 int
649 libvlc_media_get_es( libvlc_media_t *p_md, libvlc_media_es_t ** pp_es )
650 {
651     assert( p_md );
652
653     input_item_t *p_input_item = p_md->p_input_item;
654     vlc_mutex_lock( &p_input_item->lock );
655
656     const int i_es = p_input_item->i_es;
657     *pp_es = (i_es > 0) ? malloc( i_es * sizeof(libvlc_media_es_t) ) : NULL;
658
659     if( !pp_es ) /* no ES, or OOM */
660     {
661         vlc_mutex_unlock( &p_input_item->lock );
662         return 0;
663     }
664
665     /* Fill array */
666     for( int i = 0; i < i_es; i++ )
667     {
668         libvlc_media_es_t *p_mes = *pp_es+i;
669         const es_format_t *p_es = p_input_item->es[i];
670
671         p_mes->i_channels = p_mes->i_rate = 0;
672         p_mes->i_width = p_mes->i_height = 0;
673
674
675         p_mes->i_codec = p_es->i_codec;
676
677         p_mes->i_profile = p_es->i_profile;
678         p_mes->i_level = p_es->i_level;
679
680         switch(p_es->i_cat)
681         {
682         case UNKNOWN_ES:
683         default:
684             p_mes->i_type = libvlc_es_unknown;
685             break;
686         case VIDEO_ES:
687             p_mes->i_type = libvlc_es_video;
688             p_mes->i_height = p_es->video.i_height;
689             p_mes->i_width = p_es->video.i_width;
690             break;
691         case AUDIO_ES:
692             p_mes->i_type = libvlc_es_audio;
693             p_mes->i_channels = p_es->audio.i_channels;
694             p_mes->i_rate = p_es->audio.i_rate;
695             break;
696         case SPU_ES:
697             p_mes->i_type = libvlc_es_text;
698             break;
699         }
700     }
701
702     vlc_mutex_unlock( &p_input_item->lock );
703     return i_es;
704 }