Skip to content

Commit

Permalink
#362: fix repeated sound overruns: ignore early overruns (first 2 sec…
Browse files Browse the repository at this point in the history
…onds), and bump max-size-time first time it happens

git-svn-id: https://xpra.org/svn/Xpra/trunk@3777 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 5, 2013
1 parent 6ba1ce5 commit 9679269
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/xpra/sound/sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import sys, os
import sys, os, time

from xpra.sound.sound_pipeline import SoundPipeline, debug
from xpra.sound.pulseaudio_util import has_pa
Expand All @@ -30,8 +30,8 @@
GST_QUEUE_LEAK_UPSTREAM = 1
GST_QUEUE_LEAK_DOWNSTREAM = 2

QUEUE_LEAK = int(os.environ.get("XPRA_SOUND_QUEUE_LEAK", GST_QUEUE_NO_LEAK))
QUEUE_TIME = int(os.environ.get("XPRA_SOUND_QUEUE_TIME", "200"))*1000000 #ns
QUEUE_TIME = int(os.environ.get("XPRA_SOUND_QUEUE_TIME", "400"))*1000000 #ns
QUEUE_START_TIME = int(os.environ.get("XPRA_SOUND_QUEUE_START_TIME", "200"))*1000000 #ns
QUEUE_MIN_TIME = int(os.environ.get("XPRA_SOUND_QUEUE_MIN_TIME", "50"))*1000000 #ns
QUEUE_TIME = max(0, QUEUE_TIME)
QUEUE_MIN_TIME = max(0, min(QUEUE_TIME, QUEUE_MIN_TIME))
Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(self, sink_type=DEFAULT_SINK, options={}, codec=MP3, decoder_option
self.sink_type = sink_type
decoder_str = plugin_str(decoder, decoder_options)
pipeline_els = []
pipeline_els.append("appsrc name=src max-bytes=8192")
pipeline_els.append("appsrc name=src max-bytes=512")
pipeline_els.append(parser)
pipeline_els.append(decoder_str)
if VOLUME:
Expand All @@ -76,10 +76,10 @@ def __init__(self, sink_type=DEFAULT_SINK, options={}, codec=MP3, decoder_option
pipeline_els.append("queue" +
" name=queue"+
" min-threshold-time=%s" % QUEUE_MIN_TIME+
" max-size-time=%s" % QUEUE_TIME+
" leaky=%s" % QUEUE_LEAK)
" max-size-time=%s" % QUEUE_START_TIME+
" leaky=%s" % GST_QUEUE_LEAK_DOWNSTREAM)
else:
pipeline_els.append("queue leaky=%s" % QUEUE_LEAK)
pipeline_els.append("queue leaky=%s" % GST_QUEUE_LEAK_DOWNSTREAM)
pipeline_els.append(sink_type)
self.setup_pipeline_and_bus(pipeline_els)
self.volume = self.pipeline.get_by_name("volume")
Expand All @@ -93,6 +93,13 @@ def __init__(self, sink_type=DEFAULT_SINK, options={}, codec=MP3, decoder_option
self.queue = self.pipeline.get_by_name("queue")
def overrun(*args):
debug("sound sink queue overrun: level=%s", int(self.queue.get_property("current-level-time")/1000000))
#no overruns for the first 2 seconds:
if time.time()-self.start_time<2.0:
return
#if we haven't done so yet, just bump the max-size-time
if int(self.queue.get_property("max-size-time")) < QUEUE_TIME:
self.queue.set_property("max-size-time", QUEUE_TIME)
return
self.emit("overrun")
def underrun(*args):
debug("sound sink queue underrun: level=%s", int(self.queue.get_property("current-level-time")/1000000))
Expand Down
4 changes: 4 additions & 0 deletions src/xpra/sound/sound_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import time

from xpra.signal_object import SignalObject
from xpra.sound.gstreamer_util import gst
from xpra.log import Logger, debug_if_env
Expand All @@ -28,6 +30,7 @@ def __init__(self, codec):
self.bus_message_handler_id = None
self.bitrate = -1
self.pipeline = None
self.start_time = 0
self.state = "stopped"
self.buffer_count = 0
self.byte_count = 0
Expand All @@ -49,6 +52,7 @@ def setup_pipeline_and_bus(self, elements):
debug("pipeline elements=%s", elements)
pipeline_str = " ! ".join([x for x in elements if x is not None])
debug("pipeline=%s", pipeline_str)
self.start_time = time.time()
self.pipeline = gst.parse_launch(pipeline_str)
self.bus = self.pipeline.get_bus()
self.bus_message_handler_id = self.bus.connect("message", self.on_message)
Expand Down

0 comments on commit 9679269

Please sign in to comment.