From ae9411e33406ff13dd7ad8d2763ad5f537539fc5 Mon Sep 17 00:00:00 2001 From: Ezequiel Garcia Date: Wed, 30 Sep 2020 14:22:14 -0300 Subject: [PATCH] v4l2codecs: h264: Only slice-based need SLICE_PARAMS and PRED_WEIGHTS Frame-based decoding mode doesn't require SLICE_PARAMS and PRED_WEIGHTS controls. Moreover, if the driver doesn't support these two controls, trying to set them will fail. Fix this by only setting these on slice-based decoding mode. Part-of: --- sys/v4l2codecs/gstv4l2codech264dec.c | 46 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/sys/v4l2codecs/gstv4l2codech264dec.c b/sys/v4l2codecs/gstv4l2codech264dec.c index 62fa7f3c74..bd802eb287 100644 --- a/sys/v4l2codecs/gstv4l2codech264dec.c +++ b/sys/v4l2codecs/gstv4l2codech264dec.c @@ -126,22 +126,22 @@ gst_v4l2_decoder_h264_api_check (GstV4l2CodecH264Dec * self) unsigned int size; } controls[] = { { - .id = V4L2_CID_MPEG_VIDEO_H264_SPS, + .id = V4L2_CID_STATELESS_H264_SPS, .size = sizeof(struct v4l2_ctrl_h264_sps), }, { - .id = V4L2_CID_MPEG_VIDEO_H264_PPS, + .id = V4L2_CID_STATELESS_H264_PPS, .size = sizeof(struct v4l2_ctrl_h264_pps), }, { - .id = V4L2_CID_MPEG_VIDEO_H264_SCALING_MATRIX, + .id = V4L2_CID_STATELESS_H264_SCALING_MATRIX, .size = sizeof(struct v4l2_ctrl_h264_scaling_matrix), }, { - .id = V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS, + .id = V4L2_CID_STATELESS_H264_DECODE_PARAMS, .size = sizeof(struct v4l2_ctrl_h264_decode_params), }, { - .id = V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAMS, + .id = V4L2_CID_STATELESS_H264_SLICE_PARAMS, .size = sizeof(struct v4l2_ctrl_h264_slice_params), }, { - .id = V4L2_CID_MPEG_VIDEO_H264_PRED_WEIGHTS, + .id = V4L2_CID_STATELESS_H264_PRED_WEIGHTS, .size = sizeof(struct v4l2_ctrl_h264_pred_weights), } }; @@ -1012,6 +1012,7 @@ gst_v4l2_codec_h264_dec_submit_bitstream (GstV4l2CodecH264Dec * self, GstV4l2Request *prev_request, *request = NULL; gsize bytesused; gboolean ret = FALSE; + guint count; /* *INDENT-OFF* */ struct v4l2_ext_control control[] = { @@ -1030,22 +1031,13 @@ gst_v4l2_codec_h264_dec_submit_bitstream (GstV4l2CodecH264Dec * self, .ptr = &self->scaling_matrix, .size = sizeof (self->scaling_matrix), }, - { - .id = V4L2_CID_STATELESS_H264_SLICE_PARAMS, - .ptr = self->slice_params->data, - .size = g_array_get_element_size (self->slice_params) - * self->num_slices, - }, - { - .id = V4L2_CID_STATELESS_H264_PRED_WEIGHTS, - .ptr = &self->pred_weight, - .size = sizeof (self->pred_weight), - }, { .id = V4L2_CID_STATELESS_H264_DECODE_PARAMS, .ptr = &self->decode_params, .size = sizeof (self->decode_params), }, + { }, + { }, }; /* *INDENT-ON* */ @@ -1081,8 +1073,24 @@ gst_v4l2_codec_h264_dec_submit_bitstream (GstV4l2CodecH264Dec * self, goto done; } - if (!gst_v4l2_decoder_set_controls (self->decoder, request, control, - G_N_ELEMENTS (control))) { + /* Always set SPS, PPS, SCALING_MATRIX and DECODE_PARAMS */ + count = 4; + + /* If it's not slice-based then it doesn't support per-slice controls. */ + if (is_slice_based (self)) { + control[count].id = V4L2_CID_STATELESS_H264_SLICE_PARAMS; + control[count].ptr = self->slice_params->data; + control[count].size = g_array_get_element_size (self->slice_params) + * self->num_slices; + count++; + + control[count].id = V4L2_CID_STATELESS_H264_PRED_WEIGHTS; + control[count].ptr = &self->pred_weight; + control[count].size = sizeof (self->pred_weight); + count++; + } + + if (!gst_v4l2_decoder_set_controls (self->decoder, request, control, count)) { GST_ELEMENT_ERROR (self, RESOURCE, WRITE, ("Driver did not accept the bitstream parameters."), (NULL)); goto done;