mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-29 03:21:29 +00:00
More granular video scrubbing
This commit is contained in:
parent
0bf61a2794
commit
6f268d7998
@ -19,11 +19,18 @@ private func readPacketCallback(userData: UnsafeMutableRawPointer?, buffer: Unsa
|
|||||||
data = context.mediaBox.resourceData(context.fileReference.media.resource, size: context.size, in: requestRange, mode: .partial)
|
data = context.mediaBox.resourceData(context.fileReference.media.resource, size: context.size, in: requestRange, mode: .partial)
|
||||||
let requiredDataIsNotLocallyAvailable = context.requiredDataIsNotLocallyAvailable
|
let requiredDataIsNotLocallyAvailable = context.requiredDataIsNotLocallyAvailable
|
||||||
var fetchedData: Data?
|
var fetchedData: Data?
|
||||||
|
let fetchDisposable = MetaDisposable()
|
||||||
|
let isInitialized = context.videoStream != nil
|
||||||
|
let mediaBox = context.mediaBox
|
||||||
|
let reference = context.fileReference.resourceReference(context.fileReference.media.resource)
|
||||||
let disposable = data.start(next: { data in
|
let disposable = data.start(next: { data in
|
||||||
if data.count == readCount {
|
if data.count == readCount {
|
||||||
fetchedData = data
|
fetchedData = data
|
||||||
semaphore.signal()
|
semaphore.signal()
|
||||||
} else {
|
} else {
|
||||||
|
if isInitialized {
|
||||||
|
fetchDisposable.set(fetchedMediaResource(mediaBox: mediaBox, reference: reference, ranges: [(requestRange, .maximum)]).start())
|
||||||
|
}
|
||||||
requiredDataIsNotLocallyAvailable?()
|
requiredDataIsNotLocallyAvailable?()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -32,15 +39,11 @@ private func readPacketCallback(userData: UnsafeMutableRawPointer?, buffer: Unsa
|
|||||||
semaphore.signal()
|
semaphore.signal()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
var fetchDisposable: Disposable?
|
|
||||||
if context.videoStream != nil {
|
|
||||||
fetchDisposable = fetchedMediaResource(mediaBox: context.mediaBox, reference: context.fileReference.resourceReference(context.fileReference.media.resource), ranges: [(requestRange, .elevated)]).start()
|
|
||||||
}
|
|
||||||
semaphore.wait()
|
semaphore.wait()
|
||||||
|
|
||||||
disposable.dispose()
|
disposable.dispose()
|
||||||
cancelDisposable.dispose()
|
cancelDisposable.dispose()
|
||||||
fetchDisposable?.dispose()
|
fetchDisposable.dispose()
|
||||||
|
|
||||||
if let fetchedData = fetchedData {
|
if let fetchedData = fetchedData {
|
||||||
fetchedData.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
fetchedData.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||||
|
|||||||
@ -70,6 +70,7 @@ public protocol MediaResourceDataFetchCopyLocalItem {
|
|||||||
public enum MediaBoxFetchPriority: Int32 {
|
public enum MediaBoxFetchPriority: Int32 {
|
||||||
case `default` = 0
|
case `default` = 0
|
||||||
case elevated = 1
|
case elevated = 1
|
||||||
|
case maximum = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum MediaResourceDataFetchResult {
|
public enum MediaResourceDataFetchResult {
|
||||||
|
|||||||
@ -400,7 +400,7 @@ private enum MultipartFetchSource {
|
|||||||
private final class MultipartFetchManager {
|
private final class MultipartFetchManager {
|
||||||
let parallelParts: Int
|
let parallelParts: Int
|
||||||
let defaultPartSize = 128 * 1024
|
let defaultPartSize = 128 * 1024
|
||||||
let partAlignment = 128 * 1024
|
let partAlignment = 4 * 1024
|
||||||
|
|
||||||
var resource: TelegramMediaResource
|
var resource: TelegramMediaResource
|
||||||
var resourceReference: MediaResourceReference?
|
var resourceReference: MediaResourceReference?
|
||||||
@ -571,15 +571,19 @@ private final class MultipartFetchManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while !intervalsToFetch.isEmpty && self.fetchingParts.count < self.parallelParts && !self.reuploadingToCdn && !self.revalidatingMediaReference {
|
while !intervalsToFetch.isEmpty && self.fetchingParts.count < self.parallelParts && !self.reuploadingToCdn && !self.revalidatingMediaReference {
|
||||||
var elevatedIndices: [Int] = []
|
|
||||||
|
var indicesByPriority: [MediaBoxFetchPriority: [Int]] = [:]
|
||||||
for i in 0 ..< intervalsToFetch.count {
|
for i in 0 ..< intervalsToFetch.count {
|
||||||
if case .elevated = intervalsToFetch[i].1 {
|
if indicesByPriority[intervalsToFetch[i].1] == nil {
|
||||||
elevatedIndices.append(i)
|
indicesByPriority[intervalsToFetch[i].1] = []
|
||||||
}
|
}
|
||||||
|
indicesByPriority[intervalsToFetch[i].1]!.append(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentIntervalIndex: Int
|
let currentIntervalIndex: Int
|
||||||
if !elevatedIndices.isEmpty {
|
if let maxIndices = indicesByPriority[.maximum], !maxIndices.isEmpty {
|
||||||
|
currentIntervalIndex = maxIndices[self.nextFetchingPartId % maxIndices.count]
|
||||||
|
} else if let elevatedIndices = indicesByPriority[.elevated], !elevatedIndices.isEmpty {
|
||||||
currentIntervalIndex = elevatedIndices[self.nextFetchingPartId % elevatedIndices.count]
|
currentIntervalIndex = elevatedIndices[self.nextFetchingPartId % elevatedIndices.count]
|
||||||
} else {
|
} else {
|
||||||
currentIntervalIndex = self.nextFetchingPartId % intervalsToFetch.count
|
currentIntervalIndex = self.nextFetchingPartId % intervalsToFetch.count
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user