control.c 5.06 KB
Newer Older
1
/*****************************************************************************
zorglub's avatar
zorglub committed
2
 * control.c : Handle control of the playlist & running through it
3
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
4
 * Copyright (C) 1999-2004 VLC authors and VideoLAN
Jean-Paul Saman's avatar
Jean-Paul Saman committed
5
 * $Id$
6
7
8
9
 *
 * Authors: Samuel Hocevar <sam@zoy.org>
 *          Clément Stenac <zorglub@videolan.org>
 *
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
10
11
12
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
13
14
15
16
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
17
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
 *
Jean-Baptiste Kempf's avatar
LGPL    
Jean-Baptiste Kempf committed
20
21
22
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23
 *****************************************************************************/
24
25
26
27
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

28
#include <vlc_common.h>
29
#include "vlc_playlist.h"
30
#include "playlist_internal.h"
31
#include <assert.h>
32
33
34
35
36

/*****************************************************************************
 * Playlist control
 *****************************************************************************/

37
38
void playlist_Lock( playlist_t *pl )
{
39
    vlc_mutex_lock( &pl_priv(pl)->lock );
40
41
42
43
}

void playlist_Unlock( playlist_t *pl )
{
44
    vlc_mutex_unlock( &pl_priv(pl)->lock );
45
46
47
48
}

void playlist_AssertLocked( playlist_t *pl )
{
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
{
Pierre d'Herbemont's avatar
Pierre d'Herbemont committed
54
55
    PL_ASSERT_LOCKED;

56
57
    if( pl_priv(p_playlist)->killed )
        return;
58
59
60
61

    switch( i_query )
    {
    case PLAYLIST_STOP:
62
63
        pl_priv(p_playlist)->request.b_request = true;
        pl_priv(p_playlist)->request.p_item = NULL;
64
        pl_priv(p_playlist)->request.p_node = NULL;
65
66
        break;

67
68
    // Node can be null, it will keep the same. Use with care ...
    // Item null = take the first child of node
69
    case PLAYLIST_VIEWPLAY:
70
71
72
73
    {
        playlist_item_t *p_node = va_arg( args, playlist_item_t * );
        playlist_item_t *p_item = va_arg( args, playlist_item_t * );

74
75
        if ( p_node == NULL )
        {
76
            p_node = get_current_status_node( p_playlist );
77
            assert( p_node );
78
        }
79
80
81
82
        pl_priv(p_playlist)->request.i_skip = 0;
        pl_priv(p_playlist)->request.b_request = true;
        pl_priv(p_playlist)->request.p_node = p_node;
        pl_priv(p_playlist)->request.p_item = p_item;
zorglub's avatar
zorglub committed
83
        if( p_item && var_GetBool( p_playlist, "random" ) )
84
            pl_priv(p_playlist)->b_reset_currently_playing = true;
85
        break;
86
    }
87
88

    case PLAYLIST_PLAY:
89
        if( pl_priv(p_playlist)->p_input == NULL )
90
        {
91
92
93
94
            pl_priv(p_playlist)->request.b_request = true;
            pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
            pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
            pl_priv(p_playlist)->request.i_skip = 0;
95
        }
96
97
        else
            var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
98
99
        break;

100
    case PLAYLIST_TOGGLE_PAUSE:
101
102
103
104
105
106
        if( pl_priv(p_playlist)->p_input == NULL )
        {
            pl_priv(p_playlist)->request.b_request = true;
            pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
            pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
            pl_priv(p_playlist)->request.i_skip = 0;
107
        }
108
        else
109
110
        if( var_GetInteger( pl_priv(p_playlist)->p_input, "state" ) == PAUSE_S )
            var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
111
        else
112
            var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
113
114
115
        break;

    case PLAYLIST_SKIP:
116
117
118
119
        pl_priv(p_playlist)->request.p_node = get_current_status_node( p_playlist );
        pl_priv(p_playlist)->request.p_item = get_current_status_item( p_playlist );
        pl_priv(p_playlist)->request.i_skip = (int) va_arg( args, int );
        pl_priv(p_playlist)->request.b_request = true;
120
        break;
121
122
123
124
125
126
127
128
129
130
131
132

    case PLAYLIST_PAUSE:
        if( pl_priv(p_playlist)->p_input == NULL )
            return;
        var_SetInteger( pl_priv(p_playlist)->p_input, "state", PAUSE_S );
        break;

    case PLAYLIST_RESUME:
        if( pl_priv(p_playlist)->p_input == NULL )
            return;
        var_SetInteger( pl_priv(p_playlist)->p_input, "state", PLAYING_S );
        break;
133
    }
134
    vlc_cond_signal( &pl_priv(p_playlist)->signal );
135
}
136

137
138
139
140
141
142
143
144
145
void playlist_Control( playlist_t *p_playlist, int query, bool locked, ... )
{
    va_list args;

    PL_LOCK_IF( !locked );
    va_start( args, locked );
    playlist_vaControl( p_playlist, query, args );
    va_end( args );
    PL_UNLOCK_IF( !locked );
146
}