videodec/enc: clear reconfigure flag if negotiate succeeds

So that it avoids to send an allocation query twice.
One from an early call to gst_video_encoder_negotiate from a
subclass, then one from gst_video_encoder_allocate_output_frame.
Which means that previously gst_video_encoder_negotiate was not
clearing the GST_PAD_FLAG_NEED_RECONFIGURE even on success.

Fixes bug https://bugzilla.gnome.org/show_bug.cgi?id=719684
This commit is contained in:
Julien Isorce 2013-12-05 14:31:25 +00:00
parent 4a37d90e9d
commit 79ef75888c
2 changed files with 68 additions and 19 deletions

View file

@ -459,6 +459,8 @@ static gboolean gst_video_decoder_propose_allocation_default (GstVideoDecoder *
static gboolean gst_video_decoder_negotiate_default (GstVideoDecoder * decoder); static gboolean gst_video_decoder_negotiate_default (GstVideoDecoder * decoder);
static GstFlowReturn gst_video_decoder_parse_available (GstVideoDecoder * dec, static GstFlowReturn gst_video_decoder_parse_available (GstVideoDecoder * dec,
gboolean at_eos, gboolean new_buffer); gboolean at_eos, gboolean new_buffer);
static gboolean gst_video_decoder_negotiate_unlocked (GstVideoDecoder *
decoder);
/* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
* method to get to the padtemplates */ * method to get to the padtemplates */
@ -2461,14 +2463,16 @@ gst_video_decoder_finish_frame (GstVideoDecoder * decoder,
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstVideoDecoderPrivate *priv = decoder->priv; GstVideoDecoderPrivate *priv = decoder->priv;
GstBuffer *output_buffer; GstBuffer *output_buffer;
gboolean needs_reconfigure = FALSE;
GST_LOG_OBJECT (decoder, "finish frame %p", frame); GST_LOG_OBJECT (decoder, "finish frame %p", frame);
GST_VIDEO_DECODER_STREAM_LOCK (decoder); GST_VIDEO_DECODER_STREAM_LOCK (decoder);
needs_reconfigure = gst_pad_check_reconfigure (decoder->srcpad);
if (G_UNLIKELY (priv->output_state_changed || (priv->output_state if (G_UNLIKELY (priv->output_state_changed || (priv->output_state
&& gst_pad_check_reconfigure (decoder->srcpad)))) { && needs_reconfigure))) {
if (!gst_video_decoder_negotiate (decoder)) { if (!gst_video_decoder_negotiate_unlocked (decoder)) {
gst_pad_mark_reconfigure (decoder->srcpad); gst_pad_mark_reconfigure (decoder->srcpad);
if (GST_PAD_IS_FLUSHING (decoder->srcpad)) if (GST_PAD_IS_FLUSHING (decoder->srcpad))
ret = GST_FLOW_FLUSHING; ret = GST_FLOW_FLUSHING;
@ -3183,11 +3187,25 @@ done:
return ret; return ret;
} }
static gboolean
gst_video_decoder_negotiate_unlocked (GstVideoDecoder * decoder)
{
GstVideoDecoderClass *klass = GST_VIDEO_DECODER_GET_CLASS (decoder);
gboolean ret = TRUE;
if (G_LIKELY (klass->negotiate))
ret = klass->negotiate (decoder);
return ret;
}
/** /**
* gst_video_decoder_negotiate: * gst_video_decoder_negotiate:
* @decoder: a #GstVideoDecoder * @decoder: a #GstVideoDecoder
* *
* Negotiate with downstreame elements to currently configured #GstVideoCodecState. * Negotiate with downstream elements to currently configured #GstVideoCodecState.
* Unmark GST_PAD_FLAG_NEED_RECONFIGURE in any case. But mark it again if
* negotiate fails.
* *
* Returns: #TRUE if the negotiation succeeded, else #FALSE. * Returns: #TRUE if the negotiation succeeded, else #FALSE.
*/ */
@ -3202,8 +3220,12 @@ gst_video_decoder_negotiate (GstVideoDecoder * decoder)
klass = GST_VIDEO_DECODER_GET_CLASS (decoder); klass = GST_VIDEO_DECODER_GET_CLASS (decoder);
GST_VIDEO_DECODER_STREAM_LOCK (decoder); GST_VIDEO_DECODER_STREAM_LOCK (decoder);
if (klass->negotiate) gst_pad_check_reconfigure (decoder->srcpad);
if (klass->negotiate) {
ret = klass->negotiate (decoder); ret = klass->negotiate (decoder);
if (!ret)
gst_pad_mark_reconfigure (decoder->srcpad);
}
GST_VIDEO_DECODER_STREAM_UNLOCK (decoder); GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
return ret; return ret;
@ -3227,14 +3249,15 @@ gst_video_decoder_allocate_output_buffer (GstVideoDecoder * decoder)
{ {
GstFlowReturn flow; GstFlowReturn flow;
GstBuffer *buffer = NULL; GstBuffer *buffer = NULL;
gboolean needs_reconfigure = FALSE;
GST_DEBUG ("alloc src buffer"); GST_DEBUG ("alloc src buffer");
GST_VIDEO_DECODER_STREAM_LOCK (decoder); GST_VIDEO_DECODER_STREAM_LOCK (decoder);
needs_reconfigure = gst_pad_check_reconfigure (decoder->srcpad);
if (G_UNLIKELY (!decoder->priv->output_state if (G_UNLIKELY (!decoder->priv->output_state
|| decoder->priv->output_state_changed || decoder->priv->output_state_changed || needs_reconfigure)) {
|| gst_pad_check_reconfigure (decoder->srcpad))) { if (!gst_video_decoder_negotiate_unlocked (decoder)) {
if (!gst_video_decoder_negotiate (decoder)) {
if (decoder->priv->output_state) { if (decoder->priv->output_state) {
GST_DEBUG_OBJECT (decoder, "Failed to negotiate, fallback allocation"); GST_DEBUG_OBJECT (decoder, "Failed to negotiate, fallback allocation");
gst_pad_mark_reconfigure (decoder->srcpad); gst_pad_mark_reconfigure (decoder->srcpad);
@ -3295,6 +3318,7 @@ gst_video_decoder_allocate_output_frame (GstVideoDecoder *
GstFlowReturn flow_ret; GstFlowReturn flow_ret;
GstVideoCodecState *state; GstVideoCodecState *state;
int num_bytes; int num_bytes;
gboolean needs_reconfigure = FALSE;
g_return_val_if_fail (decoder->priv->output_state, GST_FLOW_NOT_NEGOTIATED); g_return_val_if_fail (decoder->priv->output_state, GST_FLOW_NOT_NEGOTIATED);
g_return_val_if_fail (frame->output_buffer == NULL, GST_FLOW_ERROR); g_return_val_if_fail (frame->output_buffer == NULL, GST_FLOW_ERROR);
@ -3312,9 +3336,9 @@ gst_video_decoder_allocate_output_frame (GstVideoDecoder *
goto error; goto error;
} }
if (G_UNLIKELY (decoder->priv->output_state_changed needs_reconfigure = gst_pad_check_reconfigure (decoder->srcpad);
|| gst_pad_check_reconfigure (decoder->srcpad))) { if (G_UNLIKELY (decoder->priv->output_state_changed || needs_reconfigure)) {
if (!gst_video_decoder_negotiate (decoder)) { if (!gst_video_decoder_negotiate_unlocked (decoder)) {
GST_DEBUG_OBJECT (decoder, "Failed to negotiate, fallback allocation"); GST_DEBUG_OBJECT (decoder, "Failed to negotiate, fallback allocation");
gst_pad_mark_reconfigure (decoder->srcpad); gst_pad_mark_reconfigure (decoder->srcpad);
} }

View file

@ -232,6 +232,8 @@ static gboolean gst_video_encoder_decide_allocation_default (GstVideoEncoder *
static gboolean gst_video_encoder_propose_allocation_default (GstVideoEncoder * static gboolean gst_video_encoder_propose_allocation_default (GstVideoEncoder *
encoder, GstQuery * query); encoder, GstQuery * query);
static gboolean gst_video_encoder_negotiate_default (GstVideoEncoder * encoder); static gboolean gst_video_encoder_negotiate_default (GstVideoEncoder * encoder);
static gboolean gst_video_encoder_negotiate_unlocked (GstVideoEncoder *
encoder);
/* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init
* method to get to the padtemplates */ * method to get to the padtemplates */
@ -1570,11 +1572,25 @@ no_decide_allocation:
} }
} }
static gboolean
gst_video_encoder_negotiate_unlocked (GstVideoEncoder * encoder)
{
GstVideoEncoderClass *klass = GST_VIDEO_ENCODER_GET_CLASS (encoder);
gboolean ret = TRUE;
if (G_LIKELY (klass->negotiate))
ret = klass->negotiate (encoder);
return ret;
}
/** /**
* gst_video_encoder_negotiate: * gst_video_encoder_negotiate:
* @encoder: a #GstVideoEncoder * @encoder: a #GstVideoEncoder
* *
* Negotiate with downstream elements to currently configured #GstVideoCodecState. * Negotiate with downstream elements to currently configured #GstVideoCodecState.
* Unmark GST_PAD_FLAG_NEED_RECONFIGURE in any case. But mark it again if
* negotiate fails.
* *
* Returns: #TRUE if the negotiation succeeded, else #FALSE. * Returns: #TRUE if the negotiation succeeded, else #FALSE.
*/ */
@ -1590,8 +1606,12 @@ gst_video_encoder_negotiate (GstVideoEncoder * encoder)
klass = GST_VIDEO_ENCODER_GET_CLASS (encoder); klass = GST_VIDEO_ENCODER_GET_CLASS (encoder);
GST_VIDEO_ENCODER_STREAM_LOCK (encoder); GST_VIDEO_ENCODER_STREAM_LOCK (encoder);
if (klass->negotiate) gst_pad_check_reconfigure (encoder->srcpad);
if (klass->negotiate) {
ret = klass->negotiate (encoder); ret = klass->negotiate (encoder);
if (!ret)
gst_pad_mark_reconfigure (encoder->srcpad);
}
GST_VIDEO_ENCODER_STREAM_UNLOCK (encoder); GST_VIDEO_ENCODER_STREAM_UNLOCK (encoder);
return ret; return ret;
@ -1611,16 +1631,17 @@ GstBuffer *
gst_video_encoder_allocate_output_buffer (GstVideoEncoder * encoder, gsize size) gst_video_encoder_allocate_output_buffer (GstVideoEncoder * encoder, gsize size)
{ {
GstBuffer *buffer; GstBuffer *buffer;
gboolean needs_reconfigure = FALSE;
g_return_val_if_fail (size > 0, NULL); g_return_val_if_fail (size > 0, NULL);
GST_DEBUG ("alloc src buffer"); GST_DEBUG ("alloc src buffer");
GST_VIDEO_ENCODER_STREAM_LOCK (encoder); GST_VIDEO_ENCODER_STREAM_LOCK (encoder);
needs_reconfigure = gst_pad_check_reconfigure (encoder->srcpad);
if (G_UNLIKELY (encoder->priv->output_state_changed if (G_UNLIKELY (encoder->priv->output_state_changed
|| (encoder->priv->output_state || (encoder->priv->output_state && needs_reconfigure))) {
&& gst_pad_check_reconfigure (encoder->srcpad)))) { if (!gst_video_encoder_negotiate_unlocked (encoder)) {
if (!gst_video_encoder_negotiate (encoder)) {
GST_DEBUG_OBJECT (encoder, "Failed to negotiate, fallback allocation"); GST_DEBUG_OBJECT (encoder, "Failed to negotiate, fallback allocation");
gst_pad_mark_reconfigure (encoder->srcpad); gst_pad_mark_reconfigure (encoder->srcpad);
goto fallback; goto fallback;
@ -1666,13 +1687,15 @@ GstFlowReturn
gst_video_encoder_allocate_output_frame (GstVideoEncoder * gst_video_encoder_allocate_output_frame (GstVideoEncoder *
encoder, GstVideoCodecFrame * frame, gsize size) encoder, GstVideoCodecFrame * frame, gsize size)
{ {
gboolean needs_reconfigure = FALSE;
g_return_val_if_fail (frame->output_buffer == NULL, GST_FLOW_ERROR); g_return_val_if_fail (frame->output_buffer == NULL, GST_FLOW_ERROR);
GST_VIDEO_ENCODER_STREAM_LOCK (encoder); GST_VIDEO_ENCODER_STREAM_LOCK (encoder);
needs_reconfigure = gst_pad_check_reconfigure (encoder->srcpad);
if (G_UNLIKELY (encoder->priv->output_state_changed if (G_UNLIKELY (encoder->priv->output_state_changed
|| (encoder->priv->output_state || (encoder->priv->output_state && needs_reconfigure))) {
&& gst_pad_check_reconfigure (encoder->srcpad)))) { if (!gst_video_encoder_negotiate_unlocked (encoder)) {
if (!gst_video_encoder_negotiate (encoder)) {
GST_DEBUG_OBJECT (encoder, "Failed to negotiate, fallback allocation"); GST_DEBUG_OBJECT (encoder, "Failed to negotiate, fallback allocation");
gst_pad_mark_reconfigure (encoder->srcpad); gst_pad_mark_reconfigure (encoder->srcpad);
} }
@ -1733,6 +1756,7 @@ gst_video_encoder_finish_frame (GstVideoEncoder * encoder,
gboolean send_headers = FALSE; gboolean send_headers = FALSE;
gboolean discont = (frame->presentation_frame_number == 0); gboolean discont = (frame->presentation_frame_number == 0);
GstBuffer *buffer; GstBuffer *buffer;
gboolean needs_reconfigure = FALSE;
encoder_class = GST_VIDEO_ENCODER_GET_CLASS (encoder); encoder_class = GST_VIDEO_ENCODER_GET_CLASS (encoder);
@ -1745,9 +1769,10 @@ gst_video_encoder_finish_frame (GstVideoEncoder * encoder,
GST_VIDEO_ENCODER_STREAM_LOCK (encoder); GST_VIDEO_ENCODER_STREAM_LOCK (encoder);
needs_reconfigure = gst_pad_check_reconfigure (encoder->srcpad);
if (G_UNLIKELY (priv->output_state_changed || (priv->output_state if (G_UNLIKELY (priv->output_state_changed || (priv->output_state
&& gst_pad_check_reconfigure (encoder->srcpad)))) { && needs_reconfigure))) {
if (!gst_video_encoder_negotiate (encoder)) { if (!gst_video_encoder_negotiate_unlocked (encoder)) {
gst_pad_mark_reconfigure (encoder->srcpad); gst_pad_mark_reconfigure (encoder->srcpad);
if (GST_PAD_IS_FLUSHING (encoder->srcpad)) if (GST_PAD_IS_FLUSHING (encoder->srcpad))
ret = GST_FLOW_FLUSHING; ret = GST_FLOW_FLUSHING;