videocodec.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * VIDEO MOTION CODECs internal API for video devices
  3. *
  4. * Interface for MJPEG (and maybe later MPEG/WAVELETS) codec's
  5. * bound to a master device.
  6. *
  7. * (c) 2002 Wolfgang Scherr <scherr@net4you.at>
  8. *
  9. * $Id: videocodec.h,v 1.1.2.4 2003/01/14 21:15:03 rbultje Exp $
  10. *
  11. * ------------------------------------------------------------------------
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. *
  27. * ------------------------------------------------------------------------
  28. */
  29. /* =================== */
  30. /* general description */
  31. /* =================== */
  32. /* Should ease the (re-)usage of drivers supporting cards with (different)
  33. video codecs. The codecs register to this module their functionality,
  34. and the processors (masters) can attach to them if they fit.
  35. The codecs are typically have a "strong" binding to their master - so I
  36. don't think it makes sense to have a full blown interfacing as with e.g.
  37. i2c. If you have an other opinion, let's discuss & implement it :-)))
  38. Usage:
  39. The slave has just to setup the videocodec structure and use two functions:
  40. videocodec_register(codecdata);
  41. videocodec_unregister(codecdata);
  42. The best is just calling them at module (de-)initialisation.
  43. The master sets up the structure videocodec_master and calls:
  44. codecdata=videocodec_attach(master_codecdata);
  45. videocodec_detach(codecdata);
  46. The slave is called during attach/detach via functions setup previously
  47. during register. At that time, the master_data pointer is set up
  48. and the slave can access any io registers of the master device (in the case
  49. the slave is bound to it). Otherwise it doesn't need this functions and
  50. therfor they may not be initialized.
  51. The other functions are just for convenience, as they are for sure used by
  52. most/all of the codecs. The last ones may be omitted, too.
  53. See the structure declaration below for more information and which data has
  54. to be set up for the master and the slave.
  55. ----------------------------------------------------------------------------
  56. The master should have "knowledge" of the slave and vice versa. So the data
  57. structures sent to/from slave via set_data/get_data set_image/get_image are
  58. device dependent and vary between MJPEG/MPEG/WAVELET/... devices. (!!!!)
  59. ----------------------------------------------------------------------------
  60. */
  61. /* ========================================== */
  62. /* description of the videocodec_io structure */
  63. /* ========================================== */
  64. /*
  65. ==== master setup ====
  66. name -> name of the device structure for reference and debugging
  67. master_data -> data ref. for the master (e.g. the zr36055,57,67)
  68. readreg -> ref. to read-fn from register (setup by master, used by slave)
  69. writereg -> ref. to write-fn to register (setup by master, used by slave)
  70. this two functions do the lowlevel I/O job
  71. ==== slave functionality setup ====
  72. slave_data -> data ref. for the slave (e.g. the zr36050,60)
  73. check -> fn-ref. checks availability of an device, returns -EIO on failure or
  74. the type on success
  75. this makes espcecially sense if a driver module supports more than
  76. one codec which may be quite similar to access, nevertheless it
  77. is good for a first functionality check
  78. -- main functions you always need for compression/decompression --
  79. set_mode -> this fn-ref. resets the entire codec, and sets up the mode
  80. with the last defined norm/size (or device default if not
  81. available) - it returns 0 if the mode is possible
  82. set_size -> this fn-ref. sets the norm and image size for
  83. compression/decompression (returns 0 on success)
  84. the norm param is defined in videodev2.h (V4L2_STD_*)
  85. additional setup may be available, too - but the codec should work with
  86. some default values even without this
  87. set_data -> sets device-specific data (tables, quality etc.)
  88. get_data -> query device-specific data (tables, quality etc.)
  89. if the device delivers interrupts, they may be setup/handled here
  90. setup_interrupt -> codec irq setup (not needed for 36050/60)
  91. handle_interrupt -> codec irq handling (not needed for 36050/60)
  92. if the device delivers pictures, they may be handled here
  93. put_image -> puts image data to the codec (not needed for 36050/60)
  94. get_image -> gets image data from the codec (not needed for 36050/60)
  95. the calls include frame numbers and flags (even/odd/...)
  96. if needed and a flag which allows blocking until its ready
  97. */
  98. /* ============== */
  99. /* user interface */
  100. /* ============== */
  101. /*
  102. Currently there is only a information display planned, as the layer
  103. is not visible for the user space at all.
  104. Information is available via procfs. The current entry is "/proc/videocodecs"
  105. but it makes sense to "hide" it in the /proc/video tree of v4l(2) --TODO--.
  106. A example for such an output is:
  107. <S>lave or attached <M>aster name type flags magic (connected as)
  108. S zr36050 0002 0000d001 00000000 (TEMPLATE)
  109. M zr36055[0] 0001 0000c001 00000000 (zr36050[0])
  110. M zr36055[1] 0001 0000c001 00000000 (zr36050[1])
  111. */
  112. /* =============================================== */
  113. /* special defines for the videocodec_io structure */
  114. /* =============================================== */
  115. #ifndef __LINUX_VIDEOCODEC_H
  116. #define __LINUX_VIDEOCODEC_H
  117. #include <linux/videodev2.h>
  118. #define CODEC_DO_COMPRESSION 0
  119. #define CODEC_DO_EXPANSION 1
  120. /* this are the current codec flags I think they are needed */
  121. /* -> type value in structure */
  122. #define CODEC_FLAG_JPEG 0x00000001L // JPEG codec
  123. #define CODEC_FLAG_MPEG 0x00000002L // MPEG1/2/4 codec
  124. #define CODEC_FLAG_DIVX 0x00000004L // DIVX codec
  125. #define CODEC_FLAG_WAVELET 0x00000008L // WAVELET codec
  126. // room for other types
  127. #define CODEC_FLAG_MAGIC 0x00000800L // magic key must match
  128. #define CODEC_FLAG_HARDWARE 0x00001000L // is a hardware codec
  129. #define CODEC_FLAG_VFE 0x00002000L // has direct video frontend
  130. #define CODEC_FLAG_ENCODER 0x00004000L // compression capability
  131. #define CODEC_FLAG_DECODER 0x00008000L // decompression capability
  132. #define CODEC_FLAG_NEEDIRQ 0x00010000L // needs irq handling
  133. #define CODEC_FLAG_RDWRPIC 0x00020000L // handles picture I/O
  134. /* a list of modes, some are just examples (is there any HW?) */
  135. #define CODEC_MODE_BJPG 0x0001 // Baseline JPEG
  136. #define CODEC_MODE_LJPG 0x0002 // Lossless JPEG
  137. #define CODEC_MODE_MPEG1 0x0003 // MPEG 1
  138. #define CODEC_MODE_MPEG2 0x0004 // MPEG 2
  139. #define CODEC_MODE_MPEG4 0x0005 // MPEG 4
  140. #define CODEC_MODE_MSDIVX 0x0006 // MS DivX
  141. #define CODEC_MODE_ODIVX 0x0007 // Open DivX
  142. #define CODEC_MODE_WAVELET 0x0008 // Wavelet
  143. /* this are the current codec types I want to implement */
  144. /* -> type value in structure */
  145. #define CODEC_TYPE_NONE 0
  146. #define CODEC_TYPE_L64702 1
  147. #define CODEC_TYPE_ZR36050 2
  148. #define CODEC_TYPE_ZR36016 3
  149. #define CODEC_TYPE_ZR36060 4
  150. /* the type of data may be enhanced by future implementations (data-fn.'s) */
  151. /* -> used in command */
  152. #define CODEC_G_STATUS 0x0000 /* codec status (query only) */
  153. #define CODEC_S_CODEC_MODE 0x0001 /* codec mode (baseline JPEG, MPEG1,... */
  154. #define CODEC_G_CODEC_MODE 0x8001
  155. #define CODEC_S_VFE 0x0002 /* additional video frontend setup */
  156. #define CODEC_G_VFE 0x8002
  157. #define CODEC_S_MMAP 0x0003 /* MMAP setup (if available) */
  158. #define CODEC_S_JPEG_TDS_BYTE 0x0010 /* target data size in bytes */
  159. #define CODEC_G_JPEG_TDS_BYTE 0x8010
  160. #define CODEC_S_JPEG_SCALE 0x0011 /* scaling factor for quant. tables */
  161. #define CODEC_G_JPEG_SCALE 0x8011
  162. #define CODEC_S_JPEG_HDT_DATA 0x0018 /* huffman-tables */
  163. #define CODEC_G_JPEG_HDT_DATA 0x8018
  164. #define CODEC_S_JPEG_QDT_DATA 0x0019 /* quantizing-tables */
  165. #define CODEC_G_JPEG_QDT_DATA 0x8019
  166. #define CODEC_S_JPEG_APP_DATA 0x001A /* APP marker */
  167. #define CODEC_G_JPEG_APP_DATA 0x801A
  168. #define CODEC_S_JPEG_COM_DATA 0x001B /* COM marker */
  169. #define CODEC_G_JPEG_COM_DATA 0x801B
  170. #define CODEC_S_PRIVATE 0x1000 /* "private" commands start here */
  171. #define CODEC_G_PRIVATE 0x9000
  172. #define CODEC_G_FLAG 0x8000 /* this is how 'get' is detected */
  173. /* types of transfer, directly user space or a kernel buffer (image-fn.'s) */
  174. /* -> used in get_image, put_image */
  175. #define CODEC_TRANSFER_KERNEL 0 /* use "memcopy" */
  176. #define CODEC_TRANSFER_USER 1 /* use "to/from_user" */
  177. /* ========================= */
  178. /* the structures itself ... */
  179. /* ========================= */
  180. struct vfe_polarity {
  181. unsigned int vsync_pol:1;
  182. unsigned int hsync_pol:1;
  183. unsigned int field_pol:1;
  184. unsigned int blank_pol:1;
  185. unsigned int subimg_pol:1;
  186. unsigned int poe_pol:1;
  187. unsigned int pvalid_pol:1;
  188. unsigned int vclk_pol:1;
  189. };
  190. struct vfe_settings {
  191. __u32 x, y; /* Offsets into image */
  192. __u32 width, height; /* Area to capture */
  193. __u16 decimation; /* Decimation divider */
  194. __u16 flags; /* Flags for capture */
  195. __u16 quality; /* quality of the video */
  196. };
  197. struct tvnorm {
  198. u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
  199. };
  200. struct jpeg_com_marker {
  201. int len; /* number of usable bytes in data */
  202. char data[60];
  203. };
  204. struct jpeg_app_marker {
  205. int appn; /* number app segment */
  206. int len; /* number of usable bytes in data */
  207. char data[60];
  208. };
  209. struct videocodec {
  210. struct module *owner;
  211. /* -- filled in by slave device during register -- */
  212. char name[32];
  213. unsigned long magic; /* may be used for client<->master attaching */
  214. unsigned long flags; /* functionality flags */
  215. unsigned int type; /* codec type */
  216. /* -- these is filled in later during master device attach -- */
  217. struct videocodec_master *master_data;
  218. /* -- these are filled in by the slave device during register -- */
  219. void *data; /* private slave data */
  220. /* attach/detach client functions (indirect call) */
  221. int (*setup) (struct videocodec * codec);
  222. int (*unset) (struct videocodec * codec);
  223. /* main functions, every client needs them for sure! */
  224. // set compression or decompression (or freeze, stop, standby, etc)
  225. int (*set_mode) (struct videocodec * codec,
  226. int mode);
  227. // setup picture size and norm (for the codec's video frontend)
  228. int (*set_video) (struct videocodec * codec,
  229. struct tvnorm * norm,
  230. struct vfe_settings * cap,
  231. struct vfe_polarity * pol);
  232. // other control commands, also mmap setup etc.
  233. int (*control) (struct videocodec * codec,
  234. int type,
  235. int size,
  236. void *data);
  237. /* additional setup/query/processing (may be NULL pointer) */
  238. // interrupt setup / handling (for irq's delivered by master)
  239. int (*setup_interrupt) (struct videocodec * codec,
  240. long mode);
  241. int (*handle_interrupt) (struct videocodec * codec,
  242. int source,
  243. long flag);
  244. // picture interface (if any)
  245. long (*put_image) (struct videocodec * codec,
  246. int tr_type,
  247. int block,
  248. long *fr_num,
  249. long *flag,
  250. long size,
  251. void *buf);
  252. long (*get_image) (struct videocodec * codec,
  253. int tr_type,
  254. int block,
  255. long *fr_num,
  256. long *flag,
  257. long size,
  258. void *buf);
  259. };
  260. struct videocodec_master {
  261. /* -- filled in by master device for registration -- */
  262. char name[32];
  263. unsigned long magic; /* may be used for client<->master attaching */
  264. unsigned long flags; /* functionality flags */
  265. unsigned int type; /* master type */
  266. void *data; /* private master data */
  267. __u32(*readreg) (struct videocodec * codec,
  268. __u16 reg);
  269. void (*writereg) (struct videocodec * codec,
  270. __u16 reg,
  271. __u32 value);
  272. };
  273. /* ================================================= */
  274. /* function prototypes of the master/slave interface */
  275. /* ================================================= */
  276. /* attach and detach commands for the master */
  277. // * master structure needs to be kmalloc'ed before calling attach
  278. // and free'd after calling detach
  279. // * returns pointer on success, NULL on failure
  280. extern struct videocodec *videocodec_attach(struct videocodec_master *);
  281. // * 0 on success, <0 (errno) on failure
  282. extern int videocodec_detach(struct videocodec *);
  283. /* register and unregister commands for the slaves */
  284. // * 0 on success, <0 (errno) on failure
  285. extern int videocodec_register(const struct videocodec *);
  286. // * 0 on success, <0 (errno) on failure
  287. extern int videocodec_unregister(const struct videocodec *);
  288. /* the other calls are directly done via the videocodec structure! */
  289. #endif /*ifndef __LINUX_VIDEOCODEC_H */