bugfix
This commit is contained in:
parent
8b89abfbea
commit
b74c2f9b2a
@ -1,4 +1,5 @@
|
|||||||
import random
|
import random
|
||||||
|
from traceback import print_exc
|
||||||
from aiortc.contrib.media import MediaBlackhole, MediaPlayer, MediaRecorder, MediaRelay
|
from aiortc.contrib.media import MediaBlackhole, MediaPlayer, MediaRecorder, MediaRelay
|
||||||
from aiortc import MediaStreamTrack, VideoStreamTrack, AudioStreamTrack
|
from aiortc import MediaStreamTrack, VideoStreamTrack, AudioStreamTrack
|
||||||
|
|
||||||
@ -43,11 +44,18 @@ class MyAudioStreamTrack(AudioStreamTrack):
|
|||||||
print(f'{self.kind=}, {self.__class__.__name__}, {dir(self)}')
|
print(f'{self.kind=}, {self.__class__.__name__}, {dir(self)}')
|
||||||
|
|
||||||
async def recv(self):
|
async def recv(self):
|
||||||
print(f'============{self.__class__.__name__}, {self.source.duration=}, {self.source.time=}')
|
try:
|
||||||
|
return await self._recv()
|
||||||
|
except MediaStreamError:
|
||||||
|
self.source_reload()
|
||||||
|
return await self._recv()
|
||||||
|
except Exception as e:
|
||||||
|
print_exc()
|
||||||
|
raise e
|
||||||
|
|
||||||
|
async def _recv(self):
|
||||||
if self.source is None:
|
if self.source is None:
|
||||||
return None
|
return None
|
||||||
if self.track.readyState != 'live':
|
|
||||||
self.source_reload()
|
|
||||||
f = await self.track.recv()
|
f = await self.track.recv()
|
||||||
return f
|
return f
|
||||||
|
|
||||||
@ -73,11 +81,18 @@ class MyVideoStreamTrack(VideoStreamTrack):
|
|||||||
print(f'{self.kind=}, {self.__class__.__name__}, {dir(self)}')
|
print(f'{self.kind=}, {self.__class__.__name__}, {dir(self)}')
|
||||||
|
|
||||||
async def recv(self):
|
async def recv(self):
|
||||||
print(f'============{self.__class__.__name__}, {self.source.duration=}, {self.source.time=}')
|
try:
|
||||||
|
return await self._recv()
|
||||||
|
except MediaStreamError:
|
||||||
|
self.source_reload()
|
||||||
|
return self._recv()
|
||||||
|
except Exception as e:
|
||||||
|
print_exc()
|
||||||
|
raise e
|
||||||
|
|
||||||
|
async def _recv(self):
|
||||||
if self.source is None:
|
if self.source is None:
|
||||||
return None
|
return None
|
||||||
if self.track.readyState != 'live':
|
|
||||||
self.source_reload()
|
|
||||||
f = await self.track.recv()
|
f = await self.track.recv()
|
||||||
return f
|
return f
|
||||||
|
|
||||||
@ -107,7 +122,6 @@ class LoopingVideoTrack(VideoStreamTrack):
|
|||||||
|
|
||||||
async def recv(self):
|
async def recv(self):
|
||||||
frame = await self.player.video.recv()
|
frame = await self.player.video.recv()
|
||||||
print(f'{self.__class__.__name__}, {self.source.duration=}, {self.source.time=}')
|
|
||||||
if self.player.video.readyState != 'live':
|
if self.player.video.readyState != 'live':
|
||||||
self.player = MyMediaPlayer(self.player._file_path)
|
self.player = MyMediaPlayer(self.player._file_path)
|
||||||
frame = await self.player.video.recv()
|
frame = await self.player.video.recv()
|
||||||
|
@ -127,8 +127,8 @@ class RTCLLM:
|
|||||||
'pc':pc
|
'pc':pc
|
||||||
})
|
})
|
||||||
pc.addTrack(MyAudioStreamTrack(player))
|
pc.addTrack(MyAudioStreamTrack(player))
|
||||||
pc.addTrack(LoopingVideoTrack('./1.mp4'))
|
pc.addTrack(MyVideoStreamTrack(player))
|
||||||
# pc.addTrack(MyVideoStreamTrack(player))
|
# pc.addTrack(LoopingVideoTrack('./1.mp4'))
|
||||||
# pc.addTrack(player.video)
|
# pc.addTrack(player.video)
|
||||||
await self.ws_send(json.dumps({'type':'callAccepted', 'to':data['from']}))
|
await self.ws_send(json.dumps({'type':'callAccepted', 'to':data['from']}))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user