vlm.c 7.49 KB
Newer Older
Clément Stenac's avatar
Clément Stenac committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*****************************************************************************
 * vlm.c: libvlc new API VLM handling functions
 *****************************************************************************
 * Copyright (C) 2005 the VideoLAN team
 * $Id: playlist.c 14265 2006-02-12 17:31:39Z zorglub $
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (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
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU 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.
 *****************************************************************************/

#include <libvlc_internal.h>
#include <vlc/libvlc.h>

#include <vlc/vlc.h>
#include <vlc_input.h>
#include <vlc_vlm.h>

void InitVLM( libvlc_instance_t *p_instance )
{
Clément Stenac's avatar
Clément Stenac committed
33
#ifdef ENABLE_VLM
Clément Stenac's avatar
Clément Stenac committed
34 35
    if( p_instance->p_vlm ) return;
    p_instance->p_vlm = vlm_New( p_instance->p_vlc );
Clément Stenac's avatar
Clément Stenac committed
36 37 38
#else
    p_instance->p_vlm = NULL;
#endif
Clément Stenac's avatar
Clément Stenac committed
39 40 41 42
}

#define CHECK_VLM { if( !p_instance->p_vlm ) InitVLM( p_instance ); \
                    if( !p_instance->p_vlm ) {\
Clément Stenac's avatar
Clément Stenac committed
43 44
                  libvlc_exception_raise( p_exception, \
                  "Unable to create VLM. It might be disabled." ); return; } }
Clément Stenac's avatar
Clément Stenac committed
45

Clément Stenac's avatar
Clément Stenac committed
46 47 48 49 50 51 52
#define GET_MEDIA { p_media = vlm_MediaSearch( p_instance->p_vlm, psz_name );\
                   if( !p_media ) \
                   { \
                        libvlc_exception_raise( p_exception, \
                                                "Media %s does not exist", \
                                                psz_name ); return; } }

Clément Stenac's avatar
Clément Stenac committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
void libvlc_vlm_add_broadcast( libvlc_instance_t *p_instance, char *psz_name,
                               char *psz_input, char *psz_output,
                               int i_options, char **ppsz_options,
                               int b_enabled, int b_loop,
                               libvlc_exception_t *p_exception )
{
    vlm_media_t *p_media;
    CHECK_VLM;

    p_media = vlm_MediaNew( p_instance->p_vlm, psz_name, BROADCAST_TYPE );
    if( !p_media )
    {
        libvlc_exception_raise( p_exception, "Media %s creation failed",
                                psz_name );
        return;
    }
    libvlc_vlm_change_media( p_instance, psz_name, psz_input, psz_output,
                             i_options, ppsz_options, b_enabled, b_loop,
                             p_exception );

}

void libvlc_vlm_del_media( libvlc_instance_t *p_instance, char *psz_name,
                           libvlc_exception_t *p_exception )
{
    char *psz_message;
    vlm_message_t *answer;
    CHECK_VLM;
Clément Stenac's avatar
Clément Stenac committed
81
#ifdef ENABLE_VLM
Clément Stenac's avatar
Clément Stenac committed
82 83 84 85 86 87 88 89
    asprintf( &psz_message, "del %s", psz_name );
    vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
    if( answer->psz_value )
    {
        libvlc_exception_raise( p_exception, "Unable to delete %s",
                                psz_name );
    }
    free( psz_message);
Clément Stenac's avatar
Clément Stenac committed
90
#endif
Clément Stenac's avatar
Clément Stenac committed
91 92 93 94 95 96 97
}

void libvlc_vlm_set_enabled( libvlc_instance_t *p_instance, char *psz_name,
                             int b_enabled, libvlc_exception_t *p_exception )
{
    vlm_media_t *p_media;
    CHECK_VLM;
Clément Stenac's avatar
Clément Stenac committed
98
#ifdef ENABLE_VLM
Clément Stenac's avatar
Clément Stenac committed
99
    GET_MEDIA;
Clément Stenac's avatar
Clément Stenac committed
100 101
    if( b_enabled != 0 ) b_enabled = 1;
    p_media->b_enabled = b_enabled;
Clément Stenac's avatar
Clément Stenac committed
102
#endif
Clément Stenac's avatar
Clément Stenac committed
103 104
}

