~ubuntu-branches/ubuntu/maverick/vlc/maverick

« back to all changes in this revision

Viewing changes to src/control/core.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-09-17 21:56:14 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20080917215614-tj0vx8xzd57e52t8
Tags: 0.9.2-1ubuntu1
* New Upstream Release, exception granted by
    - dktrkranz, norsetto, Hobbsee (via irc). LP: #270404

Changes done in ubuntu:

* add libxul-dev to build-depends
* make sure that vlc is build against libxul in configure. This doesn't
  change anything in the package, but makes it more robust if building
  in an 'unclean' chroot or when modifying the package.
* debian/control: make Vcs-* fields point to the motumedia branch
* add libx264-dev and libass-dev to build-depends
  LP: #210354, #199870
* actually enable libass support by passing --enable-libass to configure
* enable libdca: add libdca-dev to build depends and --enable-libdca
* install the x264 plugin.

Changes already in the pkg-multimedia branch in debian:

* don't install usr/share/vlc/mozilla in debian/mozilla-plugin-vlc.install  
* new upstream .desktop file now registers flash video mimetype LP: #261567
* add Xb-Npp-Applications to mozilla-plugin-vlc
* remove duplicate entries in debian/vlc-nox.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright (C) 2005 the VideoLAN team
5
5
 * $Id$
6
6
 *
7
 
 * Authors: Cl�ent Stenac <zorglub@videolan.org>
 
7
 * Authors: Clément Stenac <zorglub@videolan.org>
8
8
 *
9
9
 * This program is free software; you can redistribute it and/or modify
10
10
 * it under the terms of the GNU General Public License as published by
20
20
 * along with this program; if not, write to the Free Software
21
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22
22
 *****************************************************************************/
 
23
 
 
24
#include "libvlc_internal.h"
 
25
#include <vlc/libvlc.h>
 
26
 
 
27
#include <vlc_interface.h>
 
28
 
23
29
#include <stdarg.h>
24
 
#include <libvlc_internal.h>
25
 
#include <vlc/libvlc.h>
 
30
#include <limits.h>
 
31
#include <assert.h>
26
32
 
27
 
#include <vlc/intf.h>
 
33
static const char nomemstr[] = "Insufficient memory";
28
34
 
29
35
/*************************************************************************
30
36
 * Exceptions handling
31
37
 *************************************************************************/
32
 
inline void libvlc_exception_init( libvlc_exception_t *p_exception )
 
