From 631ac812433e156260eec3cd6462c0cd9c2e7887 Mon Sep 17 00:00:00 2001
From: fgwt202412 <191263616+fgwt202412@users.noreply.github.com>
Date: Mon, 16 Dec 2024 10:51:33 -0500
Subject: [PATCH] FG-2933: Add mp4a.40.2 capture to MCAP recording demo
---
.../McapRecordingDemo/McapRecordingDemo.tsx | 30 +++-
.../components/McapRecordingDemo/Recorder.ts | 12 ++
.../McapRecordingDemo/audioCapture.ts | 130 +++++++++++++-----
3 files changed, 134 insertions(+), 38 deletions(-)
diff --git a/website/src/components/McapRecordingDemo/McapRecordingDemo.tsx b/website/src/components/McapRecordingDemo/McapRecordingDemo.tsx
index 3f0050be0..a7f724419 100644
--- a/website/src/components/McapRecordingDemo/McapRecordingDemo.tsx
+++ b/website/src/components/McapRecordingDemo/McapRecordingDemo.tsx
@@ -20,6 +20,7 @@ import {
CompressedAudioData,
startAudioCapture,
supportsOpusEncoding,
+ supportsMP4AEncoding,
} from "./audioCapture";
import {
CompressedVideoFrame,
@@ -144,6 +145,7 @@ export function McapRecordingDemo(): JSX.Element {
const [recordH265, setRecordH265] = useState(false);
const [recordVP9, setRecordVP9] = useState(false);
const [recordAV1, setRecordAV1] = useState(false);
+ const [recordMP4A, setRecordMP4A] = useState(false);
const [recordOpus, setRecordOpus] = useState(false);
const [recordMouse, setRecordMouse] = useState(true);
const [recordOrientation, setRecordOrientation] = useState(true);
@@ -164,6 +166,7 @@ export function McapRecordingDemo(): JSX.Element {
const { data: h265Support } = useAsync(supportsH265Encoding);
const { data: vp9Support } = useAsync(supportsVP9Encoding);
const { data: av1Support } = useAsync(supportsAV1Encoding);
+ const { data: mp4aSupport } = useAsync(supportsMP4AEncoding);
const { data: opusSupport } = useAsync(supportsOpusEncoding);
const canStartRecording =
@@ -174,6 +177,7 @@ export function McapRecordingDemo(): JSX.Element {
(recordH265 && !videoError) ||
(recordH264 && !videoError) ||
(recordJpeg && !videoError) ||
+ (recordMP4A && !audioError) ||
(recordOpus && !audioError);
// Automatically pause recording after 30 seconds to avoid unbounded growth
@@ -304,7 +308,7 @@ export function McapRecordingDemo(): JSX.Element {
undefined,
);
- const enableMicrophone = recordOpus;
+ const enableMicrophone = recordMP4A || recordOpus;
useEffect(() => {
const progress = audioProgressRef.current;
if (!progress || !enableMicrophone) {
@@ -327,7 +331,7 @@ export function McapRecordingDemo(): JSX.Element {
setAudioStream(undefined);
setAudioError(undefined);
};
- }, [enableMicrophone, recordOpus]);
+ }, [enableMicrophone]);
useEffect(() => {
if (!enableMicrophone || !recording || !audioStream) {
@@ -335,6 +339,7 @@ export function McapRecordingDemo(): JSX.Element {
}
const cleanup = startAudioCapture({
+ enableMP4A: recordMP4A,
enableOpus: recordOpus,
stream: audioStream,
onAudioData: (data) => {
@@ -348,7 +353,14 @@ export function McapRecordingDemo(): JSX.Element {
return () => {
cleanup?.();
};
- }, [addAudioData, enableMicrophone, recordOpus, audioStream, recording]);
+ }, [
+ addAudioData,
+ enableMicrophone,
+ recordMP4A,
+ recordOpus,
+ audioStream,
+ recording,
+ ]);
const onRecordClick = useCallback(
(event: React.MouseEvent) => {
@@ -488,6 +500,18 @@ export function McapRecordingDemo(): JSX.Element {
/>
Camera (JPEG)
+ {mp4aSupport === true && (
+
+ )}
{opusSupport === true && (