1 /*****************************************************************************
2 * control.c : Handle control of the playlist & running through it
3 *****************************************************************************
4 * Copyright (C) 1999-2004 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Clément Stenac <zorglub@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
28 #include <vlc_common.h>
29 #include "vlc_playlist.h"
30 #include "playlist_internal.h"
33 /*****************************************************************************
35 *****************************************************************************/
36 static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args );
38 /*****************************************************************************
40 *****************************************************************************/
42 playlist_t *__pl_Hold( vlc_object_t *p_this )
47 pl = libvlc_priv (p_this->p_libvlc)->p_playlist;
49 assert( VLC_OBJECT(pl) != p_this /* This does not make sense to hold the playlist
50 using pl_Hold. use vlc_object_hold in this case */ );
57 void __pl_Release( vlc_object_t *p_this )
59 playlist_t *pl = libvlc_priv (p_this->p_libvlc)->p_playlist;
62 /* The rule is that pl_Release() should act on
63 the same object than pl_Hold() */
64 assert( VLC_OBJECT(pl) != p_this);
66 vlc_object_release( pl );
69 int playlist_Control( playlist_t * p_playlist, int i_query,
74 PL_LOCK_IF( !b_locked );
75 va_start( args, b_locked );
76 i_result = PlaylistVAControl( p_playlist, i_query, args );
78 PL_UNLOCK_IF( !b_locked );
83 static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args )
85 playlist_item_t *p_item, *p_node;
90 if( !vlc_object_alive( p_playlist ) )
93 if( playlist_IsEmpty( p_playlist ) )
99 pl_priv(p_playlist)->request.i_status = PLAYLIST_STOPPED;
100 pl_priv(p_playlist)->request.b_request = true;
101 pl_priv(p_playlist)->request.p_item = NULL;
104 // Node can be null, it will keep the same. Use with care ...
105 // Item null = take the first child of node
106 case PLAYLIST_VIEWPLAY:
107 p_node = (playlist_item_t *)va_arg( args, playlist_item_t * );
108 p_item = (playlist_item_t *)va_arg( args, playlist_item_t * );
109 if ( p_node == NULL )
111 p_node = get_current_status_node( p_playlist );
114 pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
115 pl_priv(p_playlist)->request.i_skip = 0;
116 pl_priv(p_playlist)->request.b_request = true;
117 pl_priv(p_playlist)->request.p_node = p_node;
118 pl_priv(p_playlist)->request.p_item = p_item;
119 if( p_item && var_GetBool( p_playlist, "random" ) )
120 pl_priv(p_playlist)->b_reset_currently_playing = true;
124 if( pl_priv(p_playlist)->p_input )
126 val.i_int = PLAYING_S;
127 var_Set( pl_priv(p_playlist)->p_input, "state", val );
132 pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
133 pl_priv(p_playlist)->request.b_request = true;
134 pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
135 pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
136 pl_priv(p_playlist)->request.i_skip = 0;
142 if( pl_priv(p_playlist)->p_input )
143 var_Get( pl_priv(p_playlist)->p_input, "state", &val );
145 if( val.i_int == PAUSE_S )
147 pl_priv(p_playlist)->status.i_status = PLAYLIST_RUNNING;
148 if( pl_priv(p_playlist)->p_input )
150 val.i_int = PLAYING_S;
151 var_Set( pl_priv(p_playlist)->p_input, "state", val );
156 pl_priv(p_playlist)->status.i_status = PLAYLIST_PAUSED;
157 if( pl_priv(p_playlist)->p_input )
160 var_Set( pl_priv(p_playlist)->p_input, "state", val );
166 pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
167 pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
168 pl_priv(p_playlist)->request.i_skip = (int) va_arg( args, int );
169 /* if already running, keep running */
170 if( pl_priv(p_playlist)->status.i_status != PLAYLIST_STOPPED )
171 pl_priv(p_playlist)->request.i_status = pl_priv(p_playlist)->status.i_status;
172 pl_priv(p_playlist)->request.b_request = true;
176 msg_Err( p_playlist, "unknown playlist query" );
179 vlc_object_signal_unlocked( p_playlist );
184 /*****************************************************************************
186 *****************************************************************************/
187 /** Enqueue an item for preparsing */
188 int playlist_PreparseEnqueue( playlist_t *p_playlist,
189 input_item_t *p_item, bool b_locked )
191 playlist_private_t *p_sys = pl_priv(p_playlist);
193 PL_LOCK_IF( !b_locked );
194 if( p_sys->p_preparser )
195 playlist_preparser_Push( p_sys->p_preparser, p_item );
196 PL_UNLOCK_IF( !b_locked );
201 int playlist_AskForArtEnqueue( playlist_t *p_playlist,
202 input_item_t *p_item, bool b_locked )
204 playlist_private_t *p_sys = pl_priv(p_playlist);
206 PL_LOCK_IF( !b_locked );
207 if( p_sys->p_fetcher )
208 playlist_fetcher_Push( p_sys->p_fetcher, p_item );
209 PL_UNLOCK_IF( !b_locked );