use new non-blocking strategy (affects all reads)
This commit is contained in:
parent
7e08c8f28e
commit
d1ce737886
9
csdr.py
9
csdr.py
@ -26,7 +26,6 @@ import os
|
||||
import code
|
||||
import signal
|
||||
import fcntl
|
||||
import select
|
||||
|
||||
class dsp:
|
||||
|
||||
@ -394,6 +393,10 @@ class dsp:
|
||||
if self.csdr_dynamic_bufsize: my_env["CSDR_DYNAMIC_BUFSIZE_ON"]="1";
|
||||
if self.csdr_print_bufsizes: my_env["CSDR_PRINT_BUFSIZES"]="1";
|
||||
self.process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setpgrp, env=my_env)
|
||||
|
||||
#set stdout to non-blocking to avoid blocking the main loop when no audio was decoded in digital modes
|
||||
self.set_pipe_nonblocking(self.process.stdout)
|
||||
|
||||
self.running = True
|
||||
|
||||
#open control pipes for csdr and send initialization data
|
||||
@ -419,9 +422,9 @@ class dsp:
|
||||
return self.process.stdout.read(size)
|
||||
|
||||
def read_async(self, size):
|
||||
if (select.select([self.process.stdout], [], [], 0)[0] != []):
|
||||
try:
|
||||
return self.process.stdout.read(size)
|
||||
else:
|
||||
except IOError:
|
||||
return None
|
||||
|
||||
def stop(self):
|
||||
|
@ -306,13 +306,16 @@ def spectrum_thread_function():
|
||||
print "[openwebrx-spectrum] Spectrum thread initialized successfully."
|
||||
dsp.start()
|
||||
if cfg.csdr_dynamic_bufsize:
|
||||
dsp.read(8) #dummy read to skip bufsize & preamble
|
||||
dsp.read_async(8) #dummy read to skip bufsize & preamble
|
||||
print "[openwebrx-spectrum] Note: CSDR_DYNAMIC_BUFSIZE_ON = 1"
|
||||
print "[openwebrx-spectrum] Spectrum thread started."
|
||||
bytes_to_read=int(dsp.get_fft_bytes_to_read())
|
||||
spectrum_thread_counter=0
|
||||
while True:
|
||||
data=dsp.read(bytes_to_read)
|
||||
data=dsp.read_async(bytes_to_read)
|
||||
if data is None:
|
||||
time.sleep(.01)
|
||||
continue
|
||||
#print "gotcha",len(data),"bytes of spectrum data via spectrum_thread_function()"
|
||||
if spectrum_thread_counter >= cfg.fft_fps:
|
||||
spectrum_thread_counter=0
|
||||
|
Loading…
Reference in New Issue
Block a user