audio: Use timed pop for message loop and gst clocks
This commit is contained in:
parent
628c828087
commit
9e8b3263ab
@ -1,7 +1,6 @@
|
|||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import time
|
|
||||||
|
|
||||||
import pygst
|
import pygst
|
||||||
pygst.require('0.10')
|
pygst.require('0.10')
|
||||||
@ -31,7 +30,7 @@ class Scanner(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, timeout=1000, proxy_config=None):
|
def __init__(self, timeout=1000, proxy_config=None):
|
||||||
self._timeout_ms = timeout
|
self._timeout_ms = int(timeout)
|
||||||
self._proxy_config = proxy_config or {}
|
self._proxy_config = proxy_config or {}
|
||||||
|
|
||||||
def scan(self, uri):
|
def scan(self, uri):
|
||||||
@ -52,7 +51,7 @@ class Scanner(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
_start_pipeline(pipeline)
|
_start_pipeline(pipeline)
|
||||||
tags, mime = _process(pipeline, self._timeout_ms / 1000.0)
|
tags, mime = _process(pipeline, self._timeout_ms)
|
||||||
duration = _query_duration(pipeline)
|
duration = _query_duration(pipeline)
|
||||||
seekable = _query_seekable(pipeline)
|
seekable = _query_seekable(pipeline)
|
||||||
finally:
|
finally:
|
||||||
@ -120,17 +119,19 @@ def _query_seekable(pipeline):
|
|||||||
return query.parse_seeking()[1]
|
return query.parse_seeking()[1]
|
||||||
|
|
||||||
|
|
||||||
def _process(pipeline, timeout):
|
def _process(pipeline, timeout_ms):
|
||||||
start = time.time()
|
clock = pipeline.get_clock()
|
||||||
tags, mime, missing_description = {}, None, None
|
|
||||||
bus = pipeline.get_bus()
|
bus = pipeline.get_bus()
|
||||||
|
timeout = timeout_ms * gst.MSECOND
|
||||||
|
tags, mime, missing_description = {}, None, None
|
||||||
|
|
||||||
while time.time() - start < timeout:
|
start = clock.get_time()
|
||||||
if not bus.have_pending():
|
while timeout > 0:
|
||||||
continue
|
message = bus.timed_pop(timeout)
|
||||||
message = bus.pop()
|
|
||||||
|
|
||||||
if message.type == gst.MESSAGE_ELEMENT:
|
if message is None:
|
||||||
|
break
|
||||||
|
elif message.type == gst.MESSAGE_ELEMENT:
|
||||||
if gst.pbutils.is_missing_plugin_message(message):
|
if gst.pbutils.is_missing_plugin_message(message):
|
||||||
missing_description = encoding.locale_decode(
|
missing_description = encoding.locale_decode(
|
||||||
_missing_plugin_desc(message))
|
_missing_plugin_desc(message))
|
||||||
@ -153,4 +154,6 @@ def _process(pipeline, timeout):
|
|||||||
# Note that this will only keep the last tag.
|
# Note that this will only keep the last tag.
|
||||||
tags.update(utils.convert_taglist(taglist))
|
tags.update(utils.convert_taglist(taglist))
|
||||||
|
|
||||||
raise exceptions.ScannerError('Timeout after %dms' % (timeout * 1000))
|
timeout -= clock.get_time() - start
|
||||||
|
|
||||||
|
raise exceptions.ScannerError('Timeout after %dms' % timeout_ms)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user