mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
possible fix for #132
it seems, pyaudio isnt terminated correctly. running it within a subprocess which will be closed after execution, pyaudio seems to be terminated and not causing a problem anymore on raspberry pi. Yay
This commit is contained in:
parent
7a93f0a824
commit
efc700b1f7
2 changed files with 33 additions and 17 deletions
14
tnc/audio.py
14
tnc/audio.py
|
@ -10,6 +10,10 @@ import json
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
import pyaudio
|
import pyaudio
|
||||||
|
from multiprocessing import Process, Queue
|
||||||
|
AUDIO_DEVICES = Queue()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ERROR_HANDLER_FUNC = CFUNCTYPE(None, c_char_p, c_int, c_char_p, c_int, c_char_p)
|
ERROR_HANDLER_FUNC = CFUNCTYPE(None, c_char_p, c_int, c_char_p, c_int, c_char_p)
|
||||||
|
|
||||||
|
@ -29,8 +33,13 @@ def noalsaerr():
|
||||||
# p = pyaudio.PyAudio()
|
# p = pyaudio.PyAudio()
|
||||||
######################################################
|
######################################################
|
||||||
|
|
||||||
|
|
||||||
def get_audio_devices():
|
def get_audio_devices():
|
||||||
|
p = Process(target=update_audio_devices)
|
||||||
|
p.start()
|
||||||
|
p.join()
|
||||||
|
return AUDIO_DEVICES.get()
|
||||||
|
|
||||||
|
def update_audio_devices():
|
||||||
# UPDATE LIST OF AUDIO DEVICES
|
# UPDATE LIST OF AUDIO DEVICES
|
||||||
try:
|
try:
|
||||||
# we need to "try" this, because sometimes libasound.so isn't in the default place
|
# we need to "try" this, because sometimes libasound.so isn't in the default place
|
||||||
|
@ -61,5 +70,6 @@ def get_audio_devices():
|
||||||
output_devices.append({"id": i, "name": str(name)})
|
output_devices.append({"id": i, "name": str(name)})
|
||||||
|
|
||||||
p.terminate()
|
p.terminate()
|
||||||
|
AUDIO_DEVICES.put([input_devices, output_devices])
|
||||||
|
|
||||||
|
|
||||||
return [input_devices, output_devices]
|
|
||||||
|
|
16
tnc/sock.py
16
tnc/sock.py
|
@ -78,16 +78,14 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
data = SOCKET_QUEUE.get()
|
data = SOCKET_QUEUE.get()
|
||||||
sock_data = bytes(data, 'utf-8')
|
sock_data = bytes(data, 'utf-8')
|
||||||
sock_data += b'\n' # append line limiter
|
sock_data += b'\n' # append line limiter
|
||||||
|
|
||||||
# send data to all clients
|
# send data to all clients
|
||||||
try:
|
#try:
|
||||||
for client in CONNECTED_CLIENTS:
|
for client in CONNECTED_CLIENTS:
|
||||||
try:
|
try:
|
||||||
client.send(sock_data)
|
client.send(sock_data)
|
||||||
except:
|
except:
|
||||||
print("connection lost...")
|
print("connection lost...")
|
||||||
CONNECTED_CLIENTS.remove(self.request)
|
|
||||||
except:
|
|
||||||
print("client not anymore in client list")
|
|
||||||
|
|
||||||
# we want to transmit scatter data only once to reduce network traffic
|
# we want to transmit scatter data only once to reduce network traffic
|
||||||
static.SCATTER = []
|
static.SCATTER = []
|
||||||
|
@ -106,7 +104,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
if chunk == b'':
|
if chunk == b'':
|
||||||
#print("connection broken. Closing...")
|
#print("connection broken. Closing...")
|
||||||
self.connection_alive = False
|
self.connection_alive = False
|
||||||
|
print(chunk)
|
||||||
if data.startswith(b'{') and data.endswith(b'}\n'):
|
if data.startswith(b'{') and data.endswith(b'}\n'):
|
||||||
# split data by \n if we have multiple commands in socket buffer
|
# split data by \n if we have multiple commands in socket buffer
|
||||||
data = data.split(b'\n')
|
data = data.split(b'\n')
|
||||||
|
@ -120,6 +118,14 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
else:
|
else:
|
||||||
process_daemon_commands(commands)
|
process_daemon_commands(commands)
|
||||||
|
|
||||||
|
# wait some time between processing multiple commands
|
||||||
|
# this is only a first test to avoid doubled transmission
|
||||||
|
# we might improve this by only processing one command or
|
||||||
|
# doing some kind of selection to determin which commands need to be dropped
|
||||||
|
# and which one can be processed during a running transmission
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
|
||||||
# finally delete our rx buffer to be ready for new commands
|
# finally delete our rx buffer to be ready for new commands
|
||||||
data = bytes()
|
data = bytes()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in a new issue