Skip to content

Commit

Permalink
Commit initial attempt at flushing frames
Browse files Browse the repository at this point in the history
  • Loading branch information
friendlymatthew committed Oct 21, 2024
1 parent 4b9e9b9 commit f7d0048
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ initializeDecoder();
let highestSpatialLayer = 3,
highestTemporalLayer = 3;

let newSpatialLayer = highestSpatialLayer;

let firstChunkTimestamp = null;
let firstChunkSecondaryTimestamp = null;

Expand All @@ -84,7 +86,6 @@ async function handleTransform(operation, readable, writable) {
const delta = timestamp - firstChunkTimestamp;
const size = data.byteLength;

console.log(`layered`, {timestamp, spatialIndex, temporalIndex, size, type});

postMessage({
operation: 'encoded-frame',
Expand Down Expand Up @@ -143,16 +144,26 @@ async function handleTransform(operation, readable, writable) {
const {temporalIndex, spatialIndex, width, height} = encodedFrame.getMetadata();
const {timestamp, data, type} = encodedFrame;

if (temporalIndex < highestTemporalLayer && spatialIndex < highestSpatialLayer) {
// console.log("Decoding encodedChunk: ", {timestamp, temporalIndex, spatialIndex})
if (newSpatialLayer !== highestSpatialLayer) {
console.log("mismatch");

if (type === 'key') {
await videoDecoder.flush();
highestSpatialLayer = newSpatialLayer;
}
}


const chunk = new EncodedVideoChunk({
timestamp,
data,
type,
});
if (spatialIndex < highestSpatialLayer) {
if (temporalIndex < highestTemporalLayer) {
const chunk = new EncodedVideoChunk({
timestamp,
data,
type,
});

await videoDecoder.decode(chunk);
await videoDecoder.decode(chunk);
}
}

controller.enqueue(encodedFrame);
Expand Down Expand Up @@ -201,10 +212,9 @@ onmessage = async ({data}) => {
if (temporal) {
highestTemporalLayer = layer;
} else {
highestSpatialLayer = layer;
newSpatialLayer = layer;
}

// console.log("LAYER CHANGE!", data);
}
};

Expand Down

0 comments on commit f7d0048

Please sign in to comment.