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 *****************************************************************************/
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>
35 #include <vlc_common.h>
36 #include <vlc_input.h>
38 #include <vlc_playlist.h> /* For the preparser */
41 #include "../src/libvlc.h"
43 #include "libvlc_internal.h"
44 #include "media_internal.h"
46 static const vlc_meta_type_t libvlc_to_vlc_meta
[] =
48 [libvlc_meta_Title
] = vlc_meta_Title
,
49 [libvlc_meta_Artist
] = vlc_meta_Artist
,
50 [libvlc_meta_Genre
] = vlc_meta_Genre
,
51 [libvlc_meta_Copyright
] = vlc_meta_Copyright
,
52 [libvlc_meta_Album
] = vlc_meta_Album
,
53 [libvlc_meta_TrackNumber
] = vlc_meta_TrackNumber
,
54 [libvlc_meta_Description
] = vlc_meta_Description
,
55 [libvlc_meta_Rating
] = vlc_meta_Rating
,
56 [libvlc_meta_Date
] = vlc_meta_Date
,
57 [libvlc_meta_Setting
] = vlc_meta_Setting
,
58 [libvlc_meta_URL
] = vlc_meta_URL
,
59 [libvlc_meta_Language
] = vlc_meta_Language
,
60 [libvlc_meta_NowPlaying
] = vlc_meta_NowPlaying
,
61 [libvlc_meta_Publisher
] = vlc_meta_Publisher
,
62 [libvlc_meta_EncodedBy
] = vlc_meta_EncodedBy
,
63 [libvlc_meta_ArtworkURL
] = vlc_meta_ArtworkURL
,
64 [libvlc_meta_TrackID
] = vlc_meta_TrackID
67 static const libvlc_meta_t vlc_to_libvlc_meta
[] =
69 [vlc_meta_Title
] = libvlc_meta_Title
,
70 [vlc_meta_Artist
] = libvlc_meta_Artist
,
71 [vlc_meta_Genre
] = libvlc_meta_Genre
,
72 [vlc_meta_Copyright
] = libvlc_meta_Copyright
,
73 [vlc_meta_Album
] = libvlc_meta_Album
,
74 [vlc_meta_TrackNumber
] = libvlc_meta_TrackNumber
,
75 [vlc_meta_Description
] = libvlc_meta_Description
,
76 [vlc_meta_Rating
] = libvlc_meta_Rating
,
77 [vlc_meta_Date
] = libvlc_meta_Date
,
78 [vlc_meta_Setting
] = libvlc_meta_Setting
,
79 [vlc_meta_URL
] = libvlc_meta_URL
,
80 [vlc_meta_Language
] = libvlc_meta_Language
,
81 [vlc_meta_NowPlaying
] = libvlc_meta_NowPlaying
,
82 [vlc_meta_Publisher
] = libvlc_meta_Publisher
,
83 [vlc_meta_EncodedBy
] = libvlc_meta_EncodedBy
,
84 [vlc_meta_ArtworkURL
] = libvlc_meta_ArtworkURL
,
85 [vlc_meta_TrackID
] = libvlc_meta_TrackID
88 /**************************************************************************
89 * input_item_subitem_added (Private) (vlc event Callback)
90 **************************************************************************/
91 static void input_item_subitem_added( const vlc_event_t
*p_event
,
94 libvlc_media_t
* p_md
= user_data
;
95 libvlc_media_t
* p_md_child
;
98 p_md_child
= libvlc_media_new_from_input_item(
99 p_md
->p_libvlc_instance
,
100 p_event
->u
.input_item_subitem_added
.p_new_child
);
102 /* Add this to our media list */
103 if( !p_md
->p_subitems
)
105 p_md
->p_subitems
= libvlc_media_list_new( p_md
->p_libvlc_instance
);
106 libvlc_media_list_set_media( p_md
->p_subitems
, p_md
);
108 if( p_md
->p_subitems
)
110 libvlc_media_list_add_media( p_md
->p_subitems
, p_md_child
);
113 /* Construct the event */
114 event
.type
= libvlc_MediaSubItemAdded
;
115 event
.u
.media_subitem_added
.new_child
= p_md_child
;
118 libvlc_event_send( p_md
->p_event_manager
, &event
);
119 libvlc_media_release( p_md_child
);
122 /**************************************************************************
123 * input_item_subitemtree_added (Private) (vlc event Callback)
124 **************************************************************************/
125 static void input_item_subitemtree_added( const vlc_event_t
* p_event
,
128 libvlc_media_t
* p_md
= user_data
;
129 libvlc_event_t event
;
131 /* Construct the event */
132 event
.type
= libvlc_MediaSubItemTreeAdded
;
133 event
.u
.media_subitemtree_added
.item
= p_md
;
136 libvlc_event_send( p_md
->p_event_manager
, &event
);
139 /**************************************************************************
140 * input_item_meta_changed (Private) (vlc event Callback)
141 **************************************************************************/
142 static void input_item_meta_changed( const vlc_event_t
*p_event
,
145 libvlc_media_t
* p_md
= user_data
;
146 libvlc_event_t event
;
148 /* Construct the event */
149 event
.type
= libvlc_MediaMetaChanged
;
150 event
.u
.media_meta_changed
.meta_type
=
151 vlc_to_libvlc_meta
[p_event
->u
.input_item_meta_changed
.meta_type
];
154 libvlc_event_send( p_md
->p_event_manager
, &event
);
157 /**************************************************************************
158 * input_item_duration_changed (Private) (vlc event Callback)
159 **************************************************************************/
160 static void input_item_duration_changed( const vlc_event_t
*p_event
,
163 libvlc_media_t
* p_md
= user_data
;
164 libvlc_event_t event
;
166 /* Construct the event */
167 event
.type
= libvlc_MediaDurationChanged
;
168 event
.u
.media_duration_changed
.new_duration
=
169 from_mtime(p_event
->u
.input_item_duration_changed
.new_duration
);
172 libvlc_event_send( p_md
->p_event_manager
, &event
);
175 /**************************************************************************
176 * input_item_preparsed_changed (Private) (vlc event Callback)
177 **************************************************************************/
178 static void input_item_preparsed_changed(const vlc_event_t
*p_event
,
181 libvlc_media_t
*media
= user_data
;
182 libvlc_event_t event
;
184 /* Eventually notify libvlc_media_parse() */
185 vlc_mutex_lock(&media
->parsed_lock
);
186 media
->is_parsed
= true;
187 vlc_cond_broadcast(&media
->parsed_cond
);
188 vlc_mutex_unlock(&media
->parsed_lock
);
191 /* Construct the event */
192 event
.type
= libvlc_MediaParsedChanged
;
193 event
.u
.media_parsed_changed
.new_status
=
194 p_event
->u
.input_item_preparsed_changed
.new_status
;
197 libvlc_event_send(media
->p_event_manager
, &event
);
200 /**************************************************************************
201 * Install event handler (Private)
202 **************************************************************************/
203 static void install_input_item_observer( libvlc_media_t
*p_md
)
205 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
206 vlc_InputItemSubItemAdded
,
207 input_item_subitem_added
,
209 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
210 vlc_InputItemMetaChanged
,
211 input_item_meta_changed
,
213 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
214 vlc_InputItemDurationChanged
,
215 input_item_duration_changed
,
217 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
218 vlc_InputItemPreparsedChanged
,
219 input_item_preparsed_changed
,
221 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
222 vlc_InputItemSubItemTreeAdded
,
223 input_item_subitemtree_added
,
227 /**************************************************************************
228 * Uninstall event handler (Private)
229 **************************************************************************/
230 static void uninstall_input_item_observer( libvlc_media_t
*p_md
)
232 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
233 vlc_InputItemSubItemAdded
,
234 input_item_subitem_added
,
236 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
237 vlc_InputItemMetaChanged
,
238 input_item_meta_changed
,
240 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
241 vlc_InputItemDurationChanged
,
242 input_item_duration_changed
,
244 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
245 vlc_InputItemPreparsedChanged
,
246 input_item_preparsed_changed
,
248 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
249 vlc_InputItemSubItemTreeAdded
,
250 input_item_subitemtree_added
,
254 /**************************************************************************
255 * Create a new media descriptor object from an input_item
257 * That's the generic constructor
258 **************************************************************************/
259 libvlc_media_t
* libvlc_media_new_from_input_item(
260 libvlc_instance_t
*p_instance
,
261 input_item_t
*p_input_item
)
263 libvlc_media_t
* p_md
;
267 libvlc_printerr( "No input item given" );
271 p_md
= calloc( 1, sizeof(libvlc_media_t
) );
274 libvlc_printerr( "Not enough memory" );
278 p_md
->p_libvlc_instance
= p_instance
;
279 p_md
->p_input_item
= p_input_item
;
280 p_md
->i_refcount
= 1;
282 vlc_cond_init(&p_md
->parsed_cond
);
283 vlc_mutex_init(&p_md
->parsed_lock
);
285 p_md
->state
= libvlc_NothingSpecial
;
287 /* A media descriptor can be a playlist. When you open a playlist
288 * It can give a bunch of item to read. */
289 p_md
->p_subitems
= NULL
;
291 p_md
->p_event_manager
= libvlc_event_manager_new( p_md
, p_instance
);
292 if( unlikely(p_md
->p_event_manager
== NULL
) )
298 libvlc_event_manager_t
*em
= p_md
->p_event_manager
;
299 libvlc_event_manager_register_event_type(em
, libvlc_MediaMetaChanged
);
300 libvlc_event_manager_register_event_type(em
, libvlc_MediaSubItemAdded
);
301 libvlc_event_manager_register_event_type(em
, libvlc_MediaFreed
);
302 libvlc_event_manager_register_event_type(em
, libvlc_MediaDurationChanged
);
303 libvlc_event_manager_register_event_type(em
, libvlc_MediaStateChanged
);
304 libvlc_event_manager_register_event_type(em
, libvlc_MediaParsedChanged
);
305 libvlc_event_manager_register_event_type(em
, libvlc_MediaSubItemTreeAdded
);
307 vlc_gc_incref( p_md
->p_input_item
);
309 install_input_item_observer( p_md
);
314 /**************************************************************************
315 * Create a new media descriptor object
316 **************************************************************************/
317 libvlc_media_t
*libvlc_media_new_location( libvlc_instance_t
*p_instance
,
318 const char * psz_mrl
)
320 input_item_t
* p_input_item
;
321 libvlc_media_t
* p_md
;
323 p_input_item
= input_item_New( psz_mrl
, NULL
);
327 libvlc_printerr( "Not enough memory" );
331 p_md
= libvlc_media_new_from_input_item( p_instance
, p_input_item
);
333 /* The p_input_item is retained in libvlc_media_new_from_input_item */
334 vlc_gc_decref( p_input_item
);
339 libvlc_media_t
*libvlc_media_new_path( libvlc_instance_t
*p_instance
,
342 char *mrl
= vlc_path2uri( path
, NULL
);
343 if( unlikely(mrl
== NULL
) )
345 libvlc_printerr( "Not enough memory" );
349 libvlc_media_t
*m
= libvlc_media_new_location( p_instance
, mrl
);
354 libvlc_media_t
*libvlc_media_new_fd( libvlc_instance_t
*p_instance
, int fd
)
357 snprintf( mrl
, sizeof(mrl
), "fd://%d", fd
);
359 return libvlc_media_new_location( p_instance
, mrl
);
362 /**************************************************************************
363 * Create a new media descriptor object
364 **************************************************************************/
365 libvlc_media_t
* libvlc_media_new_as_node( libvlc_instance_t
*p_instance
,
366 const char * psz_name
)
368 input_item_t
* p_input_item
;
369 libvlc_media_t
* p_md
;
371 p_input_item
= input_item_New( "vlc://nop", psz_name
);
375 libvlc_printerr( "Not enough memory" );
379 p_md
= libvlc_media_new_from_input_item( p_instance
, p_input_item
);
381 p_md
->p_subitems
= libvlc_media_list_new( p_md
->p_libvlc_instance
);
386 /**************************************************************************
387 * Add an option to the media descriptor,
388 * that will be used to determine how the media_player will read the
389 * media. This allow to use VLC advanced reading/streaming
390 * options in a per-media basis
392 * The options are detailled in vlc --long-help, for instance "--sout-all"
393 **************************************************************************/
394 void libvlc_media_add_option( libvlc_media_t
* p_md
,
395 const char * psz_option
)
397 libvlc_media_add_option_flag( p_md
, psz_option
,
398 VLC_INPUT_OPTION_UNIQUE
|VLC_INPUT_OPTION_TRUSTED
);
401 /**************************************************************************
402 * Same as libvlc_media_add_option but with configurable flags.
403 **************************************************************************/
404 void libvlc_media_add_option_flag( libvlc_media_t
* p_md
,
405 const char * ppsz_option
,
408 input_item_AddOption( p_md
->p_input_item
, ppsz_option
, i_flags
);
411 /**************************************************************************
412 * Delete a media descriptor object
413 **************************************************************************/
414 void libvlc_media_release( libvlc_media_t
*p_md
)
421 if( p_md
->i_refcount
> 0 )
424 if( p_md
->p_subitems
)
425 libvlc_media_list_release( p_md
->p_subitems
);
427 uninstall_input_item_observer( p_md
);
428 vlc_gc_decref( p_md
->p_input_item
);
430 vlc_cond_destroy( &p_md
->parsed_cond
);
431 vlc_mutex_destroy( &p_md
->parsed_lock
);
433 /* Construct the event */
434 libvlc_event_t event
;
435 event
.type
= libvlc_MediaFreed
;
436 event
.u
.media_freed
.md
= p_md
;
439 libvlc_event_send( p_md
->p_event_manager
, &event
);
441 libvlc_event_manager_release( p_md
->p_event_manager
);
446 /**************************************************************************
447 * Retain a media descriptor object
448 **************************************************************************/
449 void libvlc_media_retain( libvlc_media_t
*p_md
)
455 /**************************************************************************
456 * Duplicate a media descriptor object
457 **************************************************************************/
459 libvlc_media_duplicate( libvlc_media_t
*p_md_orig
)
461 return libvlc_media_new_from_input_item(
462 p_md_orig
->p_libvlc_instance
, p_md_orig
->p_input_item
);
465 /**************************************************************************
466 * Get mrl from a media descriptor object
467 **************************************************************************/
469 libvlc_media_get_mrl( libvlc_media_t
* p_md
)
472 return input_item_GetURI( p_md
->p_input_item
);
475 /**************************************************************************
476 * Getter for meta information
477 **************************************************************************/
479 char *libvlc_media_get_meta( libvlc_media_t
*p_md
, libvlc_meta_t e_meta
)
481 char *psz_meta
= input_item_GetMeta( p_md
->p_input_item
,
482 libvlc_to_vlc_meta
[e_meta
] );
483 /* Should be integrated in core */
484 if( psz_meta
== NULL
&& e_meta
== libvlc_meta_Title
485 && p_md
->p_input_item
->psz_name
!= NULL
)
486 psz_meta
= strdup( p_md
->p_input_item
->psz_name
);
491 /**************************************************************************
492 * Setter for meta information
493 **************************************************************************/
495 void libvlc_media_set_meta( libvlc_media_t
*p_md
, libvlc_meta_t e_meta
, const char *psz_value
)
498 input_item_SetMeta( p_md
->p_input_item
, libvlc_to_vlc_meta
[e_meta
], psz_value
);
501 int libvlc_media_save_meta( libvlc_media_t
*p_md
)
504 vlc_object_t
*p_obj
= VLC_OBJECT(p_md
->p_libvlc_instance
->p_libvlc_int
);
505 return input_item_WriteMeta( p_obj
, p_md
->p_input_item
) == VLC_SUCCESS
;
508 /**************************************************************************
509 * Getter for state information
510 * Can be error, playing, buffering, NothingSpecial.
511 **************************************************************************/
514 libvlc_media_get_state( libvlc_media_t
*p_md
)
520 /**************************************************************************
521 * Setter for state information (LibVLC Internal)
522 **************************************************************************/
525 libvlc_media_set_state( libvlc_media_t
*p_md
,
526 libvlc_state_t state
)
528 libvlc_event_t event
;
532 /* Construct the event */
533 event
.type
= libvlc_MediaStateChanged
;
534 event
.u
.media_state_changed
.new_state
= state
;
537 libvlc_event_send( p_md
->p_event_manager
, &event
);
540 /**************************************************************************
542 **************************************************************************/
543 libvlc_media_list_t
*
544 libvlc_media_subitems( libvlc_media_t
* p_md
)
546 if( p_md
->p_subitems
)
547 libvlc_media_list_retain( p_md
->p_subitems
);
548 return p_md
->p_subitems
;
551 /**************************************************************************
552 * Getter for statistics information
553 **************************************************************************/
554 int libvlc_media_get_stats( libvlc_media_t
*p_md
,
555 libvlc_media_stats_t
*p_stats
)
557 if( !p_md
->p_input_item
)
560 input_stats_t
*p_itm_stats
= p_md
->p_input_item
->p_stats
;
561 vlc_mutex_lock( &p_itm_stats
->lock
);
562 p_stats
->i_read_bytes
= p_itm_stats
->i_read_bytes
;
563 p_stats
->f_input_bitrate
= p_itm_stats
->f_input_bitrate
;
565 p_stats
->i_demux_read_bytes
= p_itm_stats
->i_demux_read_bytes
;
566 p_stats
->f_demux_bitrate
= p_itm_stats
->f_demux_bitrate
;
567 p_stats
->i_demux_corrupted
= p_itm_stats
->i_demux_corrupted
;
568 p_stats
->i_demux_discontinuity
= p_itm_stats
->i_demux_discontinuity
;
570 p_stats
->i_decoded_video
= p_itm_stats
->i_decoded_video
;
571 p_stats
->i_decoded_audio
= p_itm_stats
->i_decoded_audio
;
573 p_stats
->i_displayed_pictures
= p_itm_stats
->i_displayed_pictures
;
574 p_stats
->i_lost_pictures
= p_itm_stats
->i_lost_pictures
;
576 p_stats
->i_played_abuffers
= p_itm_stats
->i_played_abuffers
;
577 p_stats
->i_lost_abuffers
= p_itm_stats
->i_lost_abuffers
;
579 p_stats
->i_sent_packets
= p_itm_stats
->i_sent_packets
;
580 p_stats
->i_sent_bytes
= p_itm_stats
->i_sent_bytes
;
581 p_stats
->f_send_bitrate
= p_itm_stats
->f_send_bitrate
;
582 vlc_mutex_unlock( &p_itm_stats
->lock
);
586 /**************************************************************************
588 **************************************************************************/
589 libvlc_event_manager_t
*
590 libvlc_media_event_manager( libvlc_media_t
* p_md
)
594 return p_md
->p_event_manager
;
597 /**************************************************************************
598 * Get duration of media object (in ms)
599 **************************************************************************/
601 libvlc_media_get_duration( libvlc_media_t
* p_md
)
605 if( !p_md
->p_input_item
)
607 libvlc_printerr( "No input item" );
611 if (!input_item_IsPreparsed( p_md
->p_input_item
))
614 return from_mtime(input_item_GetDuration( p_md
->p_input_item
));
617 static int media_parse(libvlc_media_t
*media
)
619 /* TODO: fetcher and parser independent of playlist */
620 #warning FIXME: remove pl_Get
621 playlist_t
*playlist
= pl_Get(media
->p_libvlc_instance
->p_libvlc_int
);
623 /* TODO: Fetch art on need basis. But how not to break compatibility? */
624 playlist_AskForArtEnqueue(playlist
, media
->p_input_item
);
625 return playlist_PreparseEnqueue(playlist
, media
->p_input_item
);
628 /**************************************************************************
629 * Parse the media and wait.
630 **************************************************************************/
632 libvlc_media_parse(libvlc_media_t
*media
)
634 vlc_mutex_lock(&media
->parsed_lock
);
635 if (!media
->has_asked_preparse
)
637 media
->has_asked_preparse
= true;
638 vlc_mutex_unlock(&media
->parsed_lock
);
640 if (media_parse(media
))
641 /* Parse failed: do not wait! */
643 vlc_mutex_lock(&media
->parsed_lock
);
646 while (!media
->is_parsed
)
647 vlc_cond_wait(&media
->parsed_cond
, &media
->parsed_lock
);
648 vlc_mutex_unlock(&media
->parsed_lock
);
651 /**************************************************************************
652 * Parse the media but do not wait.
653 **************************************************************************/
655 libvlc_media_parse_async(libvlc_media_t
*media
)
659 vlc_mutex_lock(&media
->parsed_lock
);
660 needed
= !media
->has_asked_preparse
;
661 media
->has_asked_preparse
= true;
662 vlc_mutex_unlock(&media
->parsed_lock
);
668 /**************************************************************************
669 * Get parsed status for media object.
670 **************************************************************************/
672 libvlc_media_is_parsed(libvlc_media_t
*media
)
676 vlc_mutex_lock(&media
->parsed_lock
);
677 parsed
= media
->is_parsed
;
678 vlc_mutex_unlock(&media
->parsed_lock
);
682 /**************************************************************************
683 * Sets media descriptor's user_data. user_data is specialized data
684 * accessed by the host application, VLC.framework uses it as a pointer to
685 * an native object that references a libvlc_media_t pointer
686 **************************************************************************/
688 libvlc_media_set_user_data( libvlc_media_t
* p_md
, void * p_new_user_data
)
691 p_md
->p_user_data
= p_new_user_data
;
694 /**************************************************************************
695 * Get 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_get_user_data( libvlc_media_t
* p_md
)
703 return p_md
->p_user_data
;
706 /**************************************************************************
707 * Get media descriptor's elementary streams description
708 **************************************************************************/
710 libvlc_media_get_tracks_info( libvlc_media_t
*p_md
, libvlc_media_track_info_t
** pp_es
)
714 input_item_t
*p_input_item
= p_md
->p_input_item
;
715 vlc_mutex_lock( &p_input_item
->lock
);
717 const int i_es
= p_input_item
->i_es
;
718 *pp_es
= (i_es
> 0) ? malloc( i_es
* sizeof(libvlc_media_track_info_t
) ) : NULL
;
720 if( !*pp_es
) /* no ES, or OOM */
722 vlc_mutex_unlock( &p_input_item
->lock
);
727 for( int i
= 0; i
< i_es
; i
++ )
729 libvlc_media_track_info_t
*p_mes
= *pp_es
+i
;
730 const es_format_t
*p_es
= p_input_item
->es
[i
];
732 p_mes
->i_codec
= p_es
->i_codec
;
733 p_mes
->i_id
= p_es
->i_id
;
735 p_mes
->i_profile
= p_es
->i_profile
;
736 p_mes
->i_level
= p_es
->i_level
;
742 p_mes
->i_type
= libvlc_track_unknown
;
745 p_mes
->i_type
= libvlc_track_video
;
746 p_mes
->u
.video
.i_height
= p_es
->video
.i_height
;
747 p_mes
->u
.video
.i_width
= p_es
->video
.i_width
;
750 p_mes
->i_type
= libvlc_track_audio
;
751 p_mes
->u
.audio
.i_channels
= p_es
->audio
.i_channels
;
752 p_mes
->u
.audio
.i_rate
= p_es
->audio
.i_rate
;
755 p_mes
->i_type
= libvlc_track_text
;
760 vlc_mutex_unlock( &p_input_item
->lock
);
765 libvlc_media_tracks_get( libvlc_media_t
*p_md
, libvlc_media_track_t
*** pp_es
)
769 input_item_t
*p_input_item
= p_md
->p_input_item
;
770 vlc_mutex_lock( &p_input_item
->lock
);
772 const int i_es
= p_input_item
->i_es
;
773 *pp_es
= (i_es
> 0) ? calloc( i_es
, sizeof(**pp_es
) ) : NULL
;
775 if( !*pp_es
) /* no ES, or OOM */
777 vlc_mutex_unlock( &p_input_item
->lock
);
782 for( int i
= 0; i
< i_es
; i
++ )
784 libvlc_media_track_t
*p_mes
= calloc( 1, sizeof(*p_mes
) );
787 p_mes
->audio
= malloc( __MAX(__MAX(sizeof(*p_mes
->audio
),
788 sizeof(*p_mes
->video
)),
789 sizeof(*p_mes
->subtitle
)) );
791 if ( !p_mes
|| !p_mes
->audio
)
793 libvlc_media_tracks_release( *pp_es
, i_es
);
796 vlc_mutex_unlock( &p_input_item
->lock
);
801 const es_format_t
*p_es
= p_input_item
->es
[i
];
803 p_mes
->i_codec
= p_es
->i_codec
;
804 p_mes
->i_original_fourcc
= p_es
->i_original_fourcc
;
805 p_mes
->i_id
= p_es
->i_id
;
807 p_mes
->i_profile
= p_es
->i_profile
;
808 p_mes
->i_level
= p_es
->i_level
;
810 p_mes
->i_bitrate
= p_es
->i_bitrate
;
811 p_mes
->psz_language
= p_es
->psz_language
!= NULL
? strdup(p_es
->psz_language
) : NULL
;
812 p_mes
->psz_description
= p_es
->psz_description
!= NULL
? strdup(p_es
->psz_description
) : NULL
;
818 p_mes
->i_type
= libvlc_track_unknown
;
821 p_mes
->i_type
= libvlc_track_video
;
822 p_mes
->video
->i_height
= p_es
->video
.i_height
;
823 p_mes
->video
->i_width
= p_es
->video
.i_width
;
824 p_mes
->video
->i_sar_num
= p_es
->video
.i_sar_num
;
825 p_mes
->video
->i_sar_den
= p_es
->video
.i_sar_den
;
826 p_mes
->video
->i_frame_rate_num
= p_es
->video
.i_frame_rate
;
827 p_mes
->video
->i_frame_rate_den
= p_es
->video
.i_frame_rate_base
;
830 p_mes
->i_type
= libvlc_track_audio
;
831 p_mes
->audio
->i_channels
= p_es
->audio
.i_channels
;
832 p_mes
->audio
->i_rate
= p_es
->audio
.i_rate
;
835 p_mes
->i_type
= libvlc_track_text
;
836 p_mes
->subtitle
->psz_encoding
= p_es
->subs
.psz_encoding
!= NULL
?
837 strdup(p_es
->subs
.psz_encoding
) : NULL
;
842 vlc_mutex_unlock( &p_input_item
->lock
);
847 /**************************************************************************
848 * Release media descriptor's elementary streams description array
849 **************************************************************************/
850 void libvlc_media_tracks_release( libvlc_media_track_t
**p_tracks
, unsigned i_count
)
852 for( unsigned i
= 0; i
< i_count
; ++i
)
856 free( p_tracks
[i
]->psz_language
);
857 free( p_tracks
[i
]->psz_description
);
858 switch( p_tracks
[i
]->i_type
)
860 case libvlc_track_audio
:
862 case libvlc_track_video
:
864 case libvlc_track_text
:
865 free( p_tracks
[i
]->subtitle
->psz_encoding
);
867 case libvlc_track_unknown
:
871 free( p_tracks
[i
]->audio
);