1 /*****************************************************************************
2 * media_player.c: Libvlc API Media Instance management functions
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "libvlc_internal.h"
26 #include <vlc/libvlc.h>
27 #include <vlc_demux.h>
28 #include <vlc_input.h>
33 input_state_changed( const vlc_event_t * event, void * p_userdata );
36 input_seekable_changed( vlc_object_t * p_this, char const * psz_cmd,
37 vlc_value_t oldval, vlc_value_t newval,
40 input_pausable_changed( vlc_object_t * p_this, char const * psz_cmd,
41 vlc_value_t oldval, vlc_value_t newval,
44 input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
45 vlc_value_t oldval, vlc_value_t newval,
48 static const libvlc_state_t vlc_to_libvlc_state_array[] =
50 [INIT_S] = libvlc_NothingSpecial,
51 [OPENING_S] = libvlc_Opening,
52 [BUFFERING_S] = libvlc_Buffering,
53 [PLAYING_S] = libvlc_Playing,
54 [PAUSE_S] = libvlc_Paused,
55 [END_S] = libvlc_Ended,
56 [ERROR_S] = libvlc_Error,
59 static inline libvlc_state_t vlc_to_libvlc_state( int vlc_state )
61 if( vlc_state < 0 || vlc_state > 6 )
64 return vlc_to_libvlc_state_array[vlc_state];
68 * Release the associated input thread
70 * Object lock is NOT held.
72 static void release_input_thread( libvlc_media_player_t *p_mi )
74 input_thread_t * p_input_thread;
76 if( !p_mi || !p_mi->p_input_thread )
79 p_input_thread = p_mi->p_input_thread;
81 /* No one is tracking this input_thread appart us. Destroy it */
82 if( p_mi->b_own_its_input_thread )
84 vlc_event_manager_t * p_em = input_get_event_manager( p_input_thread );
85 vlc_event_detach( p_em, vlc_InputStateChanged, input_state_changed, p_mi );
86 var_DelCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
87 var_DelCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
88 var_DelCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
90 /* We owned this one */
91 input_StopThread( p_input_thread );
92 vlc_thread_join( p_input_thread );
94 var_Destroy( p_input_thread, "drawable" );
97 vlc_object_release( p_input_thread );
99 p_mi->p_input_thread = NULL;
103 * Retrieve the input thread. Be sure to release the object
104 * once you are done with it. (libvlc Internal)
106 * Object lock is held.
108 input_thread_t *libvlc_get_input_thread( libvlc_media_player_t *p_mi,
109 libvlc_exception_t *p_e )
111 input_thread_t *p_input_thread;
113 if( !p_mi ) RAISENULL( "Media Instance is NULL" );
115 vlc_mutex_lock( &p_mi->object_lock );
117 if( !p_mi->p_input_thread )
119 vlc_mutex_unlock( &p_mi->object_lock );
120 RAISENULL( "Input is NULL" );
123 p_input_thread = p_mi->p_input_thread;
124 vlc_object_hold( p_input_thread );
126 vlc_mutex_unlock( &p_mi->object_lock );
128 return p_input_thread;
132 * input_state_changed (Private) (vlc_InputStateChanged callback)
135 input_state_changed( const vlc_event_t * event, void * p_userdata )
137 libvlc_media_player_t * p_mi = p_userdata;
138 libvlc_event_t forwarded_event;
139 libvlc_event_type_t type = event->u.input_state_changed.new_state;
144 libvlc_media_set_state( p_mi->p_md, libvlc_NothingSpecial, NULL);
145 forwarded_event.type = libvlc_MediaPlayerNothingSpecial;
148 libvlc_media_set_state( p_mi->p_md, libvlc_Opening, NULL);
149 forwarded_event.type = libvlc_MediaPlayerOpening;
152 libvlc_media_set_state( p_mi->p_md, libvlc_Buffering, NULL);
153 forwarded_event.type = libvlc_MediaPlayerBuffering;
156 libvlc_media_set_state( p_mi->p_md, libvlc_Playing, NULL);
157 forwarded_event.type = libvlc_MediaPlayerPlaying;
160 libvlc_media_set_state( p_mi->p_md, libvlc_Paused, NULL);
161 forwarded_event.type = libvlc_MediaPlayerPaused;
164 libvlc_media_set_state( p_mi->p_md, libvlc_Ended, NULL);
165 forwarded_event.type = libvlc_MediaPlayerEndReached;
168 libvlc_media_set_state( p_mi->p_md, libvlc_Error, NULL);
169 forwarded_event.type = libvlc_MediaPlayerEncounteredError;
176 libvlc_event_send( p_mi->p_event_manager, &forwarded_event );
181 input_seekable_changed( vlc_object_t * p_this, char const * psz_cmd,
182 vlc_value_t oldval, vlc_value_t newval,
188 libvlc_media_player_t * p_mi = p_userdata;
189 libvlc_event_t event;
191 libvlc_media_set_state( p_mi->p_md, libvlc_NothingSpecial, NULL);
192 event.type = libvlc_MediaPlayerSeekableChanged;
193 event.u.media_player_seekable_changed.new_seekable = newval.b_bool;
195 libvlc_event_send( p_mi->p_event_manager, &event );
200 input_pausable_changed( vlc_object_t * p_this, char const * psz_cmd,
201 vlc_value_t oldval, vlc_value_t newval,
207 libvlc_media_player_t * p_mi = p_userdata;
208 libvlc_event_t event;
210 libvlc_media_set_state( p_mi->p_md, libvlc_NothingSpecial, NULL);
211 event.type = libvlc_MediaPlayerPausableChanged;
212 event.u.media_player_pausable_changed.new_pausable = newval.b_bool;
214 libvlc_event_send( p_mi->p_event_manager, &event );
219 input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
220 vlc_value_t oldval, vlc_value_t newval,
224 input_thread_t * p_input = (input_thread_t *)p_this;
225 libvlc_media_player_t * p_mi = p_userdata;
226 libvlc_event_t event;
228 if( newval.i_int != INPUT_EVENT_TIMES )
231 assert( !strcmp(psz_cmd, "intf-event" ) );
233 if( var_GetInteger( p_input, "state" ) != PLAYING_S )
234 return VLC_SUCCESS; /* Don't send the position while stopped */
237 event.type = libvlc_MediaPlayerPositionChanged;
238 event.u.media_player_position_changed.new_position = var_GetFloat( p_input, "position" );;
239 libvlc_event_send( p_mi->p_event_manager, &event );
242 event.type = libvlc_MediaPlayerTimeChanged;
243 event.u.media_player_time_changed.new_time = var_GetTime( p_input, "time" );
244 libvlc_event_send( p_mi->p_event_manager, &event );
251 /**************************************************************************
252 * Create a Media Instance object
253 **************************************************************************/
254 libvlc_media_player_t *
255 libvlc_media_player_new( libvlc_instance_t * p_libvlc_instance,
256 libvlc_exception_t * p_e )
258 libvlc_media_player_t * p_mi;
260 if( !p_libvlc_instance )
262 libvlc_exception_raise( p_e, "invalid libvlc instance" );
266 p_mi = malloc( sizeof(libvlc_media_player_t) );
269 libvlc_exception_raise( p_e, "Not enough memory" );
274 p_mi->p_libvlc_instance = p_libvlc_instance;
275 p_mi->p_input_thread = NULL;
276 /* refcount strategy:
277 * - All items created by _new start with a refcount set to 1
278 * - Accessor _release decrease the refcount by 1, if after that
279 * operation the refcount is 0, the object is destroyed.
280 * - Accessor _retain increase the refcount by 1 (XXX: to implement) */
281 p_mi->i_refcount = 1;
282 p_mi->b_own_its_input_thread = true;
283 /* object_lock strategy:
284 * - No lock held in constructor
285 * - Lock when accessing all variable this lock is held
286 * - Lock when attempting to destroy the object the lock is also held */
287 vlc_mutex_init( &p_mi->object_lock );
288 p_mi->p_event_manager = libvlc_event_manager_new( p_mi,
289 p_libvlc_instance, p_e );
290 if( libvlc_exception_raised( p_e ) )
296 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
297 libvlc_MediaPlayerNothingSpecial, p_e );
298 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
299 libvlc_MediaPlayerOpening, p_e );
300 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
301 libvlc_MediaPlayerBuffering, p_e );
302 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
303 libvlc_MediaPlayerPlaying, p_e );
304 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
305 libvlc_MediaPlayerPaused, p_e );
306 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
307 libvlc_MediaPlayerStopped, p_e );
308 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
309 libvlc_MediaPlayerForward, p_e );
310 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
311 libvlc_MediaPlayerBackward, p_e );
312 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
313 libvlc_MediaPlayerEndReached, p_e );
314 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
315 libvlc_MediaPlayerEncounteredError, p_e );
317 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
318 libvlc_MediaPlayerPositionChanged, p_e );
319 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
320 libvlc_MediaPlayerTimeChanged, p_e );
321 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
322 libvlc_MediaPlayerTitleChanged, p_e );
323 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
324 libvlc_MediaPlayerSeekableChanged, p_e );
325 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
326 libvlc_MediaPlayerPausableChanged, p_e );
331 /**************************************************************************
332 * Create a Media Instance object with a media descriptor
333 **************************************************************************/
334 libvlc_media_player_t *
335 libvlc_media_player_new_from_media(
336 libvlc_media_t * p_md,
337 libvlc_exception_t *p_e )
339 libvlc_media_player_t * p_mi;
340 p_mi = libvlc_media_player_new( p_md->p_libvlc_instance, p_e );
345 libvlc_media_retain( p_md );
351 /**************************************************************************
352 * Create a new media instance object from an input_thread (Libvlc Internal)
353 **************************************************************************/
354 libvlc_media_player_t * libvlc_media_player_new_from_input_thread(
355 struct libvlc_instance_t *p_libvlc_instance,
356 input_thread_t *p_input,
357 libvlc_exception_t *p_e )
359 libvlc_media_player_t * p_mi;
363 libvlc_exception_raise( p_e, "invalid input thread" );
367 p_mi = libvlc_media_player_new( p_libvlc_instance, p_e );
372 p_mi->p_md = libvlc_media_new_from_input_item(
374 input_GetItem( p_input ), p_e );
378 libvlc_media_player_destroy( p_mi );
382 /* will be released in media_player_release() */
383 vlc_object_hold( p_input );
385 p_mi->p_input_thread = p_input;
386 p_mi->b_own_its_input_thread = false;
391 /**************************************************************************
392 * Destroy a Media Instance object (libvlc internal)
394 * Warning: No lock held here, but hey, this is internal.
395 **************************************************************************/
396 void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
398 input_thread_t *p_input_thread;
399 libvlc_exception_t p_e;
401 libvlc_exception_init( &p_e );
406 p_input_thread = libvlc_get_input_thread( p_mi, &p_e );
408 if( libvlc_exception_raised( &p_e ) )
410 libvlc_event_manager_release( p_mi->p_event_manager );
411 libvlc_exception_clear( &p_e );
413 return; /* no need to worry about no input thread */
415 vlc_mutex_destroy( &p_mi->object_lock );
417 vlc_object_release( p_input_thread );
419 libvlc_media_release( p_mi->p_md );
424 /**************************************************************************
425 * Release a Media Instance object
426 **************************************************************************/
427 void libvlc_media_player_release( libvlc_media_player_t *p_mi )
432 vlc_mutex_lock( &p_mi->object_lock );
436 if( p_mi->i_refcount > 0 )
438 vlc_mutex_unlock( &p_mi->object_lock );
441 vlc_mutex_unlock( &p_mi->object_lock );
442 vlc_mutex_destroy( &p_mi->object_lock );
444 release_input_thread( p_mi );
446 libvlc_event_manager_release( p_mi->p_event_manager );
448 libvlc_media_release( p_mi->p_md );
453 /**************************************************************************
454 * Retain a Media Instance object
455 **************************************************************************/
456 void libvlc_media_player_retain( libvlc_media_player_t *p_mi )
464 /**************************************************************************
465 * Set the Media descriptor associated with the instance
466 **************************************************************************/
467 void libvlc_media_player_set_media(
468 libvlc_media_player_t *p_mi,
469 libvlc_media_t *p_md,
470 libvlc_exception_t *p_e )
477 vlc_mutex_lock( &p_mi->object_lock );
479 release_input_thread( p_mi );
482 libvlc_media_set_state( p_mi->p_md, libvlc_NothingSpecial, p_e );
484 libvlc_media_release( p_mi->p_md );
489 vlc_mutex_unlock( &p_mi->object_lock );
490 return; /* It is ok to pass a NULL md */
493 libvlc_media_retain( p_md );
496 /* The policy here is to ignore that we were created using a different
497 * libvlc_instance, because we don't really care */
498 p_mi->p_libvlc_instance = p_md->p_libvlc_instance;
500 vlc_mutex_unlock( &p_mi->object_lock );
503 /**************************************************************************
504 * Get the Media descriptor associated with the instance
505 **************************************************************************/
507 libvlc_media_player_get_media(
508 libvlc_media_player_t *p_mi,
509 libvlc_exception_t *p_e )
516 libvlc_media_retain( p_mi->p_md );
520 /**************************************************************************
521 * Get the event Manager
522 **************************************************************************/
523 libvlc_event_manager_t *
524 libvlc_media_player_event_manager(
525 libvlc_media_player_t *p_mi,
526 libvlc_exception_t *p_e )
530 return p_mi->p_event_manager;
533 /**************************************************************************
535 **************************************************************************/
536 void libvlc_media_player_play( libvlc_media_player_t *p_mi,
537 libvlc_exception_t *p_e )
539 input_thread_t * p_input_thread;
541 if( (p_input_thread = libvlc_get_input_thread( p_mi, p_e )) )
543 /* A thread already exists, send it a play message */
544 input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
545 vlc_object_release( p_input_thread );
549 /* Ignore previous exception */
550 libvlc_exception_clear( p_e );
552 vlc_mutex_lock( &p_mi->object_lock );
556 libvlc_exception_raise( p_e, "no associated media descriptor" );
557 vlc_mutex_unlock( &p_mi->object_lock );
561 p_mi->p_input_thread = input_CreateThread( p_mi->p_libvlc_instance->p_libvlc_int,
562 p_mi->p_md->p_input_item );
565 if( !p_mi->p_input_thread )
567 vlc_mutex_unlock( &p_mi->object_lock );
571 p_input_thread = p_mi->p_input_thread;
576 val.i_int = p_mi->drawable;
577 var_Create( p_input_thread, "drawable", VLC_VAR_DOINHERIT );
578 var_Set( p_input_thread, "drawable", val );
581 vlc_event_manager_t * p_em = input_get_event_manager( p_input_thread );
582 vlc_event_attach( p_em, vlc_InputStateChanged, input_state_changed, p_mi );
584 var_AddCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
585 var_AddCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
586 var_AddCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
588 vlc_mutex_unlock( &p_mi->object_lock );
591 /**************************************************************************
593 **************************************************************************/
594 void libvlc_media_player_pause( libvlc_media_player_t *p_mi,
595 libvlc_exception_t *p_e )
597 input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi, p_e );
599 if( !p_input_thread )
602 libvlc_state_t state = libvlc_media_player_get_state( p_mi, p_e );
604 if( state == libvlc_Playing )
606 if( libvlc_media_player_can_pause( p_mi, p_e ) )
607 input_Control( p_input_thread, INPUT_SET_STATE, PAUSE_S );
609 libvlc_media_player_stop( p_mi, p_e );
612 input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
614 vlc_object_release( p_input_thread );
617 /**************************************************************************
619 **************************************************************************/
620 void libvlc_media_player_stop( libvlc_media_player_t *p_mi,
621 libvlc_exception_t *p_e )
623 libvlc_state_t state = libvlc_media_player_get_state( p_mi, p_e );
625 if( state == libvlc_Playing || state == libvlc_Paused )
627 /* Send a stop notification event only of we are in playing or paused states */
628 libvlc_media_set_state( p_mi->p_md, libvlc_Ended, p_e );
630 /* Construct and send the event */
631 libvlc_event_t event;
632 event.type = libvlc_MediaPlayerEndReached;
633 libvlc_event_send( p_mi->p_event_manager, &event );
636 if( p_mi->b_own_its_input_thread )
638 vlc_mutex_lock( &p_mi->object_lock );
639 release_input_thread( p_mi ); /* This will stop the input thread */
640 vlc_mutex_unlock( &p_mi->object_lock );
644 input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi, p_e );
646 if( !p_input_thread )
649 input_StopThread( p_input_thread );
650 vlc_object_release( p_input_thread );
654 /**************************************************************************
656 **************************************************************************/
657 void libvlc_media_player_set_drawable( libvlc_media_player_t *p_mi,
658 libvlc_drawable_t drawable,
659 libvlc_exception_t *p_e )
661 input_thread_t *p_input_thread;
662 vout_thread_t *p_vout = NULL;
664 p_mi->drawable = drawable;
666 /* Allow on the fly drawable changing. This is tricky has this may
667 * not be supported by every vout. We though can't disable it
668 * because of some creepy drawable type that are not flexible enough
669 * (Win32 HWND for instance) */
670 p_input_thread = libvlc_get_input_thread( p_mi, p_e );
671 if( !p_input_thread ) {
672 /* No input, nothing more to do, we are fine */
673 libvlc_exception_clear( p_e );
677 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
680 vout_Control( p_vout , VOUT_REPARENT, drawable);
681 vlc_object_release( p_vout );
683 vlc_object_release( p_input_thread );
686 /**************************************************************************
688 **************************************************************************/
690 libvlc_media_player_get_drawable ( libvlc_media_player_t *p_mi, libvlc_exception_t *p_e )
693 return p_mi->drawable;
696 /**************************************************************************
697 * Getters for stream information
698 **************************************************************************/
699 libvlc_time_t libvlc_media_player_get_length(
700 libvlc_media_player_t *p_mi,
701 libvlc_exception_t *p_e )
703 input_thread_t *p_input_thread;
706 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
707 if( !p_input_thread )
710 var_Get( p_input_thread, "length", &val );
711 vlc_object_release( p_input_thread );
713 return (val.i_time+500LL)/1000LL;
716 libvlc_time_t libvlc_media_player_get_time(
717 libvlc_media_player_t *p_mi,
718 libvlc_exception_t *p_e )
720 input_thread_t *p_input_thread;
723 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
724 if( !p_input_thread )
727 var_Get( p_input_thread , "time", &val );
728 vlc_object_release( p_input_thread );
729 return (val.i_time+500LL)/1000LL;
732 void libvlc_media_player_set_time(
733 libvlc_media_player_t *p_mi,
735 libvlc_exception_t *p_e )
737 input_thread_t *p_input_thread;
740 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
741 if( !p_input_thread )
744 value.i_time = time*1000LL;
745 var_Set( p_input_thread, "time", value );
746 vlc_object_release( p_input_thread );
749 void libvlc_media_player_set_position(
750 libvlc_media_player_t *p_mi,
752 libvlc_exception_t *p_e )
754 input_thread_t *p_input_thread;
756 val.f_float = position;
758 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
759 if( !p_input_thread )
762 var_Set( p_input_thread, "position", val );
763 vlc_object_release( p_input_thread );
766 float libvlc_media_player_get_position(
767 libvlc_media_player_t *p_mi,
768 libvlc_exception_t *p_e )
770 input_thread_t *p_input_thread;
773 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
774 if( !p_input_thread )
777 var_Get( p_input_thread, "position", &val );
778 vlc_object_release( p_input_thread );
783 void libvlc_media_player_set_chapter(
784 libvlc_media_player_t *p_mi,
786 libvlc_exception_t *p_e )
788 input_thread_t *p_input_thread;
792 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
793 if( !p_input_thread )
796 var_Set( p_input_thread, "chapter", val );
797 vlc_object_release( p_input_thread );
800 int libvlc_media_player_get_chapter(
801 libvlc_media_player_t *p_mi,
802 libvlc_exception_t *p_e )
804 input_thread_t *p_input_thread;
807 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
808 if( !p_input_thread )
811 var_Get( p_input_thread, "chapter", &val );
812 vlc_object_release( p_input_thread );
817 int libvlc_media_player_get_chapter_count(
818 libvlc_media_player_t *p_mi,
819 libvlc_exception_t *p_e )
821 input_thread_t *p_input_thread;
824 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
825 if( !p_input_thread )
828 var_Change( p_input_thread, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
829 vlc_object_release( p_input_thread );
834 int libvlc_media_player_get_chapter_count_for_title(
835 libvlc_media_player_t *p_mi,
837 libvlc_exception_t *p_e )
839 input_thread_t *p_input_thread;
842 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
843 if( !p_input_thread )
847 if( asprintf( &psz_name, "title %2i", i_title ) == -1 )
849 vlc_object_release( p_input_thread );
852 var_Change( p_input_thread, psz_name, VLC_VAR_CHOICESCOUNT, &val, NULL );
853 vlc_object_release( p_input_thread );
859 void libvlc_media_player_set_title(
860 libvlc_media_player_t *p_mi,
862 libvlc_exception_t *p_e )
864 input_thread_t *p_input_thread;
868 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
869 if( !p_input_thread )
872 var_Set( p_input_thread, "title", val );
873 vlc_object_release( p_input_thread );
876 libvlc_event_t event;
877 event.type = libvlc_MediaPlayerTitleChanged;
878 event.u.media_player_title_changed.new_title = i_title;
879 libvlc_event_send( p_mi->p_event_manager, &event );
882 int libvlc_media_player_get_title(
883 libvlc_media_player_t *p_mi,
884 libvlc_exception_t *p_e )
886 input_thread_t *p_input_thread;
889 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
890 if( !p_input_thread )
893 var_Get( p_input_thread, "title", &val );
894 vlc_object_release( p_input_thread );
899 int libvlc_media_player_get_title_count(
900 libvlc_media_player_t *p_mi,
901 libvlc_exception_t *p_e )
903 input_thread_t *p_input_thread;
906 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
907 if( !p_input_thread )
910 var_Change( p_input_thread, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
911 vlc_object_release( p_input_thread );
916 void libvlc_media_player_next_chapter(
917 libvlc_media_player_t *p_mi,
918 libvlc_exception_t *p_e )
920 input_thread_t *p_input_thread;
922 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
923 if( !p_input_thread )
926 int i_type = var_Type( p_input_thread, "next-chapter" );
929 var_Set( p_input_thread, (i_type & VLC_VAR_TYPE) != 0 ?
930 "next-chapter":"next-title", val );
932 vlc_object_release( p_input_thread );
935 void libvlc_media_player_previous_chapter(
936 libvlc_media_player_t *p_mi,
937 libvlc_exception_t *p_e )
939 input_thread_t *p_input_thread;
941 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
942 if( !p_input_thread )
945 int i_type = var_Type( p_input_thread, "next-chapter" );
948 var_Set( p_input_thread, (i_type & VLC_VAR_TYPE) != 0 ?
949 "prev-chapter":"prev-title", val );
951 vlc_object_release( p_input_thread );
954 float libvlc_media_player_get_fps(
955 libvlc_media_player_t *p_mi,
956 libvlc_exception_t *p_e)
958 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
963 if( input_Control( p_input_thread, INPUT_GET_VIDEO_FPS, &f_fps ) )
965 vlc_object_release( p_input_thread );
970 int libvlc_media_player_will_play( libvlc_media_player_t *p_mi,
971 libvlc_exception_t *p_e)
973 input_thread_t *p_input_thread =
974 libvlc_get_input_thread ( p_mi, p_e);
975 if ( !p_input_thread )
978 if ( !p_input_thread->b_die && !p_input_thread->b_dead )
980 vlc_object_release( p_input_thread );
983 vlc_object_release( p_input_thread );
987 void libvlc_media_player_set_rate(
988 libvlc_media_player_t *p_mi,
990 libvlc_exception_t *p_e )
992 input_thread_t *p_input_thread;
997 RAISEVOID( "Rate value is invalid" );
999 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
1000 if( !p_input_thread )
1003 b_can_rewind = var_GetBool( p_input_thread, "can-rewind" );
1004 if( (rate < 0) && !b_can_rewind )
1006 vlc_object_release( p_input_thread );
1007 libvlc_exception_raise( p_e, "Rate value is invalid" );
1011 val.i_int = 1000.0f/rate;
1012 var_Set( p_input_thread, "rate", val );
1013 vlc_object_release( p_input_thread );
1016 float libvlc_media_player_get_rate(
1017 libvlc_media_player_t *p_mi,
1018 libvlc_exception_t *p_e )
1020 input_thread_t *p_input_thread;
1024 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
1025 if( !p_input_thread )
1026 return 0.0; /* rate < 0 indicates rewind */
1028 var_Get( p_input_thread, "rate", &val );
1029 b_can_rewind = var_GetBool( p_input_thread, "can-rewind" );
1030 if( (val.i_int < 0) && !b_can_rewind )
1032 libvlc_exception_raise( p_e, "invalid rate" );
1035 vlc_object_release( p_input_thread );
1037 return (float)1000.0f/val.i_int;
1040 libvlc_state_t libvlc_media_player_get_state(
1041 libvlc_media_player_t *p_mi,
1042 libvlc_exception_t *p_e )
1044 input_thread_t *p_input_thread;
1047 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
1048 if ( !p_input_thread )
1050 /* We do return the right value, no need to throw an exception */
1051 if( libvlc_exception_raised( p_e ) )
1052 libvlc_exception_clear( p_e );
1053 return libvlc_Ended;
1056 var_Get( p_input_thread, "state", &val );
1057 vlc_object_release( p_input_thread );
1059 return vlc_to_libvlc_state(val.i_int);
1062 int libvlc_media_player_is_seekable( libvlc_media_player_t *p_mi,
1063 libvlc_exception_t *p_e )
1065 input_thread_t *p_input_thread;
1068 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
1069 if ( !p_input_thread )
1071 /* We do return the right value, no need to throw an exception */
1072 if( libvlc_exception_raised( p_e ) )
1073 libvlc_exception_clear( p_e );
1076 var_Get( p_input_thread, "can-seek", &val );
1077 vlc_object_release( p_input_thread );
1082 /* internal function, used by audio, video */
1083 libvlc_track_description_t *
1084 libvlc_get_track_description( libvlc_media_player_t *p_mi,
1085 const char *psz_variable,
1086 libvlc_exception_t *p_e )
1088 input_thread_t *p_input = libvlc_get_input_thread( p_mi, p_e );
1093 vlc_value_t val_list, text_list;
1094 var_Change( p_input, psz_variable, VLC_VAR_GETLIST, &val_list, &text_list);
1096 if( val_list.p_list->i_count <= 0 ) /* no tracks */
1099 libvlc_track_description_t *p_track_description, *p_actual, *p_previous;
1100 p_track_description = ( libvlc_track_description_t * )
1101 malloc( sizeof( libvlc_track_description_t ) );
1102 if ( !p_track_description )
1104 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list);
1105 vlc_object_release( p_input );
1106 libvlc_exception_raise( p_e, "no enough memory" );
1109 p_actual = p_track_description;
1111 for( int i = 0; i < val_list.p_list->i_count; i++ )
1115 p_actual = ( libvlc_track_description_t * )
1116 malloc( sizeof( libvlc_track_description_t ) );
1119 libvlc_track_description_release( p_track_description );
1120 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list);
1121 vlc_object_release( p_input );
1122 libvlc_exception_raise( p_e, "no enough memory" );
1126 p_actual->i_id = val_list.p_list->p_values[i].i_int;
1127 p_actual->psz_name = strdup( text_list.p_list->p_values[i].psz_string );
1128 p_actual->p_next = NULL;
1130 p_previous->p_next = p_actual;
1131 p_previous = p_actual;
1134 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list);
1135 vlc_object_release( p_input );
1137 return p_track_description;
1140 void libvlc_track_description_release( libvlc_track_description_t *p_track_description )
1142 libvlc_track_description_t *p_actual, *p_before;
1143 p_actual = p_track_description;
1147 free( p_actual->psz_name );
1148 p_before = p_actual;
1149 p_actual = p_before->p_next;
1154 int libvlc_media_player_can_pause( libvlc_media_player_t *p_mi,
1155 libvlc_exception_t *p_e )
1157 input_thread_t *p_input_thread;
1160 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
1161 if ( !p_input_thread )
1163 /* We do return the right value, no need to throw an exception */
1164 if( libvlc_exception_raised( p_e ) )
1165 libvlc_exception_clear( p_e );
1168 var_Get( p_input_thread, "can-pause", &val );
1169 vlc_object_release( p_input_thread );