restore DRM functionality
This commit is contained in:
16
csdr/chain/drm.py
Normal file
16
csdr/chain/drm.py
Normal file
@ -0,0 +1,16 @@
|
||||
from csdr.chain.demodulator import BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain
|
||||
from pycsdr.modules import Convert
|
||||
from pycsdr.types import Format
|
||||
from owrx.drm import DrmModule
|
||||
|
||||
|
||||
class Drm(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain):
|
||||
def __init__(self):
|
||||
workers = [Convert(Format.COMPLEX_FLOAT, Format.COMPLEX_SHORT), DrmModule()]
|
||||
super().__init__(workers)
|
||||
|
||||
def getFixedIfSampleRate(self) -> int:
|
||||
return 48000
|
||||
|
||||
def getFixedAudioRate(self) -> int:
|
||||
return 48000
|
@ -4,6 +4,7 @@ from pycsdr.types import Format
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from threading import Thread
|
||||
from io import BytesIO
|
||||
from subprocess import Popen, PIPE
|
||||
import pickle
|
||||
|
||||
|
||||
@ -89,3 +90,39 @@ class PickleModule(ThreadModule):
|
||||
@abstractmethod
|
||||
def process(self, input):
|
||||
pass
|
||||
|
||||
|
||||
class PopenModule(AutoStartModule, metaclass=ABCMeta):
|
||||
def __init__(self):
|
||||
self.process = None
|
||||
super().__init__()
|
||||
|
||||
@abstractmethod
|
||||
def getCommand(self):
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
self.process = Popen(self.getCommand(), stdin=PIPE, stdout=PIPE)
|
||||
Thread(target=self.pump(self.reader.read, self.process.stdin.write)).start()
|
||||
Thread(target=self.pump(self.process.stdout.read, self.writer.write)).start()
|
||||
|
||||
def stop(self):
|
||||
if self.process is not None:
|
||||
self.process.terminate()
|
||||
self.process.wait()
|
||||
self.process = None
|
||||
self.reader.stop()
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user