From 55ae3ff0488cab92b5c5c66e29b1d9f07e28baab Mon Sep 17 00:00:00 2001 From: Jono Targett Date: Thu, 11 May 2023 15:15:55 +0930 Subject: [PATCH] Media streaming via RTP fully functional. --- data/stream.sdp | 2 +- radio.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/data/stream.sdp b/data/stream.sdp index ed06266..e6eeee5 100644 --- a/data/stream.sdp +++ b/data/stream.sdp @@ -6,4 +6,4 @@ t=0 0 a=tool:libavformat 58.29.100 m=audio 1234 RTP/AVP 97 b=AS:800 -a=rtpmap:97 PCMU/50000/2 +a=rtpmap:97 PCMU/32000/2 diff --git a/radio.py b/radio.py index 685d83a..10c2f6d 100644 --- a/radio.py +++ b/radio.py @@ -11,6 +11,7 @@ import struct class Radio: FORMAT = 'CS16' SAMPLES = 8192 + PORT = 5001 def __init__(self, device_info): self.device_info = device_info @@ -76,7 +77,7 @@ class Radio: def _init_stream(self): self.playback = subprocess.Popen( - ['/usr/bin/sox', '-t', 'raw', '-r', '32000', '-b', '16', '-c', '2', '-L', '-e', 'signed-integer', '-', '-d'], + ['/usr/bin/ffmpeg', '-f', 's16le', '-ar', '32000', '-ac', '2', '-i', '-', '-f', 'rtp', f'rtp://localhost:{Radio.PORT}'], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL @@ -120,7 +121,7 @@ if __name__ == '__main__': print('Stream started.') # Let the stream play for a while - time.sleep(5) + time.sleep(15) print('Ending stream...') sdr.end_stream()