1 /*****************************************************************************
2 * media.c: Libvlc API media descripor management
3 *****************************************************************************
4 * Copyright (C) 2007 VLC authors and VideoLAN
7 * Authors: Pierre d'Herbemont <pdherbemont@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
31 #include <vlc/libvlc.h>
32 #include <vlc/libvlc_media.h>
33 #include <vlc/libvlc_media_list.h> // For the subitems, here for convenience
34 #include <vlc/libvlc_events.h>
36 #include <vlc_common.h>
37 #include <vlc_input.h>
39 #include <vlc_playlist.h> /* For the preparser */
42 #include "../src/libvlc.h"
44 #include "libvlc_internal.h"
45 #include "media_internal.h"
47 static const vlc_meta_type_t libvlc_to_vlc_meta
[] =
49 [libvlc_meta_Title
] = vlc_meta_Title
,
50 [libvlc_meta_Artist
] = vlc_meta_Artist
,
51 [libvlc_meta_Genre
] = vlc_meta_Genre
,
52 [libvlc_meta_Copyright
] = vlc_meta_Copyright
,
53 [libvlc_meta_Album
] = vlc_meta_Album
,
54 [libvlc_meta_TrackNumber
] = vlc_meta_TrackNumber
,
55 [libvlc_meta_Description
] = vlc_meta_Description
,
56 [libvlc_meta_Rating
] = vlc_meta_Rating
,
57 [libvlc_meta_Date
] = vlc_meta_Date
,
58 [libvlc_meta_Setting
] = vlc_meta_Setting
,
59 [libvlc_meta_URL
] = vlc_meta_URL
,
60 [libvlc_meta_Language
] = vlc_meta_Language
,
61 [libvlc_meta_NowPlaying
] = vlc_meta_NowPlaying
,
62 [libvlc_meta_Publisher
] = vlc_meta_Publisher
,
63 [libvlc_meta_EncodedBy
] = vlc_meta_EncodedBy
,
64 [libvlc_meta_ArtworkURL
] = vlc_meta_ArtworkURL
,
65 [libvlc_meta_TrackID
] = vlc_meta_TrackID
,
66 [libvlc_meta_TrackTotal
] = vlc_meta_TrackTotal
,
67 [libvlc_meta_Director
] = vlc_meta_Director
,
68 [libvlc_meta_Season
] = vlc_meta_Season
,
69 [libvlc_meta_Episode
] = vlc_meta_Episode
,
70 [libvlc_meta_ShowName
] = vlc_meta_ShowName
,
71 [libvlc_meta_Actors
] = vlc_meta_Actors
74 static const libvlc_meta_t vlc_to_libvlc_meta
[] =
76 [vlc_meta_Title
] = libvlc_meta_Title
,
77 [vlc_meta_Artist
] = libvlc_meta_Artist
,
78 [vlc_meta_Genre
] = libvlc_meta_Genre
,
79 [vlc_meta_Copyright
] = libvlc_meta_Copyright
,
80 [vlc_meta_Album
] = libvlc_meta_Album
,
81 [vlc_meta_TrackNumber
] = libvlc_meta_TrackNumber
,
82 [vlc_meta_Description
] = libvlc_meta_Description
,
83 [vlc_meta_Rating
] = libvlc_meta_Rating
,
84 [vlc_meta_Date
] = libvlc_meta_Date
,
85 [vlc_meta_Setting
] = libvlc_meta_Setting
,
86 [vlc_meta_URL
] = libvlc_meta_URL
,
87 [vlc_meta_Language
] = libvlc_meta_Language
,
88 [vlc_meta_NowPlaying
] = libvlc_meta_NowPlaying
,
89 [vlc_meta_Publisher
] = libvlc_meta_Publisher
,
90 [vlc_meta_EncodedBy
] = libvlc_meta_EncodedBy
,
91 [vlc_meta_ArtworkURL
] = libvlc_meta_ArtworkURL
,
92 [vlc_meta_TrackID
] = libvlc_meta_TrackID
,
93 [vlc_meta_TrackTotal
] = libvlc_meta_TrackTotal
,
94 [vlc_meta_Director
] = libvlc_meta_Director
,
95 [vlc_meta_Season
] = libvlc_meta_Season
,
96 [vlc_meta_Episode
] = libvlc_meta_Episode
,
97 [vlc_meta_ShowName
] = libvlc_meta_ShowName
,
98 [vlc_meta_Actors
] = libvlc_meta_Actors
101 /**************************************************************************
102 * input_item_subitem_added (Private) (vlc event Callback)
103 **************************************************************************/
104 static void input_item_subitem_added( const vlc_event_t
*p_event
,
107 libvlc_media_t
* p_md
= user_data
;
108 libvlc_media_t
* p_md_child
;
109 libvlc_event_t event
;
111 p_md_child
= libvlc_media_new_from_input_item(
112 p_md
->p_libvlc_instance
,
113 p_event
->u
.input_item_subitem_added
.p_new_child
);
115 /* Add this to our media list */
116 if( p_md
->p_subitems
== NULL
)
118 p_md
->p_subitems
= libvlc_media_list_new( p_md
->p_libvlc_instance
);
119 if( unlikely(p_md
->p_subitems
== NULL
) )
121 libvlc_media_list_set_media( p_md
->p_subitems
, p_md
);
123 libvlc_media_list_add_media( p_md
->p_subitems
, p_md_child
);
125 /* Construct the event */
126 event
.type
= libvlc_MediaSubItemAdded
;
127 event
.u
.media_subitem_added
.new_child
= p_md_child
;
130 libvlc_event_send( p_md
->p_event_manager
, &event
);
131 libvlc_media_release( p_md_child
);
134 /**************************************************************************
135 * input_item_subitemtree_added (Private) (vlc event Callback)
136 **************************************************************************/
137 static void input_item_subitemtree_added( const vlc_event_t
* p_event
,
140 VLC_UNUSED( p_event
);
141 libvlc_media_t
* p_md
= user_data
;
142 libvlc_event_t event
;
144 /* Construct the event */
145 event
.type
= libvlc_MediaSubItemTreeAdded
;
146 event
.u
.media_subitemtree_added
.item
= p_md
;
149 libvlc_event_send( p_md
->p_event_manager
, &event
);
152 /**************************************************************************
153 * input_item_meta_changed (Private) (vlc event Callback)
154 **************************************************************************/
155 static void input_item_meta_changed( const vlc_event_t
*p_event
,
158 libvlc_media_t
* p_md
= user_data
;
159 libvlc_event_t event
;
161 /* Construct the event */
162 event
.type
= libvlc_MediaMetaChanged
;
163 event
.u
.media_meta_changed
.meta_type
=
164 vlc_to_libvlc_meta
[p_event
->u
.input_item_meta_changed
.meta_type
];
167 libvlc_event_send( p_md
->p_event_manager
, &event
);
170 /**************************************************************************
171 * input_item_duration_changed (Private) (vlc event Callback)
172 **************************************************************************/
173 static void input_item_duration_changed( const vlc_event_t
*p_event
,
176 libvlc_media_t
* p_md
= user_data
;
177 libvlc_event_t event
;
179 /* Construct the event */
180 event
.type
= libvlc_MediaDurationChanged
;
181 event
.u
.media_duration_changed
.new_duration
=
182 from_mtime(p_event
->u
.input_item_duration_changed
.new_duration
);
185 libvlc_event_send( p_md
->p_event_manager
, &event
);
188 /**************************************************************************
189 * input_item_preparsed_changed (Private) (vlc event Callback)
190 **************************************************************************/
191 static void input_item_preparsed_changed(const vlc_event_t
*p_event
,
194 libvlc_media_t
*media
= user_data
;
195 libvlc_event_t event
;
197 /* Eventually notify libvlc_media_parse() */
198 vlc_mutex_lock(&media
->parsed_lock
);
199 media
->is_parsed
= true;
200 vlc_cond_broadcast(&media
->parsed_cond
);
201 vlc_mutex_unlock(&media
->parsed_lock
);
204 /* Construct the event */
205 event
.type
= libvlc_MediaParsedChanged
;
206 event
.u
.media_parsed_changed
.new_status
=
207 p_event
->u
.input_item_preparsed_changed
.new_status
;
210 libvlc_event_send(media
->p_event_manager
, &event
);
213 /**************************************************************************
214 * Install event handler (Private)
215 **************************************************************************/
216 static void install_input_item_observer( libvlc_media_t
*p_md
)
218 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
219 vlc_InputItemSubItemAdded
,
220 input_item_subitem_added
,
222 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
223 vlc_InputItemMetaChanged
,
224 input_item_meta_changed
,
226 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
227 vlc_InputItemDurationChanged
,
228 input_item_duration_changed
,
230 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
231 vlc_InputItemPreparsedChanged
,
232 input_item_preparsed_changed
,
234 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
235 vlc_InputItemSubItemTreeAdded
,
236 input_item_subitemtree_added
,
240 /**************************************************************************
241 * Uninstall event handler (Private)
242 **************************************************************************/
243 static void uninstall_input_item_observer( libvlc_media_t
*p_md
)
245 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
246 vlc_InputItemSubItemAdded
,
247 input_item_subitem_added
,
249 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
250 vlc_InputItemMetaChanged
,
251 input_item_meta_changed
,
253 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
254 vlc_InputItemDurationChanged
,
255 input_item_duration_changed
,
257 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
258 vlc_InputItemPreparsedChanged
,
259 input_item_preparsed_changed
,
261 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
262 vlc_InputItemSubItemTreeAdded
,
263 input_item_subitemtree_added
,
267 /**************************************************************************
268 * Create a new media descriptor object from an input_item
270 * That's the generic constructor
271 **************************************************************************/
272 libvlc_media_t
* libvlc_media_new_from_input_item(
273 libvlc_instance_t
*p_instance
,
274 input_item_t
*p_input_item
)
276 libvlc_media_t
* p_md
;
280 libvlc_printerr( "No input item given" );
284 p_md
= calloc( 1, sizeof(libvlc_media_t
) );
287 libvlc_printerr( "Not enough memory" );
291 p_md
->p_libvlc_instance
= p_instance
;
292 p_md
->p_input_item
= p_input_item
;
293 p_md
->i_refcount
= 1;
295 vlc_cond_init(&p_md
->parsed_cond
);
296 vlc_mutex_init(&p_md
->parsed_lock
);
298 p_md
->state
= libvlc_NothingSpecial
;
300 /* A media descriptor can be a playlist. When you open a playlist
301 * It can give a bunch of item to read. */
302 p_md
->p_subitems
= NULL
;
304 p_md
->p_event_manager
= libvlc_event_manager_new( p_md
, p_instance
);
305 if( unlikely(p_md
->p_event_manager
== NULL
) )
311 libvlc_event_manager_t
*em
= p_md
->p_event_manager
;
312 libvlc_event_manager_register_event_type(em
, libvlc_MediaMetaChanged
);
313 libvlc_event_manager_register_event_type(em
, libvlc_MediaSubItemAdded
);
314 libvlc_event_manager_register_event_type(em
, libvlc_MediaFreed
);
315 libvlc_event_manager_register_event_type(em
, libvlc_MediaDurationChanged
);
316 libvlc_event_manager_register_event_type(em
, libvlc_MediaStateChanged
);
317 libvlc_event_manager_register_event_type(em
, libvlc_MediaParsedChanged
);
318 libvlc_event_manager_register_event_type(em
, libvlc_MediaSubItemTreeAdded
);
320 vlc_gc_incref( p_md
->p_input_item
);
322 install_input_item_observer( p_md
);
327 /**************************************************************************
328 * Create a new media descriptor object
329 **************************************************************************/
330 libvlc_media_t
*libvlc_media_new_location( libvlc_instance_t
*p_instance
,
331 const char * psz_mrl
)
333 input_item_t
* p_input_item
;
334 libvlc_media_t
* p_md
;
336 p_input_item
= input_item_New( psz_mrl
, NULL
);
340 libvlc_printerr( "Not enough memory" );
344 p_md
= libvlc_media_new_from_input_item( p_instance
, p_input_item
);
346 /* The p_input_item is retained in libvlc_media_new_from_input_item */
347 vlc_gc_decref( p_input_item
);
352 libvlc_media_t
*libvlc_media_new_path( libvlc_instance_t
*p_instance
,
355 char *mrl
= vlc_path2uri( path
, NULL
);
356 if( unlikely(mrl
== NULL
) )
358 libvlc_printerr( "%s", vlc_strerror_c(errno
) );
362 libvlc_media_t
*m
= libvlc_media_new_location( p_instance
, mrl
);
367 libvlc_media_t
*libvlc_media_new_fd( libvlc_instance_t
*p_instance
, int fd
)
370 snprintf( mrl
, sizeof(mrl
), "fd://%d", fd
);
372 return libvlc_media_new_location( p_instance
, mrl
);
375 /**************************************************************************
376 * Create a new media descriptor object
377 **************************************************************************/
378 libvlc_media_t
* libvlc_media_new_as_node( libvlc_instance_t
*p_instance
,
379 const char * psz_name
)
381 input_item_t
* p_input_item
;
382 libvlc_media_t
* p_md
;
384 p_input_item
= input_item_New( "vlc://nop", psz_name
);
388 libvlc_printerr( "Not enough memory" );
392 p_md
= libvlc_media_new_from_input_item( p_instance
, p_input_item
);
394 p_md
->p_subitems
= libvlc_media_list_new( p_md
->p_libvlc_instance
);
399 /**************************************************************************
400 * Add an option to the media descriptor,
401 * that will be used to determine how the media_player will read the
402 * media. This allow to use VLC advanced reading/streaming
403 * options in a per-media basis
405 * The options are detailled in vlc --long-help, for instance "--sout-all"
406 **************************************************************************/
407 void libvlc_media_add_option( libvlc_media_t
* p_md
,
408 const char * psz_option
)
410 libvlc_media_add_option_flag( p_md
, psz_option
,
411 VLC_INPUT_OPTION_UNIQUE
|VLC_INPUT_OPTION_TRUSTED
);
414 /**************************************************************************
415 * Same as libvlc_media_add_option but with configurable flags.
416 **************************************************************************/
417 void libvlc_media_add_option_flag( libvlc_media_t
* p_md
,
418 const char * ppsz_option
,
421 input_item_AddOption( p_md
->p_input_item
, ppsz_option
, i_flags
);
424 /**************************************************************************
425 * Delete a media descriptor object
426 **************************************************************************/
427 void libvlc_media_release( libvlc_media_t
*p_md
)
434 if( p_md
->i_refcount
> 0 )
437 if( p_md
->p_subitems
)
438 libvlc_media_list_release( p_md
->p_subitems
);
440 uninstall_input_item_observer( p_md
);
441 vlc_gc_decref( p_md
->p_input_item
);
443 vlc_cond_destroy( &p_md
->parsed_cond
);
444 vlc_mutex_destroy( &p_md
->parsed_lock
);
446 /* Construct the event */
447 libvlc_event_t event
;
448 event
.type
= libvlc_MediaFreed
;
449 event
.u
.media_freed
.md
= p_md
;
452 libvlc_event_send( p_md
->p_event_manager
, &event
);
454 libvlc_event_manager_release( p_md
->p_event_manager
);
459 /**************************************************************************
460 * Retain a media descriptor object
461 **************************************************************************/
462 void libvlc_media_retain( libvlc_media_t
*p_md
)
468 /**************************************************************************
469 * Duplicate a media descriptor object
470 **************************************************************************/
472 libvlc_media_duplicate( libvlc_media_t
*p_md_orig
)
474 return libvlc_media_new_from_input_item(
475 p_md_orig
->p_libvlc_instance
, p_md_orig
->p_input_item
);
478 /**************************************************************************
479 * Get mrl from a media descriptor object
480 **************************************************************************/
482 libvlc_media_get_mrl( libvlc_media_t
* p_md
)
485 return input_item_GetURI( p_md
->p_input_item
);
488 /**************************************************************************
489 * Getter for meta information
490 **************************************************************************/
492 char *libvlc_media_get_meta( libvlc_media_t
*p_md
, libvlc_meta_t e_meta
)
494 char *psz_meta
= input_item_GetMeta( p_md
->p_input_item
,
495 libvlc_to_vlc_meta
[e_meta
] );
496 /* Should be integrated in core */
497 if( psz_meta
== NULL
&& e_meta
== libvlc_meta_Title
498 && p_md
->p_input_item
->psz_name
!= NULL
)
499 psz_meta
= strdup( p_md
->p_input_item
->psz_name
);
504 /**************************************************************************
505 * Setter for meta information
506 **************************************************************************/
508 void libvlc_media_set_meta( libvlc_media_t
*p_md
, libvlc_meta_t e_meta
, const char *psz_value
)
511 input_item_SetMeta( p_md
->p_input_item
, libvlc_to_vlc_meta
[e_meta
], psz_value
);
514 int libvlc_media_save_meta( libvlc_media_t
*p_md
)
517 vlc_object_t
*p_obj
= VLC_OBJECT(p_md
->p_libvlc_instance
->p_libvlc_int
);
518 return input_item_WriteMeta( p_obj
, p_md
->p_input_item
) == VLC_SUCCESS
;
521 /**************************************************************************
522 * Getter for state information
523 * Can be error, playing, buffering, NothingSpecial.
524 **************************************************************************/
527 libvlc_media_get_state( libvlc_media_t
*p_md
)
533 /**************************************************************************
534 * Setter for state information (LibVLC Internal)
535 **************************************************************************/
538 libvlc_media_set_state( libvlc_media_t
*p_md
,
539 libvlc_state_t state
)
541 libvlc_event_t event
;
545 /* Construct the event */
546 event
.type
= libvlc_MediaStateChanged
;
547 event
.u
.media_state_changed
.new_state
= state
;
550 libvlc_event_send( p_md
->p_event_manager
, &event
);
553 /**************************************************************************
555 **************************************************************************/
556 libvlc_media_list_t
*
557 libvlc_media_subitems( libvlc_media_t
* p_md
)
559 if( p_md
->p_subitems
)
560 libvlc_media_list_retain( p_md
->p_subitems
);
561 return p_md
->p_subitems
;
564 /**************************************************************************
565 * Getter for statistics information
566 **************************************************************************/
567 int libvlc_media_get_stats( libvlc_media_t
*p_md
,
568 libvlc_media_stats_t
*p_stats
)
570 if( !p_md
->p_input_item
)
573 input_stats_t
*p_itm_stats
= p_md
->p_input_item
->p_stats
;
574 vlc_mutex_lock( &p_itm_stats
->lock
);
575 p_stats
->i_read_bytes
= p_itm_stats
->i_read_bytes
;
576 p_stats
->f_input_bitrate
= p_itm_stats
->f_input_bitrate
;
578 p_stats
->i_demux_read_bytes
= p_itm_stats
->i_demux_read_bytes
;
579 p_stats
->f_demux_bitrate
= p_itm_stats
->f_demux_bitrate
;
580 p_stats
->i_demux_corrupted
= p_itm_stats
->i_demux_corrupted
;
581 p_stats
->i_demux_discontinuity
= p_itm_stats
->i_demux_discontinuity
;
583 p_stats
->i_decoded_video
= p_itm_stats
->i_decoded_video
;
584 p_stats
->i_decoded_audio
= p_itm_stats
->i_decoded_audio
;
586 p_stats
->i_displayed_pictures
= p_itm_stats
->i_displayed_pictures
;
587 p_stats
->i_lost_pictures
= p_itm_stats
->i_lost_pictures
;
589 p_stats
->i_played_abuffers
= p_itm_stats
->i_played_abuffers
;
590 p_stats
->i_lost_abuffers
= p_itm_stats
->i_lost_abuffers
;
592 p_stats
->i_sent_packets
= p_itm_stats
->i_sent_packets
;
593 p_stats
->i_sent_bytes
= p_itm_stats
->i_sent_bytes
;
594 p_stats
->f_send_bitrate
= p_itm_stats
->f_send_bitrate
;
595 vlc_mutex_unlock( &p_itm_stats
->lock
);
599 /**************************************************************************
601 **************************************************************************/
602 libvlc_event_manager_t
*
603 libvlc_media_event_manager( libvlc_media_t
* p_md
)
607 return p_md
->p_event_manager
;
610 /**************************************************************************
611 * Get duration of media object (in ms)
612 **************************************************************************/
614 libvlc_media_get_duration( libvlc_media_t
* p_md
)
618 if( !p_md
->p_input_item
)
620 libvlc_printerr( "No input item" );
624 if (!input_item_IsPreparsed( p_md
->p_input_item
))
627 return from_mtime(input_item_GetDuration( p_md
->p_input_item
));
630 static int media_parse(libvlc_media_t
*media
)
632 libvlc_int_t
*libvlc
= media
->p_libvlc_instance
->p_libvlc_int
;
633 input_item_t
*item
= media
->p_input_item
;
635 /* TODO: Fetch art on need basis. But how not to break compatibility? */
636 libvlc_ArtRequest(libvlc
, item
, META_REQUEST_OPTION_NONE
);
637 return libvlc_MetaRequest(libvlc
, item
, META_REQUEST_OPTION_NONE
);
640 /**************************************************************************
641 * Parse the media and wait.
642 **************************************************************************/
644 libvlc_media_parse(libvlc_media_t
*media
)
646 vlc_mutex_lock(&media
->parsed_lock
);
647 if (!media
->has_asked_preparse
)
649 media
->has_asked_preparse
= true;
650 vlc_mutex_unlock(&media
->parsed_lock
);
652 if (media_parse(media
))
653 /* Parse failed: do not wait! */
655 vlc_mutex_lock(&media
->parsed_lock
);
658 while (!media
->is_parsed
)
659 vlc_cond_wait(&media
->parsed_cond
, &media
->parsed_lock
);
660 vlc_mutex_unlock(&media
->parsed_lock
);
663 /**************************************************************************
664 * Parse the media but do not wait.
665 **************************************************************************/
667 libvlc_media_parse_async(libvlc_media_t
*media
)
671 vlc_mutex_lock(&media
->parsed_lock
);
672 needed
= !media
->has_asked_preparse
;
673 media
->has_asked_preparse
= true;
674 vlc_mutex_unlock(&media
->parsed_lock
);
680 /**************************************************************************
681 * Get parsed status for media object.
682 **************************************************************************/
684 libvlc_media_is_parsed(libvlc_media_t
*media
)
688 vlc_mutex_lock(&media
->parsed_lock
);
689 parsed
= media
->is_parsed
;
690 vlc_mutex_unlock(&media
->parsed_lock
);
694 /**************************************************************************
695 * Sets media descriptor's user_data. user_data is specialized data
696 * accessed by the host application, VLC.framework uses it as a pointer to
697 * an native object that references a libvlc_media_t pointer
698 **************************************************************************/
700 libvlc_media_set_user_data( libvlc_media_t
* p_md
, void * p_new_user_data
)
703 p_md
->p_user_data
= p_new_user_data
;
706 /**************************************************************************
707 * Get media descriptor's user_data. user_data is specialized data
708 * accessed by the host application, VLC.framework uses it as a pointer to
709 * an native object that references a libvlc_media_t pointer
710 **************************************************************************/
712 libvlc_media_get_user_data( libvlc_media_t
* p_md
)
715 return p_md
->p_user_data
;
718 /**************************************************************************
719 * Get media descriptor's elementary streams description
720 **************************************************************************/
722 libvlc_media_get_tracks_info( libvlc_media_t
*p_md
, libvlc_media_track_info_t
** pp_es
)
726 input_item_t
*p_input_item
= p_md
->p_input_item
;
727 vlc_mutex_lock( &p_input_item
->lock
);
729 const int i_es
= p_input_item
->i_es
;
730 *pp_es
= (i_es
> 0) ? malloc( i_es
* sizeof(libvlc_media_track_info_t
) ) : NULL
;
732 if( !*pp_es
) /* no ES, or OOM */
734 vlc_mutex_unlock( &p_input_item
->lock
);
739 for( int i
= 0; i
< i_es
; i
++ )
741 libvlc_media_track_info_t
*p_mes
= *pp_es
+i
;
742 const es_format_t
*p_es
= p_input_item
->es
[i
];
744 p_mes
->i_codec
= p_es
->i_codec
;
745 p_mes
->i_id
= p_es
->i_id
;
747 p_mes
->i_profile
= p_es
->i_profile
;
748 p_mes
->i_level
= p_es
->i_level
;
754 p_mes
->i_type
= libvlc_track_unknown
;
757 p_mes
->i_type
= libvlc_track_video
;
758 p_mes
->u
.video
.i_height
= p_es
->video
.i_height
;
759 p_mes
->u
.video
.i_width
= p_es
->video
.i_width
;
762 p_mes
->i_type
= libvlc_track_audio
;
763 p_mes
->u
.audio
.i_channels
= p_es
->audio
.i_channels
;
764 p_mes
->u
.audio
.i_rate
= p_es
->audio
.i_rate
;
767 p_mes
->i_type
= libvlc_track_text
;
772 vlc_mutex_unlock( &p_input_item
->lock
);
777 libvlc_media_tracks_get( libvlc_media_t
*p_md
, libvlc_media_track_t
*** pp_es
)
781 input_item_t
*p_input_item
= p_md
->p_input_item
;
782 vlc_mutex_lock( &p_input_item
->lock
);
784 const int i_es
= p_input_item
->i_es
;
785 *pp_es
= (i_es
> 0) ? calloc( i_es
, sizeof(**pp_es
) ) : NULL
;
787 if( !*pp_es
) /* no ES, or OOM */
789 vlc_mutex_unlock( &p_input_item
->lock
);
794 for( int i
= 0; i
< i_es
; i
++ )
796 libvlc_media_track_t
*p_mes
= calloc( 1, sizeof(*p_mes
) );
799 p_mes
->audio
= malloc( __MAX(__MAX(sizeof(*p_mes
->audio
),
800 sizeof(*p_mes
->video
)),
801 sizeof(*p_mes
->subtitle
)) );
803 if ( !p_mes
|| !p_mes
->audio
)
805 libvlc_media_tracks_release( *pp_es
, i_es
);
808 vlc_mutex_unlock( &p_input_item
->lock
);
813 const es_format_t
*p_es
= p_input_item
->es
[i
];
815 p_mes
->i_codec
= p_es
->i_codec
;
816 p_mes
->i_original_fourcc
= p_es
->i_original_fourcc
;
817 p_mes
->i_id
= p_es
->i_id
;
819 p_mes
->i_profile
= p_es
->i_profile
;
820 p_mes
->i_level
= p_es
->i_level
;
822 p_mes
->i_bitrate
= p_es
->i_bitrate
;
823 p_mes
->psz_language
= p_es
->psz_language
!= NULL
? strdup(p_es
->psz_language
) : NULL
;
824 p_mes
->psz_description
= p_es
->psz_description
!= NULL
? strdup(p_es
->psz_description
) : NULL
;
830 p_mes
->i_type
= libvlc_track_unknown
;
833 p_mes
->i_type
= libvlc_track_video
;
834 p_mes
->video
->i_height
= p_es
->video
.i_height
;
835 p_mes
->video
->i_width
= p_es
->video
.i_width
;
836 p_mes
->video
->i_sar_num
= p_es
->video
.i_sar_num
;
837 p_mes
->video
->i_sar_den
= p_es
->video
.i_sar_den
;
838 p_mes
->video
->i_frame_rate_num
= p_es
->video
.i_frame_rate
;
839 p_mes
->video
->i_frame_rate_den
= p_es
->video
.i_frame_rate_base
;
842 p_mes
->i_type
= libvlc_track_audio
;
843 p_mes
->audio
->i_channels
= p_es
->audio
.i_channels
;
844 p_mes
->audio
->i_rate
= p_es
->audio
.i_rate
;
847 p_mes
->i_type
= libvlc_track_text
;
848 p_mes
->subtitle
->psz_encoding
= p_es
->subs
.psz_encoding
!= NULL
?
849 strdup(p_es
->subs
.psz_encoding
) : NULL
;
854 vlc_mutex_unlock( &p_input_item
->lock
);
859 /**************************************************************************
860 * Release media descriptor's elementary streams description array
861 **************************************************************************/
862 void libvlc_media_tracks_release( libvlc_media_track_t
**p_tracks
, unsigned i_count
)
864 for( unsigned i
= 0; i
< i_count
; ++i
)
868 free( p_tracks
[i
]->psz_language
);
869 free( p_tracks
[i
]->psz_description
);
870 switch( p_tracks
[i
]->i_type
)
872 case libvlc_track_audio
:
874 case libvlc_track_video
:
876 case libvlc_track_text
:
877 free( p_tracks
[i
]->subtitle
->psz_encoding
);
879 case libvlc_track_unknown
:
883 free( p_tracks
[i
]->audio
);