Skip to content

Commit

Permalink
Add fps to subscribe setting (livekit#484)
Browse files Browse the repository at this point in the history
* Add fps to subscribe setting

* solve comments
  • Loading branch information
cnderrauber committed Oct 26, 2022
1 parent ebbd669 commit 9a54cb4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lovely-ties-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Add fps field to SubscribeSetting
11 changes: 11 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ <h2>Livekit Sample App</h2>
<option value="medium">medium</option>
<option value="low">low</option>
</select>
<select
id="preferred-fps"
class="custom-select"
style="width: auto"
onchange="appActions.handlePreferredFPS(event)"
>
<option value="" selected>PreferredFPS</option>
<option value="30">30</option>
<option value="15">15</option>
<option value="8">8</option>
</select>
</div>
</div>

Expand Down
11 changes: 11 additions & 0 deletions example/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,17 @@ const appActions = {
});
}
},

handlePreferredFPS: (e: Event) => {
const fps = +(<HTMLSelectElement>e.target).value;
if (currentRoom) {
currentRoom.participants.forEach((participant) => {
participant.tracks.forEach((track) => {
track.setVideoFPS(fps);
});
});
}
},
};

declare global {
Expand Down
13 changes: 12 additions & 1 deletion src/proto/livekit_rtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ export interface UpdateTrackSettings {
width: number;
/** for video, height to receive */
height: number;
/** for video, frame rate to receive */
fps: number;
}

export interface LeaveRequest {
Expand Down Expand Up @@ -1843,7 +1845,7 @@ export const UpdateSubscription = {
};

function createBaseUpdateTrackSettings(): UpdateTrackSettings {
return { trackSids: [], disabled: false, quality: 0, width: 0, height: 0 };
return { trackSids: [], disabled: false, quality: 0, width: 0, height: 0, fps: 0 };
}

export const UpdateTrackSettings = {
Expand All @@ -1863,6 +1865,9 @@ export const UpdateTrackSettings = {
if (message.height !== 0) {
writer.uint32(48).uint32(message.height);
}
if (message.fps !== 0) {
writer.uint32(56).uint32(message.fps);
}
return writer;
},

Expand All @@ -1888,6 +1893,9 @@ export const UpdateTrackSettings = {
case 6:
message.height = reader.uint32();
break;
case 7:
message.fps = reader.uint32();
break;
default:
reader.skipType(tag & 7);
break;
Expand All @@ -1903,6 +1911,7 @@ export const UpdateTrackSettings = {
quality: isSet(object.quality) ? videoQualityFromJSON(object.quality) : 0,
width: isSet(object.width) ? Number(object.width) : 0,
height: isSet(object.height) ? Number(object.height) : 0,
fps: isSet(object.fps) ? Number(object.fps) : 0,
};
},

Expand All @@ -1917,6 +1926,7 @@ export const UpdateTrackSettings = {
message.quality !== undefined && (obj.quality = videoQualityToJSON(message.quality));
message.width !== undefined && (obj.width = Math.round(message.width));
message.height !== undefined && (obj.height = Math.round(message.height));
message.fps !== undefined && (obj.fps = Math.round(message.fps));
return obj;
},

Expand All @@ -1927,6 +1937,7 @@ export const UpdateTrackSettings = {
message.quality = object.quality ?? 0;
message.width = object.width ?? 0;
message.height = object.height ?? 0;
message.fps = object.fps ?? 0;
return message;
},
};
Expand Down
20 changes: 20 additions & 0 deletions src/room/track/RemoteTrackPublication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default class RemoteTrackPublication extends TrackPublication {

protected videoDimensions?: Track.Dimensions;

protected fps?: number;

constructor(kind: Track.Kind, id: string, name: string, autoSubscribe: boolean | undefined) {
super(kind, id, name);
this.subscribed = autoSubscribe;
Expand Down Expand Up @@ -143,6 +145,23 @@ export default class RemoteTrackPublication extends TrackPublication {
this.emitTrackUpdate();
}

setVideoFPS(fps: number) {
if (!this.isManualOperationAllowed()) {
return;
}

if (!(this.track instanceof RemoteVideoTrack)) {
return;
}

if (this.fps === fps) {
return;
}

this.fps = fps;
this.emitTrackUpdate();
}

get videoQuality(): VideoQuality | undefined {
return this.currentVideoQuality;
}
Expand Down Expand Up @@ -256,6 +275,7 @@ export default class RemoteTrackPublication extends TrackPublication {
const settings: UpdateTrackSettings = UpdateTrackSettings.fromPartial({
trackSids: [this.trackSid],
disabled: this.disabled,
fps: this.fps,
});
if (this.videoDimensions) {
settings.width = this.videoDimensions.width;
Expand Down

0 comments on commit 9a54cb4

Please sign in to comment.