🎥 Make videos programmatically with React
webcodecs: Make needsToBeMultipleOfTwo optional and export rotateAndResizeVideoFrame as public API
copilot-swe-agent[bot]0d69cca54e84
diff --git a/packages/webcodecs/src/index.ts b/packages/webcodecs/src/index.tsindex 479912d595..2c2f67e211 100644--- a/packages/webcodecs/src/index.ts+++ b/packages/webcodecs/src/index.ts@@ -45,6 +45,7 @@ export type {VideoOperation,} from './on-video-track-handler';export type {ResizeOperation} from './resizing/mode';+export {rotateAndResizeVideoFrame} from './rotate-and-resize-video-frame';export {createVideoEncoder} from './video-encoder';export type {WebCodecsVideoEncoder} from './video-encoder';export {webcodecsController} from './webcodecs-controller';diff --git a/packages/webcodecs/src/rotate-and-resize-video-frame.ts b/packages/webcodecs/src/rotate-and-resize-video-frame.tsindex 153e158908..f07a528d89 100644--- a/packages/webcodecs/src/rotate-and-resize-video-frame.ts+++ b/packages/webcodecs/src/rotate-and-resize-video-frame.ts@@ -11,12 +11,12 @@ export const normalizeVideoRotation = (rotation: number) => {export const rotateAndResizeVideoFrame = ({frame,rotation,- needsToBeMultipleOfTwo,+ needsToBeMultipleOfTwo = false,resizeOperation,}: {frame: VideoFrame;rotation: number;- needsToBeMultipleOfTwo: boolean;+ needsToBeMultipleOfTwo?: boolean;resizeOperation: ResizeOperation | null;}) => {const normalized = ((rotation % 360) + 360) % 360;diff --git a/packages/webcodecs/src/test/rotate-and-resize-video-frame.test.ts b/packages/webcodecs/src/test/rotate-and-resize-video-frame.test.tsnew file mode 100644index 0000000000..945465bc8d--- /dev/null+++ b/packages/webcodecs/src/test/rotate-and-resize-video-frame.test.ts@@ -0,0 +1,65 @@+import {expect, test} from 'bun:test';+import {rotateAndResizeVideoFrame} from '../rotate-and-resize-video-frame';++// Test that focuses on API structure and parameter validation+test('rotateAndResizeVideoFrame - function exists and has correct signature', () => {+ expect(typeof rotateAndResizeVideoFrame).toBe('function');+});++test('rotateAndResizeVideoFrame - throws error for invalid rotation', () => {+ // Mock VideoFrame that's sufficient for this test+ const mockFrame = {+ displayWidth: 100,+ displayHeight: 200,+ timestamp: 0,+ duration: 1000000,+ close: () => {},+ } as unknown as VideoFrame;++ expect(() => {+ rotateAndResizeVideoFrame({+ frame: mockFrame,+ rotation: 45, // Not a multiple of 90+ resizeOperation: null,+ });+ }).toThrow('Only 90 degree rotations are supported');+});++test('rotateAndResizeVideoFrame - accepts optional needsToBeMultipleOfTwo parameter', () => {+ // Mock VideoFrame that's sufficient for this test+ const mockFrame = {+ displayWidth: 100,+ displayHeight: 200,+ timestamp: 0,+ duration: 1000000,+ close: () => {},+ } as unknown as VideoFrame;++ // Should not throw when needsToBeMultipleOfTwo is omitted+ expect(() => {+ rotateAndResizeVideoFrame({+ frame: mockFrame,+ rotation: 0,+ resizeOperation: null,+ });+ }).not.toThrow();++ // Should not throw when needsToBeMultipleOfTwo is explicitly provided+ expect(() => {+ rotateAndResizeVideoFrame({+ frame: mockFrame,+ rotation: 0,+ resizeOperation: null,+ needsToBeMultipleOfTwo: true,+ });+ }).not.toThrow();++ expect(() => {+ rotateAndResizeVideoFrame({+ frame: mockFrame,+ rotation: 0,+ resizeOperation: null,+ needsToBeMultipleOfTwo: false,+ });+ }).not.toThrow();+});\ No newline at end of file