Skip to content

Commit

Permalink
Merge pull request #84 from ssssam/sam/gstreamer-memory-leak-fix
Browse files Browse the repository at this point in the history
gstdec: Avoid leaking memory when reading audio data
  • Loading branch information
sampsyo committed Jan 20, 2019
2 parents 1ab1fb5 + 2cd2456 commit 9d49f28
Showing 1 changed file with 14 additions and 1 deletion.
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()
success, info = mem.map(Gst.MapFlags.READ)
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

0 comments on commit 9d49f28

Please sign in to comment.