Clément Stenac's avatar
Clément Stenac committed
105 106 107 108 109
void libvlc_vlm_set_loop( libvlc_instance_t *p_instance, char *psz_name,
                          int b_loop, libvlc_exception_t *p_exception )
{
    vlm_media_t *p_media;
    CHECK_VLM;
Clément Stenac's avatar
Clément Stenac committed
110
#ifdef ENABLE_VLM
Clément Stenac's avatar
Clément Stenac committed
111 112 113
    GET_MEDIA;
    if( b_loop != 0 ) b_loop = 1;
    p_media->b_loop = b_loop;
Clément Stenac's avatar
Clément Stenac committed
114
#endif
Clément Stenac's avatar
Clément Stenac committed
115 116 117 118 119 120 121 122
}

void libvlc_vlm_set_output( libvlc_instance_t *p_instance, char *psz_name,
                            char *psz_output,  libvlc_exception_t *p_exception )
{
    vlm_media_t *p_media;
    int i_ret;
    CHECK_VLM;
Clément Stenac's avatar
Clément Stenac committed
123
#ifdef ENABLE_VLM
Clément Stenac's avatar
Clément Stenac committed
124 125 126 127 128
    GET_MEDIA;

    vlc_mutex_lock( &p_instance->p_vlm->lock );
    i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
    if( i_ret )
Clément Stenac's avatar
Clément Stenac committed
129 130 131 132
    {
         libvlc_exception_raise( p_exception, "Unable to set output" );
         vlc_mutex_unlock( &p_instance->p_vlm->lock );return;
    }
Clément Stenac's avatar
Clément Stenac committed
133
    vlc_mutex_unlock( &p_instance->p_vlm->lock );
Clément Stenac's avatar
Clément Stenac committed
134
#endif
Clément Stenac's avatar
Clément Stenac committed
135 136 137 138 139 140 141 142
}

void libvlc_vlm_set_input( libvlc_instance_t *p_instance, char *psz_name,
                           char *psz_input,  libvlc_exception_t *p_exception )
{
    vlm_media_t *p_media;
    int i_ret;
    CHECK_VLM;
Clément Stenac's avatar
Clément Stenac committed
143
#ifdef ENABLE_VLM
Clément Stenac's avatar
Clément Stenac committed
144
    vlc_mutex_lock( &p_instance->p_vlm->lock );
Clément Stenac's avatar
Clément Stenac committed
145
    GET_MEDIA;
Clément Stenac's avatar
Clément Stenac committed
146

Clément Stenac's avatar
Clément Stenac committed
147
    i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "inputdel", "all" );
Clément Stenac's avatar
Clément Stenac committed
148
    if( i_ret )
Clément Stenac's avatar
Clément Stenac committed
149 150 151 152
    {
         libvlc_exception_raise( p_exception, "Unable to change input" );
         vlc_mutex_unlock( &p_instance->p_vlm->lock );return;
    }
Clément Stenac's avatar
Clément Stenac committed
153
    i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
Clément Stenac's avatar
Clément Stenac committed
154
    if( i_ret )
Clément Stenac's avatar
Clément Stenac committed
155 156 157 158
    {
        libvlc_exception_raise( p_exception, "Unable to change input" );
        vlc_mutex_unlock( &p_instance->p_vlm->lock );return;
    }
Clément Stenac's avatar
Clément Stenac committed
159
    vlc_mutex_unlock( &p_instance->p_vlm->lock );
Clément Stenac's avatar
Clément Stenac committed
160
#endif
Clément Stenac's avatar
Clément Stenac committed
161 162 163 164 165 166 167 168
}

