Created
October 12, 2018 11:20
-
-
Save chertov/3d0d6bc3fc3d54ccfc9ef11398a530f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//use std::sync::{Arc, Mutex}; | |
//use tokio::prelude::*; | |
//use futures::Stream; | |
//use futures::{Future}; | |
#[macro_use] | |
extern crate nix; | |
use std::thread; | |
use std::fs::File; | |
use std::os::unix::io::IntoRawFd; | |
use std::io::prelude::*; | |
// use dlopen::raw::Library; | |
use hi::{str_err}; | |
pub static HI_SUCCESS: i32 = hi::HI_SUCCESS as i32; | |
static ALIGN_WIDTH: u32 = 64; | |
extern "C" { # [ link_name = "sensor_register_callback" ] pub fn sensor_register_callback() -> i32; } | |
extern "C" { # [ link_name = "sensor_unregister_callback" ] pub fn sensor_unregister_callback() -> i32; } | |
fn main() { | |
unsafe { hi::HI_MPI_SYS_Exit() }; | |
unsafe { hi::HI_MPI_VB_Exit() }; | |
let mut vb_conf = hi::VB_CONF_S { | |
u32MaxPoolCnt: 128, | |
astCommPool: [ | |
hi::hiVB_CONF_S_hiVB_CPOOL_S { | |
u32BlkCnt: 0, | |
u32BlkSize: 0, | |
acMmzName: [0;16usize] | |
}; 16usize] | |
}; | |
vb_conf.astCommPool[0].u32BlkSize = 3159360; | |
vb_conf.astCommPool[0].u32BlkCnt = 10; | |
let res = unsafe { hi::HI_MPI_VB_SetConf(&vb_conf) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_VB_SetConf failed with error code: {}", str_err(res)); | |
} | |
let supplement_conf = hi::VB_SUPPLEMENT_CONF_S { | |
u32SupplementConf: 1, | |
}; | |
let res = unsafe { hi::HI_MPI_VB_SetSupplementConf(&supplement_conf) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_VB_SetSupplementConf failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe { hi::HI_MPI_VB_Init() }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_VB_Init failed with error code: {}", str_err(res)); | |
} | |
let sys_conf = hi::MPP_SYS_CONF_S { | |
u32AlignWidth: ALIGN_WIDTH, | |
}; | |
let res = unsafe { hi::HI_MPI_SYS_SetConf(&sys_conf) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_SYS_SetConf failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe { hi::HI_MPI_SYS_Init() }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_SYS_Init failed with error code: {}", str_err(res)); | |
} | |
// =========== | |
{ | |
// let fd = std::fs::File::open("/dev/hi_mipi"); | |
// ioctl_none_bad!(tiocnxcl, libc::TIOCNXCL); | |
// let file = File::open("/dev/hi_mipi").unwrap(); | |
// use std::os::unix::io::AsRawFd; | |
// let fd = unsafe { tiocnxcl(file.as_raw_fd()) }; | |
use nix::fcntl::OFlag; | |
let fd = nix::fcntl::open( "/dev/hi_mipi", OFlag::O_RDWR, nix::sys::stat::Mode::empty(), ); | |
if fd.is_err() { panic!("warning: open hi_mipi dev failed {:?}", fd.err()); } | |
let fd = fd.unwrap(); | |
//println!("=============set_mipi_attr wdr_mode: {:?}\n", vi_config.wdr_mode); | |
let mipi_cmos3_v3_attr = hi::combo_dev_attr_t { | |
input_mode: hi::input_mode_t::INPUT_MODE_CMOS_33V, | |
__bindgen_anon_1: hi::combo_dev_attr_t__bindgen_ty_1 { | |
mipi_attr: hi::mipi_dev_attr_t { | |
lane_id: [0i16; 8], | |
raw_data_type: hi::raw_data_type_e::RAW_DATA_8BIT, | |
}, | |
}, | |
}; | |
let combo_dev_attr = &mipi_cmos3_v3_attr; | |
// #define HI_MIPI_IOC_MAGIC 'm' | |
// #define HI_MIPI_SET_DEV_ATTR _IOW(HI_MIPI_IOC_MAGIC, 0x01, combo_dev_attr_t) | |
// if (ioctl(fd, HI_MIPI_SET_DEV_ATTR, pstcomboDevAttr)) | |
const HI_MIPI_IOC_MAGIC: u8 = b'm'; | |
ioctl_write_ptr!(hi_mipi_set_dev_attr, HI_MIPI_IOC_MAGIC, 0x01, hi::combo_dev_attr_t); | |
// let res = unsafe { libc::ioctl(fd, request_code_write!(HI_MIPI_IOC_MAGIC, 0x01, std::mem::size_of::<hi::combo_dev_attr_t>()), combo_dev_attr) }; | |
let res = unsafe { hi_mipi_set_dev_attr(fd, combo_dev_attr).unwrap() }; | |
if res != HI_SUCCESS { | |
panic!("set mipi attr failed"); | |
} | |
//let _ = unsafe{ tiocnxcl(fd) }; | |
let _ = nix::unistd::close(fd); | |
} | |
// =========== | |
// let lib_path = "libsns_imx222.so"; | |
// let lib = Library::open(lib_path).expect("Could not open library " + lib_path); | |
// sensor_register_callback | |
println!("sensor_register_callback"); | |
let res = unsafe{ sensor_register_callback() }; | |
if HI_SUCCESS != res { | |
panic!("sensor_register_callback failed with error code: {}", str_err(res)); | |
} | |
let isp_dev = 0 as hi::ISP_DEV; | |
let mut lib = hi::ALG_LIB_S { | |
acLibName: *b"hisi_ae_lib\0 ", | |
s32Id: 0, | |
}; | |
lib.s32Id = 0; | |
lib.acLibName = *b"hisi_ae_lib\0 "; | |
println!("HI_MPI_AE_Register"); | |
let res = unsafe { hi::HI_MPI_AE_Register(isp_dev, &mut lib) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_AE_Register failed with error code: {}", str_err(res)); | |
} | |
lib.s32Id = 0; | |
lib.acLibName = *b"hisi_awb_lib\0 "; | |
println!("HI_MPI_AWB_Register"); | |
let res = unsafe { hi::HI_MPI_AWB_Register(isp_dev, &mut lib) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_AWB_Register failed with error code: {}", str_err(res)); | |
} | |
lib.s32Id = 0; | |
lib.acLibName = *b"hisi_af_lib\0 "; | |
println!("HI_MPI_AF_Register"); | |
let res = unsafe { hi::HI_MPI_AF_Register(isp_dev, &mut lib) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_AF_Register failed with error code: {}", str_err(res)); | |
} | |
println!("HI_MPI_ISP_MemInit"); | |
let res = unsafe { hi::HI_MPI_ISP_MemInit(isp_dev) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_ISP_MemInit failed with error code: {}", str_err(res)); | |
} | |
return; | |
let wdr_mode = hi::ISP_WDR_MODE_S { | |
enWDRMode: hi::WDR_MODE_E::WDR_MODE_NONE, | |
}; | |
let res = unsafe { hi::HI_MPI_ISP_SetWDRMode(isp_dev, &wdr_mode) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_ISP_SetWDRMode failed with error code: {}", str_err(res)); | |
} | |
let pub_attr = hi::ISP_PUB_ATTR_S { | |
enBayer: hi::ISP_BAYER_FORMAT_E::BAYER_RGGB, | |
f32FrameRate: 30.0, | |
stWndRect: hi::RECT_S { | |
s32X: 200, | |
s32Y: 20, | |
u32Width: 1920, | |
u32Height: 1080, | |
}, | |
}; | |
let res = unsafe { hi::HI_MPI_ISP_SetPubAttr(isp_dev, &pub_attr) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_ISP_SetPubAttr failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe { hi::HI_MPI_ISP_Init(isp_dev) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_ISP_Init failed with error code: {}", str_err(res)); | |
} | |
thread::spawn(|| { | |
let isp_dev = 0 as hi::ISP_DEV; | |
let res = unsafe { hi::HI_MPI_ISP_Run(isp_dev) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_ISP_Run failed with error code: {}", str_err(res)); | |
} | |
}); | |
let vi_dev = 0 as hi::VI_DEV; | |
let mut vi_dev_attr = hi::VI_DEV_ATTR_S::new(); | |
vi_dev_attr.enIntfMode = hi::VI_INTF_MODE_E::VI_MODE_DIGITAL_CAMERA; | |
vi_dev_attr.enWorkMode = hi::VI_WORK_MODE_E::VI_WORK_MODE_1Multiplex; | |
vi_dev_attr.au32CompMask[0] = 0xFFF00000; | |
vi_dev_attr.au32CompMask[1] = 0x0; | |
vi_dev_attr.enScanMode = hi::VI_SCAN_MODE_E::VI_SCAN_PROGRESSIVE; | |
vi_dev_attr.s32AdChnId = [-1i32; 4]; | |
vi_dev_attr.stDevRect.s32X = 0; | |
vi_dev_attr.stDevRect.s32Y = 0; | |
vi_dev_attr.stDevRect.u32Width = 1920; | |
vi_dev_attr.stDevRect.u32Height = 1080; | |
let res = unsafe { hi::HI_MPI_VI_SetDevAttr(vi_dev, &vi_dev_attr) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_VI_SetDevAttr failed with error code: {}", str_err(res)); | |
} | |
let mut wdr_mode = hi::ISP_WDR_MODE_S { | |
enWDRMode: hi::WDR_MODE_E::WDR_MODE_NONE, | |
}; | |
let res = unsafe { hi::HI_MPI_ISP_GetWDRMode(isp_dev, &mut wdr_mode) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_ISP_GetWDRMode failed with error code: {}", str_err(res)); | |
} | |
// TODO | |
let wdr_addr = hi::VI_WDR_ATTR_S { | |
enWDRMode: hi::WDR_MODE_E::WDR_MODE_NONE, | |
bCompress: hi::HI_BOOL::HI_FALSE, | |
}; | |
let res = unsafe { hi::HI_MPI_VI_SetWDRAttr(vi_dev, &wdr_addr) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_VI_SetWDRAttr failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe { hi::HI_MPI_VI_EnableDev(vi_dev) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_VI_EnableDev failed with error code: {}", str_err(res)); | |
} | |
let vi_chn = 0 as hi::VI_CHN; | |
let mut chn_attr = hi::VI_CHN_ATTR_S::new(); | |
chn_attr.stCapRect.s32X = 0; | |
chn_attr.stCapRect.s32Y = 0; | |
chn_attr.stCapRect.u32Width = 1920; | |
chn_attr.stCapRect.u32Height = 1080; | |
chn_attr.stDestSize.u32Width = 1920; | |
chn_attr.stDestSize.u32Height = 1080; | |
chn_attr.enCapSel = hi::VI_CAPSEL_E::VI_CAPSEL_BOTH; | |
chn_attr.enPixFormat = hi::PIXEL_FORMAT_E::PIXEL_FORMAT_YUV_SEMIPLANAR_420; | |
chn_attr.bMirror = hi::HI_BOOL::HI_FALSE; | |
chn_attr.bFlip = hi::HI_BOOL::HI_FALSE; | |
chn_attr.s32SrcFrameRate = -1; | |
chn_attr.s32DstFrameRate = -1; | |
chn_attr.enCompressMode = hi::COMPRESS_MODE_E::COMPRESS_MODE_NONE; | |
let chn_attr = chn_attr; | |
let res = unsafe { hi::HI_MPI_VI_SetChnAttr(vi_chn, &chn_attr) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_VI_SetChnAttr failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VI_EnableChn(vi_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VI_EnableChn failed with error code: {}", str_err(res)); | |
} | |
let vpss_grp : hi::VPSS_GRP = 0; | |
let mut vpss_grp_attr = hi::VPSS_GRP_ATTR_S { | |
u32MaxW: 1920, | |
u32MaxH: 1080, | |
enPixFmt: hi::PIXEL_FORMAT_E::PIXEL_FORMAT_YUV_SEMIPLANAR_420, | |
bIeEn: hi::HI_BOOL::HI_FALSE, | |
bDciEn: hi::HI_BOOL::HI_FALSE, | |
bNrEn: hi::HI_BOOL::HI_TRUE, | |
bHistEn: hi::HI_BOOL::HI_FALSE, | |
enDieMode: hi::VPSS_DIE_MODE_E::VPSS_DIE_MODE_NODIE, | |
}; | |
let res = unsafe{ hi::HI_MPI_VPSS_CreateGrp(vpss_grp, &mut vpss_grp_attr) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VPSS_CreateGrp failed with error code: {}", str_err(res)); | |
} | |
let mut nr_param = hi::VPSS_NR_PARAM_U { | |
stNRParam_V1: hi::VPSS_NR_PARAM_V1_S { | |
s32YPKStr: 0, | |
s32YSFStr: 0, | |
s32YTFStr: 0, | |
s32TFStrMax: 0, | |
s32TFStrMov: 0, | |
s32YSmthStr: 0, | |
s32YSmthRat: 0, | |
s32YSFStrDlt: 0, | |
s32YSFStrDl: 0, | |
s32YTFStrDlt: 0, | |
s32YTFStrDl: 0, | |
s32YSFBriRat: 0, | |
s32CSFStr: 0, | |
s32CTFstr: 0, | |
s32YTFMdWin: 0, | |
}, | |
}; | |
let res = unsafe{ hi::HI_MPI_VPSS_GetNRParam(vpss_grp, &mut nr_param) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VPSS_GetNRParam failed with error code: {}", str_err(res)); | |
} | |
// TODO | |
let mut nr_param = hi::VPSS_NR_PARAM_U { | |
stNRParam_V1: hi::VPSS_NR_PARAM_V1_S { | |
s32YPKStr: 0, | |
s32YSFStr: 100, | |
s32YTFStr: 64, | |
s32TFStrMax: 12, | |
s32TFStrMov: 0, | |
s32YSmthStr: 0, | |
s32YSmthRat: 16, | |
s32YSFStrDlt: 0, | |
s32YSFStrDl: 0, | |
s32YTFStrDlt: 0, | |
s32YTFStrDl: 0, | |
s32YSFBriRat: 24, | |
s32CSFStr: 32, | |
s32CTFstr: 0, | |
s32YTFMdWin: 1, | |
}, | |
}; | |
let res = unsafe{ hi::HI_MPI_VPSS_SetNRParam(vpss_grp, &mut nr_param) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VPSS_SetNRParam failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VPSS_StartGrp(vpss_grp) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VPSS_StartGrp failed with error code: {}", str_err(res)); | |
} | |
let mut src_chn = hi::MPP_CHN_S { | |
enModId: hi::MOD_ID_E::HI_ID_VIU, | |
s32DevId: 0, | |
s32ChnId: 0, | |
}; | |
let mut dest_chn = hi::MPP_CHN_S { | |
enModId: hi::MOD_ID_E::HI_ID_VPSS, | |
s32DevId: 0, | |
s32ChnId: 0, | |
}; | |
let res = unsafe{ hi::HI_MPI_SYS_Bind(&mut src_chn, &mut dest_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_SYS_Bind failed with error code: {}", str_err(res)); | |
} | |
let vpss_chn : hi::VPSS_CHN = 0; | |
let mut vpss_chn_attr = hi::VPSS_CHN_ATTR_S { | |
bSpEn: hi::HI_BOOL::HI_FALSE, | |
bBorderEn: hi::HI_BOOL::HI_FALSE, | |
bMirror: hi::HI_BOOL::HI_FALSE, | |
bFlip: hi::HI_BOOL::HI_FALSE, | |
s32SrcFrameRate: -1, | |
s32DstFrameRate: -1, | |
stBorder: hi::BORDER_S { | |
u32TopWidth: 0, | |
u32BottomWidth: 0, | |
u32LeftWidth: 0, | |
u32RightWidth: 0, | |
u32Color: 0, | |
} | |
}; | |
let res = unsafe{ hi::HI_MPI_VPSS_SetChnAttr(vpss_grp, vpss_chn, &mut vpss_chn_attr) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VPSS_SetChnAttr failed with error code: {}", str_err(res)); | |
} | |
let mut vpss_chn_mode = hi::VPSS_CHN_MODE_S { | |
enChnMode: hi::VPSS_CHN_MODE_E::VPSS_CHN_MODE_USER, | |
u32Width: 1920, | |
u32Height: 1080, | |
bDouble: hi::HI_BOOL::HI_FALSE, | |
enPixelFormat: hi::PIXEL_FORMAT_E::PIXEL_FORMAT_YUV_SEMIPLANAR_420, | |
enCompressMode: hi::COMPRESS_MODE_E::COMPRESS_MODE_NONE, | |
}; | |
let res = unsafe{ hi::HI_MPI_VPSS_SetChnMode(vpss_grp, vpss_chn, &mut vpss_chn_mode) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VPSS_SetChnMode failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VPSS_EnableChn(vpss_grp, vpss_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VPSS_EnableChn failed with error code: {}", str_err(res)); | |
} | |
let mut isp_dcf = hi::ISP_DCF_INFO_S { | |
au8ImageDescription: [248,156,240,190,200,154,240,190,0,224,239,182,0,0,0,0,248,156,240,190,216,154,240,190,16,174,240,182,0,0,0,0,], | |
au8Make: [248,156,240,190,232,154,240,190,200,172,240,182,0,0,0,0,248,156,240,190,248,154,240,190,128,171,240,182,0,0,0,0,], | |
au8Model: [248,156,240,190,8,155,240,190,64,170,240,182,0,0,0,0,248,156,240,190,24,155,240,190,0,169,240,182,0,0,0,0,], | |
au8Software: [248,156,240,190,40,155,240,190,184,167,240,182,0,0,0,0,248,156,240,190,56,155,240,190,112,166,240,182,0,0,0,0,], | |
u16ISOSpeedRatings: 40184, | |
u32FNumber: 3203439432, | |
u32MaxApertureValue: 3069224232, | |
u32ExposureTime: 0, | |
u32ExposureBiasValue: 3203439864, | |
u8ExposureProgram: 88, | |
u8MeteringMode: 155, | |
u8LightSource: 240, | |
u32FocalLength: 3069223904, | |
u8SceneType: 0, | |
u8CustomRendered: 0, | |
u8ExposureMode: 0, | |
u8WhiteBalance: 0, | |
u8FocalLengthIn35mmFilm: 248, | |
u8SceneCaptureType: 156, | |
u8GainControl: 240, | |
u8Contrast: 190, | |
u8Saturation: 104, | |
u8Sharpness: 155, | |
}; | |
let res = unsafe{ hi::HI_MPI_ISP_GetDCFInfo(&mut isp_dcf) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_ISP_GetDCFInfo failed with error code: {}", str_err(res)); | |
} | |
let mut isp_dcf = hi::ISP_DCF_INFO_S { | |
au8ImageDescription: [84,104,117,109,98,110,97,105,108,32,116,101,115,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,], | |
au8Make: [72,105,115,105,108,105,99,111,110,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,], | |
au8Model: [72,105,115,105,108,105,99,111,110,32,73,80,32,67,97,109,101,114,97,0,0,0,0,0,0,0,0,0,0,0,0,0,], | |
au8Software: [118,46,49,46,49,46,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,], | |
u16ISOSpeedRatings: 500, | |
u32FNumber: 65551, | |
u32MaxApertureValue: 65537, | |
u32ExposureTime: 65540, | |
u32ExposureBiasValue: 5, | |
u8ExposureProgram: 1, | |
u8MeteringMode: 1, | |
u8LightSource: 1, | |
u32FocalLength: 6553601, | |
u8SceneType: 0, | |
u8CustomRendered: 0, | |
u8ExposureMode: 0, | |
u8WhiteBalance: 1, | |
u8FocalLengthIn35mmFilm: 1, | |
u8SceneCaptureType: 1, | |
u8GainControl: 1, | |
u8Contrast: 5, | |
u8Saturation: 1, | |
u8Sharpness: 5, | |
}; | |
let res = unsafe{ hi::HI_MPI_ISP_SetDCFInfo(&mut isp_dcf) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_ISP_SetDCFInfo failed with error code: {}", str_err(res)); | |
} | |
let jpeg_attr = hi::VENC_ATTR_JPEG_S { | |
u32MaxPicWidth: 1920, /*maximum width of a picture to be encoded, in pixel*/ | |
u32MaxPicHeight: 1080, /*maximum height of a picture to be encoded, in pixel*/ | |
u32BufSize: (((1920+15)>>4)<<4) * (((1080+15)>>4)<<4), /*stream buffer size*/ | |
bByFrame: hi::HI_BOOL::HI_TRUE, /*get stream mode is field mode or frame mode*/ | |
u32PicWidth: 1920, /*width of a picture to be encoded, in pixel*/ | |
u32PicHeight: 1080, /*height of a picture to be encoded, in pixel*/ | |
bSupportDCF: hi::HI_BOOL::HI_FALSE, /*support dcf*/ | |
}; | |
let ve_attr = hi::VENC_ATTR_S { | |
enType: hi::PAYLOAD_TYPE_E::PT_JPEG, | |
__bindgen_anon_1: hi::hiVENC_ATTR_S__bindgen_ty_1 { | |
stAttrJpeg: jpeg_attr, | |
}, | |
}; | |
let rc_attr = hi::VENC_RC_ATTR_S { | |
enRcMode: hi::VENC_RC_MODE_E::VENC_RC_MODE_H264CBR, | |
__bindgen_anon_1: hi::hiVENC_RC_ATTR_S__bindgen_ty_1 { | |
stAttrH264Cbr: hi::VENC_ATTR_H264_CBR_S { | |
u32Gop: 0, /*the interval of ISLICE. */ | |
u32StatTime: 0, /* the rate statistic time, the unit is senconds(s) */ | |
u32SrcFrmRate: 0, /* the input frame rate of the sample_venc chnnel */ | |
fr32DstFrmRate: 0, /* the target frame rate of the sample_venc chnnel */ | |
u32BitRate: 0, /* average bitrate */ | |
u32FluctuateLevel: 0, | |
}, | |
}, | |
pRcAttr: 0 as *mut std::os::raw::c_void, | |
}; | |
let venc_chn : hi::VENC_CHN = 0; | |
let venc_chn_attr = hi::VENC_CHN_ATTR_S { | |
stVeAttr: ve_attr, | |
stRcAttr: rc_attr, | |
}; | |
let res = unsafe{ hi::HI_MPI_VENC_CreateChn(venc_chn, &venc_chn_attr) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_CreateChn failed with error code: {}", str_err(res)); | |
} | |
let mut src_chn = hi::MPP_CHN_S { | |
enModId: hi::MOD_ID_E::HI_ID_VPSS, | |
s32DevId: 0, | |
s32ChnId: 0, | |
}; | |
let mut dest_chn = hi::MPP_CHN_S { | |
enModId: hi::MOD_ID_E::HI_ID_VENC, | |
s32DevId: 0, | |
s32ChnId: 0, | |
}; | |
let res = unsafe{ hi::HI_MPI_SYS_Bind(&mut src_chn, &mut dest_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_StartRecvPic failed with error code: {}", str_err(res)); | |
} | |
let mut recv_param = hi::VENC_RECV_PIC_PARAM_S { s32RecvPicNum: 1 }; | |
let res = unsafe{ hi::HI_MPI_VENC_StartRecvPicEx(venc_chn, &mut recv_param) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_StartRecvPic failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VENC_GetFd(venc_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_GetFd failed with error code: {}", str_err(res)); | |
} | |
let mut stat = hi::VENC_CHN_STAT_S { | |
u32LeftPics: 3203439068, | |
u32LeftStreamBytes: 0, | |
u32LeftStreamFrames: 0, | |
u32CurPacks: 0, | |
u32LeftRecvPics: 0, | |
u32LeftEncPics: 0, | |
}; | |
let res = unsafe{ hi::HI_MPI_VENC_Query(venc_chn, &mut stat) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_Query failed with error code: {}", str_err(res)); | |
} | |
let pack = hi::VENC_PACK_S { | |
u32PhyAddr: 0, | |
pu8Addr: 0 as *mut u8, | |
u32Len: 0, | |
u64PTS: 0, | |
bFrameEnd: hi::HI_BOOL::HI_TRUE, | |
DataType: hi::VENC_DATA_TYPE_U { | |
enH264EType: hi::H264E_NALU_TYPE_E::H264E_NALU_PSLICE, | |
}, | |
u32Offset: 0, | |
u32DataNum: 0, | |
stPackInfo: [hi::hiVENC_PACK_INFO_S { | |
u32PackLength:0, | |
u32PackOffset:0, | |
u32PackType: hi::hiVENC_DATA_TYPE_U { | |
enH264EType: hi::H264E_NALU_TYPE_E::H264E_NALU_PSLICE, | |
} | |
}; 8], | |
}; | |
//let mut x: hi::VENC_PACK_S = unsafe { std::mem::uninitialized() }; | |
let mut packs = vec![pack; stat.u32CurPacks as usize].into_boxed_slice(); | |
// let mut data: [Vec<u32>; 1000]; | |
// data = mem::uninitialized(); | |
let mut stream = hi::VENC_STREAM_S { | |
pstPack: packs.as_mut_ptr(), | |
u32PackCount: 0, | |
u32Seq: 0, | |
__bindgen_anon_1: hi::hiVENC_STREAM_S__bindgen_ty_1 { | |
stJpegInfo: hi::VENC_STREAM_INFO_JPEG_S { | |
u32PicBytesNum: 0, | |
u32Qfactor: 0, | |
u32UpdateAttrCnt: 0, | |
} | |
}, | |
}; | |
let res = unsafe{ hi::HI_MPI_VENC_GetStream(venc_chn, &mut stream, -1) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_GetStream failed with error code: {}", str_err(res)); | |
} | |
// TODO | |
let packs = unsafe { std::slice::from_raw_parts(stream.pstPack as *const hi::hiVENC_PACK_S, stream.u32PackCount as usize) }; | |
let mut jpg_file = File::create("/tmp/rust.jpg").unwrap(); | |
for pack in packs { | |
println!("{}", pack.u32PhyAddr); | |
let buf = unsafe { std::slice::from_raw_parts(pack.pu8Addr.offset(pack.u32Offset as isize), (pack.u32Len - pack.u32Offset) as usize) }; | |
jpg_file.write(buf).unwrap(); | |
jpg_file.flush().unwrap(); | |
} | |
let res = unsafe{ hi::HI_MPI_VENC_ReleaseStream(venc_chn, &mut stream) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_ReleaseStream failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VENC_StopRecvPic(venc_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_StopRecvPic failed with error code: {}", str_err(res)); | |
} | |
let mut src_chn = hi::MPP_CHN_S { | |
enModId: hi::MOD_ID_E::HI_ID_VPSS, | |
s32DevId: 0, | |
s32ChnId: 0, | |
}; | |
let mut dest_chn = hi::MPP_CHN_S { | |
enModId: hi::MOD_ID_E::HI_ID_VENC, | |
s32DevId: 0, | |
s32ChnId: 0, | |
}; | |
let res = unsafe{ hi::HI_MPI_SYS_UnBind(&mut src_chn, &mut dest_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_SYS_UnBind failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VENC_StopRecvPic(venc_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_StopRecvPic failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VENC_DestroyChn(venc_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_DestroyChn failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VENC_DestroyChn(venc_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_DestroyChn failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VPSS_DisableChn(vpss_grp, vpss_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VENC_DestroyChn failed with error code: {}", str_err(res)); | |
} | |
let mut src_chn = hi::MPP_CHN_S { | |
enModId: hi::MOD_ID_E::HI_ID_VIU, | |
s32DevId: 0, | |
s32ChnId: 0, | |
}; | |
let mut dest_chn = hi::MPP_CHN_S { | |
enModId: hi::MOD_ID_E::HI_ID_VPSS, | |
s32DevId: 0, | |
s32ChnId: 0, | |
}; | |
let res = unsafe{ hi::HI_MPI_SYS_UnBind(&mut src_chn, &mut dest_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_SYS_UnBind failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VPSS_StopGrp(vpss_grp) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VPSS_StopGrp failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VPSS_DestroyGrp(vpss_grp) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VPSS_DestroyGrp failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VI_DisableChn(vi_chn) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VI_DisableChn failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VI_DisableDev(vi_dev) }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VI_DisableDev failed with error code: {}", str_err(res)); | |
} | |
lib.s32Id = 0; | |
lib.acLibName = *b"hisi_af_lib\0 "; | |
let res = unsafe { hi::HI_MPI_AF_UnRegister(isp_dev, &mut lib) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_AF_UnRegister failed with error code: {}", str_err(res)); | |
} | |
lib.s32Id = 0; | |
lib.acLibName = *b"hisi_awb_lib\0 "; | |
let res = unsafe { hi::HI_MPI_AWB_UnRegister(isp_dev, &mut lib) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_AWB_UnRegister failed with error code: {}", str_err(res)); | |
} | |
lib.s32Id = 0; | |
lib.acLibName = *b"hisi_ae_lib\0 "; | |
let res = unsafe { hi::HI_MPI_AE_UnRegister(isp_dev, &mut lib) }; | |
if HI_SUCCESS != res { | |
panic!("HI_MPI_AE_UnRegister failed with error code: {}", str_err(res)); | |
} | |
// sensor_unregister_callback | |
let res = unsafe{ sensor_unregister_callback() }; | |
if HI_SUCCESS != res { | |
panic!("sensor_unregister_callback failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_SYS_Exit() }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_SYS_Exit failed with error code: {}", str_err(res)); | |
} | |
let res = unsafe{ hi::HI_MPI_VB_Exit() }; | |
if res != HI_SUCCESS { | |
panic!("HI_MPI_VB_Exit failed with error code: {}", str_err(res)); | |
} | |
// println!("Ok!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment