From 021529b2ecea940b07fda18cad42f3516e5c8cad Mon Sep 17 00:00:00 2001 From: saravanan Date: Thu, 14 Nov 2024 15:39:39 +0800 Subject: [PATCH 1/5] exposed TweaksConfig.forceReuseVideoCodecReasons --- CHANGELOG.md | 4 +++ .../reactnative/converter/JsonConverter.kt | 21 ++++++++++++++ src/tweaksConfig.ts | 28 +++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4346b632..bdc9f713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- exposed `TweaksConfig.forceReuseVideoCodecReasons` + ### Fixed - Error where setting `PlaybackConfig.isAutoplayEnabled = true` causes the player view creation to fail on Android diff --git a/android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt b/android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt index 78438e5c..931e4d9a 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt @@ -6,6 +6,7 @@ import com.bitmovin.analytics.api.CustomData import com.bitmovin.analytics.api.DefaultMetadata import com.bitmovin.analytics.api.SourceMetadata import com.bitmovin.player.api.DeviceDescription.DeviceName +import com.bitmovin.player.api.ForceReuseVideoCodecReason import com.bitmovin.player.api.PlaybackConfig import com.bitmovin.player.api.PlayerConfig import com.bitmovin.player.api.TweaksConfig @@ -167,6 +168,16 @@ fun ReadableMap.toStyleConfig(): StyleConfig = StyleConfig().apply { withString("scalingMode") { scalingMode = ScalingMode.valueOf(it) } } +/** + * Converts any JS string into an `AdSourceType` enum value. + */ +private fun String.forceReuseVideoCodecReason(): ForceReuseVideoCodecReason? = when (this) { + "ColorInfoMismatch" -> ForceReuseVideoCodecReason.ColorInfoMismatch + "MaxInputSizeExceeded" -> ForceReuseVideoCodecReason.MaxInputSizeExceeded + "MaxResolutionExceeded" -> ForceReuseVideoCodecReason.MaxResolutionExceeded + else -> null +} + /** * Converts any JS object into a `TweaksConfig` object. */ @@ -189,6 +200,16 @@ fun ReadableMap.toTweaksConfig(): TweaksConfig = TweaksConfig().apply { withBoolean("useDrmSessionForClearSources") { useDrmSessionForClearSources = it } withBoolean("useFiletypeExtractorFallbackForHls") { useFiletypeExtractorFallbackForHls = it } withBoolean("preferSoftwareDecodingForAds") { preferSoftwareDecodingForAds = it } + withStringArray("forceReuseVideoCodecReasons") { + val mutableSet = mutableSetOf() + for (item in it) { + val reason = item?.forceReuseVideoCodecReason() + if (reason != null) { + mutableSet.add(reason) + } + } + forceReuseVideoCodecReasons = mutableSet + } } /** diff --git a/src/tweaksConfig.ts b/src/tweaksConfig.ts index 2269baf7..c0220854 100644 --- a/src/tweaksConfig.ts +++ b/src/tweaksConfig.ts @@ -1,3 +1,21 @@ +/** + * The different reasons when the video codec should be reused. + */ +export enum ForceReuseVideoCodecReason { + /** + * The new video quality color information is not compatible. + */ + ColorInfoMismatch = 'ColorInfoMismatch', + /** + * The new video quality exceed the decoder's configured maximum sample size. + */ + MaxInputSizeExceeded = 'MaxInputSizeExceeded', + /** + * The new video quality exceed the decoder's configured maximum resolution. + */ + MaxResolutionExceeded = 'MaxResolutionExceeded', +} + /** * This configuration is used as an incubator for experimental features. Tweaks are not officially * supported and are not guaranteed to be stable, i.e. their naming, functionality and API can @@ -170,4 +188,14 @@ export interface TweaksConfig { * @platform iOS */ updatesNowPlayingInfoCenter?: boolean; + + /** + * When switching between video formats (eg: adapting between video qualities) the codec might be recreated due to several reasons. + * This behaviour can cause brief black screens when switching between video qualities as codec recreation can be slow. + * + * Default is `[]` i.e not set + * + * @platform Android + */ + forceReuseVideoCodecReasons?: Array; } From cdf799debdf74e1c9eddec71bf290e5435456358 Mon Sep 17 00:00:00 2001 From: saravanan Date: Thu, 14 Nov 2024 15:42:26 +0800 Subject: [PATCH 2/5] updated default value --- src/tweaksConfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tweaksConfig.ts b/src/tweaksConfig.ts index c0220854..59316e56 100644 --- a/src/tweaksConfig.ts +++ b/src/tweaksConfig.ts @@ -193,7 +193,7 @@ export interface TweaksConfig { * When switching between video formats (eg: adapting between video qualities) the codec might be recreated due to several reasons. * This behaviour can cause brief black screens when switching between video qualities as codec recreation can be slow. * - * Default is `[]` i.e not set + * Default is `null` i.e not set * * @platform Android */ From 6c0fe0be72537d83455ef8ef5378a17d315bcd97 Mon Sep 17 00:00:00 2001 From: Lukas Knoch-Girstmair Date: Fri, 15 Nov 2024 12:51:25 +0100 Subject: [PATCH 3/5] To idiomatic Kotlin --- .../reactnative/converter/JsonConverter.kt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt b/android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt index 931e4d9a..45edf392 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt @@ -169,9 +169,9 @@ fun ReadableMap.toStyleConfig(): StyleConfig = StyleConfig().apply { } /** - * Converts any JS string into an `AdSourceType` enum value. + * Converts any JS string into an `ForceReuseVideoCodecReason` enum value. */ -private fun String.forceReuseVideoCodecReason(): ForceReuseVideoCodecReason? = when (this) { +private fun String.toForceReuseVideoCodecReason(): ForceReuseVideoCodecReason? = when (this) { "ColorInfoMismatch" -> ForceReuseVideoCodecReason.ColorInfoMismatch "MaxInputSizeExceeded" -> ForceReuseVideoCodecReason.MaxInputSizeExceeded "MaxResolutionExceeded" -> ForceReuseVideoCodecReason.MaxResolutionExceeded @@ -201,14 +201,10 @@ fun ReadableMap.toTweaksConfig(): TweaksConfig = TweaksConfig().apply { withBoolean("useFiletypeExtractorFallbackForHls") { useFiletypeExtractorFallbackForHls = it } withBoolean("preferSoftwareDecodingForAds") { preferSoftwareDecodingForAds = it } withStringArray("forceReuseVideoCodecReasons") { - val mutableSet = mutableSetOf() - for (item in it) { - val reason = item?.forceReuseVideoCodecReason() - if (reason != null) { - mutableSet.add(reason) - } - } - forceReuseVideoCodecReasons = mutableSet + forceReuseVideoCodecReasons = it + .filterNotNull() + .mapNotNull(String::toForceReuseVideoCodecReason) + .toSet() } } From 0ec9d9803d26f4617e9aa96bcc608edf4864c50c Mon Sep 17 00:00:00 2001 From: Lukas Knoch-Girstmair Date: Fri, 15 Nov 2024 12:57:51 +0100 Subject: [PATCH 4/5] Use Native android documentation --- src/tweaksConfig.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/tweaksConfig.ts b/src/tweaksConfig.ts index 59316e56..90d0654c 100644 --- a/src/tweaksConfig.ts +++ b/src/tweaksConfig.ts @@ -1,5 +1,11 @@ /** - * The different reasons when the video codec should be reused. + * When switching the video quality, the video decoder's configuration might change + * as the player can't always know if the codec supports such configuration change, it destroys and recreates it. + * This behaviour can cause brief black screens when switching between video qualities as codec recreation can be slow. + * + * If a codec is know to support a given configuration change without issues, + * the configuration can be added to the `TweaksConfig.forceReuseVideoCodecReasons` + * to always reuse the video codec and avoid the black screen. */ export enum ForceReuseVideoCodecReason { /** @@ -190,8 +196,13 @@ export interface TweaksConfig { updatesNowPlayingInfoCenter?: boolean; /** - * When switching between video formats (eg: adapting between video qualities) the codec might be recreated due to several reasons. - * This behaviour can cause brief black screens when switching between video qualities as codec recreation can be slow. + * When switching between video formats (eg: adapting between video qualities) + * the codec might be recreated due to several reasons. + * This behaviour can cause brief black screens when switching between video qualities as codec recreation can be + * slow. + * + * If a device is know to support video format changes and keep the current decoder without issues, + * this set can be filled with multiple `ForceReuseVideoCodecReason` and avoid the black screen. * * Default is `null` i.e not set * From 5b860f6b2d089884f126a89577c9f7cf19a622eb Mon Sep 17 00:00:00 2001 From: Lukas Knoch-Girstmair Date: Fri, 15 Nov 2024 15:03:22 +0100 Subject: [PATCH 5/5] Update CHANGELOG.md Co-authored-by: Matthias Tamegger <5555332+matamegger@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05fdf875..8c074951 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Added -- exposed `TweaksConfig.forceReuseVideoCodecReasons` +- Android: `TweaksConfig.forceReuseVideoCodecReasons` that allows to force the reuse of the video codec despite a configuration change. This flag should be set only, if it is known that the codec can handle the given configuration change ### Changed