From cc8fa3042ef9d8207c53fee10895984136e5b5a5 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Sun, 23 May 2021 11:29:57 +0300
Subject: [PATCH 23/23] More ffmpeg-4.4 patches renaming B0 to B0_ due to
 termux-specific includes defining macro in termbits.h

---
 .../thirdparty/src/ffmpeg-4.4.patch_1         |  35 +++++
 .../thirdparty/src/ffmpeg-4.4.patch_2         | 139 ++++++++++++++++++
 .../thirdparty/src/ffmpeg-4.4.patch_3         | 104 +++++++++++++
 3 files changed, 278 insertions(+)
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_1
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_2
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_3

diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_1 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_1
new file mode 100644
index 00000000..36643f41
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_1
@@ -0,0 +1,35 @@
+--- ffmpeg-4.4/libavcodec/aaccoder.c.orig	2021-05-08 11:52:41.824074401 +0300
++++ ffmpeg-4.4/libavcodec/aaccoder.c	2021-05-08 11:55:06.868074410 +0300
+@@ -800,7 +800,7 @@
+ 
+                 for (sid_sf_boost = 0; sid_sf_boost < 4; sid_sf_boost++) {
+                     float dist1 = 0.0f, dist2 = 0.0f;
+-                    int B0 = 0, B1 = 0;
++                    int B0_ = 0, B1 = 0;
+                     int minidx;
+                     int mididx, sididx;
+                     int midcb, sidcb;
+@@ -862,12 +862,12 @@
+                                                     sididx,
+                                                     sidcb,
+                                                     mslambda / (minthr * bmax), INFINITY, &b4, NULL, 0);
+-                        B0 += b1+b2;
++                        B0_ += b1+b2;
+                         B1 += b3+b4;
+                         dist1 -= b1+b2;
+                         dist2 -= b3+b4;
+                     }
+-                    cpe->ms_mask[w*16+g] = dist2 <= dist1 && B1 < B0;
++                    cpe->ms_mask[w*16+g] = dist2 <= dist1 && B1 < B0_;
+                     if (cpe->ms_mask[w*16+g]) {
+                         if (sce0->band_type[w*16+g] != NOISE_BT && sce1->band_type[w*16+g] != NOISE_BT) {
+                             sce0->sf_idx[w*16+g] = mididx;
+@@ -879,7 +879,7 @@
+                             cpe->ms_mask[w*16+g] = 0;
+                         }
+                         break;
+-                    } else if (B1 > B0) {
++                    } else if (B1 > B0_) {
+                         /* More boost won't fix this */
+                         break;
+                     }
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_2 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_2
new file mode 100644
index 00000000..45adca97
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_2
@@ -0,0 +1,139 @@
+--- ffmpeg-4.4/libavcodec/hevc_mvs.c.orig	2021-05-08 12:22:19.580985429 +0300
++++ ffmpeg-4.4/libavcodec/hevc_mvs.c	2021-05-08 12:29:05.340985454 +0300
+@@ -307,8 +307,8 @@
+     const int xB1    = x0 + nPbW - 1;
+     const int yB1    = y0 - 1;
+ 
+-    const int xB0    = x0 + nPbW;
+-    const int yB0    = y0 - 1;
++    const int xB0_    = x0 + nPbW;
++    const int yB0_    = y0 - 1;
+ 
+     const int xA0    = x0 - 1;
+     const int yA0    = y0 + nPbH;
+@@ -365,14 +365,14 @@
+     }
+ 
+     // above right spatial merge candidate
+-    is_available_b0 = AVAILABLE(cand_up_right, B0) &&
+-                      xB0 < s->ps.sps->width &&
+-                      PRED_BLOCK_AVAILABLE(B0) &&
+-                      !is_diff_mer(s, xB0, yB0, x0, y0);
++    is_available_b0 = AVAILABLE(cand_up_right, B0_) &&
++                      xB0_ < s->ps.sps->width &&
++                      PRED_BLOCK_AVAILABLE(B0_) &&
++                      !is_diff_mer(s, xB0_, yB0_, x0, y0);
+ 
+     if (is_available_b0 &&
+-        !(is_available_b1 && COMPARE_MV_REFIDX(B0, B1))) {
+-        mergecandlist[nb_merge_cand] = TAB_MVF_PU(B0);
++        !(is_available_b1 && COMPARE_MV_REFIDX(B0_, B1))) {
++        mergecandlist[nb_merge_cand] = TAB_MVF_PU(B0_);
+         if (merge_idx == nb_merge_cand)
+             return;
+         nb_merge_cand++;
+@@ -588,7 +588,7 @@
+     MvField *tab_mvf = s->ref->tab_mvf;
+     int isScaledFlag_L0 = 0;
+     int availableFlagLXA0 = 1;
+-    int availableFlagLXB0 = 1;
++    int availableFlagLXB0_ = 1;
+     int numMVPCandLX = 0;
+     int min_pu_width = s->ps.sps->min_pu_width;
+ 
+@@ -596,7 +596,7 @@
+     int is_available_a0;
+     int xA1, yA1;
+     int is_available_a1;
+-    int xB0, yB0;
++    int xB0_, yB0_;
+     int is_available_b0;
+     int xB1, yB1;
+     int is_available_b1;
+@@ -677,12 +677,12 @@
+ b_candidates:
+     // B candidates
+     // above right spatial merge candidate
+-    xB0    = x0 + nPbW;
+-    yB0    = y0 - 1;
++    xB0_    = x0 + nPbW;
++    yB0_    = y0 - 1;
+ 
+-    is_available_b0 =  AVAILABLE(cand_up_right, B0) &&
+-                       xB0 < s->ps.sps->width &&
+-                       PRED_BLOCK_AVAILABLE(B0);
++    is_available_b0 =  AVAILABLE(cand_up_right, B0_) &&
++                       xB0_ < s->ps.sps->width &&
++                       PRED_BLOCK_AVAILABLE(B0_);
+ 
+     // above spatial merge candidate
+     xB1    = x0 + nPbW - 1;
+@@ -696,10 +696,10 @@
+ 
+     // above right spatial merge candidate
+     if (is_available_b0) {
+-        if (MP_MX(B0, pred_flag_index_l0, mxB)) {
++        if (MP_MX(B0_, pred_flag_index_l0, mxB)) {
+             goto scalef;
+         }
+-        if (MP_MX(B0, pred_flag_index_l1, mxB)) {
++        if (MP_MX(B0_, pred_flag_index_l1, mxB)) {
+             goto scalef;
+         }
+     }
+@@ -723,40 +723,40 @@
+             goto scalef;
+         }
+     }
+-    availableFlagLXB0 = 0;
++    availableFlagLXB0_ = 0;
+ 
+ scalef:
+     if (!isScaledFlag_L0) {
+-        if (availableFlagLXB0) {
++        if (availableFlagLXB0_) {
+             availableFlagLXA0 = 1;
+             mxA = mxB;
+         }
+-        availableFlagLXB0 = 0;
++        availableFlagLXB0_ = 0;
+ 
+         // XB0 and L1
+         if (is_available_b0) {
+-            availableFlagLXB0 = MP_MX_LT(B0, pred_flag_index_l0, mxB);
+-            if (!availableFlagLXB0)
+-                availableFlagLXB0 = MP_MX_LT(B0, pred_flag_index_l1, mxB);
++            availableFlagLXB0_ = MP_MX_LT(B0_, pred_flag_index_l0, mxB);
++            if (!availableFlagLXB0_)
++                availableFlagLXB0_ = MP_MX_LT(B0_, pred_flag_index_l1, mxB);
+         }
+ 
+-        if (is_available_b1 && !availableFlagLXB0) {
+-            availableFlagLXB0 = MP_MX_LT(B1, pred_flag_index_l0, mxB);
+-            if (!availableFlagLXB0)
+-                availableFlagLXB0 = MP_MX_LT(B1, pred_flag_index_l1, mxB);
++        if (is_available_b1 && !availableFlagLXB0_) {
++            availableFlagLXB0_ = MP_MX_LT(B1, pred_flag_index_l0, mxB);
++            if (!availableFlagLXB0_)
++                availableFlagLXB0_ = MP_MX_LT(B1, pred_flag_index_l1, mxB);
+         }
+ 
+-        if (is_available_b2 && !availableFlagLXB0) {
+-            availableFlagLXB0 = MP_MX_LT(B2, pred_flag_index_l0, mxB);
+-            if (!availableFlagLXB0)
+-                availableFlagLXB0 = MP_MX_LT(B2, pred_flag_index_l1, mxB);
++        if (is_available_b2 && !availableFlagLXB0_) {
++            availableFlagLXB0_ = MP_MX_LT(B2, pred_flag_index_l0, mxB);
++            if (!availableFlagLXB0_)
++                availableFlagLXB0_ = MP_MX_LT(B2, pred_flag_index_l1, mxB);
+         }
+     }
+ 
+     if (availableFlagLXA0)
+         mvpcand_list[numMVPCandLX++] = mxA;
+ 
+-    if (availableFlagLXB0 && (!availableFlagLXA0 || mxA.x != mxB.x || mxA.y != mxB.y))
++    if (availableFlagLXB0_ && (!availableFlagLXA0 || mxA.x != mxB.x || mxA.y != mxB.y))
+         mvpcand_list[numMVPCandLX++] = mxB;
+ 
+     //temporal motion vector prediction candidate
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_3 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_3
new file mode 100644
index 00000000..4442402c
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch_3
@@ -0,0 +1,104 @@
+--- ffmpeg-4.4/libavcodec/opus_pvq.c.orig	2021-05-08 12:19:49.996985421 +0300
++++ ffmpeg-4.4/libavcodec/opus_pvq.c	2021-05-08 12:21:12.440985425 +0300
+@@ -495,12 +495,12 @@
+     uint32_t N0 = N;
+     int N_B = N / blocks;
+     int N_B0 = N_B;
+-    int B0 = blocks;
++    int B0_ = blocks;
+     int time_divide = 0;
+     int recombine = 0;
+     int inv = 0;
+     float mid = 0, side = 0;
+-    int longblocks = (B0 == 1);
++    int longblocks = (B0_ == 1);
+     uint32_t cm = 0;
+ 
+     if (N == 1) {
+@@ -532,7 +532,7 @@
+         /* Band recombining to increase frequency resolution */
+ 
+         if (lowband &&
+-            (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0 > 1)) {
++            (recombine || ((N_B & 1) == 0 && tf_change < 0) || B0_ > 1)) {
+             for (i = 0; i < N; i++)
+                 lowband_scratch[i] = lowband[i];
+             lowband = lowband_scratch;
+@@ -556,13 +556,13 @@
+             time_divide++;
+             tf_change++;
+         }
+-        B0 = blocks;
++        B0_ = blocks;
+         N_B0 = N_B;
+ 
+         /* Reorganize the samples in time order instead of frequency order */
+-        if (B0 > 1 && (quant || lowband))
++        if (B0_ > 1 && (quant || lowband))
+             celt_deinterleave_hadamard(pvq->hadamard_tmp, quant ? X : lowband,
+-                                       N_B >> recombine, B0 << recombine,
++                                       N_B >> recombine, B0_ << recombine,
+                                        longblocks);
+     }
+ 
+@@ -604,7 +604,7 @@
+             if (quant) {
+                 if (stereo && N > 2)
+                     ff_opus_rc_enc_uint_step(rc, itheta, qn / 2);
+-                else if (stereo || B0 > 1)
++                else if (stereo || B0_ > 1)
+                     ff_opus_rc_enc_uint(rc, itheta, qn + 1);
+                 else
+                     ff_opus_rc_enc_uint_tri(rc, itheta, qn);
+@@ -619,7 +619,7 @@
+             } else {
+                 if (stereo && N > 2)
+                     itheta = ff_opus_rc_dec_uint_step(rc, qn / 2);
+-                else if (stereo || B0 > 1)
++                else if (stereo || B0_ > 1)
+                     itheta = ff_opus_rc_dec_uint(rc, qn+1);
+                 else
+                     itheta = ff_opus_rc_dec_uint_tri(rc, qn);
+@@ -725,7 +725,7 @@
+ 
+             /* Give more bits to low-energy MDCTs than they would
+              * otherwise deserve */
+-            if (B0 > 1 && !stereo && (itheta & 0x3fff)) {
++            if (B0_ > 1 && !stereo && (itheta & 0x3fff)) {
+                 if (itheta > 8192)
+                     /* Rough approximation for pre-echo masking */
+                     delta -= delta >> (4 - duration);
+@@ -764,14 +764,14 @@
+                 cmt = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks,
+                                       next_lowband2, duration, NULL, next_level,
+                                       gain * side, NULL, fill >> blocks);
+-                cm |= cmt << ((B0 >> 1) & (stereo - 1));
++                cm |= cmt << ((B0_ >> 1) & (stereo - 1));
+             } else {
+                 /* For a stereo split, the high bits of fill are always zero,
+                  * so no folding will be done to the side. */
+                 cm = pvq->quant_band(pvq, f, rc, band, Y, NULL, N, sbits, blocks,
+                                      next_lowband2, duration, NULL, next_level,
+                                      gain * side, NULL, fill >> blocks);
+-                cm <<= ((B0 >> 1) & (stereo - 1));
++                cm <<= ((B0_ >> 1) & (stereo - 1));
+                 rebalance = sbits - (rebalance - f->remaining2);
+                 if (rebalance > 3 << 3 && itheta != 16384)
+                     mbits += rebalance - (3 << 3);
+@@ -842,13 +842,13 @@
+         int k;
+ 
+         /* Undo the sample reorganization going from time order to frequency order */
+-        if (B0 > 1)
++        if (B0_ > 1)
+             celt_interleave_hadamard(pvq->hadamard_tmp, X, N_B >> recombine,
+-                                     B0 << recombine, longblocks);
++                                     B0_ << recombine, longblocks);
+ 
+         /* Undo time-freq changes that we did earlier */
+         N_B = N_B0;
+-        blocks = B0;
++        blocks = B0_;
+         for (k = 0; k < time_divide; k++) {
+             blocks >>= 1;
+             N_B <<= 1;
-- 
2.31.1

