1 /* ---------------------------------------------------------------------------- 2 * Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved. 3 * Description: LiteOS USB Driver Video Stream HeadFile 4 * Author: huangjieliang 5 * Create: 2017-04-17 6 * Redistribution and use in source and binary forms, with or without modification, 7 * are permitted provided that the following conditions are met: 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 14 * to endorse or promote products derived from this software without specific prior written 15 * permission. 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * --------------------------------------------------------------------------- */ 28 /* ---------------------------------------------------------------------------- 29 * Notice of Export Control Law 30 * =============================================== 31 * Huawei LiteOS may be subject to applicable export control laws and regulations, which might 32 * include those applicable to Huawei LiteOS of U.S. and the country in which you are located. 33 * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such 34 * applicable export control laws and regulations. 35 * --------------------------------------------------------------------------- */ 36 37 #ifndef LITEOS_USB_DEVICE_VIDEO_H 38 #define LITEOS_USB_DEVICE_VIDEO_H 39 40 #include <los_typedef.h> 41 42 #ifdef __cplusplus 43 #if __cplusplus 44 extern "C" { 45 #endif /* __cplusplus */ 46 #endif /* __cplusplus */ 47 48 /* UVC function error codes */ 49 50 #define UVC_OK 0x00 /* No error, function has successfully completed */ 51 #define UVC_ERROR_NOMATCH 0x01 /* The operation can not be complete, due to mismatch of UVC state */ 52 #define UVC_ERROR_HANDLE 0x02 /* Mismatch of UVC handle, UVC can be obtained only once before calling close */ 53 #define UVC_ERROR_PTR 0x03 /* Invalid pointer */ 54 #define UVC_ERROR_MEMORY 0x04 /* Memory error */ 55 #define UVC_ERROR_VALUE 0x05 /* Incorrect value */ 56 #define UVC_ERROR_FATAL 0x06 /* Fatal internal error, please contact the one who wrote the code */ 57 58 /* UVC video frame format */ 59 60 #define UVC_VFF_YUY2 0x00 61 #define UVC_VFF_H264 0x01 62 #define UVC_VFF_MJPG 0x02 63 64 #define UVC_INVALID_HANDLE 0xFFFFFFFF 65 66 /* 67 * parameter structure used to open a Video handle (UVC device) 68 */ 69 70 struct uvc_open_param 71 { 72 #define UVC_VIDEO_WIDTH_DEF 1920 73 #define UVC_VIDEO_HEIGHT_DEF 1080 74 #define UVC_VIDEO_WIDTH_MAX 4096 75 #define UVC_VIDEO_HEIGHT_MAX 4096 76 uint32_t vid_width; /* width of the video frame, in pixels */ 77 uint32_t vid_height; /* height of the video frame, in pixels */ 78 uint32_t vid_format; /* format of video frame */ 79 80 uint32_t bulk_size; 81 uint32_t imgsize; 82 }; 83 84 enum format_switch_status 85 { 86 FORMAT_SWITCH_FINISH = 0, 87 FORMAT_SWITCH_PENDING 88 }; 89 90 /* 91 * format info 92 */ 93 94 struct uvc_format_info 95 { 96 uint32_t width; 97 uint32_t height; 98 uint32_t format; 99 100 uint32_t status; 101 } __attribute__((packed)); 102 103 /* type-define UVC handle as pointer type */ 104 105 typedef void *uvc_t; 106 107 /* open the UVC device, and returns a handle */ 108 109 extern int uvc_open_device(uvc_t *hdl, struct uvc_open_param *param); 110 111 /* closes a UVC handle */ 112 113 extern int uvc_close_device(uvc_t uvc); 114 115 /* check the frame switch status */ 116 117 extern enum format_switch_status uvc_format_status_check(void); 118 119 extern int uvc_format_info_get(struct uvc_format_info *info); 120 121 #define UVC_WAIT_HOST_NOP 0x0 122 #define UVC_WAIT_HOST_FOREVER 0x1 123 124 /* 125 * Wait for UVC USB host connection 126 */ 127 128 extern int uvc_wait_host(uvc_t uvc, int wait_option, int *connected); 129 130 /* UVC device state definitions */ 131 132 enum uvc_state 133 { 134 UVC_STATE_IDLE = 0x01, /* UVC device has been opened, but not connected to USB host */ 135 UVC_STATE_CONN = 0x02, /* UVC device has connected to USB host, but not trasmitting video data */ 136 UVC_STATE_TRAN_COPY = 0x04, /* UVC device has connected to USB host, and transmitting video data */ 137 UVC_STATE_TRAN_NOCP = 0x08, 138 UVC_STATE_ERR = 0x10, /* indicates that UVC device has encounterred an error */ 139 UVC_STATE_NONE = 0x20 /* Not used */ 140 }; 141 142 /* 143 * the function returns the operating state of UVC device 144 */ 145 146 extern int uvc_get_state(uvc_t uvc, uint32_t *state); 147 148 /* structure used for callback furnction, (partial) frame data; 149 * structure used to describe next complete frame data. 150 * quite simple, is it not? 151 */ 152 153 struct uvc_transfer_data 154 { 155 uint8_t *data; /* UVC_STATE_TRAN_COPY: copy target address; UVC_STATE_TRAN_NOCP: NULL */ 156 uint32_t length; /* length of data */ 157 uint32_t last; /* last piece of data in the frame? (ignored when UVC_STATE_TRAN_NOCP) */ 158 }; 159 160 /* 161 * callback function proto-type, copy (partial) video frame data 162 * callback function proto-type, used while transmitting single 163 * frame of video data one by one 164 */ 165 166 typedef int (*uvc_continue_func)(uvc_t uvc, struct uvc_transfer_data *td, void *priv); 167 168 /* start video transmission, copy method */ 169 170 extern int uvc_video_tran_copy(uvc_t uvc, uvc_continue_func copy_func, void *priv); 171 172 /* start video transmission, no-copy method */ 173 174 extern int uvc_video_tran_nocp(uvc_t uvc, uvc_continue_func next_func, void *priv); 175 176 /* stop stransmission */ 177 178 extern int uvc_video_stop(uvc_t uvc); 179 void usb_format_yuv_semiplanar_420(char *buf_virt_y, char *buf_virt_c, uint8_t *frame_mem, 180 uint32_t frame_len, uint32_t frame_height, uint32_t frame_width); 181 182 extern uint32_t g_uvc_mutex; 183 184 #ifdef __cplusplus 185 #if __cplusplus 186 } 187 #endif /* __cplusplus */ 188 #endif /* __cplusplus */ 189 190 #endif 191