2 #include <mediacontrol_internal.h>
3 #include <vlc/mediacontrol.h>
5 mediacontrol_Instance* mediacontrol_new( char** args, mediacontrol_Exception *exception )
7 mediacontrol_Instance* retval;
17 for ( p_tmp = args ; *p_tmp != NULL ; p_tmp++ )
21 ppsz_argv = malloc( ( i_count + 2 ) * sizeof( char * ) ) ;
24 exception->code = mediacontrol_InternalException;
25 exception->message = "Out of memory";
29 for ( i_index = 0; i_index < i_count; i_index++ )
31 ppsz_argv[i_index + 1] = strdup( args[i_index] );
32 if( ! ppsz_argv[i_index + 1] )
34 exception->code = mediacontrol_InternalException;
35 exception->message = "Out of memory";
40 ppsz_argv[i_count + 1] = NULL;
42 p_vlc_id = VLC_Create();
46 exception->code = mediacontrol_InternalException;
47 exception->message = strdup( "Unable to create VLC" );
51 p_vlc = ( vlc_object_t* )vlc_current_object( p_vlc_id );
55 exception->code = mediacontrol_InternalException;
56 exception->message = strdup( "Unable to find VLC object" );
59 retval = ( mediacontrol_Instance* )malloc( sizeof( mediacontrol_Instance ) );
62 exception->code = mediacontrol_InternalException;
63 exception->message = strdup( "Out of memory" );
67 if( VLC_Init( p_vlc_id, i_count + 1, ppsz_argv ) != VLC_SUCCESS )
69 exception->code = mediacontrol_InternalException;
70 exception->message = strdup( "Cannot initialize VLC" );
74 retval->p_vlc = p_vlc;
75 retval->vlc_object_id = p_vlc_id;
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 );
82 if( ! retval->p_playlist || ! retval->p_intf )
84 exception->code = mediacontrol_InternalException;
85 exception->message = strdup( "No available interface" );
94 mediacontrol_exit( mediacontrol_Instance *self )
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_vlc );
101 VLC_CleanUp( self->vlc_object_id );
102 VLC_Destroy( self->vlc_object_id );