Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('Roundtrip a frame', async t => {
let frm = beamcoder.frame({
pts: 1234567890,
width: 1920,
height: 1080,
format: 'yuv422p',
metadata: { wibble: 'wobble' },
side_data: { replaygain : Buffer.from('wombles') }
}).alloc();
let redis = new Redis();
await redis.del(`beam:frame:${frm.pts}`);
// for ( let x = 0 ; x < 100 ; x++ ) {
let start = process.hrtime();
let frmr = frameToRedis(frm.toJSON());
console.log('frameToRedis', process.hrtime(start));
start = process.hrtime();
test('Roundtrip a packet', async t => {
let data = Buffer.alloc(65536);
for ( let x = 0 ; x < data.length ; x++ ) data[x] = x % 128;
let pkt = beamcoder.packet({
pts: 9876543210,
dts: null,
data: data,
flags: { KEY: true },
side_data: { replaygain: Buffer.from('wibble') }
});
let redis = new Redis();
await redis.del(`beam:packet:${pkt.pts}`);
let rdpr = null;
// for ( let x = 0 ; x < 100 ; x++ ) {
let start = process.hrtime();
let pktj = pkt.toJSON();
console.log('toJSON', process.hrtime(start));
start = process.hrtime();
let pktr = packetToRedis(pktj);
console.log('packetToRedis', process.hrtime(start));
let pktr = packetToRedis(pktj);
console.log('packetToRedis', process.hrtime(start));
console.log(pktr);
start = process.hrtime();
t.equal(await redis.hmset(`beam:packet:${pkt.pts}`, pktr), 'OK',
'redis says set OK.');
console.log('Set took', process.hrtime(start));
start = process.hrtime();
let rdp = await redis.hgetallBuffer(`beam:packet:${pkt.pts}`);
console.log('Get took', process.hrtime(start));
start = process.hrtime();
rdpr = packetFromRedis(rdp);
console.log('packetFromRedis', process.hrtime(start));
// }
// t.equal(Buffer.compare(rdp.data, data), 0, 'data has roundtripped OK.');
let rp = beamcoder.packet(rdpr);
t.ok(rp, 'roundtrip packet is truthy.');
console.log(rp);
await redis.quit();
t.end();
});
test('GET a frame', async t => {
try {
t.ok(await flushdb(), 'database flushed OK.');
t.comment('### Retrieve a frame');
t.deepEqual(await redisio.storeMedia('test_url', testUtil.frm, 3),
['OK-crt', 'OK-crt', 'OK-crt', 'OK-crt'], 'test frame stored OK.');
let response = await request(server).get('/beams/test_url/stream_3/42')
.expect(200);
t.ok(response.ok, 'response claims OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
t.ok(Array.isArray(response.body), 'result is an array.');
let frm = beamcoder.frame(response.body[0]);
t.ok(frm, 'roundtrip frame is truthy.');
t.deepEqual(frm.toJSON(), frm.toJSON(),
'retrieved frame as expected.');
t.deepEqual(frm.buf_sizes, [ 2073600, 1036800, 1036800 ],
'has expected buf_sizes parameter.');
t.comment('### Frame not found');
response = await request(server).get('/beams/test_url/stream_3/41')
.expect(404);
t.notOk(response.ok, 'response is not OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
t.deepEqual(response.body, { statusCode: 404,
error: 'Not Found',
message: `Media with name 'test_url:stream_3:41' was not found: Unable to find requested media elements.` }, // eslint-disable-line
'error message structure as expected.');
test('GET a frame directly', async t => {
try {
t.ok(await flushdb(), 'database flushed OK.');
t.comment('### Retrieve a frame directly');
t.deepEqual(await redisio.storeMedia('test_url', testUtil.frm, 3),
['OK-crt', 'OK-crt', 'OK-crt', 'OK-crt'], 'test frame stored OK.');
let response = await request(server).get('/beams/test_url/stream_3/frame_42')
.expect(200);
t.ok(response.ok, 'response claims OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
t.notOk(Array.isArray(response.body), 'result is an array.');
let frm = beamcoder.frame(response.body);
t.ok(frm, 'roundtrip frame is truthy.');
t.deepEqual(frm.toJSON(), frm.toJSON(),
'retrieved frame as expected.');
t.deepEqual(frm.buf_sizes, [ 2073600, 1036800, 1036800 ],
'has expected buf_sizes parameter.');
t.comment('### Frame not found');
response = await request(server).get('/beams/test_url/stream_3/frame_41')
.expect(404);
t.notOk(response.ok, 'response is not OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
t.deepEqual(response.body, { statusCode: 404,
error: 'Not Found',
message: `Frame with name 'test_url:stream_3:frame_41' was not found: Frame in stream 'stream_3' with timestamp '41' is not found.` }, // eslint-disable-line
'error message structure as expected.');
} catch (err) {
test('GET a packet', async t => {
try {
t.ok(await flushdb(), 'database flushed OK.');
t.comment('### Retrieve a packet');
t.deepEqual(await redisio.storeMedia('test_url', testUtil.pkt), ['OK-crt','OK-crt'],
'test packet stored OK.');
let response = await request(server).get('/beams/test_url/stream_3/42')
.expect(200);
t.ok(response.ok, 'response claims OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
t.ok(Array.isArray(response.body), 'result is an array.');
let pkt = beamcoder.packet(response.body[0]);
t.ok(pkt, 'roundtrip packet is truthy.');
t.deepEqual(pkt.toJSON(), testUtil.pkt.toJSON(),
'retrieved packet as expected.');
t.equal(pkt.size, 16383, 'has expected size parameter.');
t.comment('### Packet not found');
response = await request(server).get('/beams/test_url/stream_3/41')
.expect(404);
t.notOk(response.ok, 'response is not OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
t.deepEqual(response.body, { statusCode: 404,
error: 'Not Found',
message: `Media with name 'test_url:stream_3:41' was not found: Unable to find requested media elements.` }, // eslint-disable-line
'error message structure as expected.');
t.comment('### Retrieve one packet from a range');
test('GET a stream', async t => {
try {
t.ok(await flushdb(), 'database flushed OK.');
t.comment('### Retrieve a stream');
t.deepEqual(await redisio.storeFormat(testUtil.fmt), ['OK','OK','OK'],
'test format stored.');
let response = await request(server).get('/beams/test_url/stream_1').expect(200);
t.ok(response.ok, 'response claims OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
let fmt = beamcoder.format();
let str = fmt.newStream(response.body);
str.__index(response.body.index);
t.deepEqual(str.toJSON(), testUtil.stream1, 'roundtrip equal.');
t.comment('### Retrive a stream that does not exist.');
response = await request(server).get('/beams/test_url/stream_42').expect(404);
t.notOk(response.ok, 'response is not OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
t.deepEqual(response.body, { statusCode: 404,
error: 'Not Found',
message: `Stream with name 'test_url:stream_42' was not found: Unable to retrieve a stream with key 'beamengine:test_url:stream_42'.` }, // eslint-disable-line
'error message structure as expected.');
t.comment('### Retrieve a stream by type - video');
response = await request(server).get('/beams/test_url/video').expect(200);
t.ok(response.ok, 'response claims OK.');
test('GET a format', async t => {
try {
t.ok(await flushdb(), 'database flushed OK.');
t.comment('### Retrieve a format');
t.deepEqual(await redisio.storeFormat(testUtil.fmt), ['OK','OK','OK'],
'test format stored.');
let response = await request(server).get('/beams/test_url').expect(200);
t.ok(response.ok, 'response claims OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
let fmt = beamcoder.format(response.body);
t.deepEqual(stripNewStream(fmt), stripNewStream(testUtil.fmt), 'roundtrip equal.');
t.comment('### Retrive a format that does not exist.');
response = await request(server).get('/beams/wibble').expect(404);
t.notOk(response.ok, 'response is not OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
t.deepEqual(response.body, { statusCode: 404,
error: 'Not Found',
message: `Format with name 'wibble' was not found: Unable to retrieve a format with key 'beamengine:wibble'.` }, // eslint-disable-line
'error message structure as expected.');
} catch (err) {
t.fail(err);
}
t.end();
});
response = await request(server).get('/beams/test_url/stream_3/41')
.expect(404);
t.notOk(response.ok, 'response is not OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
t.deepEqual(response.body, { statusCode: 404,
error: 'Not Found',
message: `Media with name 'test_url:stream_3:41' was not found: Unable to find requested media elements.` }, // eslint-disable-line
'error message structure as expected.');
t.comment('### Retrieve one packet from a range');
response = await request(server).get('/beams/test_url/stream_3/40-45')
.expect(200);
t.ok(response.ok, 'response claims OK.');
t.equal(response.type, 'application/json', 'response is JSON.');
t.ok(Array.isArray(response.body), 'result is an array.');
pkt = beamcoder.packet(response.body[0]);
t.ok(pkt, 'roundtrip packet is truthy.');
t.deepEqual(pkt.toJSON(), testUtil.pkt.toJSON(),
'retrieved packet as expected.');
t.equal(pkt.size, 16383, 'has expected size parameter.');
t.comment('### Store ten packets');
t.ok(await flushdb(), 'database flushed OK.');
for ( let x = 0 ; x < 10 ; x++) {
let tpkt = testUtil.pkt;
tpkt.pts = (x * 10) - 40;
t.deepEqual(await redisio.storeMedia('test_url', tpkt), ['OK-crt','OK-crt'],
`test packet ${tpkt.pts} stored OK.`);
}
t.comment('### Retrieve three by range');
// const globalWorkItems = Uint32Array.from([ width, height ]);
const testImageProgram = await context.createProgram(testImage, {
globalWorkItems: Uint32Array.from([ width, height ])
});
const numBytesV210 = v210_io.getPitchBytes(width) * height;
const v210Src = await context.createBuffer(numBytesV210, 'readonly', 'coarse');
const numBytesRGBA = width * height * 4 * 4;
const rgbaDst = await context.createBuffer(numBytesRGBA, 'readwrite', 'coarse');
const imageDst = await context.createBuffer(numBytesRGBA, 'readwrite', 'coarse');
const v210Dst = await context.createBuffer(numBytesV210, 'writeonly', 'coarse');
let dm = await beamy.demuxer('file:../media/dpp/AS11_DPP_HD_EXAMPLE_1.mxf')
console.log(dm)
let dec = await beamy.decoder({ demuxer: dm, stream_index: 0 })
let enc = beamy.encoder({ name: 'v210', codec_id: 127, width: 1920, height: 1080, pix_fmt: 'yuv422p10le', bits_per_raw_sample: 20, time_base: [ 1, 25 ] })
console.log(enc)
let playback = await macadam.playback({
deviceIndex: 0, // Index relative to the 'macadam.getDeviceInfo()' array
displayMode: macadam.bmdModeHD1080i50,
pixelFormat: macadam.bmdFormat10BitYUV
})
let result = []
let counter = 0
async function read() {
let p = await dm.read()