Skip to content

Commit b432800

Browse files
author
Isaac
committed
Part 2 of video fixes
(cherry picked from commit abd3791)
1 parent 4d66bf7 commit b432800

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

submodules/MediaPlayer/Sources/FFMpegMediaFrameSource.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
8383
private let fetchAutomatically: Bool
8484
private let maximumFetchSize: Int?
8585
private let storeAfterDownload: (() -> Void)?
86+
private let isAudioVideoMessage: Bool
8687

8788
private let taskQueue: ThreadTaskQueue
8889
private let thread: Thread
@@ -103,7 +104,7 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
103104
}
104105
}
105106

106-
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) {
107+
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) {
107108
self.queue = queue
108109
self.postbox = postbox
109110
self.userLocation = userLocation
@@ -121,6 +122,7 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
121122
self.lowWaterDuration = lowWaterDuration
122123
self.highWaterDuration = highWaterDuration
123124
self.storeAfterDownload = storeAfterDownload
125+
self.isAudioVideoMessage = isAudioVideoMessage
124126

125127
self.taskQueue = ThreadTaskQueue()
126128

@@ -199,9 +201,10 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
199201
let fetchAutomatically = self.fetchAutomatically
200202
let maximumFetchSize = self.maximumFetchSize
201203
let storeAfterDownload = self.storeAfterDownload
204+
let isAudioVideoMessage = self.isAudioVideoMessage
202205

203206
self.performWithContext { [weak self] context in
204-
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)
207+
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)
205208

206209
let (frames, endOfStream) = context.takeFrames(until: timestamp, types: types)
207210

@@ -253,6 +256,7 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
253256
let fetchAutomatically = self.fetchAutomatically
254257
let maximumFetchSize = self.maximumFetchSize
255258
let storeAfterDownload = self.storeAfterDownload
259+
let isAudioVideoMessage = self.isAudioVideoMessage
256260

257261
let currentSemaphore = Atomic<Atomic<DispatchSemaphore?>?>(value: nil)
258262

@@ -263,7 +267,7 @@ public final class FFMpegMediaFrameSource: NSObject, MediaFrameSource {
263267
self.performWithContext { [weak self] context in
264268
let _ = currentSemaphore.swap(context.currentSemaphore)
265269

266-
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)
270+
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)
267271

268272
context.seek(timestamp: timestamp, completed: { streamDescriptionsAndTimestamp in
269273
queue.async {

submodules/MediaPlayer/Sources/FFMpegMediaFrameSourceContext.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ final class FFMpegMediaFrameSourceContext: NSObject {
337337
self.autosaveDisposable.dispose()
338338
}
339339

340-
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)?) {
340+
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) {
341341
if self.readingError || self.initializedState != nil {
342342
return
343343
}
@@ -408,7 +408,7 @@ final class FFMpegMediaFrameSourceContext: NSObject {
408408
}
409409

410410
var directFilePath: String?
411-
if !streamable {
411+
if !streamable && isAudioVideoMessage {
412412
let data = postbox.mediaBox.resourceData(resourceReference.resource, pathExtension: nil, option: .complete(waitUntilFetchStatus: false))
413413
let semaphore = DispatchSemaphore(value: 0)
414414
let _ = self.currentSemaphore.swap(semaphore)

0 commit comments

Comments
 (0)