Skip to content

Instantly share code, notes, and snippets.

View quink-black's full-sized avatar

quink quink-black

View GitHub Profile
@quink-black
quink-black / asm-opt.md
Created December 29, 2024 06:39
From A to X: Infrastructure for Assembly Optimization

From libass, to dav1d, to FFmpeg, to x264, and perhaps more projects I haven't noticed, these projects have a lot of handwritten assembly optimization and use the same pattern to build the assembly optimization infrastructure. This article introduces the composition of this infrastructure from three stages: coding, runtime, and test and benchmark.

Most people don't need this infrastructure, but they can learn some good engineering practices. Even if doing mundane work, it's good to understand how the pyramid is built.

  1. Coding stage
@quink-black
quink-black / windows_cpu_freq.cpp
Created May 23, 2024 13:06
Windows CPU frequency
#include <windows.h>
#include <ntstatus.h>
#include <powerbase.h>
#include <stdio.h>
#include <vector>
#pragma comment(lib, "powrprof.lib")
typedef struct _PROCESSOR_POWER_INFORMATION {
@quink-black
quink-black / vaapi_egl_interop_example.c
Created January 20, 2023 12:01 — forked from kajott/vaapi_egl_interop_example.c
example code for minimal-overhead hardware-accelerated video decoding and display on Linux using VA-API/EGL interoperability
#if 0 // self-compiling code: chmod +x this file and run it like a script
BINARY=vaapi_egl_interop_example
gcc -std=c99 -Wall -Wextra -pedantic -Werror -g -fsanitize=address -o $BINARY $0 \
`pkg-config libavcodec libavformat libavutil libva gl egl libdrm --cflags --libs` \
-lX11 -lva-x11 -lva-drm || exit 1
test "$1" = "--compile-only" && exit 0
exec env ASAN_OPTIONS=fast_unwind_on_malloc=0 ./$BINARY $*
#endif /*
Minimal example application for hardware video decoding on Linux and display
@quink-black
quink-black / H.264参数集处理.md
Last active March 6, 2025 11:34
H.264参数集处理

H.264参数集处理

[toc]

摘要

介绍H.264参数集与几种字节流格式的关系,以及in-band/out-of-band传递参数集的方式与容器格式、传输协议的关系,描述MP4格式、FLV格式处理参数集的一些兼容性问题。

=================================================================
==28728==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 528 byte(s) in 2 object(s) allocated from:
#0 0x5648c5aae5e0 in __interceptor_posix_memalign (/mnt/src/src/ffmpeg-build/build/ffmpeg/ffmpeg+0x5d85e0)
#1 0x5648c8b9532a in av_malloc src/libavutil/mem.c:87
#2 0x5648c63daa09 in avio_alloc_context src/libavformat/aviobuf.c:140
#3 0x5648c63dfc8b in ffio_fdopen src/libavformat/aviobuf.c:1002
#4 0x5648c63e1287 in ffio_open_whitelist src/libavformat/aviobuf.c:1171
#5 0x5648c66cfaca in io_open_default src/libavformat/options.c:124
@quink-black
quink-black / HLS如何切码流.md
Created October 20, 2021 12:09
HLS如何切码流

HLS协议的核心设计至少包括三点:大规模分发、多设备兼容和码率自适应。码率自适应包括自适应算法设计以及如何实现切换。HLS协议本身不负责自适应算法,它描述的是如何实现切换。一个基础问题:从a.m3u8切换到b.m3u8时,如何在b.m3u8中找到要播放的切片?

最简单、看起来最合理的方案:在b.m3u8中找匹配的sequence number。可能多数播放器是这么做的。

但是,HLS草案第9版(2012年9月)新增了这么一段描述:

https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-09

used to synchronize the old and new timelines precisely. A client MUST NOT assume that segments with the same media sequence number in

diff --git a/libavcodec/aarch64/videodsp.S b/libavcodec/aarch64/videodsp.S
index 24067cc2af..fe2da0658e 100644
--- a/libavcodec/aarch64/videodsp.S
+++ b/libavcodec/aarch64/videodsp.S
@@ -19,10 +19,11 @@
#include "libavutil/aarch64/asm.S"
function ff_prefetch_aarch64, export=1
+1:
subs w2, w2, #2
@quink-black
quink-black / 如何找到虚函数地址.md
Last active March 28, 2021 03:51
如何找到虚函数地址

如何找到虚函数地址

摘要

关于虚函数的实现、虚函数表的含义,已经有很多资料介绍。这里分析一个实际问题:虚函数寻址的编译实现,或者说如何找到虚函数的地址。弄清楚这一问题,有助于理解分析通过野指针调用虚函数时的行为表现。

  • 注意:本文分析虚函数具体实现,具体实现与编译器有关。测试环境包括Android + armv8 + clang, macOS + x64 + clang.

虚函数解引用的汇编

@quink-black
quink-black / how-to-build-vlc-on-android.md
Created February 4, 2021 17:26
How to build VLC on Android

How to build VLC on Android

  • This is an introduction about build VLC on Android natively, not cross build VLC for Android
  • It's pretty useless, just for fun.

Prepare

  1. Install termux from F-Droid or Google play on Android device

Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required. A minimal base system is installed automatically - additional packages are available using the APT package manager.

diff --git a/modules/video_output/opengl/interop.c b/modules/video_output/opengl/interop.c
index 96d548519e..6ded931189 100644
--- a/modules/video_output/opengl/interop.c
+++ b/modules/video_output/opengl/interop.c
@@ -321,6 +321,24 @@ interop_rgb_base_init(struct vlc_gl_interop *interop, GLenum tex_target,
break;
case VLC_CODEC_RGB32:
+ if (interop->fmt_in.i_rmask == 0x00ff0000
+ && interop->fmt_in.i_gmask == 0x0000ff00