Media streaming via RTP fully functional.

This commit is contained in:
Jono Targett 2023-05-11 15:15:55 +09:30
parent 0b559a8f85
commit 55ae3ff048
2 changed files with 4 additions and 3 deletions

View File

@ -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

View File

@ -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()