From 14cd252502c22e0a52d84a623f632152e3448690 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 11 Sep 2024 12:01:41 +0800 Subject: [PATCH] bugfix --- rtcllm/aav.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/rtcllm/aav.py b/rtcllm/aav.py index 069aa5b..0e6ac1a 100644 --- a/rtcllm/aav.py +++ b/rtcllm/aav.py @@ -5,13 +5,25 @@ from aiortc import VideoStreamTrack, AudioStreamTrack class MyMediaPlayer(MediaPlayer): pass -class MyAudioStreamTrack(AudioStreamTrack): +class MyTrackBasea: def __init__(self, source=None): - super().__init__() self.source = source + self.track = self.set_track() + self.track.on('ended', self.reload) + + def set_track(self): + if self.kind == 'audio': + self.track = self.source.audio + else: + self.track = self.source.video + + def self.reload(self): + print(f'reload the source----{self.source._file_path}') + self.set_source(MyMediaPlayer(self.source._file_path)) def set_source(self, source): self.source = source + self.set_track() async def recv(self): if self.source is None: @@ -23,20 +35,13 @@ class MyAudioStreamTrack(AudioStreamTrack): f = await self.source.audio.recv() return f -class MyVideoStreamTrack(VideoStreamTrack): + +class MyAudioStreamTrack(AudioStreamTrack, MyTrackBasea): def __init__(self, source=None): - super().__init__() - self.source = source + AudioStreamTrack.__init__(self) + MyTrackBase.__init__(self, source=source) - def set_source(self, source): - self.source = source - - async def recv(self): - if self.source is None: - return None - f = await self.source.video.recv() - while f is None: - print('MyVideoTrack::recv(): will reload source') - self.set_source(MyMediaPlayer(self.source._file_path)) - f = await self.source.video.recv() - return f +class MyVideoStreamTrack(VideoStreamTrack, MyTrackBasea): + def __init__(self, source=None): + VideoStreamTrack.__init__(self) + MyTrackBase.__init__(self, source=source)