mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
WIP 2
This commit is contained in:
+36
-12
@@ -193,6 +193,11 @@ export class PacketCursor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const timestamp of timestamps) {
|
||||||
|
const thumbnail = await cursor.seekTo(timestamp);
|
||||||
|
console.log(thumbnail);
|
||||||
|
}
|
||||||
|
|
||||||
export class VideoSampleCursor2 {
|
export class VideoSampleCursor2 {
|
||||||
track: InputVideoTrack;
|
track: InputVideoTrack;
|
||||||
initialized = false;
|
initialized = false;
|
||||||
@@ -212,6 +217,7 @@ export class VideoSampleCursor2 {
|
|||||||
|
|
||||||
decodedTimestamps: number[] = [];
|
decodedTimestamps: number[] = [];
|
||||||
maxDecodedSequenceNumber = -1;
|
maxDecodedSequenceNumber = -1;
|
||||||
|
pumpTargetSequenceNumber = -1;
|
||||||
pumpMutex = new AsyncMutex2();
|
pumpMutex = new AsyncMutex2();
|
||||||
|
|
||||||
private constructor(track: InputVideoTrack, decoder: VideoDecoderWrapper) {
|
private constructor(track: InputVideoTrack, decoder: VideoDecoderWrapper) {
|
||||||
@@ -238,23 +244,29 @@ export class VideoSampleCursor2 {
|
|||||||
cursor.decodedTimestamps.shift();
|
cursor.decodedTimestamps.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor.stopPump) {
|
console.log('revc', sample.timestamp, cursor.pendingRequests.length);
|
||||||
sample.close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('revc', sample.timestamp);
|
|
||||||
|
|
||||||
if (cursor.pendingRequests.length === 0) {
|
if (cursor.pendingRequests.length === 0) {
|
||||||
cursor.sampleQueue.push(sample);
|
if (cursor.stopPump) {
|
||||||
|
sample.close();
|
||||||
|
} else {
|
||||||
|
cursor.sampleQueue.push(sample);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
let given = false;
|
||||||
|
|
||||||
for (let i = 0; i < cursor.pendingRequests.length; i++) {
|
for (let i = 0; i < cursor.pendingRequests.length; i++) {
|
||||||
const request = cursor.pendingRequests[i]!;
|
const request = cursor.pendingRequests[i]!;
|
||||||
if (request.timestamp <= sample.timestamp) {
|
if (request.timestamp <= sample.timestamp) {
|
||||||
request.resolve(sample.clone());
|
request.resolve(given ? sample.clone() : sample);
|
||||||
cursor.pendingRequests.splice(i--, 1);
|
cursor.pendingRequests.splice(i--, 1);
|
||||||
|
given = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!given) {
|
||||||
|
sample.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cursor.current?.close();
|
// cursor.current?.close();
|
||||||
@@ -296,6 +308,7 @@ export class VideoSampleCursor2 {
|
|||||||
using _ = this.pumpMutex.lock();
|
using _ = this.pumpMutex.lock();
|
||||||
|
|
||||||
const targetPacket = await this.packetCursor.peekAt(timestamp);
|
const targetPacket = await this.packetCursor.peekAt(timestamp);
|
||||||
|
console.log('target');
|
||||||
if (!targetPacket) {
|
if (!targetPacket) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -351,6 +364,7 @@ export class VideoSampleCursor2 {
|
|||||||
this.sampleQueue.length = 0;
|
this.sampleQueue.length = 0;
|
||||||
this.maxDecodedSequenceNumber = -1;
|
this.maxDecodedSequenceNumber = -1;
|
||||||
this.decodedTimestamps.length = 0;
|
this.decodedTimestamps.length = 0;
|
||||||
|
this.pumpTargetSequenceNumber = -1;
|
||||||
this.stopPump = false;
|
this.stopPump = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,6 +378,10 @@ export class VideoSampleCursor2 {
|
|||||||
timestamp: targetPacket.timestamp,
|
timestamp: targetPacket.timestamp,
|
||||||
resolve: request.resolve,
|
resolve: request.resolve,
|
||||||
});
|
});
|
||||||
|
this.pumpTargetSequenceNumber = Math.max(this.pumpTargetSequenceNumber, targetPacket.sequenceNumber);
|
||||||
|
|
||||||
|
console.log('requesting', targetPacket.timestamp);
|
||||||
|
console.log('Done', this.pumpTargetSequenceNumber);
|
||||||
|
|
||||||
return request.promise;
|
return request.promise;
|
||||||
}
|
}
|
||||||
@@ -404,13 +422,18 @@ export class VideoSampleCursor2 {
|
|||||||
|
|
||||||
this.pumpRunning = true;
|
this.pumpRunning = true;
|
||||||
|
|
||||||
while (this.packetCursor.current && !this.stopPump) {
|
while (
|
||||||
|
this.packetCursor.current
|
||||||
|
&& (!this.stopPump || this.packetCursor.current.sequenceNumber <= this.pumpTargetSequenceNumber)
|
||||||
|
) {
|
||||||
const maxQueueSize = 8 ?? computeMaxQueueSize(this.sampleQueue.length); // temp
|
const maxQueueSize = 8 ?? computeMaxQueueSize(this.sampleQueue.length); // temp
|
||||||
if (this.sampleQueue.length + this.decoder.getDecodeQueueSize() > maxQueueSize) {
|
if (!this.stopPump && this.sampleQueue.length + this.decoder.getDecodeQueueSize() > maxQueueSize) {
|
||||||
await this.queueDequeue.promise;
|
await this.queueDequeue.promise;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('DECODING', this.packetCursor.current.timestamp);
|
||||||
|
|
||||||
insertSorted(this.decodedTimestamps, this.packetCursor.current.timestamp, x => x);
|
insertSorted(this.decodedTimestamps, this.packetCursor.current.timestamp, x => x);
|
||||||
this.maxDecodedSequenceNumber = this.packetCursor.current.sequenceNumber;
|
this.maxDecodedSequenceNumber = this.packetCursor.current.sequenceNumber;
|
||||||
this.decoder.decode(this.packetCursor.current);
|
this.decoder.decode(this.packetCursor.current);
|
||||||
@@ -423,10 +446,11 @@ export class VideoSampleCursor2 {
|
|||||||
this.pumpStopped.resolve();
|
this.pumpStopped.resolve();
|
||||||
this.pumpStopped = promiseWithResolvers();
|
this.pumpStopped = promiseWithResolvers();
|
||||||
|
|
||||||
this.pumpRunning = false;
|
|
||||||
|
|
||||||
this.pendingRequests.forEach(x => x.resolve(null));
|
this.pendingRequests.forEach(x => x.resolve(null));
|
||||||
this.pendingRequests.length = 0;
|
this.pendingRequests.length = 0;
|
||||||
|
|
||||||
|
this.pumpRunning = false;
|
||||||
|
console.log('pump stopped/ended');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user