This commit is contained in:
yumoqing 2024-09-11 13:48:21 +08:00
parent 7f62f1163c
commit c3799eda8c

View File

@ -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()