mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
audioencoder: Avoid wrapping temporarily mapped memory with a GstBuffer and passing that to subclass
Memory from gst_adapter_map() could live shorter than the GstMemory that the GstBuffer wraps around it, which in lucky cases 'just' caused a re-use of the same memory for multiple (potentially still in use!) input buffers, but could easily end up pointing to an already-freed memory. Manifested when an AudioToolbox encoder kept getting silence inserted in seemingly random circumstances, turned out to be the memory being re-used by GStreamer at the same time that the AT API was processing it... Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6320>
This commit is contained in:
parent
0f1dfc2db0
commit
15e0affc98
1 changed files with 3 additions and 7 deletions
|
@ -1150,12 +1150,9 @@ gst_audio_encoder_push_buffers (GstAudioEncoder * enc, gboolean force)
|
|||
|
||||
priv->got_data = FALSE;
|
||||
if (G_LIKELY (need)) {
|
||||
const guint8 *data;
|
||||
|
||||
data = gst_adapter_map (priv->adapter, priv->offset + need);
|
||||
buf =
|
||||
gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
|
||||
(gpointer) data, priv->offset + need, priv->offset, need, NULL, NULL);
|
||||
buf = gst_adapter_get_buffer (priv->adapter, priv->offset + need);
|
||||
buf = gst_buffer_make_writable (buf);
|
||||
gst_buffer_resize (buf, priv->offset, -1);
|
||||
} else if (!priv->drainable) {
|
||||
GST_DEBUG_OBJECT (enc, "non-drainable and no more data");
|
||||
goto finish;
|
||||
|
@ -1182,7 +1179,6 @@ gst_audio_encoder_push_buffers (GstAudioEncoder * enc, gboolean force)
|
|||
|
||||
if (G_LIKELY (buf)) {
|
||||
gst_buffer_unref (buf);
|
||||
gst_adapter_unmap (priv->adapter);
|
||||
}
|
||||
|
||||
finish:
|
||||
|
|
Loading…
Reference in a new issue