mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
audioencoder: Ignore caps events if the input caps did not change
This commit is contained in:
parent
d1a08af605
commit
d537a21075
1 changed files with 57 additions and 46 deletions
|
@ -186,6 +186,9 @@ enum
|
||||||
typedef struct _GstAudioEncoderContext
|
typedef struct _GstAudioEncoderContext
|
||||||
{
|
{
|
||||||
/* input */
|
/* input */
|
||||||
|
/* last negotiated input caps */
|
||||||
|
GstCaps *input_caps;
|
||||||
|
/* last negotiated input info */
|
||||||
GstAudioInfo info;
|
GstAudioInfo info;
|
||||||
|
|
||||||
/* output */
|
/* output */
|
||||||
|
@ -478,6 +481,8 @@ gst_audio_encoder_reset (GstAudioEncoder * enc, gboolean full)
|
||||||
if (enc->priv->ctx.allocator)
|
if (enc->priv->ctx.allocator)
|
||||||
gst_object_unref (enc->priv->ctx.allocator);
|
gst_object_unref (enc->priv->ctx.allocator);
|
||||||
enc->priv->ctx.allocator = NULL;
|
enc->priv->ctx.allocator = NULL;
|
||||||
|
|
||||||
|
gst_caps_replace (&enc->priv->ctx.input_caps, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_segment_init (&enc->input_segment, GST_FORMAT_TIME);
|
gst_segment_init (&enc->input_segment, GST_FORMAT_TIME);
|
||||||
|
@ -1237,8 +1242,10 @@ gst_audio_encoder_sink_setcaps (GstAudioEncoder * enc, GstCaps * caps)
|
||||||
GstAudioEncoderClass *klass;
|
GstAudioEncoderClass *klass;
|
||||||
GstAudioEncoderContext *ctx;
|
GstAudioEncoderContext *ctx;
|
||||||
GstAudioInfo state;
|
GstAudioInfo state;
|
||||||
gboolean res = TRUE, changed = FALSE;
|
gboolean res = TRUE;
|
||||||
guint old_rate;
|
guint old_rate;
|
||||||
|
GstClockTime old_min_latency;
|
||||||
|
GstClockTime old_max_latency;
|
||||||
|
|
||||||
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
|
||||||
|
|
||||||
|
@ -1254,6 +1261,16 @@ gst_audio_encoder_sink_setcaps (GstAudioEncoder * enc, GstCaps * caps)
|
||||||
if (!gst_caps_is_fixed (caps))
|
if (!gst_caps_is_fixed (caps))
|
||||||
goto refuse_caps;
|
goto refuse_caps;
|
||||||
|
|
||||||
|
if (enc->priv->ctx.input_caps
|
||||||
|
&& gst_caps_is_equal (enc->priv->ctx.input_caps, caps))
|
||||||
|
goto same_caps;
|
||||||
|
|
||||||
|
if (!gst_audio_info_from_caps (&state, caps))
|
||||||
|
goto refuse_caps;
|
||||||
|
|
||||||
|
if (enc->priv->ctx.input_caps && audio_info_is_equal (&state, &ctx->info))
|
||||||
|
goto same_caps;
|
||||||
|
|
||||||
/* adjust ts tracking to new sample rate */
|
/* adjust ts tracking to new sample rate */
|
||||||
old_rate = GST_AUDIO_INFO_RATE (&ctx->info);
|
old_rate = GST_AUDIO_INFO_RATE (&ctx->info);
|
||||||
if (GST_CLOCK_TIME_IS_VALID (enc->priv->base_ts) && old_rate) {
|
if (GST_CLOCK_TIME_IS_VALID (enc->priv->base_ts) && old_rate) {
|
||||||
|
@ -1262,64 +1279,58 @@ gst_audio_encoder_sink_setcaps (GstAudioEncoder * enc, GstCaps * caps)
|
||||||
enc->priv->samples = 0;
|
enc->priv->samples = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gst_audio_info_from_caps (&state, caps))
|
/* drain any pending old data stuff */
|
||||||
goto refuse_caps;
|
gst_audio_encoder_drain (enc);
|
||||||
|
|
||||||
changed = !audio_info_is_equal (&state, &ctx->info);
|
/* context defaults */
|
||||||
|
enc->priv->ctx.frame_samples_min = 0;
|
||||||
|
enc->priv->ctx.frame_samples_max = 0;
|
||||||
|
enc->priv->ctx.frame_max = 0;
|
||||||
|
enc->priv->ctx.lookahead = 0;
|
||||||
|
|
||||||
if (changed) {
|
/* element might report latency */
|
||||||
GstClockTime old_min_latency;
|
GST_OBJECT_LOCK (enc);
|
||||||
GstClockTime old_max_latency;
|
old_min_latency = ctx->min_latency;
|
||||||
|
old_max_latency = ctx->max_latency;
|
||||||
|
GST_OBJECT_UNLOCK (enc);
|
||||||
|
|
||||||
/* drain any pending old data stuff */
|
if (klass->set_format)
|
||||||
gst_audio_encoder_drain (enc);
|
res = klass->set_format (enc, &state);
|
||||||
|
|
||||||
/* context defaults */
|
if (res) {
|
||||||
enc->priv->ctx.frame_samples_min = 0;
|
ctx->info = state;
|
||||||
enc->priv->ctx.frame_samples_max = 0;
|
gst_caps_replace (&enc->priv->ctx.input_caps, caps);
|
||||||
enc->priv->ctx.frame_max = 0;
|
|
||||||
enc->priv->ctx.lookahead = 0;
|
|
||||||
|
|
||||||
/* element might report latency */
|
|
||||||
GST_OBJECT_LOCK (enc);
|
|
||||||
old_min_latency = ctx->min_latency;
|
|
||||||
old_max_latency = ctx->max_latency;
|
|
||||||
GST_OBJECT_UNLOCK (enc);
|
|
||||||
|
|
||||||
if (klass->set_format)
|
|
||||||
res = klass->set_format (enc, &state);
|
|
||||||
|
|
||||||
if (res)
|
|
||||||
ctx->info = state;
|
|
||||||
|
|
||||||
/* invalidate state to ensure no casual carrying on */
|
|
||||||
if (!res) {
|
|
||||||
GST_DEBUG_OBJECT (enc, "subclass did not accept format");
|
|
||||||
gst_audio_info_init (&state);
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* notify if new latency */
|
|
||||||
GST_OBJECT_LOCK (enc);
|
|
||||||
if ((ctx->min_latency > 0 && ctx->min_latency != old_min_latency) ||
|
|
||||||
(ctx->max_latency > 0 && ctx->max_latency != old_max_latency)) {
|
|
||||||
GST_OBJECT_UNLOCK (enc);
|
|
||||||
/* post latency message on the bus */
|
|
||||||
gst_element_post_message (GST_ELEMENT (enc),
|
|
||||||
gst_message_new_latency (GST_OBJECT (enc)));
|
|
||||||
GST_OBJECT_LOCK (enc);
|
|
||||||
}
|
|
||||||
GST_OBJECT_UNLOCK (enc);
|
|
||||||
} else {
|
} else {
|
||||||
GST_DEBUG_OBJECT (enc, "new audio format identical to configured format");
|
/* invalidate state to ensure no casual carrying on */
|
||||||
|
GST_DEBUG_OBJECT (enc, "subclass did not accept format");
|
||||||
|
gst_audio_info_init (&state);
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* notify if new latency */
|
||||||
|
GST_OBJECT_LOCK (enc);
|
||||||
|
if ((ctx->min_latency > 0 && ctx->min_latency != old_min_latency) ||
|
||||||
|
(ctx->max_latency > 0 && ctx->max_latency != old_max_latency)) {
|
||||||
|
GST_OBJECT_UNLOCK (enc);
|
||||||
|
/* post latency message on the bus */
|
||||||
|
gst_element_post_message (GST_ELEMENT (enc),
|
||||||
|
gst_message_new_latency (GST_OBJECT (enc)));
|
||||||
|
GST_OBJECT_LOCK (enc);
|
||||||
|
}
|
||||||
|
GST_OBJECT_UNLOCK (enc);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
same_caps:
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (enc, "new audio format identical to configured format");
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
refuse_caps:
|
refuse_caps:
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue