]> git.sesse.net Git - vlc/blob - src/control/mediacontrol_init.c
For consistency, remove references to vlc from libvlc
[vlc] / src / control / mediacontrol_init.c
1 #define __VLC__
2 #include <mediacontrol_internal.h>
3 #include <vlc/mediacontrol.h>
4
5 mediacontrol_Instance* mediacontrol_new( char** args, mediacontrol_Exception *exception )
6 {
7     mediacontrol_Instance* retval;
8     vlc_object_t *p_vlc;
9     int p_vlc_id;
10     char **ppsz_argv;
11     int i_count = 0;
12     int i_index;
13     char **p_tmp;
14
15     if( args )
16     {
17         for ( p_tmp = args ; *p_tmp != NULL ; p_tmp++ )
18             i_count++;
19     }
20
21     ppsz_argv = malloc( ( i_count + 2 ) * sizeof( char * ) ) ;
22     if( ! ppsz_argv )
23     {
24         exception->code = mediacontrol_InternalException;
25         exception->message = "out of memory";
26         return NULL;
27     }
28     ppsz_argv[0] = "vlc";
29     for ( i_index = 0; i_index < i_count; i_index++ )
30     {
31         ppsz_argv[i_index + 1] = strdup( args[i_index] );
32         if( ! ppsz_argv[i_index + 1] )
33         {
34             exception->code = mediacontrol_InternalException;
35             exception->message = "out of memory";
36             return NULL;
37         }
38     }
39
40     ppsz_argv[i_count + 1] = NULL;
41
42     p_vlc_id = VLC_Create();
43
44     if( p_vlc_id < 0 )
45     {
46         exception->code = mediacontrol_InternalException;
47         exception->message = strdup( "unable to create VLC" );
48         return NULL;        
49     }
50
51     p_vlc = ( vlc_object_t* )vlc_current_object( p_vlc_id );
52   
53     if( ! p_vlc )
54     {
55         exception->code = mediacontrol_InternalException;
56         exception->message = strdup( "unable to find VLC object" );
57         return NULL;
58     }
59     retval = ( mediacontrol_Instance* )malloc( sizeof( mediacontrol_Instance ) );
60     if( ! retval )
61     {
62         exception->code = mediacontrol_InternalException;
63         exception->message = strdup( "out of memory" );
64         return NULL;
65     }
66
67     if( VLC_Init( p_vlc_id, i_count + 1, ppsz_argv ) != VLC_SUCCESS )
68     {
69         exception->code = mediacontrol_InternalException;
70         exception->message = strdup( "cannot initialize VLC" );
71         return NULL;
72     }
73
74     retval->p_libvlc = p_vlc;
75     retval->vlc_object_id = p_vlc_id;
76
77     /* We can keep references on these, which should not change. Is it true ? */
78     retval->p_playlist = vlc_object_find( p_vlc,
79                                          VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
80     retval->p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_ANYWHERE );
81
82     if( ! retval->p_playlist || ! retval->p_intf )
83     {
84         exception->code = mediacontrol_InternalException;
85         exception->message = strdup( "no interface available" );
86         return NULL;
87     }
88
89     
90     return retval;  
91 };
92
93 void
94 mediacontrol_exit( mediacontrol_Instance *self )
95 {
96   
97     vlc_object_release( (vlc_object_t* )self->p_playlist );
98     vlc_object_release( (vlc_object_t* )self->p_intf );
99     vlc_object_release( (vlc_object_t*)self->p_libvlc );
100   
101     VLC_CleanUp( self->vlc_object_id );
102     VLC_Destroy( self->vlc_object_id );
103 }