gspca.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #ifndef GSPCAV2_H
  2. #define GSPCAV2_H
  3. #include <linux/module.h>
  4. #include <linux/version.h>
  5. #include <linux/kernel.h>
  6. #include <linux/usb.h>
  7. #include <linux/videodev2.h>
  8. #include <media/v4l2-common.h>
  9. #include <linux/mutex.h>
  10. #ifdef CONFIG_VIDEO_ADV_DEBUG
  11. /* GSPCA our debug messages */
  12. extern int gspca_debug;
  13. #define PDEBUG(level, fmt, args...) \
  14. do {\
  15. if (gspca_debug & (level)) \
  16. printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
  17. } while (0)
  18. #define D_ERR 0x01
  19. #define D_PROBE 0x02
  20. #define D_CONF 0x04
  21. #define D_STREAM 0x08
  22. #define D_FRAM 0x10
  23. #define D_PACK 0x20
  24. #define D_USBI 0x40
  25. #define D_USBO 0x80
  26. #define D_V4L2 0x0100
  27. #else
  28. #define PDEBUG(level, fmt, args...)
  29. #endif
  30. #undef err
  31. #define err(fmt, args...) \
  32. do {\
  33. printk(KERN_ERR MODULE_NAME ": " fmt "\n", ## args); \
  34. } while (0)
  35. #undef info
  36. #define info(fmt, args...) \
  37. do {\
  38. printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
  39. } while (0)
  40. #undef warn
  41. #define warn(fmt, args...) \
  42. do {\
  43. printk(KERN_WARNING MODULE_NAME ": " fmt "\n", ## args); \
  44. } while (0)
  45. #define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
  46. /* ISOC transfers */
  47. #define MAX_NURBS 16 /* max number of URBs */
  48. #define ISO_MAX_PKT 32 /* max number of packets in an ISOC transfer */
  49. #define ISO_MAX_SIZE 0x8000 /* max size of one URB buffer (32 Kb) */
  50. /* device information - set at probe time */
  51. struct cam {
  52. char *dev_name;
  53. struct v4l2_pix_format *cam_mode; /* size nmodes */
  54. char nmodes;
  55. __u8 epaddr;
  56. };
  57. struct gspca_dev;
  58. struct gspca_frame;
  59. /* subdriver operations */
  60. typedef int (*cam_op) (struct gspca_dev *);
  61. typedef void (*cam_v_op) (struct gspca_dev *);
  62. typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *);
  63. typedef int (*cam_jpg_op) (struct gspca_dev *,
  64. struct v4l2_jpegcompression *);
  65. typedef int (*cam_qmnu_op) (struct gspca_dev *,
  66. struct v4l2_querymenu *);
  67. typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
  68. struct gspca_frame *frame,
  69. __u8 *data,
  70. int len);
  71. struct ctrl {
  72. struct v4l2_queryctrl qctrl;
  73. int (*set)(struct gspca_dev *, __s32);
  74. int (*get)(struct gspca_dev *, __s32 *);
  75. };
  76. /* subdriver description */
  77. struct sd_desc {
  78. /* information */
  79. const char *name; /* sub-driver name */
  80. /* controls */
  81. const struct ctrl *ctrls;
  82. int nctrls;
  83. /* operations */
  84. cam_cf_op config; /* called on probe */
  85. cam_op open; /* called on open */
  86. cam_v_op start; /* called on stream on */
  87. cam_v_op stopN; /* called on stream off - main alt */
  88. cam_v_op stop0; /* called on stream off - alt 0 */
  89. cam_v_op close; /* called on close */
  90. cam_pkt_op pkt_scan;
  91. /* optional operations */
  92. cam_v_op dq_callback; /* called when a frame has been dequeued */
  93. cam_jpg_op get_jcomp;
  94. cam_jpg_op set_jcomp;
  95. cam_qmnu_op querymenu;
  96. };
  97. /* packet types when moving from iso buf to frame buf */
  98. #define DISCARD_PACKET 0
  99. #define FIRST_PACKET 1
  100. #define INTER_PACKET 2
  101. #define LAST_PACKET 3
  102. struct gspca_frame {
  103. __u8 *data; /* frame buffer */
  104. __u8 *data_end; /* end of frame while filling */
  105. int vma_use_count;
  106. struct v4l2_buffer v4l2_buf;
  107. };
  108. struct gspca_dev {
  109. struct video_device vdev; /* !! must be the first item */
  110. struct file_operations fops;
  111. struct usb_device *dev;
  112. struct file *capt_file; /* file doing video capture */
  113. struct cam cam; /* device information */
  114. const struct sd_desc *sd_desc; /* subdriver description */
  115. struct urb *urb[MAX_NURBS];
  116. __u8 *frbuf; /* buffer for nframes */
  117. struct gspca_frame frame[GSPCA_MAX_FRAMES];
  118. __u32 frsz; /* frame size */
  119. char nframes; /* number of frames */
  120. char fr_i; /* frame being filled */
  121. char fr_q; /* next frame to queue */
  122. char fr_o; /* next frame to dequeue */
  123. signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
  124. char last_packet_type;
  125. __u8 iface; /* USB interface number */
  126. __u8 alt; /* USB alternate setting */
  127. __u8 curr_mode; /* current camera mode */
  128. __u32 pixfmt; /* current mode parameters */
  129. __u16 width;
  130. __u16 height;
  131. atomic_t nevent; /* number of frames done */
  132. wait_queue_head_t wq; /* wait queue */
  133. struct mutex usb_lock; /* usb exchange protection */
  134. struct mutex read_lock; /* read protection */
  135. struct mutex queue_lock; /* ISOC queue protection */
  136. __u32 sequence; /* frame sequence number */
  137. char streaming;
  138. char users; /* number of opens */
  139. char present; /* device connected */
  140. char nbufread; /* number of buffers for read() */
  141. char nurbs; /* number of allocated URBs */
  142. char memory; /* memory type (V4L2_MEMORY_xxx) */
  143. __u8 nbalt; /* number of USB alternate settings */
  144. };
  145. int gspca_dev_probe(struct usb_interface *intf,
  146. const struct usb_device_id *id,
  147. const struct sd_desc *sd_desc,
  148. int dev_size,
  149. struct module *module);
  150. void gspca_disconnect(struct usb_interface *intf);
  151. struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
  152. int packet_type,
  153. struct gspca_frame *frame,
  154. const __u8 *data,
  155. int len);
  156. #endif /* GSPCAV2_H */