Python is a good language

This commit is contained in:
Marks Polakovs 2020-04-02 20:26:58 +02:00
parent 207f5127de
commit f8a676da3c

View file

@ -5,7 +5,7 @@ import uuid
import av import av
import struct import struct
from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription from aiortc import MediaStreamTrack, RTCPeerConnection, RTCSessionDescription
from aiortc.contrib.media import MediaBlackhole, MediaPlayer, MediaRecorder from aiortc.contrib.media import MediaBlackhole, MediaPlayer
import jack as Jack import jack as Jack
@Jack.set_error_function @Jack.set_error_function
@ -40,9 +40,15 @@ class JackSender(object):
def __init__(self, track): def __init__(self, track):
self.track = track self.track = track
self.resampler = None self.resampler = None
self.ended = False
def end():
self.ended = True
async def process(self): async def process(self):
while True: while True:
if self.ended:
break
frame = await self.track.recv() frame = await self.track.recv()
# Right, depending on the format, we may need to do some fuckery. # Right, depending on the format, we may need to do some fuckery.
# Jack expects all audio to be 32 bit floating point # Jack expects all audio to be 32 bit floating point
@ -59,7 +65,14 @@ class JackSender(object):
current_session = None current_session = None
class Session(object): class Session(object):
def __init__(self):
self.websocket = None
self.sender = None
self.pc = None
async def end(): async def end():
if self.sender is not None:
self.sender.end()
await self.pc.close() await self.pc.close()
init_buffers() init_buffers()
await self.websocket.send(json.dumps({ "kind": "REPLACED" })) await self.websocket.send(json.dumps({ "kind": "REPLACED" }))
@ -78,8 +91,6 @@ class Session(object):
self.pc = RTCPeerConnection() self.pc = RTCPeerConnection()
self.recorder = MediaRecorder("/home/marks/test.opus")
@self.pc.on("signalingstatechange") @self.pc.on("signalingstatechange")
async def on_signalingstatechange(): async def on_signalingstatechange():
print(connection_id, "Signaling state is {}".format(self.pc.signalingState)) print(connection_id, "Signaling state is {}".format(self.pc.signalingState))