- backup old ffmpeg

This commit is contained in:
overtake
2021-12-17 17:41:30 +04:00
parent 7abb7527c6
commit ecaf36e83e
13 changed files with 26 additions and 208 deletions

View File

@@ -27,7 +27,6 @@ typedef struct FFMpegStreamMetrics {
extern int FFMpegCodecIdH264;
extern int FFMpegCodecIdHEVC;
extern int FFMpegCodecIdMPEG4;
extern int FFMpegCodecIdVP9;
@class FFMpegAVCodecContext;
@@ -48,8 +47,6 @@ extern int FFMpegCodecIdVP9;
- (FFMpegFpsAndTimebase)fpsAndTimebaseForStreamIndex:(int32_t)streamIndex defaultTimeBase:(CMTime)defaultTimeBase;
- (FFMpegStreamMetrics)metricsForStreamAtIndex:(int32_t)streamIndex;
- (void)forceVideoCodecId:(int)videoCodecId;
@end
NS_ASSUME_NONNULL_END

View File

@@ -7,11 +7,6 @@ typedef NS_ENUM(NSUInteger, FFMpegAVFrameColorRange) {
FFMpegAVFrameColorRangeFull
};
typedef NS_ENUM(NSUInteger, FFMpegAVFramePixelFormat) {
FFMpegAVFramePixelFormatYUV,
FFMpegAVFramePixelFormatYUVA
};
@interface FFMpegAVFrame : NSObject
@property (nonatomic, readonly) int32_t width;
@@ -21,7 +16,6 @@ typedef NS_ENUM(NSUInteger, FFMpegAVFramePixelFormat) {
@property (nonatomic, readonly) int64_t pts;
@property (nonatomic, readonly) int64_t duration;
@property (nonatomic, readonly) FFMpegAVFrameColorRange colorRange;
@property (nonatomic, readonly) FFMpegAVFramePixelFormat pixelFormat;
- (instancetype)init;

View File

@@ -9,7 +9,6 @@
int FFMpegCodecIdH264 = AV_CODEC_ID_H264;
int FFMpegCodecIdHEVC = AV_CODEC_ID_HEVC;
int FFMpegCodecIdMPEG4 = AV_CODEC_ID_MPEG4;
int FFMpegCodecIdVP9 = AV_CODEC_ID_VP9;
@interface FFMpegAVFormatContext () {
AVFormatContext *_impl;
@@ -145,9 +144,4 @@ int FFMpegCodecIdVP9 = AV_CODEC_ID_VP9;
return (FFMpegStreamMetrics){ .width = _impl->streams[streamIndex]->codecpar->width, .height = _impl->streams[streamIndex]->codecpar->height, .rotationAngle = rotationAngle, .extradata = _impl->streams[streamIndex]->codecpar->extradata, .extradataSize = _impl->streams[streamIndex]->codecpar->extradata_size };
}
- (void)forceVideoCodecId:(int)videoCodecId {
_impl->video_codec_id = videoCodecId;
_impl->video_codec = avcodec_find_decoder(videoCodecId);
}
@end

View File

@@ -62,13 +62,4 @@
return _impl;
}
- (FFMpegAVFramePixelFormat)pixelFormat {
switch (_impl->format) {
case AV_PIX_FMT_YUVA420P:
return FFMpegAVFramePixelFormatYUVA;
default:
return FFMpegAVFramePixelFormatYUV;
}
}
@end

View File

@@ -245,17 +245,6 @@ public final class FFMpegMediaVideoFrameDecoder: MediaTrackFrameDecoder {
}
var pixelBufferRef: CVPixelBuffer?
let pixelFormat: OSType
switch frame.pixelFormat {
case .YUV:
pixelFormat = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
case .YUVA:
pixelFormat = kCVPixelFormatType_420YpCbCr8VideoRange_8A_TriPlanar
default:
pixelFormat = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
}
if let pixelBufferPool = self.pixelBufferPool {
let auxAttributes: [String: Any] = [kCVPixelBufferPoolAllocationThresholdKey as String: bufferCount as NSNumber];
let err = CVPixelBufferPoolCreatePixelBufferWithAuxAttributes(kCFAllocatorDefault, pixelBufferPool, auxAttributes as CFDictionary, &pixelBufferRef)
@@ -269,22 +258,21 @@ public final class FFMpegMediaVideoFrameDecoder: MediaTrackFrameDecoder {
var options: [String: Any] = [kCVPixelBufferBytesPerRowAlignmentKey as String: frame.lineSize[0] as NSNumber]
options[kCVPixelBufferIOSurfacePropertiesKey as String] = ioSurfaceProperties
CVPixelBufferCreate(kCFAllocatorDefault,
Int(frame.width),
Int(frame.height),
pixelFormat,
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
options as CFDictionary,
&pixelBufferRef)
}
guard let pixelBuffer = pixelBufferRef else {
return nil
}
let srcPlaneSize = Int(frame.lineSize[1]) * Int(frame.height / 2)
let dstPlaneSize = srcPlaneSize * 2
let dstPlane: UnsafeMutablePointer<UInt8>
if let (existingDstPlane, existingDstPlaneSize) = self.dstPlane, existingDstPlaneSize == dstPlaneSize {
dstPlane = existingDstPlane
@@ -297,30 +285,29 @@ public final class FFMpegMediaVideoFrameDecoder: MediaTrackFrameDecoder {
}
fillDstPlane(dstPlane, frame.data[1]!, frame.data[2]!, srcPlaneSize)
let status = CVPixelBufferLockBaseAddress(pixelBuffer, [])
if status != kCVReturnSuccess {
return nil
}
let bytesPerRowY = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0)
let bytePerRowY = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0)
let bytesPerRowUV = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 1)
let bytesPerRowA = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 2)
var base = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0)!
if bytesPerRowY == frame.lineSize[0] {
memcpy(base, frame.data[0]!, bytesPerRowY * Int(frame.height))
if bytePerRowY == frame.lineSize[0] {
memcpy(base, frame.data[0]!, bytePerRowY * Int(frame.height))
} else {
var dest = base
var src = frame.data[0]!
let linesize = Int(frame.lineSize[0])
for _ in 0 ..< Int(frame.height) {
memcpy(dest, src, linesize)
dest = dest.advanced(by: bytesPerRowY)
dest = dest.advanced(by: bytePerRowY)
src = src.advanced(by: linesize)
}
}
base = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1)!
if bytesPerRowUV == frame.lineSize[1] * 2 {
memcpy(base, dstPlane, Int(frame.height / 2) * bytesPerRowUV)
@@ -334,23 +321,7 @@ public final class FFMpegMediaVideoFrameDecoder: MediaTrackFrameDecoder {
src = src.advanced(by: linesize)
}
}
if case .YUVA = frame.pixelFormat {
base = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 2)!
if bytesPerRowA == frame.lineSize[3] {
memcpy(base, frame.data[3]!, bytesPerRowA * Int(frame.height))
} else {
var dest = base
var src = frame.data[3]!
let linesize = Int(frame.lineSize[3])
for _ in 0 ..< Int(frame.height) {
memcpy(dest, src, linesize)
dest = dest.advanced(by: bytesPerRowA)
src = src.advanced(by: linesize)
}
}
}
CVPixelBufferUnlockBaseAddress(pixelBuffer, [])
var formatRef: CMVideoFormatDescription?

