static gboolean gst_fsl_vpu_base_enc_stop(GstVideoEncoder *encoder) { gboolean ret; VpuEncRetCode enc_ret; GstFslVpuBaseEnc *vpu_base_enc; GstFslVpuBaseEncClass *klass; ret = TRUE; vpu_base_enc = GST_FSL_VPU_BASE_ENC(encoder); klass = GST_FSL_VPU_BASE_ENC_CLASS(G_OBJECT_GET_CLASS(vpu_base_enc)); if (vpu_base_enc->framebuffers != NULL) { gst_object_unref(vpu_base_enc->framebuffers); vpu_base_enc->framebuffers = NULL; } if (vpu_base_enc->output_phys_buffer != NULL) { gst_allocator_free(gst_fsl_vpu_enc_allocator_obtain(), (GstMemory *)(vpu_base_enc->output_phys_buffer)); vpu_base_enc->output_phys_buffer = NULL; } gst_fsl_vpu_base_enc_close_encoder(vpu_base_enc); gst_fsl_vpu_base_enc_free_enc_mem_blocks(vpu_base_enc); g_mutex_lock(&inst_counter_mutex); if (klass->inst_counter > 0) { --klass->inst_counter; if (klass->inst_counter == 0) { enc_ret = VPU_EncUnLoad(); if (enc_ret != VPU_ENC_RET_SUCCESS) { GST_ERROR_OBJECT(vpu_base_enc, "unloading VPU encoder failed: %s", gst_fsl_vpu_strerror(enc_ret)); } else GST_INFO_OBJECT(vpu_base_enc, "VPU encoder unloaded"); } } g_mutex_unlock(&inst_counter_mutex); return ret; }
void gst_imx_vpu_base_enc_unload(void) { VpuEncRetCode ret; g_mutex_lock(&inst_counter_mutex); if (inst_counter > 0) { --inst_counter; if (inst_counter == 0) { ret = VPU_EncUnLoad(); if (ret != VPU_ENC_RET_SUCCESS) { GST_ERROR("unloading VPU encoder failed: %s", gst_imx_vpu_strerror(ret)); } else GST_INFO("VPU encoder unloaded"); } } g_mutex_unlock(&inst_counter_mutex); }
void enc_exit() { VPU_EncClose(gHandle); VPU_EncUnLoad(); enc_mem_free(&gMemInfo); }
int enc_init(int w, int h, int fps, VpuCodStd std) { int tmp, nBufNum, nAlign, nSize; VpuEncRetCode res; VpuVersionInfo ver; VpuWrapperVersionInfo vver; VpuMemInfo sMemInfo; VpuEncOpenParam sEncOpenParam; VpuEncInitInfo sEncInitInfo; VpuFrameBuffer sFrameBuf[MAX_FRAME_NUM]; res = VPU_EncLoad(); if(res != VPU_ENC_RET_SUCCESS) { printf("VPU_ENC load error : %d\n", res); return -1; } res = VPU_EncGetVersionInfo(&ver); if (res != VPU_ENC_RET_SUCCESS) { printf("VPU_ENC get version error : %d\n", res); goto err; } res = VPU_EncGetWrapperVersionInfo(&vver); if (res != VPU_ENC_RET_SUCCESS) { printf("VPU_ENC get wrapper version error : %d\n", res); goto err; } printf("======= VPU ENC =======\n"); printf(" LIB : %d.%d.%d\n", ver.nLibMajor, ver.nLibMinor, ver.nLibRelease); printf(" FW : %d.%d.%d.%d\n", ver.nFwMajor, ver.nFwMinor, ver.nFwRelease, ver.nFwCode); printf(" WLIB: %d.%d.%d\n", vver.nMajor, vver.nMinor, vver.nRelease); printf("=======================\n"); res = VPU_EncQueryMem(&sMemInfo); if (res != VPU_ENC_RET_SUCCESS) { printf("VPU_ENC query memory error : %d\n", res); goto err; } tmp = enc_mem_alloc(&sMemInfo, &gMemInfo); if(tmp) { printf("enc_mem_alloc error\n"); goto err; } bzero(&sEncOpenParam, sizeof(VpuEncOpenParam)); sEncOpenParam.eFormat = std; sEncOpenParam.sMirror = VPU_ENC_MIRDIR_NONE; sEncOpenParam.nPicWidth = w; sEncOpenParam.nPicHeight = h; sEncOpenParam.nRotAngle = 0; sEncOpenParam.nFrameRate = fps; sEncOpenParam.nBitRate = 5000; sEncOpenParam.nGOPSize = 100; sEncOpenParam.nChromaInterleave = 0; sEncOpenParam.nMapType = 0; sEncOpenParam.nLinear2TiledEnable = 0; sEncOpenParam.eColorFormat = VPU_COLOR_420; sEncOpenParam.nInitialDelay = 0; sEncOpenParam.nVbvBufferSize = 0; sEncOpenParam.sliceMode.sliceMode = 0; /* 0: 1 slice per picture; 1: Multiple slices per picture */ sEncOpenParam.sliceMode.sliceSizeMode = 0; /* 0: silceSize defined by bits; 1: sliceSize defined by MB number*/ sEncOpenParam.sliceMode.sliceSize = 4000;//4000; /* Size of a slice in bits or MB numbers */ //sEncOpenParam.enableAutoSkip = 1; sEncOpenParam.nUserGamma = 0.75*32768; /* (0*32768 <= gamma <= 1*32768) */ sEncOpenParam.nRcIntervalMode = 0; //1; /* 0:normal, 1:frame_level, 2:slice_level, 3: user defined Mb_level */ sEncOpenParam.nMbInterval = 0; // sEncOpenParam.nAvcIntra16x16OnlyModeEnable = 0; // sEncOpenParam.VpuEncStdParam.avcParam.avc_constrainedIntraPredFlag = 0; // sEncOpenParam.VpuEncStdParam.avcParam.avc_disableDeblk = 0; // sEncOpenParam.VpuEncStdParam.avcParam.avc_deblkFilterOffsetAlpha = 0; // sEncOpenParam.VpuEncStdParam.avcParam.avc_deblkFilterOffsetBeta = 0; // sEncOpenParam.VpuEncStdParam.avcParam.avc_chromaQpOffset = 0; // sEncOpenParam.VpuEncStdParam.avcParam.avc_audEnable = 0; // sEncOpenParam.VpuEncStdParam.avcParam.avc_fmoEnable = 0; // sEncOpenParam.VpuEncStdParam.avcParam.avc_fmoType = 0; // sEncOpenParam.VpuEncStdParam.avcParam.avc_fmoSliceNum = 0; // sEncOpenParam.VpuEncStdParam.avcParam.avc_fmoSliceSaveBufSize = 32; /* FMO_SLICE_SAVE_BUF_SIZE */ res = VPU_EncOpen(&gHandle, &sMemInfo, &sEncOpenParam); if (res != VPU_ENC_RET_SUCCESS) { printf("VPU_ENC open error : %d\n", res); goto err1; } res = VPU_EncConfig(gHandle, VPU_ENC_CONF_NONE, NULL); if(VPU_ENC_RET_SUCCESS != res) { printf("VPU_ENC config error : %d\n", res); goto err2; } //get initinfo res = VPU_EncGetInitialInfo(gHandle, &sEncInitInfo); if(VPU_ENC_RET_SUCCESS != res) { printf("VPU_ENC get Init Info error : %d\n", res); goto err2; } nBufNum = sEncInitInfo.nMinFrameBufferCount; nAlign = sEncInitInfo.nAddressAlignment; printf("Init OK: min buffer cnt: %d, alignment: %d\n", nBufNum, nAlign); tmp = enc_mem_frame(sEncOpenParam.eFormat, sFrameBuf, nBufNum, w, h, &gMemInfo, nAlign); if(tmp) { printf("enc_mem_frame error\n"); goto err2; } res = VPU_EncRegisterFrameBuffer(gHandle, sFrameBuf, nBufNum, w); if(VPU_ENC_RET_SUCCESS != res) { printf("VPU_ENC register frame buffer error : %d\n", res); goto err2; } nSize = w * h * 3 / 2; nSize += nAlign * 2; bzero(&sMemInfo, sizeof(VpuMemInfo)); sMemInfo.nSubBlockNum = 2; sMemInfo.MemSubBlock[0].MemType = VPU_MEM_PHY; sMemInfo.MemSubBlock[0].nAlignment = nAlign; sMemInfo.MemSubBlock[0].nSize = nSize; sMemInfo.MemSubBlock[1].MemType = VPU_MEM_PHY; sMemInfo.MemSubBlock[1].nAlignment = nAlign; sMemInfo.MemSubBlock[1].nSize = nSize; nSize = enc_mem_alloc(&sMemInfo, &gMemInfo); if(nSize) { printf("enc_mem_alloc error\n"); goto err2; } bzero(&gEncParam, sizeof(VpuEncEncParam)); gEncParam.eFormat = VPU_V_AVC; gEncParam.nPicWidth = w; gEncParam.nPicHeight = h; gEncParam.nFrameRate = sEncOpenParam.nFrameRate; gEncParam.nQuantParam = 0; gEncParam.nInPhyInput = (unsigned int)sMemInfo.MemSubBlock[0].pPhyAddr; gEncParam.nInVirtInput = (unsigned int)sMemInfo.MemSubBlock[0].pVirtAddr; gEncParam.nInInputSize = nSize; gEncParam.nInPhyOutput = (unsigned int)sMemInfo.MemSubBlock[1].pPhyAddr; gEncParam.nInVirtOutput=(unsigned int)sMemInfo.MemSubBlock[1].pVirtAddr; gEncParam.nInOutputBufLen = nSize; gEncParam.nForceIPicture = 0; gEncParam.nSkipPicture = 0; gEncParam.nEnableAutoSkip = 0; gEncParam.pInFrame = NULL; return 0; err2: VPU_EncClose(gHandle); err1: enc_mem_free(&gMemInfo); err: VPU_EncUnLoad(); return -1; }