-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathaudiodecoder.py
39 lines (30 loc) · 1023 Bytes
/
audiodecoder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# "Autobox" dongle driver for HTML 'streaming'
# Created by Colin Munro, December 2019
# See README.md for more information
"""Simple utility code to decode an h264 stream to a series of PNGs."""
import subprocess, threading, os, fcntl, queue
import time
class AudioDecoder:
class _Thread(threading.Thread):
def __init__(self, owner):
super().__init__()
self.owner = owner
self.running = threading.Event()
self.shutdown = False
def run(self):
pass
# while not self.shutdown:
# pass
def __init__(self):
self.child = subprocess.Popen(["ffplay", "-f", "s16le", "-ac", "2", "-ar", "44100", "-nodisp", "-"], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, bufsize=1)
self.thread = self._Thread(self)
self.thread.start()
def stop(self):
print("AudioDecoder: stop")
self.child.terminate()
self.thread.shutdown = True
self.thread.join()
def send(self, data):
self.child.stdin.write(data)
self.child.stdin.flush()
# self.thread.running.set()