stream pushing ok without access permission of /dev/video0
[rtmpclient.git] / app / src / main / jni / libuvc / include / libuvc / libuvc_original.h
1 #ifndef LIBUVC_H
2 #define LIBUVC_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <stdio.h> // FILE
9 #include <libusb-1.0/libusb.h>
10 #include <libuvc/libuvc_config.h>
11
12 /** UVC error types, based on libusb errors
13  * @ingroup diag
14  */
15 typedef enum uvc_error {
16   /** Success (no error) */
17   UVC_SUCCESS = 0,
18   /** Input/output error */
19   UVC_ERROR_IO = -1,
20   /** Invalid parameter */
21   UVC_ERROR_INVALID_PARAM = -2,
22   /** Access denied */
23   UVC_ERROR_ACCESS = -3,
24   /** No such device */
25   UVC_ERROR_NO_DEVICE = -4,
26   /** Entity not found */
27   UVC_ERROR_NOT_FOUND = -5,
28   /** Resource busy */
29   UVC_ERROR_BUSY = -6,
30   /** Operation timed out */
31   UVC_ERROR_TIMEOUT = -7,
32   /** Overflow */
33   UVC_ERROR_OVERFLOW = -8,
34   /** Pipe error */
35   UVC_ERROR_PIPE = -9,
36   /** System call interrupted */
37   UVC_ERROR_INTERRUPTED = -10,
38   /** Insufficient memory */
39   UVC_ERROR_NO_MEM = -11,
40   /** Operation not supported */
41   UVC_ERROR_NOT_SUPPORTED = -12,
42   /** Device is not UVC-compliant */
43   UVC_ERROR_INVALID_DEVICE = -50,
44   /** Mode not supported */
45   UVC_ERROR_INVALID_MODE = -51,
46   /** Resource has a callback (can't use polling and async) */
47   UVC_ERROR_CALLBACK_EXISTS = -52,
48   /** Undefined error */
49   UVC_ERROR_OTHER = -99
50 } uvc_error_t;
51
52 /** Color coding of stream, transport-independent
53  * @ingroup streaming
54  */
55 enum uvc_frame_format {
56   UVC_FRAME_FORMAT_UNKNOWN = 0,
57   /** Any supported format */
58   UVC_FRAME_FORMAT_ANY = 0,
59   UVC_FRAME_FORMAT_UNCOMPRESSED,
60   UVC_FRAME_FORMAT_COMPRESSED,
61   /** YUYV/YUV2/YUV422: YUV encoding with one luminance value per pixel and
62    * one UV (chrominance) pair for every two pixels.
63    */
64   UVC_FRAME_FORMAT_YUYV,
65   UVC_FRAME_FORMAT_UYVY,
66   /** 24-bit RGB */
67   UVC_FRAME_FORMAT_RGB,
68   UVC_FRAME_FORMAT_BGR,
69   /** Motion-JPEG (or JPEG) encoded images */
70   UVC_FRAME_FORMAT_MJPEG,
71   UVC_FRAME_FORMAT_GRAY8,
72   /** Number of formats understood */
73   UVC_FRAME_FORMAT_COUNT,
74 };
75
76 /* UVC_COLOR_FORMAT_* have been replaced with UVC_FRAME_FORMAT_*. Please use
77  * UVC_FRAME_FORMAT_* instead of using these. */
78 #define UVC_COLOR_FORMAT_UNKNOWN UVC_FRAME_FORMAT_UNKNOWN
79 #define UVC_COLOR_FORMAT_UNCOMPRESSED UVC_FRAME_FORMAT_UNCOMPRESSED
80 #define UVC_COLOR_FORMAT_COMPRESSED UVC_FRAME_FORMAT_COMPRESSED
81 #define UVC_COLOR_FORMAT_YUYV UVC_FRAME_FORMAT_YUYV
82 #define UVC_COLOR_FORMAT_UYVY UVC_FRAME_FORMAT_UYVY
83 #define UVC_COLOR_FORMAT_RGB UVC_FRAME_FORMAT_RGB
84 #define UVC_COLOR_FORMAT_BGR UVC_FRAME_FORMAT_BGR
85 #define UVC_COLOR_FORMAT_MJPEG UVC_FRAME_FORMAT_MJPEG
86 #define UVC_COLOR_FORMAT_GRAY8 UVC_FRAME_FORMAT_GRAY8
87
88 /** UVC request code (A.8) */
89 enum uvc_req_code {
90   UVC_RC_UNDEFINED = 0x00,
91   UVC_SET_CUR = 0x01,
92   UVC_GET_CUR = 0x81,
93   UVC_GET_MIN = 0x82,
94   UVC_GET_MAX = 0x83,
95   UVC_GET_RES = 0x84,
96   UVC_GET_LEN = 0x85,
97   UVC_GET_INFO = 0x86,
98   UVC_GET_DEF = 0x87
99 };
100
101 enum uvc_device_power_mode {
102   UVC_VC_VIDEO_POWER_MODE_FULL = 0x000b,
103   UVC_VC_VIDEO_POWER_MODE_DEVICE_DEPENDENT = 0x001b,
104 };
105
106 /** Camera terminal control selector (A.9.4) */
107 enum uvc_ct_ctrl_selector {
108   UVC_CT_CONTROL_UNDEFINED = 0x00,
109   UVC_CT_SCANNING_MODE_CONTROL = 0x01,
110   UVC_CT_AE_MODE_CONTROL = 0x02,
111   UVC_CT_AE_PRIORITY_CONTROL = 0x03,
112   UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL = 0x04,
113   UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL = 0x05,
114   UVC_CT_FOCUS_ABSOLUTE_CONTROL = 0x06,
115   UVC_CT_FOCUS_RELATIVE_CONTROL = 0x07,
116   UVC_CT_FOCUS_AUTO_CONTROL = 0x08,
117   UVC_CT_IRIS_ABSOLUTE_CONTROL = 0x09,
118   UVC_CT_IRIS_RELATIVE_CONTROL = 0x0a,
119   UVC_CT_ZOOM_ABSOLUTE_CONTROL = 0x0b,
120   UVC_CT_ZOOM_RELATIVE_CONTROL = 0x0c,
121   UVC_CT_PANTILT_ABSOLUTE_CONTROL = 0x0d,
122   UVC_CT_PANTILT_RELATIVE_CONTROL = 0x0e,
123   UVC_CT_ROLL_ABSOLUTE_CONTROL = 0x0f,
124   UVC_CT_ROLL_RELATIVE_CONTROL = 0x10,
125   UVC_CT_PRIVACY_CONTROL = 0x11
126 };
127
128 /** Processing unit control selector (A.9.5) */
129 enum uvc_pu_ctrl_selector {
130   UVC_PU_CONTROL_UNDEFINED = 0x00,
131   UVC_PU_BACKLIGHT_COMPENSATION_CONTROL = 0x01,
132   UVC_PU_BRIGHTNESS_CONTROL = 0x02,
133   UVC_PU_CONTRAST_CONTROL = 0x03,
134   UVC_PU_GAIN_CONTROL = 0x04,
135   UVC_PU_POWER_LINE_FREQUENCY_CONTROL = 0x05,
136   UVC_PU_HUE_CONTROL = 0x06,
137   UVC_PU_SATURATION_CONTROL = 0x07,
138   UVC_PU_SHARPNESS_CONTROL = 0x08,
139   UVC_PU_GAMMA_CONTROL = 0x09,
140   UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL = 0x0a,
141   UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL = 0x0b,
142   UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL = 0x0c,
143   UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL = 0x0d,
144   UVC_PU_DIGITAL_MULTIPLIER_CONTROL = 0x0e,
145   UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL = 0x0f,
146   UVC_PU_HUE_AUTO_CONTROL = 0x10,
147   UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL = 0x11,
148   UVC_PU_ANALOG_LOCK_STATUS_CONTROL = 0x12
149 };
150
151 /** USB terminal type (B.1) */
152 enum uvc_term_type {
153   UVC_TT_VENDOR_SPECIFIC = 0x0100,
154   UVC_TT_STREAMING = 0x0101
155 };
156
157 /** Input terminal type (B.2) */
158 enum uvc_it_type {
159   UVC_ITT_VENDOR_SPECIFIC = 0x0200,
160   UVC_ITT_CAMERA = 0x0201,
161   UVC_ITT_MEDIA_TRANSPORT_INPUT = 0x0202
162 };
163
164 /** Output terminal type (B.3) */
165 enum uvc_ot_type {
166   UVC_OTT_VENDOR_SPECIFIC = 0x0300,
167   UVC_OTT_DISPLAY = 0x0301,
168   UVC_OTT_MEDIA_TRANSPORT_OUTPUT = 0x0302
169 };
170
171 /** External terminal type (B.4) */
172 enum uvc_et_type {
173   UVC_EXTERNAL_VENDOR_SPECIFIC = 0x0400,
174   UVC_COMPOSITE_CONNECTOR = 0x0401,
175   UVC_SVIDEO_CONNECTOR = 0x0402,
176   UVC_COMPONENT_CONNECTOR = 0x0403
177 };
178
179 /** Context, equivalent to libusb's contexts.
180  *
181  * May either own a libusb context or use one that's already made.
182  *
183  * Always create these with uvc_get_context.
184  */
185 struct uvc_context;
186 typedef struct uvc_context uvc_context_t;
187
188 /** UVC device.
189  *
190  * Get this from uvc_get_device_list() or uvc_find_device().
191  */
192 struct uvc_device;
193 typedef struct uvc_device uvc_device_t;
194
195 /** Handle on an open UVC device.
196  *
197  * Get one of these from uvc_open(). Once you uvc_close()
198  * it, it's no longer valid.
199  */
200 struct uvc_device_handle;
201 typedef struct uvc_device_handle uvc_device_handle_t;
202
203 /** Handle on an open UVC stream.
204  *
205  * Get one of these from uvc_stream_open*().
206  * Once you uvc_stream_close() it, it will no longer be valid.
207  */
208 struct uvc_stream_handle;
209 typedef struct uvc_stream_handle uvc_stream_handle_t;
210
211 /** Representation of the interface that brings data into the UVC device */
212 typedef struct uvc_input_terminal {
213   struct uvc_input_terminal *prev, *next;
214   /** Index of the terminal within the device */
215   uint8_t bTerminalID;
216   /** Type of terminal (e.g., camera) */
217   enum uvc_it_type wTerminalType;
218   uint16_t wObjectiveFocalLengthMin;
219   uint16_t wObjectiveFocalLengthMax;
220   uint16_t wOcularFocalLength;
221   /** Camera controls (meaning of bits given in {uvc_ct_ctrl_selector}) */
222   uint64_t bmControls;
223 } uvc_input_terminal_t;
224
225 typedef struct uvc_output_terminal {
226   struct uvc_output_terminal *prev, *next;
227   /** @todo */
228 } uvc_output_terminal_t;
229
230 /** Represents post-capture processing functions */
231 typedef struct uvc_processing_unit {
232   struct uvc_processing_unit *prev, *next;
233   /** Index of the processing unit within the device */
234   uint8_t bUnitID;
235   /** Index of the terminal from which the device accepts images */
236   uint8_t bSourceID;
237   /** Processing controls (meaning of bits given in {uvc_pu_ctrl_selector}) */
238   uint64_t bmControls;
239 } uvc_processing_unit_t;
240
241 /** Custom processing or camera-control functions */
242 typedef struct uvc_extension_unit {
243   struct uvc_extension_unit *prev, *next;
244   /** Index of the extension unit within the device */
245   uint8_t bUnitID;
246   /** GUID identifying the extension unit */
247   uint8_t guidExtensionCode[16];
248   /** Bitmap of available controls (manufacturer-dependent) */
249   uint64_t bmControls;
250 } uvc_extension_unit_t;
251
252 enum uvc_status_class {
253   UVC_STATUS_CLASS_CONTROL = 0x10,
254   UVC_STATUS_CLASS_CONTROL_CAMERA = 0x11,
255   UVC_STATUS_CLASS_CONTROL_PROCESSING = 0x12,
256 };
257
258 enum uvc_status_attribute {
259   UVC_STATUS_ATTRIBUTE_VALUE_CHANGE = 0x00,
260   UVC_STATUS_ATTRIBUTE_INFO_CHANGE = 0x01,
261   UVC_STATUS_ATTRIBUTE_FAILURE_CHANGE = 0x02,
262   UVC_STATUS_ATTRIBUTE_UNKNOWN = 0xff
263 };
264
265 /** A callback function to accept status updates
266  * @ingroup device
267  */
268 typedef void(uvc_status_callback_t)(enum uvc_status_class status_class,
269                                     int event,
270                                     int selector,
271                                     enum uvc_status_attribute status_attribute,
272                                     void *data, size_t data_len,
273                                     void *user_ptr);
274
275 /** Structure representing a UVC device descriptor.
276  *
277  * (This isn't a standard structure.)
278  */
279 typedef struct uvc_device_descriptor {
280   /** Vendor ID */
281   uint16_t idVendor;
282   /** Product ID */
283   uint16_t idProduct;
284   /** UVC compliance level, e.g. 0x0100 (1.0), 0x0110 */
285   uint16_t bcdUVC;
286   /** Serial number (null if unavailable) */
287   const char *serialNumber;
288   /** Device-reported manufacturer name (or null) */
289   const char *manufacturer;
290   /** Device-reporter product name (or null) */
291   const char *product;
292 } uvc_device_descriptor_t;
293
294 /** An image frame received from the UVC device
295  * @ingroup streaming
296  */
297 typedef struct uvc_frame {
298   /** Image data for this frame */
299   void *data;
300   /** Size of image data buffer */
301   size_t data_bytes;
302   /** Width of image in pixels */
303   uint32_t width;
304   /** Height of image in pixels */
305   uint32_t height;
306   /** Pixel data format */
307   enum uvc_frame_format frame_format;
308   /** Number of bytes per horizontal line (undefined for compressed format) */
309   size_t step;
310   /** Frame number (may skip, but is strictly monotonically increasing) */
311   uint32_t sequence;
312   /** Estimate of system time when the device started capturing the image */
313   struct timeval capture_time;
314   /** Handle on the device that produced the image.
315    * @warning You must not call any uvc_* functions during a callback. */
316   uvc_device_handle_t *source;
317   /** Is the data buffer owned by the library?
318    * If 1, the data buffer can be arbitrarily reallocated by frame conversion
319    * functions.
320    * If 0, the data buffer will not be reallocated or freed by the library.
321    * Set this field to zero if you are supplying the buffer.
322    */
323   uint8_t library_owns_data;
324 } uvc_frame_t;
325
326 /** A callback function to handle incoming assembled UVC frames
327  * @ingroup streaming
328  */
329 typedef void(uvc_frame_callback_t)(struct uvc_frame *frame, void *user_ptr);
330
331 /** Streaming mode, includes all information needed to select stream
332  * @ingroup streaming
333  */
334 typedef struct uvc_stream_ctrl {
335   uint16_t bmHint;
336   uint8_t bFormatIndex;
337   uint8_t bFrameIndex;
338   uint32_t dwFrameInterval;
339   uint16_t wKeyFrameRate;
340   uint16_t wPFrameRate;
341   uint16_t wCompQuality;
342   uint16_t wCompWindowSize;
343   uint16_t wDelay;
344   uint32_t dwMaxVideoFrameSize;
345   uint32_t dwMaxPayloadTransferSize;
346   /** @todo add UVC 1.1 parameters */
347   uint8_t bInterfaceNumber;
348 } uvc_stream_ctrl_t;
349
350 uvc_error_t uvc_init(uvc_context_t **ctx, struct libusb_context *usb_ctx);
351 void uvc_exit(uvc_context_t *ctx);
352
353 uvc_error_t uvc_get_device_list(
354     uvc_context_t *ctx,
355     uvc_device_t ***list);
356 void uvc_free_device_list(uvc_device_t **list, uint8_t unref_devices);
357
358 uvc_error_t uvc_get_device_descriptor(
359     uvc_device_t *dev,
360     uvc_device_descriptor_t **desc);
361 void uvc_free_device_descriptor(
362     uvc_device_descriptor_t *desc);
363
364 uint8_t uvc_get_bus_number(uvc_device_t *dev);
365 uint8_t uvc_get_device_address(uvc_device_t *dev);
366
367 uvc_error_t uvc_find_device(
368     uvc_context_t *ctx,
369     uvc_device_t **dev,
370     int vid, int pid, const char *sn);
371
372 uvc_error_t uvc_open(
373     uvc_device_t *dev,
374     uvc_device_handle_t **devh);
375 void uvc_close(uvc_device_handle_t *devh);
376
377 uvc_device_t *uvc_get_device(uvc_device_handle_t *devh);
378 libusb_device_handle *uvc_get_libusb_handle(uvc_device_handle_t *devh);
379
380 void uvc_ref_device(uvc_device_t *dev);
381 void uvc_unref_device(uvc_device_t *dev);
382
383 void uvc_set_status_callback(uvc_device_handle_t *devh,
384                              uvc_status_callback_t cb,
385                              void *user_ptr);
386
387 const uvc_input_terminal_t *uvc_get_input_terminals(uvc_device_handle_t *devh);
388 const uvc_output_terminal_t *uvc_get_output_terminals(uvc_device_handle_t *devh);
389 const uvc_processing_unit_t *uvc_get_processing_units(uvc_device_handle_t *devh);
390 const uvc_extension_unit_t *uvc_get_extension_units(uvc_device_handle_t *devh);
391
392 uvc_error_t uvc_get_stream_ctrl_format_size(
393     uvc_device_handle_t *devh,
394     uvc_stream_ctrl_t *ctrl,
395     enum uvc_frame_format format,
396     int width, int height,
397     int fps
398     );
399
400 uvc_error_t uvc_probe_stream_ctrl(
401     uvc_device_handle_t *devh,
402     uvc_stream_ctrl_t *ctrl);
403
404 uvc_error_t uvc_start_streaming(
405     uvc_device_handle_t *devh,
406     uvc_stream_ctrl_t *ctrl,
407     uvc_frame_callback_t *cb,
408     void *user_ptr,
409     uint8_t isochronous);
410
411 uvc_error_t uvc_start_iso_streaming(
412     uvc_device_handle_t *devh,
413     uvc_stream_ctrl_t *ctrl,
414     uvc_frame_callback_t *cb,
415     void *user_ptr);
416
417 void uvc_stop_streaming(uvc_device_handle_t *devh);
418
419 uvc_error_t uvc_stream_open_ctrl(uvc_device_handle_t *devh, uvc_stream_handle_t **strmh, uvc_stream_ctrl_t *ctrl);
420 uvc_error_t uvc_stream_ctrl(uvc_stream_handle_t *strmh, uvc_stream_ctrl_t *ctrl);
421 uvc_error_t uvc_stream_start(uvc_stream_handle_t *strmh,
422     uvc_frame_callback_t *cb,
423     void *user_ptr,
424     uint8_t isochronous);
425 uvc_error_t uvc_stream_start_iso(uvc_stream_handle_t *strmh,
426     uvc_frame_callback_t *cb,
427     void *user_ptr);
428 uvc_error_t uvc_stream_get_frame(
429     uvc_stream_handle_t *strmh,
430     uvc_frame_t **frame,
431     int32_t timeout_us
432 );
433 uvc_error_t uvc_stream_stop(uvc_stream_handle_t *strmh);
434 void uvc_stream_close(uvc_stream_handle_t *strmh);
435
436 uvc_error_t uvc_get_power_mode(uvc_device_handle_t *devh, enum uvc_device_power_mode *mode, enum uvc_req_code req_code);
437 uvc_error_t uvc_set_power_mode(uvc_device_handle_t *devh, enum uvc_device_power_mode mode);
438 uvc_error_t uvc_get_ae_mode(uvc_device_handle_t *devh, int *mode, enum uvc_req_code req_code);
439 uvc_error_t uvc_set_ae_mode(uvc_device_handle_t *devh, int mode);
440 uvc_error_t uvc_get_ae_priority(uvc_device_handle_t *devh, uint8_t *priority, enum uvc_req_code req_code);
441 uvc_error_t uvc_set_ae_priority(uvc_device_handle_t *devh, uint8_t priority);
442 uvc_error_t uvc_get_exposure_abs(uvc_device_handle_t *devh, int *time, enum uvc_req_code req_code);
443 uvc_error_t uvc_set_exposure_abs(uvc_device_handle_t *devh, int time);
444 uvc_error_t uvc_get_exposure_rel(uvc_device_handle_t *devh, int *step, enum uvc_req_code req_code);
445 uvc_error_t uvc_set_exposure_rel(uvc_device_handle_t *devh, int step);
446 uvc_error_t uvc_get_scanning_mode(uvc_device_handle_t *devh, int *step, enum uvc_req_code req_code);
447 uvc_error_t uvc_set_scanning_mode(uvc_device_handle_t *devh, int mode);
448 uvc_error_t uvc_get_focus_abs(uvc_device_handle_t *devh, short *focus, enum uvc_req_code req_code);
449 uvc_error_t uvc_set_focus_abs(uvc_device_handle_t *devh, short focus);
450 uvc_error_t uvc_get_pantilt_abs(uvc_device_handle_t *devh, int *pan, int *tilt, enum uvc_req_code req_code);
451 uvc_error_t uvc_set_pantilt_abs(uvc_device_handle_t *devh, int pan, int tilt);
452
453 int uvc_get_ctrl_len(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl);
454 int uvc_get_ctrl(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl, void *data, int len, enum uvc_req_code req_code);
455 int uvc_set_ctrl(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl, void *data, int len);
456
457 void uvc_perror(uvc_error_t err, const char *msg);
458 const char* uvc_strerror(uvc_error_t err);
459 void uvc_print_diag(uvc_device_handle_t *devh, FILE *stream);
460 void uvc_print_stream_ctrl(uvc_stream_ctrl_t *ctrl, FILE *stream);
461
462 uvc_frame_t *uvc_allocate_frame(size_t data_bytes);
463 void uvc_free_frame(uvc_frame_t *frame);
464
465 uvc_error_t uvc_duplicate_frame(uvc_frame_t *in, uvc_frame_t *out);
466
467 uvc_error_t uvc_yuyv2rgb(uvc_frame_t *in, uvc_frame_t *out);
468 uvc_error_t uvc_uyvy2rgb(uvc_frame_t *in, uvc_frame_t *out);
469 uvc_error_t uvc_any2rgb(uvc_frame_t *in, uvc_frame_t *out);
470
471 uvc_error_t uvc_yuyv2bgr(uvc_frame_t *in, uvc_frame_t *out);
472 uvc_error_t uvc_uyvy2bgr(uvc_frame_t *in, uvc_frame_t *out);
473 uvc_error_t uvc_any2bgr(uvc_frame_t *in, uvc_frame_t *out);
474
475 #ifdef LIBUVC_HAS_JPEG
476 uvc_error_t uvc_mjpeg2rgb(uvc_frame_t *in, uvc_frame_t *out);
477 #endif
478
479 #ifdef __cplusplus
480 }
481 #endif
482
483 #endif // !def(LIBUVC_H)
484