nvdec: Add support dynamic output format change

Implementing ::negotiate() method to support runtime output format
change. If downstream was reconfigured, baseclass will invoke
::negotiate() method, and nvdec should update output memory
type depending on downstream caps.
This commit is contained in:
Seungha Yang 2019-08-09 20:19:38 +09:00
parent 39f800c449
commit 069fe93452

View file

@ -157,7 +157,9 @@ static gboolean gst_nvdec_src_query (GstVideoDecoder * decoder,
static gboolean gst_nvdec_flush (GstVideoDecoder * decoder);
static GstFlowReturn gst_nvdec_drain (GstVideoDecoder * decoder);
static GstFlowReturn gst_nvdec_finish (GstVideoDecoder * decoder);
static gboolean gst_nvdec_negotiate (GstVideoDecoder * decoder);
#define gst_nvdec_parent_class parent_class
G_DEFINE_ABSTRACT_TYPE (GstNvDec, gst_nvdec, GST_TYPE_VIDEO_DECODER);
static void
@ -179,6 +181,7 @@ gst_nvdec_class_init (GstNvDecClass * klass)
video_decoder_class->drain = GST_DEBUG_FUNCPTR (gst_nvdec_drain);
video_decoder_class->flush = GST_DEBUG_FUNCPTR (gst_nvdec_flush);
video_decoder_class->finish = GST_DEBUG_FUNCPTR (gst_nvdec_finish);
video_decoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_nvdec_negotiate);
element_class->set_context = GST_DEBUG_FUNCPTR (gst_nvdec_set_context);
}
@ -406,8 +409,29 @@ parser_sequence_callback (GstNvDec * nvdec, CUVIDEOFORMAT * format)
}
if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (nvdec)) || updata) {
if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (nvdec))) {
nvdec->last_ret = GST_FLOW_NOT_NEGOTIATED;
return FALSE;
}
}
return TRUE;
error:
nvdec->last_ret = GST_FLOW_ERROR;
return FALSE;
}
static gboolean
gst_nvdec_negotiate (GstVideoDecoder * decoder)
{
GstNvDec *nvdec = GST_NVDEC (decoder);
GstVideoCodecState *state;
GstVideoInfo *vinfo;
GstVideoInfo *out_info = &nvdec->out_info;
gboolean ret;
GST_DEBUG_OBJECT (nvdec, "negotiate");
state = gst_video_decoder_set_output_state (GST_VIDEO_DECODER (nvdec),
GST_VIDEO_INFO_FORMAT (out_info), GST_VIDEO_INFO_WIDTH (out_info),
@ -464,18 +488,14 @@ parser_sequence_callback (GstNvDec * nvdec, CUVIDEOFORMAT * format)
nvdec->output_state = state;
if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (nvdec))) {
GST_WARNING_OBJECT (nvdec, "failed to negotiate with downstream");
ret = GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
if (!ret) {
GST_ERROR_OBJECT (nvdec, "failed to negotiate with downstream");
nvdec->last_ret = GST_FLOW_NOT_NEGOTIATED;
return FALSE;
}
}
return TRUE;
error:
nvdec->last_ret = GST_FLOW_ERROR;
return FALSE;
return ret;
}
static gboolean