mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-22 23:28:16 +00:00
audioencoder: Protect samples_in/bytes_out and audio info with object lock
It might cause invalid calculations during the CONVERT query otherwise.
This commit is contained in:
parent
8d8262a00c
commit
5cbd1a7bca
1 changed files with 23 additions and 5 deletions
|
@ -479,8 +479,10 @@ gst_audio_encoder_reset (GstAudioEncoder * enc, gboolean full)
|
|||
|
||||
if (full) {
|
||||
enc->priv->active = FALSE;
|
||||
GST_OBJECT_LOCK (enc);
|
||||
enc->priv->samples_in = 0;
|
||||
enc->priv->bytes_out = 0;
|
||||
GST_OBJECT_UNLOCK (enc);
|
||||
|
||||
g_list_foreach (enc->priv->ctx.headers, (GFunc) gst_buffer_unref, NULL);
|
||||
g_list_free (enc->priv->ctx.headers);
|
||||
|
@ -491,12 +493,14 @@ gst_audio_encoder_reset (GstAudioEncoder * enc, gboolean full)
|
|||
gst_object_unref (enc->priv->ctx.allocator);
|
||||
enc->priv->ctx.allocator = NULL;
|
||||
|
||||
GST_OBJECT_LOCK (enc);
|
||||
gst_caps_replace (&enc->priv->ctx.input_caps, NULL);
|
||||
gst_caps_replace (&enc->priv->ctx.caps, NULL);
|
||||
gst_caps_replace (&enc->priv->ctx.allocation_caps, NULL);
|
||||
|
||||
memset (&enc->priv->ctx, 0, sizeof (enc->priv->ctx));
|
||||
gst_audio_info_init (&enc->priv->ctx.info);
|
||||
GST_OBJECT_UNLOCK (enc);
|
||||
|
||||
if (enc->priv->upstream_tags) {
|
||||
gst_tag_list_unref (enc->priv->upstream_tags);
|
||||
|
@ -911,7 +915,9 @@ gst_audio_encoder_finish_frame (GstAudioEncoder * enc, GstBuffer * buf,
|
|||
GST_BUFFER_OFFSET_END (tmpbuf) = priv->bytes_out + size;
|
||||
}
|
||||
|
||||
GST_OBJECT_LOCK (enc);
|
||||
priv->bytes_out += size;
|
||||
GST_OBJECT_UNLOCK (enc);
|
||||
|
||||
gst_pad_push (enc->srcpad, tmpbuf);
|
||||
}
|
||||
|
@ -973,7 +979,9 @@ gst_audio_encoder_finish_frame (GstAudioEncoder * enc, GstBuffer * buf,
|
|||
}
|
||||
}
|
||||
|
||||
GST_OBJECT_LOCK (enc);
|
||||
priv->bytes_out += size;
|
||||
GST_OBJECT_UNLOCK (enc);
|
||||
|
||||
if (G_UNLIKELY (priv->discont)) {
|
||||
GST_LOG_OBJECT (enc, "marking discont");
|
||||
|
@ -1118,7 +1126,9 @@ gst_audio_encoder_push_buffers (GstAudioEncoder * enc, gboolean force)
|
|||
/* mark this already as consumed,
|
||||
* which it should be when subclass gives us data in exchange for samples */
|
||||
priv->offset += need;
|
||||
GST_OBJECT_LOCK (enc);
|
||||
priv->samples_in += need / ctx->info.bpf;
|
||||
GST_OBJECT_UNLOCK (enc);
|
||||
|
||||
/* subclass might not want to be bothered with leftover data,
|
||||
* so take care of that here if so, otherwise pass along */
|
||||
|
@ -1430,8 +1440,10 @@ gst_audio_encoder_sink_setcaps (GstAudioEncoder * enc, GstCaps * caps)
|
|||
res = klass->set_format (enc, &state);
|
||||
|
||||
if (res) {
|
||||
GST_OBJECT_LOCK (enc);
|
||||
ctx->info = state;
|
||||
gst_caps_replace (&enc->priv->ctx.input_caps, caps);
|
||||
GST_OBJECT_UNLOCK (enc);
|
||||
} else {
|
||||
/* invalidate state to ensure no casual carrying on */
|
||||
GST_DEBUG_OBJECT (enc, "subclass did not accept format");
|
||||
|
@ -1717,8 +1729,11 @@ gst_audio_encoder_sink_query_default (GstAudioEncoder * enc, GstQuery * query)
|
|||
gint64 src_val, dest_val;
|
||||
|
||||
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
||||
if (!(res = gst_audio_info_convert (&enc->priv->ctx.info,
|
||||
src_fmt, src_val, dest_fmt, &dest_val)))
|
||||
GST_OBJECT_LOCK (enc);
|
||||
res = gst_audio_info_convert (&enc->priv->ctx.info,
|
||||
src_fmt, src_val, dest_fmt, &dest_val);
|
||||
GST_OBJECT_UNLOCK (enc);
|
||||
if (!res)
|
||||
goto error;
|
||||
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
||||
res = TRUE;
|
||||
|
@ -1919,9 +1934,12 @@ gst_audio_encoder_src_query_default (GstAudioEncoder * enc, GstQuery * query)
|
|||
gint64 src_val, dest_val;
|
||||
|
||||
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
||||
if (!(res = __gst_audio_encoded_audio_convert (&enc->priv->ctx.info,
|
||||
enc->priv->bytes_out, enc->priv->samples_in, src_fmt, src_val,
|
||||
&dest_fmt, &dest_val)))
|
||||
GST_OBJECT_LOCK (enc);
|
||||
res = __gst_audio_encoded_audio_convert (&enc->priv->ctx.info,
|
||||
enc->priv->bytes_out, enc->priv->samples_in, src_fmt, src_val,
|
||||
&dest_fmt, &dest_val);
|
||||
GST_OBJECT_UNLOCK (enc);
|
||||
if (!res)
|
||||
break;
|
||||
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue