Skip to content

Commit 599a139

Browse files
committed
x265: Backport some patches from x265_git master
Signed-off-by: Zoltán Böszörményi <[email protected]>
1 parent bcfba1a commit 599a139

14 files changed

+891
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
From 825b5da5c15d48f42ea88319b975cbffba689694 Mon Sep 17 00:00:00 2001
2+
From: Uthayakumar Muthu <[email protected]>
3+
Date: Tue, 3 Dec 2024 18:04:43 +0530
4+
Subject: [PATCH 01/13] Fix error message for x265 check when StrictCbr is
5+
enabled
6+
7+
Upstream-Status: Backport
8+
---
9+
source/common/param.cpp | 2 +-
10+
1 file changed, 1 insertion(+), 1 deletion(-)
11+
12+
diff --git a/source/common/param.cpp b/source/common/param.cpp
13+
index a35b06339..7d934b351 100755
14+
--- a/source/common/param.cpp
15+
+++ b/source/common/param.cpp
16+
@@ -1870,7 +1870,7 @@ int x265_check_params(x265_param* param)
17+
CHECK(param->rc.rateControlMode == X265_RC_CQP && param->rc.bStatRead,
18+
"Constant QP is incompatible with 2pass");
19+
CHECK(param->rc.bStrictCbr && (param->rc.bitrate <= 0 || param->rc.vbvBufferSize <=0),
20+
- "Strict-cbr cannot be applied without specifying target bitrate or vbv bufsize");
21+
+ "Strict-cbr cannot be applied without specifying both target bitrate and vbv bufsize");
22+
CHECK(strlen(param->analysisSave) && (param->analysisSaveReuseLevel < 0 || param->analysisSaveReuseLevel > 10),
23+
"Invalid analysis save refine level. Value must be between 1 and 10 (inclusive)");
24+
CHECK(strlen(param->analysisLoad) && (param->analysisLoadReuseLevel < 0 || param->analysisLoadReuseLevel > 10),
25+
--
26+
2.48.1
27+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From 35e750ed50d91036e3ee9c05be978bd95bc7cb7f Mon Sep 17 00:00:00 2001
2+
From: Min Chen <[email protected]>
3+
Date: Wed, 11 Dec 2024 03:10:16 -0800
4+
Subject: [PATCH 02/13] Fix memory leak if no command line option
5+
6+
Upstream-Status: Backport
7+
---
8+
source/x265cli.cpp | 12 ++++++------
9+
1 file changed, 6 insertions(+), 6 deletions(-)
10+
11+
diff --git a/source/x265cli.cpp b/source/x265cli.cpp
12+
index 6ca6fb495..0f3fc3070 100755
13+
--- a/source/x265cli.cpp
14+
+++ b/source/x265cli.cpp
15+
@@ -617,6 +617,12 @@ namespace X265_NS {
16+
17+
bool CLIOptions::parse(int argc, char **argv)
18+
{
19+
+ if (argc <= 1)
20+
+ {
21+
+ x265_log(NULL, X265_LOG_ERROR, "No input file. Run x265 --help for a list of options.\n");
22+
+ return true;
23+
+ }
24+
+
25+
bool bError = false;
26+
int bShowHelp = false;
27+
int inputBitDepth = 8;
28+
@@ -636,12 +642,6 @@ namespace X265_NS {
29+
int svtEnabled = 0;
30+
argCnt = argc;
31+
32+
- if (argc <= 1)
33+
- {
34+
- x265_log(NULL, X265_LOG_ERROR, "No input file. Run x265 --help for a list of options.\n");
35+
- return true;
36+
- }
37+
-
38+
/* Presets are applied before all other options. */
39+
for (optind = 0;;)
40+
{
41+
--
42+
2.48.1
43+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
From 56f7026cbdc3eb2c55078b22cb76817294419bd0 Mon Sep 17 00:00:00 2001
2+
From: Min Chen <[email protected]>
3+
Date: Thu, 28 Nov 2024 16:09:28 -0800
4+
Subject: [PATCH 03/13] Fix SEI buffer memory leaks
5+
6+
Upstream-Status: Backport
7+
---
8+
source/encoder/encoder.cpp | 16 ++++++++++++++++
9+
1 file changed, 16 insertions(+)
10+
11+
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
12+
index 2e65cb1a9..e3285bbae 100644
13+
--- a/source/encoder/encoder.cpp
14+
+++ b/source/encoder/encoder.cpp
15+
@@ -1082,6 +1082,16 @@ void Encoder::copyUserSEIMessages(Frame *frame, const x265_picture* pic_in)
16+
}
17+
18+
int numPayloads = pic_in->userSEI.numPayloads + toneMapPayload + userPayload;
19+
+
20+
+ // TODO: we may reuse buffer if become smaller than exist buffer
21+
+ if (frame->m_userSEI.payloads && numPayloads != frame->m_userSEI.numPayloads)
22+
+ {
23+
+ for (int i = 0; i < frame->m_userSEI.numPayloads; i++)
24+
+ delete[] frame->m_userSEI.payloads[i].payload;
25+
+ delete[] frame->m_userSEI.payloads;
26+
+ frame->m_userSEI.payloads = NULL;
27+
+ }
28+
+
29+
frame->m_userSEI.numPayloads = numPayloads;
30+
31+
if (frame->m_userSEI.numPayloads)
32+
@@ -1102,6 +1112,12 @@ void Encoder::copyUserSEIMessages(Frame *frame, const x265_picture* pic_in)
33+
else
34+
input = pic_in->userSEI.payloads[i];
35+
36+
+ // TODO: condition may improve, because buffer size may change from big to small, but never back to original allocate size
37+
+ if (frame->m_userSEI.payloads[i].payload && frame->m_userSEI.payloads[i].payloadSize < input.payloadSize)
38+
+ {
39+
+ delete[] frame->m_userSEI.payloads[i].payload;
40+
+ frame->m_userSEI.payloads[i].payload = NULL;
41+
+ }
42+
if (!frame->m_userSEI.payloads[i].payload)
43+
frame->m_userSEI.payloads[i].payload = new uint8_t[input.payloadSize];
44+
memcpy(frame->m_userSEI.payloads[i].payload, input.payload, input.payloadSize);
45+
--
46+
2.48.1
47+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
From 1a0ba366cc223bf8c54ed2deb9b3ca2226d70837 Mon Sep 17 00:00:00 2001
2+
From: Min Chen <[email protected]>
3+
Date: Thu, 5 Dec 2024 22:32:27 -0800
4+
Subject: [PATCH 04/13] Fix shared link issue (R_X86_64_PC32)
5+
6+
Upstream-Status: Backport
7+
---
8+
source/common/x86/cpu-a.asm | 7 +++++++
9+
source/common/x86/pixel-util8.asm | 18 +++++++++++++++++-
10+
2 files changed, 24 insertions(+), 1 deletion(-)
11+
12+
diff --git a/source/common/x86/cpu-a.asm b/source/common/x86/cpu-a.asm
13+
index 0930e142b..747b921f7 100644
14+
--- a/source/common/x86/cpu-a.asm
15+
+++ b/source/common/x86/cpu-a.asm
16+
@@ -174,7 +174,14 @@ cglobal safe_intel_cpu_indicator_init
17+
sub rsp, 32 ; shadow space
18+
%endif
19+
and rsp, ~31
20+
+%if WIN64
21+
+ lea rax, [intel_cpu_indicator_init]
22+
+ call rax
23+
+%elif UNIX64
24+
+ call [rel intel_cpu_indicator_init wrt ..plt]
25+
+%else
26+
call intel_cpu_indicator_init
27+
+%endif
28+
leave
29+
%if ARCH_X86_64
30+
pop r14
31+
diff --git a/source/common/x86/pixel-util8.asm b/source/common/x86/pixel-util8.asm
32+
index 3f8c6be35..6ad2852d3 100644
33+
--- a/source/common/x86/pixel-util8.asm
34+
+++ b/source/common/x86/pixel-util8.asm
35+
@@ -8484,7 +8484,13 @@ cglobal costCoeffNxN, 6,11,6
36+
; r4 - nonZero
37+
; r5 - scanFlagMask
38+
; r6 - sum
39+
+
40+
+%if UNIX64
41+
+ mov r0, [private_prefix %+ _entropyStateBits wrt ..gotpc]
42+
+%else
43+
lea r0, [private_prefix %+ _entropyStateBits]
44+
+ ;mov r0, private_prefix %+ _entropyStateBits
45+
+%endif
46+
mov r1, r6mp
47+
xor r6d, r6d
48+
xor r4d, r4d
49+
@@ -8664,7 +8670,12 @@ cglobal costCoeffNxN, 6,10,5
50+
; r6 - sum
51+
; {r3,r4} - ctxSig[15-0]
52+
; r8m - (numNonZero != 0) || (subPosBase == 0)
53+
+%if UNIX64
54+
+ mov r0, [private_prefix %+ _entropyStateBits wrt ..gotpc]
55+
+%else
56+
lea r0, [private_prefix %+ _entropyStateBits]
57+
+ ;mov r0, private_prefix %+ _entropyStateBits
58+
+%endif
59+
mov r1, r6mp
60+
xor r6d, r6d
61+
xor r8d, r8d
62+
@@ -8903,7 +8914,12 @@ cglobal costC1C2Flag, 4,12,2
63+
or r11d, 0x100 ; default value setting to 8
64+
bsf r11d, r11d
65+
66+
- lea r5, [private_prefix %+ _entropyStateBits]
67+
+%if UNIX64
68+
+ mov r5, [private_prefix %+ _entropyStateBits wrt ..gotpc]
69+
+%else
70+
+ lea r5, [private_prefix %+ _entropyStateBits]
71+
+ ;mov r5, private_prefix %+ _entropyStateBits
72+
+%endif
73+
xor r6d, r6d
74+
mov r4d, 0xFFFFFFF9
75+
76+
--
77+
2.48.1
78+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From 8e1d8c5613c99f644e252275a187673bb651f71c Mon Sep 17 00:00:00 2001
2+
From: Ponsanthini <[email protected]>
3+
Date: Thu, 19 Dec 2024 23:36:14 +0530
4+
Subject: [PATCH 05/13] Add check for input video resolution exceeding 8k
5+
6+
Upstream-Status: Backport
7+
---
8+
source/common/param.cpp | 1 +
9+
1 file changed, 1 insertion(+)
10+
11+
diff --git a/source/common/param.cpp b/source/common/param.cpp
12+
index 7d934b351..0fa1cffa2 100755
13+
--- a/source/common/param.cpp
14+
+++ b/source/common/param.cpp
15+
@@ -1667,6 +1667,7 @@ int x265_check_params(x265_param* param)
16+
{
17+
#define CHECK(expr, msg) check_failed |= _confirm(param, expr, msg)
18+
int check_failed = 0; /* abort if there is a fatal configuration problem */
19+
+ CHECK((param->sourceWidth >= 8192 && param->sourceHeight >= 4320), "Input video resolution exceeds the maximum supported 8K resolution of 8192x4320");
20+
CHECK(param->uhdBluray == 1 && (X265_DEPTH != 10 || param->internalCsp != 1 || param->interlaceMode != 0),
21+
"uhd-bd: bit depth, chroma subsample, source picture type must be 10, 4:2:0, progressive");
22+
CHECK(param->maxCUSize != 64 && param->maxCUSize != 32 && param->maxCUSize != 16,
23+
--
24+
2.48.1
25+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
From 30290ccd0edfc1c79eb275e7fc40797ba6e1e35c Mon Sep 17 00:00:00 2001
2+
From: Ponsanthini <[email protected]>
3+
Date: Tue, 7 Jan 2025 17:09:44 +0530
4+
Subject: [PATCH 06/13] Fix max supported input resolution check
5+
6+
Upstream-Status: Backport
7+
---
8+
source/common/param.cpp | 2 +-
9+
1 file changed, 1 insertion(+), 1 deletion(-)
10+
11+
diff --git a/source/common/param.cpp b/source/common/param.cpp
12+
index 0fa1cffa2..ead908013 100755
13+
--- a/source/common/param.cpp
14+
+++ b/source/common/param.cpp
15+
@@ -1667,7 +1667,7 @@ int x265_check_params(x265_param* param)
16+
{
17+
#define CHECK(expr, msg) check_failed |= _confirm(param, expr, msg)
18+
int check_failed = 0; /* abort if there is a fatal configuration problem */
19+
- CHECK((param->sourceWidth >= 8192 && param->sourceHeight >= 4320), "Input video resolution exceeds the maximum supported 8K resolution of 8192x4320");
20+
+ CHECK((param->sourceWidth > 8192 && param->sourceHeight > 4320), "Input video resolution exceeds the maximum supported 8K resolution of 8192x4320");
21+
CHECK(param->uhdBluray == 1 && (X265_DEPTH != 10 || param->internalCsp != 1 || param->interlaceMode != 0),
22+
"uhd-bd: bit depth, chroma subsample, source picture type must be 10, 4:2:0, progressive");
23+
CHECK(param->maxCUSize != 64 && param->maxCUSize != 32 && param->maxCUSize != 16,
24+
--
25+
2.48.1
26+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
From aa19c727a559d35c81c0ad7ff04094cf71c7c5f8 Mon Sep 17 00:00:00 2001
2+
From: Uthayakumar Muthu <[email protected]>
3+
Date: Mon, 9 Dec 2024 15:39:04 +0530
4+
Subject: [PATCH 07/13] Add Feature flag support in x265_config
5+
6+
Upstream-Status: Backport
7+
---
8+
source/CMakeLists.txt | 11 +++++++++++
9+
source/x265_config.h.in | 3 +++
10+
2 files changed, 14 insertions(+)
11+
12+
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
13+
index 5c6dda9e8..f39bcc5c4 100755
14+
--- a/source/CMakeLists.txt
15+
+++ b/source/CMakeLists.txt
16+
@@ -696,17 +696,28 @@ endif(DETAILED_CU_STATS)
17+
option(ENABLE_ALPHA "Enable alpha encoding in x265" OFF)
18+
if(ENABLE_ALPHA)
19+
add_definitions(-DENABLE_ALPHA)
20+
+ set(ENABLE_ALPHA 1)
21+
+else()
22+
+ set(ENABLE_ALPHA 0)
23+
endif()
24+
25+
option(ENABLE_MULTIVIEW "Enable Multi-view encoding in HEVC" OFF)
26+
if(ENABLE_MULTIVIEW)
27+
add_definitions(-DENABLE_MULTIVIEW)
28+
+ set(ENABLE_MULTIVIEW 1)
29+
+else()
30+
+ set(ENABLE_MULTIVIEW 0)
31+
endif()
32+
33+
option(ENABLE_SCC_EXT "Enable screen content coding extension in HEVC" OFF)
34+
if(ENABLE_SCC_EXT)
35+
add_definitions(-DENABLE_SCC_EXT)
36+
+ set(ENABLE_SCC_EXT 1)
37+
+else()
38+
+ set(ENABLE_SCC_EXT 0)
39+
endif()
40+
+configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
41+
+ "${PROJECT_BINARY_DIR}/x265_config.h")
42+
43+
add_subdirectory(encoder)
44+
add_subdirectory(common)
45+
diff --git a/source/x265_config.h.in b/source/x265_config.h.in
46+
index 17c1ecb02..83e703567 100644
47+
--- a/source/x265_config.h.in
48+
+++ b/source/x265_config.h.in
49+
@@ -30,5 +30,8 @@
50+
* the shared library SONAME on platforms which support it. It also
51+
* prevents linking against a different version of the static lib */
52+
#define X265_BUILD ${X265_BUILD}
53+
+#define ENABLE_ALPHA ${ENABLE_ALPHA}
54+
+#define ENABLE_MULTIVIEW ${ENABLE_MULTIVIEW}
55+
+#define ENABLE_SCC_EXT ${ENABLE_SCC_EXT}
56+
57+
#endif
58+
--
59+
2.48.1
60+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From 9d1a40d7c7a5919d15316388e4de5b5a825b4407 Mon Sep 17 00:00:00 2001
2+
From: Uthayakumar Muthu <[email protected]>
3+
Date: Wed, 18 Dec 2024 11:29:55 +0530
4+
Subject: [PATCH 08/13] Fix the buffer size and frame out of bound access issue
5+
6+
Upstream-Status: Backport
7+
---
8+
source/encoder/encoder.cpp | 4 ++--
9+
source/encoder/frameencoder.cpp | 2 +-
10+
2 files changed, 3 insertions(+), 3 deletions(-)
11+
12+
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
13+
index e3285bbae..5932d819f 100644
14+
--- a/source/encoder/encoder.cpp
15+
+++ b/source/encoder/encoder.cpp
16+
@@ -2731,14 +2731,14 @@ char* Encoder::statsString(EncStats& stat, char* buffer, size_t bufferSize)
17+
18+
if (m_param->bEnablePsnr)
19+
{
20+
- len += snprintf(buffer + len, sizeof(buffer) - len," PSNR Mean: Y:%.3lf U:%.3lf V:%.3lf",
21+
+ len += snprintf(buffer + len, bufferSize - len," PSNR Mean: Y:%.3lf U:%.3lf V:%.3lf",
22+
stat.m_psnrSumY / (double)stat.m_numPics,
23+
stat.m_psnrSumU / (double)stat.m_numPics,
24+
stat.m_psnrSumV / (double)stat.m_numPics);
25+
}
26+
if (m_param->bEnableSsim)
27+
{
28+
- snprintf(buffer + len, sizeof(buffer) - len, " SSIM Mean: %.6lf (%.3lfdB)",
29+
+ snprintf(buffer + len, bufferSize - len, " SSIM Mean: %.6lf (%.3lfdB)",
30+
stat.m_globalSsim / (double)stat.m_numPics,
31+
x265_ssim2dB(stat.m_globalSsim / (double)stat.m_numPics));
32+
}
33+
diff --git a/source/encoder/frameencoder.cpp b/source/encoder/frameencoder.cpp
34+
index 5749f994e..9188f4c8c 100644
35+
--- a/source/encoder/frameencoder.cpp
36+
+++ b/source/encoder/frameencoder.cpp
37+
@@ -2435,7 +2435,7 @@ void FrameEncoder::vmafFrameLevelScore()
38+
39+
Frame** FrameEncoder::getEncodedPicture(NALList& output)
40+
{
41+
- if (m_frame[0] && (m_param->numLayers <= 1 || m_frame[1]))
42+
+ if (m_frame[0] && (m_param->numLayers <= 1 || (MAX_LAYERS > 1 && m_frame[1])))
43+
{
44+
/* block here until worker thread completes */
45+
m_done.wait();
46+
--
47+
2.48.1
48+

0 commit comments

Comments
 (0)