improve webrtc audio quality

This commit is contained in:
lipku 2024-04-20 17:41:25 +08:00
parent b9d77f9fb5
commit a3a86bf299
2 changed files with 11 additions and 7 deletions

View File

@ -43,7 +43,7 @@
<h2>Media</h2>
<audio id="audio" autoplay="true"></audio>
<video id="video" autoplay="true" playsinline="true"></video>
<video id="video" style="width:600px;" autoplay="true" playsinline="true"></video>
</div>
<script src="client.js"></script>

View File

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