1 #include <stdbool.h>
2 #include <string.h>
3 #include <sys/ioctl.h>
4 #include <sys/time.h>
5 #include <sys/types.h>
6 #include <unistd.h>
7
8 #include "HaasLog.h"
9 #include "ak_common.h"
10 #include "ak_common_video.h"
11 #include "ak_venc.h"
12 #include "ak_vi.h"
13 #include "ak_vpss.h"
14 #include "dev_info.h"
15 #include "minIni.h"
16 #include "usb_s_uvc_ioctl.h"
17 #include "videocommon.h"
18
19 #define UVC_ENC_CONFIG_FILE "/etc/config/anyka_app.ini"
20
py_venc_init(int width,int height,int fps,int media_type)21 int py_venc_init(int width, int height, int fps, int media_type)
22 {
23 int ret = -1, handle_id = -1;
24 struct venc_param param;
25
26 param.width = width;
27 param.height = height;
28 param.fps = fps;
29 param.goplen = fps * 2;
30 param.target_kbps = 1024;
31 param.max_kbps = 1024;
32 param.br_mode = BR_MODE_CBR;
33 param.minqp = 25;
34 param.maxqp = 48;
35 param.initqp = (param.minqp + param.maxqp) >> 1;
36 param.chroma_mode = CHROMA_4_2_0;
37 param.max_picture_size = 0;
38 param.enc_level = 41;
39 param.smart_mode = 0;
40 param.smart_goplen = 100;
41 param.smart_quality = 50;
42 param.smart_static_value = 0;
43 param.jpeg_qlevel = JPEG_QLEVEL_DEFAULT;
44 param.smart_static_value = 550;
45
46 if (VIDEO_MEDIA_TYPE_JPEG == media_type) {
47 param.minqp =
48 ini_getl("usbcam", "mjpeg_minqp", 50, UVC_ENC_CONFIG_FILE);
49 param.maxqp =
50 ini_getl("usbcam", "mjpeg_maxqp", 50, UVC_ENC_CONFIG_FILE);
51 param.max_kbps =
52 ini_getl("usbcam", "mjpeg_kbps", 1024, UVC_ENC_CONFIG_FILE);
53 param.target_kbps =
54 ini_getl("usbcam", "mjpeg_kbps", 1024, UVC_ENC_CONFIG_FILE);
55
56 param.profile = PROFILE_JPEG;
57 param.enc_out_type = MJPEG_ENC_TYPE;
58 } else if (VIDEO_MEDIA_TYPE_H264 == media_type) {
59 param.minqp = ini_getl("usbcam", "h264_minqp", 25, UVC_ENC_CONFIG_FILE);
60 param.maxqp = ini_getl("usbcam", "h264_maxqp", 48, UVC_ENC_CONFIG_FILE);
61 param.max_kbps =
62 ini_getl("usbcam", "h264_kbps", 1024, UVC_ENC_CONFIG_FILE);
63 param.target_kbps =
64 ini_getl("usbcam", "h264_kbps", 1024, UVC_ENC_CONFIG_FILE);
65
66 param.profile = PROFILE_MAIN;
67 param.enc_out_type = H264_ENC_TYPE;
68 } else {
69 param.minqp = ini_getl("usbcam", "hevc_minqp", 25, UVC_ENC_CONFIG_FILE);
70 param.maxqp = ini_getl("usbcam", "hevc_maxqp", 50, UVC_ENC_CONFIG_FILE);
71 param.max_kbps =
72 ini_getl("usbcam", "hevc_kbps", 1024, UVC_ENC_CONFIG_FILE);
73 param.target_kbps =
74 ini_getl("usbcam", "hevc_kbps", 1024, UVC_ENC_CONFIG_FILE);
75
76 param.profile = PROFILE_HEVC_MAIN;
77 param.enc_out_type = HEVC_ENC_TYPE;
78 }
79
80 ret = ak_venc_open(¶m, &handle_id);
81 if (ret || -1 == handle_id) {
82 LOG_E("%s, enc open fail(id:%d, ret:%d)\r\n", __func__, ret, handle_id);
83 return ret;
84 }
85
86 return handle_id;
87 }
88