Skip to content

Commit

Permalink
v4l2codecs: h264: Set frame flags
Browse files Browse the repository at this point in the history
V4L spec now requires coded buffer flags to be set in accordance to the
frame type. In particular this is required by H.264 decoder of NVIDIA Tegra
SoC to operate properly. Set the flags based on type of parsed slices.
  • Loading branch information
digetx committed Jan 16, 2022
1 parent de2434f commit aee292f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codech264dec.c
Expand Up @@ -68,6 +68,7 @@ struct _GstV4l2CodecH264Dec
guint chroma_format_idc;
guint num_slices;
gboolean first_slice;
guint frame_flags;

GstV4l2CodecAllocator *sink_allocator;
GstV4l2CodecAllocator *src_allocator;
Expand Down Expand Up @@ -981,6 +982,7 @@ gst_v4l2_codec_h264_dec_start_picture (GstH264Decoder * decoder,
dpb);

self->first_slice = TRUE;
self->frame_flags = 0;

return GST_FLOW_OK;
}
Expand Down Expand Up @@ -1288,6 +1290,20 @@ gst_v4l2_codec_h264_dec_decode_slice (GstH264Decoder * decoder,
slice->nalu.size);
self->bitstream_map.size += nal_size;

switch (slice->header.type % 5) {
case GST_H264_P_SLICE:
self->frame_flags |= V4L2_BUF_FLAG_PFRAME;
break;

case GST_H264_B_SLICE:
self->frame_flags |= V4L2_BUF_FLAG_BFRAME;
break;

case GST_H264_I_SLICE:
self->frame_flags |= V4L2_BUF_FLAG_KEYFRAME;
break;
}

return GST_FLOW_OK;
}

Expand All @@ -1296,11 +1312,11 @@ gst_v4l2_codec_h264_dec_end_picture (GstH264Decoder * decoder,
GstH264Picture * picture)
{
GstV4l2CodecH264Dec *self = GST_V4L2_CODEC_H264_DEC (decoder);
guint flags = 0;
guint flags = self->frame_flags;

/* Hold on the output frame if this is first field of a pair */
if (picture->field != GST_H264_PICTURE_FIELD_FRAME && !picture->second_field)
flags = V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF;
flags |= V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF;

if (!gst_v4l2_codec_h264_dec_submit_bitstream (self, picture, flags))
return GST_FLOW_ERROR;
Expand Down

0 comments on commit aee292f

Please sign in to comment.