void libvlc_vlm_add_input( libvlc_instance_t *p_instance, char *psz_name,
                           char *psz_input,  libvlc_exception_t *p_exception )
{
    vlm_media_t *p_media;
    int i_ret;
    CHECK_VLM;
Clément Stenac's avatar
Clément Stenac committed
169
#ifdef ENABLE_VLM
Clément Stenac's avatar
Clément Stenac committed
170
    vlc_mutex_lock( &p_instance->p_vlm->lock );
Clément Stenac's avatar
Clément Stenac committed
171
    GET_MEDIA;
Clément Stenac's avatar
Clément Stenac committed
172

Clément Stenac's avatar
Clément Stenac committed
173
    i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
Clément Stenac's avatar
Clément Stenac committed
174
    if( i_ret )
Clément Stenac's avatar
Clément Stenac committed
175 176 177 178
    {
         libvlc_exception_raise( p_exception, "Unable to change input" );
         vlc_mutex_unlock( &p_instance->p_vlm->lock ); return;
    }
Clément Stenac's avatar
Clément Stenac committed
179 180

    vlc_mutex_unlock( &p_instance->p_vlm->lock );
Clément Stenac's avatar
Clément Stenac committed
181
#endif
Clément Stenac's avatar
Clément Stenac committed
182 183 184
}


Clément Stenac's avatar
Clément Stenac committed
185 186 187 188 189 190
void libvlc_vlm_change_media( libvlc_instance_t *p_instance, char *psz_name,
                              char *psz_input, char *psz_output, int i_options,
                              char **ppsz_options, int b_enabled, int b_loop,
                              libvlc_exception_t *p_exception )
{
    vlm_media_t *p_media;
Clément Stenac's avatar
Clément Stenac committed
191
    int i_ret;
Clément Stenac's avatar
Clément Stenac committed
192
    CHECK_VLM;
Clément Stenac's avatar
Clément Stenac committed
193 194
#ifdef ENABLE_VLM
    vlc_mutex_lock( &p_instance->p_vlm->lock );
Clément Stenac's avatar
Clément Stenac committed
195
    GET_MEDIA;
Clément Stenac's avatar
Clément Stenac committed
196 197 198
    if( b_enabled != 0 ) b_enabled = 1;
    if( b_loop != 0 ) b_loop = 1;

Clément Stenac's avatar
Clément Stenac committed
199
    i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
Clément Stenac's avatar
Clément Stenac committed
200 201 202 203 204 205
    if( i_ret )
    {
        libvlc_exception_raise( p_exception, "Unable to set output" );
        vlc_mutex_unlock( &p_instance->p_vlm->lock );
        return;
    }
Clément Stenac's avatar
Clément Stenac committed
206 207
    p_media->b_enabled = b_enabled;
    p_media->b_loop = b_loop;
Clément Stenac's avatar
Clément Stenac committed
208 209 210

    i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "output", psz_output );
    if( i_ret )
Clément Stenac's avatar
Clément Stenac committed
211 212 213 214
    {
        libvlc_exception_raise( p_exception, "Unable to set output" );
        vlc_mutex_unlock( &p_instance->p_vlm->lock ); return;
    }
Clément Stenac's avatar
Clément Stenac committed
215
    i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "inputdel", "all" );
Clément Stenac's avatar
Clément Stenac committed
216
    if( i_ret )
Clément Stenac's avatar
Clément Stenac committed
217 218 219 220
    {
        libvlc_exception_raise( p_exception, "Unable to change input" );
        vlc_mutex_unlock( &p_instance->p_vlm->lock ); return;
    }
Clément Stenac's avatar
Clément Stenac committed
221
    i_ret = vlm_MediaSetup( p_instance->p_vlm, p_media, "input", psz_input );
Clément Stenac's avatar
Clément Stenac committed
222
    if( i_ret )
Clément Stenac's avatar
Clément Stenac committed
223 224 225 226
    {
        libvlc_exception_raise( p_exception, "Unable to change input" );
        vlc_mutex_unlock( &p_instance->p_vlm->lock );return;
    }
Clément Stenac's avatar
Clément Stenac committed
227 228

    vlc_mutex_unlock( &p_instance->p_vlm->lock );
Clément Stenac's avatar
Clément Stenac committed
229
#endif
Clément Stenac's avatar
Clément Stenac committed
230
}