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_seekable_changed( vlc_object_t * p_this, char const * psz_cmd,
34 vlc_value_t oldval, vlc_value_t newval,
37 input_pausable_changed( vlc_object_t * p_this, char const * psz_cmd,
38 vlc_value_t oldval, vlc_value_t newval,
41 input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
42 vlc_value_t oldval, vlc_value_t newval,
45 static int SnapshotTakenCallback( vlc_object_t *p_this, char const *psz_cmd,
46 vlc_value_t oldval, vlc_value_t newval, void *p_data );
48 static const libvlc_state_t vlc_to_libvlc_state_array[] =
50 [INIT_S] = libvlc_NothingSpecial,
51 [OPENING_S] = libvlc_Opening,
52 [PLAYING_S] = libvlc_Playing,
53 [PAUSE_S] = libvlc_Paused,
54 [END_S] = libvlc_Ended,
55 [ERROR_S] = libvlc_Error,
58 static inline libvlc_state_t vlc_to_libvlc_state( int vlc_state )
60 if( vlc_state < 0 || vlc_state > 6 )
63 return vlc_to_libvlc_state_array[vlc_state];
67 * Release the associated input thread
69 * Object lock is NOT held.
71 static void release_input_thread( libvlc_media_player_t *p_mi )
73 input_thread_t * p_input_thread;
75 if( !p_mi || !p_mi->p_input_thread )
78 p_input_thread = p_mi->p_input_thread;
80 /* No one is tracking this input_thread appart us. Destroy it */
81 if( p_mi->b_own_its_input_thread )
83 var_DelCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
84 var_DelCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
85 var_DelCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
87 /* We owned this one */
88 input_StopThread( p_input_thread );
89 vlc_thread_join( p_input_thread );
91 var_Destroy( p_input_thread, "drawable" );
94 vlc_object_release( p_input_thread );
96 p_mi->p_input_thread = NULL;
100 * Retrieve the input thread. Be sure to release the object
101 * once you are done with it. (libvlc Internal)
103 * Object lock is held.
105 input_thread_t *libvlc_get_input_thread( libvlc_media_player_t *p_mi,
106 libvlc_exception_t *p_e )
108 input_thread_t *p_input_thread;
110 if( !p_mi ) RAISENULL( "Media Instance is NULL" );
112 vlc_mutex_lock( &p_mi->object_lock );
114 if( !p_mi->p_input_thread )
116 vlc_mutex_unlock( &p_mi->object_lock );
117 RAISENULL( "Input is NULL" );
120 p_input_thread = p_mi->p_input_thread;
121 vlc_object_hold( p_input_thread );
123 vlc_mutex_unlock( &p_mi->object_lock );
125 return p_input_thread;
129 input_seekable_changed( vlc_object_t * p_this, char const * psz_cmd,
130 vlc_value_t oldval, vlc_value_t newval,
136 libvlc_media_player_t * p_mi = p_userdata;
137 libvlc_event_t event;
139 libvlc_media_set_state( p_mi->p_md, libvlc_NothingSpecial, NULL);
140 event.type = libvlc_MediaPlayerSeekableChanged;
141 event.u.media_player_seekable_changed.new_seekable = newval.b_bool;
143 libvlc_event_send( p_mi->p_event_manager, &event );
148 input_pausable_changed( vlc_object_t * p_this, char const * psz_cmd,
149 vlc_value_t oldval, vlc_value_t newval,
155 libvlc_media_player_t * p_mi = p_userdata;
156 libvlc_event_t event;
158 libvlc_media_set_state( p_mi->p_md, libvlc_NothingSpecial, NULL);
159 event.type = libvlc_MediaPlayerPausableChanged;
160 event.u.media_player_pausable_changed.new_pausable = newval.b_bool;
162 libvlc_event_send( p_mi->p_event_manager, &event );
167 input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
168 vlc_value_t oldval, vlc_value_t newval,
172 input_thread_t * p_input = (input_thread_t *)p_this;
173 libvlc_media_player_t * p_mi = p_userdata;
174 libvlc_event_t event;
176 assert( !strcmp( psz_cmd, "intf-event" ) );
178 if( newval.i_int == INPUT_EVENT_STATE )
180 libvlc_state_t libvlc_state;
182 switch ( var_GetInteger( p_input, "state" ) )
185 libvlc_state = libvlc_NothingSpecial;
186 event.type = libvlc_MediaPlayerNothingSpecial;
189 libvlc_state = libvlc_Opening;
190 event.type = libvlc_MediaPlayerOpening;
193 libvlc_state = libvlc_Playing;
194 event.type = libvlc_MediaPlayerPlaying;
197 libvlc_state = libvlc_Paused;
198 event.type = libvlc_MediaPlayerPaused;
201 libvlc_state = libvlc_Ended;
202 event.type = libvlc_MediaPlayerEndReached;
205 libvlc_state = libvlc_Error;
206 event.type = libvlc_MediaPlayerEncounteredError;
213 libvlc_media_set_state( p_mi->p_md, libvlc_state, NULL);
214 libvlc_event_send( p_mi->p_event_manager, &event );
216 else if( newval.i_int == INPUT_EVENT_TIMES )
218 if( var_GetInteger( p_input, "state" ) != PLAYING_S )
219 return VLC_SUCCESS; /* Don't send the position while stopped */
222 event.type = libvlc_MediaPlayerPositionChanged;
223 event.u.media_player_position_changed.new_position = var_GetFloat( p_input, "position" );;
224 libvlc_event_send( p_mi->p_event_manager, &event );
227 event.type = libvlc_MediaPlayerTimeChanged;
228 event.u.media_player_time_changed.new_time = var_GetTime( p_input, "time" );
229 libvlc_event_send( p_mi->p_event_manager, &event );
237 /**************************************************************************
238 * Create a Media Instance object
239 **************************************************************************/
240 libvlc_media_player_t *
241 libvlc_media_player_new( libvlc_instance_t * p_libvlc_instance,
242 libvlc_exception_t * p_e )
244 libvlc_media_player_t * p_mi;
246 if( !p_libvlc_instance )
248 libvlc_exception_raise( p_e, "invalid libvlc instance" );
252 p_mi = malloc( sizeof(libvlc_media_player_t) );
255 libvlc_exception_raise( p_e, "Not enough memory" );
260 p_mi->p_libvlc_instance = p_libvlc_instance;
261 p_mi->p_input_thread = NULL;
262 /* refcount strategy:
263 * - All items created by _new start with a refcount set to 1
264 * - Accessor _release decrease the refcount by 1, if after that
265 * operation the refcount is 0, the object is destroyed.
266 * - Accessor _retain increase the refcount by 1 (XXX: to implement) */
267 p_mi->i_refcount = 1;
268 p_mi->b_own_its_input_thread = true;
269 /* object_lock strategy:
270 * - No lock held in constructor
271 * - Lock when accessing all variable this lock is held
272 * - Lock when attempting to destroy the object the lock is also held */
273 vlc_mutex_init( &p_mi->object_lock );
274 p_mi->p_event_manager = libvlc_event_manager_new( p_mi,
275 p_libvlc_instance, p_e );
276 if( libvlc_exception_raised( p_e ) )
282 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
283 libvlc_MediaPlayerNothingSpecial, p_e );
284 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
285 libvlc_MediaPlayerOpening, p_e );
286 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
287 libvlc_MediaPlayerBuffering, p_e );
288 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
289 libvlc_MediaPlayerPlaying, p_e );
290 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
291 libvlc_MediaPlayerPaused, p_e );
292 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
293 libvlc_MediaPlayerStopped, p_e );
294 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
295 libvlc_MediaPlayerForward, p_e );
296 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
297 libvlc_MediaPlayerBackward, p_e );
298 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
299 libvlc_MediaPlayerEndReached, p_e );
300 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
301 libvlc_MediaPlayerEncounteredError, p_e );
303 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
304 libvlc_MediaPlayerPositionChanged, p_e );
305 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
306 libvlc_MediaPlayerTimeChanged, p_e );
307 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
308 libvlc_MediaPlayerTitleChanged, p_e );
309 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
310 libvlc_MediaPlayerSeekableChanged, p_e );
311 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
312 libvlc_MediaPlayerPausableChanged, p_e );
314 /* Snapshot initialization */
315 libvlc_event_manager_register_event_type( p_mi->p_event_manager,
316 libvlc_MediaPlayerSnapshotTaken, p_e );
317 /* Attach a var callback to the global object to provide the glue between
318 vout_thread that generates the event and media_player that re-emits it
319 with its own event manager
321 var_Create( p_libvlc_instance->p_libvlc_int, "vout-snapshottaken", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
322 var_AddCallback( p_libvlc_instance->p_libvlc_int, "vout-snapshottaken", SnapshotTakenCallback, p_mi );
327 /**************************************************************************
328 * Create a Media Instance object with a media descriptor
329 **************************************************************************/
330 libvlc_media_player_t *
331 libvlc_media_player_new_from_media(
332 libvlc_media_t * p_md,
333 libvlc_exception_t *p_e )
335 libvlc_media_player_t * p_mi;
336 p_mi = libvlc_media_player_new( p_md->p_libvlc_instance, p_e );
341 libvlc_media_retain( p_md );
347 /**************************************************************************
348 * Create a new media instance object from an input_thread (Libvlc Internal)
349 **************************************************************************/
350 libvlc_media_player_t * libvlc_media_player_new_from_input_thread(
351 struct libvlc_instance_t *p_libvlc_instance,
352 input_thread_t *p_input,
353 libvlc_exception_t *p_e )
355 libvlc_media_player_t * p_mi;
359 libvlc_exception_raise( p_e, "invalid input thread" );
363 p_mi = libvlc_media_player_new( p_libvlc_instance, p_e );
368 p_mi->p_md = libvlc_media_new_from_input_item(
370 input_GetItem( p_input ), p_e );
374 libvlc_media_player_destroy( p_mi );
378 /* will be released in media_player_release() */
379 vlc_object_hold( p_input );
381 p_mi->p_input_thread = p_input;
382 p_mi->b_own_its_input_thread = false;
387 /**************************************************************************
388 * Destroy a Media Instance object (libvlc internal)
390 * Warning: No lock held here, but hey, this is internal.
391 **************************************************************************/
392 void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
394 input_thread_t *p_input_thread;
395 libvlc_exception_t p_e;
397 libvlc_exception_init( &p_e );
402 /* Detach Callback from the main libvlc object */
403 var_DelCallback( p_mi->p_libvlc_instance->p_libvlc_int, "vout-snapshottaken", SnapshotTakenCallback, p_mi );
405 p_input_thread = libvlc_get_input_thread( p_mi, &p_e );
407 if( libvlc_exception_raised( &p_e ) )
409 libvlc_event_manager_release( p_mi->p_event_manager );
410 libvlc_exception_clear( &p_e );
412 return; /* no need to worry about no input thread */
414 vlc_mutex_destroy( &p_mi->object_lock );
416 vlc_object_release( p_input_thread );
418 libvlc_media_release( p_mi->p_md );
423 /**************************************************************************
424 * Release a Media Instance object
425 **************************************************************************/
426 void libvlc_media_player_release( libvlc_media_player_t *p_mi )
431 vlc_mutex_lock( &p_mi->object_lock );
435 if( p_mi->i_refcount > 0 )
437 vlc_mutex_unlock( &p_mi->object_lock );
440 vlc_mutex_unlock( &p_mi->object_lock );
441 vlc_mutex_destroy( &p_mi->object_lock );
443 release_input_thread( p_mi );
445 libvlc_event_manager_release( p_mi->p_event_manager );
447 libvlc_media_release( p_mi->p_md );
452 /**************************************************************************
453 * Retain a Media Instance object
454 **************************************************************************/
455 void libvlc_media_player_retain( libvlc_media_player_t *p_mi )
463 /**************************************************************************
464 * Set the Media descriptor associated with the instance
465 **************************************************************************/
466 void libvlc_media_player_set_media(
467 libvlc_media_player_t *p_mi,
468 libvlc_media_t *p_md,
469 libvlc_exception_t *p_e )
476 vlc_mutex_lock( &p_mi->object_lock );
478 release_input_thread( p_mi );
481 libvlc_media_set_state( p_mi->p_md, libvlc_NothingSpecial, p_e );
483 libvlc_media_release( p_mi->p_md );
488 vlc_mutex_unlock( &p_mi->object_lock );
489 return; /* It is ok to pass a NULL md */
492 libvlc_media_retain( p_md );
495 /* The policy here is to ignore that we were created using a different
496 * libvlc_instance, because we don't really care */
497 p_mi->p_libvlc_instance = p_md->p_libvlc_instance;
499 vlc_mutex_unlock( &p_mi->object_lock );
502 /**************************************************************************
503 * Get the Media descriptor associated with the instance
504 **************************************************************************/
506 libvlc_media_player_get_media(
507 libvlc_media_player_t *p_mi,
508 libvlc_exception_t *p_e )
515 libvlc_media_retain( p_mi->p_md );
519 /**************************************************************************
520 * Get the event Manager
521 **************************************************************************/
522 libvlc_event_manager_t *
523 libvlc_media_player_event_manager(
524 libvlc_media_player_t *p_mi,
525 libvlc_exception_t *p_e )
529 return p_mi->p_event_manager;
532 /**************************************************************************
533 * Trigger a snapshot Taken Event
534 *************************************************************************/
535 static int SnapshotTakenCallback( vlc_object_t *p_this, char const *psz_cmd,
536 vlc_value_t oldval, vlc_value_t newval, void *p_data )
538 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
541 libvlc_media_player_t* p_mi = (libvlc_media_player_t*) p_data ;
542 libvlc_event_t event ;
543 event.type = libvlc_MediaPlayerSnapshotTaken ;
544 event.u.media_player_snapshot_taken.psz_filename = newval.psz_string ;
545 /* Snapshot psz data is a vlc_variable owned by libvlc object .
546 Its memmory management is taken care by the obj*/
547 msg_Dbg( p_this, "about to emit libvlc_snapshot_taken.make psz_str=0x%x (%s)",
548 event.u.media_player_snapshot_taken.psz_filename ,event.u.media_player_snapshot_taken.psz_filename );
549 libvlc_event_send( p_mi->p_event_manager, &event );
554 /**************************************************************************
556 **************************************************************************/
557 void libvlc_media_player_play( libvlc_media_player_t *p_mi,
558 libvlc_exception_t *p_e )
560 input_thread_t * p_input_thread;
562 if( (p_input_thread = libvlc_get_input_thread( p_mi, p_e )) )
564 /* A thread already exists, send it a play message */
565 input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
566 vlc_object_release( p_input_thread );
570 /* Ignore previous exception */
571 libvlc_exception_clear( p_e );
573 vlc_mutex_lock( &p_mi->object_lock );
577 libvlc_exception_raise( p_e, "no associated media descriptor" );
578 vlc_mutex_unlock( &p_mi->object_lock );
582 p_mi->p_input_thread = input_CreateThread( p_mi->p_libvlc_instance->p_libvlc_int,
583 p_mi->p_md->p_input_item );
586 if( !p_mi->p_input_thread )
588 vlc_mutex_unlock( &p_mi->object_lock );
592 p_input_thread = p_mi->p_input_thread;
597 val.i_int = p_mi->drawable;
598 var_Create( p_input_thread, "drawable", VLC_VAR_DOINHERIT );
599 var_Set( p_input_thread, "drawable", val );
602 var_AddCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
603 var_AddCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
604 var_AddCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
606 vlc_mutex_unlock( &p_mi->object_lock );
609 /**************************************************************************
611 **************************************************************************/
612 void libvlc_media_player_pause( libvlc_media_player_t *p_mi,
613 libvlc_exception_t *p_e )
615 input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi, p_e );
617 if( !p_input_thread )
620 libvlc_state_t state = libvlc_media_player_get_state( p_mi, p_e );
622 if( state == libvlc_Playing )
624 if( libvlc_media_player_can_pause( p_mi, p_e ) )
625 input_Control( p_input_thread, INPUT_SET_STATE, PAUSE_S );
627 libvlc_media_player_stop( p_mi, p_e );
630 input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
632 vlc_object_release( p_input_thread );
635 /**************************************************************************
637 **************************************************************************/
638 void libvlc_media_player_stop( libvlc_media_player_t *p_mi,
639 libvlc_exception_t *p_e )
641 libvlc_state_t state = libvlc_media_player_get_state( p_mi, p_e );
643 if( state == libvlc_Playing || state == libvlc_Paused )
645 /* Send a stop notification event only of we are in playing or paused states */
646 libvlc_media_set_state( p_mi->p_md, libvlc_Ended, p_e );
648 /* Construct and send the event */
649 libvlc_event_t event;
650 event.type = libvlc_MediaPlayerStopped;
651 libvlc_event_send( p_mi->p_event_manager, &event );
654 if( p_mi->b_own_its_input_thread )
656 vlc_mutex_lock( &p_mi->object_lock );
657 release_input_thread( p_mi ); /* This will stop the input thread */
658 vlc_mutex_unlock( &p_mi->object_lock );
662 input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi, p_e );
664 if( !p_input_thread )
667 input_StopThread( p_input_thread );
668 vlc_object_release( p_input_thread );
672 /**************************************************************************
674 **************************************************************************/
675 void libvlc_media_player_set_drawable( libvlc_media_player_t *p_mi,
676 libvlc_drawable_t drawable,
677 libvlc_exception_t *p_e )
679 input_thread_t *p_input_thread;
680 vout_thread_t *p_vout = NULL;
682 p_mi->drawable = drawable;
684 /* Allow on the fly drawable changing. This is tricky has this may
685 * not be supported by every vout. We though can't disable it
686 * because of some creepy drawable type that are not flexible enough
687 * (Win32 HWND for instance) */
688 p_input_thread = libvlc_get_input_thread( p_mi, p_e );
689 if( !p_input_thread ) {
690 /* No input, nothing more to do, we are fine */
691 libvlc_exception_clear( p_e );
695 p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
698 vout_Control( p_vout , VOUT_REPARENT, drawable);
699 vlc_object_release( p_vout );
701 vlc_object_release( p_input_thread );
704 /**************************************************************************
706 **************************************************************************/
708 libvlc_media_player_get_drawable ( libvlc_media_player_t *p_mi, libvlc_exception_t *p_e )
711 return p_mi->drawable;
714 /**************************************************************************
715 * Getters for stream information
716 **************************************************************************/
717 libvlc_time_t libvlc_media_player_get_length(
718 libvlc_media_player_t *p_mi,
719 libvlc_exception_t *p_e )
721 input_thread_t *p_input_thread;
724 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
725 if( !p_input_thread )
728 var_Get( p_input_thread, "length", &val );
729 vlc_object_release( p_input_thread );
731 return (val.i_time+500LL)/1000LL;
734 libvlc_time_t libvlc_media_player_get_time(
735 libvlc_media_player_t *p_mi,
736 libvlc_exception_t *p_e )
738 input_thread_t *p_input_thread;
741 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
742 if( !p_input_thread )
745 var_Get( p_input_thread , "time", &val );
746 vlc_object_release( p_input_thread );
747 return (val.i_time+500LL)/1000LL;
750 void libvlc_media_player_set_time(
751 libvlc_media_player_t *p_mi,
753 libvlc_exception_t *p_e )
755 input_thread_t *p_input_thread;
758 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
759 if( !p_input_thread )
762 value.i_time = time*1000LL;
763 var_Set( p_input_thread, "time", value );
764 vlc_object_release( p_input_thread );
767 void libvlc_media_player_set_position(
768 libvlc_media_player_t *p_mi,
770 libvlc_exception_t *p_e )
772 input_thread_t *p_input_thread;
774 val.f_float = position;
776 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
777 if( !p_input_thread )
780 var_Set( p_input_thread, "position", val );
781 vlc_object_release( p_input_thread );
784 float libvlc_media_player_get_position(
785 libvlc_media_player_t *p_mi,
786 libvlc_exception_t *p_e )
788 input_thread_t *p_input_thread;
791 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
792 if( !p_input_thread )
795 var_Get( p_input_thread, "position", &val );
796 vlc_object_release( p_input_thread );
801 void libvlc_media_player_set_chapter(
802 libvlc_media_player_t *p_mi,
804 libvlc_exception_t *p_e )
806 input_thread_t *p_input_thread;
810 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
811 if( !p_input_thread )
814 var_Set( p_input_thread, "chapter", val );
815 vlc_object_release( p_input_thread );
818 int libvlc_media_player_get_chapter(
819 libvlc_media_player_t *p_mi,
820 libvlc_exception_t *p_e )
822 input_thread_t *p_input_thread;
825 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
826 if( !p_input_thread )
829 var_Get( p_input_thread, "chapter", &val );
830 vlc_object_release( p_input_thread );
835 int libvlc_media_player_get_chapter_count(
836 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 )
846 var_Change( p_input_thread, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
847 vlc_object_release( p_input_thread );
852 int libvlc_media_player_get_chapter_count_for_title(
853 libvlc_media_player_t *p_mi,
855 libvlc_exception_t *p_e )
857 input_thread_t *p_input_thread;
860 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
861 if( !p_input_thread )
865 if( asprintf( &psz_name, "title %2i", i_title ) == -1 )
867 vlc_object_release( p_input_thread );
870 var_Change( p_input_thread, psz_name, VLC_VAR_CHOICESCOUNT, &val, NULL );
871 vlc_object_release( p_input_thread );
877 void libvlc_media_player_set_title(
878 libvlc_media_player_t *p_mi,
880 libvlc_exception_t *p_e )
882 input_thread_t *p_input_thread;
886 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
887 if( !p_input_thread )
890 var_Set( p_input_thread, "title", val );
891 vlc_object_release( p_input_thread );
894 libvlc_event_t event;
895 event.type = libvlc_MediaPlayerTitleChanged;
896 event.u.media_player_title_changed.new_title = i_title;
897 libvlc_event_send( p_mi->p_event_manager, &event );
900 int libvlc_media_player_get_title(
901 libvlc_media_player_t *p_mi,
902 libvlc_exception_t *p_e )
904 input_thread_t *p_input_thread;
907 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
908 if( !p_input_thread )
911 var_Get( p_input_thread, "title", &val );
912 vlc_object_release( p_input_thread );
917 int libvlc_media_player_get_title_count(
918 libvlc_media_player_t *p_mi,
919 libvlc_exception_t *p_e )
921 input_thread_t *p_input_thread;
924 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
925 if( !p_input_thread )
928 var_Change( p_input_thread, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
929 vlc_object_release( p_input_thread );
934 void libvlc_media_player_next_chapter(
935 libvlc_media_player_t *p_mi,
936 libvlc_exception_t *p_e )
938 input_thread_t *p_input_thread;
940 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
941 if( !p_input_thread )
944 int i_type = var_Type( p_input_thread, "next-chapter" );
947 var_Set( p_input_thread, (i_type & VLC_VAR_TYPE) != 0 ?
948 "next-chapter":"next-title", val );
950 vlc_object_release( p_input_thread );
953 void libvlc_media_player_previous_chapter(
954 libvlc_media_player_t *p_mi,
955 libvlc_exception_t *p_e )
957 input_thread_t *p_input_thread;
959 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
960 if( !p_input_thread )
963 int i_type = var_Type( p_input_thread, "next-chapter" );
966 var_Set( p_input_thread, (i_type & VLC_VAR_TYPE) != 0 ?
967 "prev-chapter":"prev-title", val );
969 vlc_object_release( p_input_thread );
972 float libvlc_media_player_get_fps(
973 libvlc_media_player_t *p_mi,
974 libvlc_exception_t *p_e)
976 input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
981 if( input_Control( p_input_thread, INPUT_GET_VIDEO_FPS, &f_fps ) )
983 vlc_object_release( p_input_thread );
988 int libvlc_media_player_will_play( libvlc_media_player_t *p_mi,
989 libvlc_exception_t *p_e)
991 input_thread_t *p_input_thread =
992 libvlc_get_input_thread ( p_mi, p_e);
993 if ( !p_input_thread )
996 if ( !p_input_thread->b_die && !p_input_thread->b_dead )
998 vlc_object_release( p_input_thread );
1001 vlc_object_release( p_input_thread );
1005 void libvlc_media_player_set_rate(
1006 libvlc_media_player_t *p_mi,
1008 libvlc_exception_t *p_e )
1010 input_thread_t *p_input_thread;
1015 RAISEVOID( "Rate value is invalid" );
1017 p_input_thread = libvlc_get_input_thread ( p_mi, p_e);
1018 if( !p_input_thread )
1021 b_can_rewind = var_GetBool( p_input_thread, "can-rewind" );
1022 if( (rate < 0) && !b_can_rewind )
1024 vlc_object_release( p_input_thread );
1025 libvlc_exception_raise( p_e, "Rate value is invalid" );
1029 val.i_int = 1000.0f/rate;
1030 var_Set( p_input_thread, "rate", val );
1031 vlc_object_release( p_input_thread );
1034 float libvlc_media_player_get_rate(
1035 libvlc_media_player_t *p_mi,
1036 libvlc_exception_t *p_e )
1038 input_thread_t *p_input_thread;
1042 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
1043 if( !p_input_thread )
1044 return 0.0; /* rate < 0 indicates rewind */
1046 var_Get( p_input_thread, "rate", &val );
1047 b_can_rewind = var_GetBool( p_input_thread, "can-rewind" );
1048 if( (val.i_int < 0) && !b_can_rewind )
1050 libvlc_exception_raise( p_e, "invalid rate" );
1053 vlc_object_release( p_input_thread );
1055 return (float)1000.0f/val.i_int;
1058 libvlc_state_t libvlc_media_player_get_state(
1059 libvlc_media_player_t *p_mi,
1060 libvlc_exception_t *p_e )
1062 input_thread_t *p_input_thread;
1065 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
1066 if ( !p_input_thread )
1068 /* We do return the right value, no need to throw an exception */
1069 if( libvlc_exception_raised( p_e ) )
1070 libvlc_exception_clear( p_e );
1071 return libvlc_Ended;
1074 var_Get( p_input_thread, "state", &val );
1075 vlc_object_release( p_input_thread );
1077 return vlc_to_libvlc_state(val.i_int);
1080 int libvlc_media_player_is_seekable( libvlc_media_player_t *p_mi,
1081 libvlc_exception_t *p_e )
1083 input_thread_t *p_input_thread;
1086 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
1087 if ( !p_input_thread )
1089 /* We do return the right value, no need to throw an exception */
1090 if( libvlc_exception_raised( p_e ) )
1091 libvlc_exception_clear( p_e );
1094 var_Get( p_input_thread, "can-seek", &val );
1095 vlc_object_release( p_input_thread );
1100 /* internal function, used by audio, video */
1101 libvlc_track_description_t *
1102 libvlc_get_track_description( libvlc_media_player_t *p_mi,
1103 const char *psz_variable,
1104 libvlc_exception_t *p_e )
1106 input_thread_t *p_input = libvlc_get_input_thread( p_mi, p_e );
1111 vlc_value_t val_list, text_list;
1112 var_Change( p_input, psz_variable, VLC_VAR_GETLIST, &val_list, &text_list);
1114 if( val_list.p_list->i_count <= 0 ) /* no tracks */
1117 libvlc_track_description_t *p_track_description, *p_actual, *p_previous;
1118 p_track_description = ( libvlc_track_description_t * )
1119 malloc( sizeof( libvlc_track_description_t ) );
1120 if ( !p_track_description )
1122 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list);
1123 vlc_object_release( p_input );
1124 libvlc_exception_raise( p_e, "no enough memory" );
1127 p_actual = p_track_description;
1129 for( int i = 0; i < val_list.p_list->i_count; i++ )
1133 p_actual = ( libvlc_track_description_t * )
1134 malloc( sizeof( libvlc_track_description_t ) );
1137 libvlc_track_description_release( p_track_description );
1138 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list);
1139 vlc_object_release( p_input );
1140 libvlc_exception_raise( p_e, "no enough memory" );
1144 p_actual->i_id = val_list.p_list->p_values[i].i_int;
1145 p_actual->psz_name = strdup( text_list.p_list->p_values[i].psz_string );
1146 p_actual->p_next = NULL;
1148 p_previous->p_next = p_actual;
1149 p_previous = p_actual;
1152 var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list);
1153 vlc_object_release( p_input );
1155 return p_track_description;
1158 void libvlc_track_description_release( libvlc_track_description_t *p_track_description )
1160 libvlc_track_description_t *p_actual, *p_before;
1161 p_actual = p_track_description;
1165 free( p_actual->psz_name );
1166 p_before = p_actual;
1167 p_actual = p_before->p_next;
1172 int libvlc_media_player_can_pause( libvlc_media_player_t *p_mi,
1173 libvlc_exception_t *p_e )
1175 input_thread_t *p_input_thread;
1178 p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
1179 if ( !p_input_thread )
1181 /* We do return the right value, no need to throw an exception */
1182 if( libvlc_exception_raised( p_e ) )
1183 libvlc_exception_clear( p_e );
1186 var_Get( p_input_thread, "can-pause", &val );
1187 vlc_object_release( p_input_thread );