Created
October 19, 2023 01:06
-
-
Save btoconnor/343157333a9d2fa9a31ece7f23bebdf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tvapp/tuner/antenna.py b/tvapp/tuner/antenna.py | |
index f6c9615..f34105b 100644 | |
--- a/tvapp/tuner/antenna.py | |
+++ b/tvapp/tuner/antenna.py | |
@@ -97,9 +97,11 @@ class AntennaTuner(Tuner): | |
Tuner.__init__(self, "unused_str_adapter_%s" % url, prefix, type_) | |
self.encoder_cmd = None | |
self.tuner_cmd = None | |
+ self.monitor_cmd = None | |
self.channel_proc = None | |
self.ffmpeg_proc = None | |
+ self.monitor_proc = None | |
self.adapter_number = url | |
self.channels = channels | |
@@ -120,6 +122,7 @@ class AntennaTuner(Tuner): | |
""" | |
tuner_cmd = self._build_channel_command(req_channel) | |
encoder_cmd = self._build_encoder_command(req_channel, req_quality) | |
+ monitor_cmd = self._build_monitor_command() | |
logging.info("Changing channel to {}".format(req_channel)) | |
@@ -131,6 +134,7 @@ class AntennaTuner(Tuner): | |
log.debug("Changing stream requires stopping!") | |
self.tuner_cmd = tuner_cmd | |
self.encoder_cmd = encoder_cmd | |
+ self.monitor_cmd = monitor_cmd | |
self.stop_stream() | |
def _build_tunerproc(self): | |
@@ -145,6 +149,9 @@ class AntennaTuner(Tuner): | |
if self.encoder_cmd is None: | |
self.encoder_cmd = self._build_encoder_command(default_channel, default_quality) | |
+ if self.monitor_cmd is None: | |
+ self.monitor_cmd = self._build_monitor_command() | |
+ | |
self.channel_proc = subprocess.Popen(self.tuner_cmd, stdout=subprocess.PIPE) | |
self.ffmpeg_proc = subprocess.Popen( | |
self.encoder_cmd, | |
@@ -152,6 +159,11 @@ class AntennaTuner(Tuner): | |
stderr=subprocess.PIPE | |
) | |
+ self.monitor_proc = subprocess.Popen( | |
+ self.monitor_cmd, | |
+ stderr=subprocess.PIPE | |
+ ) | |
+ | |
return self.ffmpeg_proc | |
def _stop_tuner_proc(self): | |
@@ -167,9 +179,12 @@ class AntennaTuner(Tuner): | |
if self.channel_proc.poll() is None: | |
self.channel_proc.send_signal(subprocess.signal.SIGTERM) | |
+ if self.monitor_proc.poll() is None: | |
+ self.monitor_proc.send_signal(subprocess.signal.SIGTERM) | |
+ | |
st = time.time() | |
- for proc in [self.ffmpeg_proc, self.channel_proc]: | |
+ for proc in [self.ffmpeg_proc, self.channel_proc, self.monitor_proc]: | |
while True: | |
# Kill the process if it takes longer than 3 seconds | |
# to terminate gracefully | |
@@ -178,14 +193,16 @@ class AntennaTuner(Tuner): | |
if time.time() - st > 3.0: | |
proc.send_signal(subprocess.signal.SIGKILL) | |
- self.stop_was_kill = True # Do we need to update this?? | |
+ self.stop_was_kill = True # Do we need to update this?? | |
break | |
self.ffmpeg_proc.wait() | |
self.channel_proc.wait() | |
+ self.monitor_proc.wait() | |
self.ffmpeg_proc = None | |
self.channel_proc = None | |
+ self.monitor_proc = None | |
# Need to set this as well because this is what the base tuner | |
# is watching to detect if needs to stop the tuner procs. | |
@@ -242,6 +259,14 @@ class AntennaTuner(Tuner): | |
return command | |
+ def _build_monitor_command(self): | |
+ # dvb-fe-tool -a 0 -m | |
+ return [ | |
+ "dvb-fe-tool", | |
+ "-a", self.adapter_number, | |
+ "-m" | |
+ ] | |
+ | |
def _build_audio_channel_opts(self, quality): | |
"Build ffmpeg command opts for audio channels" | |
num_audio_channels = self.AUDIO_CHANNELS[quality] | |
diff --git a/tvapp/tuner/base.py b/tvapp/tuner/base.py | |
index fb10b38..9a12e96 100644 | |
--- a/tvapp/tuner/base.py | |
+++ b/tvapp/tuner/base.py | |
@@ -179,6 +179,11 @@ class Tuner: | |
if res[0]: | |
self.updatetime = curtime | |
self.tunerproc.stderr.read() | |
+ | |
+ # TODO: Grab output from monitor proc for CNR and SNR values | |
+ # Sample message: | |
+ # `Lock (0x1f) Signal= -13.00dBm C/N= 23.20dB` | |
+ | |
return | |
if (curtime - self.updatetime > FREEZETIME | |
and curtime - self.start_time > FREEZESTARTTIME): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment