1 /*****************************************************************************
2 * control.c : Handle control of the playlist & running through it
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VLC authors and VideoLAN
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 it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * 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 *****************************************************************************/
37 void playlist_Lock( playlist_t *pl )
39 vlc_mutex_lock( &pl_priv(pl)->lock );
42 void playlist_Unlock( playlist_t *pl )
44 vlc_mutex_unlock( &pl_priv(pl)->lock );
47 void playlist_AssertLocked( playlist_t *pl )
49 vlc_assert_locked( &pl_priv(pl)->lock );
52 static void playlist_vaControl( playlist_t *p_playlist, int i_query, va_list args )
56 if( i_query != PLAYLIST_STOP )
57 if( pl_priv(p_playlist)->killed || playlist_IsEmpty( p_playlist ) )
63 pl_priv(p_playlist)->request.b_request = true;
64 pl_priv(p_playlist)->request.p_item = NULL;
65 pl_priv(p_playlist)->request.p_node = NULL;
68 // Node can be null, it will keep the same. Use with care ...
69 // Item null = take the first child of node
70 case PLAYLIST_VIEWPLAY:
72 playlist_item_t *p_node = va_arg( args, playlist_item_t * );
73 playlist_item_t *p_item = va_arg( args, playlist_item_t * );
77 p_node = get_current_status_node( p_playlist );
80 pl_priv(p_playlist)->request.i_skip = 0;
81 pl_priv(p_playlist)->request.b_request = true;
82 pl_priv(p_playlist)->request.p_node = p_node;
83 pl_priv(p_playlist)->request.p_item = p_item;
84 if( p_item && var_GetBool( p_playlist, "random" ) )
85 pl_priv(p_playlist)->b_reset_currently_playing = true;
90 if( pl_priv(p_playlist)->p_input == NULL )
92 pl_priv(p_playlist)->request.b_request = true;
93 pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
94 pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
95 pl_priv(p_playlist)->request.i_skip = 0;
98 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
101 case PLAYLIST_TOGGLE_PAUSE:
102 if( pl_priv(p_playlist)->p_input == NULL )
104 pl_priv(p_playlist)->request.b_request = true;
105 pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
106 pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
107 pl_priv(p_playlist)->request.i_skip = 0;
110 if( var_GetInteger( pl_priv(p_playlist)->p_input, "state" ) == PAUSE_S )
111 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
113 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
117 pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
118 pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
119 pl_priv(p_playlist)->request.i_skip = (int) va_arg( args, int );
120 pl_priv(p_playlist)->request.b_request = true;
124 if( pl_priv(p_playlist)->p_input == NULL )
126 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
129 case PLAYLIST_RESUME:
130 if( pl_priv(p_playlist)->p_input == NULL )
132 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
135 vlc_cond_signal( &pl_priv(p_playlist)->signal );
138 void playlist_Control( playlist_t *p_playlist, int query, bool locked, ... )
142 PL_LOCK_IF( !locked );
143 va_start( args, locked );
144 playlist_vaControl( p_playlist, query, args );
146 PL_UNLOCK_IF( !locked );