LiVES 1.3.11-svn
|
00001 // LiVES - decoder plugin header 00002 // (c) G. Finch 2008 <salsaman@xs4all.nl> 00003 // released under the GNU GPL 3 or later 00004 // see file COPYING or www.gnu.org for details 00005 00006 00007 #ifndef __DECPLUGIN_H__ 00008 #define __DECPLUGIN_H__ 00009 00010 #ifdef __cplusplus 00011 extern "C" 00012 { 00013 #endif /* __cplusplus */ 00014 00015 #include <inttypes.h> 00016 #include <sys/types.h> 00017 00018 // palettes, etc. 00019 #ifdef HAVE_SYSTEM_WEED 00020 #include "weed/weed-palettes.h" 00021 #else 00022 #include "../../../libweed/weed-palettes.h" 00023 #endif 00024 00025 #ifdef IS_DARWIN 00026 #ifndef lseek64 00027 #define lseek64 lseek 00028 #endif 00029 #ifndef off64_t 00030 #define off64_t off_t 00031 #endif 00032 #endif 00033 00034 00035 typedef int boolean; 00036 #undef TRUE 00037 #undef FALSE 00038 #define TRUE 1 00039 #define FALSE 0 00040 00041 typedef enum { 00042 LIVES_INTERLACE_NONE=0, 00043 LIVES_INTERLACE_BOTTOM_FIRST=1, 00044 LIVES_INTERLACE_TOP_FIRST=2 00045 } lives_interlace_t; 00046 00048 #define LIVES_SEEK_FAST (1<<0) 00049 00051 #define LIVES_SEEK_NEEDS_CALCULATION (1<<1) 00052 #define LIVES_SEEK_QUALITY_LOSS (1<<2) 00053 00054 00055 typedef struct { 00056 char *URI; 00057 00058 int nclips; 00059 char container_name[512]; 00060 00062 int current_clip; 00063 00064 // video data 00065 int width; 00066 int height; 00067 int64_t nframes; 00068 lives_interlace_t interlace; 00069 00072 int offs_x; 00073 int offs_y; 00074 int frame_width; 00075 int frame_height; 00076 00077 float par; 00078 00079 float fps; 00080 00081 int *palettes; 00082 00084 int current_palette; 00085 00086 int YUV_sampling; 00087 int YUV_clamping; 00088 int YUV_subspace; 00089 char video_name[512]; 00090 00091 /* audio data */ 00092 int arate; 00093 int achans; 00094 int asamps; 00095 boolean asigned; 00096 boolean ainterleaf; 00097 char audio_name[512]; 00098 00099 int seek_flag; 00100 00101 void *priv; 00102 00103 } lives_clip_data_t; 00104 00105 00106 00107 // std functions 00108 const char *version(void); 00109 00110 00115 00116 lives_clip_data_t *get_clip_data(const char *URI, lives_clip_data_t *clip_data); 00117 00119 boolean get_frame(const lives_clip_data_t *cdata, int64_t frame, void **pixel_data); 00120 00122 void clip_data_free(lives_clip_data_t *); 00123 00124 00125 00126 00127 // opt fns 00128 const char *module_check_init(void); 00129 00130 int64_t rip_audio (const lives_clip_data_t *, const char *fname, int64_t stframe, int64_t nframes, unsigned char **abuff); 00131 void rip_audio_cleanup(const lives_clip_data_t *); 00132 00133 void module_unload(void); 00134 00135 00136 00137 00138 00139 #define MK_FOURCC(a, b, c, d) ((a<<24)|(b<<16)|(c<<8)|d) 00140 00141 00142 00143 00144 00145 00146 // bitstream functions from vlc 00147 00148 00149 00150 typedef struct bs_s 00151 { 00152 uint8_t *p_start; 00153 uint8_t *p; 00154 uint8_t *p_end; 00155 00156 ssize_t i_left; 00157 } bs_t; 00158 00159 static inline void bs_init( bs_t *s, const void *p_data, size_t i_data ) 00160 { 00161 s->p_start = (void *)p_data; 00162 s->p = s->p_start; 00163 s->p_end = s->p_start + i_data; 00164 s->i_left = 8; 00165 } 00166 00167 static inline int bs_pos( const bs_t *s ) 00168 { 00169 return( 8 * ( s->p - s->p_start ) + 8 - s->i_left ); 00170 } 00171 00172 static inline int bs_eof( const bs_t *s ) 00173 { 00174 return( s->p >= s->p_end ? 1: 0 ); 00175 } 00176 00177 static inline uint32_t bs_read( bs_t *s, int i_count ) 00178 { 00179 static const uint32_t i_mask[33] = 00180 { 0x00, 00181 0x01, 0x03, 0x07, 0x0f, 00182 0x1f, 0x3f, 0x7f, 0xff, 00183 0x1ff, 0x3ff, 0x7ff, 0xfff, 00184 0x1fff, 0x3fff, 0x7fff, 0xffff, 00185 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 00186 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 00187 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 00188 0x1fffffff,0x3fffffff,0x7fffffff,0xffffffff}; 00189 int i_shr; 00190 uint32_t i_result = 0; 00191 00192 while( i_count > 0 ) 00193 { 00194 if( s->p >= s->p_end ) 00195 { 00196 break; 00197 } 00198 00199 if( ( i_shr = s->i_left - i_count ) >= 0 ) 00200 { 00201 /* more in the buffer than requested */ 00202 i_result |= ( *s->p >> i_shr )&i_mask[i_count]; 00203 s->i_left -= i_count; 00204 if( s->i_left == 0 ) 00205 { 00206 s->p++; 00207 s->i_left = 8; 00208 } 00209 return( i_result ); 00210 } 00211 else 00212 { 00213 /* less in the buffer than requested */ 00214 i_result |= (*s->p&i_mask[s->i_left]) << -i_shr; 00215 i_count -= s->i_left; 00216 s->p++; 00217 s->i_left = 8; 00218 } 00219 } 00220 00221 return( i_result ); 00222 } 00223 00224 static inline uint32_t bs_read1( bs_t *s ) 00225 { 00226 if( s->p < s->p_end ) 00227 { 00228 unsigned int i_result; 00229 00230 s->i_left--; 00231 i_result = ( *s->p >> s->i_left )&0x01; 00232 if( s->i_left == 0 ) 00233 { 00234 s->p++; 00235 s->i_left = 8; 00236 } 00237 return i_result; 00238 } 00239 00240 return 0; 00241 } 00242 00243 static inline uint32_t bs_show( bs_t *s, int i_count ) 00244 { 00245 bs_t s_tmp = *s; 00246 return bs_read( &s_tmp, i_count ); 00247 } 00248 00249 static inline void bs_skip( bs_t *s, ssize_t i_count ) 00250 { 00251 s->i_left -= i_count; 00252 00253 if( s->i_left <= 0 ) 00254 { 00255 const int i_bytes = ( -s->i_left + 8 ) / 8; 00256 00257 s->p += i_bytes; 00258 s->i_left += 8 * i_bytes; 00259 } 00260 } 00261 00262 static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits ) 00263 { 00264 while( i_count > 0 ) 00265 { 00266 if( s->p >= s->p_end ) 00267 { 00268 break; 00269 } 00270 00271 i_count--; 00272 00273 if( ( i_bits >> i_count )&0x01 ) 00274 { 00275 *s->p |= 1 << ( s->i_left - 1 ); 00276 } 00277 else 00278 { 00279 *s->p &= ~( 1 << ( s->i_left - 1 ) ); 00280 } 00281 s->i_left--; 00282 if( s->i_left == 0 ) 00283 { 00284 s->p++; 00285 s->i_left = 8; 00286 } 00287 } 00288 } 00289 00290 static inline void bs_align( bs_t *s ) 00291 { 00292 if( s->i_left != 8 ) 00293 { 00294 s->i_left = 8; 00295 s->p++; 00296 } 00297 } 00298 00299 static inline void bs_align_0( bs_t *s ) 00300 { 00301 if( s->i_left != 8 ) 00302 { 00303 bs_write( s, s->i_left, 0 ); 00304 } 00305 } 00306 00307 static inline void bs_align_1( bs_t *s ) 00308 { 00309 while( s->i_left != 8 ) 00310 { 00311 bs_write( s, 1, 1 ); 00312 } 00313 } 00314 00315 00316 #ifdef __cplusplus 00317 } 00318 #endif /* __cplusplus */ 00319 00320 #endif // #ifndef __DECPLUGIN_H__