From c3799eda8c36e5742add5caaa2809400c095b26c Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 11 Sep 2024 13:48:21 +0800 Subject: [PATCH] bugfix --- rtcllm/aav.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/rtcllm/aav.py b/rtcllm/aav.py index 893184c..b8306e9 100644 --- a/rtcllm/aav.py +++ b/rtcllm/aav.py @@ -35,14 +35,63 @@ class MyTrackBase: return f -class MyAudioStreamTrack(MyTrackBase, AudioStreamTrack): +class MyAudioStreamTrack(AudioStreamTrack): def __init__(self, source=None): AudioStreamTrack.__init__(self) - MyTrackBase.__init__(self, source) - print(dir(self), self.__class__.__name__) + self.source = source + self.set_source_track() + print(f'{self.kind=}, {self.__class__.__name__}, {dir(self)}') -class MyVideoStreamTrack(MyTrackBase, VideoStreamTrack): + async def recv(self): + print(f'============{self.__class__.__name__}, {self.source.duration=}, {self.source.time=}') + if self.source is None: + return None + if self.track.readyState != 'live': + self.source_reload() + f = await self.track.recv() + return f + + def set_source_track(self): + if self.kind == 'audio': + self.track = self.source.audio + else: + self.track = self.source.video + + def source_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_source_track() + +class MyVideoStreamTrack(VideoStreamTrack): def __init__(self, source=None): VideoStreamTrack.__init__(self) - MyTrackBase.__init__(self, source) - print(dir(self), self.__class__.__name__) + self.source = source + self.set_source_track() + print(f'{self.kind=}, {self.__class__.__name__}, {dir(self)}') + + async def recv(self): + print(f'============{self.__class__.__name__}, {self.source.duration=}, {self.source.time=}') + if self.source is None: + return None + if self.track.readyState != 'live': + self.source_reload() + f = await self.track.recv() + return f + + def set_source_track(self): + if self.kind == 'audio': + self.track = self.source.audio + else: + self.track = self.source.video + + def source_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_source_track() +