audio: Renegotiate if necessary

And also correct usage of the base class stream lock.
This commit is contained in:
Sebastian Dröge 2012-07-23 12:01:12 +02:00
parent df08e333d2
commit d55d7fdc38
2 changed files with 38 additions and 4 deletions

View file

@ -577,8 +577,6 @@ gst_audio_decoder_set_output_format (GstAudioDecoder * dec,
GST_DEBUG_OBJECT (dec, "setting src caps %" GST_PTR_FORMAT, caps);
GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
res = gst_pad_set_caps (dec->srcpad, caps);
gst_caps_unref (caps);
if (!res)
@ -613,6 +611,8 @@ gst_audio_decoder_set_output_format (GstAudioDecoder * dec,
dec->priv->ctx.params = params;
done:
GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
if (query)
gst_query_unref (query);
@ -913,6 +913,13 @@ gst_audio_decoder_finish_frame (GstAudioDecoder * dec, GstBuffer * buf,
GST_AUDIO_DECODER_STREAM_LOCK (dec);
if (G_UNLIKELY (gst_pad_check_reconfigure (dec->srcpad))) {
if (!gst_audio_decoder_set_output_format (dec, &ctx->info)) {
ret = GST_FLOW_NOT_NEGOTIATED;
goto exit;
}
}
if (buf && priv->pending_events) {
GList *pending_events, *l;
@ -2798,7 +2805,7 @@ gst_audio_decoder_merge_tags (GstAudioDecoder * dec,
GstBuffer *
gst_audio_decoder_allocate_output_buffer (GstAudioDecoder * dec, gsize size)
{
GstBuffer *buffer;
GstBuffer *buffer = NULL;
g_return_val_if_fail (size > 0, NULL);
@ -2806,10 +2813,17 @@ gst_audio_decoder_allocate_output_buffer (GstAudioDecoder * dec, gsize size)
GST_AUDIO_DECODER_STREAM_LOCK (dec);
if (G_UNLIKELY (GST_AUDIO_INFO_IS_VALID (&dec->priv->ctx.info)
&& gst_pad_check_reconfigure (dec->srcpad))) {
if (!gst_audio_decoder_set_output_format (dec, &dec->priv->ctx.info))
goto done;
}
buffer =
gst_buffer_new_allocate (dec->priv->ctx.allocator, size,
&dec->priv->ctx.params);
done:
GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
return buffer;

View file

@ -609,6 +609,15 @@ gst_audio_encoder_finish_frame (GstAudioEncoder * enc, GstBuffer * buf,
"accepting %" G_GSIZE_FORMAT " bytes encoded data as %d samples",
buf ? gst_buffer_get_size (buf) : -1, samples);
if (G_UNLIKELY (gst_pad_check_reconfigure (enc->srcpad))) {
GstCaps *caps = gst_pad_get_current_caps (enc->srcpad);
if (!gst_audio_encoder_set_output_format (enc, caps)) {
ret = GST_FLOW_NOT_NEGOTIATED;
goto exit;
}
gst_caps_unref (caps);
}
/* mark subclass still alive and providing */
if (G_LIKELY (buf))
priv->got_data = TRUE;
@ -2573,7 +2582,7 @@ no_decide_allocation:
GstBuffer *
gst_audio_encoder_allocate_output_buffer (GstAudioEncoder * enc, gsize size)
{
GstBuffer *buffer;
GstBuffer *buffer = NULL;
g_return_val_if_fail (size > 0, NULL);
@ -2581,10 +2590,21 @@ gst_audio_encoder_allocate_output_buffer (GstAudioEncoder * enc, gsize size)
GST_AUDIO_ENCODER_STREAM_LOCK (enc);
if (G_UNLIKELY (gst_pad_has_current_caps (enc->srcpad)
&& gst_pad_check_reconfigure (enc->srcpad))) {
GstCaps *caps = gst_pad_get_current_caps (enc->srcpad);
if (!gst_audio_encoder_set_output_format (enc, caps)) {
gst_caps_unref (caps);
goto done;
}
gst_caps_unref (caps);
}
buffer =
gst_buffer_new_allocate (enc->priv->ctx.allocator, size,
&enc->priv->ctx.params);
done:
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
return buffer;