2021-01-08 17:32:49 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { useRef, useCallback } from 'react';
|
|
|
|
import { FRAME_BUFFER_SIZE } from './constants';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A hook that returns a function. This function returns a "singleton" `ArrayBuffer` to be
|
|
|
|
* used in call video rendering.
|
|
|
|
*
|
|
|
|
* This is most useful for group calls, where we can reuse the same frame buffer instead
|
|
|
|
* of allocating one per participant. Be careful when using this buffer elsewhere, as it
|
|
|
|
* is not cleaned up and may hold stale data.
|
|
|
|
*/
|
2021-12-11 00:21:28 +00:00
|
|
|
export function useGetCallingFrameBuffer(): () => Buffer {
|
|
|
|
const ref = useRef<Buffer | null>(null);
|
2021-01-08 17:32:49 +00:00
|
|
|
|
|
|
|
return useCallback(() => {
|
|
|
|
if (!ref.current) {
|
2021-12-11 00:21:28 +00:00
|
|
|
ref.current = Buffer.alloc(FRAME_BUFFER_SIZE);
|
2021-01-08 17:32:49 +00:00
|
|
|
}
|
|
|
|
return ref.current;
|
|
|
|
}, []);
|
|
|
|
}
|