This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function keepAliveTask(task) { | |
while (true) { | |
try { | |
log('starting task:', task.name) | |
task() | |
} | |
catch (error) { | |
log('task crashed:', task.name, error ) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gl.readPixels(0, 0, W, H, gl.RGBA, gl.UNSIGNED_BYTE, bufferRGB); | |
const init = { | |
timestamp: videoFrame.timestamp, | |
codedWidth: W, | |
codedHeight: H, | |
format: "RGBA", | |
}; | |
//const newFrame = new VideoFrame(bufferRGB, init); | |
const newFrame = new VideoFrame(gl.canvas, init); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const W = 1280; | |
const H = 720; | |
async function start() { | |
const buffer = new Uint8Array(W * H * 1.5); | |
const bufferRGB = new Uint8Array(W * H * 4); | |
const transformer = new TransformStream({ | |
async transform(videoFrame, controller) { | |
const startTs = performance.now(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precision highp float; | |
uniform sampler2D u_image; | |
uniform sampler2D u_image_frame; | |
uniform vec2 u_resolution; | |
varying vec2 v_texCoord; | |
void main() { | |
float x_offset = mod( gl_FragCoord.y ,2.0 ) < 1.0 ? 0.5 : 0.0 ; | |
vec4 y4 = texture2D(u_image_frame, vec2 ( v_texCoord.x / 1.0 , v_texCoord.y / 1.5 ) ) ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var glRef = {}; | |
function loadImage(src) { | |
return new Promise((resolve, reject) => { | |
const img = new Image(); | |
img.onload = () => { | |
resolve(img); | |
}; | |
img.src = src; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attribute vec2 a_position; | |
attribute vec2 a_texCoord; | |
uniform vec2 u_resolution; | |
varying vec2 v_texCoord; | |
void main() { | |
gl_Position = vec4(( (a_position / u_resolution * 2.0) - 1.0) * vec2(1, -1), 0, 1); | |
v_texCoord = a_texCoord; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WASM_FILE = "./main.wasm"; | |
const W = 640; | |
const H = 360; | |
let mem_in, mem_out; | |
let mem_bg_img; | |
let instance = null; | |
let memoryStates = new WeakMap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#define WASM_EXPORT __attribute__((visibility("default"))) | |
uint16_t w; // frame width | |
uint16_t h ; // frame height | |
uint8_t * input_buffer; | |
uint8_t * out_buffer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const W = 640; // video frame width | |
const H = 360; // video frame height | |
const pixelData = await imageLoader("./seaside.png"); // get the pixel data of the backgroung image in RGBA format | |
const buffer = new Uint8Array(W * H * 1.5); // byte buffer for the incoming frame in YUV 422 format | |
const bufferRGB = new Uint8Array(W * H * 4); // byte buffer for the result frame in RGBA format | |
const transformer = new TransformStream({ | |
async transform(videoFrame, controller) { | |
const copyResult = await videoFrame.copyTo(buffer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{offset: 0, stride: 640}, | |
{offset: 921600, stride: 320}, | |
{offset: 1152000, stride: 320} | |
] |
NewerOlder