1 /*****************************************************************************
2 * media_player.c: Libvlc API Media Instance management functions
3 *****************************************************************************
4 * Copyright (C) 2005-2011 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_media.h>
31 #include <vlc/libvlc_events.h>
33 #include <vlc_demux.h>
34 #include <vlc_input.h>
39 #include "libvlc_internal.h"
40 #include "media_internal.h" // libvlc_media_set_state()
41 #include "media_player_internal.h"
44 input_seekable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
45 vlc_value_t oldval
, vlc_value_t newval
,
48 input_pausable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
49 vlc_value_t oldval
, vlc_value_t newval
,
52 input_scrambled_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
53 vlc_value_t oldval
, vlc_value_t newval
,
56 input_event_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
57 vlc_value_t oldval
, vlc_value_t newval
,
61 snapshot_was_taken( vlc_object_t
*p_this
, char const *psz_cmd
,
62 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
);
64 static void libvlc_media_player_destroy( libvlc_media_player_t
*p_mi
);
70 #define register_event(a, b) __register_event(a, libvlc_MediaPlayer ## b)
71 static inline void __register_event(libvlc_media_player_t
*mp
, libvlc_event_type_t type
)
73 libvlc_event_manager_register_event_type(mp
->p_event_manager
, type
);
77 * The input lock protects the input and input resource pointer.
78 * It MUST NOT be used from callbacks.
80 * The object lock protects the reset, namely the media and the player state.
81 * It can, and usually needs to be taken from callbacks.
82 * The object lock can be acquired under the input lock... and consequently
83 * the opposite order is STRICTLY PROHIBITED.
85 static inline void lock(libvlc_media_player_t
*mp
)
87 vlc_mutex_lock(&mp
->object_lock
);
90 static inline void unlock(libvlc_media_player_t
*mp
)
92 vlc_mutex_unlock(&mp
->object_lock
);
95 static inline void lock_input(libvlc_media_player_t
*mp
)
97 vlc_mutex_lock(&mp
->input
.lock
);
100 static inline void unlock_input(libvlc_media_player_t
*mp
)
102 vlc_mutex_unlock(&mp
->input
.lock
);
106 * Release the associated input thread.
108 * Object lock is NOT held.
109 * Input lock is held or instance is being destroyed.
111 static void release_input_thread( libvlc_media_player_t
*p_mi
, bool b_input_abort
)
115 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
116 if( !p_input_thread
)
118 p_mi
->input
.p_thread
= NULL
;
120 var_DelCallback( p_input_thread
, "can-seek",
121 input_seekable_changed
, p_mi
);
122 var_DelCallback( p_input_thread
, "can-pause",
123 input_pausable_changed
, p_mi
);
124 var_DelCallback( p_input_thread
, "program-scrambled",
125 input_scrambled_changed
, p_mi
);
126 var_DelCallback( p_input_thread
, "intf-event",
127 input_event_changed
, p_mi
);
129 /* We owned this one */
130 input_Stop( p_input_thread
, b_input_abort
);
131 input_Close( p_input_thread
);
135 * Retrieve the input thread. Be sure to release the object
136 * once you are done with it. (libvlc Internal)
138 input_thread_t
*libvlc_get_input_thread( libvlc_media_player_t
*p_mi
)
140 input_thread_t
*p_input_thread
;
145 p_input_thread
= p_mi
->input
.p_thread
;
147 vlc_object_hold( p_input_thread
);
149 libvlc_printerr( "No active input" );
152 return p_input_thread
;
156 * Set the internal state of the media_player. (media player Internal)
158 * Function will lock the media_player.
160 static void set_state( libvlc_media_player_t
*p_mi
, libvlc_state_t state
,
167 libvlc_media_t
*media
= p_mi
->p_md
;
169 libvlc_media_retain(media
);
176 // Also set the state of the corresponding media
177 // This is strictly for convenience.
178 libvlc_media_set_state(media
, state
);
180 libvlc_media_release(media
);
185 input_seekable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
186 vlc_value_t oldval
, vlc_value_t newval
,
192 libvlc_media_player_t
* p_mi
= p_userdata
;
193 libvlc_event_t event
;
195 event
.type
= libvlc_MediaPlayerSeekableChanged
;
196 event
.u
.media_player_seekable_changed
.new_seekable
= newval
.b_bool
;
198 libvlc_event_send( p_mi
->p_event_manager
, &event
);
203 input_pausable_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
204 vlc_value_t oldval
, vlc_value_t newval
,
210 libvlc_media_player_t
* p_mi
= p_userdata
;
211 libvlc_event_t event
;
213 event
.type
= libvlc_MediaPlayerPausableChanged
;
214 event
.u
.media_player_pausable_changed
.new_pausable
= newval
.b_bool
;
216 libvlc_event_send( p_mi
->p_event_manager
, &event
);
221 input_scrambled_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
222 vlc_value_t oldval
, vlc_value_t newval
,
228 libvlc_media_player_t
* p_mi
= p_userdata
;
229 libvlc_event_t event
;
231 event
.type
= libvlc_MediaPlayerScrambledChanged
;
232 event
.u
.media_player_scrambled_changed
.new_scrambled
= newval
.b_bool
;
234 libvlc_event_send( p_mi
->p_event_manager
, &event
);
239 input_event_changed( vlc_object_t
* p_this
, char const * psz_cmd
,
240 vlc_value_t oldval
, vlc_value_t newval
,
244 input_thread_t
* p_input
= (input_thread_t
*)p_this
;
245 libvlc_media_player_t
* p_mi
= p_userdata
;
246 libvlc_event_t event
;
248 assert( !strcmp( psz_cmd
, "intf-event" ) );
250 if( newval
.i_int
== INPUT_EVENT_STATE
)
252 libvlc_state_t libvlc_state
;
254 switch ( var_GetInteger( p_input
, "state" ) )
257 libvlc_state
= libvlc_NothingSpecial
;
258 event
.type
= libvlc_MediaPlayerNothingSpecial
;
261 libvlc_state
= libvlc_Opening
;
262 event
.type
= libvlc_MediaPlayerOpening
;
265 libvlc_state
= libvlc_Playing
;
266 event
.type
= libvlc_MediaPlayerPlaying
;
269 libvlc_state
= libvlc_Paused
;
270 event
.type
= libvlc_MediaPlayerPaused
;
273 libvlc_state
= libvlc_Ended
;
274 event
.type
= libvlc_MediaPlayerEndReached
;
277 libvlc_state
= libvlc_Error
;
278 event
.type
= libvlc_MediaPlayerEncounteredError
;
285 set_state( p_mi
, libvlc_state
, false );
286 libvlc_event_send( p_mi
->p_event_manager
, &event
);
288 else if( newval
.i_int
== INPUT_EVENT_ABORT
)
290 libvlc_state_t libvlc_state
= libvlc_Stopped
;
291 event
.type
= libvlc_MediaPlayerStopped
;
293 set_state( p_mi
, libvlc_state
, false );
294 libvlc_event_send( p_mi
->p_event_manager
, &event
);
296 else if( newval
.i_int
== INPUT_EVENT_POSITION
)
298 if( var_GetInteger( p_input
, "state" ) != PLAYING_S
)
299 return VLC_SUCCESS
; /* Don't send the position while stopped */
302 event
.type
= libvlc_MediaPlayerPositionChanged
;
303 event
.u
.media_player_position_changed
.new_position
=
304 var_GetFloat( p_input
, "position" );
305 libvlc_event_send( p_mi
->p_event_manager
, &event
);
308 event
.type
= libvlc_MediaPlayerTimeChanged
;
309 event
.u
.media_player_time_changed
.new_time
=
310 from_mtime(var_GetTime( p_input
, "time" ));
311 libvlc_event_send( p_mi
->p_event_manager
, &event
);
313 else if( newval
.i_int
== INPUT_EVENT_LENGTH
)
315 event
.type
= libvlc_MediaPlayerLengthChanged
;
316 event
.u
.media_player_length_changed
.new_length
=
317 from_mtime(var_GetTime( p_input
, "length" ));
318 libvlc_event_send( p_mi
->p_event_manager
, &event
);
320 else if( newval
.i_int
== INPUT_EVENT_CACHE
)
322 event
.type
= libvlc_MediaPlayerBuffering
;
323 event
.u
.media_player_buffering
.new_cache
= (int)(100 *
324 var_GetFloat( p_input
, "cache" ));
325 libvlc_event_send( p_mi
->p_event_manager
, &event
);
327 else if( newval
.i_int
== INPUT_EVENT_VOUT
)
329 vout_thread_t
**pp_vout
;
331 if( input_Control( p_input
, INPUT_GET_VOUTS
, &pp_vout
, &i_vout
) )
337 for( size_t i
= 0; i
< i_vout
; i
++ )
338 vlc_object_release( pp_vout
[i
] );
342 event
.type
= libvlc_MediaPlayerVout
;
343 event
.u
.media_player_vout
.new_count
= i_vout
;
344 libvlc_event_send( p_mi
->p_event_manager
, &event
);
350 /**************************************************************************
351 * Snapshot Taken Event.
353 * FIXME: This snapshot API interface makes no sense in media_player.
354 *************************************************************************/
355 static int snapshot_was_taken(vlc_object_t
*p_this
, char const *psz_cmd
,
356 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
358 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_this
);
360 libvlc_media_player_t
*mp
= p_data
;
361 libvlc_event_t event
;
362 event
.type
= libvlc_MediaPlayerSnapshotTaken
;
363 event
.u
.media_player_snapshot_taken
.psz_filename
= newval
.psz_string
;
364 libvlc_event_send(mp
->p_event_manager
, &event
);
370 static void libvlc_media_player_destroy( libvlc_media_player_t
* );
373 /**************************************************************************
374 * Create a Media Instance object.
377 * - All items created by _new start with a refcount set to 1.
378 * - Accessor _release decrease the refcount by 1, if after that
379 * operation the refcount is 0, the object is destroyed.
380 * - Accessor _retain increase the refcount by 1 (XXX: to implement)
382 * Object locking strategy:
383 * - No lock held while in constructor.
384 * - When accessing any member variable this lock is held. (XXX who locks?)
385 * - When attempting to destroy the object the lock is also held.
386 **************************************************************************/
387 libvlc_media_player_t
*
388 libvlc_media_player_new( libvlc_instance_t
*instance
)
390 libvlc_media_player_t
* mp
;
394 mp
= vlc_object_create (instance
->p_libvlc_int
, sizeof(*mp
));
395 if (unlikely(mp
== NULL
))
397 libvlc_printerr("Not enough memory");
402 var_Create (mp
, "rate", VLC_VAR_FLOAT
|VLC_VAR_DOINHERIT
);
405 var_Create (mp
, "vout", VLC_VAR_STRING
|VLC_VAR_DOINHERIT
);
406 var_Create (mp
, "window", VLC_VAR_STRING
);
407 var_Create (mp
, "vmem-lock", VLC_VAR_ADDRESS
);
408 var_Create (mp
, "vmem-unlock", VLC_VAR_ADDRESS
);
409 var_Create (mp
, "vmem-display", VLC_VAR_ADDRESS
);
410 var_Create (mp
, "vmem-data", VLC_VAR_ADDRESS
);
411 var_Create (mp
, "vmem-setup", VLC_VAR_ADDRESS
);
412 var_Create (mp
, "vmem-cleanup", VLC_VAR_ADDRESS
);
413 var_Create (mp
, "vmem-chroma", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
414 var_Create (mp
, "vmem-width", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
415 var_Create (mp
, "vmem-height", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
416 var_Create (mp
, "vmem-pitch", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
417 var_Create (mp
, "drawable-xid", VLC_VAR_INTEGER
);
418 #if defined (_WIN32) || defined (__OS2__)
419 var_Create (mp
, "drawable-hwnd", VLC_VAR_INTEGER
);
422 var_Create (mp
, "drawable-agl", VLC_VAR_INTEGER
);
423 var_Create (mp
, "drawable-nsobject", VLC_VAR_ADDRESS
);
426 var_Create (mp
, "keyboard-events", VLC_VAR_BOOL
);
427 var_SetBool (mp
, "keyboard-events", true);
428 var_Create (mp
, "mouse-events", VLC_VAR_BOOL
);
429 var_SetBool (mp
, "mouse-events", true);
431 var_Create (mp
, "fullscreen", VLC_VAR_BOOL
);
432 var_Create (mp
, "autoscale", VLC_VAR_BOOL
);
433 var_SetBool (mp
, "autoscale", true);
434 var_Create (mp
, "scale", VLC_VAR_FLOAT
);
435 var_SetFloat (mp
, "scale", 1.);
436 var_Create (mp
, "aspect-ratio", VLC_VAR_STRING
);
437 var_Create (mp
, "crop", VLC_VAR_STRING
);
438 var_Create (mp
, "deinterlace", VLC_VAR_INTEGER
);
439 var_Create (mp
, "deinterlace-mode", VLC_VAR_STRING
);
441 var_Create (mp
, "vbi-page", VLC_VAR_INTEGER
);
443 var_Create (mp
, "marq-marquee", VLC_VAR_STRING
);
444 var_Create (mp
, "marq-color", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
445 var_Create (mp
, "marq-opacity", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
446 var_Create (mp
, "marq-position", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
447 var_Create (mp
, "marq-refresh", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
448 var_Create (mp
, "marq-size", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
449 var_Create (mp
, "marq-timeout", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
450 var_Create (mp
, "marq-x", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
451 var_Create (mp
, "marq-y", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
453 var_Create (mp
, "logo-file", VLC_VAR_STRING
);
454 var_Create (mp
, "logo-x", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
455 var_Create (mp
, "logo-y", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
456 var_Create (mp
, "logo-delay", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
457 var_Create (mp
, "logo-repeat", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
458 var_Create (mp
, "logo-opacity", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
459 var_Create (mp
, "logo-position", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
461 var_Create (mp
, "contrast", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
462 var_Create (mp
, "brightness", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
463 var_Create (mp
, "hue", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
464 var_Create (mp
, "saturation", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
465 var_Create (mp
, "gamma", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
468 var_Create (mp
, "aout", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
469 var_Create (mp
, "mute", VLC_VAR_BOOL
);
470 var_Create (mp
, "volume", VLC_VAR_FLOAT
);
471 var_Create (mp
, "corks", VLC_VAR_INTEGER
);
472 var_Create (mp
, "audio-filter", VLC_VAR_STRING
);
473 var_Create (mp
, "amem-data", VLC_VAR_ADDRESS
);
474 var_Create (mp
, "amem-setup", VLC_VAR_ADDRESS
);
475 var_Create (mp
, "amem-cleanup", VLC_VAR_ADDRESS
);
476 var_Create (mp
, "amem-play", VLC_VAR_ADDRESS
);
477 var_Create (mp
, "amem-pause", VLC_VAR_ADDRESS
);
478 var_Create (mp
, "amem-resume", VLC_VAR_ADDRESS
);
479 var_Create (mp
, "amem-flush", VLC_VAR_ADDRESS
);
480 var_Create (mp
, "amem-drain", VLC_VAR_ADDRESS
);
481 var_Create (mp
, "amem-set-volume", VLC_VAR_ADDRESS
);
482 var_Create (mp
, "amem-format", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
483 var_Create (mp
, "amem-rate", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
484 var_Create (mp
, "amem-channels", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
487 var_Create (mp
, "video-title-show", VLC_VAR_BOOL
);
488 var_Create (mp
, "video-title-position", VLC_VAR_INTEGER
);
489 var_Create (mp
, "video-title-timeout", VLC_VAR_INTEGER
);
492 var_Create (mp
, "equalizer-preamp", VLC_VAR_FLOAT
);
493 var_Create (mp
, "equalizer-vlcfreqs", VLC_VAR_BOOL
);
494 var_Create (mp
, "equalizer-bands", VLC_VAR_STRING
);
497 mp
->state
= libvlc_NothingSpecial
;
498 mp
->p_libvlc_instance
= instance
;
499 mp
->input
.p_thread
= NULL
;
500 mp
->input
.p_resource
= input_resource_New(VLC_OBJECT(mp
));
501 if (unlikely(mp
->input
.p_resource
== NULL
))
503 vlc_object_release(mp
);
506 audio_output_t
*aout
= input_resource_GetAout(mp
->input
.p_resource
);
508 input_resource_PutAout(mp
->input
.p_resource
, aout
);
510 vlc_mutex_init (&mp
->input
.lock
);
512 mp
->p_event_manager
= libvlc_event_manager_new(mp
, instance
);
513 if (unlikely(mp
->p_event_manager
== NULL
))
515 input_resource_Release(mp
->input
.p_resource
);
516 vlc_object_release(mp
);
519 vlc_mutex_init(&mp
->object_lock
);
521 register_event(mp
, NothingSpecial
);
522 register_event(mp
, Opening
);
523 register_event(mp
, Buffering
);
524 register_event(mp
, Playing
);
525 register_event(mp
, Paused
);
526 register_event(mp
, Stopped
);
527 register_event(mp
, Forward
);
528 register_event(mp
, Backward
);
529 register_event(mp
, EndReached
);
530 register_event(mp
, EncounteredError
);
531 register_event(mp
, SeekableChanged
);
533 register_event(mp
, PositionChanged
);
534 register_event(mp
, TimeChanged
);
535 register_event(mp
, LengthChanged
);
536 register_event(mp
, TitleChanged
);
537 register_event(mp
, PausableChanged
);
539 register_event(mp
, Vout
);
540 register_event(mp
, ScrambledChanged
);
542 /* Snapshot initialization */
543 register_event(mp
, SnapshotTaken
);
545 register_event(mp
, MediaChanged
);
547 /* Attach a var callback to the global object to provide the glue between
548 * vout_thread that generates the event and media_player that re-emits it
549 * with its own event manager
551 * FIXME: It's unclear why we want to put this in public API, and why we
552 * want to expose it in such a limiting and ugly way.
554 var_AddCallback(mp
->p_libvlc
, "snapshot-file", snapshot_was_taken
, mp
);
556 libvlc_retain(instance
);
560 /**************************************************************************
561 * Create a Media Instance object with a media descriptor.
562 **************************************************************************/
563 libvlc_media_player_t
*
564 libvlc_media_player_new_from_media( libvlc_media_t
* p_md
)
566 libvlc_media_player_t
* p_mi
;
568 p_mi
= libvlc_media_player_new( p_md
->p_libvlc_instance
);
572 libvlc_media_retain( p_md
);
578 /**************************************************************************
579 * Destroy a Media Instance object (libvlc internal)
581 * Warning: No lock held here, but hey, this is internal. Caller must lock.
582 **************************************************************************/
583 static void libvlc_media_player_destroy( libvlc_media_player_t
*p_mi
)
587 /* Detach Callback from the main libvlc object */
588 var_DelCallback( p_mi
->p_libvlc
,
589 "snapshot-file", snapshot_was_taken
, p_mi
);
591 /* No need for lock_input() because no other threads knows us anymore */
592 if( p_mi
->input
.p_thread
)
593 release_input_thread(p_mi
, true);
594 input_resource_Terminate( p_mi
->input
.p_resource
);
595 input_resource_Release( p_mi
->input
.p_resource
);
596 vlc_mutex_destroy( &p_mi
->input
.lock
);
598 libvlc_event_manager_release( p_mi
->p_event_manager
);
599 libvlc_media_release( p_mi
->p_md
);
600 vlc_mutex_destroy( &p_mi
->object_lock
);
602 libvlc_instance_t
*instance
= p_mi
->p_libvlc_instance
;
603 vlc_object_release( p_mi
);
604 libvlc_release(instance
);
607 /**************************************************************************
608 * Release a Media Instance object.
610 * Function does the locking.
611 **************************************************************************/
612 void libvlc_media_player_release( libvlc_media_player_t
*p_mi
)
618 destroy
= !--p_mi
->i_refcount
;
622 libvlc_media_player_destroy( p_mi
);
625 /**************************************************************************
626 * Retain a Media Instance object.
628 * Caller must hold the lock.
629 **************************************************************************/
630 void libvlc_media_player_retain( libvlc_media_player_t
*p_mi
)
639 /**************************************************************************
640 * Set the Media descriptor associated with the instance.
642 * Enter without lock -- function will lock the object.
643 **************************************************************************/
644 void libvlc_media_player_set_media(
645 libvlc_media_player_t
*p_mi
,
646 libvlc_media_t
*p_md
)
650 /* FIXME I am not sure if it is a user request or on die(eof/error)
652 release_input_thread( p_mi
,
653 p_mi
->input
.p_thread
&&
654 !p_mi
->input
.p_thread
->b_eof
&&
655 !p_mi
->input
.p_thread
->b_error
);
658 set_state( p_mi
, libvlc_NothingSpecial
, true );
659 unlock_input( p_mi
);
661 libvlc_media_release( p_mi
->p_md
);
667 return; /* It is ok to pass a NULL md */
670 libvlc_media_retain( p_md
);
673 /* The policy here is to ignore that we were created using a different
674 * libvlc_instance, because we don't really care */
675 p_mi
->p_libvlc_instance
= p_md
->p_libvlc_instance
;
679 /* Send an event for the newly available media */
680 libvlc_event_t event
;
681 event
.type
= libvlc_MediaPlayerMediaChanged
;
682 event
.u
.media_player_media_changed
.new_media
= p_md
;
683 libvlc_event_send( p_mi
->p_event_manager
, &event
);
687 /**************************************************************************
688 * Get the Media descriptor associated with the instance.
689 **************************************************************************/
691 libvlc_media_player_get_media( libvlc_media_player_t
*p_mi
)
698 libvlc_media_retain( p_m
);
704 /**************************************************************************
705 * Get the event Manager.
706 **************************************************************************/
707 libvlc_event_manager_t
*
708 libvlc_media_player_event_manager( libvlc_media_player_t
*p_mi
)
710 return p_mi
->p_event_manager
;
713 /**************************************************************************
714 * Tell media player to start playing.
715 **************************************************************************/
716 int libvlc_media_player_play( libvlc_media_player_t
*p_mi
)
720 input_thread_t
*p_input_thread
= p_mi
->input
.p_thread
;
723 /* A thread already exists, send it a play message */
724 input_Control( p_input_thread
, INPUT_SET_STATE
, PLAYING_S
);
725 unlock_input( p_mi
);
729 /* Ignore previous exception */
735 unlock_input( p_mi
);
736 libvlc_printerr( "No associated media descriptor" );
740 p_input_thread
= input_Create( p_mi
, p_mi
->p_md
->p_input_item
, NULL
,
741 p_mi
->input
.p_resource
);
743 if( !p_input_thread
)
746 libvlc_printerr( "Not enough memory" );
750 var_AddCallback( p_input_thread
, "can-seek", input_seekable_changed
, p_mi
);
751 var_AddCallback( p_input_thread
, "can-pause", input_pausable_changed
, p_mi
);
752 var_AddCallback( p_input_thread
, "program-scrambled", input_scrambled_changed
, p_mi
);
753 var_AddCallback( p_input_thread
, "intf-event", input_event_changed
, p_mi
);
755 if( input_Start( p_input_thread
) )
758 var_DelCallback( p_input_thread
, "intf-event", input_event_changed
, p_mi
);
759 var_DelCallback( p_input_thread
, "can-pause", input_pausable_changed
, p_mi
);
760 var_DelCallback( p_input_thread
, "program-scrambled", input_scrambled_changed
, p_mi
);
761 var_DelCallback( p_input_thread
, "can-seek", input_seekable_changed
, p_mi
);
762 vlc_object_release( p_input_thread
);
763 libvlc_printerr( "Input initialization failure" );
766 p_mi
->input
.p_thread
= p_input_thread
;
771 void libvlc_media_player_set_pause( libvlc_media_player_t
*p_mi
, int paused
)
773 input_thread_t
* p_input_thread
= libvlc_get_input_thread( p_mi
);
774 if( !p_input_thread
)
777 libvlc_state_t state
= libvlc_media_player_get_state( p_mi
);
778 if( state
== libvlc_Playing
|| state
== libvlc_Buffering
)
782 if( libvlc_media_player_can_pause( p_mi
) )
783 input_Control( p_input_thread
, INPUT_SET_STATE
, PAUSE_S
);
785 libvlc_media_player_stop( p_mi
);
791 input_Control( p_input_thread
, INPUT_SET_STATE
, PLAYING_S
);
794 vlc_object_release( p_input_thread
);
797 /**************************************************************************
799 **************************************************************************/
800 void libvlc_media_player_pause( libvlc_media_player_t
*p_mi
)
802 libvlc_state_t state
= libvlc_media_player_get_state( p_mi
);
803 bool playing
= (state
== libvlc_Playing
|| state
== libvlc_Buffering
);
805 libvlc_media_player_set_pause( p_mi
, playing
);
808 /**************************************************************************
809 * Tells whether the media player is currently playing.
811 * Enter with lock held.
812 **************************************************************************/
813 int libvlc_media_player_is_playing( libvlc_media_player_t
*p_mi
)
815 libvlc_state_t state
= libvlc_media_player_get_state( p_mi
);
816 return (libvlc_Playing
== state
) || (libvlc_Buffering
== state
);
819 /**************************************************************************
821 **************************************************************************/
822 void libvlc_media_player_stop( libvlc_media_player_t
*p_mi
)
824 libvlc_state_t state
= libvlc_media_player_get_state( p_mi
);
827 release_input_thread( p_mi
, true ); /* This will stop the input thread */
829 /* Force to go to stopped state, in case we were in Ended, or Error
831 if( state
!= libvlc_Stopped
)
833 set_state( p_mi
, libvlc_Stopped
, false );
835 /* Construct and send the event */
836 libvlc_event_t event
;
837 event
.type
= libvlc_MediaPlayerStopped
;
838 libvlc_event_send( p_mi
->p_event_manager
, &event
);
841 input_resource_Terminate( p_mi
->input
.p_resource
);
846 void libvlc_video_set_callbacks( libvlc_media_player_t
*mp
,
847 void *(*lock_cb
) (void *, void **),
848 void (*unlock_cb
) (void *, void *, void *const *),
849 void (*display_cb
) (void *, void *),
852 var_SetAddress( mp
, "vmem-lock", lock_cb
);
853 var_SetAddress( mp
, "vmem-unlock", unlock_cb
);
854 var_SetAddress( mp
, "vmem-display", display_cb
);
855 var_SetAddress( mp
, "vmem-data", opaque
);
856 var_SetString( mp
, "vout", "vmem" );
859 void libvlc_video_set_format_callbacks( libvlc_media_player_t
*mp
,
860 libvlc_video_format_cb setup
,
861 libvlc_video_cleanup_cb cleanup
)
863 var_SetAddress( mp
, "vmem-setup", setup
);
864 var_SetAddress( mp
, "vmem-cleanup", cleanup
);
867 void libvlc_video_set_format( libvlc_media_player_t
*mp
, const char *chroma
,
868 unsigned width
, unsigned height
, unsigned pitch
)
870 var_SetString( mp
, "vmem-chroma", chroma
);
871 var_SetInteger( mp
, "vmem-width", width
);
872 var_SetInteger( mp
, "vmem-height", height
);
873 var_SetInteger( mp
, "vmem-pitch", pitch
);
876 /**************************************************************************
878 **************************************************************************/
879 void libvlc_media_player_set_nsobject( libvlc_media_player_t
*p_mi
,
882 assert (p_mi
!= NULL
);
884 var_SetAddress (p_mi
, "drawable-nsobject", drawable
);
886 (void) p_mi
; (void)drawable
;
890 /**************************************************************************
892 **************************************************************************/
893 void * libvlc_media_player_get_nsobject( libvlc_media_player_t
*p_mi
)
895 assert (p_mi
!= NULL
);
897 return var_GetAddress (p_mi
, "drawable-nsobject");
903 /**************************************************************************
905 **************************************************************************/
906 void libvlc_media_player_set_agl( libvlc_media_player_t
*p_mi
,
910 var_SetInteger (p_mi
, "drawable-agl", drawable
);
912 (void) p_mi
; (void)drawable
;
916 /**************************************************************************
918 **************************************************************************/
919 uint32_t libvlc_media_player_get_agl( libvlc_media_player_t
*p_mi
)
921 assert (p_mi
!= NULL
);
923 return var_GetInteger (p_mi
, "drawable-agl");
929 /**************************************************************************
931 **************************************************************************/
932 void libvlc_media_player_set_xwindow( libvlc_media_player_t
*p_mi
,
935 assert (p_mi
!= NULL
);
937 var_SetString (p_mi
, "vout", drawable
? "xid" : "any");
938 var_SetString (p_mi
, "window", drawable
? "embed-xid,any" : "any");
939 var_SetInteger (p_mi
, "drawable-xid", drawable
);
942 /**************************************************************************
944 **************************************************************************/
945 uint32_t libvlc_media_player_get_xwindow( libvlc_media_player_t
*p_mi
)
947 return var_GetInteger (p_mi
, "drawable-xid");
950 /**************************************************************************
952 **************************************************************************/
953 void libvlc_media_player_set_hwnd( libvlc_media_player_t
*p_mi
,
956 assert (p_mi
!= NULL
);
957 #if defined (_WIN32) || defined (__OS2__)
958 var_SetString (p_mi
, "window",
959 (drawable
!= NULL
) ? "embed-hwnd,any" : "");
960 var_SetInteger (p_mi
, "drawable-hwnd", (uintptr_t)drawable
);
962 (void) p_mi
; (void) drawable
;
966 /**************************************************************************
968 **************************************************************************/
969 void *libvlc_media_player_get_hwnd( libvlc_media_player_t
*p_mi
)
971 assert (p_mi
!= NULL
);
972 #if defined (_WIN32) || defined (__OS2__)
973 return (void *)(uintptr_t)var_GetInteger (p_mi
, "drawable-hwnd");
979 void libvlc_audio_set_callbacks( libvlc_media_player_t
*mp
,
980 libvlc_audio_play_cb play_cb
,
981 libvlc_audio_pause_cb pause_cb
,
982 libvlc_audio_resume_cb resume_cb
,
983 libvlc_audio_flush_cb flush_cb
,
984 libvlc_audio_drain_cb drain_cb
,
987 var_SetAddress( mp
, "amem-play", play_cb
);
988 var_SetAddress( mp
, "amem-pause", pause_cb
);
989 var_SetAddress( mp
, "amem-resume", resume_cb
);
990 var_SetAddress( mp
, "amem-flush", flush_cb
);
991 var_SetAddress( mp
, "amem-drain", drain_cb
);
992 var_SetAddress( mp
, "amem-data", opaque
);
993 var_SetString( mp
, "aout", "amem,none" );
995 input_resource_ResetAout(mp
->input
.p_resource
);
998 void libvlc_audio_set_volume_callback( libvlc_media_player_t
*mp
,
999 libvlc_audio_set_volume_cb cb
)
1001 var_SetAddress( mp
, "amem-set-volume", cb
);
1003 input_resource_ResetAout(mp
->input
.p_resource
);
1006 void libvlc_audio_set_format_callbacks( libvlc_media_player_t
*mp
,
1007 libvlc_audio_setup_cb setup
,
1008 libvlc_audio_cleanup_cb cleanup
)
1010 var_SetAddress( mp
, "amem-setup", setup
);
1011 var_SetAddress( mp
, "amem-cleanup", cleanup
);
1013 input_resource_ResetAout(mp
->input
.p_resource
);
1016 void libvlc_audio_set_format( libvlc_media_player_t
*mp
, const char *format
,
1017 unsigned rate
, unsigned channels
)
1019 var_SetString( mp
, "amem-format", format
);
1020 var_SetInteger( mp
, "amem-rate", rate
);
1021 var_SetInteger( mp
, "amem-channels", channels
);
1023 input_resource_ResetAout(mp
->input
.p_resource
);
1027 /**************************************************************************
1028 * Getters for stream information
1029 **************************************************************************/
1030 libvlc_time_t
libvlc_media_player_get_length(
1031 libvlc_media_player_t
*p_mi
)
1033 input_thread_t
*p_input_thread
;
1034 libvlc_time_t i_time
;
1036 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1037 if( !p_input_thread
)
1040 i_time
= from_mtime(var_GetTime( p_input_thread
, "length" ));
1041 vlc_object_release( p_input_thread
);
1046 libvlc_time_t
libvlc_media_player_get_time( libvlc_media_player_t
*p_mi
)
1048 input_thread_t
*p_input_thread
;
1049 libvlc_time_t i_time
;
1051 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1052 if( !p_input_thread
)
1055 i_time
= from_mtime(var_GetTime( p_input_thread
, "time" ));
1056 vlc_object_release( p_input_thread
);
1060 void libvlc_media_player_set_time( libvlc_media_player_t
*p_mi
,
1061 libvlc_time_t i_time
)
1063 input_thread_t
*p_input_thread
;
1065 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1066 if( !p_input_thread
)
1069 var_SetTime( p_input_thread
, "time", to_mtime(i_time
) );
1070 vlc_object_release( p_input_thread
);
1073 void libvlc_media_player_set_position( libvlc_media_player_t
*p_mi
,
1076 input_thread_t
*p_input_thread
;
1078 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1079 if( !p_input_thread
)
1082 var_SetFloat( p_input_thread
, "position", position
);
1083 vlc_object_release( p_input_thread
);
1086 float libvlc_media_player_get_position( libvlc_media_player_t
*p_mi
)
1088 input_thread_t
*p_input_thread
;
1091 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1092 if( !p_input_thread
)
1095 f_position
= var_GetFloat( p_input_thread
, "position" );
1096 vlc_object_release( p_input_thread
);
1101 void libvlc_media_player_set_chapter( libvlc_media_player_t
*p_mi
,
1104 input_thread_t
*p_input_thread
;
1106 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1107 if( !p_input_thread
)
1110 var_SetInteger( p_input_thread
, "chapter", chapter
);
1111 vlc_object_release( p_input_thread
);
1114 int libvlc_media_player_get_chapter( libvlc_media_player_t
*p_mi
)
1116 input_thread_t
*p_input_thread
;
1119 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1120 if( !p_input_thread
)
1123 i_chapter
= var_GetInteger( p_input_thread
, "chapter" );
1124 vlc_object_release( p_input_thread
);
1129 int libvlc_media_player_get_chapter_count( libvlc_media_player_t
*p_mi
)
1131 input_thread_t
*p_input_thread
;
1134 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1135 if( !p_input_thread
)
1138 var_Change( p_input_thread
, "chapter", VLC_VAR_CHOICESCOUNT
, &val
, NULL
);
1139 vlc_object_release( p_input_thread
);
1144 int libvlc_media_player_get_chapter_count_for_title(
1145 libvlc_media_player_t
*p_mi
,
1148 input_thread_t
*p_input_thread
;
1151 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1152 if( !p_input_thread
)
1156 if( asprintf( &psz_name
, "title %2i", i_title
) == -1 )
1158 vlc_object_release( p_input_thread
);
1161 var_Change( p_input_thread
, psz_name
, VLC_VAR_CHOICESCOUNT
, &val
, NULL
);
1162 vlc_object_release( p_input_thread
);
1168 void libvlc_media_player_set_title( libvlc_media_player_t
*p_mi
,
1171 input_thread_t
*p_input_thread
;
1173 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1174 if( !p_input_thread
)
1177 var_SetInteger( p_input_thread
, "title", i_title
);
1178 vlc_object_release( p_input_thread
);
1181 libvlc_event_t event
;
1182 event
.type
= libvlc_MediaPlayerTitleChanged
;
1183 event
.u
.media_player_title_changed
.new_title
= i_title
;
1184 libvlc_event_send( p_mi
->p_event_manager
, &event
);
1187 int libvlc_media_player_get_title( libvlc_media_player_t
*p_mi
)
1189 input_thread_t
*p_input_thread
;
1192 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1193 if( !p_input_thread
)
1196 i_title
= var_GetInteger( p_input_thread
, "title" );
1197 vlc_object_release( p_input_thread
);
1202 int libvlc_media_player_get_title_count( libvlc_media_player_t
*p_mi
)
1204 input_thread_t
*p_input_thread
;
1207 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1208 if( !p_input_thread
)
1211 var_Change( p_input_thread
, "title", VLC_VAR_CHOICESCOUNT
, &val
, NULL
);
1212 vlc_object_release( p_input_thread
);
1217 void libvlc_media_player_next_chapter( libvlc_media_player_t
*p_mi
)
1219 input_thread_t
*p_input_thread
;
1221 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1222 if( !p_input_thread
)
1225 int i_type
= var_Type( p_input_thread
, "next-chapter" );
1226 var_TriggerCallback( p_input_thread
, (i_type
& VLC_VAR_TYPE
) != 0 ?
1227 "next-chapter":"next-title" );
1229 vlc_object_release( p_input_thread
);
1232 void libvlc_media_player_previous_chapter( libvlc_media_player_t
*p_mi
)
1234 input_thread_t
*p_input_thread
;
1236 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1237 if( !p_input_thread
)
1240 int i_type
= var_Type( p_input_thread
, "next-chapter" );
1241 var_TriggerCallback( p_input_thread
, (i_type
& VLC_VAR_TYPE
) != 0 ?
1242 "prev-chapter":"prev-title" );
1244 vlc_object_release( p_input_thread
);
1247 float libvlc_media_player_get_fps( libvlc_media_player_t
*p_mi
)
1249 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1252 if( p_input_thread
)
1254 if( input_Control( p_input_thread
, INPUT_GET_VIDEO_FPS
, &f_fps
) )
1256 vlc_object_release( p_input_thread
);
1261 int libvlc_media_player_will_play( libvlc_media_player_t
*p_mi
)
1264 input_thread_t
*p_input_thread
=
1265 libvlc_get_input_thread ( p_mi
);
1266 if ( !p_input_thread
)
1269 b_will_play
= !p_input_thread
->b_dead
;
1270 vlc_object_release( p_input_thread
);
1275 int libvlc_media_player_set_rate( libvlc_media_player_t
*p_mi
, float rate
)
1277 var_SetFloat (p_mi
, "rate", rate
);
1279 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1280 if( !p_input_thread
)
1282 var_SetFloat( p_input_thread
, "rate", rate
);
1283 vlc_object_release( p_input_thread
);
1287 float libvlc_media_player_get_rate( libvlc_media_player_t
*p_mi
)
1289 return var_GetFloat (p_mi
, "rate");
1292 libvlc_state_t
libvlc_media_player_get_state( libvlc_media_player_t
*p_mi
)
1295 libvlc_state_t state
= p_mi
->state
;
1300 int libvlc_media_player_is_seekable( libvlc_media_player_t
*p_mi
)
1302 input_thread_t
*p_input_thread
;
1305 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1306 if ( !p_input_thread
)
1308 b_seekable
= var_GetBool( p_input_thread
, "can-seek" );
1309 vlc_object_release( p_input_thread
);
1314 void libvlc_media_player_navigate( libvlc_media_player_t
* p_mi
,
1317 static const vlc_action_t map
[] =
1319 INPUT_NAV_ACTIVATE
, INPUT_NAV_UP
, INPUT_NAV_DOWN
,
1320 INPUT_NAV_LEFT
, INPUT_NAV_RIGHT
,
1323 if( navigate
>= sizeof(map
) / sizeof(map
[0]) )
1326 input_thread_t
*p_input
= libvlc_get_input_thread ( p_mi
);
1327 if ( p_input
== NULL
)
1330 input_Control( p_input
, map
[navigate
], NULL
);
1331 vlc_object_release( p_input
);
1334 /* internal function, used by audio, video */
1335 libvlc_track_description_t
*
1336 libvlc_get_track_description( libvlc_media_player_t
*p_mi
,
1337 const char *psz_variable
)
1339 input_thread_t
*p_input
= libvlc_get_input_thread( p_mi
);
1340 libvlc_track_description_t
*p_track_description
= NULL
,
1341 *p_actual
, *p_previous
;
1346 vlc_value_t val_list
, text_list
;
1347 var_Change( p_input
, psz_variable
, VLC_VAR_GETLIST
, &val_list
, &text_list
);
1350 if( val_list
.p_list
->i_count
<= 0 )
1353 p_track_description
= ( libvlc_track_description_t
* )
1354 malloc( sizeof( libvlc_track_description_t
) );
1355 if ( !p_track_description
)
1357 libvlc_printerr( "Not enough memory" );
1360 p_actual
= p_track_description
;
1362 for( int i
= 0; i
< val_list
.p_list
->i_count
; i
++ )
1366 p_actual
= ( libvlc_track_description_t
* )
1367 malloc( sizeof( libvlc_track_description_t
) );
1370 libvlc_track_description_list_release( p_track_description
);
1371 libvlc_printerr( "Not enough memory" );
1375 p_actual
->i_id
= val_list
.p_list
->p_values
[i
].i_int
;
1376 p_actual
->psz_name
= strdup( text_list
.p_list
->p_values
[i
].psz_string
);
1377 p_actual
->p_next
= NULL
;
1379 p_previous
->p_next
= p_actual
;
1380 p_previous
= p_actual
;
1385 var_FreeList( &val_list
, &text_list
);
1386 vlc_object_release( p_input
);
1388 return p_track_description
;
1391 // Deprecated alias for libvlc_track_description_list_release
1392 void libvlc_track_description_release( libvlc_track_description_t
*p_td
)
1394 libvlc_track_description_list_release( p_td
);
1397 void libvlc_track_description_list_release( libvlc_track_description_t
*p_td
)
1399 libvlc_track_description_t
*p_actual
, *p_before
;
1404 free( p_actual
->psz_name
);
1405 p_before
= p_actual
;
1406 p_actual
= p_before
->p_next
;
1411 int libvlc_media_player_can_pause( libvlc_media_player_t
*p_mi
)
1413 input_thread_t
*p_input_thread
;
1416 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1417 if ( !p_input_thread
)
1419 b_can_pause
= var_GetBool( p_input_thread
, "can-pause" );
1420 vlc_object_release( p_input_thread
);
1425 int libvlc_media_player_program_scrambled( libvlc_media_player_t
*p_mi
)
1427 input_thread_t
*p_input_thread
;
1428 bool b_program_scrambled
;
1430 p_input_thread
= libvlc_get_input_thread ( p_mi
);
1431 if ( !p_input_thread
)
1433 b_program_scrambled
= var_GetBool( p_input_thread
, "program-scrambled" );
1434 vlc_object_release( p_input_thread
);
1436 return b_program_scrambled
;
1439 void libvlc_media_player_next_frame( libvlc_media_player_t
*p_mi
)
1441 input_thread_t
*p_input_thread
= libvlc_get_input_thread ( p_mi
);
1442 if( p_input_thread
!= NULL
)
1444 var_TriggerCallback( p_input_thread
, "frame-next" );
1445 vlc_object_release( p_input_thread
);
1450 * Private lookup table to get subpicture alignment flag values corresponding
1451 * to a libvlc_position_t enumerated value.
1453 static const unsigned char position_subpicture_alignment
[] = {
1454 [libvlc_position_center
] = 0,
1455 [libvlc_position_left
] = SUBPICTURE_ALIGN_LEFT
,
1456 [libvlc_position_right
] = SUBPICTURE_ALIGN_RIGHT
,
1457 [libvlc_position_top
] = SUBPICTURE_ALIGN_TOP
,
1458 [libvlc_position_top_left
] = SUBPICTURE_ALIGN_TOP
| SUBPICTURE_ALIGN_LEFT
,
1459 [libvlc_position_top_right
] = SUBPICTURE_ALIGN_TOP
| SUBPICTURE_ALIGN_RIGHT
,
1460 [libvlc_position_bottom
] = SUBPICTURE_ALIGN_BOTTOM
,
1461 [libvlc_position_bottom_left
] = SUBPICTURE_ALIGN_BOTTOM
| SUBPICTURE_ALIGN_LEFT
,
1462 [libvlc_position_bottom_right
] = SUBPICTURE_ALIGN_BOTTOM
| SUBPICTURE_ALIGN_RIGHT
1465 void libvlc_media_player_set_video_title_display( libvlc_media_player_t
*p_mi
, libvlc_position_t position
, unsigned timeout
)
1467 assert( position
>= libvlc_position_disable
&& position
<= libvlc_position_bottom_right
);
1469 if ( position
!= libvlc_position_disable
)
1471 var_SetBool( p_mi
, "video-title-show", true );
1472 var_SetInteger( p_mi
, "video-title-position", position_subpicture_alignment
[position
] );
1473 var_SetInteger( p_mi
, "video-title-timeout", timeout
);
1477 var_SetBool( p_mi
, "video-title-show", false );
1482 * Maximum size of a formatted equalizer amplification band frequency value.
1484 * The allowed value range is supposed to be constrained from -20.0 to 20.0.
1486 * The format string " %.07f" with a minimum value of "-20" gives a maximum
1487 * string length of e.g. " -19.1234567", i.e. 12 bytes (not including the null
1490 #define EQZ_BAND_VALUE_SIZE 12
1492 int libvlc_media_player_set_equalizer( libvlc_media_player_t
*p_mi
, libvlc_equalizer_t
*p_equalizer
)
1494 char bands
[EQZ_BANDS_MAX
* EQZ_BAND_VALUE_SIZE
+ 1];
1496 if( p_equalizer
!= NULL
)
1498 for( unsigned i
= 0, c
= 0; i
< EQZ_BANDS_MAX
; i
++ )
1500 c
= snprintf( bands
+ c
, sizeof(bands
) - c
, " %.07f",
1501 p_equalizer
->f_amp
[i
] );
1502 if( unlikely(c
>= sizeof(bands
)) )
1506 var_SetFloat( p_mi
, "equalizer-preamp", p_equalizer
->f_preamp
);
1507 var_SetString( p_mi
, "equalizer-bands", bands
);
1509 var_SetString( p_mi
, "audio-filter", p_equalizer
? "equalizer" : "" );
1511 audio_output_t
*p_aout
= input_resource_HoldAout( p_mi
->input
.p_resource
);
1512 if( p_aout
!= NULL
)
1514 if( p_equalizer
!= NULL
)
1516 var_SetFloat( p_aout
, "equalizer-preamp", p_equalizer
->f_preamp
);
1517 var_SetString( p_aout
, "equalizer-bands", bands
);
1520 var_SetString( p_mi
, "audio-filter", p_equalizer
? "equalizer" : "" );
1521 vlc_object_release( p_aout
);