00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <vlc/control.h>
00025
00026 #include <vlc/intf.h>
00027 #include <vlc/vout.h>
00028 #include <vlc/aout.h>
00029 #include <vlc_demux.h>
00030
00031 #include <vlc_osd.h>
00032
00033 #define HAS_SNAPSHOT 1
00034
00035 #ifdef HAS_SNAPSHOT
00036 #include <snapshot.h>
00037 #endif
00038
00039 #include <stdlib.h>
00040 #include <string.h>
00041
00042 #include <errno.h>
00043 #include <stdio.h>
00044 #include <ctype.h>
00045
00046 #ifdef HAVE_UNISTD_H
00047 # include <unistd.h>
00048 #endif
00049 #ifdef HAVE_SYS_TIME_H
00050 # include <sys/time.h>
00051 #endif
00052 #ifdef HAVE_SYS_TYPES_H
00053 # include <sys/types.h>
00054 #endif
00055
00056 #define RAISE( c, m ) exception->code = c; \
00057 exception->message = strdup(m);
00058
00059 vlc_int64_t mediacontrol_unit_convert( input_thread_t *p_input,
00060 mediacontrol_PositionKey from,
00061 mediacontrol_PositionKey to,
00062 vlc_int64_t value )
00063 {
00064 if( to == from )
00065 return value;
00066
00067
00068 if( !p_input )
00069 return 0;
00070
00071 switch( from )
00072 {
00073 case mediacontrol_MediaTime:
00074 if( to == mediacontrol_ByteCount )
00075 {
00076
00077
00078
00079 return 0;
00080 }
00081 if( to == mediacontrol_SampleCount )
00082 {
00083 double f_fps;
00084
00085 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
00086 return 0;
00087 else
00088 return( value * f_fps / 1000.0 );
00089 }
00090
00091
00092 break;
00093
00094 case mediacontrol_SampleCount:
00095 {
00096 double f_fps;
00097
00098 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
00099 return 0;
00100
00101 if( to == mediacontrol_ByteCount )
00102 {
00103
00104
00105
00106 return 0;
00107 }
00108
00109 if( to == mediacontrol_MediaTime )
00110 return( vlc_int64_t )( value * 1000.0 / ( double )f_fps );
00111
00112
00113 break;
00114 }
00115 case mediacontrol_ByteCount:
00116
00117 return 0;
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 break;
00140 }
00141
00142 return 0;
00143 }
00144
00145
00146
00147 vlc_int64_t
00148 mediacontrol_position2microsecond( input_thread_t* p_input, const mediacontrol_Position * pos )
00149 {
00150 switch( pos->origin )
00151 {
00152 case mediacontrol_AbsolutePosition:
00153 return ( 1000 * mediacontrol_unit_convert( p_input,
00154 pos->key,
00155 mediacontrol_MediaTime,
00156 pos->value ) );
00157 break;
00158 case mediacontrol_RelativePosition:
00159 {
00160 vlc_int64_t l_pos;
00161 vlc_value_t val;
00162
00163 val.i_time = 0;
00164 if( p_input )
00165 {
00166 var_Get( p_input, "time", &val );
00167 }
00168
00169 l_pos = 1000 * mediacontrol_unit_convert( p_input,
00170 pos->key,
00171 mediacontrol_MediaTime,
00172 pos->value );
00173 return val.i_time + l_pos;
00174 break;
00175 }
00176 case mediacontrol_ModuloPosition:
00177 {
00178 vlc_int64_t l_pos;
00179 vlc_value_t val;
00180
00181 val.i_time = 0;
00182 if( p_input )
00183 {
00184 var_Get( p_input, "length", &val );
00185 }
00186
00187 if( val.i_time > 0)
00188 {
00189 l_pos = ( 1000 * mediacontrol_unit_convert( p_input,
00190 pos->key,
00191 mediacontrol_MediaTime,
00192 pos->value ) );
00193 }
00194 else
00195 l_pos = 0;
00196
00197 return l_pos % val.i_time;
00198 break;
00199 }
00200 }
00201 return 0;
00202 }
00203
00204 mediacontrol_RGBPicture*
00205 mediacontrol_RGBPicture__alloc( int datasize )
00206 {
00207 mediacontrol_RGBPicture* pic;
00208
00209 pic = ( mediacontrol_RGBPicture * )malloc( sizeof( mediacontrol_RGBPicture ) );
00210 if( ! pic )
00211 return NULL;
00212
00213 pic->size = datasize;
00214 pic->data = ( char* )malloc( datasize );
00215 return pic;
00216 }
00217
00218 void
00219 mediacontrol_RGBPicture__free( mediacontrol_RGBPicture* pic )
00220 {
00221 if( pic )
00222 free( pic->data );
00223 free( pic );
00224 }
00225
00226 mediacontrol_PlaylistSeq*
00227 mediacontrol_PlaylistSeq__alloc( int size )
00228 {
00229 mediacontrol_PlaylistSeq* ps;
00230
00231 ps =( mediacontrol_PlaylistSeq* )malloc( sizeof( mediacontrol_PlaylistSeq ) );
00232 if( ! ps )
00233 return NULL;
00234
00235 ps->size = size;
00236 ps->data = ( char** )malloc( size * sizeof( char* ) );
00237 return ps;
00238 }
00239
00240 void
00241 mediacontrol_PlaylistSeq__free( mediacontrol_PlaylistSeq* ps )
00242 {
00243 if( ps )
00244 {
00245 int i;
00246 for( i = 0 ; i < ps->size ; i++ )
00247 free( ps->data[i] );
00248 }
00249 free( ps->data );
00250 free( ps );
00251 }
00252
00253 mediacontrol_Exception*
00254 mediacontrol_exception_init( mediacontrol_Exception *exception )
00255 {
00256 if( exception == NULL )
00257 {
00258 exception = ( mediacontrol_Exception* )malloc( sizeof( mediacontrol_Exception ) );
00259 }
00260
00261 exception->code = 0;
00262 exception->message = NULL;
00263 return exception;
00264 }
00265
00266 void
00267 mediacontrol_exception_free( mediacontrol_Exception *exception )
00268 {
00269 if( ! exception )
00270 return;
00271
00272 free( exception->message );
00273 free( exception );
00274 }
00275
00276 mediacontrol_RGBPicture*
00277 _mediacontrol_createRGBPicture( int i_width, int i_height, long i_chroma, vlc_int64_t l_date,
00278 char* p_data, int i_datasize )
00279 {
00280 mediacontrol_RGBPicture *retval;
00281
00282 retval = mediacontrol_RGBPicture__alloc( i_datasize );
00283 if( retval )
00284 {
00285 retval->width = i_width;
00286 retval->height = i_height;
00287 retval->type = i_chroma;
00288 retval->date = l_date;
00289 retval->size = i_datasize;
00290 memcpy( retval->data, p_data, i_datasize );
00291 }
00292 return retval;
00293 }