Skip to content

Commit

Permalink
Merge pull request #561 from bitmovin/PRN-147/expose-tweaksConfig-for…
Browse files Browse the repository at this point in the history
…ceReuseVideoCodecReasons

Expose `TweaksConfig.forceReuseVideoCodecReasons` from Android
  • Loading branch information
strangesource authored Nov 15, 2024
2 parents 1c20a68 + 5b860f6 commit bfde320
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [0.32.0] - 2024-11-14

### Added

- 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

- Update Bitmovin's native Android SDK version to `3.92.0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -167,6 +168,16 @@ fun ReadableMap.toStyleConfig(): StyleConfig = StyleConfig().apply {
withString("scalingMode") { scalingMode = ScalingMode.valueOf(it) }
}

/**
* Converts any JS string into an `ForceReuseVideoCodecReason` enum value.
*/
private fun String.toForceReuseVideoCodecReason(): ForceReuseVideoCodecReason? = when (this) {
"ColorInfoMismatch" -> ForceReuseVideoCodecReason.ColorInfoMismatch
"MaxInputSizeExceeded" -> ForceReuseVideoCodecReason.MaxInputSizeExceeded
"MaxResolutionExceeded" -> ForceReuseVideoCodecReason.MaxResolutionExceeded
else -> null
}

/**
* Converts any JS object into a `TweaksConfig` object.
*/
Expand All @@ -189,6 +200,12 @@ fun ReadableMap.toTweaksConfig(): TweaksConfig = TweaksConfig().apply {
withBoolean("useDrmSessionForClearSources") { useDrmSessionForClearSources = it }
withBoolean("useFiletypeExtractorFallbackForHls") { useFiletypeExtractorFallbackForHls = it }
withBoolean("preferSoftwareDecodingForAds") { preferSoftwareDecodingForAds = it }
withStringArray("forceReuseVideoCodecReasons") {
forceReuseVideoCodecReasons = it
.filterNotNull()
.mapNotNull(String::toForceReuseVideoCodecReason)
.toSet()
}
}

/**
Expand Down
39 changes: 39 additions & 0 deletions src/tweaksConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/**
* 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 {
/**
* 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
Expand Down Expand Up @@ -170,4 +194,19 @@ 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.
*
* 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
*
* @platform Android
*/
forceReuseVideoCodecReasons?: Array<ForceReuseVideoCodecReason>;
}

0 comments on commit bfde320

Please sign in to comment.