Skip to content

Commit 2337693

Browse files
committed
Dynamic video encodings
1 parent 47fe55c commit 2337693

File tree

9 files changed

+24
-37
lines changed

9 files changed

+24
-37
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/mattermost/mattermost-plugin-calls/server/public v0.0.3
2323
github.com/mattermost/mattermost/server/public v0.1.10
2424
github.com/mattermost/morph v1.1.0
25-
github.com/mattermost/rtcd v1.0.3-0.20250324194900-261d62c06e9f
25+
github.com/mattermost/rtcd v1.2.0-dev0.0.20250418164102-f5f23877892a
2626
github.com/mattermost/squirrel v0.2.0
2727
github.com/pkg/errors v0.9.1
2828
github.com/rudderlabs/analytics-go v3.3.3+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ github.com/mattermost/mattermost/server/public v0.1.10 h1:gp3XHxqj5KDkz3venimqqN
375375
github.com/mattermost/mattermost/server/public v0.1.10/go.mod h1:hu2sIyXm024PGIGhACqmCxvp3atrwRzXGgAzCvs6zJs=
376376
github.com/mattermost/morph v1.1.0 h1:Q9vrJbeM3s2jfweGheq12EFIzdNp9a/6IovcbvOQ6Cw=
377377
github.com/mattermost/morph v1.1.0/go.mod h1:gD+EaqX2UMyyuzmF4PFh4r33XneQ8Nzi+0E8nXjMa3A=
378-
github.com/mattermost/rtcd v1.0.3-0.20250324194900-261d62c06e9f h1:7WhG/Z9/h4nhxz5G5MKW2St28vaz9mLg21MOPaJ+JcU=
379-
github.com/mattermost/rtcd v1.0.3-0.20250324194900-261d62c06e9f/go.mod h1:KLu43RNFZw8Kstkztr879RTEHovax3GUOdm4W9CBllQ=
378+
github.com/mattermost/rtcd v1.2.0-dev0.0.20250418164102-f5f23877892a h1:N/82q73r97evA/9RtwJTQsnODsVKTz7XRORnnxHp45s=
379+
github.com/mattermost/rtcd v1.2.0-dev0.0.20250418164102-f5f23877892a/go.mod h1:KLu43RNFZw8Kstkztr879RTEHovax3GUOdm4W9CBllQ=
380380
github.com/mattermost/squirrel v0.2.0 h1:8ZWeyf+MWQ2cL7hu9REZgLtz2IJi51qqZEovI3T3TT8=
381381
github.com/mattermost/squirrel v0.2.0/go.mod h1:NPPtk+CdpWre4GxMGoOpzEVFVc0ZoEFyJBZGCtn9nSU=
382382
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=

lt/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/aws/aws-sdk-go v1.50.3
77
github.com/hajimehoshi/go-mp3 v0.3.4
88
github.com/mattermost/mattermost/server/public v0.1.10
9-
github.com/mattermost/rtcd v1.0.3-0.20250324194900-261d62c06e9f
9+
github.com/mattermost/rtcd v1.2.0-dev0.0.20250418164102-f5f23877892a
1010
github.com/pion/rtp v1.8.13
1111
github.com/pion/webrtc/v4 v4.0.13
1212
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302

lt/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ github.com/mattermost/logr/v2 v2.0.21 h1:CMHsP+nrbRlEC4g7BwOk1GAnMtHkniFhlSQPXy5
112112
github.com/mattermost/logr/v2 v2.0.21/go.mod h1:kZkB/zqKL9e+RY5gB3vGpsyenC+TpuiOenjMkvJJbzc=
113113
github.com/mattermost/mattermost/server/public v0.1.10 h1:gp3XHxqj5KDkz3venimqqNc62rqyF15uusQuBr8k7J4=
114114
github.com/mattermost/mattermost/server/public v0.1.10/go.mod h1:hu2sIyXm024PGIGhACqmCxvp3atrwRzXGgAzCvs6zJs=
115-
github.com/mattermost/rtcd v1.0.3-0.20250324194900-261d62c06e9f h1:7WhG/Z9/h4nhxz5G5MKW2St28vaz9mLg21MOPaJ+JcU=
116-
github.com/mattermost/rtcd v1.0.3-0.20250324194900-261d62c06e9f/go.mod h1:KLu43RNFZw8Kstkztr879RTEHovax3GUOdm4W9CBllQ=
115+
github.com/mattermost/rtcd v1.2.0-dev0.0.20250418164102-f5f23877892a h1:N/82q73r97evA/9RtwJTQsnODsVKTz7XRORnnxHp45s=
116+
github.com/mattermost/rtcd v1.2.0-dev0.0.20250418164102-f5f23877892a/go.mod h1:KLu43RNFZw8Kstkztr879RTEHovax3GUOdm4W9CBllQ=
117117
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
118118
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
119119
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=

standalone/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

