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>
41 #include "libvlc_internal.h"
42 #include "media_internal.h" // libvlc_media_set_state()
43 #include "media_player_internal.h"
44 #include "renderer_discoverer_internal.h"
46 #define ES_INIT (-2) /* -1 is reserved for ES deselect */
49 input_seekable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
50 vlc_value_t oldval
, vlc_value_t newval
,
53 input_pausable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
54 vlc_value_t oldval
, vlc_value_t newval
,
57 input_scrambled_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
58 vlc_value_t oldval
, vlc_value_t newval
,
61 input_event_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
62 vlc_value_t oldval
, vlc_value_t newval
,
66 input_es_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
67 int action
, vlc_value_t
*p_val
,
71 corks_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
72 vlc_value_t cur
, void *opaque
);
75 mute_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
76 vlc_value_t cur
, void *opaque
);
79 volume_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
80 vlc_value_t cur
, void *opaque
);
83 add_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
);
86 del_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
);
89 snapshot_was_taken( vlc_object_t
*p_this
, char const *psz_cmd
,
90 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
);
92 static void libvlc_media_player_destroy( libvlc_media_player_t
*p_mi
);
99 * The input lock protects the input and input resource pointer.
100 * It MUST NOT be used from callbacks.
102 * The object lock protects the reset, namely the media and the player state.
103 * It can, and usually needs to be taken from callbacks.
104 * The object lock can be acquired under the input lock... and consequently
105 * the opposite order is STRICTLY PROHIBITED.
107 static inline void lock(libvlc_media_player_t
*mp
)
109 vlc_mutex_lock(&mp
->object_lock
);
112 static inline void unlock(libvlc_media_player_t
*mp
)
114 vlc_mutex_unlock(&mp
->object_lock
);
117 static inline void lock_input(libvlc_media_player_t
*mp
)
119 vlc_mutex_lock(&mp
->input
.lock
);
122 static inline void unlock_input(libvlc_media_player_t
*mp
)
124 vlc_mutex_unlock(&mp
->input
.lock
);
127 static void input_item_preparsed_changed( const vlc_event_t
*p_event
,
130 libvlc_media_t
*p_md
= user_data
;
131 if( p_event
->u
.input_item_preparsed_changed
.new_status
& ITEM_PREPARSED
)
134 libvlc_event_t event
;
135 event
.type
= libvlc_MediaParsedChanged
;
136 event
.u
.media_parsed_changed
.new_status
= libvlc_media_parsed_status_done
;
137 libvlc_event_send( &p_md
->event_manager
, &event
);
141 static void media_attach_preparsed_event( libvlc_media_t
*p_md
)
143 vlc_event_attach( &p_md
->p_input_item
->event_manager
,
144 vlc_InputItemPreparsedChanged
,
145 input_item_preparsed_changed
, p_md
);
148 static void media_detach_preparsed_event( libvlc_media_t
*p_md
)
150 vlc_event_detach( &p_md
->p_input_item
->event_manager
,
151 vlc_InputItemPreparsedChanged
,
152 input_item_preparsed_changed
,
157 * Release the associated input thread.
159 * Object lock is NOT held.
160 * Input lock is held or instance is being destroyed.
162 static void release_input_thread( libvlc_media_player_t
*p_mi
)
166 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
167 if( !p_input_thread
)
169 p_mi
->input
.p_thread
= NULL
;
171 media_detach_preparsed_event( p_mi
->p_md
);
173 var_DelCallback( p_input_thread
, "can-seek",
174 input_seekable_changed
, p_mi
);
175 var_DelCallback( p_input_thread
, "can-pause",
176 input_pausable_changed
, p_mi
);
177 var_DelCallback( p_input_thread
, "program-scrambled",
178 input_scrambled_changed
, p_mi
);
179 var_DelCallback( p_input_thread
, "intf-event",
180 input_event_changed
, p_mi
);
181 del_es_callbacks( p_input_thread
, p_mi
);
183 /* We owned this one */
184 input_Stop( p_input_thread
);
185 input_Close( p_input_thread
);
189 * Retrieve the input thread. Be sure to release the object
190 * once you are done with it. (libvlc Internal)
192 input_thread_t
*libvlc_get_input_thread( libvlc_media_player_t
*p_mi
)
194 input_thread_t
*p_input_thread
;
199 p_input_thread
= p_mi
->input
.p_thread
;
201 vlc_object_hold( p_input_thread
);
203 libvlc_printerr( "No active input" );
206 return p_input_thread
;
210 * Set the internal state of the media_player. (media player Internal)
212 * Function will lock the media_player.
214 static void set_state( libvlc_media_player_t
*p_mi
, libvlc_state_t state
,
221 libvlc_media_t
*media
= p_mi
->p_md
;
223 libvlc_media_retain(media
);
230 // Also set the state of the corresponding media
231 // This is strictly for convenience.
232 libvlc_media_set_state(media
, state
);
234 libvlc_media_release(media
);
239 input_seekable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
240 vlc_value_t oldval
, vlc_value_t newval
,
246 libvlc_media_player_t
* p_mi
= p_userdata
;
247 libvlc_event_t event
;
249 event
.type
= libvlc_MediaPlayerSeekableChanged
;
250 event
.u
.media_player_seekable_changed
.new_seekable
= newval
.b_bool
;
252 libvlc_event_send( &p_mi
->event_manager
, &event
);
257 input_pausable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
258 vlc_value_t oldval
, vlc_value_t newval
,
264 libvlc_media_player_t
* p_mi
= p_userdata
;
265 libvlc_event_t event
;
267 event
.type
= libvlc_MediaPlayerPausableChanged
;
268 event
.u
.media_player_pausable_changed
.new_pausable
= newval
.b_bool
;
270 libvlc_event_send( &p_mi
->event_manager
, &event
);
275 input_scrambled_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
276 vlc_value_t oldval
, vlc_value_t newval
,
282 libvlc_media_player_t
* p_mi
= p_userdata
;
283 libvlc_event_t event
;
285 event
.type
= libvlc_MediaPlayerScrambledChanged
;
286 event
.u
.media_player_scrambled_changed
.new_scrambled
= newval
.b_bool
;
288 libvlc_event_send( &p_mi
->event_manager
, &event
);
293 input_event_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
294 vlc_value_t oldval
, vlc_value_t newval
,
297 VLC_UNUSED(oldval
); VLC_UNUSED(psz_cmd
);
298 input_thread_t
* p_input
= (input_thread_t
*)p_this
;
299 libvlc_media_player_t
* p_mi
= p_userdata
;
300 libvlc_event_t event
;
302 assert( !strcmp( psz_cmd
, "intf-event" ) );
304 if( newval
.i_int
== INPUT_EVENT_STATE
)
306 libvlc_state_t libvlc_state
;
308 switch ( var_GetInteger( p_input
, "state" ) )
311 libvlc_state
= libvlc_NothingSpecial
;
312 event
.type
= libvlc_MediaPlayerNothingSpecial
;
315 libvlc_state
= libvlc_Opening
;
316 event
.type
= libvlc_MediaPlayerOpening
;
319 libvlc_state
= libvlc_Playing
;
320 event
.type
= libvlc_MediaPlayerPlaying
;
323 libvlc_state
= libvlc_Paused
;
324 event
.type
= libvlc_MediaPlayerPaused
;
327 libvlc_state
= libvlc_Ended
;
328 event
.type
= libvlc_MediaPlayerEndReached
;
331 libvlc_state
= libvlc_Error
;
332 event
.type
= libvlc_MediaPlayerEncounteredError
;
339 set_state( p_mi
, libvlc_state
, false );
340 libvlc_event_send( &p_mi
->event_manager
, &event
);
342 else if( newval
.i_int
== INPUT_EVENT_DEAD
)
344 libvlc_state_t libvlc_state
= libvlc_Ended
;
345 event
.type
= libvlc_MediaPlayerStopped
;
347 set_state( p_mi
, libvlc_state
, false );
348 libvlc_event_send( &p_mi
->event_manager
, &event
);
350 else if( newval
.i_int
== INPUT_EVENT_POSITION
)
352 if( var_GetInteger( p_input
, "state" ) != PLAYING_S
)
353 return VLC_SUCCESS
; /* Don't send the position while stopped */
356 event
.type
= libvlc_MediaPlayerPositionChanged
;
357 event
.u
.media_player_position_changed
.new_position
=
358 var_GetFloat( p_input
, "position" );
359 libvlc_event_send( &p_mi
->event_manager
, &event
);
362 event
.type
= libvlc_MediaPlayerTimeChanged
;
363 event
.u
.media_player_time_changed
.new_time
=
364 from_mtime(var_GetInteger( p_input
, "time" ));
365 libvlc_event_send( &p_mi
->event_manager
, &event
);
367 else if( newval
.i_int
== INPUT_EVENT_LENGTH
)
369 event
.type
= libvlc_MediaPlayerLengthChanged
;
370 event
.u
.media_player_length_changed
.new_length
=
371 from_mtime(var_GetInteger( p_input
, "length" ));
372 libvlc_event_send( &p_mi
->event_manager
, &event
);
374 else if( newval
.i_int
== INPUT_EVENT_CACHE
)
376 event
.type
= libvlc_MediaPlayerBuffering
;
377 event
.u
.media_player_buffering
.new_cache
= (100 *
378 var_GetFloat( p_input
, "cache" ));
379 libvlc_event_send( &p_mi
->event_manager
, &event
);
381 else if( newval
.i_int
== INPUT_EVENT_VOUT
)
383 vout_thread_t
**pp_vout
;
385 if( input_Control( p_input
, INPUT_GET_VOUTS
, &pp_vout
, &i_vout
) )
391 for( size_t i
= 0; i
< i_vout
; i
++ )
392 vlc_object_release( pp_vout
[i
] );
396 event
.type
= libvlc_MediaPlayerVout
;
397 event
.u
.media_player_vout
.new_count
= i_vout
;
398 libvlc_event_send( &p_mi
->event_manager
, &event
);
400 else if ( newval
.i_int
== INPUT_EVENT_TITLE
)
402 event
.type
= libvlc_MediaPlayerTitleChanged
;
403 event
.u
.media_player_title_changed
.new_title
= var_GetInteger( p_input
, "title" );
404 libvlc_event_send( &p_mi
->event_manager
, &event
);
406 else if ( newval
.i_int
== INPUT_EVENT_CHAPTER
)
408 event
.type
= libvlc_MediaPlayerChapterChanged
;
409 event
.u
.media_player_chapter_changed
.new_chapter
= var_GetInteger( p_input
, "chapter" );
410 libvlc_event_send( &p_mi
->event_manager
, &event
);
412 else if ( newval
.i_int
== INPUT_EVENT_ES
)
414 /* Send ESSelected events from this callback ("intf-event") and not
415 * from "audio-es", "video-es", "spu-es" callbacks. Indeed, these
416 * callbacks are not triggered when the input_thread changes an ES
417 * while this callback is. */
419 const char *psz_name
;
420 const libvlc_track_type_t type
;
423 { "audio-es", libvlc_track_audio
, ES_INIT
},
424 { "video-es", libvlc_track_video
, ES_INIT
},
425 { "spu-es", libvlc_track_text
, ES_INIT
},
427 /* Check if an ES selection changed */
429 for( size_t i
= 0; i
< ARRAY_SIZE( es_list
); ++i
)
431 int current_es
= var_GetInteger( p_input
, es_list
[i
].psz_name
);
432 if( current_es
!= p_mi
->selected_es
[i
] )
433 es_list
[i
].new_es
= p_mi
->selected_es
[i
] = current_es
;
437 /* Send the ESSelected event for each ES that were newly selected */
438 for( size_t i
= 0; i
< ARRAY_SIZE( es_list
); ++i
)
440 if( es_list
[i
].new_es
!= ES_INIT
)
442 event
.type
= libvlc_MediaPlayerESSelected
;
443 event
.u
.media_player_es_changed
.i_type
= es_list
[i
].type
;
444 event
.u
.media_player_es_changed
.i_id
= es_list
[i
].new_es
;
445 libvlc_event_send( &p_mi
->event_manager
, &event
);
453 static int track_type_from_name(const char *psz_name
)
455 if( !strcmp( psz_name
, "video-es" ) )
456 return libvlc_track_video
;
457 else if( !strcmp( psz_name
, "audio-es" ) )
458 return libvlc_track_audio
;
459 else if( !strcmp( psz_name
, "spu-es" ) )
460 return libvlc_track_text
;
462 return libvlc_track_unknown
;
465 static int input_es_changed( vlc_object_t
*p_this
,
472 libvlc_media_player_t
*mp
= p_userdata
;
473 libvlc_event_t event
;
475 /* Ignore the "Disable" element */
476 if (p_val
&& p_val
->i_int
< 0)
481 case VLC_VAR_ADDCHOICE
:
482 event
.type
= libvlc_MediaPlayerESAdded
;
484 case VLC_VAR_DELCHOICE
:
485 case VLC_VAR_CLEARCHOICES
:
486 event
.type
= libvlc_MediaPlayerESDeleted
;
492 event
.u
.media_player_es_changed
.i_type
= track_type_from_name(psz_cmd
);
495 if (action
!= VLC_VAR_CLEARCHOICES
)
503 /* -1 means all ES tracks of this type were deleted. */
506 event
.u
.media_player_es_changed
.i_id
= i_id
;
508 libvlc_event_send(&mp
->event_manager
, &event
);
513 /**************************************************************************
514 * Snapshot Taken Event.
516 * FIXME: This snapshot API interface makes no sense in media_player.
517 *************************************************************************/
518 static int snapshot_was_taken(vlc_object_t
*p_this
, char const *psz_cmd
,
519 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
521 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_this
);
523 libvlc_media_player_t
*mp
= p_data
;
524 libvlc_event_t event
;
525 event
.type
= libvlc_MediaPlayerSnapshotTaken
;
526 event
.u
.media_player_snapshot_taken
.psz_filename
= newval
.psz_string
;
527 libvlc_event_send(&mp
->event_manager
, &event
);
532 static int corks_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
533 vlc_value_t cur
, void *opaque
)
535 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
537 if (!old
.i_int
!= !cur
.i_int
)
539 libvlc_event_t event
;
541 event
.type
= cur
.i_int
? libvlc_MediaPlayerCorked
542 : libvlc_MediaPlayerUncorked
;
543 libvlc_event_send(&mp
->event_manager
, &event
);
545 VLC_UNUSED(name
); VLC_UNUSED(opaque
);
549 static int audio_device_changed(vlc_object_t
*obj
, const char *name
,
550 vlc_value_t old
, vlc_value_t cur
, void *opaque
)
552 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
553 libvlc_event_t event
;
555 event
.type
= libvlc_MediaPlayerAudioDevice
;
556 event
.u
.media_player_audio_device
.device
= cur
.psz_string
;
557 libvlc_event_send(&mp
->event_manager
, &event
);
558 VLC_UNUSED(name
); VLC_UNUSED(old
); VLC_UNUSED(opaque
);
562 static int mute_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
563 vlc_value_t cur
, void *opaque
)
565 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
567 if (old
.b_bool
!= cur
.b_bool
)
569 libvlc_event_t event
;
571 event
.type
= cur
.b_bool
? libvlc_MediaPlayerMuted
572 : libvlc_MediaPlayerUnmuted
;
573 libvlc_event_send(&mp
->event_manager
, &event
);
575 VLC_UNUSED(name
); VLC_UNUSED(opaque
);
579 static int volume_changed(vlc_object_t
*obj
, const char *name
, vlc_value_t old
,
580 vlc_value_t cur
, void *opaque
)
582 libvlc_media_player_t
*mp
= (libvlc_media_player_t
*)obj
;
583 libvlc_event_t event
;
585 event
.type
= libvlc_MediaPlayerAudioVolume
;
586 event
.u
.media_player_audio_volume
.volume
= cur
.f_float
;
587 libvlc_event_send(&mp
->event_manager
, &event
);
588 VLC_UNUSED(name
); VLC_UNUSED(old
); VLC_UNUSED(opaque
);
592 /**************************************************************************
593 * Create a Media Instance object.
596 * - All items created by _new start with a refcount set to 1.
597 * - Accessor _release decrease the refcount by 1, if after that
598 * operation the refcount is 0, the object is destroyed.
599 * - Accessor _retain increase the refcount by 1 (XXX: to implement)
601 * Object locking strategy:
602 * - No lock held while in constructor.
603 * - When accessing any member variable this lock is held. (XXX who locks?)
604 * - When attempting to destroy the object the lock is also held.
605 **************************************************************************/
606 libvlc_media_player_t
*
607 libvlc_media_player_new( libvlc_instance_t
*instance
)
609 libvlc_media_player_t
* mp
;
613 mp
= vlc_object_create (instance
->p_libvlc_int
, sizeof(*mp
));
614 if (unlikely(mp
== NULL
))
616 libvlc_printerr("Not enough memory");
621 var_Create (mp
, "rate", VLC_VAR_FLOAT
|VLC_VAR_DOINHERIT
);
622 var_Create (mp
, "sout", VLC_VAR_STRING
);
623 var_Create (mp
, "demux-filter", VLC_VAR_STRING
);
626 var_Create (mp
, "vout", VLC_VAR_STRING
|VLC_VAR_DOINHERIT
);
627 var_Create (mp
, "window", VLC_VAR_STRING
);
628 var_Create (mp
, "vmem-lock", VLC_VAR_ADDRESS
);
629 var_Create (mp
, "vmem-unlock", VLC_VAR_ADDRESS
);
630 var_Create (mp
, "vmem-display", VLC_VAR_ADDRESS
);
631 var_Create (mp
, "vmem-data", VLC_VAR_ADDRESS
);
632 var_Create (mp
, "vmem-setup", VLC_VAR_ADDRESS
);
633 var_Create (mp
, "vmem-cleanup", VLC_VAR_ADDRESS
);
634 var_Create (mp
, "vmem-chroma", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
635 var_Create (mp
, "vmem-width", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
636 var_Create (mp
, "vmem-height", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
637 var_Create (mp
, "vmem-pitch", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
638 var_Create (mp
, "avcodec-hw", VLC_VAR_STRING
);
639 var_Create (mp
, "drawable-xid", VLC_VAR_INTEGER
);
640 #if defined (_WIN32) || defined (__OS2__)
641 var_Create (mp
, "drawable-hwnd", VLC_VAR_INTEGER
);
644 var_Create (mp
, "drawable-nsobject", VLC_VAR_ADDRESS
);
647 var_Create (mp
, "drawable-androidwindow", VLC_VAR_ADDRESS
);
650 var_Create (mp
, "keyboard-events", VLC_VAR_BOOL
);
651 var_SetBool (mp
, "keyboard-events", true);
652 var_Create (mp
, "mouse-events", VLC_VAR_BOOL
);
653 var_SetBool (mp
, "mouse-events", true);
655 var_Create (mp
, "fullscreen", VLC_VAR_BOOL
);
656 var_Create (mp
, "autoscale", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
657 var_Create (mp
, "zoom", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
658 var_Create (mp
, "aspect-ratio", VLC_VAR_STRING
);
659 var_Create (mp
, "crop", VLC_VAR_STRING
);
660 var_Create (mp
, "deinterlace", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
661 var_Create (mp
, "deinterlace-mode", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
663 var_Create (mp
, "vbi-page", VLC_VAR_INTEGER
);
664 var_SetInteger (mp
, "vbi-page", 100);
666 var_Create (mp
, "video-filter", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
667 var_Create (mp
, "sub-source", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
668 var_Create (mp
, "sub-filter", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
670 var_Create (mp
, "marq-marquee", VLC_VAR_STRING
);
671 var_Create (mp
, "marq-color", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
672 var_Create (mp
, "marq-opacity", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
673 var_Create (mp
, "marq-position", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
674 var_Create (mp
, "marq-refresh", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
675 var_Create (mp
, "marq-size", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
676 var_Create (mp
, "marq-timeout", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
677 var_Create (mp
, "marq-x", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
678 var_Create (mp
, "marq-y", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
680 var_Create (mp
, "logo-file", VLC_VAR_STRING
);
681 var_Create (mp
, "logo-x", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
682 var_Create (mp
, "logo-y", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
683 var_Create (mp
, "logo-delay", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
684 var_Create (mp
, "logo-repeat", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
685 var_Create (mp
, "logo-opacity", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
686 var_Create (mp
, "logo-position", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
688 var_Create (mp
, "contrast", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
689 var_Create (mp
, "brightness", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
690 var_Create (mp
, "hue", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
691 var_Create (mp
, "saturation", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
692 var_Create (mp
, "gamma", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
695 var_Create (mp
, "aout", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
696 var_Create (mp
, "audio-device", VLC_VAR_STRING
);
697 var_Create (mp
, "mute", VLC_VAR_BOOL
);
698 var_Create (mp
, "volume", VLC_VAR_FLOAT
);
699 var_Create (mp
, "corks", VLC_VAR_INTEGER
);
700 var_Create (mp
, "audio-filter", VLC_VAR_STRING
);
701 var_Create (mp
, "role", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
702 var_Create (mp
, "amem-data", VLC_VAR_ADDRESS
);
703 var_Create (mp
, "amem-setup", VLC_VAR_ADDRESS
);
704 var_Create (mp
, "amem-cleanup", VLC_VAR_ADDRESS
);
705 var_Create (mp
, "amem-play", VLC_VAR_ADDRESS
);
706 var_Create (mp
, "amem-pause", VLC_VAR_ADDRESS
);
707 var_Create (mp
, "amem-resume", VLC_VAR_ADDRESS
);
708 var_Create (mp
, "amem-flush", VLC_VAR_ADDRESS
);
709 var_Create (mp
, "amem-drain", VLC_VAR_ADDRESS
);
710 var_Create (mp
, "amem-set-volume", VLC_VAR_ADDRESS
);
711 var_Create (mp
, "amem-format", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
712 var_Create (mp
, "amem-rate", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
713 var_Create (mp
, "amem-channels", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
716 var_Create (mp
, "video-title-show", VLC_VAR_BOOL
);
717 var_Create (mp
, "video-title-position", VLC_VAR_INTEGER
);
718 var_Create (mp
, "video-title-timeout", VLC_VAR_INTEGER
);
721 var_Create (mp
, "equalizer-preamp", VLC_VAR_FLOAT
);
722 var_Create (mp
, "equalizer-vlcfreqs", VLC_VAR_BOOL
);
723 var_Create (mp
, "equalizer-bands", VLC_VAR_STRING
);
725 /* Initialize the shared HTTP cookie jar */
727 cookies
.p_address
= vlc_http_cookies_new();
728 if ( likely(cookies
.p_address
) )
730 var_Create(mp
, "http-cookies", VLC_VAR_ADDRESS
);
731 var_SetChecked(mp
, "http-cookies", VLC_VAR_ADDRESS
, cookies
);
735 mp
->state
= libvlc_NothingSpecial
;
736 mp
->p_libvlc_instance
= instance
;
737 mp
->input
.p_thread
= NULL
;
738 mp
->input
.p_renderer
= NULL
;
739 mp
->input
.p_resource
= input_resource_New(VLC_OBJECT(mp
));
740 if (unlikely(mp
->input
.p_resource
== NULL
))
742 vlc_object_release(mp
);
745 audio_output_t
*aout
= input_resource_GetAout(mp
->input
.p_resource
);
747 input_resource_PutAout(mp
->input
.p_resource
, aout
);
749 vlc_viewpoint_init(&mp
->viewpoint
);
751 var_Create (mp
, "viewpoint", VLC_VAR_ADDRESS
);
752 var_SetAddress( mp
, "viewpoint", &mp
->viewpoint
);
753 vlc_mutex_init (&mp
->input
.lock
);
755 libvlc_event_manager_init(&mp
->event_manager
, mp
);
756 vlc_mutex_init(&mp
->object_lock
);
758 var_AddCallback(mp
, "corks", corks_changed
, NULL
);
759 var_AddCallback(mp
, "audio-device", audio_device_changed
, NULL
);
760 var_AddCallback(mp
, "mute", mute_changed
, NULL
);
761 var_AddCallback(mp
, "volume", volume_changed
, NULL
);
763 /* Snapshot initialization */
764 /* Attach a var callback to the global object to provide the glue between
765 * vout_thread that generates the event and media_player that re-emits it
766 * with its own event manager
768 * FIXME: It's unclear why we want to put this in public API, and why we
769 * want to expose it in such a limiting and ugly way.
771 var_AddCallback(mp
->obj
.libvlc
, "snapshot-file", snapshot_was_taken
, mp
);
773 libvlc_retain(instance
);
777 /**************************************************************************
778 * Create a Media Instance object with a media descriptor.
779 **************************************************************************/
780 libvlc_media_player_t
*
781 libvlc_media_player_new_from_media( libvlc_media_t
* p_md
)
783 libvlc_media_player_t
* p_mi
;
785 p_mi
= libvlc_media_player_new( p_md
->p_libvlc_instance
);
789 libvlc_media_retain( p_md
);
795 /**************************************************************************
796 * Destroy a Media Instance object (libvlc internal)
798 * Warning: No lock held here, but hey, this is internal. Caller must lock.
799 **************************************************************************/
800 static void libvlc_media_player_destroy( libvlc_media_player_t
*p_mi
)
804 /* Detach Callback from the main libvlc object */
805 var_DelCallback( p_mi
->obj
.libvlc
,
806 "snapshot-file", snapshot_was_taken
, p_mi
);
808 /* Detach callback from the media player / input manager object */
809 var_DelCallback( p_mi
, "volume", volume_changed
, NULL
);
810 var_DelCallback( p_mi
, "mute", mute_changed
, NULL
);
811 var_DelCallback( p_mi
, "audio-device", audio_device_changed
, NULL
);
812 var_DelCallback( p_mi
, "corks", corks_changed
, NULL
);
814 /* No need for lock_input() because no other threads knows us anymore */
815 if( p_mi
->input
.p_thread
)
816 release_input_thread(p_mi
);
817 input_resource_Terminate( p_mi
->input
.p_resource
);
818 input_resource_Release( p_mi
->input
.p_resource
);
819 if( p_mi
->input
.p_renderer
)
820 vlc_renderer_item_release( p_mi
->input
.p_renderer
);
822 vlc_mutex_destroy( &p_mi
->input
.lock
);
824 libvlc_event_manager_destroy(&p_mi
->event_manager
);
825 libvlc_media_release( p_mi
->p_md
);
826 vlc_mutex_destroy( &p_mi
->object_lock
);
828 vlc_http_cookie_jar_t
*cookies
= var_GetAddress( p_mi
, "http-cookies" );
831 var_Destroy( p_mi
, "http-cookies" );
832 vlc_http_cookies_destroy( cookies
);
835 libvlc_instance_t
*instance
= p_mi
->p_libvlc_instance
;
836 vlc_object_release( p_mi
);
837 libvlc_release(instance
);
840 /**************************************************************************
841 * Release a Media Instance object.
843 * Function does the locking.
844 **************************************************************************/
845 void libvlc_media_player_release( libvlc_media_player_t
*p_mi
)
851 destroy
= !--p_mi
->i_refcount
;
855 libvlc_media_player_destroy( p_mi
);
858 /**************************************************************************
859 * Retain a Media Instance object.
861 * Caller must hold the lock.
862 **************************************************************************/
863 void libvlc_media_player_retain( libvlc_media_player_t
*p_mi
)
872 /**************************************************************************
873 * Set the Media descriptor associated with the instance.
875 * Enter without lock -- function will lock the object.
876 **************************************************************************/
877 void libvlc_media_player_set_media(
878 libvlc_media_player_t
*p_mi
,
879 libvlc_media_t
*p_md
)
883 release_input_thread( p_mi
);
886 set_state( p_mi
, libvlc_NothingSpecial
, true );
887 unlock_input( p_mi
);
889 libvlc_media_release( p_mi
->p_md
);
895 return; /* It is ok to pass a NULL md */
898 libvlc_media_retain( p_md
);
901 /* The policy here is to ignore that we were created using a different
902 * libvlc_instance, because we don't really care */
903 p_mi
->p_libvlc_instance
= p_md
->p_libvlc_instance
;
907 /* Send an event for the newly available media */
908 libvlc_event_t event
;
909 event
.type
= libvlc_MediaPlayerMediaChanged
;
910 event
.u
.media_player_media_changed
.new_media
= p_md
;
911 libvlc_event_send( &p_mi
->event_manager
, &event
);
915 /**************************************************************************
916 * Get the Media descriptor associated with the instance.
917 **************************************************************************/
919 libvlc_media_player_get_media( libvlc_media_player_t
*p_mi
)
926 libvlc_media_retain( p_m
);
932 /**************************************************************************
933 * Get the event Manager.
934 **************************************************************************/
935 libvlc_event_manager_t
*
936 libvlc_media_player_event_manager( libvlc_media_player_t
*p_mi
)
938 return &p_mi
->event_manager
;
941 static void add_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
)
943 var_AddListCallback( p_input_thread
, "video-es", input_es_changed
, p_mi
);
944 var_AddListCallback( p_input_thread
, "audio-es", input_es_changed
, p_mi
);
945 var_AddListCallback( p_input_thread
, "spu-es", input_es_changed
, p_mi
);
948 static void del_es_callbacks( input_thread_t
*p_input_thread
, libvlc_media_player_t
*p_mi
)
950 var_DelListCallback( p_input_thread
, "video-es", input_es_changed
, p_mi
);
951 var_DelListCallback( p_input_thread
, "audio-es", input_es_changed
, p_mi
);
952 var_DelListCallback( p_input_thread
, "spu-es", input_es_changed
, p_mi
);
955 /**************************************************************************
956 * Tell media player to start playing.
957 **************************************************************************/
958 int libvlc_media_player_play( libvlc_media_player_t
*p_mi
)
962 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
965 /* A thread already exists, send it a play message */
966 var_SetInteger( p_input_thread
, "state", PLAYING_S
);
967 unlock_input( p_mi
);
971 /* Ignore previous exception */
977 unlock_input( p_mi
);
978 libvlc_printerr( "No associated media descriptor" );
982 for( size_t i
= 0; i
< ARRAY_SIZE( p_mi
->selected_es
); ++i
)
983 p_mi
->selected_es
[i
] = ES_INIT
;
985 media_attach_preparsed_event( p_mi
->p_md
);
987 p_input_thread
= input_Create( p_mi
, input_LegacyEvents
, NULL
,
988 p_mi
->p_md
->p_input_item
, NULL
,
989 p_mi
->input
.p_resource
,
990 p_mi
->input
.p_renderer
);
992 if( !p_input_thread
)
995 media_detach_preparsed_event( p_mi
->p_md
);
996 libvlc_printerr( "Not enough memory" );
1000 input_LegacyVarInit( p_input_thread
);
1001 var_AddCallback( p_input_thread
, "can-seek", input_seekable_changed
, p_mi
);
1002 var_AddCallback( p_input_thread
, "can-pause", input_pausable_changed
, p_mi
);
1003 var_AddCallback( p_input_thread
, "program-scrambled", input_scrambled_changed
, p_mi
);
1004 var_AddCallback( p_input_thread
, "intf-event", input_event_changed
, p_mi
);
1005 add_es_callbacks( p_input_thread
, p_mi
);
1007 if( input_Start( p_input_thread
) )
1010 del_es_callbacks( p_input_thread
, p_mi
);
1011 var_DelCallback( p_input_thread
, "intf-event", input_event_changed
, p_mi
);
1012 var_DelCallback( p_input_thread
, "can-pause", input_pausable_changed
, p_mi
);
1013 var_DelCallback( p_input_thread
, "program-scrambled", input_scrambled_changed
, p_mi
);
1014 var_DelCallback( p_input_thread
, "can-seek", input_seekable_changed
, p_mi
);
1015 input_Close( p_input_thread
);
1016 media_detach_preparsed_event( p_mi
->p_md
);
1017 libvlc_printerr( "Input initialization failure" );
1020 p_mi
->input
.p_thread
= p_input_thread
;
1025 void libvlc_media_player_set_pause( libvlc_media_player_t
*p_mi
, int paused
)
1027 input_thread_t
* p_input_thread
= libvlc_get_input_thread( p_mi
);
1028 if( !p_input_thread
)
1033 if( libvlc_media_player_can_pause( p_mi
) )
1034 var_SetInteger( p_input_thread
, "state", PAUSE_S
);
1036 input_Stop( p_input_thread
);
1040 var_SetInteger( p_input_thread
, "state", PLAYING_S
);
1043 vlc_object_release( p_input_thread
);
1046 /**************************************************************************
1048 **************************************************************************/
1049 void libvlc_media_player_pause( libvlc_media_player_t
*p_mi
)
1051 libvlc_media_player_set_pause( p_mi
, libvlc_media_player_is_playing( p_mi
) );
1054 /**************************************************************************
1055 * Tells whether the media player is currently playing.
1056 **************************************************************************/
1057 int libvlc_media_player_is_playing( libvlc_media_player_t
*p_mi
)
1059 libvlc_state_t state
= libvlc_media_player_get_state( p_mi
);
1060 return libvlc_Playing
== state
;
1063 /**************************************************************************
1065 **************************************************************************/
1066 void libvlc_media_player_stop( libvlc_media_player_t
*p_mi
)
1069 release_input_thread( p_mi
); /* This will stop the input thread */
1071 /* Force to go to stopped state, in case we were in Ended, or Error
1073 if( p_mi
->state
!= libvlc_Stopped
)
1075 set_state( p_mi
, libvlc_Stopped
, false );
1077 /* Construct and send the event */
1078 libvlc_event_t event
;
1079 event
.type
= libvlc_MediaPlayerStopped
;
1080 libvlc_event_send( &p_mi
->event_manager
, &event
);
1083 input_resource_Terminate( p_mi
->input
.p_resource
);
1087 int libvlc_media_player_set_renderer( libvlc_media_player_t
*p_mi
,
1088 libvlc_renderer_item_t
*p_litem
)
1090 vlc_renderer_item_t
*p_item
=
1091 p_litem
? libvlc_renderer_item_to_vlc( p_litem
) : NULL
;
1094 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
1095 if( p_input_thread
)
1096 input_Control( p_input_thread
, INPUT_SET_RENDERER
, p_item
);
1098 if( p_mi
->input
.p_renderer
)
1099 vlc_renderer_item_release( p_mi
->input
.p_renderer
);
1100 p_mi
->input
.p_renderer
= p_item
? vlc_renderer_item_hold( p_item
) : NULL
;
1101 unlock_input( p_mi
);
1106 void libvlc_video_set_callbacks( libvlc_media_player_t
*mp
,
1107 void *(*lock_cb
) (void *, void **),
1108 void (*unlock_cb
) (void *, void *, void *const *),
1109 void (*display_cb
) (void *, void *),
1112 var_SetAddress( mp
, "vmem-lock", lock_cb
);
1113 var_SetAddress( mp
, "vmem-unlock", unlock_cb
);
1114 var_SetAddress( mp
, "vmem-display", display_cb
);
1115 var_SetAddress( mp
, "vmem-data", opaque
);
1116 var_SetString( mp
, "avcodec-hw", "none" );
1117 var_SetString( mp
, "vout", "vmem" );
1118 var_SetString( mp
, "window", "dummy" );
1121 void libvlc_video_set_format_callbacks( libvlc_media_player_t
*mp
,
1122 libvlc_video_format_cb setup
,
1123 libvlc_video_cleanup_cb cleanup
)
1125 var_SetAddress( mp
, "vmem-setup", setup
);
1126 var_SetAddress( mp
, "vmem-cleanup", cleanup
);
1129 void libvlc_video_set_format( libvlc_media_player_t
*mp
, const char *chroma
,
1130 unsigned width
, unsigned height
, unsigned pitch
)
1132 var_SetString( mp
, "vmem-chroma", chroma
);
1133 var_SetInteger( mp
, "vmem-width", width
);
1134 var_SetInteger( mp
, "vmem-height", height
);
1135 var_SetInteger( mp
, "vmem-pitch", pitch
);
1138 /**************************************************************************
1140 **************************************************************************/
1141 void libvlc_media_player_set_nsobject( libvlc_media_player_t
*p_mi
,
1144 assert (p_mi
!= NULL
);
1146 var_SetString (p_mi
, "avcodec-hw", "");
1147 var_SetString (p_mi
, "vout", "");
1148 var_SetString (p_mi
, "window", "");
1149 var_SetAddress (p_mi
, "drawable-nsobject", drawable
);
1152 libvlc_printerr ("can't set nsobject: APPLE build required");
1154 var_SetString (p_mi
, "vout", "none");
1155 var_SetString (p_mi
, "window", "none");
1159 /**************************************************************************
1161 **************************************************************************/
1162 void * libvlc_media_player_get_nsobject( libvlc_media_player_t
*p_mi
)
1164 assert (p_mi
!= NULL
);
1166 return var_GetAddress (p_mi
, "drawable-nsobject");
1173 /**************************************************************************
1175 **************************************************************************/
1176 void libvlc_media_player_set_xwindow( libvlc_media_player_t
*p_mi
,
1179 assert (p_mi
!= NULL
);
1181 var_SetString (p_mi
, "avcodec-hw", "");
1182 var_SetString (p_mi
, "vout", "");
1183 var_SetString (p_mi
, "window", drawable
? "embed-xid,any" : "");
1184 var_SetInteger (p_mi
, "drawable-xid", drawable
);
1187 /**************************************************************************
1189 **************************************************************************/
1190 uint32_t libvlc_media_player_get_xwindow( libvlc_media_player_t
*p_mi
)
1192 return var_GetInteger (p_mi
, "drawable-xid");
1195 /**************************************************************************
1197 **************************************************************************/
1198 void libvlc_media_player_set_hwnd( libvlc_media_player_t
*p_mi
,
1201 assert (p_mi
!= NULL
);
1202 #if defined (_WIN32) || defined (__OS2__)
1203 var_SetString (p_mi
, "avcodec-hw", "");
1204 var_SetString (p_mi
, "vout", "");
1205 var_SetString (p_mi
, "window",
1206 (drawable
!= NULL
) ? "embed-hwnd,any" : "");
1207 var_SetInteger (p_mi
, "drawable-hwnd", (uintptr_t)drawable
);
1210 libvlc_printerr ("can't set nsobject: WIN32 build required");
1212 var_SetString (p_mi
, "vout", "none");
1213 var_SetString (p_mi
, "window", "none");
1217 /**************************************************************************
1219 **************************************************************************/
1220 void *libvlc_media_player_get_hwnd( libvlc_media_player_t
*p_mi
)
1222 assert (p_mi
!= NULL
);
1223 #if defined (_WIN32) || defined (__OS2__)
1224 return (void *)(uintptr_t)var_GetInteger (p_mi
, "drawable-hwnd");
1231 /**************************************************************************
1232 * set_android_context
1233 **************************************************************************/
1234 void libvlc_media_player_set_android_context( libvlc_media_player_t
*p_mi
,
1235 void *p_awindow_handler
)
1237 assert (p_mi
!= NULL
);
1239 var_SetAddress (p_mi
, "drawable-androidwindow", p_awindow_handler
);
1241 (void) p_awindow_handler
;
1242 libvlc_printerr ("can't set android context: ANDROID build required");
1244 var_SetString (p_mi
, "vout", "none");
1245 var_SetString (p_mi
, "window", "none");
1249 void libvlc_audio_set_callbacks( libvlc_media_player_t
*mp
,
1250 libvlc_audio_play_cb play_cb
,
1251 libvlc_audio_pause_cb pause_cb
,
1252 libvlc_audio_resume_cb resume_cb
,
1253 libvlc_audio_flush_cb flush_cb
,
1254 libvlc_audio_drain_cb drain_cb
,
1257 var_SetAddress( mp
, "amem-play", play_cb
);
1258 var_SetAddress( mp
, "amem-pause", pause_cb
);
1259 var_SetAddress( mp
, "amem-resume", resume_cb
);
1260 var_SetAddress( mp
, "amem-flush", flush_cb
);
1261 var_SetAddress( mp
, "amem-drain", drain_cb
);
1262 var_SetAddress( mp
, "amem-data", opaque
);
1263 var_SetString( mp
, "aout", "amem,none" );
1265 input_resource_ResetAout(mp
->input
.p_resource
);
1268 void libvlc_audio_set_volume_callback( libvlc_media_player_t
*mp
,
1269 libvlc_audio_set_volume_cb cb
)
1271 var_SetAddress( mp
, "amem-set-volume", cb
);
1273 input_resource_ResetAout(mp
->input
.p_resource
);
1276 void libvlc_audio_set_format_callbacks( libvlc_media_player_t
*mp
,
1277 libvlc_audio_setup_cb setup
,
1278 libvlc_audio_cleanup_cb cleanup
)
1280 var_SetAddress( mp
, "amem-setup", setup
);
1281 var_SetAddress( mp
, "amem-cleanup", cleanup
);
1283 input_resource_ResetAout(mp
->input
.p_resource
);
1286 void libvlc_audio_set_format( libvlc_media_player_t
*mp
, const char *format
,
1287 unsigned rate
, unsigned channels
)
1289 var_SetString( mp
, "amem-format", format
);
1290 var_SetInteger( mp
, "amem-rate", rate
);
1291 var_SetInteger( mp
, "amem-channels", channels
);
1293 input_resource_ResetAout(mp
->input
.p_resource
);
1297 /**************************************************************************
1298 * Getters for stream information
1299 **************************************************************************/
1300 libvlc_time_t
libvlc_media_player_get_length(
1301 libvlc_media_player_t
*p_mi
)
1303 input_thread_t
*p_input_thread
;
1304 libvlc_time_t i_time
;
1306 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1307 if( !p_input_thread
)
1310 i_time
= from_mtime(var_GetInteger( p_input_thread
, "length" ));
1311 vlc_object_release( p_input_thread
);
1316 libvlc_time_t
libvlc_media_player_get_time( libvlc_media_player_t
*p_mi
)
1318 input_thread_t
*p_input_thread
;
1319 libvlc_time_t i_time
;
1321 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1322 if( !p_input_thread
)
1325 i_time
= from_mtime(var_GetInteger( p_input_thread
, "time" ));
1326 vlc_object_release( p_input_thread
);
1330 int libvlc_media_player_set_time( libvlc_media_player_t
*p_mi
,
1331 libvlc_time_t i_time
, bool b_fast
)
1333 input_thread_t
*p_input_thread
;
1335 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1336 if( !p_input_thread
)
1339 input_SetTime( p_input_thread
, to_mtime(i_time
), b_fast
);
1340 vlc_object_release( p_input_thread
);
1344 int libvlc_media_player_set_position( libvlc_media_player_t
*p_mi
,
1345 float position
, bool b_fast
)
1347 input_thread_t
*p_input_thread
;
1349 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1350 if( !p_input_thread
)
1353 input_SetPosition( p_input_thread
, position
, b_fast
);
1354 vlc_object_release( p_input_thread
);
1358 float libvlc_media_player_get_position( libvlc_media_player_t
*p_mi
)
1360 input_thread_t
*p_input_thread
;
1363 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1364 if( !p_input_thread
)
1367 f_position
= var_GetFloat( p_input_thread
, "position" );
1368 vlc_object_release( p_input_thread
);
1373 void libvlc_media_player_set_chapter( libvlc_media_player_t
*p_mi
,
1376 input_thread_t
*p_input_thread
;
1378 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1379 if( !p_input_thread
)
1382 var_SetInteger( p_input_thread
, "chapter", chapter
);
1383 vlc_object_release( p_input_thread
);
1386 int libvlc_media_player_get_chapter( libvlc_media_player_t
*p_mi
)
1388 input_thread_t
*p_input_thread
;
1391 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1392 if( !p_input_thread
)
1395 i_chapter
= var_GetInteger( p_input_thread
, "chapter" );
1396 vlc_object_release( p_input_thread
);
1401 int libvlc_media_player_get_chapter_count( libvlc_media_player_t
*p_mi
)
1403 input_thread_t
*p_input_thread
;
1406 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1407 if( !p_input_thread
)
1410 int i_ret
= var_Change( p_input_thread
, "chapter", VLC_VAR_CHOICESCOUNT
, &val
);
1411 vlc_object_release( p_input_thread
);
1413 return i_ret
== VLC_SUCCESS
? (ssize_t
)val
: -1;
1416 int libvlc_media_player_get_chapter_count_for_title(
1417 libvlc_media_player_t
*p_mi
,
1422 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1423 if( !p_input_thread
)
1426 char psz_name
[sizeof ("title ") + 3 * sizeof (int)];
1427 sprintf( psz_name
, "title %2u", i_title
);
1429 int i_ret
= var_Change( p_input_thread
, psz_name
, VLC_VAR_CHOICESCOUNT
, &val
);
1430 vlc_object_release( p_input_thread
);
1432 return i_ret
== VLC_SUCCESS
? (ssize_t
)val
: -1;
1435 void libvlc_media_player_set_title( libvlc_media_player_t
*p_mi
,
1438 input_thread_t
*p_input_thread
;
1440 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1441 if( !p_input_thread
)
1444 var_SetInteger( p_input_thread
, "title", i_title
);
1445 vlc_object_release( p_input_thread
);
1448 libvlc_event_t event
;
1449 event
.type
= libvlc_MediaPlayerTitleChanged
;
1450 event
.u
.media_player_title_changed
.new_title
= i_title
;
1451 libvlc_event_send( &p_mi
->event_manager
, &event
);
1454 int libvlc_media_player_get_title( libvlc_media_player_t
*p_mi
)
1456 input_thread_t
*p_input_thread
;
1459 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1460 if( !p_input_thread
)
1463 i_title
= var_GetInteger( p_input_thread
, "title" );
1464 vlc_object_release( p_input_thread
);
1469 int libvlc_media_player_get_title_count( libvlc_media_player_t
*p_mi
)
1471 input_thread_t
*p_input_thread
;
1474 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1475 if( !p_input_thread
)
1478 int i_ret
= var_Change( p_input_thread
, "title", VLC_VAR_CHOICESCOUNT
, &val
);
1479 vlc_object_release( p_input_thread
);
1481 return i_ret
== VLC_SUCCESS
? (ssize_t
)val
: -1;
1484 int libvlc_media_player_get_full_title_descriptions( libvlc_media_player_t
*p_mi
,
1485 libvlc_title_description_t
*** pp_titles
)
1489 input_thread_t
*p_input_thread
= libvlc_get_input_thread( p_mi
);
1491 if( !p_input_thread
)
1494 input_title_t
**p_input_title
;
1498 int ret
= input_Control( p_input_thread
, INPUT_GET_FULL_TITLE_INFO
,
1499 &p_input_title
, &count
);
1500 vlc_object_release( p_input_thread
);
1501 if( ret
!= VLC_SUCCESS
)
1504 libvlc_title_description_t
**titles
= vlc_alloc( count
, sizeof (*titles
) );
1505 if( count
> 0 && unlikely(titles
== NULL
) )
1509 for( int i
= 0; i
< count
; i
++)
1511 libvlc_title_description_t
*title
= malloc( sizeof (*title
) );
1512 if( unlikely(title
== NULL
) )
1514 libvlc_title_descriptions_release( titles
, i
);
1519 /* we want to return milliseconds to match the rest of the API */
1520 title
->i_duration
= MS_FROM_VLC_TICK(p_input_title
[i
]->i_length
);
1521 title
->i_flags
= p_input_title
[i
]->i_flags
;
1522 if( p_input_title
[i
]->psz_name
)
1523 title
->psz_name
= strdup( p_input_title
[i
]->psz_name
);
1525 title
->psz_name
= NULL
;
1526 vlc_input_title_Delete( p_input_title
[i
] );
1528 free( p_input_title
);
1530 *pp_titles
= titles
;
1534 void libvlc_title_descriptions_release( libvlc_title_description_t
**p_titles
,
1537 for (unsigned i
= 0; i
< i_count
; i
++ )
1542 free( p_titles
[i
]->psz_name
);
1543 free( p_titles
[i
] );
1548 int libvlc_media_player_get_full_chapter_descriptions( libvlc_media_player_t
*p_mi
,
1549 int i_chapters_of_title
,
1550 libvlc_chapter_description_t
*** pp_chapters
)
1554 input_thread_t
*p_input_thread
= libvlc_get_input_thread( p_mi
);
1556 if( !p_input_thread
)
1559 seekpoint_t
**p_seekpoint
= NULL
;
1560 input_title_t
**pp_title
, *p_title
= NULL
;
1561 int i_title_count
= 0, ci_chapter_count
= 0;
1562 int ret
= input_Control( p_input_thread
, INPUT_GET_FULL_TITLE_INFO
, &pp_title
,
1564 vlc_object_release( p_input_thread
);
1566 if( ret
!= VLC_SUCCESS
|| i_chapters_of_title
>= i_title_count
)
1569 p_title
= pp_title
[i_chapters_of_title
];
1570 int64_t i_title_duration
= MS_FROM_VLC_TICK(p_title
->i_length
);
1571 p_seekpoint
= p_title
->seekpoint
;
1572 ci_chapter_count
= p_title
->i_seekpoint
;
1574 if( ci_chapter_count
== 0 || p_seekpoint
== NULL
)
1577 *pp_chapters
= calloc( ci_chapter_count
, sizeof(**pp_chapters
) );
1584 for( int i
= 0; i
< ci_chapter_count
; ++i
)
1586 libvlc_chapter_description_t
*p_chapter
= malloc( sizeof(*p_chapter
) );
1587 if( unlikely(p_chapter
== NULL
) )
1591 (*pp_chapters
)[i
] = p_chapter
;
1593 p_chapter
->i_time_offset
= p_seekpoint
[i
]->i_time_offset
/ 1000;
1595 if( i
< ci_chapter_count
- 1 )
1597 p_chapter
->i_duration
= p_seekpoint
[i
+ 1]->i_time_offset
/ 1000 -
1598 p_chapter
->i_time_offset
;
1602 if ( i_title_duration
)
1603 p_chapter
->i_duration
= i_title_duration
- p_chapter
->i_time_offset
;
1605 p_chapter
->i_duration
= 0;
1608 if( p_seekpoint
[i
]->psz_name
)
1610 p_chapter
->psz_name
= strdup( p_seekpoint
[i
]->psz_name
);
1614 p_chapter
->psz_name
= NULL
;
1616 vlc_seekpoint_Delete( p_seekpoint
[i
] );
1617 p_seekpoint
[i
] = NULL
;
1620 free( p_seekpoint
);
1621 return ci_chapter_count
;
1625 libvlc_chapter_descriptions_release( *pp_chapters
, ci_chapter_count
);
1626 for( int i
= 0; i
< i_title_count
; i
++ )
1627 vlc_input_title_Delete( pp_title
[i
] );
1632 void libvlc_chapter_descriptions_release( libvlc_chapter_description_t
**p_chapters
,
1635 for (unsigned i
= 0; i
< i_count
; i
++ )
1637 if ( !p_chapters
[i
] )
1640 free( p_chapters
[i
]->psz_name
);
1641 free( p_chapters
[i
] );
1646 void libvlc_media_player_next_chapter( libvlc_media_player_t
*p_mi
)
1648 input_thread_t
*p_input_thread
;
1650 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1651 if( !p_input_thread
)
1654 int i_type
= var_Type( p_input_thread
, "next-chapter" );
1655 var_TriggerCallback( p_input_thread
, (i_type
& VLC_VAR_TYPE
) != 0 ?
1656 "next-chapter":"next-title" );
1658 vlc_object_release( p_input_thread
);
1661 void libvlc_media_player_previous_chapter( libvlc_media_player_t
*p_mi
)
1663 input_thread_t
*p_input_thread
;
1665 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1666 if( !p_input_thread
)
1669 int i_type
= var_Type( p_input_thread
, "next-chapter" );
1670 var_TriggerCallback( p_input_thread
, (i_type
& VLC_VAR_TYPE
) != 0 ?
1671 "prev-chapter":"prev-title" );
1673 vlc_object_release( p_input_thread
);
1676 int libvlc_media_player_will_play( libvlc_media_player_t
*p_mi
)
1678 input_thread_t
*p_input_thread
=
1679 libvlc_get_input_thread ( p_mi
);
1680 if ( !p_input_thread
)
1683 int state
= var_GetInteger( p_input_thread
, "state" );
1684 vlc_object_release( p_input_thread
);
1686 return state
!= END_S
&& state
!= ERROR_S
;
1689 int libvlc_media_player_set_rate( libvlc_media_player_t
*p_mi
, float rate
)
1691 var_SetFloat (p_mi
, "rate", rate
);
1693 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1694 if( !p_input_thread
)
1696 var_SetFloat( p_input_thread
, "rate", rate
);
1697 vlc_object_release( p_input_thread
);
1701 float libvlc_media_player_get_rate( libvlc_media_player_t
*p_mi
)
1703 return var_GetFloat (p_mi
, "rate");
1706 libvlc_state_t
libvlc_media_player_get_state( libvlc_media_player_t
*p_mi
)
1709 libvlc_state_t state
= p_mi
->state
;
1714 int libvlc_media_player_is_seekable( libvlc_media_player_t
*p_mi
)
1716 input_thread_t
*p_input_thread
;
1719 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1720 if ( !p_input_thread
)
1722 b_seekable
= var_GetBool( p_input_thread
, "can-seek" );
1723 vlc_object_release( p_input_thread
);
1728 void libvlc_media_player_navigate( libvlc_media_player_t
* p_mi
,
1731 static const int map
[] =
1733 INPUT_NAV_ACTIVATE
, INPUT_NAV_UP
, INPUT_NAV_DOWN
,
1734 INPUT_NAV_LEFT
, INPUT_NAV_RIGHT
, INPUT_NAV_POPUP
,
1737 if( navigate
>= sizeof(map
) / sizeof(map
[0]) )
1740 input_thread_t
*p_input
= libvlc_get_input_thread ( p_mi
);
1741 if ( p_input
== NULL
)
1744 input_Control( p_input
, map
[navigate
], NULL
);
1745 vlc_object_release( p_input
);
1748 /* internal function, used by audio, video */
1749 libvlc_track_description_t
*
1750 libvlc_get_track_description( libvlc_media_player_t
*p_mi
,
1751 const char *psz_variable
)
1753 input_thread_t
*p_input
= libvlc_get_input_thread( p_mi
);
1754 libvlc_track_description_t
*ret
, **pp
= &ret
;
1759 vlc_value_t
*val_list
;
1763 int i_ret
= var_Change( p_input
, psz_variable
, VLC_VAR_GETCHOICES
,
1764 &count
, &val_list
, &text_list
);
1765 if( i_ret
!= VLC_SUCCESS
)
1768 for (size_t i
= 0; i
< count
; i
++)
1770 libvlc_track_description_t
*tr
= malloc(sizeof (*tr
));
1771 if (unlikely(tr
== NULL
))
1773 libvlc_printerr("Not enough memory");
1778 tr
->i_id
= val_list
[i
].i_int
;
1779 tr
->psz_name
= text_list
[i
];
1786 vlc_object_release( p_input
);
1791 void libvlc_track_description_list_release( libvlc_track_description_t
*p_td
)
1793 libvlc_track_description_t
*p_actual
, *p_before
;
1798 free( p_actual
->psz_name
);
1799 p_before
= p_actual
;
1800 p_actual
= p_before
->p_next
;
1805 int libvlc_media_player_can_pause( libvlc_media_player_t
*p_mi
)
1807 input_thread_t
*p_input_thread
;
1810 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1811 if ( !p_input_thread
)
1813 b_can_pause
= var_GetBool( p_input_thread
, "can-pause" );
1814 vlc_object_release( p_input_thread
);
1819 int libvlc_media_player_program_scrambled( libvlc_media_player_t
*p_mi
)
1821 input_thread_t
*p_input_thread
;
1822 bool b_program_scrambled
;
1824 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1825 if ( !p_input_thread
)
1827 b_program_scrambled
= var_GetBool( p_input_thread
, "program-scrambled" );
1828 vlc_object_release( p_input_thread
);
1830 return b_program_scrambled
;
1833 void libvlc_media_player_next_frame( libvlc_media_player_t
*p_mi
)
1835 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1836 if( p_input_thread
!= NULL
)
1838 var_TriggerCallback( p_input_thread
, "frame-next" );
1839 vlc_object_release( p_input_thread
);
1844 * Private lookup table to get subpicture alignment flag values corresponding
1845 * to a libvlc_position_t enumerated value.
1847 static const unsigned char position_subpicture_alignment
[] = {
1848 [libvlc_position_center
] = 0,
1849 [libvlc_position_left
] = SUBPICTURE_ALIGN_LEFT
,
1850 [libvlc_position_right
] = SUBPICTURE_ALIGN_RIGHT
,
1851 [libvlc_position_top
] = SUBPICTURE_ALIGN_TOP
,
1852 [libvlc_position_top_left
] = SUBPICTURE_ALIGN_TOP
| SUBPICTURE_ALIGN_LEFT
,
1853 [libvlc_position_top_right
] = SUBPICTURE_ALIGN_TOP
| SUBPICTURE_ALIGN_RIGHT
,
1854 [libvlc_position_bottom
] = SUBPICTURE_ALIGN_BOTTOM
,
1855 [libvlc_position_bottom_left
] = SUBPICTURE_ALIGN_BOTTOM
| SUBPICTURE_ALIGN_LEFT
,
1856 [libvlc_position_bottom_right
] = SUBPICTURE_ALIGN_BOTTOM
| SUBPICTURE_ALIGN_RIGHT
1859 void libvlc_media_player_set_video_title_display( libvlc_media_player_t
*p_mi
, libvlc_position_t position
, unsigned timeout
)
1861 assert( position
>= libvlc_position_disable
&& position
<= libvlc_position_bottom_right
);
1863 if ( position
!= libvlc_position_disable
)
1865 var_SetBool( p_mi
, "video-title-show", true );
1866 var_SetInteger( p_mi
, "video-title-position", position_subpicture_alignment
[position
] );
1867 var_SetInteger( p_mi
, "video-title-timeout", timeout
);
1871 var_SetBool( p_mi
, "video-title-show", false );
1875 int libvlc_media_player_add_slave( libvlc_media_player_t
*p_mi
,
1876 libvlc_media_slave_type_t i_type
,
1877 const char *psz_uri
, bool b_select
)
1879 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1881 if( p_input_thread
== NULL
)
1883 libvlc_media_t
*p_media
= libvlc_media_player_get_media( p_mi
);
1884 if( p_media
== NULL
)
1887 int i_ret
= libvlc_media_slaves_add( p_media
, i_type
, 4, psz_uri
);
1888 libvlc_media_release( p_media
);
1893 int i_ret
= input_AddSlave( p_input_thread
, (enum slave_type
) i_type
,
1894 psz_uri
, b_select
, false, false );
1895 vlc_object_release( p_input_thread
);
1897 return i_ret
== VLC_SUCCESS
? 0 : -1;
1902 * Maximum size of a formatted equalizer amplification band frequency value.
1904 * The allowed value range is supposed to be constrained from -20.0 to 20.0.
1906 * The format string " %.07f" with a minimum value of "-20" gives a maximum
1907 * string length of e.g. " -19.1234567", i.e. 12 bytes (not including the null
1910 #define EQZ_BAND_VALUE_SIZE 12
1912 int libvlc_media_player_set_equalizer( libvlc_media_player_t
*p_mi
, libvlc_equalizer_t
*p_equalizer
)
1914 char bands
[EQZ_BANDS_MAX
* EQZ_BAND_VALUE_SIZE
+ 1];
1916 if( p_equalizer
!= NULL
)
1918 for( unsigned i
= 0, c
= 0; i
< EQZ_BANDS_MAX
; i
++ )
1920 c
+= snprintf( bands
+ c
, sizeof(bands
) - c
, " %.07f",
1921 p_equalizer
->f_amp
[i
] );
1922 if( unlikely(c
>= sizeof(bands
)) )
1926 var_SetFloat( p_mi
, "equalizer-preamp", p_equalizer
->f_preamp
);
1927 var_SetString( p_mi
, "equalizer-bands", bands
);
1929 var_SetString( p_mi
, "audio-filter", p_equalizer
? "equalizer" : "" );
1931 audio_output_t
*p_aout
= input_resource_HoldAout( p_mi
->input
.p_resource
);
1932 if( p_aout
!= NULL
)
1934 if( p_equalizer
!= NULL
)
1936 var_SetFloat( p_aout
, "equalizer-preamp", p_equalizer
->f_preamp
);
1937 var_SetString( p_aout
, "equalizer-bands", bands
);
1940 var_SetString( p_aout
, "audio-filter", p_equalizer
? "equalizer" : "" );
1941 vlc_object_release( p_aout
);
1947 static const char roles
[][16] =
1949 [libvlc_role_Music
] = "music",
1950 [libvlc_role_Video
] = "video",
1951 [libvlc_role_Communication
] = "communication",
1952 [libvlc_role_Game
] = "game",
1953 [libvlc_role_Notification
] = "notification",
1954 [libvlc_role_Animation
] = "animation",
1955 [libvlc_role_Production
] = "production",
1956 [libvlc_role_Accessibility
] = "accessibility",
1957 [libvlc_role_Test
] = "test",
1960 int libvlc_media_player_set_role(libvlc_media_player_t
*mp
, unsigned role
)
1962 if (role
>= ARRAY_SIZE(roles
)
1963 || var_SetString(mp
, "role", roles
[role
]) != VLC_SUCCESS
)
1968 int libvlc_media_player_get_role(libvlc_media_player_t
*mp
)
1971 char *str
= var_GetString(mp
, "role");
1975 for (size_t i
= 0; i
< ARRAY_SIZE(roles
); i
++)
1976 if (!strcmp(roles
[i
], str
))