From 656d15e6a7881eccee65bac3f389ced559dfccf6 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Sun, 10 Nov 2024 12:10:26 -0500
Subject: mythtv: update to latest fixes; add libx265 v4.0 patch

---
 linhes/mythtv/PKGBUILD                |  6 ++-
 linhes/mythtv/libx265_build_210.patch | 79 +++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 2 deletions(-)
 create mode 100644 linhes/mythtv/libx265_build_210.patch

diff --git a/linhes/mythtv/PKGBUILD b/linhes/mythtv/PKGBUILD
index 5f00e17..aecd1ed 100644
--- a/linhes/mythtv/PKGBUILD
+++ b/linhes/mythtv/PKGBUILD
@@ -7,8 +7,8 @@
 # Contributor: dorphell <dorphell@archlinux.org>
 
 pkgname=mythtv
-pkgver=34+fixes.20240704.c63d023a
-pkgrel=2
+pkgver=34+fixes.20241102.c3764375
+pkgrel=1
 pkgdesc="A Homebrew PVR project"
 arch=('x86_64')
 url="https://www.mythtv.org/"
@@ -91,6 +91,7 @@ patches="0031-UPnP-Reduce-startup-latency-by-moving-blocking-code-to-own-thread.
          0059-portchecker-speedup.patch
          0227-OSD-Add-interlaced-status-to-OSD-debug-screen.patch
          autoskip_reduce_commskip_jumpback.patch
+         libx265_build_210.patch
          defaultThemeLinHES.patch"
 
 source=(
@@ -115,6 +116,7 @@ sha256sums=('SKIP'
             '1ed4be912cd1ebd73553306958b7a2bc98e466b947dfb5d90ad7c0590a5a3747'
             '630c80c588a9b278c4421d356c5cbaa0debf149524bc896656b580b89d8fae88'
             '8a81e724d902976056dc824e7304df343c230ce67ec6ce1d18e110c5ef818ef6'
+            '5a3cc5fef32f7a530fb546ce57b82a7b5f87c76944e5c35ed9616776b0b25ee3'
             '3ff9f48ead83a8dd7a87cc08df066c00813b48b9171cc7bf74ba0e3cb2570d00')
 
 prepare() {
diff --git a/linhes/mythtv/libx265_build_210.patch b/linhes/mythtv/libx265_build_210.patch
new file mode 100644
index 0000000..f0d3e32
--- /dev/null
+++ b/linhes/mythtv/libx265_build_210.patch
@@ -0,0 +1,79 @@
+--- ./mythtv/external/FFmpeg/libavcodec/libx265.c.orig	2024-11-09 12:34:49.704170780 -0500
++++ ./mythtv/external/FFmpeg/libavcodec/libx265.c	2024-11-09 12:32:09.941082796 -0500
+@@ -504,7 +504,13 @@
+ {
+     libx265Context *ctx = avctx->priv_data;
+     x265_picture x265pic;
+-    x265_picture x265pic_out = { 0 };
++#if X265_BUILD >= 210
++    x265_picture x265pic_layers_out[MAX_SCALABLE_LAYERS];
++    x265_picture* x265pic_lyrptr_out[MAX_SCALABLE_LAYERS];
++#else
++    x265_picture x265pic_solo_out = { 0 };
++#endif
++    x265_picture* x265pic_out;
+     x265_nal *nal;
+     uint8_t *dst;
+     int pict_type;
+@@ -575,8 +581,16 @@
+         }
+     }
+ 
++#if X265_BUILD >= 210
++    for (i = 0; i < MAX_SCALABLE_LAYERS; i++)
++        x265pic_lyrptr_out[i] = &x265pic_layers_out[i];
++
++    ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,
++                                   pic ? &x265pic : NULL, x265pic_lyrptr_out);
++#else
+     ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,
+-                                   pic ? &x265pic : NULL, &x265pic_out);
++                                   pic ? &x265pic : NULL, &x265pic_solo_out);
++#endif
+ 
+     av_freep(&x265pic.quantOffsets);
+ 
+@@ -604,10 +618,16 @@
+             pkt->flags |= AV_PKT_FLAG_KEY;
+     }
+ 
+-    pkt->pts = x265pic_out.pts;
+-    pkt->dts = x265pic_out.dts;
++#if X265_BUILD >= 210
++    x265pic_out = x265pic_lyrptr_out[0];
++#else
++    x265pic_out = &x265pic_solo_out;
++#endif
++
++    pkt->pts = x265pic_out->pts;
++    pkt->dts = x265pic_out->dts;
+ 
+-    switch (x265pic_out.sliceType) {
++    switch (x265pic_out->sliceType) {
+     case X265_TYPE_IDR:
+     case X265_TYPE_I:
+         pict_type = AV_PICTURE_TYPE_I;
+@@ -625,17 +645,17 @@
+     }
+ 
+ #if X265_BUILD >= 130
+-    if (x265pic_out.sliceType == X265_TYPE_B)
++    if (x265pic_out->sliceType == X265_TYPE_B)
+ #else
+-    if (x265pic_out.frameData.sliceType == 'b')
++    if (x265pic_out->frameData.sliceType == 'b')
+ #endif
+         pkt->flags |= AV_PKT_FLAG_DISPOSABLE;
+ 
+-    ff_side_data_set_encoder_stats(pkt, x265pic_out.frameData.qp * FF_QP2LAMBDA, NULL, 0, pict_type);
++    ff_side_data_set_encoder_stats(pkt, x265pic_out->frameData.qp * FF_QP2LAMBDA, NULL, 0, pict_type);
+ 
+-    if (x265pic_out.userData) {
+-        memcpy(&avctx->reordered_opaque, x265pic_out.userData, sizeof(avctx->reordered_opaque));
+-        av_freep(&x265pic_out.userData);
++    if (x265pic_out->userData) {
++        memcpy(&avctx->reordered_opaque, x265pic_out->userData, sizeof(avctx->reordered_opaque));
++        av_freep(&x265pic_out->userData);
+     } else
+         avctx->reordered_opaque = 0;
+ 
-- 
cgit v0.12