standalone/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"extract": "formatjs extract 'src/**/*.{ts,tsx}' --ignore 'src/**/*.d.ts' --out-file i18n/temp.json --id-interpolation-pattern '[sha512:contenthash:base64:6]' && formatjs compile 'i18n/temp.json' --out-file i18n/en.json && rm i18n/temp.json"
1919
},
2020
"dependencies": {
21-
"@mattermost/calls-common": "github:mattermost/calls-common#7c22d44c742a8cdb52a4c84f5e5640fea39fb86d",
21+
"@mattermost/calls-common": "github:mattermost/calls-common#24b6bdbc7036109de7cd707180ccb78bc3563177",
2222
"@mattermost/compass-icons": "0.1.31",
2323
"@msgpack/msgpack": "2.7.1",
2424
"bootstrap": "3.4.1",

webapp/package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"dependencies": {
2222
"@floating-ui/react": "0.26.12",
23-
"@mattermost/calls-common": "github:mattermost/calls-common#7c22d44c742a8cdb52a4c84f5e5640fea39fb86d",
23+
"@mattermost/calls-common": "github:mattermost/calls-common#24b6bdbc7036109de7cd707180ccb78bc3563177",
2424
"@mediapipe/tasks-vision": "0.10.22-rc.20250304",
2525
"@msgpack/msgpack": "2.7.1",
2626
"@redux-devtools/extension": "3.2.3",

webapp/src/client.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// eslint-disable max-lines
55
// eslint-disable-next-line simple-import-sort/imports
66
import {parseRTCStats, RTCMonitor, RTCPeer} from '@mattermost/calls-common';
7-
import type {EmojiData, CallsClientJoinData, TrackInfo, RTPEncodingParameters} from '@mattermost/calls-common/lib/types';
7+
import {type EmojiData, type CallsClientJoinData, type TrackInfo, type RTPEncodingParameters} from '@mattermost/calls-common/lib/types';
88

99
import {EventEmitter} from 'events';
1010

@@ -75,7 +75,6 @@ export default class CallsClient extends EventEmitter {
7575
private connected = false;
7676
public initTime = Date.now();
7777
private rtcMonitor: RTCMonitor | null = null;
78-
private av1Codec: RTCRtpCodecCapability | null = null;
7978
private defaultAudioTrackOptions: MediaTrackConstraints;
8079
private defaultVideoTrackOptions: MediaTrackConstraints;
8180
private defaultVideoTrackEncodings: RTPEncodingParameters[];
@@ -391,8 +390,7 @@ export default class CallsClient extends EventEmitter {
391390
this.channelID = joinData.channelID;
392391

393392
if (this.config.enableAV1 && !this.config.simulcast) {
394-
this.av1Codec = await RTCPeer.getVideoCodec('video/AV1');
395-
if (this.av1Codec) {
393+
if (await RTCPeer.getVideoCodec('video/AV1')) {
396394
logDebug('client has AV1 support');
397395
joinData.av1Support = true;
398396
}
@@ -478,6 +476,7 @@ export default class CallsClient extends EventEmitter {
478476
},
479477
simulcast: this.config.simulcast,
480478
dcSignaling: this.config.dcSignaling,
479+
enableAV1: this.config.enableAV1,
481480
});
482481

483482
this.peer = peer;
@@ -836,6 +835,9 @@ export default class CallsClient extends EventEmitter {
836835
if (this.remoteVideoTracks.length < 1 || this.remoteVideoTracks[this.remoteVideoTracks.length - 1].readyState !== 'live') {
837836
return null;
838837
}
838+
839+
// We return the last video track since it should be the most recent one with updated encoding if codec changes.
840+
// Obviously we'll have to review this once we add support for more than one video track (i.e., outside of DMs).
839841
return new MediaStream([this.remoteVideoTracks[this.remoteVideoTracks.length - 1]]);
840842
}
841843

@@ -884,17 +886,8 @@ export default class CallsClient extends EventEmitter {
884886
};
885887

886888
logDebug('adding stream to peer', screenStream.id);
887-
888-
// Always send a fallback track (VP8 encoded) for receivers that don't yet support AV1.
889889
await this.peer.addStream(screenStream);
890890

891-
if (this.config.enableAV1 && this.av1Codec) {
892-
logDebug('AV1 supported, sending track', this.av1Codec);
893-
await this.peer.addStream(screenStream, [{
894-
codec: this.av1Codec,
895-
}]);
896-
}
897-
898891
this.ws.send('screen_on', {
899892
data: JSON.stringify({
900893
screenStreamID: screenStream.id,
@@ -1008,13 +1001,6 @@ export default class CallsClient extends EventEmitter {
10081001
await this.peer.replaceTrack(localVideoTrackID, localVideoTrack);
10091002
} else {
10101003
await this.peer.addTrack(localVideoTrack, this.localVideoStream, {encodings: this.defaultVideoTrackEncodings});
1011-
if (this.config.enableAV1 && this.av1Codec) {
1012-
logDebug('AV1 supported, sending track', this.av1Codec);
1013-
await this.peer.addTrack(localVideoTrack, this.localVideoStream, {
1014-
codec: this.av1Codec,
1015-
encodings: this.defaultVideoTrackEncodings,
1016-
});
1017-
}
10181004
this.videoTrackAdded = true;
10191005
}
10201006

0 commit comments

Comments
 (0)