Merge pull request #3728 from Bnyro/master

Exclude HDR streams when not supported by device
This commit is contained in:
Bnyro 2023-05-08 17:04:40 +02:00 committed by GitHub
commit 0d67c435f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 16 deletions

View File

@ -24,7 +24,7 @@ object DashHelper {
val formats: MutableList<PipedStream> = mutableListOf()
)
fun createManifest(streams: Streams): String {
fun createManifest(streams: Streams, supportsHdr: Boolean): String {
val builder: DocumentBuilder = builderFactory.newDocumentBuilder()
val doc = builder.newDocument()
@ -40,17 +40,18 @@ object DashHelper {
val adapSetInfos = ArrayList<AdapSetInfo>()
val enabledVideoCodecs = PlayerHelper.enabledVideoCodecs
for (stream in streams.videoStreams
for (
stream in streams.videoStreams
// used to avoid including LBRY HLS inside the streams in the manifest
.filter { !it.format.orEmpty().contains("HLS") }
// filter the codecs according to the user's preferences
.filter {
if (enabledVideoCodecs != "all") {
it.codec?.lowercase()?.startsWith(enabledVideoCodecs) ?: true
} else {
true
}
}) {
enabledVideoCodecs == "all" || it.codec.orEmpty().lowercase().startsWith(
enabledVideoCodecs
)
}
.filter { supportsHdr || !it.quality.orEmpty().uppercase().contains("HDR") }
) {
// ignore dual format streams
if (!stream.videoOnly!!) {
continue

View File

@ -0,0 +1,22 @@
package com.github.libretube.helpers
import android.content.Context
import android.hardware.display.DisplayManager
import android.os.Build
import android.view.Display
object DisplayHelper {
/**
* Detect whether the device supports HDR as the ExoPlayer doesn't handle it properly
* Returns false on and below SDK 24
*/
fun supportsHdr(context: Context): Boolean {
val displayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
val display = displayManager.getDisplay(Display.DEFAULT_DISPLAY)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
display.hdrCapabilities.supportedHdrTypes.isNotEmpty()
} else {
false
}
}
}

View File

@ -64,15 +64,9 @@ import com.github.libretube.extensions.hideKeyboard
import com.github.libretube.extensions.toID
import com.github.libretube.extensions.toastFromMainDispatcher
import com.github.libretube.extensions.updateParameters
import com.github.libretube.helpers.BackgroundHelper
import com.github.libretube.helpers.DashHelper
import com.github.libretube.helpers.ImageHelper
import com.github.libretube.helpers.NavigationHelper
import com.github.libretube.helpers.PlayerHelper
import com.github.libretube.helpers.*
import com.github.libretube.helpers.PlayerHelper.checkForSegments
import com.github.libretube.helpers.PlayerHelper.loadPlaybackParams
import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.helpers.ProxyHelper
import com.github.libretube.obj.PlayerNotificationData
import com.github.libretube.obj.ShareData
import com.github.libretube.obj.VideoResolution
@ -1327,7 +1321,10 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
val uri = streams.dash?.let { ProxyHelper.unwrapIfEnabled(it) }?.toUri().takeIf {
streams.livestream || streams.videoStreams.isEmpty()
} ?: let {
val manifest = DashHelper.createManifest(streams)
val manifest = DashHelper.createManifest(
streams,
DisplayHelper.supportsHdr(requireContext())
)
// encode to base64
val encoded = Base64.encodeToString(manifest.toByteArray(), Base64.DEFAULT)