Skip to content

Commit 4f00086

Browse files
gsasson-scclaude
andcommitted
Address review: add fpsLimit, simplify options, reword cameraFacing doc
- VideoSourceInput gains optional fpsLimit, passed to createVideoSource. - Pass options object directly (createVideoSource defaults undefined fields). - Reword cameraFacing doc per review. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4cf7b7a commit 4f00086

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/internal/sourceUtils.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,19 @@ describe("sourceUtils", () => {
348348
videoElement.dispatchEvent(new Event("canplay"));
349349
await promise;
350350

351-
expect(mockCreateVideoSource).toHaveBeenCalledWith(videoElement, undefined);
351+
// createVideoSource is always called with an options object; trackingData is just undefined here.
352+
const options = mockCreateVideoSource.mock.calls[0]?.[1];
353+
expect(options?.trackingData).toBeUndefined();
354+
});
355+
356+
it("should pass fpsLimit through", async () => {
357+
const source = { kind: "video" as const, url: "https://example.com/video.mp4", fpsLimit: 30 };
358+
359+
const promise = createCameraKitSource(source);
360+
videoElement.dispatchEvent(new Event("canplay"));
361+
await promise;
362+
363+
expect(mockCreateVideoSource.mock.calls[0]?.[1]?.fpsLimit).toBe(30);
352364
});
353365

354366
it("should pass cameraFacing through as cameraType", async () => {

src/internal/sourceUtils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export async function createCameraKitSource(source: SourceInput): Promise<Source
4545
autoplay: source.autoplay,
4646
trackingDataUrl: source.trackingDataUrl,
4747
cameraFacing: source.cameraFacing,
48+
fpsLimit: source.fpsLimit,
4849
});
4950
} else if (source.kind === "image") {
5051
return createCameraKitImageSource({
@@ -112,11 +113,13 @@ function createCameraKitVideoSource({
112113
autoplay,
113114
trackingDataUrl,
114115
cameraFacing,
116+
fpsLimit,
115117
}: {
116118
videoUrl: string;
117119
autoplay?: boolean;
118120
trackingDataUrl?: string;
119121
cameraFacing?: CameraFacing;
122+
fpsLimit?: number;
120123
}) {
121124
return new Promise<SourceApplication>((res, rej) => {
122125
autoplay = autoplay ?? true;
@@ -138,12 +141,8 @@ function createCameraKitVideoSource({
138141
// before any playback has started, so there is no orphaned playing video to clean up.
139142
const trackingData = trackingDataUrl ? await fetchTrackingData(trackingDataUrl) : undefined;
140143
if (autoplay) await videoInput.play();
141-
const videoSourceOptions =
142-
trackingData || cameraFacing
143-
? { ...(trackingData ? { trackingData } : {}), ...(cameraFacing ? { cameraType: cameraFacing } : {}) }
144-
: undefined;
145144
res({
146-
cameraKitSource: createVideoSource(videoInput, videoSourceOptions),
145+
cameraKitSource: createVideoSource(videoInput, { trackingData, cameraType: cameraFacing, fpsLimit }),
147146
transform: Transform2D.Identity,
148147
inputSize: [videoInput.videoWidth, videoInput.videoHeight],
149148
initializedSourceInput: {

src/types.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ export type VideoSourceInput = {
5656
*/
5757
trackingDataUrl?: string;
5858
/**
59-
* Camera the video should be treated as coming from. Passed to `createVideoSource` as `cameraType`,
60-
* which surfaces to the lens (e.g. front/back-facing behavior) and engine tracking. Defaults to
61-
* `"user"` (front). Set `"environment"` for back-facing / world content. `"user"` ↔ front, `"environment"` ↔ back.
59+
* Front/rear camera semantic the video should be treated as. Passed to CameraKit as `cameraType`,
60+
* which affects Lens feature behavior such as surface tracking. Defaults to "user".
61+
* "user" is front-facing; "environment" is rear-facing.
6262
*/
6363
cameraFacing?: CameraFacing;
64+
/**
65+
* Optional cap on frames per second processed from the video. Passed to `createVideoSource` as
66+
* `fpsLimit`. Defaults to the video's native frame rate when omitted.
67+
*/
68+
fpsLimit?: number;
6469
};
6570
export type ImageSourceInput = { kind: "image"; url: string };
6671

0 commit comments

Comments
 (0)