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 *****************************************************************************/
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_input.h>
39 #include <vlc_actions.h>
42 #include "libvlc_internal.h"
43 #include "media_internal.h" // libvlc_media_set_state()
44 #include "media_player_internal.h"
45 #include "renderer_discoverer_internal.h"
47 #define ES_INIT (-2) /* -1 is reserved for ES deselect */
50 input_seekable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
51 vlc_value_t oldval
, vlc_value_t newval
,
54 input_pausable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
55 vlc_value_t oldval
, vlc_value_t newval
,
58 input_scrambled_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
59 vlc_value_t oldval
, vlc_value_t newval
,
62 input_event_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
63 vlc_value_t oldval
, vlc_value_t newval
,
67 input_es_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
68 int action
, vlc_value_t
*p_val
,
72 corks_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
73 vlc_value_t cur
, void *opaque
);
76 mute_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
77 vlc_value_t cur
, void *opaque
);
80 volume_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
81 vlc_value_t cur
, void *opaque
);
84 add_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
);
87 del_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
);
90 snapshot_was_taken( vlc_object_t
*p_this
, char const *psz_cmd
,
91 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
);
93 static void libvlc_media_player_destroy( libvlc_media_player_t
*p_mi
);
100 * The input lock protects the input and input resource pointer.
101 * It MUST NOT be used from callbacks.
103 * The object lock protects the reset, namely the media and the player state.
104 * It can, and usually needs to be taken from callbacks.
105 * The object lock can be acquired under the input lock... and consequently
106 * the opposite order is STRICTLY PROHIBITED.
108 static inline void lock(libvlc_media_player_t
*mp
)
110 vlc_mutex_lock(&mp
->object_lock
);
113 static inline void unlock(libvlc_media_player_t
*mp
)
115 vlc_mutex_unlock(&mp
->object_lock
);
118 static inline void lock_input(libvlc_media_player_t
*mp
)
120 vlc_mutex_lock(&mp
->input
.lock
);
123 static inline void unlock_input(libvlc_media_player_t
*mp
)
125 vlc_mutex_unlock(&mp
->input
.lock
);
128 static void input_item_preparsed_changed( const vlc_event_t
*p_event
,
131 libvlc_media_t
*p_md
= user_data
;
132 if( p_event
->u
.input_item_preparsed_changed
.new_status
& ITEM_PREPARSED
)
135 libvlc_event_t event
;
136 event
.type
= libvlc_MediaParsedChanged
;
137 event
.u
.media_parsed_changed
.new_status
= libvlc_media_parsed_status_done
;
138 libvlc_event_send( &p_md
->event_manager
, &event
);
142 static void media_attach_preparsed_event( libvlc_media_t
*p_md
)
144 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
145 vlc_InputItemPreparsedChanged
,
146 input_item_preparsed_changed
, p_md
);
149 static void media_detach_preparsed_event( libvlc_media_t
*p_md
)
151 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
152 vlc_InputItemPreparsedChanged
,
153 input_item_preparsed_changed
,
158 * Release the associated input thread.
160 * Object lock is NOT held.
161 * Input lock is held or instance is being destroyed.
163 static void release_input_thread( libvlc_media_player_t
*p_mi
)
167 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
168 if( !p_input_thread
)
170 p_mi
->input
.p_thread
= NULL
;
172 media_detach_preparsed_event( p_mi
->p_md
);
174 var_DelCallback( p_input_thread
, "can-seek",
175 input_seekable_changed
, p_mi
);
176 var_DelCallback( p_input_thread
, "can-pause",
177 input_pausable_changed
, p_mi
);
178 var_DelCallback( p_input_thread
, "program-scrambled",
179 input_scrambled_changed
, p_mi
);
180 var_DelCallback( p_input_thread
, "intf-event",
181 input_event_changed
, p_mi
);
182 del_es_callbacks( p_input_thread
, p_mi
);
184 /* We owned this one */
185 input_Stop( p_input_thread
);
186 input_Close( p_input_thread
);
190 * Retrieve the input thread. Be sure to release the object
191 * once you are done with it. (libvlc Internal)
193 input_thread_t
*libvlc_get_input_thread( libvlc_media_player_t
*p_mi
)
195 input_thread_t
*p_input_thread
;
200 p_input_thread
= p_mi
->input
.p_thread
;
202 vlc_object_hold( p_input_thread
);
204 libvlc_printerr( "No active input" );
207 return p_input_thread
;
211 * Set the internal state of the media_player. (media player Internal)
213 * Function will lock the media_player.
215 static void set_state( libvlc_media_player_t
*p_mi
, libvlc_state_t state
,
222 libvlc_media_t
*media
= p_mi
->p_md
;
224 libvlc_media_retain(media
);
231 // Also set the state of the corresponding media
232 // This is strictly for convenience.
233 libvlc_media_set_state(media
, state
);
235 libvlc_media_release(media
);
240 input_seekable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
241 vlc_value_t oldval
, vlc_value_t newval
,
247 libvlc_media_player_t
* p_mi
= p_userdata
;
248 libvlc_event_t event
;
250 event
.type
= libvlc_MediaPlayerSeekableChanged
;
251 event
.u
.media_player_seekable_changed
.new_seekable
= newval
.b_bool
;
253 libvlc_event_send( &p_mi
->event_manager
, &event
);
258 input_pausable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
259 vlc_value_t oldval
, vlc_value_t newval
,
265 libvlc_media_player_t
* p_mi
= p_userdata
;
266 libvlc_event_t event
;
268 event
.type
= libvlc_MediaPlayerPausableChanged
;
269 event
.u
.media_player_pausable_changed
.new_pausable
= newval
.b_bool
;
271 libvlc_event_send( &p_mi
->event_manager
, &event
);
276 input_scrambled_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
277 vlc_value_t oldval
, vlc_value_t newval
,
283 libvlc_media_player_t
* p_mi
= p_userdata
;
284 libvlc_event_t event
;
286 event
.type
= libvlc_MediaPlayerScrambledChanged
;
287 event
.u
.media_player_scrambled_changed
.new_scrambled
= newval
.b_bool
;
289 libvlc_event_send( &p_mi
->event_manager
, &event
);
294 input_event_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
295 vlc_value_t oldval
, vlc_value_t newval
,
298 VLC_UNUSED(oldval
); VLC_UNUSED(psz_cmd
);
299 input_thread_t
* p_input
= (input_thread_t
*)p_this
;
300 libvlc_media_player_t
* p_mi
= p_userdata
;
301 libvlc_event_t event
;
303 assert( !strcmp( psz_cmd
, "intf-event" ) );
305 if( newval
.i_int
== INPUT_EVENT_STATE
)
307 libvlc_state_t libvlc_state
;
309 switch ( var_GetInteger( p_input
, "state" ) )
312 libvlc_state
= libvlc_NothingSpecial
;
313 event
.type
= libvlc_MediaPlayerNothingSpecial
;
316 libvlc_state
= libvlc_Opening
;
317 event
.type
= libvlc_MediaPlayerOpening
;
320 libvlc_state
= libvlc_Playing
;
321 event
.type
= libvlc_MediaPlayerPlaying
;
324 libvlc_state
= libvlc_Paused
;
325 event
.type
= libvlc_MediaPlayerPaused
;
328 libvlc_state
= libvlc_Ended
;
329 event
.type
= libvlc_MediaPlayerEndReached
;
332 libvlc_state
= libvlc_Error
;
333 event
.type
= libvlc_MediaPlayerEncounteredError
;
340 set_state( p_mi
, libvlc_state
, false );
341 libvlc_event_send( &p_mi
->event_manager
, &event
);
343 else if( newval
.i_int
== INPUT_EVENT_DEAD
)
345 libvlc_state_t libvlc_state
= libvlc_Ended
;
346 event
.type
= libvlc_MediaPlayerStopped
;
348 set_state( p_mi
, libvlc_state
, false );
349 libvlc_event_send( &p_mi
->event_manager
, &event
);
351 else if( newval
.i_int
== INPUT_EVENT_POSITION
)
353 if( var_GetInteger( p_input
, "state" ) != PLAYING_S
)
354 return VLC_SUCCESS
; /* Don't send the position while stopped */
357 event
.type
= libvlc_MediaPlayerPositionChanged
;
358 event
.u
.media_player_position_changed
.new_position
=
359 var_GetFloat( p_input
, "position" );
360 libvlc_event_send( &p_mi
->event_manager
, &event
);
363 event
.type
= libvlc_MediaPlayerTimeChanged
;
364 event
.u
.media_player_time_changed
.new_time
=
365 from_mtime(var_GetInteger( p_input
, "time" ));
366 libvlc_event_send( &p_mi
->event_manager
, &event
);
368 else if( newval
.i_int
== INPUT_EVENT_LENGTH
)
370 event
.type
= libvlc_MediaPlayerLengthChanged
;
371 event
.u
.media_player_length_changed
.new_length
=
372 from_mtime(var_GetInteger( p_input
, "length" ));
373 libvlc_event_send( &p_mi
->event_manager
, &event
);
375 else if( newval
.i_int
== INPUT_EVENT_CACHE
)
377 event
.type
= libvlc_MediaPlayerBuffering
;
378 event
.u
.media_player_buffering
.new_cache
= (100 *
379 var_GetFloat( p_input
, "cache" ));
380 libvlc_event_send( &p_mi
->event_manager
, &event
);
382 else if( newval
.i_int
== INPUT_EVENT_VOUT
)
384 vout_thread_t
**pp_vout
;
386 if( input_Control( p_input
, INPUT_GET_VOUTS
, &pp_vout
, &i_vout
) )
392 for( size_t i
= 0; i
< i_vout
; i
++ )
393 vlc_object_release( pp_vout
[i
] );
397 event
.type
= libvlc_MediaPlayerVout
;
398 event
.u
.media_player_vout
.new_count
= i_vout
;
399 libvlc_event_send( &p_mi
->event_manager
, &event
);
401 else if ( newval
.i_int
== INPUT_EVENT_TITLE
)
403 event
.type
= libvlc_MediaPlayerTitleChanged
;
404 event
.u
.media_player_title_changed
.new_title
= var_GetInteger( p_input
, "title" );
405 libvlc_event_send( &p_mi
->event_manager
, &event
);
407 else if ( newval
.i_int
== INPUT_EVENT_CHAPTER
)
409 event
.type
= libvlc_MediaPlayerChapterChanged
;
410 event
.u
.media_player_chapter_changed
.new_chapter
= var_GetInteger( p_input
, "chapter" );
411 libvlc_event_send( &p_mi
->event_manager
, &event
);
413 else if ( newval
.i_int
== INPUT_EVENT_ES
)
415 /* Send ESSelected events from this callback ("intf-event") and not
416 * from "audio-es", "video-es", "spu-es" callbacks. Indeed, these
417 * callbacks are not triggered when the input_thread changes an ES
418 * while this callback is. */
420 const char *psz_name
;
421 const libvlc_track_type_t type
;
424 { "audio-es", libvlc_track_audio
, ES_INIT
},
425 { "video-es", libvlc_track_video
, ES_INIT
},
426 { "spu-es", libvlc_track_text
, ES_INIT
},
428 /* Check if an ES selection changed */
430 for( size_t i
= 0; i
< ARRAY_SIZE( es_list
); ++i
)
432 int current_es
= var_GetInteger( p_input
, es_list
[i
].psz_name
);
433 if( current_es
!= p_mi
->selected_es
[i
] )
434 es_list
[i
].new_es
= p_mi
->selected_es
[i
] = current_es
;
438 /* Send the ESSelected event for each ES that were newly selected */
439 for( size_t i
= 0; i
< ARRAY_SIZE( es_list
); ++i
)
441 if( es_list
[i
].new_es
!= ES_INIT
)
443 event
.type
= libvlc_MediaPlayerESSelected
;
444 event
.u
.media_player_es_changed
.i_type
= es_list
[i
].type
;
445 event
.u
.media_player_es_changed
.i_id
= es_list
[i
].new_es
;
446 libvlc_event_send( &p_mi
->event_manager
, &event
);
454 static int track_type_from_name(const char *psz_name
)
456 if( !strcmp( psz_name
, "video-es" ) )
457 return libvlc_track_video
;
458 else if( !strcmp( psz_name
, "audio-es" ) )
459 return libvlc_track_audio
;
460 else if( !strcmp( psz_name
, "spu-es" ) )
461 return libvlc_track_text
;
463 return libvlc_track_unknown
;
466 static int input_es_changed( vlc_object_t
*p_this
,
473 libvlc_media_player_t
*mp
= p_userdata
;
474 libvlc_event_t event
;
476 /* Ignore the "Disable" element */
477 if (p_val
&& p_val
->i_int
< 0)
482 case VLC_VAR_ADDCHOICE
:
483 event
.type
= libvlc_MediaPlayerESAdded
;
485 case VLC_VAR_DELCHOICE
:
486 case VLC_VAR_CLEARCHOICES
:
487 event
.type
= libvlc_MediaPlayerESDeleted
;
493 event
.u
.media_player_es_changed
.i_type
= track_type_from_name(psz_cmd
);
496 if (action
!= VLC_VAR_CLEARCHOICES
)
504 /* -1 means all ES tracks of this type were deleted. */
507 event
.u
.media_player_es_changed
.i_id
= i_id
;
509 libvlc_event_send(&mp
->event_manager
, &event
);
514 /**************************************************************************
515 * Snapshot Taken Event.
517 * FIXME: This snapshot API interface makes no sense in media_player.
518 *************************************************************************/
519 static int snapshot_was_taken(vlc_object_t
*p_this
, char const *psz_cmd
,
520 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
522 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_this
);
524 libvlc_media_player_t
*mp
= p_data
;
525 libvlc_event_t event
;
526 event
.type
= libvlc_MediaPlayerSnapshotTaken
;
527 event
.u
.media_player_snapshot_taken
.psz_filename
= newval
.psz_string
;
528 libvlc_event_send(&mp
->event_manager
, &event
);
533 static int corks_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
534 vlc_value_t cur
, void *opaque
)
536 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
538 if (!old
.i_int
!= !cur
.i_int
)
540 libvlc_event_t event
;
542 event
.type
= cur
.i_int
? libvlc_MediaPlayerCorked
543 : libvlc_MediaPlayerUncorked
;
544 libvlc_event_send(&mp
->event_manager
, &event
);
546 VLC_UNUSED(name
); VLC_UNUSED(opaque
);
550 static int audio_device_changed(vlc_object_t
*obj
, const char *name
,
551 vlc_value_t old
, vlc_value_t cur
, void *opaque
)
553 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
554 libvlc_event_t event
;
556 event
.type
= libvlc_MediaPlayerAudioDevice
;
557 event
.u
.media_player_audio_device
.device
= cur
.psz_string
;
558 libvlc_event_send(&mp
->event_manager
, &event
);
559 VLC_UNUSED(name
); VLC_UNUSED(old
); VLC_UNUSED(opaque
);
563 static int mute_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
564 vlc_value_t cur
, void *opaque
)
566 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
568 if (old
.b_bool
!= cur
.b_bool
)
570 libvlc_event_t event
;
572 event
.type
= cur
.b_bool
? libvlc_MediaPlayerMuted
573 : libvlc_MediaPlayerUnmuted
;
574 libvlc_event_send(&mp
->event_manager
, &event
);
576 VLC_UNUSED(name
); VLC_UNUSED(opaque
);
580 static int volume_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
581 vlc_value_t cur
, void *opaque
)
583 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
584 libvlc_event_t event
;
586 event
.type
= libvlc_MediaPlayerAudioVolume
;
587 event
.u
.media_player_audio_volume
.volume
= cur
.f_float
;
588 libvlc_event_send(&mp
->event_manager
, &event
);
589 VLC_UNUSED(name
); VLC_UNUSED(old
); VLC_UNUSED(opaque
);
593 /**************************************************************************
594 * Create a Media Instance object.
597 * - All items created by _new start with a refcount set to 1.
598 * - Accessor _release decrease the refcount by 1, if after that
599 * operation the refcount is 0, the object is destroyed.
600 * - Accessor _retain increase the refcount by 1 (XXX: to implement)
602 * Object locking strategy:
603 * - No lock held while in constructor.
604 * - When accessing any member variable this lock is held. (XXX who locks?)
605 * - When attempting to destroy the object the lock is also held.
606 **************************************************************************/
607 libvlc_media_player_t
*
608 libvlc_media_player_new( libvlc_instance_t
*instance
)
610 libvlc_media_player_t
* mp
;
614 mp
= vlc_object_create (instance
->p_libvlc_int
, sizeof(*mp
));
615 if (unlikely(mp
== NULL
))
617 libvlc_printerr("Not enough memory");
622 var_Create (mp
, "rate", VLC_VAR_FLOAT
|VLC_VAR_DOINHERIT
);
623 var_Create (mp
, "sout", VLC_VAR_STRING
);
624 var_Create (mp
, "demux-filter", VLC_VAR_STRING
);
627 var_Create (mp
, "vout", VLC_VAR_STRING
|VLC_VAR_DOINHERIT
);
628 var_Create (mp
, "window", VLC_VAR_STRING
);
629 var_Create (mp
, "gl", VLC_VAR_STRING
);
630 var_Create (mp
, "gles2", VLC_VAR_STRING
);
631 var_Create (mp
, "vmem-lock", VLC_VAR_ADDRESS
);
632 var_Create (mp
, "vmem-unlock", VLC_VAR_ADDRESS
);
633 var_Create (mp
, "vmem-display", VLC_VAR_ADDRESS
);
634 var_Create (mp
, "vmem-data", VLC_VAR_ADDRESS
);
635 var_Create (mp
, "vmem-setup", VLC_VAR_ADDRESS
);
636 var_Create (mp
, "vmem-cleanup", VLC_VAR_ADDRESS
);
637 var_Create (mp
, "vmem-chroma", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
638 var_Create (mp
, "vmem-width", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
639 var_Create (mp
, "vmem-height", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
640 var_Create (mp
, "vmem-pitch", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
642 var_Create( mp
, "vgl-opaque", VLC_VAR_ADDRESS
);
643 var_Create( mp
, "vgl-setup-cb", VLC_VAR_ADDRESS
);
644 var_Create( mp
, "vgl-cleanup-cb", VLC_VAR_ADDRESS
);
645 var_Create( mp
, "vgl-resize-cb", VLC_VAR_ADDRESS
);
646 var_Create( mp
, "vgl-swap-cb", VLC_VAR_ADDRESS
);
647 var_Create( mp
, "vgl-get-proc-address-cb", VLC_VAR_ADDRESS
);
648 var_Create( mp
, "vgl-make-current-cb", VLC_VAR_ADDRESS
);
650 var_Create (mp
, "avcodec-hw", VLC_VAR_STRING
);
651 var_Create (mp
, "drawable-xid", VLC_VAR_INTEGER
);
652 #if defined (_WIN32) || defined (__OS2__)
653 var_Create (mp
, "drawable-hwnd", VLC_VAR_INTEGER
);
656 var_Create (mp
, "drawable-nsobject", VLC_VAR_ADDRESS
);
659 var_Create (mp
, "drawable-androidwindow", VLC_VAR_ADDRESS
);
662 var_Create (mp
, "keyboard-events", VLC_VAR_BOOL
);
663 var_SetBool (mp
, "keyboard-events", true);
664 var_Create (mp
, "mouse-events", VLC_VAR_BOOL
);
665 var_SetBool (mp
, "mouse-events", true);
667 var_Create (mp
, "fullscreen", VLC_VAR_BOOL
);
668 var_Create (mp
, "autoscale", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
669 var_Create (mp
, "zoom", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
670 var_Create (mp
, "aspect-ratio", VLC_VAR_STRING
);
671 var_Create (mp
, "crop", VLC_VAR_STRING
);
672 var_Create (mp
, "deinterlace", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
673 var_Create (mp
, "deinterlace-mode", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
675 var_Create (mp
, "vbi-page", VLC_VAR_INTEGER
);
676 var_SetInteger (mp
, "vbi-page", 100);
678 var_Create (mp
, "video-filter", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
679 var_Create (mp
, "sub-source", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
680 var_Create (mp
, "sub-filter", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
682 var_Create (mp
, "marq-marquee", VLC_VAR_STRING
);
683 var_Create (mp
, "marq-color", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
684 var_Create (mp
, "marq-opacity", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
685 var_Create (mp
, "marq-position", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
686 var_Create (mp
, "marq-refresh", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
687 var_Create (mp
, "marq-size", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
688 var_Create (mp
, "marq-timeout", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
689 var_Create (mp
, "marq-x", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
690 var_Create (mp
, "marq-y", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
692 var_Create (mp
, "logo-file", VLC_VAR_STRING
);
693 var_Create (mp
, "logo-x", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
694 var_Create (mp
, "logo-y", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
695 var_Create (mp
, "logo-delay", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
696 var_Create (mp
, "logo-repeat", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
697 var_Create (mp
, "logo-opacity", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
698 var_Create (mp
, "logo-position", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
700 var_Create (mp
, "contrast", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
701 var_Create (mp
, "brightness", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
702 var_Create (mp
, "hue", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
703 var_Create (mp
, "saturation", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
704 var_Create (mp
, "gamma", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
707 var_Create (mp
, "aout", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
708 var_Create (mp
, "audio-device", VLC_VAR_STRING
);
709 var_Create (mp
, "mute", VLC_VAR_BOOL
);
710 var_Create (mp
, "volume", VLC_VAR_FLOAT
);
711 var_Create (mp
, "corks", VLC_VAR_INTEGER
);
712 var_Create (mp
, "audio-filter", VLC_VAR_STRING
);
713 var_Create (mp
, "role", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
714 var_Create (mp
, "amem-data", VLC_VAR_ADDRESS
);
715 var_Create (mp
, "amem-setup", VLC_VAR_ADDRESS
);
716 var_Create (mp
, "amem-cleanup", VLC_VAR_ADDRESS
);
717 var_Create (mp
, "amem-play", VLC_VAR_ADDRESS
);
718 var_Create (mp
, "amem-pause", VLC_VAR_ADDRESS
);
719 var_Create (mp
, "amem-resume", VLC_VAR_ADDRESS
);
720 var_Create (mp
, "amem-flush", VLC_VAR_ADDRESS
);
721 var_Create (mp
, "amem-drain", VLC_VAR_ADDRESS
);
722 var_Create (mp
, "amem-set-volume", VLC_VAR_ADDRESS
);
723 var_Create (mp
, "amem-format", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
724 var_Create (mp
, "amem-rate", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
725 var_Create (mp
, "amem-channels", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
728 var_Create (mp
, "video-title-show", VLC_VAR_BOOL
);
729 var_Create (mp
, "video-title-position", VLC_VAR_INTEGER
);
730 var_Create (mp
, "video-title-timeout", VLC_VAR_INTEGER
);
733 var_Create (mp
, "equalizer-preamp", VLC_VAR_FLOAT
);
734 var_Create (mp
, "equalizer-vlcfreqs", VLC_VAR_BOOL
);
735 var_Create (mp
, "equalizer-bands", VLC_VAR_STRING
);
737 /* Initialize the shared HTTP cookie jar */
739 cookies
.p_address
= vlc_http_cookies_new();
740 if ( likely(cookies
.p_address
) )
742 var_Create(mp
, "http-cookies", VLC_VAR_ADDRESS
);
743 var_SetChecked(mp
, "http-cookies", VLC_VAR_ADDRESS
, cookies
);
747 mp
->state
= libvlc_NothingSpecial
;
748 mp
->p_libvlc_instance
= instance
;
749 mp
->input
.p_thread
= NULL
;
750 mp
->input
.p_renderer
= NULL
;
751 mp
->input
.p_resource
= input_resource_New(VLC_OBJECT(mp
));
752 if (unlikely(mp
->input
.p_resource
== NULL
))
754 vlc_object_release(mp
);
757 audio_output_t
*aout
= input_resource_GetAout(mp
->input
.p_resource
);
759 input_resource_PutAout(mp
->input
.p_resource
, aout
);
761 vlc_viewpoint_init(&mp
->viewpoint
);
763 var_Create (mp
, "viewpoint", VLC_VAR_ADDRESS
);
764 var_SetAddress( mp
, "viewpoint", &mp
->viewpoint
);
765 vlc_mutex_init (&mp
->input
.lock
);
767 libvlc_event_manager_init(&mp
->event_manager
, mp
);
768 vlc_mutex_init(&mp
->object_lock
);
770 var_AddCallback(mp
, "corks", corks_changed
, NULL
);
771 var_AddCallback(mp
, "audio-device", audio_device_changed
, NULL
);
772 var_AddCallback(mp
, "mute", mute_changed
, NULL
);
773 var_AddCallback(mp
, "volume", volume_changed
, NULL
);
775 /* Snapshot initialization */
776 /* Attach a var callback to the global object to provide the glue between
777 * vout_thread that generates the event and media_player that re-emits it
778 * with its own event manager
780 * FIXME: It's unclear why we want to put this in public API, and why we
781 * want to expose it in such a limiting and ugly way.
783 var_AddCallback(mp
->obj
.libvlc
, "snapshot-file", snapshot_was_taken
, mp
);
785 libvlc_retain(instance
);
789 /**************************************************************************
790 * Create a Media Instance object with a media descriptor.
791 **************************************************************************/
792 libvlc_media_player_t
*
793 libvlc_media_player_new_from_media( libvlc_media_t
* p_md
)
795 libvlc_media_player_t
* p_mi
;
797 p_mi
= libvlc_media_player_new( p_md
->p_libvlc_instance
);
801 libvlc_media_retain( p_md
);
807 /**************************************************************************
808 * Destroy a Media Instance object (libvlc internal)
810 * Warning: No lock held here, but hey, this is internal. Caller must lock.
811 **************************************************************************/
812 static void libvlc_media_player_destroy( libvlc_media_player_t
*p_mi
)
816 /* Detach Callback from the main libvlc object */
817 var_DelCallback( p_mi
->obj
.libvlc
,
818 "snapshot-file", snapshot_was_taken
, p_mi
);
820 /* Detach callback from the media player / input manager object */
821 var_DelCallback( p_mi
, "volume", volume_changed
, NULL
);
822 var_DelCallback( p_mi
, "mute", mute_changed
, NULL
);
823 var_DelCallback( p_mi
, "audio-device", audio_device_changed
, NULL
);
824 var_DelCallback( p_mi
, "corks", corks_changed
, NULL
);
826 /* No need for lock_input() because no other threads knows us anymore */
827 if( p_mi
->input
.p_thread
)
828 release_input_thread(p_mi
);
829 input_resource_Terminate( p_mi
->input
.p_resource
);
830 input_resource_Release( p_mi
->input
.p_resource
);
831 if( p_mi
->input
.p_renderer
)
832 vlc_renderer_item_release( p_mi
->input
.p_renderer
);
834 vlc_mutex_destroy( &p_mi
->input
.lock
);
836 libvlc_event_manager_destroy(&p_mi
->event_manager
);
837 libvlc_media_release( p_mi
->p_md
);
838 vlc_mutex_destroy( &p_mi
->object_lock
);
840 vlc_http_cookie_jar_t
*cookies
= var_GetAddress( p_mi
, "http-cookies" );
843 var_Destroy( p_mi
, "http-cookies" );
844 vlc_http_cookies_destroy( cookies
);
847 libvlc_instance_t
*instance
= p_mi
->p_libvlc_instance
;
848 vlc_object_release( p_mi
);
849 libvlc_release(instance
);
852 /**************************************************************************
853 * Release a Media Instance object.
855 * Function does the locking.
856 **************************************************************************/
857 void libvlc_media_player_release( libvlc_media_player_t
*p_mi
)
863 destroy
= !--p_mi
->i_refcount
;
867 libvlc_media_player_destroy( p_mi
);
870 /**************************************************************************
871 * Retain a Media Instance object.
873 * Caller must hold the lock.
874 **************************************************************************/
875 void libvlc_media_player_retain( libvlc_media_player_t
*p_mi
)
884 /**************************************************************************
885 * Set the Media descriptor associated with the instance.
887 * Enter without lock -- function will lock the object.
888 **************************************************************************/
889 void libvlc_media_player_set_media(
890 libvlc_media_player_t
*p_mi
,
891 libvlc_media_t
*p_md
)
895 release_input_thread( p_mi
);
898 set_state( p_mi
, libvlc_NothingSpecial
, true );
899 unlock_input( p_mi
);
901 libvlc_media_release( p_mi
->p_md
);
907 return; /* It is ok to pass a NULL md */
910 libvlc_media_retain( p_md
);
913 /* The policy here is to ignore that we were created using a different
914 * libvlc_instance, because we don't really care */
915 p_mi
->p_libvlc_instance
= p_md
->p_libvlc_instance
;
919 /* Send an event for the newly available media */
920 libvlc_event_t event
;
921 event
.type
= libvlc_MediaPlayerMediaChanged
;
922 event
.u
.media_player_media_changed
.new_media
= p_md
;
923 libvlc_event_send( &p_mi
->event_manager
, &event
);
927 /**************************************************************************
928 * Get the Media descriptor associated with the instance.
929 **************************************************************************/
931 libvlc_media_player_get_media( libvlc_media_player_t
*p_mi
)
938 libvlc_media_retain( p_m
);
944 /**************************************************************************
945 * Get the event Manager.
946 **************************************************************************/
947 libvlc_event_manager_t
*
948 libvlc_media_player_event_manager( libvlc_media_player_t
*p_mi
)
950 return &p_mi
->event_manager
;
953 static void add_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
)
955 var_AddListCallback( p_input_thread
, "video-es", input_es_changed
, p_mi
);
956 var_AddListCallback( p_input_thread
, "audio-es", input_es_changed
, p_mi
);
957 var_AddListCallback( p_input_thread
, "spu-es", input_es_changed
, p_mi
);
960 static void del_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
)
962 var_DelListCallback( p_input_thread
, "video-es", input_es_changed
, p_mi
);
963 var_DelListCallback( p_input_thread
, "audio-es", input_es_changed
, p_mi
);
964 var_DelListCallback( p_input_thread
, "spu-es", input_es_changed
, p_mi
);
967 static void on_input_event(input_thread_t
*input
,
968 const struct vlc_input_event
*event
, void *userdata
)
970 if (event
->type
== INPUT_EVENT_SUBITEMS
)
972 libvlc_media_player_t
*media_player
= userdata
;
973 libvlc_media_t
*media
= media_player
->p_md
;
974 libvlc_media_add_subtree(media
, event
->subitems
);
977 input_LegacyEvents(input
, event
, userdata
);
980 /**************************************************************************
981 * Tell media player to start playing.
982 **************************************************************************/
983 int libvlc_media_player_play( libvlc_media_player_t
*p_mi
)
987 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
990 /* A thread already exists, send it a play message */
991 var_SetInteger( p_input_thread
, "state", PLAYING_S
);
992 unlock_input( p_mi
);
996 /* Ignore previous exception */
1002 unlock_input( p_mi
);
1003 libvlc_printerr( "No associated media descriptor" );
1007 for( size_t i
= 0; i
< ARRAY_SIZE( p_mi
->selected_es
); ++i
)
1008 p_mi
->selected_es
[i
] = ES_INIT
;
1010 media_attach_preparsed_event( p_mi
->p_md
);
1012 p_input_thread
= input_Create( p_mi
, on_input_event
, p_mi
,
1013 p_mi
->p_md
->p_input_item
, NULL
,
1014 p_mi
->input
.p_resource
,
1015 p_mi
->input
.p_renderer
);
1017 if( !p_input_thread
)
1020 media_detach_preparsed_event( p_mi
->p_md
);
1021 libvlc_printerr( "Not enough memory" );
1025 input_LegacyVarInit( p_input_thread
);
1026 var_AddCallback( p_input_thread
, "can-seek", input_seekable_changed
, p_mi
);
1027 var_AddCallback( p_input_thread
, "can-pause", input_pausable_changed
, p_mi
);
1028 var_AddCallback( p_input_thread
, "program-scrambled", input_scrambled_changed
, p_mi
);
1029 var_AddCallback( p_input_thread
, "intf-event", input_event_changed
, p_mi
);
1030 add_es_callbacks( p_input_thread
, p_mi
);
1032 if( input_Start( p_input_thread
) )
1035 del_es_callbacks( p_input_thread
, p_mi
);
1036 var_DelCallback( p_input_thread
, "intf-event", input_event_changed
, p_mi
);
1037 var_DelCallback( p_input_thread
, "can-pause", input_pausable_changed
, p_mi
);
1038 var_DelCallback( p_input_thread
, "program-scrambled", input_scrambled_changed
, p_mi
);
1039 var_DelCallback( p_input_thread
, "can-seek", input_seekable_changed
, p_mi
);
1040 input_Close( p_input_thread
);
1041 media_detach_preparsed_event( p_mi
->p_md
);
1042 libvlc_printerr( "Input initialization failure" );
1045 p_mi
->input
.p_thread
= p_input_thread
;
1050 void libvlc_media_player_set_pause( libvlc_media_player_t
*p_mi
, int paused
)
1052 input_thread_t
* p_input_thread
= libvlc_get_input_thread( p_mi
);
1053 if( !p_input_thread
)
1058 if( libvlc_media_player_can_pause( p_mi
) )
1059 var_SetInteger( p_input_thread
, "state", PAUSE_S
);
1061 input_Stop( p_input_thread
);
1065 var_SetInteger( p_input_thread
, "state", PLAYING_S
);
1068 vlc_object_release( p_input_thread
);
1071 /**************************************************************************
1073 **************************************************************************/
1074 void libvlc_media_player_pause( libvlc_media_player_t
*p_mi
)
1076 libvlc_media_player_set_pause( p_mi
, libvlc_media_player_is_playing( p_mi
) );
1079 /**************************************************************************
1080 * Tells whether the media player is currently playing.
1081 **************************************************************************/
1082 int libvlc_media_player_is_playing( libvlc_media_player_t
*p_mi
)
1084 libvlc_state_t state
= libvlc_media_player_get_state( p_mi
);
1085 return libvlc_Playing
== state
;
1088 /**************************************************************************
1090 **************************************************************************/
1091 void libvlc_media_player_stop( libvlc_media_player_t
*p_mi
)
1094 release_input_thread( p_mi
); /* This will stop the input thread */
1096 /* Force to go to stopped state, in case we were in Ended, or Error
1098 if( p_mi
->state
!= libvlc_Stopped
)
1100 set_state( p_mi
, libvlc_Stopped
, false );
1102 /* Construct and send the event */
1103 libvlc_event_t event
;
1104 event
.type
= libvlc_MediaPlayerStopped
;
1105 libvlc_event_send( &p_mi
->event_manager
, &event
);
1108 input_resource_Terminate( p_mi
->input
.p_resource
);
1112 int libvlc_media_player_set_renderer( libvlc_media_player_t
*p_mi
,
1113 libvlc_renderer_item_t
*p_litem
)
1115 vlc_renderer_item_t
*p_item
=
1116 p_litem
? libvlc_renderer_item_to_vlc( p_litem
) : NULL
;
1119 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
1120 if( p_input_thread
)
1121 input_Control( p_input_thread
, INPUT_SET_RENDERER
, p_item
);
1123 if( p_mi
->input
.p_renderer
)
1124 vlc_renderer_item_release( p_mi
->input
.p_renderer
);
1125 p_mi
->input
.p_renderer
= p_item
? vlc_renderer_item_hold( p_item
) : NULL
;
1126 unlock_input( p_mi
);
1131 void libvlc_video_set_callbacks( libvlc_media_player_t
*mp
,
1132 void *(*lock_cb
) (void *, void **),
1133 void (*unlock_cb
) (void *, void *, void *const *),
1134 void (*display_cb
) (void *, void *),
1137 var_SetAddress( mp
, "vmem-lock", lock_cb
);
1138 var_SetAddress( mp
, "vmem-unlock", unlock_cb
);
1139 var_SetAddress( mp
, "vmem-display", display_cb
);
1140 var_SetAddress( mp
, "vmem-data", opaque
);
1141 var_SetString( mp
, "avcodec-hw", "none" );
1142 var_SetString( mp
, "vout", "vmem" );
1143 var_SetString( mp
, "window", "dummy" );
1146 void libvlc_video_set_format_callbacks( libvlc_media_player_t
*mp
,
1147 libvlc_video_format_cb setup
,
1148 libvlc_video_cleanup_cb cleanup
)
1150 var_SetAddress( mp
, "vmem-setup", setup
);
1151 var_SetAddress( mp
, "vmem-cleanup", cleanup
);
1154 void libvlc_video_set_format( libvlc_media_player_t
*mp
, const char *chroma
,
1155 unsigned width
, unsigned height
, unsigned pitch
)
1157 var_SetString( mp
, "vmem-chroma", chroma
);
1158 var_SetInteger( mp
, "vmem-width", width
);
1159 var_SetInteger( mp
, "vmem-height", height
);
1160 var_SetInteger( mp
, "vmem-pitch", pitch
);
1163 void libvlc_video_set_opengl_callbacks( libvlc_media_player_t
*mp
,
1164 libvlc_gl_engine_t gl_engine
,
1165 libvlc_gl_setup_cb setup_cb
,
1166 libvlc_gl_cleanup_cb cleanup_cb
,
1167 libvlc_gl_resize_cb resize_cb
,
1168 libvlc_gl_swap_cb swap_cb
,
1169 libvlc_gl_makeCurrent_cb makeCurrent_cb
,
1170 libvlc_gl_getProcAddress_cb getProcAddress_cb
,
1174 //use the default android window
1175 var_SetString( mp
, "window", "");
1177 var_SetString( mp
, "window", "wdummy");
1180 if( gl_engine
== libvlc_gl_engine_gles2
)
1182 var_SetString ( mp
, "vout", "gles2" );
1183 var_SetString ( mp
, "gles2", "vgl" );
1187 var_SetString ( mp
, "vout", "gl" );
1188 var_SetString ( mp
, "gl", "vgl");
1191 var_SetAddress( mp
, "vgl-opaque", opaque
);
1192 var_SetAddress( mp
, "vgl-setup-cb", setup_cb
);
1193 var_SetAddress( mp
, "vgl-cleanup-cb", cleanup_cb
);
1194 var_SetAddress( mp
, "vgl-resize-cb", resize_cb
);
1195 var_SetAddress( mp
, "vgl-swap-cb", swap_cb
);
1196 var_SetAddress( mp
, "vgl-get-proc-address-cb", getProcAddress_cb
);
1197 var_SetAddress( mp
, "vgl-make-current-cb", makeCurrent_cb
);
1201 /**************************************************************************
1203 **************************************************************************/
1204 void libvlc_media_player_set_nsobject( libvlc_media_player_t
*p_mi
,
1207 assert (p_mi
!= NULL
);
1209 var_SetString (p_mi
, "avcodec-hw", "");
1210 var_SetString (p_mi
, "vout", "");
1211 var_SetString (p_mi
, "window", "");
1212 var_SetAddress (p_mi
, "drawable-nsobject", drawable
);
1215 libvlc_printerr ("can't set nsobject: APPLE build required");
1217 var_SetString (p_mi
, "vout", "none");
1218 var_SetString (p_mi
, "window", "none");
1222 /**************************************************************************
1224 **************************************************************************/
1225 void * libvlc_media_player_get_nsobject( libvlc_media_player_t
*p_mi
)
1227 assert (p_mi
!= NULL
);
1229 return var_GetAddress (p_mi
, "drawable-nsobject");
1236 /**************************************************************************
1238 **************************************************************************/
1239 void libvlc_media_player_set_xwindow( libvlc_media_player_t
*p_mi
,
1242 assert (p_mi
!= NULL
);
1244 var_SetString (p_mi
, "avcodec-hw", "");
1245 var_SetString (p_mi
, "vout", "");
1246 var_SetString (p_mi
, "window", drawable
? "embed-xid,any" : "");
1247 var_SetInteger (p_mi
, "drawable-xid", drawable
);
1250 /**************************************************************************
1252 **************************************************************************/
1253 uint32_t libvlc_media_player_get_xwindow( libvlc_media_player_t
*p_mi
)
1255 return var_GetInteger (p_mi
, "drawable-xid");
1258 /**************************************************************************
1260 **************************************************************************/
1261 void libvlc_media_player_set_hwnd( libvlc_media_player_t
*p_mi
,
1264 assert (p_mi
!= NULL
);
1265 #if defined (_WIN32) || defined (__OS2__)
1266 var_SetString (p_mi
, "avcodec-hw", "");
1267 var_SetString (p_mi
, "vout", "");
1268 var_SetString (p_mi
, "window",
1269 (drawable
!= NULL
) ? "embed-hwnd,any" : "");
1270 var_SetInteger (p_mi
, "drawable-hwnd", (uintptr_t)drawable
);
1273 libvlc_printerr ("can't set hwnd: WIN32 build required");
1275 var_SetString (p_mi
, "vout", "none");
1276 var_SetString (p_mi
, "window", "none");
1280 /**************************************************************************
1282 **************************************************************************/
1283 void *libvlc_media_player_get_hwnd( libvlc_media_player_t
*p_mi
)
1285 assert (p_mi
!= NULL
);
1286 #if defined (_WIN32) || defined (__OS2__)
1287 return (void *)(uintptr_t)var_GetInteger (p_mi
, "drawable-hwnd");
1294 /**************************************************************************
1295 * set_android_context
1296 **************************************************************************/
1297 void libvlc_media_player_set_android_context( libvlc_media_player_t
*p_mi
,
1298 void *p_awindow_handler
)
1300 assert (p_mi
!= NULL
);
1302 var_SetAddress (p_mi
, "drawable-androidwindow", p_awindow_handler
);
1304 (void) p_awindow_handler
;
1305 libvlc_printerr ("can't set android context: ANDROID build required");
1307 var_SetString (p_mi
, "vout", "none");
1308 var_SetString (p_mi
, "window", "none");
1312 void libvlc_audio_set_callbacks( libvlc_media_player_t
*mp
,
1313 libvlc_audio_play_cb play_cb
,
1314 libvlc_audio_pause_cb pause_cb
,
1315 libvlc_audio_resume_cb resume_cb
,
1316 libvlc_audio_flush_cb flush_cb
,
1317 libvlc_audio_drain_cb drain_cb
,
1320 var_SetAddress( mp
, "amem-play", play_cb
);
1321 var_SetAddress( mp
, "amem-pause", pause_cb
);
1322 var_SetAddress( mp
, "amem-resume", resume_cb
);
1323 var_SetAddress( mp
, "amem-flush", flush_cb
);
1324 var_SetAddress( mp
, "amem-drain", drain_cb
);
1325 var_SetAddress( mp
, "amem-data", opaque
);
1326 var_SetString( mp
, "aout", "amem,none" );
1328 input_resource_ResetAout(mp
->input
.p_resource
);
1331 void libvlc_audio_set_volume_callback( libvlc_media_player_t
*mp
,
1332 libvlc_audio_set_volume_cb cb
)
1334 var_SetAddress( mp
, "amem-set-volume", cb
);
1336 input_resource_ResetAout(mp
->input
.p_resource
);
1339 void libvlc_audio_set_format_callbacks( libvlc_media_player_t
*mp
,
1340 libvlc_audio_setup_cb setup
,
1341 libvlc_audio_cleanup_cb cleanup
)
1343 var_SetAddress( mp
, "amem-setup", setup
);
1344 var_SetAddress( mp
, "amem-cleanup", cleanup
);
1346 input_resource_ResetAout(mp
->input
.p_resource
);
1349 void libvlc_audio_set_format( libvlc_media_player_t
*mp
, const char *format
,
1350 unsigned rate
, unsigned channels
)
1352 var_SetString( mp
, "amem-format", format
);
1353 var_SetInteger( mp
, "amem-rate", rate
);
1354 var_SetInteger( mp
, "amem-channels", channels
);
1356 input_resource_ResetAout(mp
->input
.p_resource
);
1360 /**************************************************************************
1361 * Getters for stream information
1362 **************************************************************************/
1363 libvlc_time_t
libvlc_media_player_get_length(
1364 libvlc_media_player_t
*p_mi
)
1366 input_thread_t
*p_input_thread
;
1367 libvlc_time_t i_time
;
1369 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1370 if( !p_input_thread
)
1373 i_time
= from_mtime(var_GetInteger( p_input_thread
, "length" ));
1374 vlc_object_release( p_input_thread
);
1379 libvlc_time_t
libvlc_media_player_get_time( libvlc_media_player_t
*p_mi
)
1381 input_thread_t
*p_input_thread
;
1382 libvlc_time_t i_time
;
1384 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1385 if( !p_input_thread
)
1388 i_time
= from_mtime(var_GetInteger( p_input_thread
, "time" ));
1389 vlc_object_release( p_input_thread
);
1393 int libvlc_media_player_set_time( libvlc_media_player_t
*p_mi
,
1394 libvlc_time_t i_time
, bool b_fast
)
1396 input_thread_t
*p_input_thread
;
1398 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1399 if( !p_input_thread
)
1402 input_SetTime( p_input_thread
, to_mtime(i_time
), b_fast
);
1403 vlc_object_release( p_input_thread
);
1407 int libvlc_media_player_set_position( libvlc_media_player_t
*p_mi
,
1408 float position
, bool b_fast
)
1410 input_thread_t
*p_input_thread
;
1412 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1413 if( !p_input_thread
)
1416 input_SetPosition( p_input_thread
, position
, b_fast
);
1417 vlc_object_release( p_input_thread
);
1421 float libvlc_media_player_get_position( libvlc_media_player_t
*p_mi
)
1423 input_thread_t
*p_input_thread
;
1426 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1427 if( !p_input_thread
)
1430 f_position
= var_GetFloat( p_input_thread
, "position" );
1431 vlc_object_release( p_input_thread
);
1436 void libvlc_media_player_set_chapter( libvlc_media_player_t
*p_mi
,
1439 input_thread_t
*p_input_thread
;
1441 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1442 if( !p_input_thread
)
1445 var_SetInteger( p_input_thread
, "chapter", chapter
);
1446 vlc_object_release( p_input_thread
);
1449 int libvlc_media_player_get_chapter( libvlc_media_player_t
*p_mi
)
1451 input_thread_t
*p_input_thread
;
1454 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1455 if( !p_input_thread
)
1458 i_chapter
= var_GetInteger( p_input_thread
, "chapter" );
1459 vlc_object_release( p_input_thread
);
1464 int libvlc_media_player_get_chapter_count( libvlc_media_player_t
*p_mi
)
1466 input_thread_t
*p_input_thread
;
1469 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1470 if( !p_input_thread
)
1473 int i_ret
= var_Change( p_input_thread
, "chapter", VLC_VAR_CHOICESCOUNT
, &val
);
1474 vlc_object_release( p_input_thread
);
1476 return i_ret
== VLC_SUCCESS
? (ssize_t
)val
: -1;
1479 int libvlc_media_player_get_chapter_count_for_title(
1480 libvlc_media_player_t
*p_mi
,
1485 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1486 if( !p_input_thread
)
1489 char psz_name
[sizeof ("title ") + 3 * sizeof (int)];
1490 sprintf( psz_name
, "title %2u", i_title
);
1492 int i_ret
= var_Change( p_input_thread
, psz_name
, VLC_VAR_CHOICESCOUNT
, &val
);
1493 vlc_object_release( p_input_thread
);
1495 return i_ret
== VLC_SUCCESS
? (ssize_t
)val
: -1;
1498 void libvlc_media_player_set_title( libvlc_media_player_t
*p_mi
,
1501 input_thread_t
*p_input_thread
;
1503 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1504 if( !p_input_thread
)
1507 var_SetInteger( p_input_thread
, "title", i_title
);
1508 vlc_object_release( p_input_thread
);
1511 libvlc_event_t event
;
1512 event
.type
= libvlc_MediaPlayerTitleChanged
;
1513 event
.u
.media_player_title_changed
.new_title
= i_title
;
1514 libvlc_event_send( &p_mi
->event_manager
, &event
);
1517 int libvlc_media_player_get_title( libvlc_media_player_t
*p_mi
)
1519 input_thread_t
*p_input_thread
;
1522 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1523 if( !p_input_thread
)
1526 i_title
= var_GetInteger( p_input_thread
, "title" );
1527 vlc_object_release( p_input_thread
);
1532 int libvlc_media_player_get_title_count( libvlc_media_player_t
*p_mi
)
1534 input_thread_t
*p_input_thread
;
1537 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1538 if( !p_input_thread
)
1541 int i_ret
= var_Change( p_input_thread
, "title", VLC_VAR_CHOICESCOUNT
, &val
);
1542 vlc_object_release( p_input_thread
);
1544 return i_ret
== VLC_SUCCESS
? (ssize_t
)val
: -1;
1547 int libvlc_media_player_get_full_title_descriptions( libvlc_media_player_t
*p_mi
,
1548 libvlc_title_description_t
*** pp_titles
)
1552 input_thread_t
*p_input_thread
= libvlc_get_input_thread( p_mi
);
1554 if( !p_input_thread
)
1557 input_title_t
**p_input_title
;
1561 int ret
= input_Control( p_input_thread
, INPUT_GET_FULL_TITLE_INFO
,
1562 &p_input_title
, &count
);
1563 vlc_object_release( p_input_thread
);
1564 if( ret
!= VLC_SUCCESS
)
1567 libvlc_title_description_t
**titles
= vlc_alloc( count
, sizeof (*titles
) );
1568 if( count
> 0 && unlikely(titles
== NULL
) )
1572 for( int i
= 0; i
< count
; i
++)
1574 libvlc_title_description_t
*title
= malloc( sizeof (*title
) );
1575 if( unlikely(title
== NULL
) )
1577 libvlc_title_descriptions_release( titles
, i
);
1582 /* we want to return milliseconds to match the rest of the API */
1583 title
->i_duration
= MS_FROM_VLC_TICK(p_input_title
[i
]->i_length
);
1584 title
->i_flags
= p_input_title
[i
]->i_flags
;
1585 if( p_input_title
[i
]->psz_name
)
1586 title
->psz_name
= strdup( p_input_title
[i
]->psz_name
);
1588 title
->psz_name
= NULL
;
1589 vlc_input_title_Delete( p_input_title
[i
] );
1591 free( p_input_title
);
1593 *pp_titles
= titles
;
1597 void libvlc_title_descriptions_release( libvlc_title_description_t
**p_titles
,
1600 for (unsigned i
= 0; i
< i_count
; i
++ )
1605 free( p_titles
[i
]->psz_name
);
1606 free( p_titles
[i
] );
1611 int libvlc_media_player_get_full_chapter_descriptions( libvlc_media_player_t
*p_mi
,
1612 int i_chapters_of_title
,
1613 libvlc_chapter_description_t
*** pp_chapters
)
1617 input_thread_t
*p_input_thread
= libvlc_get_input_thread( p_mi
);
1619 if( !p_input_thread
)
1622 seekpoint_t
**p_seekpoint
= NULL
;
1623 input_title_t
**pp_title
, *p_title
= NULL
;
1624 int i_title_count
= 0, ci_chapter_count
= 0;
1625 int ret
= input_Control( p_input_thread
, INPUT_GET_FULL_TITLE_INFO
, &pp_title
,
1627 vlc_object_release( p_input_thread
);
1629 if( ret
!= VLC_SUCCESS
|| i_chapters_of_title
>= i_title_count
)
1632 p_title
= pp_title
[i_chapters_of_title
];
1633 int64_t i_title_duration
= MS_FROM_VLC_TICK(p_title
->i_length
);
1634 p_seekpoint
= p_title
->seekpoint
;
1635 ci_chapter_count
= p_title
->i_seekpoint
;
1637 if( ci_chapter_count
== 0 || p_seekpoint
== NULL
)
1640 *pp_chapters
= calloc( ci_chapter_count
, sizeof(**pp_chapters
) );
1647 for( int i
= 0; i
< ci_chapter_count
; ++i
)
1649 libvlc_chapter_description_t
*p_chapter
= malloc( sizeof(*p_chapter
) );
1650 if( unlikely(p_chapter
== NULL
) )
1654 (*pp_chapters
)[i
] = p_chapter
;
1656 p_chapter
->i_time_offset
= MS_FROM_VLC_TICK( p_seekpoint
[i
]->i_time_offset
);
1658 if( i
< ci_chapter_count
- 1 )
1660 p_chapter
->i_duration
= MS_FROM_VLC_TICK( p_seekpoint
[i
+ 1]->i_time_offset
) -
1661 p_chapter
->i_time_offset
;
1665 if ( i_title_duration
)
1666 p_chapter
->i_duration
= i_title_duration
- p_chapter
->i_time_offset
;
1668 p_chapter
->i_duration
= 0;
1671 if( p_seekpoint
[i
]->psz_name
)
1673 p_chapter
->psz_name
= strdup( p_seekpoint
[i
]->psz_name
);
1677 p_chapter
->psz_name
= NULL
;
1679 vlc_seekpoint_Delete( p_seekpoint
[i
] );
1680 p_seekpoint
[i
] = NULL
;
1683 free( p_seekpoint
);
1684 return ci_chapter_count
;
1688 libvlc_chapter_descriptions_release( *pp_chapters
, ci_chapter_count
);
1689 for( int i
= 0; i
< i_title_count
; i
++ )
1690 vlc_input_title_Delete( pp_title
[i
] );
1695 void libvlc_chapter_descriptions_release( libvlc_chapter_description_t
**p_chapters
,
1698 for (unsigned i
= 0; i
< i_count
; i
++ )
1700 if ( !p_chapters
[i
] )
1703 free( p_chapters
[i
]->psz_name
);
1704 free( p_chapters
[i
] );
1709 void libvlc_media_player_next_chapter( libvlc_media_player_t
*p_mi
)
1711 input_thread_t
*p_input_thread
;
1713 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1714 if( !p_input_thread
)
1717 int i_type
= var_Type( p_input_thread
, "next-chapter" );
1718 var_TriggerCallback( p_input_thread
, (i_type
& VLC_VAR_TYPE
) != 0 ?
1719 "next-chapter":"next-title" );
1721 vlc_object_release( p_input_thread
);
1724 void libvlc_media_player_previous_chapter( libvlc_media_player_t
*p_mi
)
1726 input_thread_t
*p_input_thread
;
1728 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1729 if( !p_input_thread
)
1732 int i_type
= var_Type( p_input_thread
, "next-chapter" );
1733 var_TriggerCallback( p_input_thread
, (i_type
& VLC_VAR_TYPE
) != 0 ?
1734 "prev-chapter":"prev-title" );
1736 vlc_object_release( p_input_thread
);
1739 int libvlc_media_player_will_play( libvlc_media_player_t
*p_mi
)
1741 input_thread_t
*p_input_thread
=
1742 libvlc_get_input_thread ( p_mi
);
1743 if ( !p_input_thread
)
1746 int state
= var_GetInteger( p_input_thread
, "state" );
1747 vlc_object_release( p_input_thread
);
1749 return state
!= END_S
&& state
!= ERROR_S
;
1752 int libvlc_media_player_set_rate( libvlc_media_player_t
*p_mi
, float rate
)
1754 var_SetFloat (p_mi
, "rate", rate
);
1756 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1757 if( !p_input_thread
)
1759 var_SetFloat( p_input_thread
, "rate", rate
);
1760 vlc_object_release( p_input_thread
);
1764 float libvlc_media_player_get_rate( libvlc_media_player_t
*p_mi
)
1766 return var_GetFloat (p_mi
, "rate");
1769 libvlc_state_t
libvlc_media_player_get_state( libvlc_media_player_t
*p_mi
)
1772 libvlc_state_t state
= p_mi
->state
;
1777 int libvlc_media_player_is_seekable( libvlc_media_player_t
*p_mi
)
1779 input_thread_t
*p_input_thread
;
1782 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1783 if ( !p_input_thread
)
1785 b_seekable
= var_GetBool( p_input_thread
, "can-seek" );
1786 vlc_object_release( p_input_thread
);
1791 void libvlc_media_player_navigate( libvlc_media_player_t
* p_mi
,
1794 static const int map
[] =
1796 INPUT_NAV_ACTIVATE
, INPUT_NAV_UP
, INPUT_NAV_DOWN
,
1797 INPUT_NAV_LEFT
, INPUT_NAV_RIGHT
, INPUT_NAV_POPUP
,
1800 if( navigate
>= sizeof(map
) / sizeof(map
[0]) )
1803 input_thread_t
*p_input
= libvlc_get_input_thread ( p_mi
);
1804 if ( p_input
== NULL
)
1807 input_Control( p_input
, map
[navigate
], NULL
);
1808 vlc_object_release( p_input
);
1811 /* internal function, used by audio, video */
1812 libvlc_track_description_t
*
1813 libvlc_get_track_description( libvlc_media_player_t
*p_mi
,
1814 const char *psz_variable
)
1816 input_thread_t
*p_input
= libvlc_get_input_thread( p_mi
);
1817 libvlc_track_description_t
*ret
, **pp
= &ret
;
1822 vlc_value_t
*val_list
;
1826 int i_ret
= var_Change( p_input
, psz_variable
, VLC_VAR_GETCHOICES
,
1827 &count
, &val_list
, &text_list
);
1828 if( i_ret
!= VLC_SUCCESS
)
1831 for (size_t i
= 0; i
< count
; i
++)
1833 libvlc_track_description_t
*tr
= malloc(sizeof (*tr
));
1834 if (unlikely(tr
== NULL
))
1836 libvlc_printerr("Not enough memory");
1841 tr
->i_id
= val_list
[i
].i_int
;
1842 tr
->psz_name
= text_list
[i
];
1849 vlc_object_release( p_input
);
1854 void libvlc_track_description_list_release( libvlc_track_description_t
*p_td
)
1856 libvlc_track_description_t
*p_actual
, *p_before
;
1861 free( p_actual
->psz_name
);
1862 p_before
= p_actual
;
1863 p_actual
= p_before
->p_next
;
1868 int libvlc_media_player_can_pause( libvlc_media_player_t
*p_mi
)
1870 input_thread_t
*p_input_thread
;
1873 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1874 if ( !p_input_thread
)
1876 b_can_pause
= var_GetBool( p_input_thread
, "can-pause" );
1877 vlc_object_release( p_input_thread
);
1882 int libvlc_media_player_program_scrambled( libvlc_media_player_t
*p_mi
)
1884 input_thread_t
*p_input_thread
;
1885 bool b_program_scrambled
;
1887 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1888 if ( !p_input_thread
)
1890 b_program_scrambled
= var_GetBool( p_input_thread
, "program-scrambled" );
1891 vlc_object_release( p_input_thread
);
1893 return b_program_scrambled
;
1896 void libvlc_media_player_next_frame( libvlc_media_player_t
*p_mi
)
1898 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1899 if( p_input_thread
!= NULL
)
1901 var_TriggerCallback( p_input_thread
, "frame-next" );
1902 vlc_object_release( p_input_thread
);
1907 * Private lookup table to get subpicture alignment flag values corresponding
1908 * to a libvlc_position_t enumerated value.
1910 static const unsigned char position_subpicture_alignment
[] = {
1911 [libvlc_position_center
] = 0,
1912 [libvlc_position_left
] = SUBPICTURE_ALIGN_LEFT
,
1913 [libvlc_position_right
] = SUBPICTURE_ALIGN_RIGHT
,
1914 [libvlc_position_top
] = SUBPICTURE_ALIGN_TOP
,
1915 [libvlc_position_top_left
] = SUBPICTURE_ALIGN_TOP
| SUBPICTURE_ALIGN_LEFT
,
1916 [libvlc_position_top_right
] = SUBPICTURE_ALIGN_TOP
| SUBPICTURE_ALIGN_RIGHT
,
1917 [libvlc_position_bottom
] = SUBPICTURE_ALIGN_BOTTOM
,
1918 [libvlc_position_bottom_left
] = SUBPICTURE_ALIGN_BOTTOM
| SUBPICTURE_ALIGN_LEFT
,
1919 [libvlc_position_bottom_right
] = SUBPICTURE_ALIGN_BOTTOM
| SUBPICTURE_ALIGN_RIGHT
1922 void libvlc_media_player_set_video_title_display( libvlc_media_player_t
*p_mi
, libvlc_position_t position
, unsigned timeout
)
1924 assert( position
>= libvlc_position_disable
&& position
<= libvlc_position_bottom_right
);
1926 if ( position
!= libvlc_position_disable
)
1928 var_SetBool( p_mi
, "video-title-show", true );
1929 var_SetInteger( p_mi
, "video-title-position", position_subpicture_alignment
[position
] );
1930 var_SetInteger( p_mi
, "video-title-timeout", timeout
);
1934 var_SetBool( p_mi
, "video-title-show", false );
1938 int libvlc_media_player_add_slave( libvlc_media_player_t
*p_mi
,
1939 libvlc_media_slave_type_t i_type
,
1940 const char *psz_uri
, bool b_select
)
1942 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1944 if( p_input_thread
== NULL
)
1946 libvlc_media_t
*p_media
= libvlc_media_player_get_media( p_mi
);
1947 if( p_media
== NULL
)
1950 int i_ret
= libvlc_media_slaves_add( p_media
, i_type
, 4, psz_uri
);
1951 libvlc_media_release( p_media
);
1956 int i_ret
= input_AddSlave( p_input_thread
, (enum slave_type
) i_type
,
1957 psz_uri
, b_select
, false, false );
1958 vlc_object_release( p_input_thread
);
1960 return i_ret
== VLC_SUCCESS
? 0 : -1;
1965 * Maximum size of a formatted equalizer amplification band frequency value.
1967 * The allowed value range is supposed to be constrained from -20.0 to 20.0.
1969 * The format string " %.07f" with a minimum value of "-20" gives a maximum
1970 * string length of e.g. " -19.1234567", i.e. 12 bytes (not including the null
1973 #define EQZ_BAND_VALUE_SIZE 12
1975 int libvlc_media_player_set_equalizer( libvlc_media_player_t
*p_mi
, libvlc_equalizer_t
*p_equalizer
)
1977 char bands
[EQZ_BANDS_MAX
* EQZ_BAND_VALUE_SIZE
+ 1];
1979 if( p_equalizer
!= NULL
)
1981 for( unsigned i
= 0, c
= 0; i
< EQZ_BANDS_MAX
; i
++ )
1983 c
+= snprintf( bands
+ c
, sizeof(bands
) - c
, " %.07f",
1984 p_equalizer
->f_amp
[i
] );
1985 if( unlikely(c
>= sizeof(bands
)) )
1989 var_SetFloat( p_mi
, "equalizer-preamp", p_equalizer
->f_preamp
);
1990 var_SetString( p_mi
, "equalizer-bands", bands
);
1992 var_SetString( p_mi
, "audio-filter", p_equalizer
? "equalizer" : "" );
1994 audio_output_t
*p_aout
= input_resource_HoldAout( p_mi
->input
.p_resource
);
1995 if( p_aout
!= NULL
)
1997 if( p_equalizer
!= NULL
)
1999 var_SetFloat( p_aout
, "equalizer-preamp", p_equalizer
->f_preamp
);
2000 var_SetString( p_aout
, "equalizer-bands", bands
);
2003 var_SetString( p_aout
, "audio-filter", p_equalizer
? "equalizer" : "" );
2004 vlc_object_release( p_aout
);
2010 static const char roles
[][16] =
2012 [libvlc_role_Music
] = "music",
2013 [libvlc_role_Video
] = "video",
2014 [libvlc_role_Communication
] = "communication",
2015 [libvlc_role_Game
] = "game",
2016 [libvlc_role_Notification
] = "notification",
2017 [libvlc_role_Animation
] = "animation",
2018 [libvlc_role_Production
] = "production",
2019 [libvlc_role_Accessibility
] = "accessibility",
2020 [libvlc_role_Test
] = "test",
2023 int libvlc_media_player_set_role(libvlc_media_player_t
*mp
, unsigned role
)
2025 if (role
>= ARRAY_SIZE(roles
)
2026 || var_SetString(mp
, "role", roles
[role
]) != VLC_SUCCESS
)
2031 int libvlc_media_player_get_role(libvlc_media_player_t
*mp
)
2034 char *str
= var_GetString(mp
, "role");
2038 for (size_t i
= 0; i
< ARRAY_SIZE(roles
); i
++)
2039 if (!strcmp(roles
[i
], str
))