audio: Move sample to data conversion to a helper.

Also add check for None buffer being returned.
This commit is contained in:
Thomas Adamcik 2016-03-25 13:09:44 +01:00
parent 6faa19dbf3
commit 64a58e0662

View File

@ -54,13 +54,9 @@ gstreamer-GstTagList.html
elif isinstance(value, (compat.text_type, bool, numbers.Number)):
result[tag].append(value)
elif isinstance(value, Gst.Sample):
buf = value.get_buffer()
(found, mapinfo) = buf.map(Gst.MapFlags.READ)
if found:
try:
result[tag].append(bytes(mapinfo.data))
finally:
buf.unmap(mapinfo)
data = _extract_sample_data(value)
if data:
result[tag].append(data)
else:
logger.log(
log.TRACE_LOG_LEVEL,
@ -70,6 +66,19 @@ gstreamer-GstTagList.html
return result
def _extract_sample_data(sample):
buf = sample.get_buffer()
if not buf:
return None
found, mapinfo = buf.map(Gst.MapFlags.READ)
if not found:
return None
try:
return bytes(mapinfo.data)
finally:
buf.unmap(mapinfo)
# TODO: split based on "stream" and "track" based conversion? i.e. handle data
# from radios in it's own helper instead?
def convert_tags_to_track(tags):