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
,
53 bool locked
, va_list args
)
55 PL_LOCK_IF( !locked
);
57 if( pl_priv(p_playlist
)->killed
)
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
* );
75 assert( locked
|| (p_item
== NULL
&& p_node
== NULL
) );
79 p_node
= get_current_status_node( p_playlist
);
82 pl_priv(p_playlist
)->request
.i_skip
= 0;
83 pl_priv(p_playlist
)->request
.b_request
= true;
84 pl_priv(p_playlist
)->request
.p_node
= p_node
;
85 pl_priv(p_playlist
)->request
.p_item
= p_item
;
86 if( p_item
&& var_GetBool( p_playlist
, "random" ) )
87 pl_priv(p_playlist
)->b_reset_currently_playing
= true;
92 if( pl_priv(p_playlist
)->p_input
== NULL
)
94 pl_priv(p_playlist
)->request
.b_request
= true;
95 pl_priv(p_playlist
)->request
.p_node
= get_current_status_node( p_playlist
);
96 pl_priv(p_playlist
)->request
.p_item
= get_current_status_item( p_playlist
);
97 pl_priv(p_playlist
)->request
.i_skip
= 0;
100 var_SetInteger( pl_priv(p_playlist
)->p_input
, "state", PLAYING_S
);
103 case PLAYLIST_TOGGLE_PAUSE
:
104 if( pl_priv(p_playlist
)->p_input
== NULL
)
106 pl_priv(p_playlist
)->request
.b_request
= true;
107 pl_priv(p_playlist
)->request
.p_node
= get_current_status_node( p_playlist
);
108 pl_priv(p_playlist
)->request
.p_item
= get_current_status_item( p_playlist
);
109 pl_priv(p_playlist
)->request
.i_skip
= 0;
112 if( var_GetInteger( pl_priv(p_playlist
)->p_input
, "state" ) == PAUSE_S
)
113 var_SetInteger( pl_priv(p_playlist
)->p_input
, "state", PLAYING_S
);
115 var_SetInteger( pl_priv(p_playlist
)->p_input
, "state", PAUSE_S
);
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
= (int) va_arg( args
, int );
122 pl_priv(p_playlist
)->request
.b_request
= true;
126 if( pl_priv(p_playlist
)->p_input
== NULL
)
128 var_SetInteger( pl_priv(p_playlist
)->p_input
, "state", PAUSE_S
);
131 case PLAYLIST_RESUME
:
132 if( pl_priv(p_playlist
)->p_input
== NULL
)
134 var_SetInteger( pl_priv(p_playlist
)->p_input
, "state", PLAYING_S
);
137 vlc_cond_signal( &pl_priv(p_playlist
)->signal
);
138 PL_UNLOCK_IF( !locked
);
141 void playlist_Control( playlist_t
*p_playlist
, int query
, int locked
, ... )
145 va_start( args
, locked
);
146 playlist_vaControl( p_playlist
, query
, (bool)locked
, args
);