Segmentation Faul Error
Posted: 2025-04-16 8:17
Hi, I have try to modify luckfox_pici_rtsp_opencv example. I'm try to add VPSS to source code, but when it's fail, error is Segmentation Faul( Core Dump).
Please help me check which part is wrong. Thank you!!
this is my main code:
And this is error:
Please help me check which part is wrong. Thank you!!
this is my main code:
Code: Select all
int main(int argc, char *argv[]) {
system("RkLunch-stop.sh");
RK_S32 s32Ret = 0;
int width = DISP_WIDTH;
int height = DISP_HEIGHT;
char fps_text[16];
float fps = 0;
memset(fps_text,0,16);
//h264_frame
VENC_STREAM_S stFrame;
stFrame.pstPack = (VENC_PACK_S *)malloc(sizeof(VENC_PACK_S));
RK_U64 H264_PTS = 0;
RK_U32 H264_TimeRef = 0;
VIDEO_FRAME_INFO_S stViFrame;
// Create Pool
MB_POOL_CONFIG_S PoolCfg;
memset(&PoolCfg, 0, sizeof(MB_POOL_CONFIG_S));
PoolCfg.u64MBSize = width * height * 3 ;
printf("%d\n",atoi(argv[1]));
RK_U32 blk = (RK_U32)atoi(argv[1]);
PoolCfg.u32MBCnt = blk;
printf("%d\n",blk);
PoolCfg.enAllocType = MB_ALLOC_TYPE_DMA;
//PoolCfg.bPreAlloc = RK_FALSE;
MB_POOL src_Pool = RK_MPI_MB_CreatePool(&PoolCfg);
printf("Create Pool success !\n");
// Get MB from Pool
MB_BLK src_Blk = RK_MPI_MB_GetMB(src_Pool, width * height * 3, RK_TRUE);
// Build h264_frame
VIDEO_FRAME_INFO_S h264_frame;
h264_frame.stVFrame.u32Width = width;
h264_frame.stVFrame.u32Height = height;
h264_frame.stVFrame.u32VirWidth = width;
h264_frame.stVFrame.u32VirHeight = height;
h264_frame.stVFrame.enPixelFormat = RK_FMT_RGB888;
h264_frame.stVFrame.u32FrameFlag = 160;
h264_frame.stVFrame.pMbBlk = src_Blk;
unsigned char *data = (unsigned char *)RK_MPI_MB_Handle2VirAddr(src_Blk);
cv::Mat frame(cv::Size(width,height),CV_8UC3,data);
// rkaiq init
RK_BOOL multi_sensor = RK_FALSE;
const char *iq_dir = "/etc/iqfiles";
rk_aiq_working_mode_t hdr_mode = RK_AIQ_WORKING_MODE_NORMAL;
//hdr_mode = RK_AIQ_WORKING_MODE_ISP_HDR2;
SAMPLE_COMM_ISP_Init(0, hdr_mode, multi_sensor, iq_dir);
SAMPLE_COMM_ISP_Run(0);
// rkmpi init
if (RK_MPI_SYS_Init() != RK_SUCCESS) {
RK_LOGE("rk mpi sys init fail!");
return -1;
}
// rtsp init
rtsp_demo_handle g_rtsplive = NULL;
rtsp_session_handle g_rtsp_session;
g_rtsplive = create_rtsp_demo(554);
g_rtsp_session = rtsp_new_session(g_rtsplive, "/live/0");
rtsp_set_video(g_rtsp_session, RTSP_CODEC_ID_VIDEO_H264, NULL, 0);
rtsp_sync_video_ts(g_rtsp_session, rtsp_get_reltime(), rtsp_get_ntptime());
// vi init
vi_dev_init();
vi_chn_init(0, width, height);
if(vpss_init(0,width, height)== RK_SUCCESS){
printf("VPSS INIT SUCCESS\n");
}
// venc init
RK_CODEC_ID_E enCodecType = RK_VIDEO_ID_AVC;
venc_init(0, width, height, enCodecType);
MPP_CHN_S stSrcChn,stvpssChn;
stSrcChn.enModId = RK_ID_VI;
stSrcChn.s32ChnId =0;
stSrcChn.s32DevId = 0;
stvpssChn.enModId = RK_ID_VPSS;
stvpssChn.s32ChnId =0;
stvpssChn.s32DevId = 0;
RK_MPI_SYS_Bind(&stSrcChn,&stvpssChn);
printf("init success\n");
while(1) {
// get vi frame
h264_frame.stVFrame.u32TimeRef = H264_TimeRef++;
h264_frame.stVFrame.u64PTS = TEST_COMM_GetNowUs();
// s32Ret = RK_MPI_VI_GetChnFrame(0, 0, &stViFrame, -1);
s32Ret = RK_MPI_VPSS_GetChnFrame(0,0,&stViFrame, -1);
if(s32Ret == RK_SUCCESS)
{
void *vi_data = RK_MPI_MB_Handle2VirAddr(stViFrame.stVFrame.pMbBlk);
cv::Mat yuv420sp(height + height / 2, width, CV_8UC1, vi_data);
cv::Mat bgr(height, width, CV_8UC3, data);
// cv::rotate(bgr,bgr,ROTATION_180);
cv::cvtColor(yuv420sp, bgr, cv::COLOR_YUV420sp2BGR);
cv::resize(bgr, frame, cv::Size(width ,height), 0, 0, cv::INTER_LINEAR);
sprintf(fps_text,"fps = %.2f",fps);
cv::putText(frame,fps_text,
cv::Point(40, 40),
cv::FONT_HERSHEY_SIMPLEX,1,
cv::Scalar(0,255,0),2);
}
memcpy(data, frame.data, width * height * 3);
// encode H264
RK_MPI_VENC_SendFrame(0, &h264_frame ,-1);
// rtsp
s32Ret = RK_MPI_VENC_GetStream(0, &stFrame, -1);
if(s32Ret == RK_SUCCESS) {
if(g_rtsplive && g_rtsp_session) {
//printf("len = %d PTS = %d \n",stFrame.pstPack->u32Len, stFrame.pstPack->u64PTS);
void *pData = RK_MPI_MB_Handle2VirAddr(stFrame.pstPack->pMbBlk);
rtsp_tx_video(g_rtsp_session, (uint8_t *)pData, stFrame.pstPack->u32Len,
stFrame.pstPack->u64PTS);
rtsp_do_event(g_rtsplive);
}
RK_U64 nowUs = TEST_COMM_GetNowUs();
fps = (float) 1000000 / (float)(nowUs - h264_frame.stVFrame.u64PTS);
}
// release frame
s32Ret = RK_MPI_VI_ReleaseChnFrame(0, 0, &stViFrame);
if (s32Ret != RK_SUCCESS) {
RK_LOGE("RK_MPI_VI_ReleaseChnFrame fail %x", s32Ret);
}
s32Ret = RK_MPI_VENC_ReleaseStream(0, &stFrame);
if (s32Ret != RK_SUCCESS) {
RK_LOGE("RK_MPI_VENC_ReleaseStream fail %x", s32Ret);
}
}
// Destory MB
RK_MPI_MB_ReleaseMB(src_Blk);
// Destory Pool
RK_MPI_MB_DestroyPool(src_Pool);
RK_MPI_VI_DisableChn(0, 0);
RK_MPI_VI_DisableDev(0);
RK_MPI_VPSS_StopGrp(0);
RK_MPI_VPSS_DestroyGrp(0);
SAMPLE_COMM_ISP_Stop(0);
RK_MPI_VENC_StopRecvFrame(0);
RK_MPI_VENC_DestroyChn(0);
free(stFrame.pstPack);
if (g_rtsplive)
rtsp_del_demo(g_rtsplive);
RK_MPI_SYS_Exit();
return 0;
}
Code: Select all
=== 0 ===
RTDeviceV4L2 15:57:56-766 {ispStreamOn :511} do ispStreamOn done
vpss_init
rga_api version 1.10.1_[0]
VPSS INIT SUCCESS
venc_init
MpiAdapterEncode 15:57:56-780 {ma_encode_create :1743} ringbuf buf_size 3112960
MpiAdapterEncode 15:57:56-788 {ma_encode_create :1782} mem_fd = 55
init success
=== 1 ===
MpiAdapterEncode 15:57:56-863 {ma_encode_get_pack:2079} map ptr: 0xa3d9e000, fd 56
[DEBUG utils.c:134:rtsp_codec_data_parse_from_user_h264] sps 30
[DEBUG utils.c:142:rtsp_codec_data_parse_from_user_h264] pps 4
Segmentation fault (core dumped)