import TelegramUIPrivateModule import CoreMedia final class FFMpegMediaVideoFrameDecoder: MediaTrackFrameDecoder { private let codecContext: UnsafeMutablePointer private let videoFrame: UnsafeMutablePointer private var resetDecoderOnNextFrame = true init(codecContext: UnsafeMutablePointer) { self.codecContext = codecContext self.videoFrame = av_frame_alloc() } deinit { av_frame_unref(self.videoFrame) var codecContextRef: UnsafeMutablePointer? = codecContext avcodec_free_context(&codecContextRef) } func decode(frame: MediaTrackDecodableFrame) -> MediaTrackFrame? { var status = avcodec_send_packet(self.codecContext, frame.packet) if status == 0 { status = avcodec_receive_frame(self.codecContext, self.videoFrame) if status == 0 { return convertVideoFrame(self.videoFrame, pts: frame.pts, duration: frame.duration) } } return nil } private func convertVideoFrame(_ frame: UnsafeMutablePointer, pts: CMTime, duration: CMTime) -> MediaTrackFrame? { return nil } func reset() { avcodec_flush_buffers(self.codecContext) self.resetDecoderOnNextFrame = true } }