Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]

Diff markup

Differences between /xawtv-3.94/libng/grab-ng.h (Version 2.6.11.8) and /xawtv-3.94/libng/grab-ng.h (Version 2.6.25.8)


  1 /*                                                  1 
  2  * next generation[tm] xawtv capture interface    
  3  *                                                
  4  * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org>    
  5  *                                                
  6  */                                               
  7                                                   
  8 #include <pthread.h>                              
  9 #include <sys/types.h>                            
 10                                                   
 11 #include "devices.h"                              
 12 #include "list.h"                                 
 13                                                   
 14 extern int  ng_debug;                             
 15 extern int  ng_chromakey;                         
 16 extern int  ng_jpeg_quality;                      
 17 extern int  ng_ratio_x;                           
 18 extern int  ng_ratio_y;                           
 19 extern char ng_v4l_conf[256];                     
 20                                                   
 21 #define BUG_ON(condition,message)       if (co    
 22         fprintf(stderr,"BUG: %s [%s:%d]\n",\      
 23                 message,__FILE__,__LINE__);\      
 24         exit(1);}                                 
 25                                                   
 26 #if __STDC_VERSION__ < 199901                     
 27 # define restrict                                 
 28 # define bool int                                 
 29 #endif                                            
 30                                                   
 31 #define UNSET          (-1U)                      
 32 #define DIMOF(array)   (sizeof(array)/sizeof(a    
 33 #define SDIMOF(array)  ((signed int)(sizeof(ar    
 34 #define GETELEM(array,index,default) \            
 35         (index < sizeof(array)/sizeof(array[0]    
 36                                                   
 37                                                   
 38 /* -------------------------------------------    
 39 /* defines                                        
 40                                                   
 41 #define VIDEO_NONE           0                    
 42 #define VIDEO_RGB08          1  /* bt848 dithe    
 43 #define VIDEO_GRAY           2                    
 44 #define VIDEO_RGB15_LE       3  /* 15 bpp litt    
 45 #define VIDEO_RGB16_LE       4  /* 16 bpp litt    
 46 #define VIDEO_RGB15_BE       5  /* 15 bpp big     
 47 #define VIDEO_RGB16_BE       6  /* 16 bpp big     
 48 #define VIDEO_BGR24          7  /* bgrbgrbgrbg    
 49 #define VIDEO_BGR32          8  /* bgr-bgr-bgr    
 50 #define VIDEO_RGB24          9  /* rgbrgbrgbrg    
 51 #define VIDEO_RGB32         10  /* -rgb-rgb-rg    
 52 #define VIDEO_LUT2          11  /* lookup-tabl    
 53 #define VIDEO_LUT4          12  /* lookup-tabl    
 54 #define VIDEO_YUYV          13  /* 4:2:2 */       
 55 #define VIDEO_YUV422P       14  /* YUV 4:2:2 (    
 56 #define VIDEO_YUV420P       15  /* YUV 4:2:0 (    
 57 #define VIDEO_MJPEG         16  /* MJPEG (AVI)    
 58 #define VIDEO_JPEG          17  /* JPEG (JFIF)    
 59 #define VIDEO_UYVY          18  /* 4:2:2 */       
 60 #define VIDEO_FMT_COUNT     19                    
 61                                                   
 62 #define AUDIO_NONE           0                    
 63 #define AUDIO_U8_MONO        1                    
 64 #define AUDIO_U8_STEREO      2                    
 65 #define AUDIO_S16_LE_MONO    3                    
 66 #define AUDIO_S16_LE_STEREO  4                    
 67 #define AUDIO_S16_BE_MONO    5                    
 68 #define AUDIO_S16_BE_STEREO  6                    
 69 #define AUDIO_MP3            7                    
 70 #define AUDIO_FMT_COUNT      8                    
 71                                                   
 72 #if BYTE_ORDER == BIG_ENDIAN                      
 73 # define AUDIO_S16_NATIVE_MONO   AUDIO_S16_BE_    
 74 # define AUDIO_S16_NATIVE_STEREO AUDIO_S16_BE_    
 75 # define VIDEO_RGB15_NATIVE      VIDEO_RGB15_B    
 76 # define VIDEO_RGB16_NATIVE      VIDEO_RGB16_B    
 77 #endif                                            
 78 #if BYTE_ORDER == LITTLE_ENDIAN                   
 79 # define AUDIO_S16_NATIVE_MONO   AUDIO_S16_LE_    
 80 # define AUDIO_S16_NATIVE_STEREO AUDIO_S16_LE_    
 81 # define VIDEO_RGB15_NATIVE      VIDEO_RGB15_L    
 82 # define VIDEO_RGB16_NATIVE      VIDEO_RGB16_L    
 83 #endif                                            
 84                                                   
 85 #define ATTR_TYPE_INTEGER    1   /*  range 0 -    
 86 #define ATTR_TYPE_CHOICE     2   /*  multiple     
 87 #define ATTR_TYPE_BOOL       3   /*  yes/no       
 88                                                   
 89 #define ATTR_ID_NORM         1                    
 90 #define ATTR_ID_INPUT        2                    
 91 #define ATTR_ID_VOLUME       3                    
 92 #define ATTR_ID_MUTE         4                    
 93 #define ATTR_ID_AUDIO_MODE   5                    
 94 #define ATTR_ID_COLOR        6                    
 95 #define ATTR_ID_BRIGHT       7                    
 96 #define ATTR_ID_HUE          8                    
 97 #define ATTR_ID_CONTRAST     9                    
 98 #define ATTR_ID_COUNT       10                    
 99                                                   
100 #define CAN_OVERLAY          1                    
101 #define CAN_CAPTURE          2                    
102 #define CAN_TUNE             4                    
103 #define NEEDS_CHROMAKEY      8                    
104                                                   
105 /* -------------------------------------------    
106                                                   
107 extern const unsigned int   ng_vfmt_to_depth[V    
108 extern const char*          ng_vfmt_to_desc[VI    
109                                                   
110 extern const unsigned int   ng_afmt_to_channel    
111 extern const unsigned int   ng_afmt_to_bits[AU    
112 extern const char*          ng_afmt_to_desc[AU    
113                                                   
114 extern const char*          ng_attr_to_desc[AT    
115                                                   
116 /* -------------------------------------------    
117                                                   
118 struct STRTAB {                                   
119     long nr;                                      
120     const char *str;                              
121 };                                                
122                                                   
123 struct OVERLAY_CLIP {                             
124     int x1,x2,y1,y2;                              
125 };                                                
126                                                   
127 /* -------------------------------------------    
128 /* video data structures                          
129                                                   
130 struct ng_video_fmt {                             
131     unsigned int   fmtid;         /* VIDEO_* *    
132     unsigned int   width;                         
133     unsigned int   height;                        
134     unsigned int   bytesperline;  /* zero for     
135 };                                                
136                                                   
137 struct ng_video_buf {                             
138     struct ng_video_fmt  fmt;                     
139     size_t               size;                    
140     unsigned char        *data;                   
141                                                   
142     /* meta info for frame */                     
143     struct {                                      
144         int64_t          ts;      /* time stam    
145         int              seq;                     
146         int              twice;                   
147     } info;                                       
148                                                   
149     /*                                            
150      * the lock is for the reference counter.     
151      * if the reference counter goes down to z    
152      * should be called.  priv is for the owne    
153      * buffer (can be used by the release call    
154      */                                           
155     pthread_mutex_t      lock;                    
156     pthread_cond_t       cond;                    
157     int                  refcount;                
158     void                 (*release)(struct ng_    
159     void                 *priv;                   
160 };                                                
161                                                   
162 void ng_init_video_buf(struct ng_video_buf *bu    
163 void ng_release_video_buf(struct ng_video_buf     
164 struct ng_video_buf* ng_malloc_video_buf(struc    
165                                          int s    
166 void ng_wakeup_video_buf(struct ng_video_buf *    
167 void ng_waiton_video_buf(struct ng_video_buf *    
168                                                   
169                                                   
170 /* -------------------------------------------    
171 /* audio data structures                          
172                                                   
173 struct ng_audio_fmt {                             
174     unsigned int   fmtid;         /* AUDIO_* *    
175     unsigned int   rate;                          
176 };                                                
177                                                   
178 struct ng_audio_buf {                             
179     struct ng_audio_fmt  fmt;                     
180     int                  size;                    
181     int                  written; /* for parti    
182     char                 *data;                   
183                                                   
184     struct {                                      
185         int64_t          ts;                      
186     } info;                                       
187 };                                                
188                                                   
189 struct ng_audio_buf* ng_malloc_audio_buf(struc    
190                                          int s    
191                                                   
192 /* -------------------------------------------    
193 /* someone who receives video and/or audio dat    
194                                                   
195 struct ng_format_list {                           
196     char           *name;                         
197     char           *desc;  /* if standard fmti    
198                               because it's con    
199     char           *ext;                          
200     unsigned int   fmtid;                         
201     void           *priv;                         
202 };                                                
203                                                   
204 struct ng_writer {                                
205     const char *name;                             
206     const char *desc;                             
207     const struct ng_format_list *video;           
208     const struct ng_format_list *audio;           
209     const int combined; /* both audio + video     
210                                                   
211     void* (*wr_open)(char *moviename, char *au    
212                      struct ng_video_fmt *vide    
213                      struct ng_audio_fmt *audi    
214     int (*wr_video)(void *handle, struct ng_vi    
215     int (*wr_audio)(void *handle, struct ng_au    
216     int (*wr_close)(void *handle);                
217                                                   
218     struct list_head list;                        
219 };                                                
220                                                   
221 struct ng_reader {                                
222     const char *name;                             
223     const char *desc;                             
224                                                   
225     char  *magic[4];                              
226     int   moff[4];                                
227     int   mlen[4];                                
228                                                   
229     void* (*rd_open)(char *moviename);            
230     struct ng_video_fmt* (*rd_vfmt)(void *hand    
231     struct ng_audio_fmt* (*rd_afmt)(void *hand    
232     struct ng_video_buf* (*rd_vdata)(void *han    
233     struct ng_audio_buf* (*rd_adata)(void *han    
234     int64_t (*frame_time)(void *handle);          
235     int (*rd_close)(void *handle);                
236                                                   
237     struct list_head list;                        
238 };                                                
239                                                   
240                                                   
241 /* -------------------------------------------    
242 /* attributes                                     
243                                                   
244 struct ng_attribute {                             
245     int                  id;                      
246     const char           *name;                   
247     int                  type;                    
248     int                  defval;                  
249     struct STRTAB        *choices;    /* ATTR_    
250     int                  min,max;     /* ATTR_    
251     int                  points;      /* ATTR_    
252     const void           *priv;                   
253     void                 *handle;                 
254     int         (*read)(struct ng_attribute*);    
255     void        (*write)(struct ng_attribute*,    
256 };                                                
257                                                   
258 struct ng_attribute* ng_attr_byid(struct ng_at    
259 struct ng_attribute* ng_attr_byname(struct ng_    
260 const char* ng_attr_getstr(struct ng_attribute    
261 int ng_attr_getint(struct ng_attribute *attr,     
262 void ng_attr_listchoices(struct ng_attribute *    
263 int ng_attr_int2percent(struct ng_attribute *a    
264 int ng_attr_percent2int(struct ng_attribute *a    
265 int ng_attr_parse_int(struct ng_attribute *att    
266                                                   
267 /* -------------------------------------------    
268                                                   
269 void ng_ratio_fixup(int *width, int *height, i    
270 void ng_ratio_fixup2(int *width, int *height,     
271                      int ratio_x, int ratio_y,    
272                                                   
273 /* -------------------------------------------    
274 /* device informations                            
275                                                   
276 struct ng_devinfo {                               
277     char  device[32];                             
278     char  name[64];                               
279     int   flags;                                  
280 };                                                
281                                                   
282 /* -------------------------------------------    
283 /* capture/overlay interface driver               
284                                                   
285 struct ng_vid_driver {                            
286     const char *name;                             
287                                                   
288     /* open/close */                              
289     void*  (*open)(char *device);                 
290     int    (*close)(void *handle);                
291                                                   
292     /* attributes */                              
293     char* (*get_devname)(void *handle);           
294     int   (*capabilities)(void *handle);          
295     struct ng_attribute* (*list_attrs)(void *h    
296                                                   
297     /* overlay */                                 
298     int   (*setupfb)(void *handle, struct ng_v    
299     int   (*overlay)(void *handle, struct ng_v    
300                      struct OVERLAY_CLIP *oc,     
301                                                   
302     /* capture */                                 
303     int   (*setformat)(void *handle, struct ng    
304     int   (*startvideo)(void *handle, int fps,    
305     void  (*stopvideo)(void *handle);             
306     struct ng_video_buf* (*nextframe)(void *ha    
307     struct ng_video_buf* (*getimage)(void *han    
308                                                   
309     /* tuner */                                   
310     unsigned long (*getfreq)(void *handle);       
311     void  (*setfreq)(void *handle, unsigned lo    
312     int   (*is_tuned)(void *handle);              
313                                                   
314     struct list_head list;                        
315 };                                                
316                                                   
317                                                   
318 /* -------------------------------------------    
319 /* sound driver                                   
320                                                   
321 struct ng_dsp_driver {                            
322     const char            *name;                  
323     void*                 (*open)(char *device    
324                                   int record);    
325     void                  (*close)(void *handl    
326     int                   (*fd)(void *handle);    
327     int                   (*startrec)(void *ha    
328     struct ng_audio_buf*  (*read)(void *handle    
329     struct ng_audio_buf*  (*write)(void *handl    
330     int64_t               (*latency)(void *han    
331                                                   
332     struct list_head      list;                   
333 };                                                
334                                                   
335 struct ng_mix_driver {                            
336     const char            *name;                  
337     struct ng_devinfo*    (*probe)(void);         
338     struct ng_devinfo*    (*channels)(char *de    
339     void*                 (*open)(char *device    
340     struct ng_attribute*  (*volctl)(void *hand    
341     void                  (*close)(void *handl    
342                                                   
343     struct list_head      list;                   
344 };                                                
345                                                   
346                                                   
347 /* -------------------------------------------    
348 /* color space converters                         
349                                                   
350 struct ng_video_conv {                            
351     unsigned int          fmtid_in;               
352     unsigned int          fmtid_out;              
353     void*                 (*init)(struct ng_vi    
354                                   void *priv);    
355     void                  (*frame)(void *handl    
356                                    struct ng_v    
357                                    struct ng_v    
358     void                  (*fini)(void *handle    
359     void                  *priv;                  
360                                                   
361     struct list_head      list;                   
362 };                                                
363                                                   
364 struct ng_convert_handle {                        
365     struct ng_video_fmt     ifmt;                 
366     struct ng_video_fmt     ofmt;                 
367     int                     isize;                
368     int                     osize;                
369     struct ng_video_conv    *conv;                
370     void                    *chandle;             
371 };                                                
372                                                   
373 struct ng_convert_handle* ng_convert_alloc(str    
374                                            str    
375                                            str    
376 void ng_convert_init(struct ng_convert_handle     
377 struct ng_video_buf* ng_convert_frame(struct n    
378                                       struct n    
379                                       struct n    
380 void ng_convert_fini(struct ng_convert_handle     
381 struct ng_video_buf* ng_convert_single(struct     
382                                        struct     
383                                                   
384 /* -------------------------------------------    
385 /* audio converters                               
386                                                   
387 struct ng_audio_conv {                            
388     unsigned int          fmtid_in;               
389     unsigned int          fmtid_out;              
390     void*                 (*init)(void *priv);    
391     struct ng_audio_buf*  (*frame)(void *handl    
392                                    struct ng_a    
393     void                  (*fini)(void *handle    
394     void                  *priv;                  
395                                                   
396     struct list_head      list;                   
397 };                                                
398                                                   
399 /* -------------------------------------------    
400 /* filters                                        
401                                                   
402 struct ng_filter {                                
403     char                  *name;                  
404     int                   fmts;                   
405     struct ng_attribute*  attrs;                  
406     void*                 (*init)(struct ng_vi    
407     struct ng_video_buf*  (*frame)(void *handl    
408                                    struct ng_v    
409     void                  (*fini)(void *handle    
410                                                   
411     struct list_head      list;                   
412 };                                                
413                                                   
414 /* -------------------------------------------    
415                                                   
416 /* must be changed if we break compatibility *    
417 #define NG_PLUGIN_MAGIC 0x20030129                
418                                                   
419 extern struct list_head ng_conv;                  
420 extern struct list_head ng_aconv;                 
421 extern struct list_head ng_filters;               
422 extern struct list_head ng_writers;               
423 extern struct list_head ng_readers;               
424 extern struct list_head ng_vid_drivers;           
425 extern struct list_head ng_dsp_drivers;           
426 extern struct list_head ng_mix_drivers;           
427                                                   
428 int ng_conv_register(int magic, char *plugname    
429                      struct ng_video_conv *lis    
430 int ng_aconv_register(int magic, char *plugnam    
431                       struct ng_audio_conv *li    
432 int ng_filter_register(int magic, char *plugna    
433                        struct ng_filter *filte    
434 int ng_writer_register(int magic, char *plugna    
435                        struct ng_writer *write    
436 int ng_reader_register(int magic, char *plugna    
437                        struct ng_reader *reade    
438 int ng_vid_driver_register(int magic, char *pl    
439                            struct ng_vid_drive    
440 int ng_dsp_driver_register(int magic, char *pl    
441                            struct ng_dsp_drive    
442 int ng_mix_driver_register(int magic, char *pl    
443                            struct ng_mix_drive    
444                                                   
445 struct ng_video_conv* ng_conv_find_to(unsigned    
446 struct ng_video_conv* ng_conv_find_from(unsign    
447 struct ng_video_conv* ng_conv_find_match(unsig    
448                                                   
449 const struct ng_vid_driver* ng_vid_open(char *    
450                                         struct    
451                                         void *    
452 const struct ng_dsp_driver* ng_dsp_open(char *    
453                                         int re    
454 struct ng_attribute* ng_mix_init(char *device,    
455 struct ng_reader* ng_find_reader(char *filenam    
456                                                   
457 int64_t ng_tofday_to_timestamp(struct timeval     
458 int64_t ng_get_timestamp(void);                   
459 void ng_check_clipping(int width, int height,     
460                        struct OVERLAY_CLIP *oc    
461 struct ng_video_buf* ng_filter_single(struct n    
462                                       struct n    
463                                                   
464 /* -------------------------------------------    
465                                                   
466 void ng_init(void);                               
467 void ng_lut_init(unsigned long red_mask, unsig    
468                  unsigned long blue_mask, unsi    
469                                                   
470 void ng_rgb24_to_lut2(unsigned char *dest, uns    
471 void ng_rgb24_to_lut4(unsigned char *dest, uns    
472                                                   
473 /* -------------------------------------------    
474 /* internal stuff starts here                     
475                                                   
476 #ifdef NG_PRIVATE                                 
477                                                   
478 /* init functions */                              
479 void ng_color_packed_init(void);                  
480 void ng_color_yuv2rgb_init(void);                 
481 void ng_writefile_init(void);                     
482                                                   
483 /* for yuv2rgb using lookup tables (color_lut.    
484 unsigned long   ng_lut_red[256];                  
485 unsigned long   ng_lut_green[256];                
486 unsigned long   ng_lut_blue[256];                 
487 void ng_yuv422_to_lut2(unsigned char *dest, un    
488 void ng_yuv422_to_lut4(unsigned char *dest, un    
489 void ng_yuv420p_to_lut2(void *h, struct ng_vid    
490                         struct ng_video_buf *i    
491 void ng_yuv420p_to_lut4(void *h, struct ng_vid    
492                         struct ng_video_buf *i    
493 void ng_yuv422p_to_lut2(void *h, struct ng_vid    
494                         struct ng_video_buf *i    
495 void ng_yuv422p_to_lut4(void *h, struct ng_vid    
496                         struct ng_video_buf *i    
497                                                   
498 /* color_common.c stuff */                        
499 void* ng_packed_init(struct ng_video_fmt *out,    
500 void  ng_packed_frame(void *handle, struct ng_    
501                       struct ng_video_buf *in)    
502 void* ng_conv_nop_init(struct ng_video_fmt *ou    
503 void  ng_conv_nop_fini(void *handle);             
504                                                   
505 #define NG_GENERIC_PACKED                         
506         init:           ng_packed_init,           
507         frame:          ng_packed_frame,          
508         fini:           ng_conv_nop_fini          
509                                                   
510 #endif /* NG_PRIVATE */                           
511                                                   
512 /* -------------------------------------------    
513 /*                                                
514  * Local variables:                               
515  * compile-command: "(cd ..; make)"               
516  * End:                                           
517  */                                               
518                                                   
  This page was automatically generated by the LXR engine.