move the pump mechanism, allowing the old output code to be removed

This commit is contained in:
Jakob Ketterl
2021-09-20 15:09:26 +02:00
parent 4b36aca6fc
commit 9efe41a2b1
6 changed files with 29 additions and 81 deletions

View File

@ -28,8 +28,6 @@ import threading
import math
from functools import partial
from csdr.output import Output
from owrx.aprs.direwolf import DirewolfConfig, DirewolfConfigSubscriber
from owrx.audio.chopper import AudioChopper
@ -48,7 +46,7 @@ logger = logging.getLogger(__name__)
class Dsp(DirewolfConfigSubscriber):
def __init__(self, output: Output):
def __init__(self, output):
self.pycsdr_enabled = True
self.pycsdr_chain = None
self.pycsdr_client_chain = None

View File

@ -145,23 +145,3 @@ class Chain(Module):
return self.workers[-1].getOutputFormat()
else:
raise BufferError("getOutputFormat on empty chain")
def pump(self, write):
if self.writer is None:
self.setWriter(Buffer(self.getOutputFormat()))
self.clientReader = self.writer.getReader()
def copy():
run = True
while run:
data = None
try:
data = self.clientReader.read()
except ValueError:
pass
if data is None:
run = False
else:
write(data)
return copy

View File

@ -29,6 +29,20 @@ class Module(BaseModule, metaclass=ABCMeta):
def getOutputFormat(self) -> Format:
pass
def pump(self, read, write):
def copy():
while True:
data = None
try:
data = read()
except ValueError:
pass
if data is None or isinstance(data, bytes) and len(data) == 0:
break
write(data)
return copy
class AutoStartModule(Module, metaclass=ABCMeta):
def _checkStart(self) -> None:
@ -47,20 +61,6 @@ class AutoStartModule(Module, metaclass=ABCMeta):
def start(self):
pass
def pump(self, read, write):
def copy():
while True:
data = None
try:
data = read()
except ValueError:
pass
if data is None or isinstance(data, bytes) and len(data) == 0:
break
write(data)
return copy
class ThreadModule(AutoStartModule, Thread, metaclass=ABCMeta):
def __init__(self):

View File

@ -1,36 +0,0 @@
import threading
import logging
logger = logging.getLogger(__name__)
class Output(object):
def send_output(self, t, read_fn):
if not self.supports_type(t):
# TODO rewrite the output mechanism in a way that avoids producing unnecessary data
logger.warning("dumping output of type %s since it is not supported.", t)
threading.Thread(target=self.pump(read_fn, lambda x: None), name="csdr_pump_thread").start()
return
self.receive_output(t, read_fn)
def receive_output(self, t, read_fn):
pass
def pump(self, read, write):
def copy():
run = True
while run:
data = None
try:
data = read()
except ValueError:
pass
if data is None or (isinstance(data, bytes) and len(data) == 0):
run = False
else:
write(data)
return copy
def supports_type(self, t):
return True