Skip to content

Commit

Permalink
Merge videoUploading samples together (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois authored Mar 5, 2024
1 parent 5f11215 commit 59a729b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 156 deletions.
9 changes: 9 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ module.exports = {
basePath: BASE_PATH,
compress: true,
reactStrictMode: true,
async redirects() {
return [
{
source: '/samples/videoUploadingWebCodecs',
destination: '/samples/videoUploading?videoSource=videoFrame',
permanent: true,
},
]
},
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.module.rules.push({
test: /\.(png|jpe?g|gif|webm)$/i,
Expand Down
3 changes: 0 additions & 3 deletions src/pages/samples/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ const gpuComputeDemoPages: PageComponentType = {
const webPlatformPages: PageComponentType = {
resizeCanvas: dynamic(() => import('../../sample/resizeCanvas/main')),
videoUploading: dynamic(() => import('../../sample/videoUploading/main')),
videoUploadingWebCodecs: dynamic(
() => import('../../sample/videoUploadingWebCodecs/main')
),
worker: dynamic(() => import('../../sample/worker/main')),
};

Expand Down
9 changes: 8 additions & 1 deletion src/sample/videoUploading/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
minFilter: 'linear',
});

const params = new URLSearchParams(window.location.search);

const settings = {
requestFrame: 'requestAnimationFrame',
videoSource: params.get('videoSource') || 'videoElement',
};

gui.add(settings, 'videoSource', ['videoElement', 'videoFrame']);
gui.add(settings, 'requestFrame', [
'requestAnimationFrame',
'requestVideoFrameCallback',
Expand All @@ -71,6 +75,9 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
// Sample is no longer the active page.
if (!pageState.active) return;

const externalTextureSource =
settings.videoSource === 'videoFrame' ? new VideoFrame(video) : video;

const uniformBindGroup = device.createBindGroup({
layout: pipeline.getBindGroupLayout(0),
entries: [
Expand All @@ -81,7 +88,7 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
{
binding: 2,
resource: device.importExternalTexture({
source: video,
source: externalTextureSource,
}),
},
],
Expand Down
152 changes: 0 additions & 152 deletions src/sample/videoUploadingWebCodecs/main.ts

This file was deleted.

0 comments on commit 59a729b

Please sign in to comment.