From 7836f2e47f8895e49d1e3fcbc96b9ff638c88600 Mon Sep 17 00:00:00 2001 From: seydx Date: Tue, 11 Mar 2025 01:50:41 +0100 Subject: [PATCH 1/4] check h265 --- www/video-rtc.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/www/video-rtc.js b/www/video-rtc.js index fb872b45..518e242f 100644 --- a/www/video-rtc.js +++ b/www/video-rtc.js @@ -583,7 +583,7 @@ export class VideoRTC extends HTMLElement { if (stream.getVideoTracks().length > 0) rtcPriority += 0x220; if (stream.getAudioTracks().length > 0) rtcPriority += 0x102; - if (this.mseCodecs.indexOf('hvc1.') >= 0) msePriority += 0x230; + if (this.mseCodecs.indexOf('hvc1.') >= 0 && !VideoRTC.isH265Supported()) msePriority += 0x230; if (this.mseCodecs.indexOf('avc1.') >= 0) msePriority += 0x210; if (this.mseCodecs.indexOf('mp4a.') >= 0) msePriority += 0x101; @@ -664,6 +664,23 @@ export class VideoRTC extends HTMLElement { this.send({type: 'mp4', value: this.codecs(this.video.canPlayType)}); } + static isH265Supported() { + try { + const videoCodecs = RTCRtpSender?.getCapabilities('video')?.codecs; + + if (!videoCodecs) { + return false; + } + + return videoCodecs.some(codec => + codec.mimeType.toLowerCase().includes('h265') || + codec.mimeType.toLowerCase().includes('hevc') + ); + } catch { + return false; + } + } + static btoa(buffer) { const bytes = new Uint8Array(buffer); const len = bytes.byteLength; From b28ffa9543e5d71bcfd1e45f012af96a41ae99c8 Mon Sep 17 00:00:00 2001 From: seydx Date: Tue, 11 Mar 2025 01:52:16 +0100 Subject: [PATCH 2/4] indentation --- www/video-rtc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/video-rtc.js b/www/video-rtc.js index 518e242f..143ee5a1 100644 --- a/www/video-rtc.js +++ b/www/video-rtc.js @@ -673,8 +673,8 @@ export class VideoRTC extends HTMLElement { } return videoCodecs.some(codec => - codec.mimeType.toLowerCase().includes('h265') || - codec.mimeType.toLowerCase().includes('hevc') + codec.mimeType.toLowerCase().includes('h265') || + codec.mimeType.toLowerCase().includes('hevc') ); } catch { return false; From ac96b64c64d04df8d0882bbd31f6978310d60f56 Mon Sep 17 00:00:00 2001 From: seydx Date: Sun, 16 Mar 2025 14:16:01 +0100 Subject: [PATCH 3/4] change codec priority handling for h265 --- www/video-rtc.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/www/video-rtc.js b/www/video-rtc.js index 143ee5a1..7efa0a57 100644 --- a/www/video-rtc.js +++ b/www/video-rtc.js @@ -583,7 +583,10 @@ export class VideoRTC extends HTMLElement { if (stream.getVideoTracks().length > 0) rtcPriority += 0x220; if (stream.getAudioTracks().length > 0) rtcPriority += 0x102; - if (this.mseCodecs.indexOf('hvc1.') >= 0 && !VideoRTC.isH265Supported()) msePriority += 0x230; + if (this.mseCodecs.indexOf('hvc1.')) { + if (VideoRTC.isH265Supported()) rtcPriority += 0x230; + else msePriority += 0x230; + } if (this.mseCodecs.indexOf('avc1.') >= 0) msePriority += 0x210; if (this.mseCodecs.indexOf('mp4a.') >= 0) msePriority += 0x101; From d697bdcf059c303fcf08edb6303dc3cbc3882b8e Mon Sep 17 00:00:00 2001 From: Alex X Date: Mon, 29 Sep 2025 18:21:36 +0300 Subject: [PATCH 4/4] Code refactoring for #1644 --- www/video-rtc.js | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/www/video-rtc.js b/www/video-rtc.js index 7efa0a57..a239c679 100644 --- a/www/video-rtc.js +++ b/www/video-rtc.js @@ -580,13 +580,14 @@ export class VideoRTC extends HTMLElement { /** @type {MediaStream} */ const stream = video2.srcObject; - if (stream.getVideoTracks().length > 0) rtcPriority += 0x220; + if (stream.getVideoTracks().length > 0) { + // not the best, but a pretty simple way to check a codec + const isH265Supported = this.pc.remoteDescription.sdp.includes('H265/90000'); + rtcPriority += isH265Supported ? 0x240 : 0x220; + } if (stream.getAudioTracks().length > 0) rtcPriority += 0x102; - if (this.mseCodecs.indexOf('hvc1.')) { - if (VideoRTC.isH265Supported()) rtcPriority += 0x230; - else msePriority += 0x230; - } + if (this.mseCodecs.indexOf('hvc1.') >= 0) msePriority += 0x230; if (this.mseCodecs.indexOf('avc1.') >= 0) msePriority += 0x210; if (this.mseCodecs.indexOf('mp4a.') >= 0) msePriority += 0x101; @@ -667,23 +668,6 @@ export class VideoRTC extends HTMLElement { this.send({type: 'mp4', value: this.codecs(this.video.canPlayType)}); } - static isH265Supported() { - try { - const videoCodecs = RTCRtpSender?.getCapabilities('video')?.codecs; - - if (!videoCodecs) { - return false; - } - - return videoCodecs.some(codec => - codec.mimeType.toLowerCase().includes('h265') || - codec.mimeType.toLowerCase().includes('hevc') - ); - } catch { - return false; - } - } - static btoa(buffer) { const bytes = new Uint8Array(buffer); const len = bytes.byteLength;