mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
Merge pull request #3728 from Bnyro/master
Exclude HDR streams when not supported by device
This commit is contained in:
commit
0d67c435f5
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user