1 /*****************************************************************************
2 * playlist.c: libvlc new API playlist handling 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_playlist.h>
31 #include "../playlist/playlist_internal.h"
33 #define PL p_instance->p_libvlc_int->p_playlist
35 static inline int playlist_was_locked( libvlc_instance_t
*p_instance
)
38 vlc_mutex_lock( &p_instance
->instance_lock
);
39 was_locked
= p_instance
->b_playlist_locked
;
40 vlc_mutex_unlock( &p_instance
->instance_lock
);
44 static inline void playlist_mark_locked( libvlc_instance_t
*p_instance
,
47 vlc_mutex_lock( &p_instance
->instance_lock
);
48 p_instance
->b_playlist_locked
= locked
;
49 vlc_mutex_unlock( &p_instance
->instance_lock
);
52 void libvlc_playlist_loop( libvlc_instance_t
*p_instance
, int loop
,
53 libvlc_exception_t
*p_e
)
58 var_SetBool( PL
, "loop", loop
);
61 void libvlc_playlist_play( libvlc_instance_t
*p_instance
, int i_id
,
62 int i_options
, char **ppsz_options
,
63 libvlc_exception_t
*p_e
)
69 ///\todo Handle additionnal options
71 if( PL
->items
.i_size
== 0 ) RAISEVOID( "Empty playlist" );
74 playlist_item_t
*p_item
;
75 if (! playlist_was_locked( p_instance
) )
77 playlist_mark_locked( p_instance
, 1 );
78 vlc_mutex_lock( &PL
->object_lock
);
82 p_item
= playlist_ItemGetByInputId( PL
, i_id
,
88 vlc_mutex_unlock( &PL
->object_lock
);
89 playlist_mark_locked( p_instance
, 0 );
91 RAISEVOID( "Unable to find item" );
94 playlist_Control( PL
, PLAYLIST_VIEWPLAY
, true,
95 PL
->status
.p_node
, p_item
);
98 vlc_mutex_unlock( &PL
->object_lock
);
99 playlist_mark_locked( p_instance
, 0 );
104 playlist_Control( PL
, PLAYLIST_PLAY
,
105 playlist_was_locked( p_instance
) );
109 void libvlc_playlist_pause( libvlc_instance_t
*p_instance
,
110 libvlc_exception_t
*p_e
)
113 if( playlist_Control( PL
, PLAYLIST_PAUSE
,
114 playlist_was_locked( p_instance
) ) != VLC_SUCCESS
)
115 RAISEVOID( "Empty playlist" );
119 void libvlc_playlist_stop( libvlc_instance_t
*p_instance
,
120 libvlc_exception_t
*p_e
)
123 if( playlist_Control( PL
, PLAYLIST_STOP
,
124 playlist_was_locked( p_instance
) ) != VLC_SUCCESS
)
125 RAISEVOID( "Empty playlist" );
128 void libvlc_playlist_clear( libvlc_instance_t
*p_instance
,
129 libvlc_exception_t
*p_e
)
134 playlist_Clear( PL
, playlist_was_locked( p_instance
) );
137 void libvlc_playlist_next( libvlc_instance_t
*p_instance
,
138 libvlc_exception_t
*p_e
)
141 if( playlist_Control( PL
, PLAYLIST_SKIP
, playlist_was_locked( p_instance
),
143 RAISEVOID( "Empty playlist" );
146 void libvlc_playlist_prev( libvlc_instance_t
*p_instance
,
147 libvlc_exception_t
*p_e
)
149 if( playlist_Control( PL
, PLAYLIST_SKIP
, playlist_was_locked( p_instance
),
150 -1 ) != VLC_SUCCESS
)
151 RAISEVOID( "Empty playlist" );
154 int libvlc_playlist_add( libvlc_instance_t
*p_instance
, const char *psz_uri
,
155 const char *psz_name
, libvlc_exception_t
*p_e
)
157 return libvlc_playlist_add_extended( p_instance
, psz_uri
, psz_name
,
161 int libvlc_playlist_add_extended( libvlc_instance_t
*p_instance
,
162 const char *psz_uri
, const char *psz_name
,
163 int i_options
, const char **ppsz_options
,
164 libvlc_exception_t
*p_e
)
167 if( playlist_was_locked( p_instance
) )
169 libvlc_exception_raise( p_e
, "You must unlock playlist before "
170 "calling libvlc_playlist_add" );
173 return playlist_AddExt( PL
, psz_uri
, psz_name
,
174 PLAYLIST_INSERT
, PLAYLIST_END
, -1, ppsz_options
,
175 i_options
, 1, false );
179 int libvlc_playlist_delete_item( libvlc_instance_t
*p_instance
, int i_id
,
180 libvlc_exception_t
*p_e
)
184 if( playlist_DeleteFromInput( PL
, i_id
,
185 playlist_was_locked( p_instance
) ) )
187 libvlc_exception_raise( p_e
, "deletion failed" );
193 int libvlc_playlist_isplaying( libvlc_instance_t
*p_instance
,
194 libvlc_exception_t
*p_e
)
199 return playlist_IsPlaying( PL
);
202 int libvlc_playlist_items_count( libvlc_instance_t
*p_instance
,
203 libvlc_exception_t
*p_e
)
208 return playlist_CurrentSize( PL
);
211 void libvlc_playlist_lock( libvlc_instance_t
*p_instance
)
214 vlc_mutex_lock( &PL
->object_lock
);
215 p_instance
->b_playlist_locked
= 1;
218 void libvlc_playlist_unlock( libvlc_instance_t
*p_instance
)
221 p_instance
->b_playlist_locked
= 0;
222 vlc_mutex_unlock( &PL
->object_lock
);
225 libvlc_media_player_t
* libvlc_playlist_get_media_player(
226 libvlc_instance_t
*p_instance
,
227 libvlc_exception_t
*p_e
)
229 libvlc_media_player_t
*p_mi
;
232 vlc_mutex_lock( &PL
->object_lock
);
235 p_mi
= libvlc_media_player_new_from_input_thread(
236 p_instance
, PL
->p_input
, p_e
);
240 /* no active input */
242 libvlc_exception_raise( p_e
, "No active input" );
244 vlc_mutex_unlock( &PL
->object_lock
);