diff --git a/rtcllm/aav.py b/rtcllm/aav.py index b8306e9..f212c42 100644 --- a/rtcllm/aav.py +++ b/rtcllm/aav.py @@ -37,7 +37,7 @@ class MyTrackBase: class MyAudioStreamTrack(AudioStreamTrack): def __init__(self, source=None): - AudioStreamTrack.__init__(self) + super().__init__() self.source = source self.set_source_track() print(f'{self.kind=}, {self.__class__.__name__}, {dir(self)}') @@ -67,7 +67,7 @@ class MyAudioStreamTrack(AudioStreamTrack): class MyVideoStreamTrack(VideoStreamTrack): def __init__(self, source=None): - VideoStreamTrack.__init__(self) + super().__init__() self.source = source self.set_source_track() print(f'{self.kind=}, {self.__class__.__name__}, {dir(self)}') @@ -95,3 +95,19 @@ class MyVideoStreamTrack(VideoStreamTrack): self.source = source self.set_source_track() + +class LoopingVideoTrack(VideoStreamTrack): + """ + A video track that loops a video file. + """ + def __init__(self, filename): + super().__init__() + self.player = MediaPlayer(filename) + self.iteration = 0 + + async def recv(self): + if self.player.video.readyState != 'live': + self.player = MediaPlayer(self.player._file_path) + frame = await self.player.video.recv() + return frame + diff --git a/rtcllm/rtc.py b/rtcllm/rtc.py index c89939f..0b7c3e3 100644 --- a/rtcllm/rtc.py +++ b/rtcllm/rtc.py @@ -22,7 +22,7 @@ import websockets from stt import asr from vad import AudioTrackVad from a2a import LLMAudioStreamTrack -from aav import MyMediaPlayer, MyAudioStreamTrack, MyVideoStreamTrack +from aav import MyMediaPlayer, MyAudioStreamTrack, MyVideoStreamTrack, LoopingVideoTrack from mini_omni.inference import OmniInference @@ -127,7 +127,8 @@ class RTCLLM: 'pc':pc }) pc.addTrack(MyAudioStreamTrack(player)) - pc.addTrack(MyVideoStreamTrack(player)) + pc.addTrack(LoopingVideoTrack('./1.mp4')) + # pc.addTrack(MyVideoStreamTrack(player)) # pc.addTrack(player.video) await self.ws_send(json.dumps({'type':'callAccepted', 'to':data['from']}))