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