From a473d529a8816769361c80546529cdd18d55f6ab Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Thu, 19 Sep 2024 16:48:59 +0530 Subject: [PATCH 1/6] fix: video not recovered after degradation --- .../src/media/tracks/HMSRemoteVideoTrack.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts index 841f4fc378..6ee0e10910 100644 --- a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts @@ -148,10 +148,7 @@ export class HMSRemoteVideoTrack extends HMSVideoTrack { * @returns {boolean} isDegraded - returns true if degraded * */ setLayerFromServer(layerUpdate: VideoTrackLayerUpdate) { - this._degraded = - this.enabled && - (layerUpdate.publisher_degraded || layerUpdate.subscriber_degraded) && - layerUpdate.current_layer === HMSSimulcastLayer.NONE; + this._degraded = this.getDegradationValue(layerUpdate); this._degradedAt = this._degraded ? new Date() : this._degradedAt; const currentLayer = layerUpdate.current_layer; HMSLogger.d( @@ -165,12 +162,30 @@ export class HMSRemoteVideoTrack extends HMSVideoTrack { pub_degraded=${layerUpdate.publisher_degraded} isDegraded=${this._degraded}`, ); + const stream = this.stream as HMSRemoteStream; + // There are cases where none is requested just after this + if ( + stream.getVideoLayer() === HMSSimulcastLayer.NONE && + this.hasSinks() && + currentLayer !== HMSSimulcastLayer.NONE + ) { + this.updateLayer('setLayerFromServer'); + } // No need to send preferLayer update, as server has done it already - (this.stream as HMSRemoteStream).setVideoLayerLocally(currentLayer, this.logIdentifier, 'setLayerFromServer'); + stream.setVideoLayerLocally(currentLayer, this.logIdentifier, 'setLayerFromServer'); + this.pushInHistory(`sfuLayerUpdate-${currentLayer}`); return this._degraded; } + private getDegradationValue(layerUpdate: VideoTrackLayerUpdate) { + return ( + this.enabled && + (layerUpdate.publisher_degraded || layerUpdate.subscriber_degraded) && + layerUpdate.current_layer === HMSSimulcastLayer.NONE + ); + } + private async updateLayer(source: string) { const newLayer = (this.degraded || !this.enabled || !this.hasSinks()) && !this.disableNoneLayerRequest From e83f9b0d2c58e864163931f70a40a28bef82fdf2 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Thu, 19 Sep 2024 17:27:19 +0530 Subject: [PATCH 2/6] revert: change' --- .../src/media/tracks/HMSRemoteVideoTrack.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts index 6ee0e10910..c1fd43a7d4 100644 --- a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts @@ -163,17 +163,8 @@ export class HMSRemoteVideoTrack extends HMSVideoTrack { isDegraded=${this._degraded}`, ); const stream = this.stream as HMSRemoteStream; - // There are cases where none is requested just after this - if ( - stream.getVideoLayer() === HMSSimulcastLayer.NONE && - this.hasSinks() && - currentLayer !== HMSSimulcastLayer.NONE - ) { - this.updateLayer('setLayerFromServer'); - } // No need to send preferLayer update, as server has done it already stream.setVideoLayerLocally(currentLayer, this.logIdentifier, 'setLayerFromServer'); - this.pushInHistory(`sfuLayerUpdate-${currentLayer}`); return this._degraded; } From a1a7b0067007315cd34ab2d7c77ebc236cf3c187 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 23 Sep 2024 12:46:14 +0530 Subject: [PATCH 3/6] fix: don't send none when degraded --- .../hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts index c1fd43a7d4..c316e93b83 100644 --- a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts @@ -179,7 +179,7 @@ export class HMSRemoteVideoTrack extends HMSVideoTrack { private async updateLayer(source: string) { const newLayer = - (this.degraded || !this.enabled || !this.hasSinks()) && !this.disableNoneLayerRequest + (!this.enabled || !this.hasSinks()) && !this.disableNoneLayerRequest ? HMSSimulcastLayer.NONE : this.preferredLayer; if (!this.shouldSendVideoLayer(newLayer, source)) { From a8a8fd57130893b91a655f44a0800a5dcc461547 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 23 Sep 2024 14:59:22 +0530 Subject: [PATCH 4/6] fix: simplify condition --- .../src/media/tracks/HMSRemoteVideoTrack.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts index c316e93b83..76ba6dd991 100644 --- a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts @@ -178,10 +178,13 @@ export class HMSRemoteVideoTrack extends HMSVideoTrack { } private async updateLayer(source: string) { - const newLayer = - (!this.enabled || !this.hasSinks()) && !this.disableNoneLayerRequest - ? HMSSimulcastLayer.NONE - : this.preferredLayer; + let newLayer: HMSSimulcastLayer = this.preferredLayer; + if (this.enabled || this.hasSinks()) { + newLayer = this.preferredLayer; + // send none only when the flag is not set + } else if (!this.disableNoneLayerRequest) { + newLayer = HMSSimulcastLayer.NONE; + } if (!this.shouldSendVideoLayer(newLayer, source)) { return; } From 3e757ea013c26a9816ef9d68dbe27ff3b22d34db Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 23 Sep 2024 15:00:20 +0530 Subject: [PATCH 5/6] fix: use as inline --- .../hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts index 76ba6dd991..d564bfe4ac 100644 --- a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts @@ -162,9 +162,8 @@ export class HMSRemoteVideoTrack extends HMSVideoTrack { pub_degraded=${layerUpdate.publisher_degraded} isDegraded=${this._degraded}`, ); - const stream = this.stream as HMSRemoteStream; // No need to send preferLayer update, as server has done it already - stream.setVideoLayerLocally(currentLayer, this.logIdentifier, 'setLayerFromServer'); + (this.stream as HMSRemoteStream).setVideoLayerLocally(currentLayer, this.logIdentifier, 'setLayerFromServer'); this.pushInHistory(`sfuLayerUpdate-${currentLayer}`); return this._degraded; } From d29558d4799a887937864469e1eda0d807dd5b33 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 23 Sep 2024 15:08:57 +0530 Subject: [PATCH 6/6] fix: condition --- .../hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts index d564bfe4ac..abff98bb41 100644 --- a/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts @@ -178,7 +178,7 @@ export class HMSRemoteVideoTrack extends HMSVideoTrack { private async updateLayer(source: string) { let newLayer: HMSSimulcastLayer = this.preferredLayer; - if (this.enabled || this.hasSinks()) { + if (this.enabled && this.hasSinks()) { newLayer = this.preferredLayer; // send none only when the flag is not set } else if (!this.disableNoneLayerRequest) {