If http-use-IE-proxy is enable, use Internet Explorer entered HTTP proxy server confi...
[vlc.git] / src / playlist / control.c
blob1f10fb71d7dee518cb2638bd95c1d862c4decc81
1 /*****************************************************************************
2 * control.c : Handle control of the playlist & running through it
3 *****************************************************************************
4 * Copyright (C) 1999-2004 the VideoLAN team
5 * $Id$
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 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <vlc_common.h>
29 #include "vlc_playlist.h"
30 #include "playlist_internal.h"
31 #include <assert.h>
33 /*****************************************************************************
34 * Local prototypes
35 *****************************************************************************/
36 static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args );
38 /*****************************************************************************
39 * Playlist control
40 *****************************************************************************/
42 playlist_t *__pl_Hold( vlc_object_t *p_this )
44 playlist_t *pl;
46 barrier();
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 */ );
52 if (pl)
53 vlc_object_hold (pl);
54 return pl;
57 void __pl_Release( vlc_object_t *p_this )
59 playlist_t *pl = libvlc_priv (p_this->p_libvlc)->p_playlist;
60 assert( pl != NULL );
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 void playlist_Lock( playlist_t *pl )
71 vlc_mutex_lock( &pl_priv(pl)->lock );
74 void playlist_Unlock( playlist_t *pl )
76 vlc_mutex_unlock( &pl_priv(pl)->lock );
79 void playlist_AssertLocked( playlist_t *pl )
81 vlc_assert_locked( &pl_priv(pl)->lock );
84 int playlist_Control( playlist_t * p_playlist, int i_query,
85 bool b_locked, ... )
87 va_list args;
88 int i_result;
89 PL_LOCK_IF( !b_locked );
90 va_start( args, b_locked );
91 i_result = PlaylistVAControl( p_playlist, i_query, args );
92 va_end( args );
93 PL_UNLOCK_IF( !b_locked );
95 return i_result;
98 static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args )
100 playlist_item_t *p_item, *p_node;
102 PL_ASSERT_LOCKED;
104 if( !vlc_object_alive( p_playlist ) )
105 return VLC_EGENERIC;
107 if( playlist_IsEmpty( p_playlist ) && i_query != PLAYLIST_STOP )
108 return VLC_EGENERIC;
110 switch( i_query )
112 case PLAYLIST_STOP:
113 pl_priv(p_playlist)->request.i_status = PLAYLIST_STOPPED;
114 pl_priv(p_playlist)->request.b_request = true;
115 pl_priv(p_playlist)->request.p_item = NULL;
116 break;
118 // Node can be null, it will keep the same. Use with care ...
119 // Item null = take the first child of node
120 case PLAYLIST_VIEWPLAY:
121 p_node = (playlist_item_t *)va_arg( args, playlist_item_t * );
122 p_item = (playlist_item_t *)va_arg( args, playlist_item_t * );
123 if ( p_node == NULL )
125 p_node = get_current_status_node( p_playlist );
126 assert( p_node );
128 pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
129 pl_priv(p_playlist)->request.i_skip = 0;
130 pl_priv(p_playlist)->request.b_request = true;
131 pl_priv(p_playlist)->request.p_node = p_node;
132 pl_priv(p_playlist)->request.p_item = p_item;
133 if( p_item && var_GetBool( p_playlist, "random" ) )
134 pl_priv(p_playlist)->b_reset_currently_playing = true;
135 break;
137 case PLAYLIST_PLAY:
138 if( pl_priv(p_playlist)->p_input )
140 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
141 break;
143 else
145 pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
146 pl_priv(p_playlist)->request.b_request = true;
147 pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
148 pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
149 pl_priv(p_playlist)->request.i_skip = 0;
151 break;
153 case PLAYLIST_PAUSE:
154 if( !pl_priv(p_playlist)->p_input )
155 { /* FIXME: is this really useful without input? */
156 pl_priv(p_playlist)->status.i_status = PLAYLIST_PAUSED;
157 break;
160 if( var_GetInteger( pl_priv(p_playlist)->p_input, "state" ) == PAUSE_S )
162 pl_priv(p_playlist)->status.i_status = PLAYLIST_RUNNING;
163 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
165 else
167 pl_priv(p_playlist)->status.i_status = PLAYLIST_PAUSED;
168 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
170 break;
172 case PLAYLIST_SKIP:
173 pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
174 pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
175 pl_priv(p_playlist)->request.i_skip = (int) va_arg( args, int );
176 /* if already running, keep running */
177 if( pl_priv(p_playlist)->status.i_status != PLAYLIST_STOPPED )
178 pl_priv(p_playlist)->request.i_status = pl_priv(p_playlist)->status.i_status;
179 pl_priv(p_playlist)->request.b_request = true;
180 break;
182 default:
183 msg_Err( p_playlist, "unknown playlist query" );
184 return VLC_EBADVAR;
186 vlc_cond_signal( &pl_priv(p_playlist)->signal );
188 return VLC_SUCCESS;
191 /*****************************************************************************
192 * Preparse control
193 *****************************************************************************/
194 /** Enqueue an item for preparsing */
195 int playlist_PreparseEnqueue( playlist_t *p_playlist,
196 input_item_t *p_item, bool b_locked )
198 playlist_private_t *p_sys = pl_priv(p_playlist);
200 PL_LOCK_IF( !b_locked );
201 if( p_sys->p_preparser )
202 playlist_preparser_Push( p_sys->p_preparser, p_item );
203 PL_UNLOCK_IF( !b_locked );
205 return VLC_SUCCESS;
208 int playlist_AskForArtEnqueue( playlist_t *p_playlist,
209 input_item_t *p_item, bool b_locked )
211 playlist_private_t *p_sys = pl_priv(p_playlist);
213 PL_LOCK_IF( !b_locked );
214 if( p_sys->p_fetcher )
215 playlist_fetcher_Push( p_sys->p_fetcher, p_item );
216 PL_UNLOCK_IF( !b_locked );
218 return VLC_SUCCESS;