gboolean gst_imx_vpu_base_enc_load(void) { VpuEncRetCode ret; #define VPUINIT_ERR(RET, DESC, UNLOAD) \ if ((RET) != VPU_ENC_RET_SUCCESS) \ { \ g_mutex_unlock(&inst_counter_mutex); \ GST_ERROR("%s: %s", (DESC), gst_imx_vpu_strerror(RET)); \ if (UNLOAD) \ VPU_EncUnLoad(); \ return FALSE; \ } g_mutex_lock(&inst_counter_mutex); if (inst_counter == 0) { ret = VPU_EncLoad(); VPUINIT_ERR(ret, "loading VPU encoder failed", FALSE); { VpuVersionInfo version; VpuWrapperVersionInfo wrapper_version; ret = VPU_EncGetVersionInfo(&version); VPUINIT_ERR(ret, "getting version info failed", TRUE); ret = VPU_EncGetWrapperVersionInfo(&wrapper_version); VPUINIT_ERR(ret, "getting wrapper version info failed", TRUE); GST_INFO("VPU encoder loaded"); GST_INFO("VPU firmware version %d.%d.%d_r%d", version.nFwMajor, version.nFwMinor, version.nFwRelease, version.nFwCode); GST_INFO("VPU library version %d.%d.%d", version.nLibMajor, version.nLibMinor, version.nLibRelease); GST_INFO("VPU wrapper version %d.%d.%d %s", wrapper_version.nMajor, wrapper_version.nMinor, wrapper_version.nRelease, wrapper_version.pBinary); } } ++inst_counter; g_mutex_unlock(&inst_counter_mutex); #undef VPUINIT_ERR return TRUE; }
static gboolean gst_fsl_vpu_base_enc_start(GstVideoEncoder *encoder) { VpuEncRetCode ret; GstFslVpuBaseEnc *vpu_base_enc; GstFslVpuBaseEncClass *klass; vpu_base_enc = GST_FSL_VPU_BASE_ENC(encoder); klass = GST_FSL_VPU_BASE_ENC_CLASS(G_OBJECT_GET_CLASS(vpu_base_enc)); #define VPUINIT_ERR(RET, DESC, UNLOAD) \ if ((RET) != VPU_ENC_RET_SUCCESS) \ { \ g_mutex_unlock(&inst_counter_mutex); \ GST_ELEMENT_ERROR(vpu_base_enc, LIBRARY, INIT, ("%s: %s", (DESC), gst_fsl_vpu_strerror(RET)), (NULL)); \ if (UNLOAD) \ VPU_EncUnLoad(); \ return FALSE; \ } g_mutex_lock(&inst_counter_mutex); if (klass->inst_counter == 0) { ret = VPU_EncLoad(); VPUINIT_ERR(ret, "loading VPU encoder failed", FALSE); { VpuVersionInfo version; VpuWrapperVersionInfo wrapper_version; ret = VPU_EncGetVersionInfo(&version); VPUINIT_ERR(ret, "getting version info failed", TRUE); ret = VPU_EncGetWrapperVersionInfo(&wrapper_version); VPUINIT_ERR(ret, "getting wrapper version info failed", TRUE); GST_INFO_OBJECT(vpu_base_enc, "VPU encoder loaded"); GST_INFO_OBJECT(vpu_base_enc, "VPU firmware version %d.%d.%d_r%d", version.nFwMajor, version.nFwMinor, version.nFwRelease, version.nFwCode); GST_INFO_OBJECT(vpu_base_enc, "VPU library version %d.%d.%d", version.nLibMajor, version.nLibMinor, version.nLibRelease); GST_INFO_OBJECT(vpu_base_enc, "VPU wrapper version %d.%d.%d %s", wrapper_version.nMajor, wrapper_version.nMinor, wrapper_version.nRelease, wrapper_version.pBinary); } } ++klass->inst_counter; g_mutex_unlock(&inst_counter_mutex); /* mem_info contains information about how to set up memory blocks * the VPU uses as temporary storage (they are "work buffers") */ memset(&(vpu_base_enc->mem_info), 0, sizeof(VpuMemInfo)); ret = VPU_EncQueryMem(&(vpu_base_enc->mem_info)); if (ret != VPU_ENC_RET_SUCCESS) { GST_ERROR_OBJECT(vpu_base_enc, "could not get VPU memory information: %s", gst_fsl_vpu_strerror(ret)); return FALSE; } /* Allocate the work buffers * Note that these are independent of encoder instances, so they * are allocated before the VPU_EncOpen() call, and are not * recreated in set_format */ if (!gst_fsl_vpu_base_enc_alloc_enc_mem_blocks(vpu_base_enc)) return FALSE; #undef VPUINIT_ERR /* The encoder is initialized in set_format, not here, since only then the input bitstream * format is known (and this information is necessary for initialization). */ return TRUE; }