]> git.sesse.net Git - vlc/blob - src/playlist/control.c
fifo: fix FIFO bytes size computation
[vlc] / src / playlist / control.c
1 /*****************************************************************************
2  * control.c : Handle control of the playlist & running through it
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          ClĂ©ment Stenac <zorglub@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc_common.h>
29 #include "vlc_playlist.h"
30 #include "playlist_internal.h"
31 #include <assert.h>
32
33 /*****************************************************************************
34  * Playlist control
35  *****************************************************************************/
36
37 void playlist_Lock( playlist_t *pl )
38 {
39     vlc_mutex_lock( &pl_priv(pl)->lock );
40 }
41
42 void playlist_Unlock( playlist_t *pl )
43 {
44     vlc_mutex_unlock( &pl_priv(pl)->lock );
45 }
46
47 void playlist_AssertLocked( playlist_t *pl )
48 {
49     vlc_assert_locked( &pl_priv(pl)->lock );
50 }
51
52 static void playlist_vaControl( playlist_t *p_playlist, int i_query, va_list args )
53 {
54     PL_ASSERT_LOCKED;
55
56     if( i_query != PLAYLIST_STOP )
57         if( pl_priv(p_playlist)->killed || playlist_IsEmpty( p_playlist ) )
58             return;
59
60     switch( i_query )
61     {
62     case PLAYLIST_STOP:
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;
66         break;
67
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:
71     {
72         playlist_item_t *p_node = va_arg( args, playlist_item_t * );
73         playlist_item_t *p_item = va_arg( args, playlist_item_t * );
74
75         if ( p_node == NULL )
76         {
77             p_node = get_current_status_node( p_playlist );
78             assert( p_node );
79         }
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;
86         break;
87     }
88
89     case PLAYLIST_PLAY:
90         if( pl_priv(p_playlist)->p_input == NULL )
91         {
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;
96         }
97         else
98             var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
99         break;
100
101     case PLAYLIST_TOGGLE_PAUSE:
102         if( pl_priv(p_playlist)->p_input == NULL )
103         {
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;
108         }
109         else
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 );
112         else
113             var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
114         break;
115
116     case PLAYLIST_SKIP:
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;
121         break;
122
123     case PLAYLIST_PAUSE:
124         if( pl_priv(p_playlist)->p_input == NULL )
125             return;
126         var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
127         break;
128
129     case PLAYLIST_RESUME:
130         if( pl_priv(p_playlist)->p_input == NULL )
131             return;
132         var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
133         break;
134     }
135     vlc_cond_signal( &pl_priv(p_playlist)->signal );
136 }
137
138 void playlist_Control( playlist_t *p_playlist, int query, bool locked, ... )
139 {
140     va_list args;
141
142     PL_LOCK_IF( !locked );
143     va_start( args, locked );
144     playlist_vaControl( p_playlist, query, args );
145     va_end( args );
146     PL_UNLOCK_IF( !locked );
147 }