From a3a86bf299b314df1859a3822a2172e860255dda Mon Sep 17 00:00:00 2001 From: lipku Date: Sat, 20 Apr 2024 17:41:25 +0800 Subject: [PATCH] improve webrtc audio quality --- web/webrtc.html | 2 +- webrtc.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/web/webrtc.html b/web/webrtc.html index 0103257..008a808 100644 --- a/web/webrtc.html +++ b/web/webrtc.html @@ -43,7 +43,7 @@

Media

- + diff --git a/webrtc.py b/webrtc.py index e6b0a8a..b6e216f 100644 --- a/webrtc.py +++ b/webrtc.py @@ -46,18 +46,22 @@ class PlayerStreamTrack(MediaStreamTrack): if self.kind == 'video': if hasattr(self, "_timestamp"): - self._timestamp += int(VIDEO_PTIME * VIDEO_CLOCK_RATE) - wait = self._start + (self._timestamp / VIDEO_CLOCK_RATE) - time.time() - await asyncio.sleep(wait) + self._timestamp = (time.time()-self._start) * VIDEO_CLOCK_RATE + # self._timestamp += int(VIDEO_PTIME * VIDEO_CLOCK_RATE) + # wait = self._start + (self._timestamp / VIDEO_CLOCK_RATE) - time.time() + # if wait>0: + # await asyncio.sleep(wait) else: self._start = time.time() self._timestamp = 0 return self._timestamp, VIDEO_TIME_BASE else: #audio if hasattr(self, "_timestamp"): - self._timestamp += int(AUDIO_PTIME * SAMPLE_RATE) - wait = self._start + (self._timestamp / SAMPLE_RATE) - time.time() - await asyncio.sleep(wait) + self._timestamp = (time.time()-self._start) * SAMPLE_RATE + # self._timestamp += int(AUDIO_PTIME * SAMPLE_RATE) + # wait = self._start + (self._timestamp / SAMPLE_RATE) - time.time() + # if wait>0: + # await asyncio.sleep(wait) else: self._start = time.time() self._timestamp = 0