media source: add missing refcount increment
[vlc.git] / src / playlist_legacy / control.c
blobb1e8448436a310f8c9e472a2ff52a50abad13c5b
1 /*****************************************************************************
2 * control.c : Handle control of the playlist & running through it
3 *****************************************************************************
4 * Copyright (C) 1999-2004 VLC authors and VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
7 * Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <vlc_common.h>
28 #include "vlc_playlist_legacy.h"
29 #include "playlist_internal.h"
30 #include <assert.h>
32 /*****************************************************************************
33 * Playlist control
34 *****************************************************************************/
36 void playlist_Lock( playlist_t *pl )
38 vlc_mutex_lock( &pl_priv(pl)->lock );
41 void playlist_Unlock( playlist_t *pl )
43 vlc_mutex_unlock( &pl_priv(pl)->lock );
46 bool playlist_Locked( const playlist_t *pl )
48 return vlc_mutex_marked( &pl_priv(pl)->lock );
51 static void playlist_vaControl( playlist_t *p_playlist, int i_query,
52 bool locked, va_list args )
54 PL_LOCK_IF( !locked );
56 if( pl_priv(p_playlist)->killed )
58 else
59 switch( i_query )
61 case PLAYLIST_STOP:
62 pl_priv(p_playlist)->request.b_request = true;
63 pl_priv(p_playlist)->request.p_item = NULL;
64 pl_priv(p_playlist)->request.p_node = NULL;
65 break;
67 // Node can be null, it will keep the same. Use with care ...
68 // Item null = take the first child of node
69 case PLAYLIST_VIEWPLAY:
71 playlist_item_t *p_node = va_arg( args, playlist_item_t * );
72 playlist_item_t *p_item = va_arg( args, playlist_item_t * );
74 assert( locked || (p_item == NULL && p_node == NULL) );
76 if ( p_node == NULL )
78 p_node = get_current_status_node( p_playlist );
79 assert( p_node );
81 pl_priv(p_playlist)->request.i_skip = 0;
82 pl_priv(p_playlist)->request.b_request = true;
83 pl_priv(p_playlist)->request.p_node = p_node;
84 pl_priv(p_playlist)->request.p_item = p_item;
85 if( p_item && var_GetBool( p_playlist, "random" ) )
86 pl_priv(p_playlist)->b_reset_currently_playing = true;
87 break;
90 case PLAYLIST_PLAY:
91 if( pl_priv(p_playlist)->p_input == NULL )
93 pl_priv(p_playlist)->request.b_request = true;
94 pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
95 pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
96 pl_priv(p_playlist)->request.i_skip = 0;
98 else
99 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
100 break;
102 case PLAYLIST_TOGGLE_PAUSE:
103 if( pl_priv(p_playlist)->p_input == NULL )
105 pl_priv(p_playlist)->request.b_request = true;
106 pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
107 pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
108 pl_priv(p_playlist)->request.i_skip = 0;
110 else
111 if( var_GetInteger( pl_priv(p_playlist)->p_input, "state" ) == PAUSE_S )
112 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
113 else
114 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
115 break;
117 case PLAYLIST_SKIP:
118 pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
119 pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
120 pl_priv(p_playlist)->request.i_skip = va_arg( args, int );
121 pl_priv(p_playlist)->request.b_request = true;
122 break;
124 case PLAYLIST_PAUSE:
125 if( pl_priv(p_playlist)->p_input == NULL )
126 break;
127 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
128 break;
130 case PLAYLIST_RESUME:
131 if( pl_priv(p_playlist)->p_input == NULL )
132 break;
133 var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
134 break;
136 vlc_cond_signal( &pl_priv(p_playlist)->signal );
137 PL_UNLOCK_IF( !locked );
140 void playlist_Control( playlist_t *p_playlist, int query, int locked, ... )
142 va_list args;
144 va_start( args, locked );
145 playlist_vaControl( p_playlist, query, (bool)locked, args );
146 va_end( args );