uvc_compat.h
Upload User: shyika
Upload Date: 2017-11-25
Package Size: 1227k
Code Size: 6k
Category:

Video Capture

Development Platform:

Unix_Linux

  1. #ifndef _UVC_COMPAT_H
  2. #define _UVC_COMPAT_H
  3. #include <linux/version.h>
  4. #ifndef __KERNEL__
  5. #ifndef __user
  6. #define __user
  7. #endif
  8. #endif
  9. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  10. /*
  11.  * Extended control API
  12.  */
  13. struct v4l2_ext_control
  14. {
  15. __u32 id;
  16. __u32 reserved2[2];
  17. union {
  18. __s32 value;
  19. __s64 value64;
  20. void *reserved;
  21. };
  22. } __attribute__ ((packed));
  23. struct v4l2_ext_controls
  24. {
  25. __u32 ctrl_class;
  26. __u32 count;
  27. __u32 error_idx;
  28. __u32 reserved[2];
  29. struct v4l2_ext_control *controls;
  30. };
  31. /* Values for ctrl_class field */
  32. #define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */
  33. #define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */
  34. #define V4L2_CTRL_ID_MASK (0x0fffffff)
  35. #define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL)
  36. #define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000)
  37. /* Control flags */
  38. #define V4L2_CTRL_FLAG_READ_ONLY 0x0004
  39. #define V4L2_CTRL_FLAG_UPDATE 0x0008
  40. #define V4L2_CTRL_FLAG_INACTIVE 0x0010
  41. #define V4L2_CTRL_FLAG_SLIDER 0x0020
  42. /* Query flags, to be ORed with the control ID */
  43. #define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000
  44. /* User-class control IDs defined by V4L2 */
  45. #undef V4L2_CID_BASE
  46. #define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900)
  47. #define V4L2_CID_USER_BASE V4L2_CID_BASE
  48. #define V4L2_CID_USER_CLASS (V4L2_CTRL_CLASS_USER | 1)
  49. #define VIDIOC_G_EXT_CTRLS _IOWR ('V', 71, struct v4l2_ext_controls)
  50. #define VIDIOC_S_EXT_CTRLS _IOWR ('V', 72, struct v4l2_ext_controls)
  51. #define VIDIOC_TRY_EXT_CTRLS _IOWR ('V', 73, struct v4l2_ext_controls)
  52. #endif
  53. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
  54. /*
  55.  * Frame size and frame rate enumeration
  56.  *
  57.  * Included in Linux 2.6.19
  58.  */
  59. enum v4l2_frmsizetypes
  60. {
  61. V4L2_FRMSIZE_TYPE_DISCRETE = 1,
  62. V4L2_FRMSIZE_TYPE_CONTINUOUS = 2,
  63. V4L2_FRMSIZE_TYPE_STEPWISE = 3,
  64. };
  65. struct v4l2_frmsize_discrete
  66. {
  67. __u32 width; /* Frame width [pixel] */
  68. __u32 height; /* Frame height [pixel] */
  69. };
  70. struct v4l2_frmsize_stepwise
  71. {
  72. __u32 min_width; /* Minimum frame width [pixel] */
  73. __u32 max_width; /* Maximum frame width [pixel] */
  74. __u32 step_width; /* Frame width step size [pixel] */
  75. __u32 min_height; /* Minimum frame height [pixel] */
  76. __u32 max_height; /* Maximum frame height [pixel] */
  77. __u32 step_height; /* Frame height step size [pixel] */
  78. };
  79. struct v4l2_frmsizeenum
  80. {
  81. __u32 index; /* Frame size number */
  82. __u32 pixel_format; /* Pixel format */
  83. __u32 type; /* Frame size type the device supports. */
  84.         union { /* Frame size */
  85. struct v4l2_frmsize_discrete discrete;
  86. struct v4l2_frmsize_stepwise stepwise;
  87. };
  88. __u32   reserved[2]; /* Reserved space for future use */
  89. };
  90. enum v4l2_frmivaltypes
  91. {
  92. V4L2_FRMIVAL_TYPE_DISCRETE = 1,
  93. V4L2_FRMIVAL_TYPE_CONTINUOUS = 2,
  94. V4L2_FRMIVAL_TYPE_STEPWISE = 3,
  95. };
  96. struct v4l2_frmival_stepwise
  97. {
  98. struct v4l2_fract min; /* Minimum frame interval [s] */
  99. struct v4l2_fract max; /* Maximum frame interval [s] */
  100. struct v4l2_fract step; /* Frame interval step size [s] */
  101. };
  102. struct v4l2_frmivalenum
  103. {
  104. __u32 index; /* Frame format index */
  105. __u32 pixel_format; /* Pixel format */
  106. __u32 width; /* Frame width */
  107. __u32 height; /* Frame height */
  108. __u32 type; /* Frame interval type the device supports. */
  109. union { /* Frame interval */
  110. struct v4l2_fract discrete;
  111. struct v4l2_frmival_stepwise stepwise;
  112. };
  113. __u32 reserved[2]; /* Reserved space for future use */
  114. };
  115. #define VIDIOC_ENUM_FRAMESIZES _IOWR ('V', 74, struct v4l2_frmsizeenum)
  116. #define VIDIOC_ENUM_FRAMEINTERVALS _IOWR ('V', 75, struct v4l2_frmivalenum)
  117. #endif
  118. #ifdef __KERNEL__
  119. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  120. /*
  121.  * kzalloc()
  122.  */
  123. static inline void *
  124. kzalloc(size_t size, unsigned int __nocast gfp_flags)
  125. {
  126. void *mem = kmalloc(size, gfp_flags);
  127. if (mem)
  128. memset(mem, 0, size);
  129. return mem;
  130. }
  131. #endif
  132. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
  133. /*
  134.  * vm_insert_page()
  135.  */
  136. static inline int
  137. vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
  138. struct page *page)
  139. {
  140. /* Not sure if this is needed. remap_pfn_range() sets VM_RESERVED
  141.  * in 2.6.14.
  142.  */
  143. vma->vm_flags |= VM_RESERVED;
  144. SetPageReserved(page);
  145. return remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE,
  146. vma->vm_page_prot);
  147. }
  148. #endif
  149. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
  150. /*
  151.  * v4l_printk_ioctl()
  152.  */
  153. static inline void
  154. v4l_printk_ioctl(unsigned int cmd)
  155. {
  156. switch (_IOC_TYPE(cmd)) {
  157. case 'v':
  158. printk(KERN_DEBUG "ioctl 0x%x (V4L1)n", cmd);
  159. break;
  160. case 'V':
  161. printk(KERN_DEBUG "ioctl 0x%x (%s)n",
  162. cmd, v4l2_ioctl_names[_IOC_NR(cmd)]);
  163. break;
  164. default:
  165. printk(KERN_DEBUG "ioctl 0x%x (?)n", cmd);
  166. break;
  167. }
  168. }
  169. #endif
  170. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
  171. /*
  172.  * Mutex API
  173.  */
  174. #include <asm/semaphore.h>
  175. #define mutex_lock(mutex) down(mutex)
  176. #define mutex_lock_interruptible(mutex) down_interruptible(mutex)
  177. #define mutex_unlock(mutex) up(mutex)
  178. #define mutex_init(mutex) init_MUTEX(mutex)
  179. #define mutex semaphore
  180. #else
  181. #include <asm/mutex.h>
  182. #endif
  183. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
  184. /*
  185.  * usb_endpoint_* functions
  186.  *
  187.  * Included in Linux 2.6.19
  188.  */
  189. static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
  190. {
  191. return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
  192. }
  193. static inline int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
  194. {
  195. return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
  196. USB_ENDPOINT_XFER_INT);
  197. }
  198. static inline int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd)
  199. {
  200. return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
  201. USB_ENDPOINT_XFER_ISOC);
  202. }
  203. static inline int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
  204. {
  205. return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
  206. USB_ENDPOINT_XFER_BULK);
  207. }
  208. static inline int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
  209. {
  210. return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
  211. }
  212. #endif
  213. #endif /* __KERNEL__ */
  214. #endif /* _UVC_COMPAT_H */