Skip to content

Commit

Permalink
#1773: start sending audio, test fadeout and stop packets
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@23141 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 16, 2019
1 parent abc035c commit f25d709
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
11 changes: 10 additions & 1 deletion src/unittests/unit/server/mixins/audio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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 time
import unittest

from xpra.util import AdHocStruct
Expand All @@ -14,6 +15,7 @@ class AudioMixinTest(ServerMixinTest):

def test_audio(self):
from xpra.server.mixins.audio_server import AudioServer
from xpra.server.source.audio_mixin import AudioMixin
opts = AdHocStruct()
opts.sound_source = ""
opts.speaker = "on"
Expand All @@ -23,7 +25,14 @@ def test_audio(self):
opts.pulseaudio = True
opts.pulseaudio_command = ""
opts.pulseaudio_configure_commands = []
self._test_mixin_class(AudioServer, opts)
self._test_mixin_class(AudioServer, opts, {
"sound.receive" : True,
"sound.decoders" : ("mp3",),
}, AudioMixin)
self.handle_packet(("sound-control", "start", "mp3"))
time.sleep(1)
self.handle_packet(("sound-control", "fadeout"))
time.sleep(1)
self.handle_packet(("sound-control", "stop"))

def main():
Expand Down
8 changes: 8 additions & 0 deletions src/unittests/unit/server/mixins/servermixintest_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def tearDown(self):
self.mixin.cleanup()
self.mixin = None

def debug_all(self):
from xpra.log import enable_debug_for
enable_debug_for("all")

def stop(self):
self.glib.timeout_add(1000, self.main_loop.quit)

Expand Down Expand Up @@ -73,7 +77,11 @@ def _test_mixin_class(self, mclass, opts, caps=None, source_mixin_class=None):
if source_mixin_class:
self.source = source_mixin_class()
self.protocol = AdHocStruct()
self.source.timeout_add = self.glib.timeout_add
self.source.idle_add = self.glib.idle_add
self.source.source_remove = self.glib.source_remove
self.source.protocol = self.protocol
self.source.init_from(self.protocol, x)
self.source.init_state()
self.source.parse_client_caps(caps)
self.source.get_info()
Expand Down
2 changes: 0 additions & 2 deletions src/xpra/server/mixins/audio_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@ def _process_sound_data(self, proto, packet):


def init_packet_handlers(self):
log.info("AudioServer.init_packet_handlers() supports speaker=%s, microphone=%s",
self.supports_speaker, self.supports_microphone)
if self.supports_speaker or self.supports_microphone:
self.add_packet_handlers({
"sound-control" : self._process_sound_control,
Expand Down
14 changes: 8 additions & 6 deletions src/xpra/server/source/audio_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ def audio_loop_check(self, mode="speaker"):
return True
machine_id = get_machine_id()
uuid = get_user_uuid()
#these attributes belong in a different mixin,
#so we can't assume that they exist:
client_machine_id = getattr(self, "machine_id", None)
client_uuid = getattr(self, "uuid", None)
log("audio_loop_check(%s) machine_id=%s client machine_id=%s, uuid=%s, client uuid=%s",
mode, machine_id, self.machine_id, uuid, self.uuid)
if self.machine_id:
if self.machine_id!=machine_id:
mode, machine_id, client_machine_id, uuid, client_uuid)
if client_machine_id:
if client_machine_id!=machine_id:
#not the same machine, so OK
return True
if self.uuid!=uuid:
if client_uuid!=uuid:
#different user, assume different pulseaudio server
return True
#check pulseaudio id if we have it
Expand Down Expand Up @@ -131,7 +135,6 @@ def audio_loop_check(self, mode="speaker"):

def start_sending_sound(self, codec=None, volume=1.0,
new_stream=None, new_buffer=None, skip_client_codec_check=False):
assert self.hello_sent
log("start_sending_sound(%s)", codec)
ss = None
if getattr(self, "suspended", False):
Expand Down Expand Up @@ -310,7 +313,6 @@ def stop_receiving_sound(self):
##########################################################################
# sound control commands:
def sound_control(self, action, *args):
assert self.hello_sent
action = bytestostr(action)
log("sound_control(%s, %s)", action, args)
method = getattr(self, "sound_control_%s" % (action.replace("-", "_")), None)
Expand Down
7 changes: 7 additions & 0 deletions src/xpra/server/source/stub_source_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ def user_event(self):
"""
def may_notify(self, *args, **kwargs):
pass


def send_more(self, *parts, **kwargs):
pass

def send_async(self, *parts, **kwargs):
pass

0 comments on commit f25d709

Please sign in to comment.