feat: Configure video tracks for high bitrate and prefer VP8/H264 codecs.
This commit is contained in:
@@ -25,7 +25,18 @@ socket.on('viewer', id => {
|
|||||||
peerConnections[id] = peerConnection;
|
peerConnections[id] = peerConnection;
|
||||||
|
|
||||||
activeStream.getTracks().forEach(track => {
|
activeStream.getTracks().forEach(track => {
|
||||||
peerConnection.addTrack(track, activeStream);
|
const sender = peerConnection.addTrack(track, activeStream);
|
||||||
|
|
||||||
|
// Force high bitrate for best possible 1080p60 quality
|
||||||
|
if (track.kind === 'video') {
|
||||||
|
const params = sender.getParameters();
|
||||||
|
if (!params.encodings) params.encodings = [{}];
|
||||||
|
|
||||||
|
// Set max bandwidth to 10 Mbps (10,000,000 bps)
|
||||||
|
params.encodings[0].maxBitrate = 10000000;
|
||||||
|
|
||||||
|
sender.setParameters(params).catch(e => console.error("Could not set high bitrate:", e));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
peerConnection.onicecandidate = event => {
|
peerConnection.onicecandidate = event => {
|
||||||
@@ -36,7 +47,32 @@ socket.on('viewer', id => {
|
|||||||
|
|
||||||
peerConnection
|
peerConnection
|
||||||
.createOffer()
|
.createOffer()
|
||||||
.then(sdp => peerConnection.setLocalDescription(sdp))
|
.then(sdp => {
|
||||||
|
// Force VP8/H264 on the SDP offer to maximize compatibility with Chromium
|
||||||
|
const RTCRtpSender = RTCRtpSender || window.RTCRtpSender;
|
||||||
|
if (RTCRtpSender && RTCRtpSender.getCapabilities) {
|
||||||
|
const capabilities = RTCRtpSender.getCapabilities('video');
|
||||||
|
if (capabilities && capabilities.codecs) {
|
||||||
|
const preferredCodecs = capabilities.codecs.filter(c =>
|
||||||
|
c.mimeType.toLowerCase() === 'video/vp8' ||
|
||||||
|
c.mimeType.toLowerCase() === 'video/h264'
|
||||||
|
);
|
||||||
|
if (preferredCodecs.length > 0) {
|
||||||
|
const transceivers = peerConnection.getTransceivers();
|
||||||
|
transceivers.forEach(transceiver => {
|
||||||
|
if (transceiver.receiver.track.kind === 'video') {
|
||||||
|
try {
|
||||||
|
transceiver.setCodecPreferences(preferredCodecs);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Failed to set codec preferences:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return peerConnection.setLocalDescription(sdp);
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
socket.emit('offer', id, peerConnection.localDescription);
|
socket.emit('offer', id, peerConnection.localDescription);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user