Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

mediacontrol-core.c

00001 #include "mediacontrol-core.h"
00002 
00003 #include <vlc/intf.h>
00004 #include <vlc/vout.h>
00005 #include <vlc/aout.h>
00006 #include <vlc_demux.h>
00007 
00008 #include <vlc_osd.h>
00009 
00010 #define HAS_SNAPSHOT 1
00011 
00012 #ifdef HAS_SNAPSHOT
00013 #include <snapshot.h>
00014 #endif
00015 
00016 #include <stdlib.h>                                      /* malloc(), free() */
00017 #include <string.h>
00018 
00019 #include <errno.h>                                                 /* ENOMEM */
00020 #include <stdio.h>
00021 #include <ctype.h>
00022 
00023 #ifdef HAVE_UNISTD_H
00024 #    include <unistd.h>
00025 #endif
00026 
00027 #ifdef HAVE_SYS_TIME_H
00028 #    include <sys/time.h>
00029 #endif
00030 #include <sys/types.h>
00031 
00032 #define RAISE( c, m )  exception->code = c; \
00033                        exception->message = strdup(m);
00034 
00035 long long mediacontrol_unit_convert( input_thread_t *p_input,
00036                                      mediacontrol_PositionKey from,
00037                                      mediacontrol_PositionKey to,
00038                                      long long value )
00039 {
00040     if( to == from )
00041         return value;
00042 
00043     /* For all conversions, we need data from p_input */
00044     if( !p_input )
00045         return 0;
00046 
00047     switch( from )
00048     {
00049     case mediacontrol_MediaTime:
00050         if( to == mediacontrol_ByteCount )
00051         {
00052             /* FIXME */
00053             /* vlc < 0.8 API */
00054             /* return value * 50 * p_input->stream.i_mux_rate / 1000; */
00055             return 0;
00056         }
00057         if( to == mediacontrol_SampleCount )
00058         {
00059             double f_fps;
00060 
00061             if( demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
00062                 return 0;
00063             else
00064                 return( value * f_fps / 1000.0 );
00065         }
00066         /* Cannot happen */
00067         /* See http://catb.org/~esr/jargon/html/entry/can't-happen.html */
00068         break;
00069 
00070     case mediacontrol_SampleCount:
00071     {
00072         double f_fps;
00073 
00074         if( demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
00075             return 0;
00076 
00077         if( to == mediacontrol_ByteCount )
00078         {
00079             /* FIXME */
00080             /* vlc < 0.8 API */
00081 /*             return ( long long )( value * 50 * p_input->stream.i_mux_rate / f_fps ); */
00082             return 0;
00083         }
00084 
00085         if( to == mediacontrol_MediaTime )
00086             return( long long )( value * 1000.0 / ( double )f_fps );
00087 
00088         /* Cannot happen */
00089         break;
00090     }
00091     case mediacontrol_ByteCount:
00092         /* FIXME */
00093         return 0;
00094 /* vlc < 0.8 API: */
00095 
00096 //         if( p_input->stream.i_mux_rate == 0 )
00097 //             return 0;
00098 // 
00099 //         /* Convert an offset into milliseconds. Taken from input_ext-intf.c.
00100 //            The 50 hardcoded constant comes from the definition of i_mux_rate :
00101 //            i_mux_rate : the rate we read the stream (in units of 50 bytes/s) ;
00102 //            0 if undef */
00103 //         if( to == mediacontrol_MediaTime )
00104 //             return ( long long )( 1000 * value / 50 / p_input->stream.i_mux_rate );
00105 // 
00106 //         if( to == mediacontrol_SampleCount )
00107 //         {
00108 //             double f_fps;
00109 //             if( demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
00110 //                 return 0;
00111 //             else
00112 //                 return ( long long )( value * f_fps / 50 / p_input->stream.i_mux_rate );
00113 //         }
00114         /* Cannot happen */
00115         break;
00116     }
00117     /* Cannot happen */
00118     return 0;
00119 }
00120 
00121 /* Converts a mediacontrol_Position into a time in microseconds in
00122    movie clock time */
00123 long long
00124 mediacontrol_position2microsecond( input_thread_t* p_input, const mediacontrol_Position * pos )
00125 {
00126     switch( pos->origin )
00127     {
00128     case mediacontrol_AbsolutePosition:
00129         return ( 1000 * mediacontrol_unit_convert( p_input,
00130                                                    pos->key, /* from */
00131                                                    mediacontrol_MediaTime,  /* to */
00132                                                    pos->value ) );
00133         break;
00134     case mediacontrol_RelativePosition:
00135     {
00136         long long l_pos;
00137         vlc_value_t val;
00138 
00139         val.i_time = 0;
00140         if( p_input )
00141         {
00142             var_Get( p_input, "time", &val );
00143         }
00144 
00145         l_pos = 1000 * mediacontrol_unit_convert( p_input,
00146                                                   pos->key,
00147                                                   mediacontrol_MediaTime,
00148                                                   pos->value );
00149         return val.i_time + l_pos;
00150         break;
00151     }
00152     case mediacontrol_ModuloPosition:
00153     {
00154         long long l_pos;
00155         vlc_value_t val;
00156 
00157         val.i_time = 0;
00158         if( p_input )
00159         {
00160             var_Get( p_input, "length", &val );
00161         }
00162 
00163         if( val.i_time > 0)
00164         {
00165             l_pos = ( 1000 * mediacontrol_unit_convert( p_input,
00166                                                         pos->key,
00167                                                         mediacontrol_MediaTime,
00168                                                         pos->value ) );
00169         }
00170         else
00171             l_pos = 0;
00172 
00173         return l_pos % val.i_time;
00174         break;
00175     }
00176     }
00177     return 0;
00178 }
00179 
00180 mediacontrol_RGBPicture*
00181 mediacontrol_RGBPicture__alloc( int datasize )
00182 {
00183     mediacontrol_RGBPicture* pic;
00184 
00185     pic = ( mediacontrol_RGBPicture * )malloc( sizeof( mediacontrol_RGBPicture ) );
00186     if( ! pic )
00187         return NULL;
00188 
00189     pic->size = datasize;
00190     pic->data = ( char* )malloc( datasize );
00191     return pic;
00192 }
00193 
00194 void
00195 mediacontrol_RGBPicture__free( mediacontrol_RGBPicture* pic )
00196 {
00197     if( pic )
00198         free( pic->data );
00199     free( pic );
00200 }
00201 
00202 mediacontrol_PlaylistSeq*
00203 mediacontrol_PlaylistSeq__alloc( int size )
00204 {
00205     mediacontrol_PlaylistSeq* ps;
00206 
00207     ps =( mediacontrol_PlaylistSeq* )malloc( sizeof( mediacontrol_PlaylistSeq ) );
00208     if( ! ps )
00209         return NULL;
00210 
00211     ps->size = size;
00212     ps->data = ( char** )malloc( size * sizeof( char* ) );
00213     return ps;
00214 }
00215 
00216 void
00217 mediacontrol_PlaylistSeq__free( mediacontrol_PlaylistSeq* ps )
00218 {
00219     if( ps )
00220     {
00221         int i;
00222         for( i = 0 ; i < ps->size ; i++ )
00223             free( ps->data[i] );
00224     }
00225     free( ps->data );
00226     free( ps );
00227 }
00228 
00229 mediacontrol_Exception*
00230 mediacontrol_exception_init( mediacontrol_Exception *exception )
00231 {
00232     if( exception == NULL )
00233     {
00234         exception = ( mediacontrol_Exception* )malloc( sizeof( mediacontrol_Exception ) );
00235     }
00236 
00237     exception->code = 0;
00238     exception->message = NULL;
00239     return exception;
00240 }
00241 
00242 void
00243 mediacontrol_exception_free( mediacontrol_Exception *exception )
00244 {
00245     if( ! exception )
00246         return;
00247 
00248     free( exception->message );
00249     free( exception );
00250 }
00251 
00252 mediacontrol_Instance* mediacontrol_new_from_object( vlc_object_t* p_object,
00253                                                      mediacontrol_Exception *exception )
00254 {
00255     mediacontrol_Instance* retval;
00256     vlc_object_t *p_vlc;
00257 
00258     p_vlc = vlc_object_find( p_object, VLC_OBJECT_ROOT, FIND_PARENT );
00259     if( ! p_vlc )
00260     {
00261         RAISE( mediacontrol_InternalException, "Unable to initialize VLC" );
00262         return NULL;
00263     }
00264     retval = ( mediacontrol_Instance* )malloc( sizeof( mediacontrol_Instance ) );
00265     retval->p_vlc = p_vlc;
00266     retval->vlc_object_id = p_vlc->i_object_id;
00267 
00268     /* We can keep references on these, which should not change. Is it true ? */
00269     retval->p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00270     retval->p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_ANYWHERE );
00271 
00272     if( ! retval->p_playlist || ! retval->p_intf )
00273     {
00274         RAISE( mediacontrol_InternalException, "No available interface" );
00275         return NULL;
00276     }
00277     return retval;
00278 };
00279 
00280 /* Returns the current position in the stream. The returned value can
00281    be relative or absolute( according to PositionOrigin ) and the unit
00282    is set by PositionKey */
00283 mediacontrol_Position*
00284 mediacontrol_get_media_position( mediacontrol_Instance *self,
00285                                  const mediacontrol_PositionOrigin an_origin,
00286                                  const mediacontrol_PositionKey a_key,
00287                                  mediacontrol_Exception *exception )
00288 {
00289     mediacontrol_Position* retval;
00290     vlc_value_t val;
00291     input_thread_t * p_input = self->p_playlist->p_input;
00292 
00293     exception = mediacontrol_exception_init( exception );
00294 
00295     retval = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) );
00296     retval->origin = an_origin;
00297     retval->key = a_key;
00298 
00299     if( ! p_input )
00300     {
00301         /*
00302            RAISE( mediacontrol_InternalException, "No input thread." );
00303            return( NULL );
00304         */
00305         retval->value = 0;
00306         return retval;
00307     }
00308 
00309     if(  an_origin == mediacontrol_RelativePosition
00310          || an_origin == mediacontrol_ModuloPosition )
00311     {
00312         /* Relative or ModuloPosition make no sense */
00313         retval->value = 0;
00314         return retval;
00315     }
00316 
00317     /* We are asked for an AbsolutePosition. */
00318     val.i_time = 0;
00319     var_Get( p_input, "time", &val );
00320     /* FIXME: check val.i_time > 0 */
00321 
00322     retval->value = mediacontrol_unit_convert( p_input,
00323                                                mediacontrol_MediaTime,
00324                                                a_key,
00325                                                val.i_time / 1000 );
00326     return retval;
00327 }
00328 
00329 /* Sets the media position */
00330 void
00331 mediacontrol_set_media_position( mediacontrol_Instance *self,
00332                                  const mediacontrol_Position * a_position,
00333                                  mediacontrol_Exception *exception )
00334 {
00335     vlc_value_t val;
00336     input_thread_t * p_input = self->p_playlist->p_input;
00337 
00338     exception=mediacontrol_exception_init( exception );
00339     if( ! p_input )
00340     {
00341         RAISE( mediacontrol_InternalException, "No input thread." );
00342         return;
00343     }
00344 
00345     if( !var_GetBool( p_input, "seekable" ) )
00346     {
00347         RAISE( mediacontrol_InvalidPosition, "Stream not seekable" );
00348         return;
00349     }
00350 
00351     val.i_time = mediacontrol_position2microsecond( p_input, a_position );
00352     var_Set( p_input, "time", val );
00353     return;
00354 }
00355 
00356 /* Starts playing a stream */
00357 void
00358 mediacontrol_start( mediacontrol_Instance *self,
00359                     const mediacontrol_Position * a_position,
00360                     mediacontrol_Exception *exception )
00361 {
00362     playlist_t * p_playlist = self->p_playlist;
00363 
00364     exception = mediacontrol_exception_init( exception );
00365     if( ! p_playlist )
00366     {
00367         RAISE( mediacontrol_PlaylistException, "No available playlist" );
00368         return;
00369     }
00370 
00371     vlc_mutex_lock( &p_playlist->object_lock );
00372     if( p_playlist->i_size )
00373     {
00374         vlc_value_t val;
00375 
00376         vlc_mutex_unlock( &p_playlist->object_lock );
00377 
00378         /* Set start time */
00379         val.i_int = mediacontrol_position2microsecond( p_playlist->p_input, a_position ) / 1000000;
00380         var_Set( p_playlist, "start-time", val );
00381 
00382         playlist_Play( p_playlist );
00383     }
00384     else
00385     {
00386         RAISE( mediacontrol_PlaylistException, "Empty playlist." );
00387         vlc_mutex_unlock( &p_playlist->object_lock );
00388         return;
00389     }
00390 
00391     return;
00392 }
00393 
00394 void
00395 mediacontrol_pause( mediacontrol_Instance *self,
00396                     const mediacontrol_Position * a_position,
00397                     mediacontrol_Exception *exception )
00398 {
00399     input_thread_t *p_input = self->p_playlist->p_input;;
00400 
00401     /* FIXME: use the a_position parameter */
00402     exception=mediacontrol_exception_init( exception );
00403     if( p_input != NULL )
00404     {
00405         var_SetInteger( p_input, "state", PAUSE_S );
00406     }
00407     else
00408     {
00409         RAISE( mediacontrol_InternalException, "No input" );
00410     }
00411 
00412     return;
00413 }
00414 
00415 void
00416 mediacontrol_resume( mediacontrol_Instance *self,
00417                      const mediacontrol_Position * a_position,
00418                      mediacontrol_Exception *exception )
00419 {
00420     input_thread_t *p_input = self->p_playlist->p_input;
00421 
00422     /* FIXME: use the a_position parameter */
00423     exception=mediacontrol_exception_init( exception );
00424     if( p_input != NULL )
00425     {
00426         var_SetInteger( p_input, "state", PAUSE_S );
00427     }
00428     else
00429     {
00430         RAISE( mediacontrol_InternalException, "No input" );
00431     }
00432 }
00433 
00434 void
00435 mediacontrol_stop( mediacontrol_Instance *self,
00436                    const mediacontrol_Position * a_position,
00437                    mediacontrol_Exception *exception )
00438 {
00439     /* FIXME: use the a_position parameter */
00440     exception=mediacontrol_exception_init( exception );
00441     if( !self->p_playlist )
00442     {
00443         RAISE( mediacontrol_PlaylistException, "No playlist" );
00444         return;
00445     }
00446 
00447     playlist_Stop( self->p_playlist );
00448 }
00449 
00450 void
00451 mediacontrol_playlist_add_item( mediacontrol_Instance *self,
00452                                 const char * psz_file,
00453                                 mediacontrol_Exception *exception )
00454 {
00455     exception=mediacontrol_exception_init( exception );
00456     if( !self->p_playlist )
00457     {
00458         RAISE( mediacontrol_InternalException, "No playlist" );
00459         return;
00460     }
00461 
00462     playlist_Add( self->p_playlist, psz_file, psz_file , PLAYLIST_REPLACE, 0 );
00463 }
00464 
00465 void
00466 mediacontrol_playlist_clear( mediacontrol_Instance *self,
00467                              mediacontrol_Exception *exception )
00468 {
00469     exception=mediacontrol_exception_init( exception );
00470     if( !self->p_playlist )
00471     {
00472         RAISE( mediacontrol_PlaylistException, "No playlist" );
00473         return;
00474     }
00475 
00476     playlist_Clear( self->p_playlist );
00477 
00478     return;
00479 }
00480 
00481 mediacontrol_PlaylistSeq *
00482 mediacontrol_playlist_get_list( mediacontrol_Instance *self,
00483                                 mediacontrol_Exception *exception )
00484 {
00485     mediacontrol_PlaylistSeq *retval;
00486     int i_index;
00487     playlist_t * p_playlist = self->p_playlist;;
00488     int i_playlist_size;
00489 
00490     exception=mediacontrol_exception_init( exception );
00491     if( !p_playlist )
00492     {
00493         RAISE( mediacontrol_PlaylistException, "No playlist" );
00494         return NULL;
00495     }
00496 
00497     vlc_mutex_lock( &p_playlist->object_lock );
00498     i_playlist_size = p_playlist->i_size;
00499 
00500     retval = mediacontrol_PlaylistSeq__alloc( i_playlist_size );
00501 
00502     for( i_index = 0 ; i_index < i_playlist_size ; i_index++ )
00503     {
00504         retval->data[i_index] = strdup( p_playlist->pp_items[i_index]->input.psz_uri );
00505     }
00506     vlc_mutex_unlock( &p_playlist->object_lock );
00507 
00508     return retval;
00509 }
00510 
00511 mediacontrol_RGBPicture*
00512 _mediacontrol_createRGBPicture( int i_width, int i_height, long i_chroma, long long l_date,
00513                                 char* p_data, int i_datasize )
00514 {
00515     mediacontrol_RGBPicture *retval;
00516 
00517     retval = mediacontrol_RGBPicture__alloc( i_datasize );
00518     if( retval )
00519     {
00520         retval->width  = i_width;
00521         retval->height = i_height;
00522         retval->type   = i_chroma;
00523         retval->date   = l_date;
00524         retval->size   = i_datasize;
00525         memcpy( retval->data, p_data, i_datasize );
00526     }
00527     return retval;
00528 }
00529 
00530 mediacontrol_RGBPicture *
00531 mediacontrol_snapshot( mediacontrol_Instance *self,
00532                        const mediacontrol_Position * a_position,
00533                        mediacontrol_Exception *exception )
00534 {
00535     mediacontrol_RGBPicture *retval = NULL;
00536     input_thread_t* p_input = self->p_playlist->p_input;
00537     vout_thread_t *p_vout = NULL;
00538     int i_datasize;
00539     snapshot_t **pointer;
00540     vlc_value_t val;
00541     int i_index;
00542     snapshot_t *p_best_snapshot;
00543     long searched_date;
00544 #ifdef HAS_SNAPSHOT
00545     int i_cachesize;
00546 #endif
00547 
00548     exception=mediacontrol_exception_init( exception );
00549 
00550     /*
00551        if( var_Get( self->p_vlc, "snapshot-id", &val ) == VLC_SUCCESS )
00552        p_vout = vlc_object_get( self->p_vlc, val.i_int );
00553     */
00554 
00555     /* FIXME: if in p_libvlc, we cannot have multiple video outputs */
00556     /* Once corrected, search for snapshot-id to modify all instances */
00557     if( var_Get( p_input, "snapshot-id", &val ) != VLC_SUCCESS )
00558     {
00559         RAISE( mediacontrol_InternalException, "No snapshot-id in p_input" );
00560         return NULL;
00561     }
00562     p_vout = vlc_object_get( self->p_vlc, val.i_int );
00563 
00564     if( ! p_vout )
00565     {
00566         RAISE( mediacontrol_InternalException, "No snapshot module" );
00567         return NULL;
00568     }
00569 
00570 #ifdef HAS_SNAPSHOT
00571     /* We test if the vout is a snapshot module. We cannot test
00572        pvout_psz_object_name( which is NULL ). But we can check if
00573        there are snapshot-specific variables */
00574     if( var_Get( p_vout, "snapshot-datasize", &val ) != VLC_SUCCESS )
00575     {
00576         RAISE( mediacontrol_InternalException, "No snapshot module" );
00577         vlc_object_release( p_vout );
00578         return NULL;
00579     }
00580     i_datasize = val.i_int;
00581 
00582     /* Handle the a_position parameter */
00583     if( ! ( a_position->origin == mediacontrol_RelativePosition
00584             && a_position->value == 0 ) )
00585     {
00586         /* The position is not the current one. Go to it. */
00587         mediacontrol_set_media_position( self,
00588                                          ( mediacontrol_Position* ) a_position,
00589                                          exception );
00590         if( exception->code )
00591         {
00592             vlc_object_release( p_vout );
00593             return NULL;
00594         }
00595     }
00596 
00597     /* FIXME: We should not go further until we got past the position
00598        ( which means that we had the possibility to capture the right
00599        picture ). */
00600 
00601     vlc_mutex_lock( &p_vout->picture_lock );
00602 
00603     searched_date = mediacontrol_position2microsecond( p_input,
00604                                                        ( mediacontrol_Position * ) a_position );
00605 
00606     var_Get( p_vout, "snapshot-cache-size", &val );
00607     i_cachesize = val.i_int  ;
00608 
00609     var_Get( p_vout, "snapshot-list-pointer", &val );
00610     pointer = ( snapshot_t ** )val.p_address;
00611 
00612     if( ! pointer )
00613     {
00614         RAISE( mediacontrol_InternalException, "No available snapshot" );
00615 
00616         vlc_mutex_unlock( &p_vout->picture_lock );
00617         vlc_object_release( p_vout );
00618         return NULL;
00619     }
00620 
00621     /* Find the more appropriate picture, based on date */
00622     p_best_snapshot = pointer[0];
00623 
00624     for( i_index = 1 ; i_index < i_cachesize ; i_index++ )
00625     {
00626         long l_diff = pointer[i_index]->date - searched_date;
00627         if( l_diff > 0 && l_diff < abs( p_best_snapshot->date - searched_date ))
00628         {
00629             /* This one is closer, and _after_ the requested position */
00630             p_best_snapshot = pointer[i_index];
00631         }
00632     }
00633 
00634     /* FIXME: add a test for the case that no picture matched the test
00635        ( we have p_best_snapshot == pointer[0] */
00636     retval = _mediacontrol_createRGBPicture( p_best_snapshot->i_width,
00637                                              p_best_snapshot->i_height,
00638                                              p_vout->output.i_chroma,
00639                                              p_best_snapshot->date,
00640                                              p_best_snapshot->p_data,
00641                                              i_datasize );
00642 
00643     vlc_mutex_unlock( &p_vout->picture_lock );
00644     vlc_object_release( p_vout );
00645 
00646 #endif
00647 
00648     return retval;
00649 }
00650 
00651 mediacontrol_RGBPicture **
00652 mediacontrol_all_snapshots( mediacontrol_Instance *self,
00653                             mediacontrol_Exception *exception )
00654 {
00655     mediacontrol_RGBPicture **retval = NULL;
00656     vout_thread_t *p_vout = NULL;
00657     int i_datasize;
00658     int i_cachesize;
00659     vlc_value_t val;
00660     int i_index;
00661 #ifdef HAS_SNAPSHOT
00662     snapshot_t **pointer;
00663 #endif
00664 
00665     exception=mediacontrol_exception_init( exception );
00666 
00667     if( var_Get( self->p_playlist->p_input, "snapshot-id", &val ) == VLC_SUCCESS )
00668         p_vout = vlc_object_get( self->p_vlc, val.i_int );
00669 
00670     if( ! p_vout )
00671     {
00672         RAISE( mediacontrol_InternalException, "No snapshot module" );
00673         return NULL;
00674     }
00675 #ifdef HAS_SNAPSHOT
00676     /* We test if the vout is a snapshot module. We cannot test
00677        pvout_psz_object_name( which is NULL ). But we can check if
00678        there are snapshot-specific variables */
00679     if( var_Get( p_vout, "snapshot-datasize", &val ) != VLC_SUCCESS )
00680     {
00681         RAISE( mediacontrol_InternalException, "No snapshot module" );
00682         vlc_object_release( p_vout );
00683         return NULL;
00684     }
00685     i_datasize = val.i_int;
00686 
00687     vlc_mutex_lock( &p_vout->picture_lock );
00688 
00689     var_Get( p_vout, "snapshot-cache-size", &val );
00690     i_cachesize = val.i_int  ;
00691 
00692     var_Get( p_vout, "snapshot-list-pointer", &val );
00693     pointer = ( snapshot_t ** )val.p_address;
00694 
00695     if( ! pointer )
00696     {
00697         RAISE( mediacontrol_InternalException, "No available picture" );
00698 
00699         vlc_mutex_unlock( &p_vout->picture_lock );
00700         vlc_object_release( p_vout );
00701         return NULL;
00702     }
00703 
00704     retval = ( mediacontrol_RGBPicture** )malloc( (i_cachesize + 1 ) * sizeof( char* ));
00705 
00706     for( i_index = 0 ; i_index < i_cachesize ; i_index++ )
00707     {
00708         snapshot_t *p_s = pointer[i_index];
00709         mediacontrol_RGBPicture *p_rgb;
00710 
00711         p_rgb = _mediacontrol_createRGBPicture( p_s->i_width,
00712                                                 p_s->i_height,
00713                                                 p_vout->output.i_chroma,
00714                                                 p_s->date,
00715                                                 p_s->p_data,
00716                                                 i_datasize );
00717 
00718         retval[i_index] = p_rgb;
00719     }
00720 
00721     retval[i_cachesize] = NULL;
00722 
00723     vlc_mutex_unlock( &p_vout->picture_lock );
00724     vlc_object_release( p_vout );
00725 
00726 #endif
00727 
00728     return retval;
00729 }
00730 
00731 void
00732 mediacontrol_display_text( mediacontrol_Instance *self,
00733                            const char * message,
00734                            const mediacontrol_Position * begin,
00735                            const mediacontrol_Position * end,
00736                            mediacontrol_Exception *exception )
00737 {
00738     input_thread_t *p_input = NULL;
00739     vout_thread_t *p_vout = NULL;
00740 
00741     p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
00742     if( ! p_vout )
00743     {
00744         RAISE( mediacontrol_InternalException, "No video output" );
00745         return;
00746     }
00747 
00748     if( begin->origin == mediacontrol_RelativePosition &&
00749         begin->value == 0 &&
00750         end->origin == mediacontrol_RelativePosition )
00751     {
00752         mtime_t i_duration = 0;
00753 
00754         i_duration = 1000 * mediacontrol_unit_convert( self->p_playlist->p_input,
00755                                                        end->key,
00756                                                        mediacontrol_MediaTime,
00757                                                        end->value );
00758 
00759         vout_ShowTextRelative( p_vout, DEFAULT_CHAN, ( char* ) message, NULL,
00760                                OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 20, 20,
00761                                i_duration );
00762     }
00763     else
00764     {
00765         mtime_t i_debut, i_fin, i_now;
00766 
00767         p_input = self->p_playlist->p_input;
00768         if( ! p_input )
00769         {
00770             RAISE( mediacontrol_InternalException, "No input" );
00771             vlc_object_release( p_vout );
00772             return;
00773         }
00774 
00775         /* FIXME */
00776         /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
00777         i_now = 0;
00778         
00779         i_debut = mediacontrol_position2microsecond( p_input,
00780                                                      ( mediacontrol_Position* ) begin );
00781         i_debut += i_now;
00782 
00783         i_fin = mediacontrol_position2microsecond( p_input,
00784                                                    ( mediacontrol_Position * ) end );
00785         i_fin += i_now;
00786 
00787         vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, ( char* ) message, NULL,
00788                                OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 20, 20,
00789                                i_debut, i_fin );
00790     }
00791 
00792     vlc_object_release( p_vout );
00793 }
00794 
00795 mediacontrol_StreamInformation *
00796 mediacontrol_get_stream_information( mediacontrol_Instance *self,
00797                                      mediacontrol_PositionKey a_key,
00798                                      mediacontrol_Exception *exception )
00799 {
00800     mediacontrol_StreamInformation *retval;
00801     input_thread_t *p_input = self->p_playlist->p_input;
00802     vlc_value_t val;
00803 
00804     retval = ( mediacontrol_StreamInformation* )malloc( sizeof( mediacontrol_StreamInformation ) );
00805     if( ! retval )
00806     {
00807         RAISE( mediacontrol_InternalException, "Out of memory" );
00808         return NULL;
00809     }
00810 
00811     if( ! p_input )
00812     {
00813         /* No p_input defined */
00814         retval->streamstatus = mediacontrol_UndefinedStatus;
00815         retval->url          = strdup( "None" );
00816         retval->position     = 0;
00817         retval->length       = 0;
00818     }
00819     else
00820     {
00821         switch( var_GetInteger( p_input, "state" ) )
00822         {
00823         case PLAYING_S     :
00824             retval->streamstatus = mediacontrol_PlayingStatus;
00825             break;
00826         case PAUSE_S       :
00827             retval->streamstatus = mediacontrol_PauseStatus;
00828             break;
00829         case INIT_S        :
00830             retval->streamstatus = mediacontrol_InitStatus;
00831             break;
00832         case END_S         :
00833             retval->streamstatus = mediacontrol_EndStatus;
00834             break;
00835         default :
00836             retval->streamstatus = mediacontrol_UndefinedStatus;
00837             break;
00838         }
00839 
00840         retval->url = strdup( p_input->input.p_item->psz_uri );
00841 
00842         /* TIME and LENGTH are in microseconds. We want them in ms */
00843         var_Get( p_input, "time", &val);
00844         retval->position = val.i_time / 1000;
00845 
00846         var_Get( p_input, "length", &val);
00847         retval->length = val.i_time / 1000;
00848 
00849         retval->position = mediacontrol_unit_convert( p_input,
00850                                                       mediacontrol_MediaTime, a_key,
00851                                                       retval->position );
00852         retval->length   = mediacontrol_unit_convert( p_input,
00853                                                       mediacontrol_MediaTime, a_key,
00854                                                       retval->length );
00855     }
00856     return retval;
00857 }
00858 
00859 unsigned short
00860 mediacontrol_sound_get_volume( mediacontrol_Instance *self,
00861                                mediacontrol_Exception *exception )
00862 {
00863     short retval;
00864     audio_volume_t i_volume;
00865 
00866     if( !self->p_intf )
00867     {
00868         RAISE( mediacontrol_InternalException, "No interface module" );
00869         return 0;
00870     }
00871     aout_VolumeGet( self->p_intf, &i_volume );
00872     retval = i_volume;
00873     return retval;
00874 }
00875 
00876 void
00877 mediacontrol_sound_set_volume( mediacontrol_Instance *self,
00878                                const unsigned short volume,
00879                                mediacontrol_Exception *exception )
00880 {
00881     if( !self->p_intf )
00882     {
00883         RAISE( mediacontrol_InternalException, "No interface module" );
00884         return;
00885     }
00886     aout_VolumeSet( self->p_intf,( audio_volume_t )volume );
00887 }

Generated on Tue Dec 20 10:14:30 2005 for vlc-0.8.4a by  doxygen 1.4.2