mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Part 2 of video fixes
(cherry picked from commit abd37916c30ebeee1b9b881ab571ef738675db42)
This commit is contained in:
parent
4d66bf7194
commit
b4328002c6
@ -83,6 +83,7 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
|
|||||||
private let fetchAutomatically: Bool
|
private let fetchAutomatically: Bool
|
||||||
private let maximumFetchSize: Int?
|
private let maximumFetchSize: Int?
|
||||||
private let storeAfterDownload: (() -> Void)?
|
private let storeAfterDownload: (() -> Void)?
|
||||||
|
private let isAudioVideoMessage: Bool
|
||||||
|
|
||||||
private let taskQueue: ThreadTaskQueue
|
private let taskQueue: ThreadTaskQueue
|
||||||
private let thread: Thread
|
private let thread: Thread
|
||||||
@ -103,7 +104,7 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(queue: Queue, postbox: Postbox, userLocation: MediaResourceUserLocation, userContentType: MediaResourceUserContentType, resourceReference: MediaResourceReference, tempFilePath: String?, limitedFileRange: Range<Int64>?, streamable: Bool, isSeekable: Bool, video: Bool, preferSoftwareDecoding: Bool, fetchAutomatically: Bool, maximumFetchSize: Int? = nil, stallDuration: Double = 1.0, lowWaterDuration: Double = 2.0, highWaterDuration: Double = 3.0, storeAfterDownload: (() -> Void)? = nil) {
|
public init(queue: Queue, postbox: Postbox, userLocation: MediaResourceUserLocation, userContentType: MediaResourceUserContentType, resourceReference: MediaResourceReference, tempFilePath: String?, limitedFileRange: Range<Int64>?, streamable: Bool, isSeekable: Bool, video: Bool, preferSoftwareDecoding: Bool, fetchAutomatically: Bool, maximumFetchSize: Int? = nil, stallDuration: Double = 1.0, lowWaterDuration: Double = 2.0, highWaterDuration: Double = 3.0, storeAfterDownload: (() -> Void)? = nil, isAudioVideoMessage: Bool = false) {
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
self.postbox = postbox
|
self.postbox = postbox
|
||||||
self.userLocation = userLocation
|
self.userLocation = userLocation
|
||||||
@ -121,6 +122,7 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
|
|||||||
self.lowWaterDuration = lowWaterDuration
|
self.lowWaterDuration = lowWaterDuration
|
||||||
self.highWaterDuration = highWaterDuration
|
self.highWaterDuration = highWaterDuration
|
||||||
self.storeAfterDownload = storeAfterDownload
|
self.storeAfterDownload = storeAfterDownload
|
||||||
|
self.isAudioVideoMessage = isAudioVideoMessage
|
||||||
|
|
||||||
self.taskQueue = ThreadTaskQueue()
|
self.taskQueue = ThreadTaskQueue()
|
||||||
|
|
||||||
@ -199,9 +201,10 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
|
|||||||
let fetchAutomatically = self.fetchAutomatically
|
let fetchAutomatically = self.fetchAutomatically
|
||||||
let maximumFetchSize = self.maximumFetchSize
|
let maximumFetchSize = self.maximumFetchSize
|
||||||
let storeAfterDownload = self.storeAfterDownload
|
let storeAfterDownload = self.storeAfterDownload
|
||||||
|
let isAudioVideoMessage = self.isAudioVideoMessage
|
||||||
|
|
||||||
self.performWithContext { [weak self] context in
|
self.performWithContext { [weak self] context in
|
||||||
context.initializeState(postbox: postbox, userLocation: userLocation, resourceReference: resourceReference, tempFilePath: tempFilePath, limitedFileRange: limitedFileRange, streamable: streamable, isSeekable: isSeekable, video: video, preferSoftwareDecoding: preferSoftwareDecoding, fetchAutomatically: fetchAutomatically, maximumFetchSize: maximumFetchSize, storeAfterDownload: storeAfterDownload)
|
context.initializeState(postbox: postbox, userLocation: userLocation, resourceReference: resourceReference, tempFilePath: tempFilePath, limitedFileRange: limitedFileRange, streamable: streamable, isSeekable: isSeekable, video: video, preferSoftwareDecoding: preferSoftwareDecoding, fetchAutomatically: fetchAutomatically, maximumFetchSize: maximumFetchSize, storeAfterDownload: storeAfterDownload, isAudioVideoMessage: isAudioVideoMessage)
|
||||||
|
|
||||||
let (frames, endOfStream) = context.takeFrames(until: timestamp, types: types)
|
let (frames, endOfStream) = context.takeFrames(until: timestamp, types: types)
|
||||||
|
|
||||||
@ -253,6 +256,7 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
|
|||||||
let fetchAutomatically = self.fetchAutomatically
|
let fetchAutomatically = self.fetchAutomatically
|
||||||
let maximumFetchSize = self.maximumFetchSize
|
let maximumFetchSize = self.maximumFetchSize
|
||||||
let storeAfterDownload = self.storeAfterDownload
|
let storeAfterDownload = self.storeAfterDownload
|
||||||
|
let isAudioVideoMessage = self.isAudioVideoMessage
|
||||||
|
|
||||||
let currentSemaphore = Atomic<Atomic<DispatchSemaphore?>?>(value: nil)
|
let currentSemaphore = Atomic<Atomic<DispatchSemaphore?>?>(value: nil)
|
||||||
|
|
||||||
@ -263,7 +267,7 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
|
|||||||
self.performWithContext { [weak self] context in
|
self.performWithContext { [weak self] context in
|
||||||
let _ = currentSemaphore.swap(context.currentSemaphore)
|
let _ = currentSemaphore.swap(context.currentSemaphore)
|
||||||
|
|
||||||
context.initializeState(postbox: postbox, userLocation: userLocation, resourceReference: resourceReference, tempFilePath: tempFilePath, limitedFileRange: limitedFileRange, streamable: streamable, isSeekable: isSeekable, video: video, preferSoftwareDecoding: preferSoftwareDecoding, fetchAutomatically: fetchAutomatically, maximumFetchSize: maximumFetchSize, storeAfterDownload: storeAfterDownload)
|
context.initializeState(postbox: postbox, userLocation: userLocation, resourceReference: resourceReference, tempFilePath: tempFilePath, limitedFileRange: limitedFileRange, streamable: streamable, isSeekable: isSeekable, video: video, preferSoftwareDecoding: preferSoftwareDecoding, fetchAutomatically: fetchAutomatically, maximumFetchSize: maximumFetchSize, storeAfterDownload: storeAfterDownload, isAudioVideoMessage: isAudioVideoMessage)
|
||||||
|
|
||||||
context.seek(timestamp: timestamp, completed: { streamDescriptionsAndTimestamp in
|
context.seek(timestamp: timestamp, completed: { streamDescriptionsAndTimestamp in
|
||||||
queue.async {
|
queue.async {
|
||||||
|
@ -337,7 +337,7 @@ final class FFMpegMediaFrameSourceContext: NSObject {
|
|||||||
self.autosaveDisposable.dispose()
|
self.autosaveDisposable.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeState(postbox: Postbox, userLocation: MediaResourceUserLocation, resourceReference: MediaResourceReference, tempFilePath: String?, limitedFileRange: Range<Int64>?, streamable: Bool, isSeekable: Bool, video: Bool, preferSoftwareDecoding: Bool, fetchAutomatically: Bool, maximumFetchSize: Int?, storeAfterDownload: (() -> Void)?) {
|
func initializeState(postbox: Postbox, userLocation: MediaResourceUserLocation, resourceReference: MediaResourceReference, tempFilePath: String?, limitedFileRange: Range<Int64>?, streamable: Bool, isSeekable: Bool, video: Bool, preferSoftwareDecoding: Bool, fetchAutomatically: Bool, maximumFetchSize: Int?, storeAfterDownload: (() -> Void)?, isAudioVideoMessage: Bool) {
|
||||||
if self.readingError || self.initializedState != nil {
|
if self.readingError || self.initializedState != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -408,7 +408,7 @@ final class FFMpegMediaFrameSourceContext: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var directFilePath: String?
|
var directFilePath: String?
|
||||||
if !streamable {
|
if !streamable && isAudioVideoMessage {
|
||||||
let data = postbox.mediaBox.resourceData(resourceReference.resource, pathExtension: nil, option: .complete(waitUntilFetchStatus: false))
|
let data = postbox.mediaBox.resourceData(resourceReference.resource, pathExtension: nil, option: .complete(waitUntilFetchStatus: false))
|
||||||
let semaphore = DispatchSemaphore(value: 0)
|
let semaphore = DispatchSemaphore(value: 0)
|
||||||
let _ = self.currentSemaphore.swap(semaphore)
|
let _ = self.currentSemaphore.swap(semaphore)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user