Skip to content

Commit 57f734d

Browse files
committed
fix shared mode not working when primary is under heavy motion
1 parent 7bd55b4 commit 57f734d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

addons/gst-web-core/selkies-core.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ let sharedProbingTimeoutId = null;
8383
let sharedProbingAttempts = 0;
8484
const MAX_SHARED_PROBING_ATTEMPTS = 3; // e.g., initial + 2 retries
8585
const isSharedMode = detectedSharedModeType !== null;
86+
let sharedClientHasReceivedKeyframe = false;
8687

8788
if (isSharedMode) {
8889
console.log(`Client is running in ${detectedSharedModeType} mode.`);
@@ -2587,7 +2588,6 @@ function handleDecodedFrame(frame) { // frame.codedWidth/Height are physical pix
25872588
sharedClientState = 'ready';
25882589
console.log(`Shared mode: Client is now ready to process video of type '${identifiedEncoderModeForShared}'.`);
25892590
}
2590-
return;
25912591
} else if (dataTypeByte !== 1) { // Ignore audio packets during identification
25922592
console.warn(`Shared mode (awaiting_identification): Received non-identifying binary packet type 0x${dataTypeByte.toString(16)}. Still waiting for a video packet.`);
25932593
return;
@@ -2628,6 +2628,15 @@ function handleDecodedFrame(frame) { // frame.codedWidth/Height are physical pix
26282628
(!isSharedMode && isVideoPipelineActive && currentEncoderMode !== 'jpeg' && currentEncoderMode !== 'x264enc' && currentEncoderMode !== 'x264enc-striped');
26292629

26302630
if (canProcessFullH264) {
2631+
if (isSharedMode && !sharedClientHasReceivedKeyframe) {
2632+
if (frameTypeFlag === 1) {
2633+
console.log("Shared mode: First keyframe received. Opening the gate for video decoding.");
2634+
sharedClientHasReceivedKeyframe = true;
2635+
} else {
2636+
console.log("Shared mode: Gate is closed. Discarding non-keyframe packet.");
2637+
return;
2638+
}
2639+
}
26312640
if (decoder && decoder.state === 'configured') {
26322641
const chunk = new EncodedVideoChunk({
26332642
type: frameTypeFlag === 1 ? 'key' : 'delta',
@@ -2731,6 +2740,15 @@ function handleDecodedFrame(frame) { // frame.codedWidth/Height are physical pix
27312740
(!isSharedMode && isVideoPipelineActive && (currentEncoderMode === 'x264enc' || currentEncoderMode === 'x264enc-striped'));
27322741

27332742
if (canProcessVncStripe) {
2743+
if (isSharedMode && !sharedClientHasReceivedKeyframe) {
2744+
if (video_frame_type_byte === 0x01) {
2745+
console.log("Shared mode: First keyframe received for striped video. Opening the gate.");
2746+
sharedClientHasReceivedKeyframe = true;
2747+
} else {
2748+
console.log("Shared mode: Gate is closed. Discarding non-keyframe striped packet.");
2749+
return;
2750+
}
2751+
}
27342752
if (h264Payload.byteLength === 0) return;
27352753

27362754
let decoderInfo = vncStripeDecoders[vncStripeYStart];
@@ -3660,6 +3678,11 @@ function uploadFileObject(file, pathToSend) {
36603678
function performServerInitiatedVideoReset(reason = "unknown") {
36613679
console.log(`Performing server-initiated video reset. Reason: ${reason}. Current lastReceivedVideoFrameId before reset: ${lastReceivedVideoFrameId}`);
36623680

3681+
if (isSharedMode) {
3682+
sharedClientHasReceivedKeyframe = false;
3683+
console.log(" Shared mode reset: Gate closed. Waiting for a new keyframe.");
3684+
}
3685+
36633686
lastReceivedVideoFrameId = -1;
36643687
console.log(` Reset lastReceivedVideoFrameId to ${lastReceivedVideoFrameId}.`);
36653688

0 commit comments

Comments
 (0)