mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Add avatar expansion in voice chats
This commit is contained in:
40
submodules/MediaPlayer/Sources/TimeBasedVideoPreload.swift
Normal file
40
submodules/MediaPlayer/Sources/TimeBasedVideoPreload.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import SwiftSignalKit
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
import SyncCore
|
||||
import FFMpegBinding
|
||||
|
||||
public func preloadVideoResource(postbox: Postbox, resourceReference: MediaResourceReference, duration: Double) -> Signal<Never, NoError> {
|
||||
return Signal { subscriber in
|
||||
let queue = Queue()
|
||||
let disposable = MetaDisposable()
|
||||
queue.async {
|
||||
let maximumFetchSize = 2 * 1024 * 1024 + 128 * 1024
|
||||
//let maximumFetchSize = 128
|
||||
let sourceImpl = FFMpegMediaFrameSource(queue: queue, postbox: postbox, resourceReference: resourceReference, tempFilePath: nil, streamable: true, video: true, preferSoftwareDecoding: false, fetchAutomatically: true, maximumFetchSize: maximumFetchSize)
|
||||
let source = QueueLocalObject(queue: queue, generate: {
|
||||
return sourceImpl
|
||||
})
|
||||
let signal = sourceImpl.seek(timestamp: 0.0)
|
||||
|> deliverOn(queue)
|
||||
|> mapToSignal { result -> Signal<Never, MediaFrameSourceSeekError> in
|
||||
let result = result.syncWith({ $0 })
|
||||
if let videoBuffer = result?.buffers.videoBuffer, let impl = source.syncWith({ $0 }) {
|
||||
return impl.ensureHasFrames(until: min(duration, videoBuffer.duration.seconds))
|
||||
|> ignoreValues
|
||||
|> castError(MediaFrameSourceSeekError.self)
|
||||
} else {
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
disposable.set(signal.start(error: { _ in
|
||||
subscriber.putCompletion()
|
||||
}, completed: {
|
||||
subscriber.putCompletion()
|
||||
}))
|
||||
}
|
||||
return disposable
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user