core.c 3.45 KB
Newer Older
1
/*****************************************************************************
Clément Stenac's avatar
Clément Stenac committed
2
 * core.c: Core libvlc new API functions : initialization, exceptions handling
3
 *****************************************************************************
4
 * Copyright (C) 2005 the VideoLAN team
5
 * $Id$
6
 *
Clément Stenac's avatar
Clément Stenac committed
7
 * Authors: Clment Stenac <zorglub@videolan.org>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

Clément Stenac's avatar
Clément Stenac committed
24 25
#include <libvlc_internal.h>
#include <vlc/libvlc.h>
26 27 28

#include <vlc/intf.h>

29
vlc_t * vlc_current_object( int );
30

Clément Stenac's avatar
Clément Stenac committed
31 32 33 34
/*************************************************************************
 * Exceptions handling
 *************************************************************************/
inline void libvlc_exception_init( libvlc_exception_t *p_exception )
35
{
Clément Stenac's avatar
Clément Stenac committed
36 37
    p_exception->b_raised = 0;
    p_exception->psz_message = NULL;
38 39
}

Clément Stenac's avatar
Clément Stenac committed
40
inline int libvlc_exception_raised( libvlc_exception_t *p_exception )
41
{
Clément Stenac's avatar
Clément Stenac committed
42
    return p_exception->b_raised;
43 44
}

Clément Stenac's avatar
Clément Stenac committed
45
inline char* libvlc_exception_get_message( libvlc_exception_t *p_exception )
46
{
Clément Stenac's avatar
Clément Stenac committed
47
    if( p_exception->b_raised == 1 && p_exception->psz_message )
48
    {
Clément Stenac's avatar
Clément Stenac committed
49
        return p_exception->psz_message;
50
    }
Clément Stenac's avatar
Clément Stenac committed
51
    return NULL;
52 53
}

Clément Stenac's avatar
Clément Stenac committed
54 55
inline void libvlc_exception_raise( libvlc_exception_t *p_exception,
                                    char *psz_message )
56
{
Clément Stenac's avatar
Clément Stenac committed
57 58 59
    if( p_exception == NULL ) return;
    p_exception->b_raised = 1;
    p_exception->psz_message = strdup( psz_message );
60 61 62
}


Clément Stenac's avatar
Clément Stenac committed
63 64
libvlc_instance_t * libvlc_new( int argc, char **argv,
                                libvlc_exception_t *p_exception )
65
{
Clément Stenac's avatar
Clément Stenac committed
66 67 68
    int i_vlc_id;
    libvlc_instance_t *p_new;
    vlc_t *p_vlc;
69

Clément Stenac's avatar
Clément Stenac committed
70 71
    i_vlc_id = VLC_Create();
    p_vlc = (vlc_t* ) vlc_current_object( i_vlc_id );
72

Clément Stenac's avatar
Clément Stenac committed
73
    if( !p_vlc )
74
    {
Clément Stenac's avatar
Clément Stenac committed
75 76
        libvlc_exception_raise( p_exception, "VLC initialization failed" );
        return NULL;
77
    }
Clément Stenac's avatar
Clément Stenac committed
78
    p_new = (libvlc_instance_t *)malloc( sizeof( libvlc_instance_t ) );
79

Clément Stenac's avatar
Clément Stenac committed
80 81
    /** \todo Look for interface settings. If we don't have any, add -I dummy */
    /* Because we probably don't want a GUI by default */
82

Clément Stenac's avatar
Clément Stenac committed
83
    if( !p_new )
84
    {
Clément Stenac's avatar
Clément Stenac committed
85
        libvlc_exception_raise( p_exception, "Out of memory" );
86 87 88
        return NULL;
    }

Clément Stenac's avatar
Clément Stenac committed
89
    VLC_Init( i_vlc_id, argc, argv );
90

Clément Stenac's avatar
Clément Stenac committed
91 92 93
    p_new->p_vlc = p_vlc;
    p_new->p_playlist = (playlist_t *)vlc_object_find( p_new->p_vlc,
                                VLC_OBJECT_PLAYLIST, FIND_CHILD );
94

Clément Stenac's avatar
Clément Stenac committed
95
    if( !p_new->p_playlist )
96
    {
Clément Stenac's avatar
Clément Stenac committed
97 98
        libvlc_exception_raise( p_exception, "Playlist creation failed" );
        return NULL;
99
    }
Clément Stenac's avatar
Clément Stenac committed
100
    p_new->i_vlc_id = i_vlc_id;
101

Clément Stenac's avatar
Clément Stenac committed
102
    return p_new;
103 104
}

Clément Stenac's avatar
Clément Stenac committed
105
void libvlc_destroy( libvlc_instance_t *p_instance )
106
{
Clément Stenac's avatar
Clément Stenac committed
107 108 109 110 111
    if( p_instance->p_playlist )
        vlc_object_release( p_instance->p_playlist );
    vlc_object_release( p_instance->p_vlc );
    VLC_CleanUp( p_instance->i_vlc_id );
    VLC_Destroy( p_instance->i_vlc_id );
112
}