Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wkazmierczak committed Sep 16, 2024
1 parent 8d343bc commit 7e73c56
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions demos/utils/gst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function gstStreamWebcam(ip: string, port: number, displayOutput: boolean
: ['v4l2src', 'x264enc', 'tune=zerolatency bitrate=2000 speed-preset=superfast'];

const plugins = [gstWebcamSource, 'videoconvert', gstEncoder, 'rtph264pay', 'udpsink'];
checkGstPlugins(plugins);
void checkGstPlugins(plugins);

const gstCommand =
`gst-launch-1.0 -v ` +
Expand All @@ -29,14 +29,15 @@ export function gstStreamWebcam(ip: string, port: number, displayOutput: boolean
return spawn('bash', ['-c', gstCommand], { displayOutput });
}

function checkGstPlugins(plugins: string[]) {
plugins.forEach(plugin => {
void isGstPluginAvailable(plugin).then(isAvailable => {
async function checkGstPlugins(plugins: string[]) {
await Promise.all(
plugins.map(async plugin => {
const isAvailable = await isGstPluginAvailable(plugin);
if (!isAvailable) {
throw Error(`Gstreamer plugin: ${plugin} is not available.`);
}
});
});
})
);
}

function isGstPluginAvailable(pluginName: string): Promise<boolean> {
Expand Down

0 comments on commit 7e73c56

Please sign in to comment.