View File

@@ -57,7 +57,7 @@ public final class SoftwareVideoSource {
private var enqueuedFrames: [(MediaTrackFrame, CGFloat, CGFloat, Bool)] = []
private var hasReadToEnd: Bool = false
public init(path: String, hintVP9: Bool) {
public init(path: String) {
let _ = FFMpegMediaFrameSourceContextHelpers.registerFFMpegGlobals
var s = stat()
@@ -74,9 +74,7 @@ public final class SoftwareVideoSource {
self.path = path
let avFormatContext = FFMpegAVFormatContext()
if hintVP9 {
avFormatContext.forceVideoCodecId(FFMpegCodecIdVP9)
}
let ioBufferSize = 64 * 1024
let avIoContext = FFMpegAVIOContext(bufferSize: Int32(ioBufferSize), opaqueContext: Unmanaged.passUnretained(self).toOpaque(), readPacket: readPacketCallback, writePacket: nil, seek: seekCallback)

View File

@@ -111,7 +111,7 @@ private final class UniversalSoftwareVideoSourceImpl {
fileprivate var currentNumberOfReads: Int = 0
fileprivate var currentReadBytes: Int = 0
init?(mediaBox: MediaBox, fileReference: FileMediaReference, state: ValuePromise<UniversalSoftwareVideoSourceState>, cancelInitialization: Signal<Bool, NoError>, automaticallyFetchHeader: Bool, hintVP9: Bool = false) {
init?(mediaBox: MediaBox, fileReference: FileMediaReference, state: ValuePromise<UniversalSoftwareVideoSourceState>, cancelInitialization: Signal<Bool, NoError>, automaticallyFetchHeader: Bool) {
guard let size = fileReference.media.size else {
return nil
}
@@ -134,9 +134,6 @@ private final class UniversalSoftwareVideoSourceImpl {
self.avIoContext = avIoContext
let avFormatContext = FFMpegAVFormatContext()
if hintVP9 {
avFormatContext.forceVideoCodecId(FFMpegCodecIdVP9)
}
avFormatContext.setIO(avIoContext)
if !avFormatContext.openInput() {
@@ -289,22 +286,19 @@ private final class UniversalSoftwareVideoSourceThreadParams: NSObject {
let state: ValuePromise<UniversalSoftwareVideoSourceState>
let cancelInitialization: Signal<Bool, NoError>
let automaticallyFetchHeader: Bool
let hintVP9: Bool
init(
mediaBox: MediaBox,
fileReference: FileMediaReference,
state: ValuePromise<UniversalSoftwareVideoSourceState>,
cancelInitialization: Signal<Bool, NoError>,
automaticallyFetchHeader: Bool,
hintVP9: Bool
automaticallyFetchHeader: Bool
) {
self.mediaBox = mediaBox
self.fileReference = fileReference
self.state = state
self.cancelInitialization = cancelInitialization
self.automaticallyFetchHeader = automaticallyFetchHeader
self.hintVP9 = hintVP9
}
}
@@ -387,8 +381,8 @@ public final class UniversalSoftwareVideoSource {
}
}
public init(mediaBox: MediaBox, fileReference: FileMediaReference, automaticallyFetchHeader: Bool = false, hintVP9: Bool = false) {
self.thread = Thread(target: UniversalSoftwareVideoSourceThread.self, selector: #selector(UniversalSoftwareVideoSourceThread.entryPoint(_:)), object: UniversalSoftwareVideoSourceThreadParams(mediaBox: mediaBox, fileReference: fileReference, state: self.stateValue, cancelInitialization: self.cancelInitialization.get(), automaticallyFetchHeader: automaticallyFetchHeader, hintVP9: hintVP9))
public init(mediaBox: MediaBox, fileReference: FileMediaReference, automaticallyFetchHeader: Bool = false) {
self.thread = Thread(target: UniversalSoftwareVideoSourceThread.self, selector: #selector(UniversalSoftwareVideoSourceThread.entryPoint(_:)), object: UniversalSoftwareVideoSourceThreadParams(mediaBox: mediaBox, fileReference: fileReference, state: self.stateValue, cancelInitialization: self.cancelInitialization.get(), automaticallyFetchHeader: automaticallyFetchHeader))
self.thread.name = "UniversalSoftwareVideoSource"
self.thread.start()
}

View File

@@ -1,6 +1,5 @@
import Foundation
import UIKit
import AVFoundation
import AsyncDisplayKit
import Display
import SwiftSignalKit
@@ -54,34 +53,6 @@ extension SlotMachineAnimationNode: GenericAnimatedStickerNode {
}
}
private class VideoStickerNode: ASDisplayNode, GenericAnimatedStickerNode {
private var layerHolder: SampleBufferLayer?
var manager: SoftwareVideoLayerFrameManager?
func setOverlayColor(_ color: UIColor?, animated: Bool) {
}
func update(context: AccountContext, fileReference: FileMediaReference, size: CGSize) {
let layerHolder = takeSampleBufferLayer()
layerHolder.layer.videoGravity = AVLayerVideoGravity.resizeAspectFill
layerHolder.layer.frame = CGRect(origin: CGPoint(), size: size)
self.layer.addSublayer(layerHolder.layer)
self.layerHolder = layerHolder
let manager = SoftwareVideoLayerFrameManager(account: context.account, fileReference: fileReference, layerHolder: layerHolder, hintVP9: true)
self.manager = manager
manager.start()
}
var currentFrameIndex: Int {
return 0
}
func setFrameIndex(_ frameIndex: Int) {
}
}
class ChatMessageShareButton: HighlightableButtonNode {
private let backgroundNode: NavigationBackgroundNode
private let iconNode: ASImageNode
@@ -201,9 +172,6 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
private var didSetUpAnimationNode = false
private var isPlaying = false
private var displayLink: ConstantDisplayLinkAnimator?
private var displayLinkTimestamp: Double = 0.0
private var additionalAnimationNodes: [ChatMessageTransitionNode.DecorationItemNode] = []
private var overlayMeshAnimationNode: ChatMessageTransitionNode.DecorationItemNode?
private var enqueuedAdditionalAnimations: [(Int, Double)] = []
@@ -465,10 +433,6 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
}
self.animationNode = animationNode
}
} else if let telegramFile = self.telegramFile, let fileName = telegramFile.fileName, fileName.hasSuffix(".webm") {
let videoNode = VideoStickerNode()
videoNode.update(context: item.context, fileReference: .standalone(media: telegramFile), size: CGSize(width: 184.0, height: 184.0))
self.animationNode = videoNode
} else {
let animationNode = AnimatedStickerNode()
animationNode.started = { [weak self] in
@@ -585,24 +549,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
return
}
let isPlaying = self.visibilityStatus && !self.forceStopAnimations
if let _ = self.animationNode as? VideoStickerNode {
let displayLink: ConstantDisplayLinkAnimator
if let current = self.displayLink {
displayLink = current
} else {
displayLink = ConstantDisplayLinkAnimator { [weak self] in
guard let strongSelf = self, let animationNode = strongSelf.animationNode as? VideoStickerNode else {
return
}
animationNode.manager?.tick(timestamp: strongSelf.displayLinkTimestamp)
strongSelf.displayLinkTimestamp += 1.0 / 30.0
}
displayLink.frameInterval = 2
self.displayLink = displayLink
}
self.displayLink?.isPaused = !isPlaying
} else if let animationNode = self.animationNode as? AnimatedStickerNode {
if let animationNode = self.animationNode as? AnimatedStickerNode {
let isPlaying = self.visibilityStatus && !self.forceStopAnimations
if !isPlaying {
@@ -789,8 +736,6 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
imageSize = dimensions.cgSize.aspectFitted(displaySize)
} else if let thumbnailSize = telegramFile.previewRepresentations.first?.dimensions {
imageSize = thumbnailSize.cgSize.aspectFitted(displaySize)
} else {
imageSize = displaySize
}
} else if let emojiFile = emojiFile {
isEmoji = true

View File

@@ -380,10 +380,6 @@ public final class ChatMessageItem: ListViewItem, CustomStringConvertible {
loop: for media in self.message.media {
if let telegramFile = media as? TelegramMediaFile {
if let fileName = telegramFile.fileName, fileName.hasSuffix(".webm") {
viewClassName = ChatMessageAnimatedStickerItemNode.self
break loop
}
if telegramFile.isAnimatedSticker, let size = telegramFile.size, size > 0 && size <= 128 * 1024 {
if self.message.id.peerId.namespace == Namespaces.Peer.SecretChat {
if telegramFile.fileId.namespace == Namespaces.Media.CloudFile {

View File

@@ -14,7 +14,6 @@ final class SoftwareVideoLayerFrameManager {
private let fetchDisposable: Disposable
private var dataDisposable = MetaDisposable()
private let source = Atomic<SoftwareVideoSource?>(value: nil)
private let hintVP9: Bool
private var baseTimestamp: Double?
private var frames: [MediaTrackFrame] = []
@@ -32,7 +31,7 @@ final class SoftwareVideoLayerFrameManager {
private var layerRotationAngleAndAspect: (CGFloat, CGFloat)?
init(account: Account, fileReference: FileMediaReference, layerHolder: SampleBufferLayer, hintVP9: Bool = false) {
init(account: Account, fileReference: FileMediaReference, layerHolder: SampleBufferLayer) {
var resource = fileReference.media.resource
var secondaryResource: MediaResource?
for attribute in fileReference.media.attributes {
@@ -47,7 +46,6 @@ final class SoftwareVideoLayerFrameManager {
nextWorker += 1
self.account = account
self.resource = resource
self.hintVP9 = hintVP9
self.secondaryResource = secondaryResource
self.queue = ThreadPoolQueue(threadPool: workers)
self.layerHolder = layerHolder
@@ -110,7 +108,7 @@ final class SoftwareVideoLayerFrameManager {
let size = fileSize(path)
Logger.shared.log("SoftwareVideo", "loaded video from \(stringForResource(resource)) (file size: \(String(describing: size))")
let _ = strongSelf.source.swap(SoftwareVideoSource(path: path, hintVP9: strongSelf.hintVP9))
let _ = strongSelf.source.swap(SoftwareVideoSource(path: path))
}
}))
}

View File

@@ -120,24 +120,6 @@ filegroup(
srcs = source_files,
)
vpx_headers = [
"vp8.h",
"vp8cx.h",
"vp8dx.h",
"vpx_codec.h",
"vpx_decoder.h",
"vpx_encoder.h",
"vpx_frame_buffer.h",
"vpx_image.h",
"vpx_integer.h",
"vpx_version.h",
"vpx_ext_ratectrl.h",
]
vpx_libs = [
"VPX",
]
opus_headers = [
"opus.h",
"opus_defines.h",
@@ -154,10 +136,6 @@ genrule(
name = "libffmpeg_build",
srcs = [
":FFMpegSources"
] + [
"//third-party/libvpx:Public/vpx/{}".format(x) for x in vpx_headers
] + [
"//third-party/libvpx:Public/vpx/lib{}.a".format(x) for x in vpx_libs
] + [
"//third-party/opus:Public/opus/{}".format(x) for x in opus_headers
] + [
@@ -175,21 +153,6 @@ genrule(
cp -R "submodules/ffmpeg/Sources/FFMpeg" "$$SOURCE_PATH"
mkdir "$$SOURCE_PATH/libvpx"
mkdir -p "$$SOURCE_PATH/libvpx/include/vpx"
mkdir -p "$$SOURCE_PATH/libvpx/lib"
""" +
"\n" +
"\n".join([
"cp $(location //third-party/libvpx:Public/vpx/{}) $$SOURCE_PATH/libvpx/include/vpx/".format(x) for x in vpx_headers
]) +
"\n" +
"\n".join([
"cp $(location //third-party/libvpx:Public/vpx/libVPX.a) $$SOURCE_PATH/libvpx/lib/".format(x) for x in vpx_libs
]) +
"\n" +
"""
mkdir "$$SOURCE_PATH/libopus"
mkdir -p "$$SOURCE_PATH/libopus/include/opus"
mkdir -p "$$SOURCE_PATH/libopus/lib"
@@ -268,7 +231,6 @@ objc_library(
],
deps = [
":ffmpeg_lib",
"//third-party/libvpx:vpx",
"//third-party/opus:opus",
],
visibility = [

View File

@@ -45,10 +45,9 @@ CONFIGURE_FLAGS="--enable-cross-compile --disable-programs \
--enable-avformat \
--disable-xlib \
--enable-libopus \
--enable-libvpx \
--enable-audiotoolbox \
--enable-bsf=aac_adtstoasc \
--enable-decoder=h264,libvpx_vp9,hevc,libopus,mp3,aac,flac,alac_at,pcm_s16le,pcm_s24le,gsm_ms_at \
--enable-decoder=h264,hevc,libopus,mp3,aac,flac,alac_at,pcm_s16le,pcm_s24le,gsm_ms_at \
--enable-demuxer=aac,mov,m4v,mp3,ogg,libopus,flac,wav,aiff,matroska \
--enable-parser=aac,h264,mp3,libopus \
--enable-protocol=file \
@@ -123,7 +122,6 @@ then
pushd "$SCRATCH/$RAW_ARCH"
LIBOPUS_PATH="$SOURCE_DIR/libopus"
LIBVPX_PATH="$SOURCE_DIR/libvpx"
CFLAGS="$EXTRA_CFLAGS -arch $ARCH"
if [ "$RAW_ARCH" = "i386" -o "$RAW_ARCH" = "x86_64" ]
@@ -176,7 +174,7 @@ then
--extra-ldflags="$LDFLAGS" \
--prefix="$THIN/$RAW_ARCH" \
--pkg-config="$PKG_CONFIG" \
--pkg-config-flags="--libopus_path $LIBOPUS_PATH --libvpx_path $LIBVPX_PATH" \
--pkg-config-flags="--libopus_path $LIBOPUS_PATH" \
|| exit 1
echo "$CONFIGURE_FLAGS" > "$CONFIGURED_MARKER"
fi

View File

@@ -14,8 +14,6 @@ elif [ "$1" == "--exists" ]; then
exit 0
elif [ "$NAME" == "opus" ]; then
exit 0
elif [ "$NAME" == "vpx" ]; then
exit 0
else
if [ "PRINT_ERRORS" == "1" ]; then
echo "Package $NAME was not found in the pkg-config search path."
@@ -27,15 +25,9 @@ elif [ "$1" == "--exists" ]; then
elif [ "$1" == "--cflags" ]; then
NAME="$2"
LIBOPUS_PATH=""
LIBVPX_PATH=""
if [ "$2" == "--libopus_path" ]; then
LIBOPUS_PATH="$3"
NAME="$6"
else
exit 1
fi
if [ "$4" == "--libvpx_path" ]; then
LIBVPX_PATH="$5"
NAME="$4"
else
exit 1
fi
@@ -45,24 +37,15 @@ elif [ "$1" == "--cflags" ]; then
elif [ "$NAME" == "opus" ]; then
echo "-I$LIBOPUS_PATH/include/opus"
exit 0
elif [ "$NAME" == "vpx" ]; then
echo "-I$LIBVPX_PATH/include"
exit 0
else
exit 1
fi
elif [ "$1" == "--libs" ]; then
NAME="$2"
LIBOPUS_PATH=""
LIBVPX_PATH=""
if [ "$2" == "--libopus_path" ]; then
LIBOPUS_PATH="$3"
NAME="$6"
else
exit 1
fi
if [ "$4" == "--libvpx_path" ]; then
LIBVPX_PATH="$5"
NAME="$4"
else
exit 1
fi
@@ -72,9 +55,6 @@ elif [ "$1" == "--libs" ]; then
elif [ "$NAME" == "opus" ]; then
echo "-L$LIBOPUS_PATH/lib -lopus"
exit 0
elif [ "$NAME" == "vpx" ]; then
echo "-L$LIBVPX_PATH/lib -lVPX"
exit 0
else
exit 1
fi