Skip to content

Commit

Permalink
contrib: update x265 to version 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
galad87 committed Sep 13, 2024
1 parent ec5f511 commit bd36c30
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
From c5ba94be92cc687ee36b321b7143d58393aca055 Mon Sep 17 00:00:00 2001
From: Max Dmitrichenko <[email protected]>
Date: Thu, 22 Aug 2024 07:40:48 +0200
Subject: [PATCH 1/6] Do not set thread priority on Windows

---
source/common/threadpool.cpp | 6 ------
1 file changed, 6 deletions(-)

diff --git a/source/common/threadpool.cpp b/source/common/threadpool.cpp
index 2db7a146b..4ed534d6b 100644
index 9c27be783..4d7918033 100644
--- a/source/common/threadpool.cpp
+++ b/source/common/threadpool.cpp
@@ -115,12 +115,6 @@ void WorkerThread::threadMain()
Expand All @@ -15,4 +24,6 @@ index 2db7a146b..4ed534d6b 100644
m_pool.setCurrentThreadAffinity();

sleepbitmap_t idBit = (sleepbitmap_t)1 << m_id;
--
2.39.3 (Apple Git-146)

34 changes: 34 additions & 0 deletions contrib/x265/A02-Apple-Silicon-tuning.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From b6f8695658dc8f5e0d3759a65ae37a8efefef4e4 Mon Sep 17 00:00:00 2001
From: Damiano Galassi <[email protected]>
Date: Fri, 13 Sep 2024 16:08:25 +0200
Subject: [PATCH 2/6] Apple Silicon tuning

---
source/common/threadpool.cpp | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/source/common/threadpool.cpp b/source/common/threadpool.cpp
index 4d7918033..7b53cb84e 100644
--- a/source/common/threadpool.cpp
+++ b/source/common/threadpool.cpp
@@ -661,10 +661,16 @@ void ThreadPool::getFrameThreadsCount(x265_param* p, int cpuCount)
else if (cpuCount >= 32)
p->frameNumThreads = (p->sourceHeight > 2000) ? 6 : 5;
else if (cpuCount >= 16)
- p->frameNumThreads = 4;
+#if MACOS && X265_ARCH_ARM64
+ p->frameNumThreads = 16;
+#else
+ p->frameNumThreads = 4;
+#endif
else if (cpuCount >= 8)
#if _WIN32 && X265_ARCH_ARM64
p->frameNumThreads = cpuCount;
+#elif MACOS && X265_ARCH_ARM64
+ p->frameNumThreads = 8;
#else
p->frameNumThreads = 3;
#endif
--
2.39.3 (Apple Git-146)

23 changes: 0 additions & 23 deletions contrib/x265/A02-threads-pool-adjustments.patch

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
From 8454caf458c5f5d20cce711ff8ea8de55ec1ae50 Mon Sep 17 00:00:00 2001
From 9711f557a2e9ab6e0511e18f03835f733a0bfcbc Mon Sep 17 00:00:00 2001
From: harlanc <[email protected]>
Date: Thu, 1 Dec 2022 07:46:13 +0000
Subject: [PATCH] fix crash when SEI length is variable
Subject: [PATCH 3/6] fix crash when SEI length is variable

---
source/encoder/encoder.cpp | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 0fea6553c..5a3fcafc7 100644
index 65c247aba..13d65655f 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -1103,6 +1103,12 @@ void Encoder::copyUserSEIMessages(Frame *frame, const x265_picture* pic_in)
input = seiMsg;
@@ -1113,6 +1113,12 @@ void Encoder::copyUserSEIMessages(Frame *frame, const x265_picture* pic_in)
else
input = pic_in->userSEI.payloads[i];
+

+ if (frame->m_userSEI.payloads[i].payload && (frame->m_userSEI.payloads[i].payloadSize < input.payloadSize))
+ {
+ delete[] frame->m_userSEI.payloads[i].payload;
+ frame->m_userSEI.payloads[i].payload = NULL;
+ }
+
if (!frame->m_userSEI.payloads[i].payload)
frame->m_userSEI.payloads[i].payload = new uint8_t[input.payloadSize];
memcpy(frame->m_userSEI.payloads[i].payload, input.payload, input.payloadSize);
--
2.37.1 (Apple Git-137.1)
2.39.3 (Apple Git-146)

Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
From 2d918078c803c774f828f7f070f0d345cd1a3e82 Mon Sep 17 00:00:00 2001
From: Damiano Galassi <[email protected]>
Date: Thu, 22 Aug 2024 07:46:30 +0200
Subject: [PATCH 4/6] implement ambient viewing environment sei

