[FAQ] TDA4VM: What parameters in the VPU driver are used for setting I-frame and IDR key-frame period?

Part Number: TDA4VM


Tool/software:

I'm using the TDA4VM Linux or Linux+RTOS 8.6 SDK. What parameters or patches are available to be enable I-frame period and IDR frame period?

  • As of the 8.6 SDK, the Imagination VPU GStreamer to V4L2 controls were not enabled and only were enabled in 9.0. You can still enable I-frame period by hard-coding the parameters in the 8.6 version of the driver. The following modifications in the vxe_v4l2.c will set the I-frame/IDR period to 5.

    •  In the vxe_s_ext_ctrls function under the V4L2_CID_MPEG_VIDEO_H264_I_PERIOD case, modify the ctx->rc.intra_freq = 5 and ctx->vparams.intra_cnt = 5 to make every 5 frames an I-frame:

    static int vxe_s_ext_ctrls(struct file *file, void *priv,
    			   struct v4l2_ext_controls *ctrls)
    {
    	struct vxe_enc_ctx *ctx = file2ctx(file);
    	struct device *dev = ctx->dev->dev;
    	int i;
    	int ret;
    
    	ctrls->reserved[0] = 0;
    	ctrls->reserved[1] = 0;
    
    	if (ctrls->which != V4L2_CTRL_WHICH_CUR_VAL)
    		return -EINVAL;
    
    	/* Verify first with try_ext_ctrls */
    	ret = vxe_try_ext_ctrls(file, priv, ctrls);
    	if (ret) {
    		/* Indicate verification stage error */
    		ctrls->error_idx = ctrls->count;
    		return ret;
    	}
    
    	/* Set all values in this set of commands */
    	for (i = 0; i < ctrls->count; i++) {
    		ctrls->controls[i].reserved2[0] = 0;
    
    		switch (ctrls->controls[i].id) {
    		case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
    			ctrls->controls[i].size = 0;
    			ctx->vparams.idr_period = 5;
    			break;
    		case V4L2_CID_MPEG_VIDEO_BITRATE:
    			ctrls->controls[i].size = 0;
    			ctx->rc.bits_per_second = ctrls->controls[i].value;
    			break;
    		case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:
    			ctrls->controls[i].size = 0;
    			ctx->rc.intra_freq = 5;
    			ctx->vparams.intra_cnt = 5;
    			break;
    		default:
    			dev_err(dev, "%s Invalid control id %#08x\n",
    				__func__, ctrls->controls[i].id);
    			ctrls->error_idx = i;
    			return -EINVAL;
    		}
    	}
    
    	return 0;
    }

    • To set the IDR key-frame period you will set both the above parameters and the GOP with ctx->vparams.idr_period = 5 under V4L2_CID_MPEG_VIDEO_GOP_SIZE  to make every 5 frames a key-frame.

    Since the userspace API is not implemented correctly to be controlled by GStreamer in the 5.10 (8.6 SDK) kernel. I will attach the patch that was made in the 6.1 (9.0 SDK) kernel which added this implementation to set V4L2 controls from GStreamer below:

    0268.tiL6.1-1-2-media-img-vxe-vxd-enable-GStreamer-1.20.5.patch

    With this patch you should be able to avoid hard-coding and the values in the driver and just use the GStreamer pipeline's plugins. However since this patch was implemented on a newer kernel TI is uncertain about what (if any) back-porting efforts are involved.

    Best Regards,
    Sarabesh S.