Skip to content

Commit 1b3a547

Browse files
author
Isaac
committed
subcodec
1 parent 2860819 commit 1b3a547

File tree

93 files changed

+29325
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+29325
-3
lines changed

third-party/openh264/third_party/openh264/src/codec/common/inc/wels_common_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace WelsCommon {
4444

4545
#define CTX_NA 0
4646
#define WELS_CONTEXT_COUNT 460
47-
#define LEVEL_NUMBER 17
47+
#define LEVEL_NUMBER 20
4848
typedef struct TagLevelLimits {
4949
ELevelIdc uiLevelIdc; // level idc
5050
uint32_t uiMaxMBPS; // Max macroblock processing rate(MB/s)

third-party/openh264/third_party/openh264/src/codec/common/src/common_tables.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,14 @@ const SLevelLimits g_ksLevelLimits[LEVEL_NUMBER] = {
363363

364364
{LEVEL_5_0, 589824, 22080, 110400, 135000, 135000, -2048, 2047, 2, 16}, /* level 5 */
365365
{LEVEL_5_1, 983040, 36864, 184320, 240000, 240000, -2048, 2047, 2, 16}, /* level 5.1 */
366-
{LEVEL_5_2, 2073600, 36864, 184320, 240000, 240000, -2048, 2047, 2, 16} /* level 5.2 */
366+
{LEVEL_5_2, 2073600, 36864, 184320, 240000, 240000, -2048, 2047, 2, 16}, /* level 5.2 */
367+
368+
{LEVEL_6_0, 4177920, 139264, 696320, 240000, 240000, -8192, 8191, 2, 16}, /* level 6.0 */
369+
{LEVEL_6_1, 8355840, 139264, 696320, 480000, 480000, -8192, 8191, 2, 16}, /* level 6.1 */
370+
{LEVEL_6_2, 16711680, 139264, 696320, 800000, 800000, -8192, 8191, 2, 16} /* level 6.2 */
367371
};
368372
const uint32_t g_kuiLevelMaps[LEVEL_NUMBER] = {
369-
10, 9, 11, 12, 13, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51, 52
373+
10, 9, 11, 12, 13, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51, 52, 60, 61, 62
370374
};
371375
//for cabac
372376
/* this table is from Table9-12 to Table 9-24 */

third-party/openh264/third_party/openh264/src/codec/decoder/core/src/au_parser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,12 @@ const SLevelLimits* GetLevelLimits (int32_t iLevelIdx, bool bConstraint3) {
829829
return &g_ksLevelLimits[15];
830830
case 52:
831831
return &g_ksLevelLimits[16];
832+
case 60:
833+
return &g_ksLevelLimits[17];
834+
case 61:
835+
return &g_ksLevelLimits[18];
836+
case 62:
837+
return &g_ksLevelLimits[19];
832838
default:
833839
return NULL;
834840
}

third-party/subcodec/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
build/
2+
build-*/
3+
.build/
4+
.swiftpm/
5+
*.h264
6+
*.yuv
7+
*.mbs
8+
*.trace/
9+
Tests/SubcodecTests/Fixtures/
10+
.DS_Store

third-party/subcodec/CLAUDE.md

Lines changed: 383 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(subcodec C CXX)
3+
4+
set(CMAKE_CXX_STANDARD 23)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
7+
8+
# OpenH264 root — sibling directory in telegram-ios/third-party/
9+
set(OH264_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../openh264/third_party/openh264/src/codec"
10+
CACHE PATH "Path to OpenH264 codec source directory")
11+
12+
if(NOT EXISTS "${OH264_ROOT}/api/wels/codec_api.h")
13+
message(FATAL_ERROR "OpenH264 not found at ${OH264_ROOT}. "
14+
"Expected sibling directory: ../openh264/third_party/openh264/src/codec/")
15+
endif()
16+
17+
# Find FFmpeg via pkg-config (required)
18+
find_package(PkgConfig REQUIRED)
19+
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
20+
libavcodec
21+
libavformat
22+
libavutil
23+
libswscale
24+
)
25+
26+
# --- OpenH264 (from sibling directory) ---
27+
28+
# Common sources (shared by encoder and decoder)
29+
file(GLOB OH264_COMMON_SOURCES ${OH264_ROOT}/common/src/*.cpp)
30+
list(FILTER OH264_COMMON_SOURCES EXCLUDE REGEX "(_neon|_mmi|_msa|_lsx|_lasx)")
31+
32+
add_library(oh264_common STATIC ${OH264_COMMON_SOURCES})
33+
set_target_properties(oh264_common PROPERTIES CXX_STANDARD 11)
34+
target_compile_options(oh264_common PRIVATE -w)
35+
target_include_directories(oh264_common PUBLIC
36+
${OH264_ROOT}/api/wels
37+
${OH264_ROOT}/common/inc
38+
)
39+
40+
# Processing sources
41+
file(GLOB_RECURSE OH264_PROCESSING_SOURCES ${OH264_ROOT}/processing/src/*.cpp)
42+
list(FILTER OH264_PROCESSING_SOURCES EXCLUDE REGEX "(_neon|_mmi|_msa|_lsx|_lasx|loongarch)")
43+
44+
add_library(oh264_processing STATIC ${OH264_PROCESSING_SOURCES})
45+
set_target_properties(oh264_processing PROPERTIES CXX_STANDARD 11)
46+
target_compile_options(oh264_processing PRIVATE -w)
47+
target_link_libraries(oh264_processing PRIVATE oh264_common)
48+
target_include_directories(oh264_processing PRIVATE
49+
${OH264_ROOT}/processing/interface
50+
${OH264_ROOT}/processing/src/common
51+
)
52+
53+
# Encoder sources
54+
file(GLOB OH264_ENCODER_SOURCES ${OH264_ROOT}/encoder/core/src/*.cpp)
55+
list(FILTER OH264_ENCODER_SOURCES EXCLUDE REGEX "(_neon|_mmi|_msa|_lsx|_lasx)")
56+
list(APPEND OH264_ENCODER_SOURCES ${OH264_ROOT}/encoder/plus/src/welsEncoderExt.cpp)
57+
58+
add_library(oh264_encoder STATIC ${OH264_ENCODER_SOURCES})
59+
set_target_properties(oh264_encoder PROPERTIES CXX_STANDARD 11)
60+
target_compile_options(oh264_encoder PRIVATE -w)
61+
target_link_libraries(oh264_encoder PRIVATE oh264_common oh264_processing)
62+
target_include_directories(oh264_encoder PRIVATE
63+
${OH264_ROOT}/encoder/core/inc
64+
${OH264_ROOT}/encoder/plus/inc
65+
${OH264_ROOT}/processing/interface
66+
)
67+
68+
# Decoder sources
69+
file(GLOB OH264_DECODER_SOURCES
70+
${OH264_ROOT}/decoder/core/src/*.cpp
71+
${OH264_ROOT}/decoder/plus/src/*.cpp
72+
)
73+
list(FILTER OH264_DECODER_SOURCES EXCLUDE REGEX "(_neon|_mmi|_msa|_lsx|_lasx|DllEntry)")
74+
75+
add_library(oh264_decoder STATIC ${OH264_DECODER_SOURCES})
76+
set_target_properties(oh264_decoder PROPERTIES CXX_STANDARD 11)
77+
target_compile_options(oh264_decoder PRIVATE -w)
78+
target_link_libraries(oh264_decoder PRIVATE oh264_common)
79+
target_include_directories(oh264_decoder PRIVATE
80+
${OH264_ROOT}/decoder/core/inc
81+
${OH264_ROOT}/decoder/plus/inc
82+
)
83+
84+
# Umbrella interface library
85+
add_library(openh264 INTERFACE)
86+
target_link_libraries(openh264 INTERFACE oh264_encoder oh264_decoder oh264_common oh264_processing)
87+
target_include_directories(openh264 INTERFACE ${OH264_ROOT}/api/wels)
88+
89+
# --- Vendored h264bitstream ---
90+
91+
add_library(h264bitstream STATIC
92+
third_party/h264bitstream/h264_stream.c
93+
third_party/h264bitstream/h264_nal.c
94+
third_party/h264bitstream/h264_sei.c
95+
)
96+
target_include_directories(h264bitstream PUBLIC third_party/h264bitstream)
97+
98+
# --- Core subcodec library ---
99+
100+
add_library(subcodec STATIC
101+
src/frame_writer.cpp
102+
src/cavlc.cpp
103+
src/h264_parser.cpp
104+
src/sprite_data.cpp
105+
src/mbs_encode.cpp
106+
src/mbs_mux_common.cpp
107+
src/mux_surface.cpp
108+
)
109+
target_include_directories(subcodec PUBLIC src)
110+
target_link_libraries(subcodec PUBLIC h264bitstream)
111+
112+
# --- Sprite encoder library (OpenH264 wrapper) ---
113+
114+
add_library(sprite_encode STATIC src/sprite_encode.cpp src/sprite_extractor.cpp)
115+
target_compile_options(sprite_encode PRIVATE -w)
116+
target_link_libraries(sprite_encode PUBLIC subcodec openh264)
117+
target_include_directories(sprite_encode PUBLIC src)
118+
119+
# --- Tools (require FFmpeg) ---
120+
121+
add_executable(sprite_extract tools/sprite_extract.cpp)
122+
target_link_libraries(sprite_extract sprite_encode PkgConfig::LIBAV)
123+
124+
add_executable(sprite_mux tools/sprite_mux.cpp)
125+
target_link_libraries(sprite_mux subcodec)
126+
target_include_directories(sprite_mux PRIVATE src)
127+
128+
add_executable(bench_profile tools/bench_profile.cpp)
129+
target_link_libraries(bench_profile sprite_encode PkgConfig::LIBAV)
130+
target_compile_options(bench_profile PRIVATE -w)
131+
132+
# --- Fixture generation ---
133+
134+
add_executable(generate_fixtures Tests/SubcodecTests/generate_fixtures.cpp)
135+
136+
set(FIXTURE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Tests/SubcodecTests/Fixtures)
137+
138+
add_custom_target(fixtures
139+
COMMAND ${CMAKE_COMMAND} -E make_directory ${FIXTURE_DIR}
140+
COMMAND $<TARGET_FILE:generate_fixtures> ${FIXTURE_DIR}
141+
DEPENDS generate_fixtures
142+
COMMENT "Generating YUV test fixtures in Tests/SubcodecTests/Fixtures/"
143+
)
144+
145+
# --- Tests ---
146+
147+
# Core tests (link subcodec only)
148+
set(CORE_TESTS
149+
test_cavlc test_cavlc_read test_cavlc_split test_ct_lut
150+
test_mb_p16x16 test_mb_i16x16
151+
test_p_frame_ex test_idr_frame_ex test_h264_parse
152+
test_mbs_format test_mbs_encode
153+
test_bs_copy_bits test_ebsp_writer test_rbsp_writer
154+
test_row_plans test_mux_perf
155+
)
156+
157+
foreach(t ${CORE_TESTS})
158+
add_executable(${t} test/${t}.cpp)
159+
target_link_libraries(${t} subcodec)
160+
target_include_directories(${t} PRIVATE src third_party/h264bitstream)
161+
endforeach()
162+
163+
# E2E tests (link sprite_encode = subcodec + openh264)
164+
set(E2E_TESTS
165+
test_mux test_mux_surface test_mux_alpha
166+
test_cavlc_diag test_sprite_extractor test_sprite_encode_alpha
167+
test_high_profile test_ipcm test_resize
168+
)
169+
170+
foreach(t ${E2E_TESTS})
171+
add_executable(${t} test/${t}.cpp)
172+
target_link_libraries(${t} sprite_encode)
173+
endforeach()
174+
175+
# --- CTest registration ---
176+
177+
enable_testing()
178+
179+
foreach(t ${CORE_TESTS} ${E2E_TESTS})
180+
add_test(NAME ${t} COMMAND ${t})
181+
endforeach()

third-party/subcodec/Package.swift

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// swift-tools-version: 5.9
2+
import PackageDescription
3+
4+
let oh264 = "third_party/openh264_codec"
5+
6+
let package = Package(
7+
name: "subcodec",
8+
platforms: [
9+
.macOS(.v10_15),
10+
.iOS(.v13),
11+
.tvOS(.v13),
12+
],
13+
products: [
14+
.library(name: "SubcodecObjC", targets: ["SubcodecObjC"]),
15+
],
16+
targets: [
17+
.target(
18+
name: "oh264_common",
19+
path: "\(oh264)/common",
20+
exclude: [
21+
"arm", "arm64", "x86", "mips", "loongarch",
22+
],
23+
sources: ["src"],
24+
publicHeadersPath: "inc",
25+
cxxSettings: [
26+
.headerSearchPath("../api/wels"),
27+
.unsafeFlags(["-w", "-std=c++11"]),
28+
]
29+
),
30+
.target(
31+
name: "oh264_processing",
32+
dependencies: ["oh264_common"],
33+
path: "\(oh264)/processing",
34+
exclude: [
35+
"src/arm", "src/arm64", "src/x86", "src/mips", "src/loongarch",
36+
"src/common/WelsVP.rc", "src/common/WelsVP.def",
37+
],
38+
sources: ["src"],
39+
publicHeadersPath: "interface",
40+
cxxSettings: [
41+
.headerSearchPath("src/common"),
42+
.headerSearchPath("../common/inc"),
43+
.headerSearchPath("../api/wels"),
44+
.unsafeFlags(["-w", "-std=c++11"]),
45+
]
46+
),
47+
.target(
48+
name: "oh264_encoder",
49+
dependencies: ["oh264_common", "oh264_processing"],
50+
path: "\(oh264)/encoder",
51+
exclude: [
52+
"core/arm", "core/arm64", "core/x86", "core/mips", "core/loongarch",
53+
"plus/src/DllEntry.cpp", "plus/src/wels_enc_export.def",
54+
],
55+
sources: ["core/src", "plus/src"],
56+
publicHeadersPath: "core/inc",
57+
cxxSettings: [
58+
.headerSearchPath("plus/inc"),
59+
.headerSearchPath("../common/inc"),
60+
.headerSearchPath("../api/wels"),
61+
.headerSearchPath("../processing/interface"),
62+
.unsafeFlags(["-w", "-std=c++11"]),
63+
]
64+
),
65+
.target(
66+
name: "oh264_decoder",
67+
dependencies: ["oh264_common"],
68+
path: "\(oh264)/decoder",
69+
exclude: [
70+
"core/arm", "core/arm64", "core/x86", "core/mips", "core/loongarch",
71+
"plus/src/wels_dec_export.def",
72+
],
73+
sources: ["core/src", "plus/src"],
74+
publicHeadersPath: "core/inc",
75+
cxxSettings: [
76+
.headerSearchPath("plus/inc"),
77+
.headerSearchPath("../common/inc"),
78+
.headerSearchPath("../api/wels"),
79+
.unsafeFlags(["-w", "-std=c++11"]),
80+
]
81+
),
82+
.target(
83+
name: "h264bitstream",
84+
path: "third_party/h264bitstream",
85+
sources: ["h264_stream.c", "h264_nal.c", "h264_sei.c"],
86+
publicHeadersPath: "."
87+
),
88+
.target(
89+
name: "sprite_encode",
90+
dependencies: ["subcodec", "oh264_common", "oh264_processing", "oh264_encoder", "oh264_decoder"],
91+
path: "Sources/SpriteEncode",
92+
cxxSettings: [
93+
.headerSearchPath("../../src"),
94+
.headerSearchPath("../../third_party/h264bitstream"),
95+
.headerSearchPath("../../\(oh264)/api/wels"),
96+
.headerSearchPath("../../\(oh264)/encoder/core/inc"),
97+
.headerSearchPath("../../\(oh264)/encoder/plus/inc"),
98+
.headerSearchPath("../../\(oh264)/decoder/core/inc"),
99+
.headerSearchPath("../../\(oh264)/decoder/plus/inc"),
100+
.headerSearchPath("../../\(oh264)/common/inc"),
101+
.unsafeFlags(["-std=c++23"]),
102+
]
103+
),
104+
.target(
105+
name: "subcodec",
106+
dependencies: ["h264bitstream"],
107+
path: "src",
108+
exclude: ["sprite_encode.cpp", "sprite_extractor.cpp"],
109+
publicHeadersPath: ".",
110+
cxxSettings: [
111+
.headerSearchPath("../third_party/h264bitstream"),
112+
]
113+
),
114+
.target(
115+
name: "SubcodecObjC",
116+
dependencies: ["subcodec", "sprite_encode"],
117+
path: "Sources/SubcodecObjC",
118+
publicHeadersPath: "include",
119+
cxxSettings: [
120+
.headerSearchPath("../../src"),
121+
.headerSearchPath("../../third_party/h264bitstream"),
122+
.headerSearchPath("../../\(oh264)/api/wels"),
123+
.headerSearchPath("../../\(oh264)/common/inc"),
124+
.headerSearchPath("../../\(oh264)/encoder/core/inc"),
125+
.headerSearchPath("../../\(oh264)/decoder/core/inc"),
126+
],
127+
linkerSettings: [
128+
.linkedFramework("VideoToolbox"),
129+
.linkedFramework("CoreMedia"),
130+
.linkedFramework("CoreVideo"),
131+
]
132+
),
133+
.testTarget(
134+
name: "SubcodecTests",
135+
dependencies: ["SubcodecObjC"],
136+
path: "Tests/SubcodecTests",
137+
exclude: ["generate_fixtures.cpp"],
138+
resources: [.copy("Fixtures")]
139+
),
140+
],
141+
cxxLanguageStandard: .cxx2b
142+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Placeholder header for SwiftPM target — actual headers are in src/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../../src/sprite_encode.cpp"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../../src/sprite_extractor.cpp"

0 commit comments

Comments
 (0)