38
void libvlc_exception_init( libvlc_exception_t *p_exception )
33
39
{
34
40
    p_exception->b_raised = 0;
35
41
    p_exception->psz_message = NULL;
37
43
 
38
44
void libvlc_exception_clear( libvlc_exception_t *p_exception )
39
45
{
40
 
    if( p_exception->psz_message )
 
46
    if( p_exception->psz_message != nomemstr )
41
47
        free( p_exception->psz_message );
42
48
    p_exception->psz_message = NULL;
43
49
    p_exception->b_raised = 0;
44
50
}
45
51
 
46
 
inline int libvlc_exception_raised( libvlc_exception_t *p_exception )
 
52
int libvlc_exception_raised( const libvlc_exception_t *p_exception )
47
53
{
48
54
    return (NULL != p_exception) && p_exception->b_raised;
49
55
}
50
56
 
51
 
inline char* libvlc_exception_get_message( libvlc_exception_t *p_exception )
 
57
const char *
 
58
libvlc_exception_get_message( const libvlc_exception_t *p_exception )
52
59
{
53
60
    if( p_exception->b_raised == 1 && p_exception->psz_message )
54
61
    {
57
64
    return NULL;
58
65
}
59
66
 
60
 
inline void libvlc_exception_raise( libvlc_exception_t *p_exception,
61
 
                                    char *psz_format, ... )
 
67
static void libvlc_exception_not_handled( const char *psz )
 
68
{
 
69
    fprintf( stderr, "*** LibVLC Exception not handled: %s\nSet a breakpoint in '%s' to debug.\n",
 
70
             psz, __func__ );
 
71
}
 
72
 
 
73
void libvlc_exception_raise( libvlc_exception_t *p_exception,
 
74
                             const char *psz_format, ... )
62
75
{
63
76
    va_list args;
64
 
 
65
 
    /* does caller care about exceptions ? */
66
 
    if( p_exception == NULL ) return;
67
 
 
68
 
    /* remove previous exception if it wasn't cleared */
69
 
    if( p_exception->b_raised && p_exception->psz_message )
70
 
    {
71
 
        free(p_exception->psz_message);
72
 
        p_exception->psz_message = NULL;
73
 
    }
74
 
 
 
77
    char * psz;
 
78
 
 
79
    /* Unformat-ize the message */
75
80
    va_start( args, psz_format );
76
 
    vasprintf( &p_exception->psz_message, psz_format, args );
 
81
    if( vasprintf( &psz, psz_format, args ) == -1)
 
82
        psz = (char *)nomemstr;
77
83
    va_end( args );
78
84
 
 
85
    /* Does caller care about exceptions ? */
 
86
    if( p_exception == NULL ) {
 
87
        /* Print something, so that lazy third-parties can easily
 
88
         * notice that something may have gone unnoticedly wrong */
 
89
        libvlc_exception_not_handled( psz );
 
90
        return;
 
91
    }
 
92
 
 
93
    /* Make sure that there is no unnoticed previous exception */
 
94
    if( p_exception->b_raised )
 
95
    {
 
96
        libvlc_exception_not_handled( p_exception->psz_message );
 
97
        libvlc_exception_clear( p_exception );
 
98
    }
 
99
    p_exception->psz_message = psz;
79
100
    p_exception->b_raised = 1;
80
101
}
81
102
 
82
 
libvlc_instance_t * libvlc_new( int argc, char **argv,
 
103
libvlc_instance_t * libvlc_new( int argc, const char *const *argv,
83
104
                                libvlc_exception_t *p_e )
84
105
{
85
 
    int i_vlc_id;
86
106
    libvlc_instance_t *p_new;
87
 
    vlc_t *p_vlc;
88
 
 
89
 
    i_vlc_id = VLC_Create();
90
 
    p_vlc = (vlc_t* ) vlc_current_object( i_vlc_id );
91
 
 
92
 
    if( !p_vlc ) RAISENULL( "VLC initialization failed" );
 
107
    int i_ret;
 
108
    libvlc_int_t *p_libvlc_int = libvlc_InternalCreate();
 
109
    if( !p_libvlc_int ) RAISENULL( "VLC initialization failed" );
93
110
 
94
111
    p_new = (libvlc_instance_t *)malloc( sizeof( libvlc_instance_t ) );
95
112
    if( !p_new ) RAISENULL( "Out of memory" );
96
113
 
 
114
    const char *my_argv[argc + 2];
 
115
 
 
116
    my_argv[0] = "libvlc"; /* dummy arg0, skipped by getopt() et al */
 
117
    for( int i = 0; i < argc; i++ )
 
118
         my_argv[i + 1] = argv[i];
 
119
    my_argv[argc + 1] = NULL; /* C calling conventions require a NULL */
 
120
 
97
121
    /** \todo Look for interface settings. If we don't have any, add -I dummy */
98
122
    /* Because we probably don't want a GUI by default */
99
123
 
100
 
 
101
 
    VLC_Init( i_vlc_id, argc, argv );
102
 
 
103
 
    p_new->p_vlc = p_vlc;
104
 
    p_new->p_playlist = (playlist_t *)vlc_object_find( p_new->p_vlc,
105
 
                                VLC_OBJECT_PLAYLIST, FIND_CHILD );
 
124
    i_ret=libvlc_InternalInit( p_libvlc_int, argc + 1, my_argv );
 
125
    if( i_ret == VLC_EEXITSUCCESS )
 
126
            return NULL;
 
127
    else if( i_ret != 0 )
 
128
        RAISENULL( "VLC initialization failed" );
 
129
 
 
130
    p_new->p_libvlc_int = p_libvlc_int;
106
131
    p_new->p_vlm = NULL;
107
 
 
108
 
    if( !p_new->p_playlist )
109
 
    {
110
 
        libvlc_destroy( p_new );
111
 
        RAISENULL( "Playlist creation failed" );
112
 
    }
113
 
 
114
 
    p_new->i_vlc_id = i_vlc_id;
 
132
    p_new->b_playlist_locked = 0;
 
133
    p_new->ref_count = 1;
 
134
    p_new->p_callback_list = NULL;
 
135
    vlc_mutex_init(&p_new->instance_lock);
 
136
    vlc_mutex_init(&p_new->event_callback_lock);
 
137
 
115
138
    return p_new;
116
139
}
117
140
 
118
 
void libvlc_destroy( libvlc_instance_t *p_instance )
119
 
{
120
 
    if( p_instance->p_playlist )
121
 
        vlc_object_release( p_instance->p_playlist );
122
 
    vlc_object_release( p_instance->p_vlc );
123
 
    VLC_CleanUp( p_instance->i_vlc_id );
124
 
    VLC_Destroy( p_instance->i_vlc_id );
125
 
    free( p_instance );
 
141
void libvlc_retain( libvlc_instance_t *p_instance )
 
142
{
 
143
    assert( p_instance != NULL );
 
144
    assert( p_instance->ref_count < UINT_MAX );
 
145
 
 
146
    vlc_mutex_lock( &p_instance->instance_lock );
 
147
    p_instance->ref_count++;
 
148
    vlc_mutex_unlock( &p_instance->instance_lock );
 
149
}
 
150
 
 
151
void libvlc_release( libvlc_instance_t *p_instance )
 
152
{
 
153
    vlc_mutex_t *lock = &p_instance->instance_lock;
 
154
    int refs;
 
155
 
 
156
    assert( p_instance->ref_count > 0 );
 
157
 
 
158
    vlc_mutex_lock( lock );
 
159
    refs = --p_instance->ref_count;
 
160
    vlc_mutex_unlock( lock );
 
161
 
 
162
    if( refs == 0 )
 
163
    {
 
164
        vlc_mutex_destroy( lock );
 
165
        vlc_mutex_destroy( &p_instance->event_callback_lock );
 
166
        libvlc_InternalCleanup( p_instance->p_libvlc_int );
 
167
        libvlc_InternalDestroy( p_instance->p_libvlc_int );
 
168
        free( p_instance );
 
169
    }
 
170
}
 
171
 
 
172
void libvlc_add_intf( libvlc_instance_t *p_i, const char *name,
 
173
                      libvlc_exception_t *p_e )
 
174
{
 
175
    if( libvlc_InternalAddIntf( p_i->p_libvlc_int, name ) )
 
176
        RAISEVOID( "Interface initialization failed" );
 
177
}
 
178
 
 
179
void libvlc_wait( libvlc_instance_t *p_i )
 
180
{
 
181
    libvlc_int_t *p_libvlc = p_i->p_libvlc_int;
 
182
    vlc_object_lock( p_libvlc );
 
183
    while( vlc_object_alive( p_libvlc ) )
 
184
        vlc_object_wait( p_libvlc );
 
185
    vlc_object_unlock( p_libvlc );
126
186
}
127
187
 
128
188
int libvlc_get_vlc_id( libvlc_instance_t *p_instance )
129
189
{
130
 
    return p_instance->i_vlc_id;
131
 
}
132
 
 
 
190
    return p_instance->p_libvlc_int->i_object_id;
 
191
}
 
192
 
 
193
const char * libvlc_get_version(void)
 
194
{
 
195
    return VLC_Version();
 
196
}
 
197
 
 
198
const char * libvlc_get_compiler(void)
 
199
{
 
200
    return VLC_Compiler();
 
201
}
 
202
 
 
203
const char * libvlc_get_changeset(void)
 
204
{
 
205
    return VLC_Changeset();
 
206
}