A device with no hardware HEVC decoder could still be handed an HEVC transcode: the device profile advertised a fixed codec list that assumed every device decodes everything. Prepending AV1 to reach the AV1 encoders issue #2131 asks for would have made that worse - an Apple TV 4K and every iPhone before the A17 Pro have no AV1 decoder at all. Probe the platform instead. Android enumerates MediaCodecList for a hardware decoder and iOS/tvOS ask VideoToolbox, both feeding one latched VideoDecodeCapabilities that the device profile reads when it builds its codec lists. Desktop deliberately answers nothing: a pre-Kaby-Lake Mac has no hardware HEVC decoder and an M1 no AV1 one, yet both software-decode in real time, so narrowing there would force transcodes for nothing. An unanswered or failed probe advertises everything, so the list never narrows on missing data. The transcode target becomes av1,hevc,h264 filtered by the probe. Leading with AV1 is safe because the server rotates codecs its admin has not enabled ("Allow encoding in HEVC/AV1 format", both off by default) to the back before picking one, so it costs nothing on a server that will not emit AV1. Audio now accepts everything the path can carry. The direct-play profile drops its AudioCodec list entirely - an omitted list means "any codec" to Jellyfin - so an audio stream can no longer be what blocks direct play. The transcode target lists every codec Jellyfin can put in an fMP4 segment, so a video-only transcode copies DTS or TrueHD instead of re-encoding it. Two limits bound that string: the server validates it against ^[a-zA-Z0-9\-\._,|]{0,40}$ when it echoes the list into the transcode URL, so alac does not fit and * is not a wildcard; and omitting the key is not "accept everything" here the way it is for direct play, because the server substitutes the source codec and then ships no audio at all for a source fMP4 cannot carry. close #2131
33 lines
1.1 KiB
Swift
33 lines
1.1 KiB
Swift
import CoreMedia
|
|
import Flutter
|
|
import VideoToolbox
|
|
|
|
/// Answers `com.plezy/device`'s `getVideoDecodeCapabilities` on iOS and tvOS.
|
|
///
|
|
/// Compiled into the iOS and tvOS Runners only — macOS keeps its own sources
|
|
/// and is deliberately left unprobed, because desktop CPUs software-decode
|
|
/// both codecs in real time and narrowing the profile there would force
|
|
/// transcodes for nothing.
|
|
class VideoDecodeCapabilitiesPlugin: NSObject, FlutterPlugin {
|
|
static func register(with registrar: FlutterPluginRegistrar) {
|
|
let channel = FlutterMethodChannel(
|
|
name: "com.plezy/device",
|
|
binaryMessenger: registrar.messenger()
|
|
)
|
|
registrar.addMethodCallDelegate(VideoDecodeCapabilitiesPlugin(), channel: channel)
|
|
}
|
|
|
|
func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
|
switch call.method {
|
|
case "getVideoDecodeCapabilities":
|
|
result([
|
|
"hevc": VTIsHardwareDecodeSupported(kCMVideoCodecType_HEVC),
|
|
"av1": VTIsHardwareDecodeSupported(kCMVideoCodecType_AV1),
|
|
])
|
|
default:
|
|
// The rest of `com.plezy/device` is Android-only.
|
|
result(FlutterMethodNotImplemented)
|
|
}
|
|
}
|
|
}
|