|
@@ -0,0 +1,44 @@
|
|
|
|
|
+import time
|
|
|
|
|
+import platform
|
|
|
|
|
+import threading
|
|
|
|
|
+from aiortc.contrib.media import MediaPlayer, MediaRelay
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class SENDSERVER(threading.Thread):
|
|
|
|
|
+ def __init__(self, sock, config):
|
|
|
|
|
+ threading.Thread.__init__(self)
|
|
|
|
|
+ self.setDaemon(True)
|
|
|
|
|
+ self.sock = sock
|
|
|
|
|
+ self.relay = None
|
|
|
|
|
+ self.webcam = None
|
|
|
|
|
+
|
|
|
|
|
+ def __del__(self):
|
|
|
|
|
+ self.sock.close()
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+ # 获取本地视频流
|
|
|
|
|
+ def create_local_tracks(self):
|
|
|
|
|
+ options = {"framerate": "30", "video_size": "640x480"}
|
|
|
|
|
+ print(options)
|
|
|
|
|
+ if self.relay is None:
|
|
|
|
|
+ if platform.system() == "Darwin":
|
|
|
|
|
+ self.webcam = MediaPlayer(
|
|
|
|
|
+ "default:none", format="avfoundation", options=options)
|
|
|
|
|
+ elif platform.system() == "Windows":
|
|
|
|
|
+ self.webcam = MediaPlayer(
|
|
|
|
|
+ "video=Integrated Camera", format="dshow", options=options)
|
|
|
|
|
+ else:
|
|
|
|
|
+ print('get video source')
|
|
|
|
|
+ self.webcam = MediaPlayer(
|
|
|
|
|
+ "/dev/video0", format="v4l2", options=options)
|
|
|
|
|
+ print(self.webcam)
|
|
|
|
|
+ self.relay = MediaRelay()
|
|
|
|
|
+ return None, self.relay.subscribe(self.webcam.video)
|
|
|
|
|
+
|
|
|
|
|
+ def run(self):
|
|
|
|
|
+ data = str.encode('test111')
|
|
|
|
|
+ audio, video = self.create_local_tracks()
|
|
|
|
|
+ while True:
|
|
|
|
|
+ self.sock.sendall(video)
|
|
|
|
|
+ print('发送', data)
|
|
|
|
|
+ time.sleep(1)
|