Skip to content

Commit

Permalink
WEBGL_webcodecs_video_frame: Allow software video frame support (Khro…
Browse files Browse the repository at this point in the history
…nosGroup#3200)

This lifts the restriction of importing harware video frames only.
  • Loading branch information
jchen10 authored Dec 28, 2020
1 parent 3e682ed commit c35d432
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 10 additions & 5 deletions extensions/proposals/WEBGL_webcodecs_video_frame/extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<features>
<feature>
<code>importVideoFrame</code> imports a <code>VideoFrame</code> from WebCodecs, and returns
a <code>WebGLWebCodecsVideoFrameHandle</code>. If the <code>VideoFrame</code> is not backed
by GPU, a TypeError exception will be raised. The <code>VideoFrame</code> keeps being locked
until <code>releaseVideoFrame</code> is called. While being locked, WebCodecs must NOT
manipulate the <code>VideoFrame</code> anymore.
a <code>WebGLWebCodecsVideoFrameHandle</code>. If the <code>VideoFrame</code> can't be
imported, a TypeError exception will be raised. The <code>VideoFrame</code> may keep being
locked until <code>releaseVideoFrame</code> is called. While being locked, WebCodecs must
NOT manipulate the <code>VideoFrame</code> anymore.
</feature>
</features>
</overview>
Expand Down Expand Up @@ -94,7 +94,7 @@ dictionary WebGLWebCodecsVideoFrameHandle {

<p> Next we can assemble the GLSL fragment shader to access the video frame textures.</p>
<pre>
// Note: there could many textures for 1 VideoFrame. To be simple the sample here assumes only
// Note: there could be many textures for 1 VideoFrame. To be simple the sample here assumes only
// 1 texture.
let texInfo0 = videoFrameHandle.textureInfoArray[0];
let fSource =
Expand Down Expand Up @@ -127,6 +127,7 @@ dictionary WebGLWebCodecsVideoFrameHandle {
gl.clearColor(0.0, 0.0, 0.0, 0.0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 6);
gl.bindTexture(texInfo0.target, null);
ext.releaseVideoFrame(webcodecsVideoFrame);
</pre>

Expand All @@ -146,5 +147,9 @@ dictionary WebGLWebCodecsVideoFrameHandle {
<revision date="2020/11/25">
<change>Initial revision.</change>
</revision>
<revision date="2020/12/28">
<change>Lift the hardware video frame restriction.</change>
</revision>

</history>
</proposal>
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ function requestWebGLVideoFrameHandler(canvas) {
}
}

function unbindVideoFrame(gl, videoFrameHandle, texUnit) {
const infoArray = videoFrameHandle.textureInfoArray;
for (let i = 0; i < infoArray.length; ++i) {
gl.activeTexture(texUnit + i);
gl.bindTexture(infoArray[i].target, null);
}
}

function initVertexBuffers(gl, program, videoFrame, posAttrib, coordAttrib) {
const vertices = new Float32Array([
-1.0, -1.0, 1.0, -1.0, 1.0, 1.0,
Expand Down Expand Up @@ -298,6 +306,7 @@ function requestWebGLVideoFrameHandler(canvas) {
gl.clearColor(0.0, 0.0, 0.0, 0.0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES, 0, 6);
unbindVideoFrame(gl, videoFrameHandle, gl.TEXTURE0);

// Immediately schedule rendering of the next frame
setTimeout(renderFrame, 0);
Expand All @@ -314,4 +323,4 @@ function requestWebGLVideoFrameHandler(canvas) {
}

return handleFrame;
}
}

0 comments on commit c35d432

Please sign in to comment.