mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Server-controlled AV1 support
This commit is contained in:
parent
629d2a3899
commit
e8706fd71b
@ -3609,7 +3609,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
|
||||
if case let .Video(_, _, _, _, _, videoCodec) = attribute, let videoCodec {
|
||||
qualityDebugText += " \(videoCodec)"
|
||||
if videoCodec == "av1" || videoCodec == "av01" {
|
||||
qualityDebugText += isHardwareAv1Supported ? " (HW)" : " (SW)"
|
||||
qualityDebugText += internal_isHardwareAv1Supported ? " (HW)" : " (SW)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import SwiftSignalKit
|
||||
import Postbox
|
||||
import VideoToolbox
|
||||
|
||||
public let isHardwareAv1Supported: Bool = {
|
||||
public let internal_isHardwareAv1Supported: Bool = {
|
||||
let value = VTIsHardwareDecodeSupported(kCMVideoCodecType_AV1)
|
||||
return value
|
||||
}()
|
||||
@ -39,7 +39,7 @@ public final class ChunkMediaPlayerV2: ChunkMediaPlayer {
|
||||
|
||||
func load() {
|
||||
let reader: MediaDataReader
|
||||
if self.mediaType == .video && (self.codecName == "av1" || self.codecName == "av01") && isHardwareAv1Supported {
|
||||
if self.mediaType == .video && (self.codecName == "av1" || self.codecName == "av01") && internal_isHardwareAv1Supported {
|
||||
reader = AVAssetVideoDataReader(filePath: self.tempFile.path, isVideo: self.mediaType == .video)
|
||||
} else {
|
||||
reader = FFMpegMediaDataReader(filePath: self.tempFile.path, isVideo: self.mediaType == .video, codecName: self.codecName)
|
||||
|
@ -36,7 +36,7 @@ public final class FFMpegMediaDataReader: MediaDataReader {
|
||||
|
||||
if self.isVideo {
|
||||
var passthroughDecoder = true
|
||||
if (codecName == "av1" || codecName == "av01") && !isHardwareAv1Supported {
|
||||
if (codecName == "av1" || codecName == "av01") && !internal_isHardwareAv1Supported {
|
||||
passthroughDecoder = false
|
||||
}
|
||||
let videoSource = SoftwareVideoReader(path: filePath, hintVP9: false, passthroughDecoder: passthroughDecoder)
|
||||
|
@ -16,9 +16,11 @@ import ManagedFile
|
||||
import AppBundle
|
||||
|
||||
public struct HLSCodecConfiguration {
|
||||
public var isHardwareAv1Supported: Bool
|
||||
public var isSoftwareAv1Supported: Bool
|
||||
|
||||
public init(isSoftwareAv1Supported: Bool) {
|
||||
public init(isHardwareAv1Supported: Bool, isSoftwareAv1Supported: Bool) {
|
||||
self.isHardwareAv1Supported = isHardwareAv1Supported
|
||||
self.isSoftwareAv1Supported = isSoftwareAv1Supported
|
||||
}
|
||||
}
|
||||
@ -26,6 +28,7 @@ public struct HLSCodecConfiguration {
|
||||
public extension HLSCodecConfiguration {
|
||||
init(context: AccountContext) {
|
||||
var isSoftwareAv1Supported = false
|
||||
var isHardwareAv1Supported = false
|
||||
|
||||
var length: Int = 4
|
||||
var cpuCount: UInt32 = 0
|
||||
@ -34,11 +37,14 @@ public extension HLSCodecConfiguration {
|
||||
isSoftwareAv1Supported = true
|
||||
}
|
||||
|
||||
if let data = context.currentAppConfiguration.with({ $0 }).data, let value = data["ios_enable_hardware_av1"] as? Double {
|
||||
isHardwareAv1Supported = value != 0.0
|
||||
}
|
||||
if let data = context.currentAppConfiguration.with({ $0 }).data, let value = data["ios_enable_software_av1"] as? Double {
|
||||
isSoftwareAv1Supported = value != 0.0
|
||||
}
|
||||
|
||||
self.init(isSoftwareAv1Supported: isSoftwareAv1Supported)
|
||||
self.init(isHardwareAv1Supported: isHardwareAv1Supported, isSoftwareAv1Supported: isSoftwareAv1Supported)
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,7 +58,7 @@ public final class HLSQualitySet {
|
||||
if let alternativeFile = alternativeRepresentation as? TelegramMediaFile {
|
||||
for attribute in alternativeFile.attributes {
|
||||
if case let .Video(_, size, _, _, _, videoCodec) = attribute {
|
||||
if let videoCodec, NativeVideoContent.isVideoCodecSupported(videoCodec: videoCodec, isSoftwareAv1Supported: codecConfiguration.isSoftwareAv1Supported) {
|
||||
if let videoCodec, NativeVideoContent.isVideoCodecSupported(videoCodec: videoCodec, isHardwareAv1Supported: codecConfiguration.isHardwareAv1Supported, isSoftwareAv1Supported: codecConfiguration.isSoftwareAv1Supported) {
|
||||
let key = Int(min(size.width, size.height))
|
||||
if let currentFile = qualityFiles[key] {
|
||||
var currentCodec: String?
|
||||
|
@ -59,17 +59,13 @@ public final class NativeVideoContent: UniversalVideoContent {
|
||||
let displayImage: Bool
|
||||
let hasSentFramesToDisplay: (() -> Void)?
|
||||
|
||||
public static func isVideoCodecSupported(videoCodec: String, isSoftwareAv1Supported: Bool) -> Bool {
|
||||
public static func isVideoCodecSupported(videoCodec: String, isHardwareAv1Supported: Bool, isSoftwareAv1Supported: Bool) -> Bool {
|
||||
if videoCodec == "h264" || videoCodec == "h265" || videoCodec == "avc" || videoCodec == "hevc" {
|
||||
return true
|
||||
}
|
||||
|
||||
if videoCodec == "av1" || videoCodec == "av01" {
|
||||
if isHardwareAv1Supported {
|
||||
return true
|
||||
} else {
|
||||
return isSoftwareAv1Supported
|
||||
}
|
||||
return isHardwareAv1Supported || isSoftwareAv1Supported
|
||||
}
|
||||
|
||||
return false
|
||||
|
Loading…
x
Reference in New Issue
Block a user