]> git.sesse.net Git - vlc/blob - src/playlist/control.c
input: remove subpicture decoder buffering.
[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  * Local prototypes
35  *****************************************************************************/
36 static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args );
37
38 /*****************************************************************************
39  * Playlist control
40  *****************************************************************************/
41
42 void playlist_Lock( playlist_t *pl )
43 {
44     vlc_mutex_lock( &pl_priv(pl)->lock );
45 }
46
47 void playlist_Unlock( playlist_t *pl )
48 {
49     vlc_mutex_unlock( &pl_priv(pl)->lock );
50 }
51
52 void playlist_AssertLocked( playlist_t *pl )
53 {
54     vlc_assert_locked( &pl_priv(pl)->lock );
55 }
56
57 int playlist_Control( playlist_t * p_playlist, int i_query,
58                       bool b_locked, ... )
59 {
60     va_list args;
61     int i_result;
62     PL_LOCK_IF( !b_locked );
63     va_start( args, b_locked );
64     i_result = PlaylistVAControl( p_playlist, i_query, args );
65     va_end( args );
66     PL_UNLOCK_IF( !b_locked );
67
68     return i_result;
69 }
70
71 static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args )
72 {
73     playlist_item_t *p_item, *p_node;
74
75     PL_ASSERT_LOCKED;
76
77     if( i_query != PLAYLIST_STOP )
78         if( pl_priv(p_playlist)->killed || playlist_IsEmpty( p_playlist ) )
79             return VLC_EGENERIC;
80
81     switch( i_query )
82     {
83     case PLAYLIST_STOP:
84         pl_priv(p_playlist)->request.i_status = PLAYLIST_STOPPED;
85         pl_priv(p_playlist)->request.b_request = true;
86         pl_priv(p_playlist)->request.p_item = NULL;
87         break;
88
89     // Node can be null, it will keep the same. Use with care ...
90     // Item null = take the first child of node
91     case PLAYLIST_VIEWPLAY:
92         p_node = (playlist_item_t *)va_arg( args, playlist_item_t * );
93         p_item = (playlist_item_t *)va_arg( args, playlist_item_t * );
94         if ( p_node == NULL )
95         {
96             p_node = get_current_status_node( p_playlist );
97             assert( p_node );
98         }
99         pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
100         pl_priv(p_playlist)->request.i_skip = 0;
101         pl_priv(p_playlist)->request.b_request = true;
102         pl_priv(p_playlist)->request.p_node = p_node;
103         pl_priv(p_playlist)->request.p_item = p_item;
104         if( p_item && var_GetBool( p_playlist, "random" ) )
105             pl_priv(p_playlist)->b_reset_currently_playing = true;
106         break;
107
108     case PLAYLIST_PLAY:
109         if( pl_priv(p_playlist)->p_input )
110         {
111             pl_priv(p_playlist)->status.i_status = PLAYLIST_RUNNING;
112             var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
113             break;
114         }
115         else
116         {
117             pl_priv(p_playlist)->request.i_status = PLAYLIST_RUNNING;
118             pl_priv(p_playlist)->request.b_request = true;
119             pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
120             pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
121             pl_priv(p_playlist)->request.i_skip = 0;
122         }
123         break;
124
125     case PLAYLIST_PAUSE:
126         if( !pl_priv(p_playlist)->p_input )
127         {   /* FIXME: is this really useful without input? */
128             pl_priv(p_playlist)->status.i_status = PLAYLIST_PAUSED;
129             /* return without notifying the playlist thread as there is nothing to do */
130             return VLC_SUCCESS;
131         }
132
133         if( var_GetInteger( pl_priv(p_playlist)->p_input, "state" ) == PAUSE_S )
134         {
135             pl_priv(p_playlist)->status.i_status = PLAYLIST_RUNNING;
136             var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
137         }
138         else
139         {
140             pl_priv(p_playlist)->status.i_status = PLAYLIST_PAUSED;
141             var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
142         }
143         break;
144
145     case PLAYLIST_SKIP:
146         pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
147         pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
148         pl_priv(p_playlist)->request.i_skip = (int) va_arg( args, int );
149         /* if already running, keep running */
150         if( pl_priv(p_playlist)->status.i_status != PLAYLIST_STOPPED )
151             pl_priv(p_playlist)->request.i_status = pl_priv(p_playlist)->status.i_status;
152         pl_priv(p_playlist)->request.b_request = true;
153         break;
154
155     default:
156         msg_Err( p_playlist, "unknown playlist query" );
157         return VLC_EBADVAR;
158     }
159     vlc_cond_signal( &pl_priv(p_playlist)->signal );
160
161     return VLC_SUCCESS;
162 }
163
164 /*****************************************************************************
165  * Preparse control
166  *****************************************************************************/
167 /** Enqueue an item for preparsing */
168 int playlist_PreparseEnqueue( playlist_t *p_playlist, input_item_t *p_item )
169 {
170     playlist_private_t *p_sys = pl_priv(p_playlist);
171
172     if( unlikely(p_sys->p_preparser == NULL) )
173         return VLC_ENOMEM;
174     playlist_preparser_Push( p_sys->p_preparser, p_item );
175     return VLC_SUCCESS;
176 }
177
178 int playlist_AskForArtEnqueue( playlist_t *p_playlist, input_item_t *p_item )
179 {
180     playlist_private_t *p_sys = pl_priv(p_playlist);
181
182     if( unlikely(p_sys->p_fetcher == NULL) )
183         return VLC_ENOMEM;
184     playlist_fetcher_Push( p_sys->p_fetcher, p_item );
185     return VLC_SUCCESS;
186 }
187