2021-01-08 18:58:28 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
2021-09-28 16:37:03 +00:00
|
|
|
|
2023-01-09 18:38:57 +00:00
|
|
|
import type { VideoFrameSource } from '@signalapp/ringrtc';
|
2021-01-08 18:58:28 +00:00
|
|
|
|
|
|
|
const COLORS: Array<[number, number, number]> = [
|
|
|
|
[0xff, 0x00, 0x00],
|
|
|
|
[0xff, 0x99, 0x00],
|
|
|
|
[0xff, 0xff, 0x00],
|
|
|
|
[0x00, 0xff, 0x00],
|
|
|
|
[0x00, 0x99, 0xff],
|
|
|
|
[0xff, 0x00, 0xff],
|
|
|
|
[0x99, 0x33, 0xff],
|
|
|
|
];
|
|
|
|
|
|
|
|
class FakeGroupCallVideoFrameSource implements VideoFrameSource {
|
|
|
|
private readonly sourceArray: Uint8Array;
|
|
|
|
|
|
|
|
private readonly dimensions: [number, number];
|
|
|
|
|
|
|
|
constructor(width: number, height: number, r: number, g: number, b: number) {
|
|
|
|
const length = width * height * 4;
|
|
|
|
|
|
|
|
this.sourceArray = new Uint8Array(length);
|
|
|
|
for (let i = 0; i < length; i += 4) {
|
|
|
|
this.sourceArray[i] = r;
|
|
|
|
this.sourceArray[i + 1] = g;
|
|
|
|
this.sourceArray[i + 2] = b;
|
|
|
|
this.sourceArray[i + 3] = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dimensions = [width, height];
|
|
|
|
}
|
|
|
|
|
2023-02-18 03:25:24 +00:00
|
|
|
receiveVideoFrame(
|
|
|
|
destinationBuffer: Buffer,
|
|
|
|
_maxWidth: number,
|
|
|
|
_maxHeight: number
|
|
|
|
): [number, number] | undefined {
|
2021-01-08 18:58:28 +00:00
|
|
|
// Simulate network jitter. Also improves performance when testing.
|
|
|
|
if (Math.random() < 0.5) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2021-06-29 14:39:53 +00:00
|
|
|
destinationBuffer.set(this.sourceArray);
|
2021-01-08 18:58:28 +00:00
|
|
|
return this.dimensions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This produces a fake video frame source that is a single color.
|
|
|
|
*
|
|
|
|
* The aspect ratio is fixed at 1.3 because that matches many of our stories.
|
|
|
|
*/
|
|
|
|
export function fakeGetGroupCallVideoFrameSource(
|
|
|
|
demuxId: number
|
|
|
|
): VideoFrameSource {
|
|
|
|
const color = COLORS[demuxId % COLORS.length];
|
|
|
|
if (!color) {
|
|
|
|
throw new Error('Expected a color, but it was not found');
|
|
|
|
}
|
|
|
|
const [r, g, b] = color;
|
|
|
|
|
|
|
|
return new FakeGroupCallVideoFrameSource(13, 10, r, g, b);
|
|
|
|
}
|