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_media.h>
32 #include <vlc/libvlc_events.h>
34 #include <vlc_demux.h>
35 #include <vlc_input.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 */
48 input_seekable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
49 vlc_value_t oldval
, vlc_value_t newval
,
52 input_pausable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
53 vlc_value_t oldval
, vlc_value_t newval
,
56 input_scrambled_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
57 vlc_value_t oldval
, vlc_value_t newval
,
60 input_event_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
61 vlc_value_t oldval
, vlc_value_t newval
,
65 input_es_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
66 int action
, vlc_value_t
*p_val
,
70 corks_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
71 vlc_value_t cur
, void *opaque
);
74 mute_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
75 vlc_value_t cur
, void *opaque
);
78 volume_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
79 vlc_value_t cur
, void *opaque
);
82 add_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
);
85 del_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
);
88 snapshot_was_taken( vlc_object_t
*p_this
, char const *psz_cmd
,
89 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
);
91 static void libvlc_media_player_destroy( libvlc_media_player_t
*p_mi
);
98 * The input lock protects the input and input resource pointer.
99 * It MUST NOT be used from callbacks.
101 * The object lock protects the reset, namely the media and the player state.
102 * It can, and usually needs to be taken from callbacks.
103 * The object lock can be acquired under the input lock... and consequently
104 * the opposite order is STRICTLY PROHIBITED.
106 static inline void lock(libvlc_media_player_t
*mp
)
108 vlc_mutex_lock(&mp
->object_lock
);
111 static inline void unlock(libvlc_media_player_t
*mp
)
113 vlc_mutex_unlock(&mp
->object_lock
);
116 static inline void lock_input(libvlc_media_player_t
*mp
)
118 vlc_mutex_lock(&mp
->input
.lock
);
121 static inline void unlock_input(libvlc_media_player_t
*mp
)
123 vlc_mutex_unlock(&mp
->input
.lock
);
126 static void input_item_preparsed_changed( const vlc_event_t
*p_event
,
129 libvlc_media_t
*p_md
= user_data
;
130 if( p_event
->u
.input_item_preparsed_changed
.new_status
& ITEM_PREPARSED
)
133 libvlc_event_t event
;
134 event
.type
= libvlc_MediaParsedChanged
;
135 event
.u
.media_parsed_changed
.new_status
= libvlc_media_parsed_status_done
;
136 libvlc_event_send( &p_md
->event_manager
, &event
);
140 static void media_attach_preparsed_event( libvlc_media_t
*p_md
)
142 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
143 vlc_InputItemPreparsedChanged
,
144 input_item_preparsed_changed
, p_md
);
147 static void media_detach_preparsed_event( libvlc_media_t
*p_md
)
149 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
150 vlc_InputItemPreparsedChanged
,
151 input_item_preparsed_changed
,
156 * Release the associated input thread.
158 * Object lock is NOT held.
159 * Input lock is held or instance is being destroyed.
161 static void release_input_thread( libvlc_media_player_t
*p_mi
)
165 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
166 if( !p_input_thread
)
168 p_mi
->input
.p_thread
= NULL
;
170 media_detach_preparsed_event( p_mi
->p_md
);
172 var_DelCallback( p_input_thread
, "can-seek",
173 input_seekable_changed
, p_mi
);
174 var_DelCallback( p_input_thread
, "can-pause",
175 input_pausable_changed
, p_mi
);
176 var_DelCallback( p_input_thread
, "program-scrambled",
177 input_scrambled_changed
, p_mi
);
178 var_DelCallback( p_input_thread
, "intf-event",
179 input_event_changed
, p_mi
);
180 del_es_callbacks( p_input_thread
, p_mi
);
182 /* We owned this one */
183 input_Stop( p_input_thread
);
184 input_Close( p_input_thread
);
188 * Retrieve the input thread. Be sure to release the object
189 * once you are done with it. (libvlc Internal)
191 input_thread_t
*libvlc_get_input_thread( libvlc_media_player_t
*p_mi
)
193 input_thread_t
*p_input_thread
;
198 p_input_thread
= p_mi
->input
.p_thread
;
200 vlc_object_hold( p_input_thread
);
202 libvlc_printerr( "No active input" );
205 return p_input_thread
;
209 * Set the internal state of the media_player. (media player Internal)
211 * Function will lock the media_player.
213 static void set_state( libvlc_media_player_t
*p_mi
, libvlc_state_t state
,
220 libvlc_media_t
*media
= p_mi
->p_md
;
222 libvlc_media_retain(media
);
229 // Also set the state of the corresponding media
230 // This is strictly for convenience.
231 libvlc_media_set_state(media
, state
);
233 libvlc_media_release(media
);
238 input_seekable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
239 vlc_value_t oldval
, vlc_value_t newval
,
245 libvlc_media_player_t
* p_mi
= p_userdata
;
246 libvlc_event_t event
;
248 event
.type
= libvlc_MediaPlayerSeekableChanged
;
249 event
.u
.media_player_seekable_changed
.new_seekable
= newval
.b_bool
;
251 libvlc_event_send( &p_mi
->event_manager
, &event
);
256 input_pausable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
257 vlc_value_t oldval
, vlc_value_t newval
,
263 libvlc_media_player_t
* p_mi
= p_userdata
;
264 libvlc_event_t event
;
266 event
.type
= libvlc_MediaPlayerPausableChanged
;
267 event
.u
.media_player_pausable_changed
.new_pausable
= newval
.b_bool
;
269 libvlc_event_send( &p_mi
->event_manager
, &event
);
274 input_scrambled_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
275 vlc_value_t oldval
, vlc_value_t newval
,
281 libvlc_media_player_t
* p_mi
= p_userdata
;
282 libvlc_event_t event
;
284 event
.type
= libvlc_MediaPlayerScrambledChanged
;
285 event
.u
.media_player_scrambled_changed
.new_scrambled
= newval
.b_bool
;
287 libvlc_event_send( &p_mi
->event_manager
, &event
);
292 input_event_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
293 vlc_value_t oldval
, vlc_value_t newval
,
296 VLC_UNUSED(oldval
); VLC_UNUSED(psz_cmd
);
297 input_thread_t
* p_input
= (input_thread_t
*)p_this
;
298 libvlc_media_player_t
* p_mi
= p_userdata
;
299 libvlc_event_t event
;
301 assert( !strcmp( psz_cmd
, "intf-event" ) );
303 if( newval
.i_int
== INPUT_EVENT_STATE
)
305 libvlc_state_t libvlc_state
;
307 switch ( var_GetInteger( p_input
, "state" ) )
310 libvlc_state
= libvlc_NothingSpecial
;
311 event
.type
= libvlc_MediaPlayerNothingSpecial
;
314 libvlc_state
= libvlc_Opening
;
315 event
.type
= libvlc_MediaPlayerOpening
;
318 libvlc_state
= libvlc_Playing
;
319 event
.type
= libvlc_MediaPlayerPlaying
;
322 libvlc_state
= libvlc_Paused
;
323 event
.type
= libvlc_MediaPlayerPaused
;
326 libvlc_state
= libvlc_Ended
;
327 event
.type
= libvlc_MediaPlayerEndReached
;
330 libvlc_state
= libvlc_Error
;
331 event
.type
= libvlc_MediaPlayerEncounteredError
;
338 set_state( p_mi
, libvlc_state
, false );
339 libvlc_event_send( &p_mi
->event_manager
, &event
);
341 else if( newval
.i_int
== INPUT_EVENT_DEAD
)
343 libvlc_state_t libvlc_state
= libvlc_Ended
;
344 event
.type
= libvlc_MediaPlayerStopped
;
346 set_state( p_mi
, libvlc_state
, false );
347 libvlc_event_send( &p_mi
->event_manager
, &event
);
349 else if( newval
.i_int
== INPUT_EVENT_POSITION
)
351 if( var_GetInteger( p_input
, "state" ) != PLAYING_S
)
352 return VLC_SUCCESS
; /* Don't send the position while stopped */
355 event
.type
= libvlc_MediaPlayerPositionChanged
;
356 event
.u
.media_player_position_changed
.new_position
=
357 var_GetFloat( p_input
, "position" );
358 libvlc_event_send( &p_mi
->event_manager
, &event
);
361 event
.type
= libvlc_MediaPlayerTimeChanged
;
362 event
.u
.media_player_time_changed
.new_time
=
363 from_mtime(var_GetInteger( p_input
, "time" ));
364 libvlc_event_send( &p_mi
->event_manager
, &event
);
366 else if( newval
.i_int
== INPUT_EVENT_LENGTH
)
368 event
.type
= libvlc_MediaPlayerLengthChanged
;
369 event
.u
.media_player_length_changed
.new_length
=
370 from_mtime(var_GetInteger( p_input
, "length" ));
371 libvlc_event_send( &p_mi
->event_manager
, &event
);
373 else if( newval
.i_int
== INPUT_EVENT_CACHE
)
375 event
.type
= libvlc_MediaPlayerBuffering
;
376 event
.u
.media_player_buffering
.new_cache
= (100 *
377 var_GetFloat( p_input
, "cache" ));
378 libvlc_event_send( &p_mi
->event_manager
, &event
);
380 else if( newval
.i_int
== INPUT_EVENT_VOUT
)
382 vout_thread_t
**pp_vout
;
384 if( input_Control( p_input
, INPUT_GET_VOUTS
, &pp_vout
, &i_vout
) )
390 for( size_t i
= 0; i
< i_vout
; i
++ )
391 vlc_object_release( pp_vout
[i
] );
395 event
.type
= libvlc_MediaPlayerVout
;
396 event
.u
.media_player_vout
.new_count
= i_vout
;
397 libvlc_event_send( &p_mi
->event_manager
, &event
);
399 else if ( newval
.i_int
== INPUT_EVENT_TITLE
)
401 event
.type
= libvlc_MediaPlayerTitleChanged
;
402 event
.u
.media_player_title_changed
.new_title
= var_GetInteger( p_input
, "title" );
403 libvlc_event_send( &p_mi
->event_manager
, &event
);
405 else if ( newval
.i_int
== INPUT_EVENT_CHAPTER
)
407 event
.type
= libvlc_MediaPlayerChapterChanged
;
408 event
.u
.media_player_chapter_changed
.new_chapter
= var_GetInteger( p_input
, "chapter" );
409 libvlc_event_send( &p_mi
->event_manager
, &event
);
411 else if ( newval
.i_int
== INPUT_EVENT_ES
)
413 /* Send ESSelected events from this callback ("intf-event") and not
414 * from "audio-es", "video-es", "spu-es" callbacks. Indeed, these
415 * callbacks are not triggered when the input_thread changes an ES
416 * while this callback is. */
418 const char *psz_name
;
419 const libvlc_track_type_t type
;
422 { "audio-es", libvlc_track_audio
, ES_INIT
},
423 { "video-es", libvlc_track_video
, ES_INIT
},
424 { "spu-es", libvlc_track_text
, ES_INIT
},
426 /* Check if an ES selection changed */
428 for( size_t i
= 0; i
< ARRAY_SIZE( es_list
); ++i
)
430 int current_es
= var_GetInteger( p_input
, es_list
[i
].psz_name
);
431 if( current_es
!= p_mi
->selected_es
[i
] )
432 es_list
[i
].new_es
= p_mi
->selected_es
[i
] = current_es
;
436 /* Send the ESSelected event for each ES that were newly selected */
437 for( size_t i
= 0; i
< ARRAY_SIZE( es_list
); ++i
)
439 if( es_list
[i
].new_es
!= ES_INIT
)
441 event
.type
= libvlc_MediaPlayerESSelected
;
442 event
.u
.media_player_es_changed
.i_type
= es_list
[i
].type
;
443 event
.u
.media_player_es_changed
.i_id
= es_list
[i
].new_es
;
444 libvlc_event_send( &p_mi
->event_manager
, &event
);
452 static int track_type_from_name(const char *psz_name
)
454 if( !strcmp( psz_name
, "video-es" ) )
455 return libvlc_track_video
;
456 else if( !strcmp( psz_name
, "audio-es" ) )
457 return libvlc_track_audio
;
458 else if( !strcmp( psz_name
, "spu-es" ) )
459 return libvlc_track_text
;
461 return libvlc_track_unknown
;
464 static int input_es_changed( vlc_object_t
*p_this
,
471 libvlc_media_player_t
*mp
= p_userdata
;
472 libvlc_event_t event
;
474 /* Ignore the "Disable" element */
475 if (p_val
&& p_val
->i_int
< 0)
480 case VLC_VAR_ADDCHOICE
:
481 event
.type
= libvlc_MediaPlayerESAdded
;
483 case VLC_VAR_DELCHOICE
:
484 case VLC_VAR_CLEARCHOICES
:
485 event
.type
= libvlc_MediaPlayerESDeleted
;
491 event
.u
.media_player_es_changed
.i_type
= track_type_from_name(psz_cmd
);
494 if (action
!= VLC_VAR_CLEARCHOICES
)
502 /* -1 means all ES tracks of this type were deleted. */
505 event
.u
.media_player_es_changed
.i_id
= i_id
;
507 libvlc_event_send(&mp
->event_manager
, &event
);
512 /**************************************************************************
513 * Snapshot Taken Event.
515 * FIXME: This snapshot API interface makes no sense in media_player.
516 *************************************************************************/
517 static int snapshot_was_taken(vlc_object_t
*p_this
, char const *psz_cmd
,
518 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
520 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_this
);
522 libvlc_media_player_t
*mp
= p_data
;
523 libvlc_event_t event
;
524 event
.type
= libvlc_MediaPlayerSnapshotTaken
;
525 event
.u
.media_player_snapshot_taken
.psz_filename
= newval
.psz_string
;
526 libvlc_event_send(&mp
->event_manager
, &event
);
531 static int corks_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
532 vlc_value_t cur
, void *opaque
)
534 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
536 if (!old
.i_int
!= !cur
.i_int
)
538 libvlc_event_t event
;
540 event
.type
= cur
.i_int
? libvlc_MediaPlayerCorked
541 : libvlc_MediaPlayerUncorked
;
542 libvlc_event_send(&mp
->event_manager
, &event
);
544 VLC_UNUSED(name
); VLC_UNUSED(opaque
);
548 static int audio_device_changed(vlc_object_t
*obj
, const char *name
,
549 vlc_value_t old
, vlc_value_t cur
, void *opaque
)
551 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
552 libvlc_event_t event
;
554 event
.type
= libvlc_MediaPlayerAudioDevice
;
555 event
.u
.media_player_audio_device
.device
= cur
.psz_string
;
556 libvlc_event_send(&mp
->event_manager
, &event
);
557 VLC_UNUSED(name
); VLC_UNUSED(old
); VLC_UNUSED(opaque
);
561 static int mute_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
562 vlc_value_t cur
, void *opaque
)
564 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
566 if (old
.b_bool
!= cur
.b_bool
)
568 libvlc_event_t event
;
570 event
.type
= cur
.b_bool
? libvlc_MediaPlayerMuted
571 : libvlc_MediaPlayerUnmuted
;
572 libvlc_event_send(&mp
->event_manager
, &event
);
574 VLC_UNUSED(name
); VLC_UNUSED(opaque
);
578 static int volume_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
579 vlc_value_t cur
, void *opaque
)
581 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
582 libvlc_event_t event
;
584 event
.type
= libvlc_MediaPlayerAudioVolume
;
585 event
.u
.media_player_audio_volume
.volume
= cur
.f_float
;
586 libvlc_event_send(&mp
->event_manager
, &event
);
587 VLC_UNUSED(name
); VLC_UNUSED(old
); VLC_UNUSED(opaque
);
591 /**************************************************************************
592 * Create a Media Instance object.
595 * - All items created by _new start with a refcount set to 1.
596 * - Accessor _release decrease the refcount by 1, if after that
597 * operation the refcount is 0, the object is destroyed.
598 * - Accessor _retain increase the refcount by 1 (XXX: to implement)
600 * Object locking strategy:
601 * - No lock held while in constructor.
602 * - When accessing any member variable this lock is held. (XXX who locks?)
603 * - When attempting to destroy the object the lock is also held.
604 **************************************************************************/
605 libvlc_media_player_t
*
606 libvlc_media_player_new( libvlc_instance_t
*instance
)
608 libvlc_media_player_t
* mp
;
612 mp
= vlc_object_create (instance
->p_libvlc_int
, sizeof(*mp
));
613 if (unlikely(mp
== NULL
))
615 libvlc_printerr("Not enough memory");
620 var_Create (mp
, "rate", VLC_VAR_FLOAT
|VLC_VAR_DOINHERIT
);
621 var_Create (mp
, "sout", VLC_VAR_STRING
);
622 var_Create (mp
, "demux-filter", VLC_VAR_STRING
);
625 var_Create (mp
, "vout", VLC_VAR_STRING
|VLC_VAR_DOINHERIT
);
626 var_Create (mp
, "window", VLC_VAR_STRING
);
627 var_Create (mp
, "vmem-lock", VLC_VAR_ADDRESS
);
628 var_Create (mp
, "vmem-unlock", VLC_VAR_ADDRESS
);
629 var_Create (mp
, "vmem-display", VLC_VAR_ADDRESS
);
630 var_Create (mp
, "vmem-data", VLC_VAR_ADDRESS
);
631 var_Create (mp
, "vmem-setup", VLC_VAR_ADDRESS
);
632 var_Create (mp
, "vmem-cleanup", VLC_VAR_ADDRESS
);
633 var_Create (mp
, "vmem-chroma", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
634 var_Create (mp
, "vmem-width", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
635 var_Create (mp
, "vmem-height", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
636 var_Create (mp
, "vmem-pitch", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
637 var_Create (mp
, "avcodec-hw", VLC_VAR_STRING
);
638 var_Create (mp
, "drawable-xid", VLC_VAR_INTEGER
);
639 #if defined (_WIN32) || defined (__OS2__)
640 var_Create (mp
, "drawable-hwnd", VLC_VAR_INTEGER
);
643 var_Create (mp
, "drawable-nsobject", VLC_VAR_ADDRESS
);
646 var_Create (mp
, "drawable-androidwindow", VLC_VAR_ADDRESS
);
649 var_Create (mp
, "drawable-evasobject", VLC_VAR_ADDRESS
);
652 var_Create (mp
, "keyboard-events", VLC_VAR_BOOL
);
653 var_SetBool (mp
, "keyboard-events", true);
654 var_Create (mp
, "mouse-events", VLC_VAR_BOOL
);
655 var_SetBool (mp
, "mouse-events", true);
657 var_Create (mp
, "fullscreen", VLC_VAR_BOOL
);
658 var_Create (mp
, "autoscale", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
659 var_Create (mp
, "zoom", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
660 var_Create (mp
, "aspect-ratio", VLC_VAR_STRING
);
661 var_Create (mp
, "crop", VLC_VAR_STRING
);
662 var_Create (mp
, "deinterlace", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
663 var_Create (mp
, "deinterlace-mode", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
665 var_Create (mp
, "vbi-page", VLC_VAR_INTEGER
);
666 var_SetInteger (mp
, "vbi-page", 100);
668 var_Create (mp
, "video-filter", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
669 var_Create (mp
, "sub-source", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
670 var_Create (mp
, "sub-filter", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
672 var_Create (mp
, "marq-marquee", VLC_VAR_STRING
);
673 var_Create (mp
, "marq-color", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
674 var_Create (mp
, "marq-opacity", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
675 var_Create (mp
, "marq-position", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
676 var_Create (mp
, "marq-refresh", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
677 var_Create (mp
, "marq-size", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
678 var_Create (mp
, "marq-timeout", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
679 var_Create (mp
, "marq-x", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
680 var_Create (mp
, "marq-y", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
682 var_Create (mp
, "logo-file", VLC_VAR_STRING
);
683 var_Create (mp
, "logo-x", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
684 var_Create (mp
, "logo-y", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
685 var_Create (mp
, "logo-delay", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
686 var_Create (mp
, "logo-repeat", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
687 var_Create (mp
, "logo-opacity", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
688 var_Create (mp
, "logo-position", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
690 var_Create (mp
, "contrast", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
691 var_Create (mp
, "brightness", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
692 var_Create (mp
, "hue", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
693 var_Create (mp
, "saturation", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
694 var_Create (mp
, "gamma", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
697 var_Create (mp
, "aout", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
698 var_Create (mp
, "audio-device", VLC_VAR_STRING
);
699 var_Create (mp
, "mute", VLC_VAR_BOOL
);
700 var_Create (mp
, "volume", VLC_VAR_FLOAT
);
701 var_Create (mp
, "corks", VLC_VAR_INTEGER
);
702 var_Create (mp
, "audio-filter", VLC_VAR_STRING
);
703 var_Create (mp
, "role", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
704 var_Create (mp
, "amem-data", VLC_VAR_ADDRESS
);
705 var_Create (mp
, "amem-setup", VLC_VAR_ADDRESS
);
706 var_Create (mp
, "amem-cleanup", VLC_VAR_ADDRESS
);
707 var_Create (mp
, "amem-play", VLC_VAR_ADDRESS
);
708 var_Create (mp
, "amem-pause", VLC_VAR_ADDRESS
);
709 var_Create (mp
, "amem-resume", VLC_VAR_ADDRESS
);
710 var_Create (mp
, "amem-flush", VLC_VAR_ADDRESS
);
711 var_Create (mp
, "amem-drain", VLC_VAR_ADDRESS
);
712 var_Create (mp
, "amem-set-volume", VLC_VAR_ADDRESS
);
713 var_Create (mp
, "amem-format", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
714 var_Create (mp
, "amem-rate", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
715 var_Create (mp
, "amem-channels", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
718 var_Create (mp
, "video-title-show", VLC_VAR_BOOL
);
719 var_Create (mp
, "video-title-position", VLC_VAR_INTEGER
);
720 var_Create (mp
, "video-title-timeout", VLC_VAR_INTEGER
);
723 var_Create (mp
, "equalizer-preamp", VLC_VAR_FLOAT
);
724 var_Create (mp
, "equalizer-vlcfreqs", VLC_VAR_BOOL
);
725 var_Create (mp
, "equalizer-bands", VLC_VAR_STRING
);
728 mp
->state
= libvlc_NothingSpecial
;
729 mp
->p_libvlc_instance
= instance
;
730 mp
->input
.p_thread
= NULL
;
731 mp
->input
.p_renderer
= NULL
;
732 mp
->input
.p_resource
= input_resource_New(VLC_OBJECT(mp
));
733 if (unlikely(mp
->input
.p_resource
== NULL
))
735 vlc_object_release(mp
);
738 audio_output_t
*aout
= input_resource_GetAout(mp
->input
.p_resource
);
740 input_resource_PutAout(mp
->input
.p_resource
, aout
);
742 vlc_viewpoint_init(&mp
->viewpoint
);
744 var_Create (mp
, "viewpoint", VLC_VAR_ADDRESS
);
745 var_SetAddress( mp
, "viewpoint", &mp
->viewpoint
);
746 vlc_mutex_init (&mp
->input
.lock
);
748 libvlc_event_manager_init(&mp
->event_manager
, mp
);
749 vlc_mutex_init(&mp
->object_lock
);
751 var_AddCallback(mp
, "corks", corks_changed
, NULL
);
752 var_AddCallback(mp
, "audio-device", audio_device_changed
, NULL
);
753 var_AddCallback(mp
, "mute", mute_changed
, NULL
);
754 var_AddCallback(mp
, "volume", volume_changed
, NULL
);
756 /* Snapshot initialization */
757 /* Attach a var callback to the global object to provide the glue between
758 * vout_thread that generates the event and media_player that re-emits it
759 * with its own event manager
761 * FIXME: It's unclear why we want to put this in public API, and why we
762 * want to expose it in such a limiting and ugly way.
764 var_AddCallback(mp
->obj
.libvlc
, "snapshot-file", snapshot_was_taken
, mp
);
766 libvlc_retain(instance
);
770 /**************************************************************************
771 * Create a Media Instance object with a media descriptor.
772 **************************************************************************/
773 libvlc_media_player_t
*
774 libvlc_media_player_new_from_media( libvlc_media_t
* p_md
)
776 libvlc_media_player_t
* p_mi
;
778 p_mi
= libvlc_media_player_new( p_md
->p_libvlc_instance
);
782 libvlc_media_retain( p_md
);
788 /**************************************************************************
789 * Destroy a Media Instance object (libvlc internal)
791 * Warning: No lock held here, but hey, this is internal. Caller must lock.
792 **************************************************************************/
793 static void libvlc_media_player_destroy( libvlc_media_player_t
*p_mi
)
797 /* Detach Callback from the main libvlc object */
798 var_DelCallback( p_mi
->obj
.libvlc
,
799 "snapshot-file", snapshot_was_taken
, p_mi
);
801 /* Detach callback from the media player / input manager object */
802 var_DelCallback( p_mi
, "volume", volume_changed
, NULL
);
803 var_DelCallback( p_mi
, "mute", mute_changed
, NULL
);
804 var_DelCallback( p_mi
, "audio-device", audio_device_changed
, NULL
);
805 var_DelCallback( p_mi
, "corks", corks_changed
, NULL
);
807 /* No need for lock_input() because no other threads knows us anymore */
808 if( p_mi
->input
.p_thread
)
809 release_input_thread(p_mi
);
810 input_resource_Terminate( p_mi
->input
.p_resource
);
811 input_resource_Release( p_mi
->input
.p_resource
);
812 if( p_mi
->input
.p_renderer
)
813 vlc_renderer_item_release( p_mi
->input
.p_renderer
);
815 vlc_mutex_destroy( &p_mi
->input
.lock
);
817 libvlc_event_manager_destroy(&p_mi
->event_manager
);
818 libvlc_media_release( p_mi
->p_md
);
819 vlc_mutex_destroy( &p_mi
->object_lock
);
821 libvlc_instance_t
*instance
= p_mi
->p_libvlc_instance
;
822 vlc_object_release( p_mi
);
823 libvlc_release(instance
);
826 /**************************************************************************
827 * Release a Media Instance object.
829 * Function does the locking.
830 **************************************************************************/
831 void libvlc_media_player_release( libvlc_media_player_t
*p_mi
)
837 destroy
= !--p_mi
->i_refcount
;
841 libvlc_media_player_destroy( p_mi
);
844 /**************************************************************************
845 * Retain a Media Instance object.
847 * Caller must hold the lock.
848 **************************************************************************/
849 void libvlc_media_player_retain( libvlc_media_player_t
*p_mi
)
858 /**************************************************************************
859 * Set the Media descriptor associated with the instance.
861 * Enter without lock -- function will lock the object.
862 **************************************************************************/
863 void libvlc_media_player_set_media(
864 libvlc_media_player_t
*p_mi
,
865 libvlc_media_t
*p_md
)
869 release_input_thread( p_mi
);
872 set_state( p_mi
, libvlc_NothingSpecial
, true );
873 unlock_input( p_mi
);
875 libvlc_media_release( p_mi
->p_md
);
881 return; /* It is ok to pass a NULL md */
884 libvlc_media_retain( p_md
);
887 /* The policy here is to ignore that we were created using a different
888 * libvlc_instance, because we don't really care */
889 p_mi
->p_libvlc_instance
= p_md
->p_libvlc_instance
;
893 /* Send an event for the newly available media */
894 libvlc_event_t event
;
895 event
.type
= libvlc_MediaPlayerMediaChanged
;
896 event
.u
.media_player_media_changed
.new_media
= p_md
;
897 libvlc_event_send( &p_mi
->event_manager
, &event
);
901 /**************************************************************************
902 * Get the Media descriptor associated with the instance.
903 **************************************************************************/
905 libvlc_media_player_get_media( libvlc_media_player_t
*p_mi
)
912 libvlc_media_retain( p_m
);
918 /**************************************************************************
919 * Get the event Manager.
920 **************************************************************************/
921 libvlc_event_manager_t
*
922 libvlc_media_player_event_manager( libvlc_media_player_t
*p_mi
)
924 return &p_mi
->event_manager
;
927 static void add_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
)
929 var_AddListCallback( p_input_thread
, "video-es", input_es_changed
, p_mi
);
930 var_AddListCallback( p_input_thread
, "audio-es", input_es_changed
, p_mi
);
931 var_AddListCallback( p_input_thread
, "spu-es", input_es_changed
, p_mi
);
934 static void del_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
)
936 var_DelListCallback( p_input_thread
, "video-es", input_es_changed
, p_mi
);
937 var_DelListCallback( p_input_thread
, "audio-es", input_es_changed
, p_mi
);
938 var_DelListCallback( p_input_thread
, "spu-es", input_es_changed
, p_mi
);
941 /**************************************************************************
942 * Tell media player to start playing.
943 **************************************************************************/
944 int libvlc_media_player_play( libvlc_media_player_t
*p_mi
)
948 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
951 /* A thread already exists, send it a play message */
952 input_Control( p_input_thread
, INPUT_SET_STATE
, PLAYING_S
);
953 unlock_input( p_mi
);
957 /* Ignore previous exception */
963 unlock_input( p_mi
);
964 libvlc_printerr( "No associated media descriptor" );
968 for( size_t i
= 0; i
< ARRAY_SIZE( p_mi
->selected_es
); ++i
)
969 p_mi
->selected_es
[i
] = ES_INIT
;
971 media_attach_preparsed_event( p_mi
->p_md
);
973 p_input_thread
= input_Create( p_mi
, p_mi
->p_md
->p_input_item
, NULL
,
974 p_mi
->input
.p_resource
,
975 p_mi
->input
.p_renderer
);
977 if( !p_input_thread
)
980 media_detach_preparsed_event( p_mi
->p_md
);
981 libvlc_printerr( "Not enough memory" );
985 var_AddCallback( p_input_thread
, "can-seek", input_seekable_changed
, p_mi
);
986 var_AddCallback( p_input_thread
, "can-pause", input_pausable_changed
, p_mi
);
987 var_AddCallback( p_input_thread
, "program-scrambled", input_scrambled_changed
, p_mi
);
988 var_AddCallback( p_input_thread
, "intf-event", input_event_changed
, p_mi
);
989 add_es_callbacks( p_input_thread
, p_mi
);
991 if( input_Start( p_input_thread
) )
994 del_es_callbacks( p_input_thread
, p_mi
);
995 var_DelCallback( p_input_thread
, "intf-event", input_event_changed
, p_mi
);
996 var_DelCallback( p_input_thread
, "can-pause", input_pausable_changed
, p_mi
);
997 var_DelCallback( p_input_thread
, "program-scrambled", input_scrambled_changed
, p_mi
);
998 var_DelCallback( p_input_thread
, "can-seek", input_seekable_changed
, p_mi
);
999 input_Close( p_input_thread
);
1000 media_detach_preparsed_event( p_mi
->p_md
);
1001 libvlc_printerr( "Input initialization failure" );
1004 p_mi
->input
.p_thread
= p_input_thread
;
1009 void libvlc_media_player_set_pause( libvlc_media_player_t
*p_mi
, int paused
)
1011 input_thread_t
* p_input_thread
= libvlc_get_input_thread( p_mi
);
1012 if( !p_input_thread
)
1017 if( libvlc_media_player_can_pause( p_mi
) )
1018 input_Control( p_input_thread
, INPUT_SET_STATE
, PAUSE_S
);
1020 input_Stop( p_input_thread
);
1024 input_Control( p_input_thread
, INPUT_SET_STATE
, PLAYING_S
);
1027 vlc_object_release( p_input_thread
);
1030 /**************************************************************************
1032 **************************************************************************/
1033 void libvlc_media_player_pause( libvlc_media_player_t
*p_mi
)
1035 libvlc_media_player_set_pause( p_mi
, libvlc_media_player_is_playing( p_mi
) );
1038 /**************************************************************************
1039 * Tells whether the media player is currently playing.
1040 **************************************************************************/
1041 int libvlc_media_player_is_playing( libvlc_media_player_t
*p_mi
)
1043 libvlc_state_t state
= libvlc_media_player_get_state( p_mi
);
1044 return libvlc_Playing
== state
;
1047 /**************************************************************************
1049 **************************************************************************/
1050 void libvlc_media_player_stop( libvlc_media_player_t
*p_mi
)
1053 release_input_thread( p_mi
); /* This will stop the input thread */
1055 /* Force to go to stopped state, in case we were in Ended, or Error
1057 if( p_mi
->state
!= libvlc_Stopped
)
1059 set_state( p_mi
, libvlc_Stopped
, false );
1061 /* Construct and send the event */
1062 libvlc_event_t event
;
1063 event
.type
= libvlc_MediaPlayerStopped
;
1064 libvlc_event_send( &p_mi
->event_manager
, &event
);
1067 input_resource_Terminate( p_mi
->input
.p_resource
);
1071 int libvlc_media_player_set_renderer( libvlc_media_player_t
*p_mi
,
1072 libvlc_renderer_item_t
*p_litem
)
1074 vlc_renderer_item_t
*p_item
=
1075 p_litem
? libvlc_renderer_item_to_vlc( p_litem
) : NULL
;
1078 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
1079 if( p_input_thread
)
1080 input_Control( p_input_thread
, INPUT_SET_RENDERER
, p_item
);
1082 if( p_mi
->input
.p_renderer
)
1083 vlc_renderer_item_release( p_mi
->input
.p_renderer
);
1084 p_mi
->input
.p_renderer
= p_item
? vlc_renderer_item_hold( p_item
) : NULL
;
1085 unlock_input( p_mi
);
1090 void libvlc_video_set_callbacks( libvlc_media_player_t
*mp
,
1091 void *(*lock_cb
) (void *, void **),
1092 void (*unlock_cb
) (void *, void *, void *const *),
1093 void (*display_cb
) (void *, void *),
1096 var_SetAddress( mp
, "vmem-lock", lock_cb
);
1097 var_SetAddress( mp
, "vmem-unlock", unlock_cb
);
1098 var_SetAddress( mp
, "vmem-display", display_cb
);
1099 var_SetAddress( mp
, "vmem-data", opaque
);
1100 var_SetString( mp
, "avcodec-hw", "none" );
1101 var_SetString( mp
, "vout", "vmem" );
1102 var_SetString( mp
, "window", "none" );
1105 void libvlc_video_set_format_callbacks( libvlc_media_player_t
*mp
,
1106 libvlc_video_format_cb setup
,
1107 libvlc_video_cleanup_cb cleanup
)
1109 var_SetAddress( mp
, "vmem-setup", setup
);
1110 var_SetAddress( mp
, "vmem-cleanup", cleanup
);
1113 void libvlc_video_set_format( libvlc_media_player_t
*mp
, const char *chroma
,
1114 unsigned width
, unsigned height
, unsigned pitch
)
1116 var_SetString( mp
, "vmem-chroma", chroma
);
1117 var_SetInteger( mp
, "vmem-width", width
);
1118 var_SetInteger( mp
, "vmem-height", height
);
1119 var_SetInteger( mp
, "vmem-pitch", pitch
);
1122 /**************************************************************************
1124 **************************************************************************/
1125 void libvlc_media_player_set_nsobject( libvlc_media_player_t
*p_mi
,
1128 assert (p_mi
!= NULL
);
1130 var_SetString (p_mi
, "avcodec-hw", "");
1131 var_SetString (p_mi
, "vout", "");
1132 var_SetString (p_mi
, "window", "");
1133 var_SetAddress (p_mi
, "drawable-nsobject", drawable
);
1136 libvlc_printerr ("can't set nsobject: APPLE build required");
1138 var_SetString (p_mi
, "vout", "none");
1139 var_SetString (p_mi
, "window", "none");
1143 /**************************************************************************
1145 **************************************************************************/
1146 void * libvlc_media_player_get_nsobject( libvlc_media_player_t
*p_mi
)
1148 assert (p_mi
!= NULL
);
1150 return var_GetAddress (p_mi
, "drawable-nsobject");
1157 /**************************************************************************
1159 **************************************************************************/
1160 void libvlc_media_player_set_agl( libvlc_media_player_t
*p_mi
,
1164 libvlc_printerr ("can't set agl: use libvlc_media_player_set_nsobject instead");
1166 var_SetString (p_mi
, "vout", "none");
1167 var_SetString (p_mi
, "window", "none");
1170 /**************************************************************************
1172 **************************************************************************/
1173 uint32_t libvlc_media_player_get_agl( libvlc_media_player_t
*p_mi
)
1179 /**************************************************************************
1181 **************************************************************************/
1182 void libvlc_media_player_set_xwindow( libvlc_media_player_t
*p_mi
,
1185 assert (p_mi
!= NULL
);
1187 var_SetString (p_mi
, "avcodec-hw", "");
1188 var_SetString (p_mi
, "vout", "");
1189 var_SetString (p_mi
, "window", drawable
? "embed-xid,any" : "");
1190 var_SetInteger (p_mi
, "drawable-xid", drawable
);
1193 /**************************************************************************
1195 **************************************************************************/
1196 uint32_t libvlc_media_player_get_xwindow( libvlc_media_player_t
*p_mi
)
1198 return var_GetInteger (p_mi
, "drawable-xid");
1201 /**************************************************************************
1203 **************************************************************************/
1204 void libvlc_media_player_set_hwnd( libvlc_media_player_t
*p_mi
,
1207 assert (p_mi
!= NULL
);
1208 #if defined (_WIN32) || defined (__OS2__)
1209 var_SetString (p_mi
, "avcodec-hw", "");
1210 var_SetString (p_mi
, "vout", "");
1211 var_SetString (p_mi
, "window",
1212 (drawable
!= NULL
) ? "embed-hwnd,any" : "");
1213 var_SetInteger (p_mi
, "drawable-hwnd", (uintptr_t)drawable
);
1216 libvlc_printerr ("can't set nsobject: WIN32 build required");
1218 var_SetString (p_mi
, "vout", "none");
1219 var_SetString (p_mi
, "window", "none");
1223 /**************************************************************************
1225 **************************************************************************/
1226 void *libvlc_media_player_get_hwnd( libvlc_media_player_t
*p_mi
)
1228 assert (p_mi
!= NULL
);
1229 #if defined (_WIN32) || defined (__OS2__)
1230 return (void *)(uintptr_t)var_GetInteger (p_mi
, "drawable-hwnd");
1237 /**************************************************************************
1238 * set_android_context
1239 **************************************************************************/
1240 void libvlc_media_player_set_android_context( libvlc_media_player_t
*p_mi
,
1241 void *p_awindow_handler
)
1243 assert (p_mi
!= NULL
);
1245 var_SetAddress (p_mi
, "drawable-androidwindow", p_awindow_handler
);
1247 (void) p_awindow_handler
;
1248 libvlc_printerr ("can't set android context: ANDROID build required");
1250 var_SetString (p_mi
, "vout", "none");
1251 var_SetString (p_mi
, "window", "none");
1255 /**************************************************************************
1257 **************************************************************************/
1258 int libvlc_media_player_set_evas_object( libvlc_media_player_t
*p_mi
,
1259 void *p_evas_object
)
1261 assert (p_mi
!= NULL
);
1263 var_SetString (p_mi
, "vout", "evas");
1264 var_SetString (p_mi
, "window", "none");
1265 var_SetAddress (p_mi
, "drawable-evasobject", p_evas_object
);
1268 (void) p_mi
; (void) p_evas_object
;
1273 void libvlc_audio_set_callbacks( libvlc_media_player_t
*mp
,
1274 libvlc_audio_play_cb play_cb
,
1275 libvlc_audio_pause_cb pause_cb
,
1276 libvlc_audio_resume_cb resume_cb
,
1277 libvlc_audio_flush_cb flush_cb
,
1278 libvlc_audio_drain_cb drain_cb
,
1281 var_SetAddress( mp
, "amem-play", play_cb
);
1282 var_SetAddress( mp
, "amem-pause", pause_cb
);
1283 var_SetAddress( mp
, "amem-resume", resume_cb
);
1284 var_SetAddress( mp
, "amem-flush", flush_cb
);
1285 var_SetAddress( mp
, "amem-drain", drain_cb
);
1286 var_SetAddress( mp
, "amem-data", opaque
);
1287 var_SetString( mp
, "aout", "amem,none" );
1289 input_resource_ResetAout(mp
->input
.p_resource
);
1292 void libvlc_audio_set_volume_callback( libvlc_media_player_t
*mp
,
1293 libvlc_audio_set_volume_cb cb
)
1295 var_SetAddress( mp
, "amem-set-volume", cb
);
1297 input_resource_ResetAout(mp
->input
.p_resource
);
1300 void libvlc_audio_set_format_callbacks( libvlc_media_player_t
*mp
,
1301 libvlc_audio_setup_cb setup
,
1302 libvlc_audio_cleanup_cb cleanup
)
1304 var_SetAddress( mp
, "amem-setup", setup
);
1305 var_SetAddress( mp
, "amem-cleanup", cleanup
);
1307 input_resource_ResetAout(mp
->input
.p_resource
);
1310 void libvlc_audio_set_format( libvlc_media_player_t
*mp
, const char *format
,
1311 unsigned rate
, unsigned channels
)
1313 var_SetString( mp
, "amem-format", format
);
1314 var_SetInteger( mp
, "amem-rate", rate
);
1315 var_SetInteger( mp
, "amem-channels", channels
);
1317 input_resource_ResetAout(mp
->input
.p_resource
);
1321 /**************************************************************************
1322 * Getters for stream information
1323 **************************************************************************/
1324 libvlc_time_t
libvlc_media_player_get_length(
1325 libvlc_media_player_t
*p_mi
)
1327 input_thread_t
*p_input_thread
;
1328 libvlc_time_t i_time
;
1330 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1331 if( !p_input_thread
)
1334 i_time
= from_mtime(var_GetInteger( p_input_thread
, "length" ));
1335 vlc_object_release( p_input_thread
);
1340 libvlc_time_t
libvlc_media_player_get_time( libvlc_media_player_t
*p_mi
)
1342 input_thread_t
*p_input_thread
;
1343 libvlc_time_t i_time
;
1345 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1346 if( !p_input_thread
)
1349 i_time
= from_mtime(var_GetInteger( p_input_thread
, "time" ));
1350 vlc_object_release( p_input_thread
);
1354 void libvlc_media_player_set_time( libvlc_media_player_t
*p_mi
,
1355 libvlc_time_t i_time
)
1357 input_thread_t
*p_input_thread
;
1359 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1360 if( !p_input_thread
)
1363 var_SetInteger( p_input_thread
, "time", to_mtime(i_time
) );
1364 vlc_object_release( p_input_thread
);
1367 void libvlc_media_player_set_position( libvlc_media_player_t
*p_mi
,
1370 input_thread_t
*p_input_thread
;
1372 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1373 if( !p_input_thread
)
1376 var_SetFloat( p_input_thread
, "position", position
);
1377 vlc_object_release( p_input_thread
);
1380 float libvlc_media_player_get_position( libvlc_media_player_t
*p_mi
)
1382 input_thread_t
*p_input_thread
;
1385 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1386 if( !p_input_thread
)
1389 f_position
= var_GetFloat( p_input_thread
, "position" );
1390 vlc_object_release( p_input_thread
);
1395 void libvlc_media_player_set_chapter( libvlc_media_player_t
*p_mi
,
1398 input_thread_t
*p_input_thread
;
1400 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1401 if( !p_input_thread
)
1404 var_SetInteger( p_input_thread
, "chapter", chapter
);
1405 vlc_object_release( p_input_thread
);
1408 int libvlc_media_player_get_chapter( libvlc_media_player_t
*p_mi
)
1410 input_thread_t
*p_input_thread
;
1413 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1414 if( !p_input_thread
)
1417 i_chapter
= var_GetInteger( p_input_thread
, "chapter" );
1418 vlc_object_release( p_input_thread
);
1423 int libvlc_media_player_get_chapter_count( libvlc_media_player_t
*p_mi
)
1425 input_thread_t
*p_input_thread
;
1428 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1429 if( !p_input_thread
)
1432 int i_ret
= var_Change( p_input_thread
, "chapter", VLC_VAR_CHOICESCOUNT
, &val
, NULL
);
1433 vlc_object_release( p_input_thread
);
1435 return i_ret
== VLC_SUCCESS
? val
.i_int
: -1;
1438 int libvlc_media_player_get_chapter_count_for_title(
1439 libvlc_media_player_t
*p_mi
,
1444 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1445 if( !p_input_thread
)
1448 char psz_name
[sizeof ("title ") + 3 * sizeof (int)];
1449 sprintf( psz_name
, "title %2u", i_title
);
1451 int i_ret
= var_Change( p_input_thread
, psz_name
, VLC_VAR_CHOICESCOUNT
, &val
, NULL
);
1452 vlc_object_release( p_input_thread
);
1454 return i_ret
== VLC_SUCCESS
? val
.i_int
: -1;
1457 void libvlc_media_player_set_title( libvlc_media_player_t
*p_mi
,
1460 input_thread_t
*p_input_thread
;
1462 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1463 if( !p_input_thread
)
1466 var_SetInteger( p_input_thread
, "title", i_title
);
1467 vlc_object_release( p_input_thread
);
1470 libvlc_event_t event
;
1471 event
.type
= libvlc_MediaPlayerTitleChanged
;
1472 event
.u
.media_player_title_changed
.new_title
= i_title
;
1473 libvlc_event_send( &p_mi
->event_manager
, &event
);
1476 int libvlc_media_player_get_title( libvlc_media_player_t
*p_mi
)
1478 input_thread_t
*p_input_thread
;
1481 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1482 if( !p_input_thread
)
1485 i_title
= var_GetInteger( p_input_thread
, "title" );
1486 vlc_object_release( p_input_thread
);
1491 int libvlc_media_player_get_title_count( libvlc_media_player_t
*p_mi
)
1493 input_thread_t
*p_input_thread
;
1496 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1497 if( !p_input_thread
)
1500 int i_ret
= var_Change( p_input_thread
, "title", VLC_VAR_CHOICESCOUNT
, &val
, NULL
);
1501 vlc_object_release( p_input_thread
);
1503 return i_ret
== VLC_SUCCESS
? val
.i_int
: -1;
1506 int libvlc_media_player_get_full_title_descriptions( libvlc_media_player_t
*p_mi
,
1507 libvlc_title_description_t
*** pp_titles
)
1511 input_thread_t
*p_input_thread
= libvlc_get_input_thread( p_mi
);
1513 if( !p_input_thread
)
1516 input_title_t
**p_input_title
;
1520 int ret
= input_Control( p_input_thread
, INPUT_GET_FULL_TITLE_INFO
,
1521 &p_input_title
, &count
);
1522 vlc_object_release( p_input_thread
);
1523 if( ret
!= VLC_SUCCESS
)
1526 libvlc_title_description_t
**titles
= vlc_alloc( count
, sizeof (*titles
) );
1527 if( count
> 0 && unlikely(titles
== NULL
) )
1531 for( int i
= 0; i
< count
; i
++)
1533 libvlc_title_description_t
*title
= malloc( sizeof (*title
) );
1534 if( unlikely(title
== NULL
) )
1536 libvlc_title_descriptions_release( titles
, i
);
1541 /* we want to return milliseconds to match the rest of the API */
1542 title
->i_duration
= p_input_title
[i
]->i_length
/ 1000;
1543 title
->i_flags
= p_input_title
[i
]->i_flags
;
1544 if( p_input_title
[i
]->psz_name
)
1545 title
->psz_name
= strdup( p_input_title
[i
]->psz_name
);
1547 title
->psz_name
= NULL
;
1548 vlc_input_title_Delete( p_input_title
[i
] );
1550 free( p_input_title
);
1552 *pp_titles
= titles
;
1556 void libvlc_title_descriptions_release( libvlc_title_description_t
**p_titles
,
1559 for (unsigned i
= 0; i
< i_count
; i
++ )
1564 free( p_titles
[i
]->psz_name
);
1565 free( p_titles
[i
] );
1570 int libvlc_media_player_get_full_chapter_descriptions( libvlc_media_player_t
*p_mi
,
1571 int i_chapters_of_title
,
1572 libvlc_chapter_description_t
*** pp_chapters
)
1576 input_thread_t
*p_input_thread
= libvlc_get_input_thread( p_mi
);
1578 if( !p_input_thread
)
1581 seekpoint_t
**p_seekpoint
= NULL
;
1584 int ci_chapter_count
= i_chapters_of_title
;
1586 int ret
= input_Control(p_input_thread
, INPUT_GET_SEEKPOINTS
, &p_seekpoint
, &ci_chapter_count
);
1587 if( ret
!= VLC_SUCCESS
)
1589 vlc_object_release( p_input_thread
);
1593 if (ci_chapter_count
== 0 || p_seekpoint
== NULL
)
1595 vlc_object_release( p_input_thread
);
1599 input_title_t
*p_title
;
1600 ret
= input_Control( p_input_thread
, INPUT_GET_TITLE_INFO
, &p_title
,
1601 &i_chapters_of_title
);
1602 vlc_object_release( p_input_thread
);
1603 if( ret
!= VLC_SUCCESS
)
1607 int64_t i_title_duration
= p_title
->i_length
/ 1000;
1608 vlc_input_title_Delete( p_title
);
1610 *pp_chapters
= calloc( ci_chapter_count
, sizeof(**pp_chapters
) );
1617 for( int i
= 0; i
< ci_chapter_count
; ++i
)
1619 libvlc_chapter_description_t
*p_chapter
= malloc( sizeof(*p_chapter
) );
1620 if( unlikely(p_chapter
== NULL
) )
1624 (*pp_chapters
)[i
] = p_chapter
;
1626 p_chapter
->i_time_offset
= p_seekpoint
[i
]->i_time_offset
/ 1000;
1628 if( i
< ci_chapter_count
- 1 )
1630 p_chapter
->i_duration
= p_seekpoint
[i
+ 1]->i_time_offset
/ 1000 -
1631 p_chapter
->i_time_offset
;
1635 if ( i_title_duration
)
1636 p_chapter
->i_duration
= i_title_duration
- p_chapter
->i_time_offset
;
1638 p_chapter
->i_duration
= 0;
1641 if( p_seekpoint
[i
]->psz_name
)
1643 p_chapter
->psz_name
= strdup( p_seekpoint
[i
]->psz_name
);
1647 p_chapter
->psz_name
= NULL
;
1649 vlc_seekpoint_Delete( p_seekpoint
[i
] );
1650 p_seekpoint
[i
] = NULL
;
1653 free( p_seekpoint
);
1654 return ci_chapter_count
;
1658 libvlc_chapter_descriptions_release( *pp_chapters
, ci_chapter_count
);
1659 for ( int i
= 0; i
< ci_chapter_count
; ++i
)
1660 vlc_seekpoint_Delete( p_seekpoint
[i
] );
1661 free( p_seekpoint
);
1665 void libvlc_chapter_descriptions_release( libvlc_chapter_description_t
**p_chapters
,
1668 for (unsigned i
= 0; i
< i_count
; i
++ )
1670 if ( !p_chapters
[i
] )
1673 free( p_chapters
[i
]->psz_name
);
1674 free( p_chapters
[i
] );
1679 void libvlc_media_player_next_chapter( libvlc_media_player_t
*p_mi
)
1681 input_thread_t
*p_input_thread
;
1683 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1684 if( !p_input_thread
)
1687 int i_type
= var_Type( p_input_thread
, "next-chapter" );
1688 var_TriggerCallback( p_input_thread
, (i_type
& VLC_VAR_TYPE
) != 0 ?
1689 "next-chapter":"next-title" );
1691 vlc_object_release( p_input_thread
);
1694 void libvlc_media_player_previous_chapter( libvlc_media_player_t
*p_mi
)
1696 input_thread_t
*p_input_thread
;
1698 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1699 if( !p_input_thread
)
1702 int i_type
= var_Type( p_input_thread
, "next-chapter" );
1703 var_TriggerCallback( p_input_thread
, (i_type
& VLC_VAR_TYPE
) != 0 ?
1704 "prev-chapter":"prev-title" );
1706 vlc_object_release( p_input_thread
);
1709 float libvlc_media_player_get_fps( libvlc_media_player_t
*p_mi
)
1711 libvlc_media_t
*media
= libvlc_media_player_get_media( p_mi
);
1715 input_item_t
*item
= media
->p_input_item
;
1718 vlc_mutex_lock( &item
->lock
);
1719 for( int i
= 0; i
< item
->i_es
; i
++ )
1721 const es_format_t
*fmt
= item
->es
[i
];
1723 if( fmt
->i_cat
== VIDEO_ES
&& fmt
->video
.i_frame_rate_base
> 0 )
1724 fps
= (float)fmt
->video
.i_frame_rate
1725 / (float)fmt
->video
.i_frame_rate_base
;
1727 vlc_mutex_unlock( &item
->lock
);
1728 libvlc_media_release( media
);
1733 int libvlc_media_player_will_play( libvlc_media_player_t
*p_mi
)
1735 input_thread_t
*p_input_thread
=
1736 libvlc_get_input_thread ( p_mi
);
1737 if ( !p_input_thread
)
1740 int state
= var_GetInteger( p_input_thread
, "state" );
1741 vlc_object_release( p_input_thread
);
1743 return state
!= END_S
&& state
!= ERROR_S
;
1746 int libvlc_media_player_set_rate( libvlc_media_player_t
*p_mi
, float rate
)
1748 var_SetFloat (p_mi
, "rate", rate
);
1750 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1751 if( !p_input_thread
)
1753 var_SetFloat( p_input_thread
, "rate", rate
);
1754 vlc_object_release( p_input_thread
);
1758 float libvlc_media_player_get_rate( libvlc_media_player_t
*p_mi
)
1760 return var_GetFloat (p_mi
, "rate");
1763 libvlc_state_t
libvlc_media_player_get_state( libvlc_media_player_t
*p_mi
)
1766 libvlc_state_t state
= p_mi
->state
;
1771 int libvlc_media_player_is_seekable( libvlc_media_player_t
*p_mi
)
1773 input_thread_t
*p_input_thread
;
1776 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1777 if ( !p_input_thread
)
1779 b_seekable
= var_GetBool( p_input_thread
, "can-seek" );
1780 vlc_object_release( p_input_thread
);
1785 void libvlc_media_player_navigate( libvlc_media_player_t
* p_mi
,
1788 static const int map
[] =
1790 INPUT_NAV_ACTIVATE
, INPUT_NAV_UP
, INPUT_NAV_DOWN
,
1791 INPUT_NAV_LEFT
, INPUT_NAV_RIGHT
, INPUT_NAV_POPUP
,
1794 if( navigate
>= sizeof(map
) / sizeof(map
[0]) )
1797 input_thread_t
*p_input
= libvlc_get_input_thread ( p_mi
);
1798 if ( p_input
== NULL
)
1801 input_Control( p_input
, map
[navigate
], NULL
);
1802 vlc_object_release( p_input
);
1805 /* internal function, used by audio, video */
1806 libvlc_track_description_t
*
1807 libvlc_get_track_description( libvlc_media_player_t
*p_mi
,
1808 const char *psz_variable
)
1810 input_thread_t
*p_input
= libvlc_get_input_thread( p_mi
);
1811 libvlc_track_description_t
*p_track_description
= NULL
,
1812 *p_actual
, *p_previous
;
1817 vlc_value_t val_list
, text_list
;
1818 int i_ret
= var_Change( p_input
, psz_variable
, VLC_VAR_GETCHOICES
, &val_list
, &text_list
);
1819 if( i_ret
!= VLC_SUCCESS
)
1823 if( val_list
.p_list
->i_count
<= 0 )
1826 p_track_description
= malloc( sizeof *p_track_description
);
1827 if ( !p_track_description
)
1829 libvlc_printerr( "Not enough memory" );
1832 p_actual
= p_track_description
;
1834 for( int i
= 0; i
< val_list
.p_list
->i_count
; i
++ )
1838 p_actual
= malloc( sizeof *p_actual
);
1841 libvlc_track_description_list_release( p_track_description
);
1842 libvlc_printerr( "Not enough memory" );
1844 p_track_description
= NULL
;
1848 p_actual
->i_id
= val_list
.p_list
->p_values
[i
].i_int
;
1849 p_actual
->psz_name
= strdup( text_list
.p_list
->p_values
[i
].psz_string
);
1850 p_actual
->p_next
= NULL
;
1852 p_previous
->p_next
= p_actual
;
1853 p_previous
= p_actual
;
1858 var_FreeList( &val_list
, &text_list
);
1859 vlc_object_release( p_input
);
1861 return p_track_description
;
1864 // Deprecated alias for libvlc_track_description_list_release
1865 void libvlc_track_description_release( libvlc_track_description_t
*p_td
)
1867 libvlc_track_description_list_release( p_td
);
1870 void libvlc_track_description_list_release( libvlc_track_description_t
*p_td
)
1872 libvlc_track_description_t
*p_actual
, *p_before
;
1877 free( p_actual
->psz_name
);
1878 p_before
= p_actual
;
1879 p_actual
= p_before
->p_next
;
1884 int libvlc_media_player_can_pause( libvlc_media_player_t
*p_mi
)
1886 input_thread_t
*p_input_thread
;
1889 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1890 if ( !p_input_thread
)
1892 b_can_pause
= var_GetBool( p_input_thread
, "can-pause" );
1893 vlc_object_release( p_input_thread
);
1898 int libvlc_media_player_program_scrambled( libvlc_media_player_t
*p_mi
)
1900 input_thread_t
*p_input_thread
;
1901 bool b_program_scrambled
;
1903 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1904 if ( !p_input_thread
)
1906 b_program_scrambled
= var_GetBool( p_input_thread
, "program-scrambled" );
1907 vlc_object_release( p_input_thread
);
1909 return b_program_scrambled
;
1912 void libvlc_media_player_next_frame( libvlc_media_player_t
*p_mi
)
1914 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1915 if( p_input_thread
!= NULL
)
1917 var_TriggerCallback( p_input_thread
, "frame-next" );
1918 vlc_object_release( p_input_thread
);
1923 * Private lookup table to get subpicture alignment flag values corresponding
1924 * to a libvlc_position_t enumerated value.
1926 static const unsigned char position_subpicture_alignment
[] = {
1927 [libvlc_position_center
] = 0,
1928 [libvlc_position_left
] = SUBPICTURE_ALIGN_LEFT
,
1929 [libvlc_position_right
] = SUBPICTURE_ALIGN_RIGHT
,
1930 [libvlc_position_top
] = SUBPICTURE_ALIGN_TOP
,
1931 [libvlc_position_top_left
] = SUBPICTURE_ALIGN_TOP
| SUBPICTURE_ALIGN_LEFT
,
1932 [libvlc_position_top_right
] = SUBPICTURE_ALIGN_TOP
| SUBPICTURE_ALIGN_RIGHT
,
1933 [libvlc_position_bottom
] = SUBPICTURE_ALIGN_BOTTOM
,
1934 [libvlc_position_bottom_left
] = SUBPICTURE_ALIGN_BOTTOM
| SUBPICTURE_ALIGN_LEFT
,
1935 [libvlc_position_bottom_right
] = SUBPICTURE_ALIGN_BOTTOM
| SUBPICTURE_ALIGN_RIGHT
1938 void libvlc_media_player_set_video_title_display( libvlc_media_player_t
*p_mi
, libvlc_position_t position
, unsigned timeout
)
1940 assert( position
>= libvlc_position_disable
&& position
<= libvlc_position_bottom_right
);
1942 if ( position
!= libvlc_position_disable
)
1944 var_SetBool( p_mi
, "video-title-show", true );
1945 var_SetInteger( p_mi
, "video-title-position", position_subpicture_alignment
[position
] );
1946 var_SetInteger( p_mi
, "video-title-timeout", timeout
);
1950 var_SetBool( p_mi
, "video-title-show", false );
1954 int libvlc_media_player_add_slave( libvlc_media_player_t
*p_mi
,
1955 libvlc_media_slave_type_t i_type
,
1956 const char *psz_uri
, bool b_select
)
1958 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1960 if( p_input_thread
== NULL
)
1962 libvlc_media_t
*p_media
= libvlc_media_player_get_media( p_mi
);
1963 if( p_media
== NULL
)
1966 int i_ret
= libvlc_media_slaves_add( p_media
, i_type
, 4, psz_uri
);
1967 libvlc_media_release( p_media
);
1972 int i_ret
= input_AddSlave( p_input_thread
, (enum slave_type
) i_type
,
1973 psz_uri
, b_select
, false, false );
1974 vlc_object_release( p_input_thread
);
1976 return i_ret
== VLC_SUCCESS
? 0 : -1;
1981 * Maximum size of a formatted equalizer amplification band frequency value.
1983 * The allowed value range is supposed to be constrained from -20.0 to 20.0.
1985 * The format string " %.07f" with a minimum value of "-20" gives a maximum
1986 * string length of e.g. " -19.1234567", i.e. 12 bytes (not including the null
1989 #define EQZ_BAND_VALUE_SIZE 12
1991 int libvlc_media_player_set_equalizer( libvlc_media_player_t
*p_mi
, libvlc_equalizer_t
*p_equalizer
)
1993 char bands
[EQZ_BANDS_MAX
* EQZ_BAND_VALUE_SIZE
+ 1];
1995 if( p_equalizer
!= NULL
)
1997 for( unsigned i
= 0, c
= 0; i
< EQZ_BANDS_MAX
; i
++ )
1999 c
+= snprintf( bands
+ c
, sizeof(bands
) - c
, " %.07f",
2000 p_equalizer
->f_amp
[i
] );
2001 if( unlikely(c
>= sizeof(bands
)) )
2005 var_SetFloat( p_mi
, "equalizer-preamp", p_equalizer
->f_preamp
);
2006 var_SetString( p_mi
, "equalizer-bands", bands
);
2008 var_SetString( p_mi
, "audio-filter", p_equalizer
? "equalizer" : "" );
2010 audio_output_t
*p_aout
= input_resource_HoldAout( p_mi
->input
.p_resource
);
2011 if( p_aout
!= NULL
)
2013 if( p_equalizer
!= NULL
)
2015 var_SetFloat( p_aout
, "equalizer-preamp", p_equalizer
->f_preamp
);
2016 var_SetString( p_aout
, "equalizer-bands", bands
);
2019 var_SetString( p_aout
, "audio-filter", p_equalizer
? "equalizer" : "" );
2020 vlc_object_release( p_aout
);
2026 static const char roles
[][16] =
2028 [libvlc_role_Music
] = "music",
2029 [libvlc_role_Video
] = "video",
2030 [libvlc_role_Communication
] = "communication",
2031 [libvlc_role_Game
] = "game",
2032 [libvlc_role_Notification
] = "notification",
2033 [libvlc_role_Animation
] = "animation",
2034 [libvlc_role_Production
] = "production",
2035 [libvlc_role_Accessibility
] = "accessibility",
2036 [libvlc_role_Test
] = "test",
2039 int libvlc_media_player_set_role(libvlc_media_player_t
*mp
, unsigned role
)
2041 if (role
>= ARRAY_SIZE(roles
)
2042 || var_SetString(mp
, "role", roles
[role
]) != VLC_SUCCESS
)
2047 int libvlc_media_player_get_role(libvlc_media_player_t
*mp
)
2050 char *str
= var_GetString(mp
, "role");
2054 for (size_t i
= 0; i
< ARRAY_SIZE(roles
); i
++)
2055 if (!strcmp(roles
[i
], str
))