Dav1d build

This commit is contained in:
Isaac 2024-11-14 21:15:05 +04:00
parent 79c3d87abc
commit 8be52172ab
11 changed files with 252 additions and 0 deletions

3
.gitmodules vendored
View File

@ -29,3 +29,6 @@ url=../tgcalls.git
[submodule "submodules/LottieCpp/lottiecpp"]
path = submodules/LottieCpp/lottiecpp
url = https://github.com/ali-fareed/lottiecpp.git
[submodule "third-party/dav1d/dav1d"]
path = third-party/dav1d/dav1d
url = https://github.com/ali-fareed/dav1d.git

View File

@ -33,6 +33,18 @@ http_file(
sha256 = "f794ed92ccb4e9b6619a77328f313497d7decf8fb7e047ba35a348b838e0e1e2",
)
http_file(
name = "meson_tar_gz",
urls = ["https://github.com/mesonbuild/meson/releases/download/1.6.0/meson-1.6.0.tar.gz"],
sha256 = "999b65f21c03541cf11365489c1fad22e2418bb0c3d50ca61139f2eec09d5496",
)
http_file(
name = "ninja-mac_zip",
urls = ["https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-mac.zip"],
sha256 = "89a287444b5b3e98f88a945afa50ce937b8ffd1dcc59c555ad9b1baf855298c9",
)
http_archive(
name = "appcenter_sdk",
urls = ["https://github.com/microsoft/appcenter-sdk-apple/releases/download/4.1.1/AppCenter-SDK-Apple-4.1.1.zip"],

View File

@ -18,6 +18,10 @@ objc_library(
],
deps = [
"//submodules/ffmpeg",
"//third-party/dav1d",
],
sdk_frameworks = [
"CoreMedia",
],
visibility = [
"//visibility:public",

View File

@ -0,0 +1,8 @@
#import <Foundation/Foundation.h>
#import <CoreMedia/CoreMedia.h>
NS_ASSUME_NONNULL_BEGIN
CMFormatDescriptionRef _Nullable createAV1FormatDescription(NSData *bitstreamData) CF_RETURNS_RETAINED;
NS_ASSUME_NONNULL_END

View File

@ -28,6 +28,7 @@ extern int FFMpegCodecIdH264;
extern int FFMpegCodecIdHEVC;
extern int FFMpegCodecIdMPEG4;
extern int FFMpegCodecIdVP9;
extern int FFMpegCodecIdAV1;
@class FFMpegAVCodecContext;

View File

@ -12,3 +12,4 @@
#import <FFMpegBinding/FFMpegRemuxer.h>
#import <FFMpegBinding/FFMpegLiveMuxer.h>
#import <FFMpegBinding/FrameConverter.h>
#import <FFMpegBinding/Dav1dBinding.h>

View File

@ -0,0 +1,44 @@
#import <FFMpegBinding/Dav1dBinding.h>
#import "dav1d/dav1d.h"
/*static CFDataRef ff_videotoolbox_av1c_extradata_create(Dav1dSequenceHeader *header) {
uint8_t *buf;
CFDataRef data;
header->
buf = malloc(s->seq_data_ref->size + 4);
if (!buf)
return NULL;
buf[0] = 0x81; // version and marker (constant)
buf[1] = s->raw_seq->seq_profile << 5 | s->raw_seq->seq_level_idx[0];
buf[2] = s->raw_seq->seq_tier[0] << 7 |
s->raw_seq->color_config.high_bitdepth << 6 |
s->raw_seq->color_config.twelve_bit << 5 |
s->raw_seq->color_config.mono_chrome << 4 |
s->raw_seq->color_config.subsampling_x << 3 |
s->raw_seq->color_config.subsampling_y << 2 |
s->raw_seq->color_config.chroma_sample_position;
if (s->raw_seq->initial_display_delay_present_flag)
buf[3] = 0 << 5 |
s->raw_seq->initial_display_delay_present_flag << 4 |
s->raw_seq->initial_display_delay_minus_1[0];
else
buf[3] = 0x00;
memcpy(buf + 4, s->seq_data_ref->data, s->seq_data_ref->size);
data = CFDataCreate(kCFAllocatorDefault, buf, s->seq_data_ref->size + 4);
av_free(buf);
return data;
}*/
CMFormatDescriptionRef _Nullable createAV1FormatDescription(NSData *bitstreamData) CF_RETURNS_RETAINED {
Dav1dSequenceHeader header;
if (dav1d_parse_sequence_header(&header, bitstreamData.bytes, bitstreamData.length) != 0) {
return nil;
}
return nil;
}

View File

@ -11,6 +11,7 @@ int FFMpegCodecIdH264 = AV_CODEC_ID_H264;
int FFMpegCodecIdHEVC = AV_CODEC_ID_HEVC;
int FFMpegCodecIdMPEG4 = AV_CODEC_ID_MPEG4;
int FFMpegCodecIdVP9 = AV_CODEC_ID_VP9;
int FFMpegCodecIdAV1 = AV_CODEC_ID_AV1;
@interface FFMpegAVFormatContext () {
AVFormatContext *_impl;

121
third-party/dav1d/BUILD vendored Normal file
View File

@ -0,0 +1,121 @@
generated_headers = [
"vcs_version.h",
]
headers = [
"compat/msvc/stdatomic.h",
"compat/gcc/stdatomic.h",
"compat/getopt.h",
"common/dump.h",
"common/frame.h",
"common/bitdepth.h",
"common/attributes.h",
"common/validate.h",
"common/intops.h",
"dav1d/picture.h",
"dav1d/version.h",
"dav1d/data.h",
"dav1d/headers.h",
"dav1d/common.h",
"dav1d/dav1d.h",
]
libs = [
"dav1d",
]
filegroup(
name = "dav1d_sources",
srcs = glob([
"dav1d/**/*"
]),
)
genrule(
name = "dav1d_build",
srcs = [
"build-dav1d-bazel.sh",
"arm64-iPhoneSimulator.meson",
":dav1d_sources",
"@meson_tar_gz//file",
"@ninja-mac_zip//file",
],
cmd_bash =
"""
set -ex
if [ "$(TARGET_CPU)" == "ios_arm64" ]; then
BUILD_ARCH="arm64"
elif [ "$(TARGET_CPU)" == "ios_sim_arm64" ]; then
BUILD_ARCH="sim_arm64"
else
echo "Unsupported architecture $(TARGET_CPU)"
fi
BUILD_DIR="$(RULEDIR)/build_$${BUILD_ARCH}"
rm -rf "$$BUILD_DIR"
mkdir -p "$$BUILD_DIR"
MESON_DIR="$$(pwd)/$$BUILD_DIR/meson"
rm -rf "$$MESON_DIR"
mkdir -p "$$MESON_DIR"
tar -xzf "$(location @meson_tar_gz//file)" -C "$$MESON_DIR"
NINJA_DIR="$$(pwd)/$$BUILD_DIR/ninja"
rm -rf "$$NINJA_DIR"
mkdir -p "$$NINJA_DIR"
unzip "$(location @ninja-mac_zip//file)" -d "$$NINJA_DIR"
cp $(location :build-dav1d-bazel.sh) "$$BUILD_DIR/"
cp $(location :arm64-iPhoneSimulator.meson) "$$BUILD_DIR/"
SOURCE_PATH="third-party/dav1d/dav1d"
cp -R "$$SOURCE_PATH" "$$BUILD_DIR/"
mkdir -p "$$BUILD_DIR/Public/dav1d"
mkdir -p "$$BUILD_DIR/Public/compat"
mkdir -p "$$BUILD_DIR/Public/common"
PATH="$$PATH:$$MESON_DIR/meson-1.6.0:$$NINJA_DIR" sh $$BUILD_DIR/build-dav1d-bazel.sh $$BUILD_ARCH "$$BUILD_DIR"
""" +
"\n".join([
"cp -f \"$$BUILD_DIR/dav1d/build/include/{}\" \"$(location Public/{})\"".format(header, header) for header in generated_headers
]) +
"\n" +
"\n".join([
"cp -f \"$$BUILD_DIR/dav1d/include/{}\" \"$(location Public/{})\"".format(header, header) for header in headers
]) +
"\n" +
"\n".join([
"cp -f \"$$BUILD_DIR/dav1d/build/src/lib{}.a\" \"$(location Public/dav1d/lib/lib{}.a)\"".format(lib, lib) for lib in libs
]),
outs = ["Public/" + x for x in generated_headers] +
["Public/" + x for x in headers] +
["Public/dav1d/lib/lib{}.a".format(x) for x in libs],
visibility = [
"//visibility:public",
]
)
cc_library(
name = "dav1d_lib",
srcs = [":Public/dav1d/lib/lib" + x + ".a" for x in libs]
)
objc_library(
name = "dav1d",
module_name = "dav1d",
enable_modules = True,
hdrs = [":Public/" + x for x in generated_headers],
includes = [
"Public",
],
deps = [
":dav1d_lib",
],
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,27 @@
[binaries]
c = ['clang', '-arch', 'arm64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk']
cpp = ['clang++', '-arch', 'arm64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk']
objc = ['clang', '-arch', 'arm64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk']
objcpp = ['clang++', '-arch', 'arm64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk']
ar = 'ar'
strip = 'strip'
[built-in options]
c_args = ['-mios-simulator-version-min=11.0']
cpp_args = ['-mios-simulator-version-min=11.0']
c_link_args = ['-mios-simulator-version-min=11.0']
cpp_link_args = ['-mios-simulator-version-min=11.0']
objc_args = ['-mios-simulator-version-min=11.0']
objcpp_args = ['-mios-simulator-version-min=11.0']
[properties]
root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer'
needs_exe_wrapper = true
[host_machine]
system = 'darwin'
subsystem = 'ios-simulator'
kernel = 'xnu'
cpu_family = 'arm64'
cpu = 'arm64'
endian = 'little'

30
third-party/dav1d/build-dav1d-bazel.sh vendored Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
set -e
ARCH="$1"
BUILD_DIR="$2"
MESON_OPTIONS="--buildtype=release --default-library=static -Denable_tools=false -Denable_tests=false"
CROSSFILE=""
if [ "$ARCH" = "arm64" ]; then
CROSSFILE="../package/crossfiles/arm64-iPhoneOS.meson"
elif [ "$ARCH" = "sim_arm64" ]; then
CROSSFILE="../../arm64-iPhoneSimulator.meson"
else
echo "Unsupported architecture $ARCH"
exit 1
fi
pushd "$BUILD_DIR/dav1d"
rm -rf build
mkdir build
pushd build
meson.py setup .. --cross-file="$CROSSFILE" $MESON_OPTIONS
ninja
popd
popd