---
source/common/param.cpp | 6 ++++++
source/encoder/encoder.cpp | 9 +++++++++
source/encoder/sei.h | 19 +++++++++++++++++++
source/x265.h | 9 +++++++++
4 files changed, 43 insertions(+)

diff --git a/source/common/param.cpp b/source/common/param.cpp
index 8c32fafa2..0b56235c9 100755
index d08bb604e..68f7f84fe 100755
--- a/source/common/param.cpp
+++ b/source/common/param.cpp
@@ -378,6 +378,7 @@ void x265_param_default(x265_param* param)
@@ -380,6 +380,7 @@ void x265_param_default(x265_param* param)
param->preferredTransferCharacteristics = -1;
param->pictureStructure = -1;
param->bEmitCLL = 1;
+ param->bEmitAmbientViewingEnvironment = 0;

param->bEnableFrameDuplication = 0;
param->dupThreshold = 70;
@@ -1880,6 +1881,7 @@ int x265_check_params(x265_param* param)
@@ -1929,6 +1930,7 @@ int x265_check_params(x265_param* param)
|| param->bEmitIDRRecoverySEI
|| !!param->interlaceMode
|| param->preferredTransferCharacteristics > 1
+ || param->bEmitAmbientViewingEnvironment
|| param->toneMapFile
|| param->naluFile);

@@ -2766,6 +2768,10 @@ void x265_copy_params(x265_param* dst, x265_param* src)
@@ -2850,6 +2852,10 @@ void x265_copy_params(x265_param* dst, x265_param* src)
dst->bEmitCLL = src->bEmitCLL;
dst->maxCLL = src->maxCLL;
dst->maxFALL = src->maxFALL;
Expand All @@ -30,10 +42,10 @@ index 8c32fafa2..0b56235c9 100755
dst->bEmitVUIHRDInfo = src->bEmitVUIHRDInfo;
dst->bEmitVUITimingInfo = src->bEmitVUITimingInfo;
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
index 5950f87e9..545283474 100644
index 13d65655f..e7dd30fa7 100644
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -3276,6 +3276,15 @@ void Encoder::getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs)
@@ -3429,6 +3429,15 @@ void Encoder::getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs)
}
}

Expand All @@ -50,10 +62,10 @@ index 5950f87e9..545283474 100644
{
char *opts = x265_param2string(m_param, m_sps.conformanceWindow.rightOffset, m_sps.conformanceWindow.bottomOffset);
diff --git a/source/encoder/sei.h b/source/encoder/sei.h
index 03e210639..712e4efb4 100644
index e357a1bf5..ab6086a2c 100644
--- a/source/encoder/sei.h
+++ b/source/encoder/sei.h
@@ -242,6 +242,25 @@ public:
@@ -464,6 +464,25 @@ public:
}
};

Expand All @@ -80,18 +92,18 @@ index 03e210639..712e4efb4 100644
{
public:
diff --git a/source/x265.h b/source/x265.h
index 9f3abd9d9..b6a4d3fe1 100644
index 08ccb4b74..f2981cea2 100644
--- a/source/x265.h
+++ b/source/x265.h
@@ -371,6 +371,7 @@ typedef enum
MASTERING_DISPLAY_INFO = 137,
CONTENT_LIGHT_LEVEL_INFO = 144,
ALTERNATIVE_TRANSFER_CHARACTERISTICS = 147,
+ AMBIENT_VIEWING_ENVIRONMENT = 148,
} SEIPayloadType;

typedef struct x265_sei_payload
@@ -1903,6 +1904,11 @@ typedef struct x265_param
ALPHA_CHANNEL_INFO = 165,
THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO = 176,
MULTIVIEW_SCENE_INFO = 178,
@@ -1956,6 +1957,11 @@ typedef struct x265_param
* value to that value. */
uint16_t maxLuma;

Expand All @@ -103,7 +115,7 @@ index 9f3abd9d9..b6a4d3fe1 100644
/* Maximum of the picture order count */
int log2MaxPocLsb;

@@ -2114,6 +2120,9 @@ typedef struct x265_param
@@ -2167,6 +2173,9 @@ typedef struct x265_param
/*Emit content light level info SEI*/
int bEmitCLL;

Expand All @@ -113,3 +125,6 @@ index 9f3abd9d9..b6a4d3fe1 100644
/*
* Signals picture structure SEI timing message for every frame
* picture structure 7 is signalled for frame doubling
--
2.39.3 (Apple Git-146)

Loading

0 comments on commit bd36c30

Please sign in to comment.