input: add input_SetProgramId
[vlc.git] / lib / media_player.c
blob9341c49a6874025fdca0beb8db9b9a1176501577
1 /*****************************************************************************
2 * media_player.c: Libvlc API Media Instance management functions
3 *****************************************************************************
4 * Copyright (C) 2005-2015 VLC authors and VideoLAN
6 * Authors: Clément Stenac <zorglub@videolan.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <assert.h>
29 #include <vlc/libvlc.h>
30 #include <vlc/libvlc_renderer_discoverer.h>
31 #include <vlc/libvlc_picture.h>
32 #include <vlc/libvlc_media.h>
33 #include <vlc/libvlc_events.h>
35 #include <vlc_demux.h>
36 #include <vlc_vout.h>
37 #include <vlc_aout.h>
38 #include <vlc_actions.h>
40 #include "libvlc_internal.h"
41 #include "media_internal.h" // libvlc_media_set_state()
42 #include "media_player_internal.h"
43 #include "renderer_discoverer_internal.h"
45 #define ES_INIT (-2) /* -1 is reserved for ES deselect */
47 static int
48 snapshot_was_taken( vlc_object_t *p_this, char const *psz_cmd,
49 vlc_value_t oldval, vlc_value_t newval, void *p_data );
51 static void media_attach_preparsed_event(libvlc_media_t *);
52 static void media_detach_preparsed_event(libvlc_media_t *);
54 static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi );
56 // player callbacks
58 static void
59 on_current_media_changed(vlc_player_t *player, input_item_t *new_media,
60 void *data)
62 (void) player;
64 libvlc_media_player_t *mp = data;
66 libvlc_media_t *libmedia;
67 if (new_media != NULL)
69 libmedia = new_media->libvlc_owner;
70 assert(libmedia != NULL);
72 else
73 libmedia = NULL;
75 libvlc_event_t event;
76 event.type = libvlc_MediaPlayerMediaChanged;
77 event.u.media_player_media_changed.new_media = libmedia;
78 libvlc_event_send(&mp->event_manager, &event);
81 static void
82 on_state_changed(vlc_player_t *player, enum vlc_player_state new_state,
83 void *data)
85 (void) player;
87 libvlc_media_player_t *mp = data;
89 libvlc_event_t event;
90 switch (new_state) {
91 case VLC_PLAYER_STATE_STOPPED:
92 event.type = libvlc_MediaPlayerStopped;
93 break;
94 case VLC_PLAYER_STATE_STOPPING:
95 event.type = libvlc_MediaPlayerEndReached;
96 break;
97 case VLC_PLAYER_STATE_STARTED:
98 event.type = libvlc_MediaPlayerOpening;
99 break;
100 case VLC_PLAYER_STATE_PLAYING:
101 event.type = libvlc_MediaPlayerPlaying;
102 break;
103 case VLC_PLAYER_STATE_PAUSED:
104 event.type = libvlc_MediaPlayerPaused;
105 break;
106 default:
107 vlc_assert_unreachable();
110 libvlc_event_send(&mp->event_manager, &event);
113 static void
114 on_error_changed(vlc_player_t *player, enum vlc_player_error error, void *data)
116 (void) player;
118 libvlc_media_player_t *mp = data;
120 libvlc_event_t event;
121 switch (error) {
122 case VLC_PLAYER_ERROR_NONE:
123 event.type = libvlc_MediaPlayerNothingSpecial;
124 break;
125 case VLC_PLAYER_ERROR_GENERIC:
126 event.type = libvlc_MediaPlayerEncounteredError;
127 break;
128 default:
129 vlc_assert_unreachable();
132 libvlc_event_send(&mp->event_manager, &event);
135 static void
136 on_buffering_changed(vlc_player_t *player, float new_buffering, void *data)
138 (void) player;
140 libvlc_media_player_t *mp = data;
142 libvlc_event_t event;
143 event.type = libvlc_MediaPlayerBuffering;
144 event.u.media_player_buffering.new_cache = 100 * new_buffering;
146 libvlc_event_send(&mp->event_manager, &event);
149 static void
150 on_capabilities_changed(vlc_player_t *player, int old_caps, int new_caps, void *data)
152 (void) player;
154 libvlc_media_player_t *mp = data;
156 libvlc_event_t event;
158 bool old_seekable = old_caps & VLC_PLAYER_CAP_SEEK;
159 bool new_seekable = new_caps & VLC_PLAYER_CAP_SEEK;
160 if (new_seekable != old_seekable)
162 event.type = libvlc_MediaPlayerSeekableChanged;
163 event.u.media_player_seekable_changed.new_seekable = new_seekable;
164 libvlc_event_send(&mp->event_manager, &event);
167 bool old_pauseable = old_caps & VLC_PLAYER_CAP_PAUSE;
168 bool new_pauseable = new_caps & VLC_PLAYER_CAP_PAUSE;
169 if (new_pauseable != old_pauseable)
171 event.type = libvlc_MediaPlayerPausableChanged;
172 event.u.media_player_pausable_changed.new_pausable = new_pauseable;
173 libvlc_event_send(&mp->event_manager, &event);
177 static void
178 on_position_changed(vlc_player_t *player, vlc_tick_t new_time, float new_pos,
179 void *data)
181 (void) player;
183 libvlc_media_player_t *mp = data;
185 libvlc_event_t event;
187 event.type = libvlc_MediaPlayerPositionChanged;
188 event.u.media_player_position_changed.new_position = new_pos;
189 libvlc_event_send(&mp->event_manager, &event);
191 event.type = libvlc_MediaPlayerTimeChanged;
192 event.u.media_player_time_changed.new_time = MS_FROM_VLC_TICK(new_time);
193 libvlc_event_send(&mp->event_manager, &event);
196 static void
197 on_length_changed(vlc_player_t *player, vlc_tick_t new_length, void *data)
199 (void) player;
201 libvlc_media_player_t *mp = data;
203 libvlc_event_t event;
205 event.type = libvlc_MediaPlayerLengthChanged;
206 event.u.media_player_length_changed.new_length =
207 MS_FROM_VLC_TICK(new_length);
209 libvlc_event_send(&mp->event_manager, &event);
212 static int
213 track_type_from_cat(enum es_format_category_e cat)
215 switch (cat)
217 case VIDEO_ES:
218 return libvlc_track_video;
219 case AUDIO_ES:
220 return libvlc_track_audio;
221 case SPU_ES:
222 return libvlc_track_text;
223 default:
224 return libvlc_track_unknown;
228 static void
229 on_track_list_changed(vlc_player_t *player, enum vlc_player_list_action action,
230 const struct vlc_player_track *track, void *data)
232 (void) player;
234 libvlc_media_player_t *mp = data;
236 libvlc_event_t event;
237 switch (action)
239 case VLC_PLAYER_LIST_ADDED:
240 event.type = libvlc_MediaPlayerESAdded; break;
241 case VLC_PLAYER_LIST_REMOVED:
242 event.type = libvlc_MediaPlayerESDeleted; break;
243 case VLC_PLAYER_LIST_UPDATED:
244 event.type = libvlc_MediaPlayerESUpdated; break;
247 event.u.media_player_es_changed.i_type =
248 track_type_from_cat(track->fmt.i_cat);
249 event.u.media_player_es_changed.i_id = vlc_es_id_GetInputId(track->es_id);
250 event.u.media_player_es_changed.psz_id = vlc_es_id_GetStrId(track->es_id);
252 libvlc_event_send(&mp->event_manager, &event);
255 static void
256 on_track_selection_changed(vlc_player_t *player, vlc_es_id_t *unselected_id,
257 vlc_es_id_t *selected_id, void *data)
259 (void) player;
260 (void) unselected_id;
262 libvlc_media_player_t *mp = data;
264 libvlc_event_t event;
265 event.type = libvlc_MediaPlayerESSelected;
267 if (unselected_id)
269 enum es_format_category_e cat = vlc_es_id_GetCat(unselected_id);
270 event.u.media_player_es_selection_changed.i_type = track_type_from_cat(cat);
272 if (selected_id)
274 enum es_format_category_e cat = vlc_es_id_GetCat(selected_id);
275 event.u.media_player_es_selection_changed.i_type = track_type_from_cat(cat);
278 event.u.media_player_es_selection_changed.psz_unselected_id =
279 unselected_id ? vlc_es_id_GetStrId(unselected_id) : NULL;
281 event.u.media_player_es_selection_changed.psz_selected_id =
282 selected_id ? vlc_es_id_GetStrId(selected_id) : NULL;
284 libvlc_event_send(&mp->event_manager, &event);
287 static void
288 on_program_list_changed(vlc_player_t *player,
289 enum vlc_player_list_action action,
290 const struct vlc_player_program *prgm, void* data)
292 (void) player;
293 libvlc_media_player_t *mp = data;
295 libvlc_event_t event;
296 switch (action)
298 case VLC_PLAYER_LIST_ADDED:
299 event.type = libvlc_MediaPlayerProgramAdded;
300 break;
301 case VLC_PLAYER_LIST_REMOVED:
302 event.type = libvlc_MediaPlayerProgramDeleted;
303 break;
304 case VLC_PLAYER_LIST_UPDATED:
305 event.type = libvlc_MediaPlayerProgramUpdated;
306 break;
309 event.u.media_player_program_changed.i_id = prgm->group_id;
310 libvlc_event_send(&mp->event_manager, &event);
313 static void
314 on_program_selection_changed(vlc_player_t *player, int unselected_id,
315 int selected_id, void *data)
317 (void) player;
318 libvlc_media_player_t *mp = data;
320 libvlc_event_t event;
321 event.type = libvlc_MediaPlayerProgramSelected;
322 event.u.media_player_program_selection_changed.i_unselected_id = unselected_id;
323 event.u.media_player_program_selection_changed.i_selected_id = selected_id;
325 libvlc_event_send(&mp->event_manager, &event);
328 static void
329 on_titles_changed(vlc_player_t *player,
330 vlc_player_title_list *titles, void *data)
332 (void) player;
333 (void) titles;
335 libvlc_media_player_t *mp = data;
337 libvlc_event_t event;
338 event.type = libvlc_MediaPlayerTitleListChanged;
340 libvlc_event_send(&mp->event_manager, &event);
343 static void
344 on_title_selection_changed(vlc_player_t *player,
345 const struct vlc_player_title *new_title,
346 size_t new_idx, void *data)
348 (void) player;
349 (void) new_title;
351 libvlc_media_player_t *mp = data;
353 const libvlc_title_description_t libtitle = {
354 .i_duration = MS_FROM_VLC_TICK(new_title->length),
355 .psz_name = (char *) new_title->name,
356 .i_flags = new_title->flags,
359 libvlc_event_t event;
360 event.type = libvlc_MediaPlayerTitleSelectionChanged;
361 event.u.media_player_title_selection_changed.title = &libtitle;
362 event.u.media_player_title_selection_changed.index = new_idx;
364 libvlc_event_send(&mp->event_manager, &event);
367 static void
368 on_chapter_selection_changed(vlc_player_t *player,
369 const struct vlc_player_title *title,
370 size_t title_idx,
371 const struct vlc_player_chapter *new_chapter,
372 size_t new_chapter_idx,
373 void *data)
375 (void) player;
376 (void) title;
377 (void) title_idx;
378 (void) new_chapter;
380 libvlc_media_player_t *mp = data;
382 libvlc_event_t event;
383 event.type = libvlc_MediaPlayerChapterChanged;
384 event.u.media_player_chapter_changed.new_chapter = new_chapter_idx;
386 libvlc_event_send(&mp->event_manager, &event);
389 static void
390 on_media_subitems_changed(vlc_player_t *player, input_item_t *media,
391 input_item_node_t *new_subitems, void *data)
393 (void) player;
395 libvlc_media_player_t *mp = data;
397 input_item_t *current = mp->p_md ? mp->p_md->p_input_item : NULL;
398 if (media == current)
399 libvlc_media_add_subtree(mp->p_md, new_subitems);
402 static void
403 on_cork_changed(vlc_player_t *player, unsigned cork_count, void *data)
405 (void) player;
407 libvlc_media_player_t *mp = data;
409 libvlc_event_t event;
410 event.type = cork_count ? libvlc_MediaPlayerCorked
411 : libvlc_MediaPlayerUncorked;
413 libvlc_event_send(&mp->event_manager, &event);
416 static void
417 on_vout_changed(vlc_player_t *player, enum vlc_player_vout_action action,
418 vout_thread_t *vout, enum vlc_vout_order order,
419 vlc_es_id_t *es_id, void *data)
421 (void) action;
422 (void) vout;
423 (void) order;
425 if (vlc_es_id_GetCat(es_id) != VIDEO_ES)
426 return;
428 libvlc_media_player_t *mp = data;
430 size_t count;
431 vout_thread_t **vouts = vlc_player_vout_HoldAll(player, &count);
432 if (!vouts)
433 return;
434 for (size_t i = 0; i < count; ++i)
435 vout_Release(vouts[i]);
436 free(vouts);
438 libvlc_event_t event;
439 event.type = libvlc_MediaPlayerVout;
440 event.u.media_player_vout.new_count = count;
442 libvlc_event_send(&mp->event_manager, &event);
445 // player aout callbacks
447 static void
448 on_volume_changed(audio_output_t *aout, float new_volume, void *data)
450 (void) aout;
452 libvlc_media_player_t *mp = data;
454 libvlc_event_t event;
455 event.type = libvlc_MediaPlayerAudioVolume;
456 event.u.media_player_audio_volume.volume = new_volume;
458 libvlc_event_send(&mp->event_manager, &event);
461 static void
462 on_mute_changed(audio_output_t *aout, bool new_muted, void *data)
464 (void) aout;
466 libvlc_media_player_t *mp = data;
468 libvlc_event_t event;
469 event.type = new_muted ? libvlc_MediaPlayerMuted
470 : libvlc_MediaPlayerUnmuted;
472 libvlc_event_send(&mp->event_manager, &event);
475 static void
476 on_audio_device_changed(audio_output_t *aout, const char *device, void *data)
478 (void) aout;
480 libvlc_media_player_t *mp = data;
482 libvlc_event_t event;
483 event.type = libvlc_MediaPlayerAudioDevice;
484 event.u.media_player_audio_device.device = device;
486 libvlc_event_send(&mp->event_manager, &event);
489 static const struct vlc_player_cbs vlc_player_cbs = {
490 .on_current_media_changed = on_current_media_changed,
491 .on_state_changed = on_state_changed,
492 .on_error_changed = on_error_changed,
493 .on_buffering_changed = on_buffering_changed,
494 .on_capabilities_changed = on_capabilities_changed,
495 .on_position_changed = on_position_changed,
496 .on_length_changed = on_length_changed,
497 .on_track_list_changed = on_track_list_changed,
498 .on_track_selection_changed = on_track_selection_changed,
499 .on_program_list_changed = on_program_list_changed,
500 .on_program_selection_changed = on_program_selection_changed,
501 .on_titles_changed = on_titles_changed,
502 .on_title_selection_changed = on_title_selection_changed,
503 .on_chapter_selection_changed = on_chapter_selection_changed,
504 .on_media_subitems_changed = on_media_subitems_changed,
505 .on_cork_changed = on_cork_changed,
506 .on_vout_changed = on_vout_changed,
509 static const struct vlc_player_aout_cbs vlc_player_aout_cbs = {
510 .on_volume_changed = on_volume_changed,
511 .on_mute_changed = on_mute_changed,
512 .on_device_changed = on_audio_device_changed,
515 /**************************************************************************
516 * Snapshot Taken Event.
518 * FIXME: This snapshot API interface makes no sense in media_player.
519 *************************************************************************/
520 static int snapshot_was_taken(vlc_object_t *p_this, char const *psz_cmd,
521 vlc_value_t oldval, vlc_value_t newval, void *p_data )
523 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_this);
525 libvlc_media_player_t *mp = p_data;
526 libvlc_event_t event;
527 event.type = libvlc_MediaPlayerSnapshotTaken;
528 event.u.media_player_snapshot_taken.psz_filename = newval.psz_string;
529 libvlc_event_send(&mp->event_manager, &event);
531 return VLC_SUCCESS;
534 static void input_item_preparsed_changed( const vlc_event_t *p_event,
535 void * user_data )
537 libvlc_media_t *p_md = user_data;
538 if( p_event->u.input_item_preparsed_changed.new_status & ITEM_PREPARSED )
540 /* Send the event */
541 libvlc_event_t event;
542 event.type = libvlc_MediaParsedChanged;
543 event.u.media_parsed_changed.new_status = libvlc_media_parsed_status_done;
544 libvlc_event_send( &p_md->event_manager, &event );
548 static void media_attach_preparsed_event( libvlc_media_t *p_md )
550 vlc_event_attach( &p_md->p_input_item->event_manager,
551 vlc_InputItemPreparsedChanged,
552 input_item_preparsed_changed, p_md );
555 static void media_detach_preparsed_event( libvlc_media_t *p_md )
557 vlc_event_detach( &p_md->p_input_item->event_manager,
558 vlc_InputItemPreparsedChanged,
559 input_item_preparsed_changed,
560 p_md );
563 /**************************************************************************
564 * Create a Media Instance object.
566 * Refcount strategy:
567 * - All items created by _new start with a refcount set to 1.
568 * - Accessor _release decrease the refcount by 1, if after that
569 * operation the refcount is 0, the object is destroyed.
570 * - Accessor _retain increase the refcount by 1 (XXX: to implement)
572 * Object locking strategy:
573 * - No lock held while in constructor.
574 * - When accessing any member variable this lock is held. (XXX who locks?)
575 * - When attempting to destroy the object the lock is also held.
576 **************************************************************************/
577 libvlc_media_player_t *
578 libvlc_media_player_new( libvlc_instance_t *instance )
580 libvlc_media_player_t * mp;
582 assert(instance);
584 mp = vlc_object_create (instance->p_libvlc_int, sizeof(*mp));
585 if (unlikely(mp == NULL))
587 libvlc_printerr("Not enough memory");
588 return NULL;
591 /* Input */
592 var_Create (mp, "rate", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT);
593 var_Create (mp, "sout", VLC_VAR_STRING);
594 var_Create (mp, "demux-filter", VLC_VAR_STRING);
596 /* Video */
597 var_Create (mp, "vout", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
598 var_Create (mp, "window", VLC_VAR_STRING);
599 var_Create (mp, "gl", VLC_VAR_STRING);
600 var_Create (mp, "gles2", VLC_VAR_STRING);
601 var_Create (mp, "vmem-lock", VLC_VAR_ADDRESS);
602 var_Create (mp, "vmem-unlock", VLC_VAR_ADDRESS);
603 var_Create (mp, "vmem-display", VLC_VAR_ADDRESS);
604 var_Create (mp, "vmem-data", VLC_VAR_ADDRESS);
605 var_Create (mp, "vmem-setup", VLC_VAR_ADDRESS);
606 var_Create (mp, "vmem-cleanup", VLC_VAR_ADDRESS);
607 var_Create (mp, "vmem-chroma", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
608 var_Create (mp, "vmem-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
609 var_Create (mp, "vmem-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
610 var_Create (mp, "vmem-pitch", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
612 var_Create (mp, "vout-cb-type", VLC_VAR_INTEGER );
613 var_Create( mp, "vout-cb-opaque", VLC_VAR_ADDRESS );
614 var_Create( mp, "vout-cb-setup", VLC_VAR_ADDRESS );
615 var_Create( mp, "vout-cb-cleanup", VLC_VAR_ADDRESS );
616 var_Create( mp, "vout-cb-resize-cb", VLC_VAR_ADDRESS );
617 var_Create( mp, "vout-cb-update-output", VLC_VAR_ADDRESS );
618 var_Create( mp, "vout-cb-swap", VLC_VAR_ADDRESS );
619 var_Create( mp, "vout-cb-get-proc-address", VLC_VAR_ADDRESS );
620 var_Create( mp, "vout-cb-make-current", VLC_VAR_ADDRESS );
621 var_Create( mp, "vout-cb-metadata", VLC_VAR_ADDRESS );
622 var_Create( mp, "vout-cb-select-plane", VLC_VAR_ADDRESS );
624 var_Create (mp, "dec-dev", VLC_VAR_STRING);
625 var_Create (mp, "drawable-xid", VLC_VAR_INTEGER);
626 #if defined (_WIN32) || defined (__OS2__)
627 var_Create (mp, "drawable-hwnd", VLC_VAR_INTEGER);
628 #endif
629 #ifdef __APPLE__
630 var_Create (mp, "drawable-nsobject", VLC_VAR_ADDRESS);
631 #endif
632 #ifdef __ANDROID__
633 var_Create (mp, "drawable-androidwindow", VLC_VAR_ADDRESS);
634 #endif
636 var_Create (mp, "keyboard-events", VLC_VAR_BOOL);
637 var_SetBool (mp, "keyboard-events", true);
638 var_Create (mp, "mouse-events", VLC_VAR_BOOL);
639 var_SetBool (mp, "mouse-events", true);
641 var_Create (mp, "fullscreen", VLC_VAR_BOOL);
642 var_Create (mp, "autoscale", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
643 var_Create (mp, "zoom", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
644 var_Create (mp, "aspect-ratio", VLC_VAR_STRING);
645 var_Create (mp, "crop", VLC_VAR_STRING);
646 var_Create (mp, "deinterlace", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
647 var_Create (mp, "deinterlace-mode", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
649 var_Create (mp, "vbi-page", VLC_VAR_INTEGER);
650 var_SetInteger (mp, "vbi-page", 100);
652 var_Create (mp, "video-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
653 var_Create (mp, "sub-source", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
654 var_Create (mp, "sub-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
656 var_Create (mp, "marq-marquee", VLC_VAR_STRING);
657 var_Create (mp, "marq-color", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
658 var_Create (mp, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
659 var_Create (mp, "marq-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
660 var_Create (mp, "marq-refresh", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
661 var_Create (mp, "marq-size", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
662 var_Create (mp, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
663 var_Create (mp, "marq-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
664 var_Create (mp, "marq-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
666 var_Create (mp, "logo-file", VLC_VAR_STRING);
667 var_Create (mp, "logo-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
668 var_Create (mp, "logo-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
669 var_Create (mp, "logo-delay", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
670 var_Create (mp, "logo-repeat", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
671 var_Create (mp, "logo-opacity", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
672 var_Create (mp, "logo-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
674 var_Create (mp, "contrast", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
675 var_Create (mp, "brightness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
676 var_Create (mp, "hue", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
677 var_Create (mp, "saturation", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
678 var_Create (mp, "gamma", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
680 /* Audio */
681 var_Create (mp, "aout", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
682 var_Create (mp, "audio-device", VLC_VAR_STRING);
683 var_Create (mp, "mute", VLC_VAR_BOOL);
684 var_Create (mp, "volume", VLC_VAR_FLOAT);
685 var_Create (mp, "corks", VLC_VAR_INTEGER);
686 var_Create (mp, "audio-filter", VLC_VAR_STRING);
687 var_Create (mp, "role", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
688 var_Create (mp, "amem-data", VLC_VAR_ADDRESS);
689 var_Create (mp, "amem-setup", VLC_VAR_ADDRESS);
690 var_Create (mp, "amem-cleanup", VLC_VAR_ADDRESS);
691 var_Create (mp, "amem-play", VLC_VAR_ADDRESS);
692 var_Create (mp, "amem-pause", VLC_VAR_ADDRESS);
693 var_Create (mp, "amem-resume", VLC_VAR_ADDRESS);
694 var_Create (mp, "amem-flush", VLC_VAR_ADDRESS);
695 var_Create (mp, "amem-drain", VLC_VAR_ADDRESS);
696 var_Create (mp, "amem-set-volume", VLC_VAR_ADDRESS);
697 var_Create (mp, "amem-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
698 var_Create (mp, "amem-rate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
699 var_Create (mp, "amem-channels", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
701 /* Video Title */
702 var_Create (mp, "video-title-show", VLC_VAR_BOOL);
703 var_Create (mp, "video-title-position", VLC_VAR_INTEGER);
704 var_Create (mp, "video-title-timeout", VLC_VAR_INTEGER);
706 /* Equalizer */
707 var_Create (mp, "equalizer-preamp", VLC_VAR_FLOAT);
708 var_Create (mp, "equalizer-vlcfreqs", VLC_VAR_BOOL);
709 var_Create (mp, "equalizer-bands", VLC_VAR_STRING);
711 mp->p_md = NULL;
712 mp->p_libvlc_instance = instance;
713 /* use a reentrant lock to allow calling libvlc functions from callbacks */
714 mp->player = vlc_player_New(VLC_OBJECT(mp), VLC_PLAYER_LOCK_REENTRANT,
715 NULL, NULL);
716 if (unlikely(!mp->player))
717 goto error1;
719 vlc_player_Lock(mp->player);
721 mp->listener = vlc_player_AddListener(mp->player, &vlc_player_cbs, mp);
722 if (unlikely(!mp->listener))
723 goto error2;
725 mp->aout_listener =
726 vlc_player_aout_AddListener(mp->player, &vlc_player_aout_cbs, mp);
727 if (unlikely(!mp->aout_listener))
728 goto error3;
730 vlc_player_Unlock(mp->player);
732 vlc_atomic_rc_init(&mp->rc);
733 libvlc_event_manager_init(&mp->event_manager, mp);
735 /* Snapshot initialization */
736 /* Attach a var callback to the global object to provide the glue between
737 * vout_thread that generates the event and media_player that re-emits it
738 * with its own event manager
740 * FIXME: It's unclear why we want to put this in public API, and why we
741 * want to expose it in such a limiting and ugly way.
743 var_AddCallback(vlc_object_instance(mp),
744 "snapshot-file", snapshot_was_taken, mp);
746 libvlc_retain(instance);
747 return mp;
749 error3:
750 vlc_player_RemoveListener(mp->player, mp->listener);
751 error2:
752 vlc_player_Unlock(mp->player);
753 vlc_player_Delete(mp->player);
754 error1:
755 vlc_object_delete(mp);
756 return NULL;
759 /**************************************************************************
760 * Create a Media Instance object with a media descriptor.
761 **************************************************************************/
762 libvlc_media_player_t *
763 libvlc_media_player_new_from_media( libvlc_media_t * p_md )
765 libvlc_media_player_t * p_mi;
767 p_mi = libvlc_media_player_new( p_md->p_libvlc_instance );
768 if( !p_mi )
769 return NULL;
771 libvlc_media_retain( p_md );
772 p_mi->p_md = p_md;
773 media_attach_preparsed_event(p_md);
775 vlc_player_Lock(p_mi->player);
776 int ret = vlc_player_SetCurrentMedia(p_mi->player, p_md->p_input_item);
777 vlc_player_Unlock(p_mi->player);
779 if (ret != VLC_SUCCESS)
781 media_detach_preparsed_event(p_md);
782 libvlc_media_release(p_md);
783 p_mi->p_md = NULL;
784 return NULL;
787 return p_mi;
790 /**************************************************************************
791 * Destroy a Media Instance object (libvlc internal)
793 * Warning: No lock held here, but hey, this is internal. Caller must lock.
794 **************************************************************************/
795 static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
797 assert( p_mi );
799 /* Detach Callback from the main libvlc object */
800 var_DelCallback( vlc_object_instance(p_mi),
801 "snapshot-file", snapshot_was_taken, p_mi );
803 vlc_player_Lock(p_mi->player);
804 vlc_player_aout_RemoveListener(p_mi->player, p_mi->aout_listener);
805 vlc_player_RemoveListener(p_mi->player, p_mi->listener);
806 vlc_player_Unlock(p_mi->player);
808 vlc_player_Delete(p_mi->player);
810 if (p_mi->p_md)
811 media_detach_preparsed_event(p_mi->p_md);
812 libvlc_event_manager_destroy(&p_mi->event_manager);
813 libvlc_media_release( p_mi->p_md );
815 libvlc_instance_t *instance = p_mi->p_libvlc_instance;
816 vlc_object_delete(p_mi);
817 libvlc_release(instance);
820 /**************************************************************************
821 * Release a Media Instance object.
823 * Function does the locking.
824 **************************************************************************/
825 void libvlc_media_player_release( libvlc_media_player_t *p_mi )
827 assert( p_mi );
828 if( !vlc_atomic_rc_dec( &p_mi->rc ) )
829 return;
831 libvlc_media_player_destroy( p_mi );
834 /**************************************************************************
835 * Retain a Media Instance object.
837 * Caller must hold the lock.
838 **************************************************************************/
839 void libvlc_media_player_retain( libvlc_media_player_t *p_mi )
841 assert( p_mi );
842 vlc_atomic_rc_inc( &p_mi->rc );
845 /**************************************************************************
846 * Set the Media descriptor associated with the instance.
848 * Enter without lock -- function will lock the object.
849 **************************************************************************/
850 void libvlc_media_player_set_media(
851 libvlc_media_player_t *p_mi,
852 libvlc_media_t *p_md )
854 vlc_player_Lock(p_mi->player);
856 if (p_mi->p_md)
857 media_detach_preparsed_event(p_mi->p_md);
859 libvlc_media_release( p_mi->p_md );
861 if( p_md )
863 libvlc_media_retain( p_md );
864 media_attach_preparsed_event(p_md);
866 p_mi->p_md = p_md;
868 vlc_player_SetCurrentMedia(p_mi->player, p_md->p_input_item);
870 vlc_player_Unlock(p_mi->player);
873 /**************************************************************************
874 * Get the Media descriptor associated with the instance.
875 **************************************************************************/
876 libvlc_media_t *
877 libvlc_media_player_get_media( libvlc_media_player_t *p_mi )
879 libvlc_media_t *p_m;
881 vlc_player_Lock(p_mi->player);
882 p_m = p_mi->p_md;
883 if( p_m )
884 libvlc_media_retain( p_m );
885 vlc_player_Unlock(p_mi->player);
887 return p_m;
890 /**************************************************************************
891 * Get the event Manager.
892 **************************************************************************/
893 libvlc_event_manager_t *
894 libvlc_media_player_event_manager( libvlc_media_player_t *p_mi )
896 return &p_mi->event_manager;
899 /**************************************************************************
900 * Tell media player to start playing.
901 **************************************************************************/
902 int libvlc_media_player_play( libvlc_media_player_t *p_mi )
904 vlc_player_t *player = p_mi->player;
905 vlc_player_Lock(player);
907 int ret = vlc_player_Start(player);
908 if (ret == VLC_SUCCESS)
910 if (vlc_player_IsPaused(player))
911 vlc_player_Resume(player);
914 vlc_player_Unlock(player);
915 return ret;
918 void libvlc_media_player_set_pause( libvlc_media_player_t *p_mi, int paused )
920 vlc_player_t *player = p_mi->player;
921 vlc_player_Lock(player);
923 if (paused)
925 if (vlc_player_CanPause(player))
926 vlc_player_Pause(player);
927 else
928 vlc_player_Stop(player);
930 else
932 vlc_player_Resume(player);
935 vlc_player_Unlock(player);
938 /**************************************************************************
939 * Toggle pause.
940 **************************************************************************/
941 void libvlc_media_player_pause( libvlc_media_player_t *p_mi )
943 vlc_player_t *player = p_mi->player;
944 vlc_player_Lock(player);
946 vlc_player_TogglePause(player);
948 vlc_player_Unlock(player);
951 /**************************************************************************
952 * Tells whether the media player is currently playing.
953 **************************************************************************/
954 bool libvlc_media_player_is_playing(libvlc_media_player_t *p_mi)
956 vlc_player_t *player = p_mi->player;
957 vlc_player_Lock(player);
959 bool ret = vlc_player_IsStarted(player) && !vlc_player_IsPaused(player);
961 vlc_player_Unlock(player);
962 return ret;
965 /**************************************************************************
966 * Stop playing.
967 **************************************************************************/
968 int libvlc_media_player_stop_async( libvlc_media_player_t *p_mi )
970 vlc_player_t *player = p_mi->player;
971 vlc_player_Lock(player);
973 int ret = vlc_player_Stop(player);
975 vlc_player_Unlock(player);
977 return ret;
980 int libvlc_media_player_set_renderer( libvlc_media_player_t *p_mi,
981 libvlc_renderer_item_t *p_litem )
983 vlc_player_t *player = p_mi->player;
984 vlc_player_Lock(player);
986 vlc_renderer_item_t *renderer = libvlc_renderer_item_to_vlc(p_litem);
987 vlc_player_SetRenderer(player, renderer);
989 vlc_player_Unlock(player);
990 return 0;
993 void libvlc_video_set_callbacks( libvlc_media_player_t *mp,
994 void *(*lock_cb) (void *, void **),
995 void (*unlock_cb) (void *, void *, void *const *),
996 void (*display_cb) (void *, void *),
997 void *opaque )
999 var_SetAddress( mp, "vmem-lock", lock_cb );
1000 var_SetAddress( mp, "vmem-unlock", unlock_cb );
1001 var_SetAddress( mp, "vmem-display", display_cb );
1002 var_SetAddress( mp, "vmem-data", opaque );
1003 var_SetString( mp, "dec-dev", "none" );
1004 var_SetString( mp, "vout", "vmem" );
1005 var_SetString( mp, "window", "dummy" );
1008 void libvlc_video_set_format_callbacks( libvlc_media_player_t *mp,
1009 libvlc_video_format_cb setup,
1010 libvlc_video_cleanup_cb cleanup )
1012 var_SetAddress( mp, "vmem-setup", setup );
1013 var_SetAddress( mp, "vmem-cleanup", cleanup );
1016 void libvlc_video_set_format( libvlc_media_player_t *mp, const char *chroma,
1017 unsigned width, unsigned height, unsigned pitch )
1019 var_SetString( mp, "vmem-chroma", chroma );
1020 var_SetInteger( mp, "vmem-width", width );
1021 var_SetInteger( mp, "vmem-height", height );
1022 var_SetInteger( mp, "vmem-pitch", pitch );
1025 bool libvlc_video_set_output_callbacks(libvlc_media_player_t *mp,
1026 libvlc_video_engine_t engine,
1027 libvlc_video_output_setup_cb setup_cb,
1028 libvlc_video_output_cleanup_cb cleanup_cb,
1029 libvlc_video_output_set_resize_cb resize_cb,
1030 libvlc_video_update_output_cb update_output_cb,
1031 libvlc_video_swap_cb swap_cb,
1032 libvlc_video_makeCurrent_cb makeCurrent_cb,
1033 libvlc_video_getProcAddress_cb getProcAddress_cb,
1034 libvlc_video_frameMetadata_cb metadata_cb,
1035 libvlc_video_output_select_plane_cb select_plane_cb,
1036 void *opaque)
1038 static_assert(libvlc_video_engine_disable == 0, "No engine set must default to 0");
1039 var_SetString( mp, "window", "wextern");
1041 if( engine == libvlc_video_engine_gles2 )
1043 var_SetString ( mp, "vout", "gles2" );
1044 var_SetString ( mp, "gles2", "vgl" );
1046 else if( engine == libvlc_video_engine_opengl )
1048 var_SetString ( mp, "vout", "gl" );
1049 var_SetString ( mp, "gl", "vgl");
1051 else if ( engine == libvlc_video_engine_d3d11 )
1053 var_SetString ( mp, "vout", "direct3d11" );
1054 var_SetString ( mp, "dec-dev", "d3d11" );
1056 else if ( engine == libvlc_video_engine_d3d9 )
1058 var_SetString ( mp, "vout", "direct3d9" );
1059 var_SetString ( mp, "dec-dev", "d3d9" );
1061 else if ( engine == libvlc_video_engine_disable )
1063 // use the default display module
1064 var_SetString ( mp, "vout", "" );
1065 // use the default window
1066 var_SetString( mp, "window", "");
1068 else
1069 return false;
1071 var_SetInteger( mp, "vout-cb-type", engine );
1072 var_SetAddress( mp, "vout-cb-opaque", opaque );
1073 var_SetAddress( mp, "vout-cb-setup", setup_cb );
1074 var_SetAddress( mp, "vout-cb-cleanup", cleanup_cb );
1075 var_SetAddress( mp, "vout-cb-resize-cb", resize_cb );
1076 var_SetAddress( mp, "vout-cb-update-output", update_output_cb );
1077 var_SetAddress( mp, "vout-cb-swap", swap_cb );
1078 var_SetAddress( mp, "vout-cb-get-proc-address", getProcAddress_cb );
1079 var_SetAddress( mp, "vout-cb-make-current", makeCurrent_cb );
1080 var_SetAddress( mp, "vout-cb-metadata", metadata_cb );
1081 var_SetAddress( mp, "vout-cb-select-plane", select_plane_cb );
1082 return true;
1085 /**************************************************************************
1086 * set_nsobject
1087 **************************************************************************/
1088 void libvlc_media_player_set_nsobject( libvlc_media_player_t *p_mi,
1089 void * drawable )
1091 assert (p_mi != NULL);
1092 #ifdef __APPLE__
1093 var_SetString (p_mi, "dec-dev", "");
1094 var_SetString (p_mi, "vout", "");
1095 var_SetString (p_mi, "window", "");
1096 var_SetAddress (p_mi, "drawable-nsobject", drawable);
1097 #else
1098 (void)drawable;
1099 libvlc_printerr ("can't set nsobject: APPLE build required");
1100 assert(false);
1101 var_SetString (p_mi, "vout", "none");
1102 var_SetString (p_mi, "window", "none");
1103 #endif
1106 /**************************************************************************
1107 * get_nsobject
1108 **************************************************************************/
1109 void * libvlc_media_player_get_nsobject( libvlc_media_player_t *p_mi )
1111 assert (p_mi != NULL);
1112 #ifdef __APPLE__
1113 return var_GetAddress (p_mi, "drawable-nsobject");
1114 #else
1115 (void) p_mi;
1116 return NULL;
1117 #endif
1120 /**************************************************************************
1121 * set_xwindow
1122 **************************************************************************/
1123 void libvlc_media_player_set_xwindow( libvlc_media_player_t *p_mi,
1124 uint32_t drawable )
1126 assert (p_mi != NULL);
1128 var_SetString (p_mi, "dec-dev", "");
1129 var_SetString (p_mi, "vout", "");
1130 var_SetString (p_mi, "window", drawable ? "embed-xid,any" : "");
1131 var_SetInteger (p_mi, "drawable-xid", drawable);
1134 /**************************************************************************
1135 * get_xwindow
1136 **************************************************************************/
1137 uint32_t libvlc_media_player_get_xwindow( libvlc_media_player_t *p_mi )
1139 return var_GetInteger (p_mi, "drawable-xid");
1142 /**************************************************************************
1143 * set_hwnd
1144 **************************************************************************/
1145 void libvlc_media_player_set_hwnd( libvlc_media_player_t *p_mi,
1146 void *drawable )
1148 assert (p_mi != NULL);
1149 #if defined (_WIN32) || defined (__OS2__)
1150 var_SetString (p_mi, "dec-dev", "");
1151 var_SetString (p_mi, "vout", "");
1152 var_SetString (p_mi, "window",
1153 (drawable != NULL) ? "embed-hwnd,any" : "");
1154 var_SetInteger (p_mi, "drawable-hwnd", (uintptr_t)drawable);
1155 #else
1156 (void) drawable;
1157 libvlc_printerr ("can't set hwnd: WIN32 build required");
1158 assert(false);
1159 var_SetString (p_mi, "vout", "none");
1160 var_SetString (p_mi, "window", "none");
1161 #endif
1164 /**************************************************************************
1165 * get_hwnd
1166 **************************************************************************/
1167 void *libvlc_media_player_get_hwnd( libvlc_media_player_t *p_mi )
1169 assert (p_mi != NULL);
1170 #if defined (_WIN32) || defined (__OS2__)
1171 return (void *)(uintptr_t)var_GetInteger (p_mi, "drawable-hwnd");
1172 #else
1173 (void) p_mi;
1174 return NULL;
1175 #endif
1178 /**************************************************************************
1179 * set_android_context
1180 **************************************************************************/
1181 void libvlc_media_player_set_android_context( libvlc_media_player_t *p_mi,
1182 void *p_awindow_handler )
1184 assert (p_mi != NULL);
1185 #ifdef __ANDROID__
1186 var_SetAddress (p_mi, "drawable-androidwindow", p_awindow_handler);
1187 #else
1188 (void) p_awindow_handler;
1189 libvlc_printerr ("can't set android context: ANDROID build required");
1190 assert(false);
1191 var_SetString (p_mi, "vout", "none");
1192 var_SetString (p_mi, "window", "none");
1193 #endif
1196 void libvlc_audio_set_callbacks( libvlc_media_player_t *mp,
1197 libvlc_audio_play_cb play_cb,
1198 libvlc_audio_pause_cb pause_cb,
1199 libvlc_audio_resume_cb resume_cb,
1200 libvlc_audio_flush_cb flush_cb,
1201 libvlc_audio_drain_cb drain_cb,
1202 void *opaque )
1204 var_SetAddress( mp, "amem-play", play_cb );
1205 var_SetAddress( mp, "amem-pause", pause_cb );
1206 var_SetAddress( mp, "amem-resume", resume_cb );
1207 var_SetAddress( mp, "amem-flush", flush_cb );
1208 var_SetAddress( mp, "amem-drain", drain_cb );
1209 var_SetAddress( mp, "amem-data", opaque );
1210 var_SetString( mp, "aout", "amem,none" );
1212 vlc_player_aout_Reset( mp->player );
1215 void libvlc_audio_set_volume_callback( libvlc_media_player_t *mp,
1216 libvlc_audio_set_volume_cb cb )
1218 var_SetAddress( mp, "amem-set-volume", cb );
1220 vlc_player_aout_Reset( mp->player );
1223 void libvlc_audio_set_format_callbacks( libvlc_media_player_t *mp,
1224 libvlc_audio_setup_cb setup,
1225 libvlc_audio_cleanup_cb cleanup )
1227 var_SetAddress( mp, "amem-setup", setup );
1228 var_SetAddress( mp, "amem-cleanup", cleanup );
1230 vlc_player_aout_Reset( mp->player );
1233 void libvlc_audio_set_format( libvlc_media_player_t *mp, const char *format,
1234 unsigned rate, unsigned channels )
1236 var_SetString( mp, "amem-format", format );
1237 var_SetInteger( mp, "amem-rate", rate );
1238 var_SetInteger( mp, "amem-channels", channels );
1240 vlc_player_aout_Reset( mp->player );
1244 /**************************************************************************
1245 * Getters for stream information
1246 **************************************************************************/
1247 libvlc_time_t libvlc_media_player_get_length(
1248 libvlc_media_player_t *p_mi )
1250 vlc_player_t *player = p_mi->player;
1251 vlc_player_Lock(player);
1253 vlc_tick_t length = vlc_player_GetLength(player);
1254 libvlc_time_t i_time = from_mtime(length);
1256 vlc_player_Unlock(player);
1257 return i_time;
1260 libvlc_time_t libvlc_media_player_get_time( libvlc_media_player_t *p_mi )
1262 vlc_player_t *player = p_mi->player;
1263 vlc_player_Lock(player);
1265 vlc_tick_t tick = vlc_player_GetTime(player);
1266 libvlc_time_t i_time = from_mtime(tick);
1268 vlc_player_Unlock(player);
1269 return i_time;
1272 int libvlc_media_player_set_time( libvlc_media_player_t *p_mi,
1273 libvlc_time_t i_time, bool b_fast )
1275 vlc_tick_t tick = to_mtime(i_time);
1277 vlc_player_t *player = p_mi->player;
1278 vlc_player_Lock(player);
1280 enum vlc_player_seek_speed speed = b_fast ? VLC_PLAYER_SEEK_FAST
1281 : VLC_PLAYER_SEEK_PRECISE;
1282 vlc_player_SeekByTime(player, tick, speed, VLC_PLAYER_WHENCE_ABSOLUTE);
1284 vlc_player_Unlock(player);
1286 /* may not fail anymore, keep int not to break the API */
1287 return 0;
1290 int libvlc_media_player_set_position( libvlc_media_player_t *p_mi,
1291 float position, bool b_fast )
1293 vlc_player_t *player = p_mi->player;
1294 vlc_player_Lock(player);
1296 enum vlc_player_seek_speed speed = b_fast ? VLC_PLAYER_SEEK_FAST
1297 : VLC_PLAYER_SEEK_PRECISE;
1298 vlc_player_SeekByPos(player, position, speed, VLC_PLAYER_WHENCE_ABSOLUTE);
1300 vlc_player_Unlock(player);
1302 /* may not fail anymore, keep int not to break the API */
1303 return 0;
1306 float libvlc_media_player_get_position( libvlc_media_player_t *p_mi )
1308 vlc_player_t *player = p_mi->player;
1309 vlc_player_Lock(player);
1311 float f_position = vlc_player_GetPosition(player);
1313 vlc_player_Unlock(player);
1314 return f_position;
1317 void libvlc_media_player_set_chapter( libvlc_media_player_t *p_mi,
1318 int chapter )
1320 vlc_player_t *player = p_mi->player;
1321 vlc_player_Lock(player);
1323 vlc_player_SelectChapterIdx(player, chapter);
1325 vlc_player_Unlock(player);
1328 int libvlc_media_player_get_chapter( libvlc_media_player_t *p_mi )
1330 vlc_player_t *player = p_mi->player;
1331 vlc_player_Lock(player);
1333 ssize_t i_chapter = vlc_player_GetSelectedChapterIdx(player);
1335 vlc_player_Unlock(player);
1336 return i_chapter;
1339 int libvlc_media_player_get_chapter_count( libvlc_media_player_t *p_mi )
1341 vlc_player_t *player = p_mi->player;
1342 vlc_player_Lock(player);
1344 const struct vlc_player_title *title = vlc_player_GetSelectedTitle(player);
1345 int ret = title ? (int) title->chapter_count : -1;
1347 vlc_player_Unlock(player);
1348 return ret;
1351 int libvlc_media_player_get_chapter_count_for_title(
1352 libvlc_media_player_t *p_mi,
1353 int i_title )
1355 assert(i_title >= 0);
1356 size_t idx = i_title;
1357 int ret = -1;
1359 vlc_player_t *player = p_mi->player;
1360 vlc_player_Lock(player);
1362 vlc_player_title_list *titles = vlc_player_GetTitleList(player);
1363 if (!titles)
1364 goto end;
1366 size_t titles_count = vlc_player_title_list_GetCount(titles);
1367 if (idx < titles_count)
1368 goto end;
1370 const struct vlc_player_title *title =
1371 vlc_player_title_list_GetAt(titles, idx);
1372 assert(title);
1374 ret = title->chapter_count;
1376 end:
1377 vlc_player_Unlock(player);
1378 return ret;
1381 void libvlc_media_player_set_title( libvlc_media_player_t *p_mi,
1382 int i_title )
1384 vlc_player_t *player = p_mi->player;
1385 vlc_player_Lock(player);
1387 vlc_player_SelectTitleIdx(player, i_title);
1389 vlc_player_Unlock(player);
1392 int libvlc_media_player_get_title( libvlc_media_player_t *p_mi )
1394 vlc_player_t *player = p_mi->player;
1395 vlc_player_Lock(player);
1397 ssize_t i_title = vlc_player_GetSelectedTitleIdx(player);
1399 vlc_player_Unlock(player);
1400 return i_title;
1403 int libvlc_media_player_get_title_count( libvlc_media_player_t *p_mi )
1405 vlc_player_t *player = p_mi->player;
1406 vlc_player_Lock(player);
1408 vlc_player_title_list *titles = vlc_player_GetTitleList(player);
1409 int ret = titles ? (int) vlc_player_title_list_GetCount(titles) : -1;
1411 vlc_player_Unlock(player);
1412 return ret;
1415 int libvlc_media_player_get_full_title_descriptions( libvlc_media_player_t *p_mi,
1416 libvlc_title_description_t *** pp_titles )
1418 assert( p_mi );
1420 int ret = -1;
1422 vlc_player_t *player = p_mi->player;
1423 vlc_player_Lock(player);
1425 vlc_player_title_list *titles = vlc_player_GetTitleList(player);
1426 if (!titles)
1427 goto end;
1429 size_t count = vlc_player_title_list_GetCount(titles);
1431 libvlc_title_description_t **descs = vlc_alloc(count, sizeof(*descs));
1432 if (count > 0 && !descs)
1433 goto end;
1435 for (size_t i = 0; i < count; i++)
1437 const struct vlc_player_title *title =
1438 vlc_player_title_list_GetAt(titles, i);
1439 libvlc_title_description_t *desc = malloc(sizeof(*desc));
1440 if (!desc)
1442 libvlc_title_descriptions_release(descs, i);
1443 goto end;
1446 descs[i] = desc;
1448 /* we want to return milliseconds to match the rest of the API */
1449 desc->i_duration = MS_FROM_VLC_TICK(title->length);
1450 desc->i_flags = title->flags;
1451 desc->psz_name = title->name ? strdup(title->name) : NULL;
1454 ret = count;
1455 *pp_titles = descs;
1457 end:
1458 vlc_player_Unlock(player);
1459 return ret;
1462 void libvlc_title_descriptions_release( libvlc_title_description_t **p_titles,
1463 unsigned i_count )
1465 for (unsigned i = 0; i < i_count; i++ )
1467 if ( !p_titles[i] )
1468 continue;
1470 free( p_titles[i]->psz_name );
1471 free( p_titles[i] );
1473 free( p_titles );
1476 int libvlc_media_player_get_full_chapter_descriptions( libvlc_media_player_t *p_mi,
1477 int i_chapters_of_title,
1478 libvlc_chapter_description_t *** pp_chapters )
1480 assert( p_mi );
1482 int ret = -1;
1484 vlc_player_t *player = p_mi->player;
1485 vlc_player_Lock(player);
1487 vlc_player_title_list *titles = vlc_player_GetTitleList(player);
1488 if (!titles)
1489 goto end;
1491 size_t titles_count = vlc_player_title_list_GetCount(titles);
1492 if (i_chapters_of_title < (int) titles_count)
1493 goto end;
1495 const struct vlc_player_title *title =
1496 vlc_player_title_list_GetAt(titles, i_chapters_of_title);
1497 assert(title);
1499 size_t i_chapter_count = title->chapter_count;
1501 libvlc_chapter_description_t **descs =
1502 vlc_alloc(i_chapter_count, sizeof(*descs));
1503 if (i_chapter_count > 0 && !descs)
1504 goto end;
1506 for (size_t i = 0; i < i_chapter_count; i++)
1508 const struct vlc_player_chapter *chapter = &title->chapters[i];
1509 libvlc_chapter_description_t *desc = malloc(sizeof(*desc));
1510 if (!desc)
1512 libvlc_chapter_descriptions_release(descs, i);
1513 goto end;
1516 descs[i] = desc;
1518 vlc_tick_t chapter_end = i < i_chapter_count - 1
1519 ? title->chapters[i + 1].time
1520 : title->length;
1521 desc->i_time_offset = MS_FROM_VLC_TICK(chapter->time);
1522 desc->psz_name = chapter->name ? strdup(chapter->name) : NULL;
1523 desc->i_duration = MS_FROM_VLC_TICK(chapter_end) - desc->i_time_offset;
1526 ret = i_chapter_count;
1527 *pp_chapters = descs;
1529 end:
1530 vlc_player_Unlock(player);
1531 return ret;
1534 void libvlc_chapter_descriptions_release( libvlc_chapter_description_t **p_chapters,
1535 unsigned i_count )
1537 for (unsigned i = 0; i < i_count; i++ )
1539 if ( !p_chapters[i] )
1540 continue;
1542 free( p_chapters[i]->psz_name );
1543 free( p_chapters[i] );
1545 free( p_chapters );
1548 void libvlc_media_player_next_chapter( libvlc_media_player_t *p_mi )
1550 vlc_player_t *player = p_mi->player;
1551 vlc_player_Lock(player);
1553 vlc_player_SelectNextChapter(player);
1555 vlc_player_Unlock(player);
1558 void libvlc_media_player_previous_chapter( libvlc_media_player_t *p_mi )
1560 vlc_player_t *player = p_mi->player;
1561 vlc_player_Lock(player);
1563 vlc_player_SelectPrevChapter(player);
1565 vlc_player_Unlock(player);
1568 int libvlc_media_player_set_rate( libvlc_media_player_t *p_mi, float rate )
1570 vlc_player_t *player = p_mi->player;
1571 vlc_player_Lock(player);
1573 vlc_player_ChangeRate(player, rate);
1575 vlc_player_Unlock(player);
1576 return 0;
1579 float libvlc_media_player_get_rate( libvlc_media_player_t *p_mi )
1581 vlc_player_t *player = p_mi->player;
1582 vlc_player_Lock(player);
1584 float rate = vlc_player_GetRate(player);
1586 vlc_player_Unlock(player);
1587 return rate;
1590 libvlc_state_t libvlc_media_player_get_state( libvlc_media_player_t *p_mi )
1592 vlc_player_t *player = p_mi->player;
1593 vlc_player_Lock(player);
1595 enum vlc_player_error error = vlc_player_GetError(player);
1596 enum vlc_player_state state = vlc_player_GetState(player);
1598 vlc_player_Unlock(player);
1600 if (error != VLC_PLAYER_ERROR_NONE)
1601 return libvlc_Error;
1602 switch (state) {
1603 case VLC_PLAYER_STATE_STOPPED:
1604 return libvlc_Stopped;
1605 case VLC_PLAYER_STATE_STOPPING:
1606 return libvlc_Ended;
1607 case VLC_PLAYER_STATE_STARTED:
1608 return libvlc_Opening;
1609 case VLC_PLAYER_STATE_PLAYING:
1610 return libvlc_Playing;
1611 case VLC_PLAYER_STATE_PAUSED:
1612 return libvlc_Paused;
1613 default:
1614 vlc_assert_unreachable();
1618 bool libvlc_media_player_is_seekable(libvlc_media_player_t *p_mi)
1620 vlc_player_t *player = p_mi->player;
1621 vlc_player_Lock(player);
1623 bool b_seekable = vlc_player_CanSeek(player);
1625 vlc_player_Unlock(player);
1626 return b_seekable;
1629 void libvlc_media_player_navigate( libvlc_media_player_t* p_mi,
1630 unsigned navigate )
1632 static const enum vlc_player_nav map[] =
1634 VLC_PLAYER_NAV_ACTIVATE, VLC_PLAYER_NAV_UP, VLC_PLAYER_NAV_DOWN,
1635 VLC_PLAYER_NAV_LEFT, VLC_PLAYER_NAV_RIGHT, VLC_PLAYER_NAV_POPUP,
1638 if( navigate >= sizeof(map) / sizeof(map[0]) )
1639 return;
1641 vlc_player_t *player = p_mi->player;
1642 vlc_player_Lock(player);
1644 vlc_player_Navigate(player, map[navigate]);
1646 vlc_player_Unlock(player);
1649 /* internal function, used by audio, video */
1650 libvlc_track_description_t *
1651 libvlc_get_track_description( libvlc_media_player_t *p_mi,
1652 enum es_format_category_e cat )
1654 vlc_player_t *player = p_mi->player;
1655 vlc_player_Lock(player);
1657 libvlc_track_description_t *ret, **pp = &ret;
1659 size_t count = vlc_player_GetTrackCount(player, cat);
1660 for (size_t i = 0; i < count; i++)
1662 libvlc_track_description_t *tr = malloc(sizeof (*tr));
1663 if (unlikely(tr == NULL))
1665 libvlc_printerr("Not enough memory");
1666 continue;
1669 const struct vlc_player_track *track =
1670 vlc_player_GetTrackAt(player, cat, i);
1672 *pp = tr;
1673 tr->i_id = vlc_es_id_GetInputId(track->es_id);
1674 tr->psz_name = strdup(track->name);
1675 if (unlikely(!tr->psz_name))
1677 free(tr);
1678 continue;
1680 pp = &tr->p_next;
1683 *pp = NULL;
1685 vlc_player_Unlock(player);
1686 return ret;
1689 void libvlc_track_description_list_release( libvlc_track_description_t *p_td )
1691 libvlc_track_description_t *p_actual, *p_before;
1692 p_actual = p_td;
1694 while ( p_actual )
1696 free( p_actual->psz_name );
1697 p_before = p_actual;
1698 p_actual = p_before->p_next;
1699 free( p_before );
1703 bool libvlc_media_player_can_pause(libvlc_media_player_t *p_mi)
1705 vlc_player_t *player = p_mi->player;
1706 vlc_player_Lock(player);
1708 bool b_can_pause = vlc_player_CanPause(player);
1710 vlc_player_Unlock(player);
1711 return b_can_pause;
1714 bool libvlc_media_player_program_scrambled(libvlc_media_player_t *p_mi)
1716 bool b_program_scrambled = false;
1718 vlc_player_t *player = p_mi->player;
1719 vlc_player_Lock(player);
1721 const struct vlc_player_program *program =
1722 vlc_player_GetSelectedProgram(player);
1723 if (!program)
1724 goto end;
1726 b_program_scrambled = program->scrambled;
1728 vlc_player_Unlock(player);
1729 end:
1730 return b_program_scrambled;
1733 void libvlc_media_player_next_frame( libvlc_media_player_t *p_mi )
1735 vlc_player_t *player = p_mi->player;
1736 vlc_player_Lock(player);
1738 vlc_player_NextVideoFrame(player);
1740 vlc_player_Unlock(player);
1744 * Private lookup table to get subpicture alignment flag values corresponding
1745 * to a libvlc_position_t enumerated value.
1747 static const unsigned char position_subpicture_alignment[] = {
1748 [libvlc_position_center] = 0,
1749 [libvlc_position_left] = SUBPICTURE_ALIGN_LEFT,
1750 [libvlc_position_right] = SUBPICTURE_ALIGN_RIGHT,
1751 [libvlc_position_top] = SUBPICTURE_ALIGN_TOP,
1752 [libvlc_position_top_left] = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_LEFT,
1753 [libvlc_position_top_right] = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_RIGHT,
1754 [libvlc_position_bottom] = SUBPICTURE_ALIGN_BOTTOM,
1755 [libvlc_position_bottom_left] = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_LEFT,
1756 [libvlc_position_bottom_right] = SUBPICTURE_ALIGN_BOTTOM | SUBPICTURE_ALIGN_RIGHT
1759 void libvlc_media_player_set_video_title_display( libvlc_media_player_t *p_mi, libvlc_position_t position, unsigned timeout )
1761 assert( position >= libvlc_position_disable && position <= libvlc_position_bottom_right );
1763 if ( position != libvlc_position_disable )
1765 var_SetBool( p_mi, "video-title-show", true );
1766 var_SetInteger( p_mi, "video-title-position", position_subpicture_alignment[position] );
1767 var_SetInteger( p_mi, "video-title-timeout", timeout );
1769 else
1771 var_SetBool( p_mi, "video-title-show", false );
1775 libvlc_media_tracklist_t *
1776 libvlc_media_player_get_tracklist(libvlc_media_player_t *p_mi,
1777 libvlc_track_type_t type)
1779 vlc_player_t *player = p_mi->player;
1781 vlc_player_Lock(player);
1783 libvlc_media_tracklist_t *list =
1784 libvlc_media_tracklist_from_player(player, type);
1786 vlc_player_Unlock(player);
1788 return list;
1791 libvlc_media_track_t *
1792 libvlc_media_player_get_selected_track(libvlc_media_player_t *p_mi,
1793 libvlc_track_type_t type)
1795 vlc_player_t *player = p_mi->player;
1797 vlc_player_Lock(player);
1799 const enum es_format_category_e cat = libvlc_track_type_to_escat(type);
1800 const struct vlc_player_track *track =
1801 vlc_player_GetSelectedTrack(player, cat);
1803 if (track == NULL)
1805 vlc_player_Unlock(player);
1806 return NULL;
1809 libvlc_media_track_t *libtrack =
1810 libvlc_media_track_create_from_player_track(track);
1811 vlc_player_Unlock(player);
1813 return libtrack;
1816 libvlc_media_track_t *
1817 libvlc_media_player_get_track_from_id( libvlc_media_player_t *p_mi,
1818 const char *psz_id )
1820 vlc_player_t *player = p_mi->player;
1822 vlc_player_Lock(player);
1824 enum es_format_category_e cats[] = { VIDEO_ES, AUDIO_ES, SPU_ES };
1825 for (size_t i = 0; i < ARRAY_SIZE(cats); ++i)
1827 enum es_format_category_e cat = cats[i];
1828 size_t count = vlc_player_GetTrackCount(player, cat);
1830 for (size_t j = 0; j < count; ++j)
1832 const struct vlc_player_track *track =
1833 vlc_player_GetTrackAt(player, cat, j);
1834 if (strcmp(psz_id, vlc_es_id_GetStrId(track->es_id)) == 0)
1836 libvlc_media_track_t *libtrack =
1837 libvlc_media_track_create_from_player_track(track);
1838 vlc_player_Unlock(player);
1839 return libtrack;
1845 vlc_player_Unlock(player);
1846 return NULL;
1849 void
1850 libvlc_media_player_select_track(libvlc_media_player_t *p_mi,
1851 const libvlc_media_track_t *track)
1853 assert( track != NULL );
1854 vlc_player_t *player = p_mi->player;
1856 vlc_player_Lock(player);
1858 const libvlc_media_trackpriv_t *trackpriv =
1859 libvlc_media_track_to_priv(track);
1860 vlc_player_SelectEsId(player, trackpriv->es_id,
1861 VLC_PLAYER_SELECT_EXCLUSIVE);
1863 vlc_player_Unlock(player);
1866 void
1867 libvlc_media_player_unselect_track_type( libvlc_media_player_t *p_mi,
1868 libvlc_track_type_t type )
1870 vlc_player_t *player = p_mi->player;
1871 const enum es_format_category_e cat = libvlc_track_type_to_escat(type);
1873 vlc_player_Lock(player);
1874 vlc_player_UnselectTrackCategory(player, cat);
1875 vlc_player_Unlock(player);
1878 void
1879 libvlc_media_player_select_tracks(libvlc_media_player_t *p_mi,
1880 libvlc_track_type_t type,
1881 const libvlc_media_track_t **tracks,
1882 size_t track_count)
1884 vlc_player_t *player = p_mi->player;
1886 vlc_es_id_t **es_id_list = vlc_alloc(track_count + 1, sizeof(vlc_es_id_t *));
1887 size_t es_id_idx = 0;
1889 if (es_id_list == NULL)
1890 return;
1892 const enum es_format_category_e cat = libvlc_track_type_to_escat(type);
1894 vlc_player_Lock(player);
1896 for (size_t i = 0; i < track_count; ++i)
1898 const libvlc_media_track_t *track = tracks[i];
1899 const libvlc_media_trackpriv_t *trackpriv =
1900 libvlc_media_track_to_priv(track);
1902 es_id_list[es_id_idx++] = trackpriv->es_id;
1904 es_id_list[es_id_idx++] = NULL;
1905 vlc_player_SelectEsIdList(player, cat, es_id_list);
1907 vlc_player_Unlock(player);
1909 free(es_id_list);
1912 void
1913 libvlc_media_player_select_tracks_by_ids( libvlc_media_player_t *p_mi,
1914 libvlc_track_type_t type,
1915 const char *psz_ids )
1917 const enum es_format_category_e cat = libvlc_track_type_to_escat(type);
1919 vlc_player_t *player = p_mi->player;
1921 vlc_player_Lock(player);
1923 vlc_player_SelectTracksByStringIds(player, cat, psz_ids);
1925 vlc_player_Unlock(player);
1928 int libvlc_media_player_add_slave( libvlc_media_player_t *p_mi,
1929 libvlc_media_slave_type_t i_type,
1930 const char *psz_uri, bool b_select )
1932 vlc_player_t *player = p_mi->player;
1933 vlc_player_Lock(player);
1935 enum es_format_category_e cat = i_type == libvlc_media_slave_type_subtitle
1936 ? SPU_ES
1937 : AUDIO_ES;
1939 int ret = vlc_player_AddAssociatedMedia(player, cat, psz_uri, b_select,
1940 false, false);
1942 vlc_player_Unlock(player);
1943 return ret;
1947 * Maximum size of a formatted equalizer amplification band frequency value.
1949 * The allowed value range is supposed to be constrained from -20.0 to 20.0.
1951 * The format string " %.07f" with a minimum value of "-20" gives a maximum
1952 * string length of e.g. " -19.1234567", i.e. 12 bytes (not including the null
1953 * terminator).
1955 #define EQZ_BAND_VALUE_SIZE 12
1957 int libvlc_media_player_set_equalizer( libvlc_media_player_t *p_mi, libvlc_equalizer_t *p_equalizer )
1959 char bands[EQZ_BANDS_MAX * EQZ_BAND_VALUE_SIZE + 1];
1961 if( p_equalizer != NULL )
1963 for( unsigned i = 0, c = 0; i < EQZ_BANDS_MAX; i++ )
1965 c += snprintf( bands + c, sizeof(bands) - c, " %.07f",
1966 p_equalizer->f_amp[i] );
1967 if( unlikely(c >= sizeof(bands)) )
1968 return -1;
1971 var_SetFloat( p_mi, "equalizer-preamp", p_equalizer->f_preamp );
1972 var_SetString( p_mi, "equalizer-bands", bands );
1974 var_SetString( p_mi, "audio-filter", p_equalizer ? "equalizer" : "" );
1976 audio_output_t *p_aout = vlc_player_aout_Hold( p_mi->player );
1977 if( p_aout != NULL )
1979 if( p_equalizer != NULL )
1981 var_SetFloat( p_aout, "equalizer-preamp", p_equalizer->f_preamp );
1982 var_SetString( p_aout, "equalizer-bands", bands );
1985 var_SetString( p_aout, "audio-filter", p_equalizer ? "equalizer" : "" );
1986 aout_Release(p_aout);
1989 return 0;
1993 static libvlc_player_program_t *
1994 libvlc_player_program_new(const struct vlc_player_program *program)
1996 libvlc_player_program_t *libprogram = malloc(sizeof(*libprogram));
1997 if (libprogram == NULL)
1998 return NULL;
2000 libprogram->i_group_id = program->group_id;
2001 libprogram->psz_name = strdup(program->name);
2002 libprogram->b_selected = program->selected;
2003 libprogram->b_scrambled = program->scrambled;
2005 return libprogram;
2008 void
2009 libvlc_player_program_delete( libvlc_player_program_t *program )
2011 free( program->psz_name );
2012 free( program );
2015 void libvlc_media_player_select_program_id( libvlc_media_player_t *p_mi,
2016 int program_id)
2018 vlc_player_t *player = p_mi->player;
2020 vlc_player_Lock(player);
2022 vlc_player_SelectProgram(player, program_id);
2024 vlc_player_Unlock(player);
2027 libvlc_player_program_t *
2028 libvlc_media_player_get_selected_program( libvlc_media_player_t *p_mi)
2030 vlc_player_t *player = p_mi->player;
2032 vlc_player_Lock(player);
2034 const struct vlc_player_program *program = vlc_player_GetSelectedProgram( player );
2035 if( program == NULL )
2037 vlc_player_Unlock(player);
2038 return NULL;
2040 libvlc_player_program_t *libprogram = libvlc_player_program_new(program);
2042 vlc_player_Unlock(player);
2044 return libprogram;
2047 libvlc_player_program_t *
2048 libvlc_media_player_get_program_from_id( libvlc_media_player_t *p_mi, int i_group_id )
2050 vlc_player_t *player = p_mi->player;
2052 vlc_player_Lock(player);
2054 libvlc_player_program_t *libprogram = NULL;
2056 size_t count = vlc_player_GetProgramCount(player);
2057 for (size_t i = 0; i < count; ++i)
2059 const struct vlc_player_program *program =
2060 vlc_player_GetProgramAt(player, i);
2061 assert(program);
2062 if (program->group_id == i_group_id)
2064 libprogram = libvlc_player_program_new(program);
2065 break;
2069 vlc_player_Unlock(player);
2071 return libprogram;
2074 struct libvlc_player_programlist_t
2076 size_t count;
2077 libvlc_player_program_t *programs[];
2080 size_t
2081 libvlc_player_programlist_count( const libvlc_player_programlist_t *list )
2083 return list->count;
2086 libvlc_player_program_t *
2087 libvlc_player_programlist_at( libvlc_player_programlist_t *list, size_t index )
2089 assert(index < list->count);
2090 return list->programs[index];
2093 void
2094 libvlc_player_programlist_delete( libvlc_player_programlist_t *list )
2096 for (size_t i = 0; i < list->count; ++i)
2097 libvlc_player_program_delete(list->programs[i]);
2098 free(list);
2101 libvlc_player_programlist_t *
2102 libvlc_media_player_get_programlist( libvlc_media_player_t *p_mi )
2104 vlc_player_t *player = p_mi->player;
2106 vlc_player_Lock(player);
2108 size_t count = vlc_player_GetProgramCount(player);
2109 if (count == 0)
2110 goto error;
2112 size_t size;
2113 if( mul_overflow( count, sizeof(libvlc_player_program_t *), &size) )
2114 goto error;
2115 if( add_overflow( size, sizeof(libvlc_player_programlist_t), &size) )
2116 goto error;
2118 libvlc_player_programlist_t *list = malloc( size );
2119 if( list == NULL )
2120 goto error;
2122 list->count = 0;
2123 for (size_t i = 0; i < count; ++i)
2125 const struct vlc_player_program *program =
2126 vlc_player_GetProgramAt(player, i);
2127 assert(program);
2128 list->programs[i] = libvlc_player_program_new(program);
2129 if (list->programs[i] == NULL)
2131 libvlc_player_programlist_delete(list);
2132 goto error;
2135 list->count++;
2138 vlc_player_Unlock(player);
2140 return list;
2142 error:
2143 vlc_player_Unlock(player);
2144 return NULL;
2147 static const char roles[][16] =
2149 [libvlc_role_Music] = "music",
2150 [libvlc_role_Video] = "video",
2151 [libvlc_role_Communication] = "communication",
2152 [libvlc_role_Game] = "game",
2153 [libvlc_role_Notification] = "notification",
2154 [libvlc_role_Animation] = "animation",
2155 [libvlc_role_Production] = "production",
2156 [libvlc_role_Accessibility] = "accessibility",
2157 [libvlc_role_Test] = "test",
2160 int libvlc_media_player_set_role(libvlc_media_player_t *mp, unsigned role)
2162 if (role >= ARRAY_SIZE(roles)
2163 || var_SetString(mp, "role", roles[role]) != VLC_SUCCESS)
2164 return -1;
2165 return 0;
2168 int libvlc_media_player_get_role(libvlc_media_player_t *mp)
2170 int ret = -1;
2171 char *str = var_GetString(mp, "role");
2172 if (str == NULL)
2173 return 0;
2175 for (size_t i = 0; i < ARRAY_SIZE(roles); i++)
2176 if (!strcmp(roles[i], str))
2178 ret = i;
2179 break;
2182 free(str);
2183 return ret;
2186 #include <vlc_vout_display.h>
2188 /* make sure surface structures from libvlc can be passed as such to vlc
2189 otherwise we will need wrappers between what libvlc understands and what vlc uses */
2190 #define cast_ libvlc_video_color_space_t
2191 static_assert(libvlc_video_colorspace_BT601 == (cast_)COLOR_SPACE_BT601 &&
2192 libvlc_video_colorspace_BT709 == (cast_)COLOR_SPACE_BT709 &&
2193 libvlc_video_colorspace_BT2020 == (cast_)COLOR_SPACE_BT2020
2194 , "libvlc video colorspace mismatch");
2195 #undef cast_
2197 #define cast_ libvlc_video_transfer_func_t
2198 static_assert(libvlc_video_transfer_func_LINEAR == (cast_)TRANSFER_FUNC_LINEAR &&
2199 libvlc_video_transfer_func_SRGB == (cast_)TRANSFER_FUNC_SRGB &&
2200 libvlc_video_transfer_func_BT470_BG == (cast_)TRANSFER_FUNC_BT470_BG &&
2201 libvlc_video_transfer_func_BT470_M == (cast_)TRANSFER_FUNC_BT470_M &&
2202 libvlc_video_transfer_func_BT709 == (cast_)TRANSFER_FUNC_BT709 &&
2203 libvlc_video_transfer_func_PQ == (cast_)TRANSFER_FUNC_SMPTE_ST2084 &&
2204 libvlc_video_transfer_func_SMPTE_240 == (cast_)TRANSFER_FUNC_SMPTE_240 &&
2205 libvlc_video_transfer_func_HLG == (cast_)TRANSFER_FUNC_HLG
2206 , "libvlc video transfer function mismatch");
2207 #undef cast_
2209 #define cast_ libvlc_video_color_primaries_t
2210 static_assert(libvlc_video_primaries_BT601_525 == (cast_)COLOR_PRIMARIES_BT601_525 &&
2211 libvlc_video_primaries_BT601_625 == (cast_)COLOR_PRIMARIES_BT601_625 &&
2212 libvlc_video_primaries_BT709 == (cast_)COLOR_PRIMARIES_BT709 &&
2213 libvlc_video_primaries_BT2020 == (cast_)COLOR_PRIMARIES_BT2020 &&
2214 libvlc_video_primaries_DCI_P3 == (cast_)COLOR_PRIMARIES_DCI_P3 &&
2215 libvlc_video_primaries_BT470_M == (cast_)COLOR_PRIMARIES_BT470_M
2216 , "libvlc video color primaries mismatch");
2217 #undef cast_