Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gstdec: Avoid leaking memory when reading audio data #84

Merged
merged 1 commit into from
Jan 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion audioread/gstdec.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,20 @@ def _new_sample(self, sink):
# New data is available from the pipeline! Dump it into our
# queue (or possibly block if we're full).
buf = sink.emit('pull-sample').get_buffer()
self.queue.put(buf.extract_dup(0, buf.get_size()))

# We can't use Gst.Buffer.extract() to read the data as it crashes
# when called through PyGObject. We also can't use
# Gst.Buffer.extract_dup() because we have no way in Python to free
# the memory that it returns. Instead we get access to the actual
# data via Gst.Memory.map().
mem = buf.get_all_memory()
ssssam marked this conversation as resolved.
Show resolved Hide resolved
success, info = mem.map(Gst.MapFlags.READ)
ssssam marked this conversation as resolved.
Show resolved Hide resolved
if success:
data = info.data
mem.unmap(info)
self.queue.put(data)
else:
raise GStreamerError("Unable to map buffer memory while reading the file.")
return Gst.FlowReturn.OK

def _unkown_type(self, uridecodebin, decodebin, caps):
Expand Down