Skip to content

Commit e8706fd

Browse files
author
Isaac
committed
Server-controlled AV1 support
1 parent 629d2a3 commit e8706fd

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3609,7 +3609,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
36093609
if case let .Video(_, _, _, _, _, videoCodec) = attribute, let videoCodec {
36103610
qualityDebugText += " \(videoCodec)"
36113611
if videoCodec == "av1" || videoCodec == "av01" {
3612-
qualityDebugText += isHardwareAv1Supported ? " (HW)" : " (SW)"
3612+
qualityDebugText += internal_isHardwareAv1Supported ? " (HW)" : " (SW)"
36133613
}
36143614
}
36153615
}

submodules/MediaPlayer/Sources/ChunkMediaPlayerV2.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import SwiftSignalKit
66
import Postbox
77
import VideoToolbox
88

9-
public let isHardwareAv1Supported: Bool = {
9+
public let internal_isHardwareAv1Supported: Bool = {
1010
let value = VTIsHardwareDecodeSupported(kCMVideoCodecType_AV1)
1111
return value
1212
}()
@@ -39,7 +39,7 @@ public final class ChunkMediaPlayerV2: ChunkMediaPlayer {
3939

4040
func load() {
4141
let reader: MediaDataReader
42-
if self.mediaType == .video && (self.codecName == "av1" || self.codecName == "av01") && isHardwareAv1Supported {
42+
if self.mediaType == .video && (self.codecName == "av1" || self.codecName == "av01") && internal_isHardwareAv1Supported {
4343
reader = AVAssetVideoDataReader(filePath: self.tempFile.path, isVideo: self.mediaType == .video)
4444
} else {
4545
reader = FFMpegMediaDataReader(filePath: self.tempFile.path, isVideo: self.mediaType == .video, codecName: self.codecName)

submodules/MediaPlayer/Sources/MediaDataReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public final class FFMpegMediaDataReader: MediaDataReader {
3636

3737
if self.isVideo {
3838
var passthroughDecoder = true
39-
if (codecName == "av1" || codecName == "av01") && !isHardwareAv1Supported {
39+
if (codecName == "av1" || codecName == "av01") && !internal_isHardwareAv1Supported {
4040
passthroughDecoder = false
4141
}
4242
let videoSource = SoftwareVideoReader(path: filePath, hintVP9: false, passthroughDecoder: passthroughDecoder)

submodules/TelegramUniversalVideoContent/Sources/HLSVideoContent.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ import ManagedFile
1616
import AppBundle
1717

1818
public struct HLSCodecConfiguration {
19+
public var isHardwareAv1Supported: Bool
1920
public var isSoftwareAv1Supported: Bool
2021

21-
public init(isSoftwareAv1Supported: Bool) {
22+
public init(isHardwareAv1Supported: Bool, isSoftwareAv1Supported: Bool) {
23+
self.isHardwareAv1Supported = isHardwareAv1Supported
2224
self.isSoftwareAv1Supported = isSoftwareAv1Supported
2325
}
2426
}
2527

2628
public extension HLSCodecConfiguration {
2729
init(context: AccountContext) {
2830
var isSoftwareAv1Supported = false
31+
var isHardwareAv1Supported = false
2932

3033
var length: Int = 4
3134
var cpuCount: UInt32 = 0
@@ -34,11 +37,14 @@ public extension HLSCodecConfiguration {
3437
isSoftwareAv1Supported = true
3538
}
3639

40+
if let data = context.currentAppConfiguration.with({ $0 }).data, let value = data["ios_enable_hardware_av1"] as? Double {
41+
isHardwareAv1Supported = value != 0.0
42+
}
3743
if let data = context.currentAppConfiguration.with({ $0 }).data, let value = data["ios_enable_software_av1"] as? Double {
3844
isSoftwareAv1Supported = value != 0.0
3945
}
4046

41-
self.init(isSoftwareAv1Supported: isSoftwareAv1Supported)
47+
self.init(isHardwareAv1Supported: isHardwareAv1Supported, isSoftwareAv1Supported: isSoftwareAv1Supported)
4248
}
4349
}
4450

@@ -52,7 +58,7 @@ public final class HLSQualitySet {
5258
if let alternativeFile = alternativeRepresentation as? TelegramMediaFile {
5359
for attribute in alternativeFile.attributes {
5460
if case let .Video(_, size, _, _, _, videoCodec) = attribute {
55-
if let videoCodec, NativeVideoContent.isVideoCodecSupported(videoCodec: videoCodec, isSoftwareAv1Supported: codecConfiguration.isSoftwareAv1Supported) {
61+
if let videoCodec, NativeVideoContent.isVideoCodecSupported(videoCodec: videoCodec, isHardwareAv1Supported: codecConfiguration.isHardwareAv1Supported, isSoftwareAv1Supported: codecConfiguration.isSoftwareAv1Supported) {
5662
let key = Int(min(size.width, size.height))
5763
if let currentFile = qualityFiles[key] {
5864
var currentCodec: String?

submodules/TelegramUniversalVideoContent/Sources/NativeVideoContent.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,13 @@ public final class NativeVideoContent: UniversalVideoContent {
5959
let displayImage: Bool
6060
let hasSentFramesToDisplay: (() -> Void)?
6161

62-
public static func isVideoCodecSupported(videoCodec: String, isSoftwareAv1Supported: Bool) -> Bool {
62+
public static func isVideoCodecSupported(videoCodec: String, isHardwareAv1Supported: Bool, isSoftwareAv1Supported: Bool) -> Bool {
6363
if videoCodec == "h264" || videoCodec == "h265" || videoCodec == "avc" || videoCodec == "hevc" {
6464
return true
6565
}
6666

6767
if videoCodec == "av1" || videoCodec == "av01" {
68-
if isHardwareAv1Supported {
69-
return true
70-
} else {
71-
return isSoftwareAv1Supported
72-
}
68+
return isHardwareAv1Supported || isSoftwareAv1Supported
7369
}
7470

7571
return false

0 commit comments

Comments
 (0)