Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter remote streams by their machine id #282

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions pulseaudio_dlna/pulseaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@

logger = logging.getLogger('pulseaudio_dlna.pulseaudio')

try:
with open('/var/lib/dbus/machine-id', 'r') as f:
MACHINE_ID = unicode(f.readline().strip())
except:
MACHINE_ID = None
logger.warning('Could not determine the pulseaudio machine-id!')

logger.info('MACHINE_ID: {}'.format(MACHINE_ID))


class PulseAudio(object):
def __init__(self):
Expand Down Expand Up @@ -118,9 +127,10 @@ def retry_on_fail(method, tries=5):
if retry_on_fail(self.update_playback_streams) and \
retry_on_fail(self.update_sinks):
for stream in self.streams:
for sink in self.sinks:
if sink.object_path == stream.device:
sink.streams.append(stream)
if stream.is_local_stream:
for sink in self.sinks:
if sink.object_path == stream.device:
sink.streams.append(stream)
else:
logger.error(
'Could not update sinks and streams. This normally indicates '
Expand Down Expand Up @@ -208,12 +218,14 @@ def new(self, bus, client_path):
name_bytes = properties.get('application.name', [])
icon_bytes = properties.get('application.icon_name', [])
binary_bytes = properties.get('application.process.binary', [])
machine_id_bytes = properties.get('application.process.machine_id', [])
return PulseClient(
object_path=unicode(client_path),
index=unicode(obj.Get('org.PulseAudio.Core1.Client', 'Index')),
name=self._convert_bytes_to_unicode(name_bytes),
icon=self._convert_bytes_to_unicode(icon_bytes),
binary=self._convert_bytes_to_unicode(binary_bytes),
machine_id=self._convert_bytes_to_unicode(machine_id_bytes),
)
except dbus.exceptions.DBusException:
logger.error(
Expand All @@ -227,7 +239,7 @@ class PulseClient(object):

__shared_state = {}

def __init__(self, object_path, index, name, icon, binary):
def __init__(self, object_path, index, name, icon, binary, machine_id):
if object_path not in self.__shared_state:
self.__shared_state[object_path] = {}
self.__dict__ = self.__shared_state[object_path]
Expand All @@ -237,6 +249,7 @@ def __init__(self, object_path, index, name, icon, binary):
self.name = name or 'unknown'
self.icon = icon or 'unknown'
self.binary = binary or 'unknown'
self.machine_id = machine_id

def __eq__(self, other):
return self.object_path == other.object_path
Expand Down Expand Up @@ -439,6 +452,14 @@ def __init__(self, object_path, index, device, client):
self.device = device
self.client = client

@property
def is_local_stream(self):
logger.info('{} | {} = {}'.format(
self.object_path, self.client.machine_id, MACHINE_ID))
if not MACHINE_ID or self.client.machine_id == MACHINE_ID:
return True
return False

def switch_to_source(self, index):
cmd = [
'pactl',
Expand Down Expand Up @@ -695,7 +716,7 @@ def __handle_sink_update(self, sink_path):
return

for bridge in self.bridges:
logger.debug('\n{}'.format(bridge))
logger.info('\n{}'.format(bridge))
if bridge.device.state == bridge.device.PLAYING:
if len(bridge.sink.streams) == 0 and (
not self.disable_device_stop and
Expand Down