1 #ifndef HAAS_VIDEO_COMMON_H 2 #define HAAS_VIDEO_COMMON_H 3 4 #include "ak_common.h" 5 #include "ak_vi.h" 6 #include "py/objlist.h" 7 #include "py/objstr.h" 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #define UVC_FILE "/dev/usbuvc" 14 #define UVC_DEFAULT_FORMAT VIDEO_MEDIA_TYPE_YUV 15 16 #define CAMERA_MAIN_CHN_DEFAULT_WIDTH (1920) 17 #define CAMERA_MAIN_CHN_DEFAULT_HEIGHT (1080) 18 #define CAMERA_SUB_CHN_DEFAULT_WIDTH (640) 19 #define CAMERA_SUB_CHN_DEFAULT_HEIGHT (320) 20 #define CAMERA_DEFAULT_FPS (20) 21 22 #define VIDEO_CAMERA_OBJ_CHK(obj, err_type, err_str) \ 23 do { \ 24 if (obj == NULL) { \ 25 LOG_E("%s, %s\n", __func__, err_str); \ 26 mp_raise_OSError(err_type); \ 27 return mp_const_none; \ 28 } \ 29 } while (0) 30 31 #define VIDEO_CAMERA_RET_CHK(ret, dst_ret, err_str) \ 32 do { \ 33 if (obj != dst_ret) { \ 34 LOG_E("%s, %s\n", __func__, err_str); \ 35 mp_raise_OSError(MP_EIO); \ 36 return mp_const_none; \ 37 } \ 38 } while (0) 39 40 #define VIDEO_CAMERA_OBJ_INIT_CHK(obj, err_type, err_str) \ 41 do { \ 42 if (obj == NULL || obj->frame == NULL) { \ 43 LOG_E("%s, %s\n", __func__, err_str); \ 44 mp_raise_OSError(err_type); \ 45 return mp_const_none; \ 46 } \ 47 } while (0) 48 49 #define VIDEO_CAMERA_PARAM_CHK(n_arg, dst_cnt, err_str) \ 50 do { \ 51 if (n_arg != dst_cnt) { \ 52 LOG_E("%s, %s, arg:%d\n", __func__, n_arg); \ 53 mp_raise_OSError(MP_EINVAL); \ 54 return mp_const_none; \ 55 } \ 56 } while (0) 57 58 enum { 59 VIDEO_MEDIA_TYPE_YUV = 0, 60 VIDEO_MEDIA_TYPE_JPEG, 61 VIDEO_MEDIA_TYPE_H264, 62 VIDEO_MEDIA_TYPE_HEVC, 63 }; 64 65 typedef struct video_input_frame isp_frame_t; 66 67 typedef struct _camera_obj_t { 68 mp_obj_base_t base; 69 char *mname; 70 int camera_idx; 71 int frame_rate; 72 int frame_release; 73 isp_frame_t *frame; 74 } mp_video_camera_obj_t; 75 76 int py_video_camera_frame_get(isp_frame_t *frame); 77 int py_video_camera_frame_release(isp_frame_t *frame); 78 int py_video_camera_save(isp_frame_t *frame, int pic_type, const char *path); 79 80 int py_video_camera_open(int camera_idx, int frame_rate); 81 int py_video_camera_close(int camera_idx); 82 int py_video_camera_working(); 83 int py_video_camera_config_set(int width, int height, int media_type); 84 int py_video_camera_config_get(int *width, int *height, int *media_type); 85 void py_usbcam_video_ext_process_config(void (*ext_process)(isp_frame_t *), 86 void (*ext_evt_cb)(int)); 87 88 int py_venc_init(int width, int height, int fps, int media_type); 89 90 int py_usbcam_video_init(int camera_idx, int chan_idx); 91 int py_usbcam_video_deinit(); 92 93 int py_rtsp_stop(void); 94 int py_rtsp_start(void); 95 int py_rtsp_close(void); 96 int py_rtsp_pause(void); 97 int py_rtsp_resume(void); 98 int py_rtsp_open(int camera_idx, int media_type, int fps, const char *url); 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 #endif 105