From 2d32b503f581a7cad1d741d95ce66e6f7477c677 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Wed, 19 May 2021 13:03:38 +0300
Subject: [PATCH 11/17] add ffmpeg-4.4 patches into thirdparty/src

---
 .../thirdparty/src/ffmpeg-4.4.patch0          | 12 +++
 .../thirdparty/src/ffmpeg-4.4.patch1          | 13 ++++
 .../thirdparty/src/ffmpeg-4.4.patch3          | 74 +++++++++++++++++++
 .../thirdparty/src/ffmpeg-4.4.patch5          | 30 ++++++++
 .../thirdparty/src/ffmpeg-4.4.patch6          | 12 +++
 .../thirdparty/src/ffmpeg-4.4.patch7          | 13 ++++
 .../thirdparty/src/ffmpeg-4.4.patch8          | 16 ++++
 .../thirdparty/src/ffmpeg-4.4.patch9          | 36 +++++++++
 .../thirdparty/src/ffmpeg-4.4.patchA          | 24 ++++++
 9 files changed, 230 insertions(+)
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch0
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch1
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch3
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch5
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch6
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch7
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch8
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch9
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patchA

diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch0 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch0
new file mode 100644
index 00000000..f9760935
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch0
@@ -0,0 +1,12 @@
+diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
+index 88fdbeaf1e..f39d2e7cc4 100644
+--- a/fftools/cmdutils.c
++++ b/fftools/cmdutils.c
+@@ -1184,6 +1184,7 @@ static void print_buildconf(int flags, int level)
+ 
+ void show_banner(int argc, char **argv, const OptionDef *options)
+ {
++    return;
+     int idx = locate_option(argc, argv, options, "version");
+     if (hide_banner || idx)
+         return;
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch1 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch1
new file mode 100644
index 00000000..88631302
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch1
@@ -0,0 +1,13 @@
+diff --git a/libavformat/bluray.c b/libavformat/bluray.c
+index 635c4f1b87..80a2e2c3d2 100644
+--- a/libavformat/bluray.c
++++ b/libavformat/bluray.c
+@@ -28,7 +28,7 @@
+ #include "libavutil/opt.h"
+ 
+ #define BLURAY_PROTO_PREFIX     "bluray:"
+-#define MIN_PLAYLIST_LENGTH     180     /* 3 min */
++#define MIN_PLAYLIST_LENGTH     0
+ 
+ typedef struct {
+     const AVClass *class;
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch3 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch3
new file mode 100644
index 00000000..28d3876f
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch3
@@ -0,0 +1,74 @@
+diff --git a/libavformat/avformat.h b/libavformat/avformat.h
+index e91e7f1d33..0f9b26a6d3 100644
+--- a/libavformat/avformat.h
++++ b/libavformat/avformat.h
+@@ -480,6 +480,9 @@ typedef struct AVProbeData {
+                                         The user or muxer can override this through
+                                         AVFormatContext.avoid_negative_ts
+                                         */
++#define AVFMT_SEEK_NOSTREAMS  0x80000 /**< Stream index ignored by seek,
++                                           or some streams fail to seek
++                                           */
+ 
+ #define AVFMT_SEEK_TO_PTS   0x4000000 /**< Seeking is based on PTS */
+ 
+@@ -650,7 +653,8 @@ typedef struct AVInputFormat {
+     /**
+      * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
+      * AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
+-     * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
++     * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS,
++     * AVFMT_SEEK_NOSTREAMS
+      */
+     int flags;
+ 
+diff --git a/libavformat/dv.c b/libavformat/dv.c
+index e99422d4b5..58ce1bbb5f 100644
+--- a/libavformat/dv.c
++++ b/libavformat/dv.c
+@@ -642,6 +642,7 @@ static int dv_probe(const AVProbeData *p)
+ AVInputFormat ff_dv_demuxer = {
+     .name           = "dv",
+     .long_name      = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
++    .flags          = AVFMT_SEEK_NOSTREAMS,
+     .priv_data_size = sizeof(RawDVContext),
+     .read_probe     = dv_probe,
+     .read_header    = dv_read_header,
+diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
+index cff7f0cb54..8b6d22aff2 100644
+--- a/libavformat/matroskadec.c
++++ b/libavformat/matroskadec.c
+@@ -4251,6 +4251,7 @@ static const AVClass webm_dash_class = {
+ AVInputFormat ff_matroska_demuxer = {
+     .name           = "matroska,webm",
+     .long_name      = NULL_IF_CONFIG_SMALL("Matroska / WebM"),
++    .flags          = AVFMT_SEEK_NOSTREAMS,
+     .extensions     = "mkv,mk3d,mka,mks,webm",
+     .priv_data_size = sizeof(MatroskaDemuxContext),
+     .read_probe     = matroska_probe,
+@@ -4264,6 +4265,7 @@ AVInputFormat ff_matroska_demuxer = {
+ AVInputFormat ff_webm_dash_manifest_demuxer = {
+     .name           = "webm_dash_manifest",
+     .long_name      = NULL_IF_CONFIG_SMALL("WebM DASH Manifest"),
++    .flags          = AVFMT_SEEK_NOSTREAMS,
+     .priv_data_size = sizeof(MatroskaDemuxContext),
+     .read_header    = webm_dash_manifest_read_header,
+     .read_packet    = webm_dash_manifest_read_packet,
+diff --git a/libavformat/utils.c b/libavformat/utils.c
+index 807d9f10cb..55a444e7b6 100644
+--- a/libavformat/utils.c
++++ b/libavformat/utils.c
+@@ -2486,6 +2486,13 @@ static int seek_frame_internal(AVFormatContext *s, int stream_index,
+         return seek_frame_byte(s, stream_index, timestamp, flags);
+     }
+ 
++    if (stream_index != -1 && (s->iformat->flags & AVFMT_SEEK_NOSTREAMS)) {
++            timestamp = av_rescale_q(timestamp,
++                    s->streams[stream_index]->time_base,
++                    AV_TIME_BASE_Q);
++            stream_index = -1;
++    }
++
+     if (stream_index < 0) {
+         stream_index = av_find_default_stream_index(s);
+         if (stream_index < 0)
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch5 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch5
new file mode 100644
index 00000000..32e7fe11
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch5
@@ -0,0 +1,30 @@
+diff --git a/libavfilter/formats.c b/libavfilter/formats.c
+index de4315369d..f430908343 100644
+--- a/libavfilter/formats.c
++++ b/libavfilter/formats.c
+@@ -107,11 +107,13 @@ AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b,
+        possibly causing a lossy conversion elsewhere in the graph.
+        To avoid that, pretend that there are no common formats to force the
+        insertion of a conversion filter. */
+-    if (type == AVMEDIA_TYPE_VIDEO)
+-        for (i = 0; i < a->nb_formats; i++)
++    if (type == AVMEDIA_TYPE_VIDEO) {
++        for (i = 0; i < a->nb_formats; i++) {
++            const AVPixFmtDescriptor *adesc = av_pix_fmt_desc_get(a->formats[i]);
++            if( !adesc ) continue;
+             for (j = 0; j < b->nb_formats; j++) {
+-                const AVPixFmtDescriptor *adesc = av_pix_fmt_desc_get(a->formats[i]);
+                 const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
++                if( !bdesc ) continue;
+                 alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
+                 chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
+                 if (a->formats[i] == b->formats[j]) {
+@@ -119,6 +121,8 @@ AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b,
+                     chroma1|= adesc->nb_components > 1;
+                 }
+             }
++        }
++    }
+ 
+     // If chroma or alpha can be lost through merging then do not merge
+     if (alpha2 > alpha1 || chroma2 > chroma1)
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch6 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch6
new file mode 100644
index 00000000..e59a17cc
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch6
@@ -0,0 +1,12 @@
+diff --git a/libavcodec/vdpau_mpeg12.c b/libavcodec/vdpau_mpeg12.c
+index 72220ffb4e..5687c416c9 100644
+--- a/libavcodec/vdpau_mpeg12.c
++++ b/libavcodec/vdpau_mpeg12.c
+@@ -114,6 +114,7 @@ const AVHWAccel ff_mpeg1_vdpau_hwaccel = {
+     .frame_priv_data_size = sizeof(struct vdpau_picture_context),
+     .init           = vdpau_mpeg1_init,
+     .uninit         = ff_vdpau_common_uninit,
++    .frame_params   = ff_vdpau_common_frame_params,
+     .priv_data_size = sizeof(VDPAUContext),
+     .caps_internal  = HWACCEL_CAP_ASYNC_SAFE,
+ };
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch7 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch7
new file mode 100644
index 00000000..05d3b1d0
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch7
@@ -0,0 +1,13 @@
+diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
+index 3b29a189e9..681a4187c5 100644
+--- a/libavcodec/h263dec.c
++++ b/libavcodec/h263dec.c
+@@ -684,7 +684,7 @@ frame_end:
+     if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)
+         ff_mpeg4_frame_end(avctx, buf, buf_size);
+ 
+-    if (!s->divx_packed && avctx->hwaccel)
++    if (s->divx_packed && avctx->hwaccel)
+         ff_thread_finish_setup(avctx);
+ 
+     av_assert1(s->current_picture.f->pict_type == s->current_picture_ptr->f->pict_type);
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch8 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch8
new file mode 100644
index 00000000..51bc09e3
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch8
@@ -0,0 +1,16 @@
+diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
+index 9bd0a555d4..111a9f3a46 100644
+--- a/libavformat/mpegenc.c
++++ b/libavformat/mpegenc.c
+@@ -976,9 +976,9 @@ static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr)
+         PacketDesc *pkt_desc;
+ 
+         while ((pkt_desc = stream->predecode_packet) &&
++               pkt_desc != stream->premux_packet &&
+                scr > pkt_desc->dts) { // FIXME: > vs >=
+-            if (stream->buffer_index < pkt_desc->size ||
+-                stream->predecode_packet == stream->premux_packet) {
++            if (stream->buffer_index < pkt_desc->size) {
+                 av_log(ctx, AV_LOG_ERROR,
+                        "buffer underflow st=%d bufi=%d size=%d\n",
+                        i, stream->buffer_index, pkt_desc->size);
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch9 b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch9
new file mode 100644
index 00000000..0cf24e74
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patch9
@@ -0,0 +1,36 @@
+diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
+index 718a449b6e..84685fe1d9 100644
+--- a/libavutil/hwcontext_cuda.c
++++ b/libavutil/hwcontext_cuda.c
+@@ -269,9 +269,11 @@ static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
+         CudaFunctions *cu = hwctx->internal->cuda_dl;
+ 
+         if (hwctx->internal->is_allocated && hwctx->cuda_ctx) {
++#ifdef CUDA_PRIMARY_CTX
+             if (hwctx->internal->flags & AV_CUDA_USE_PRIMARY_CONTEXT)
+                 CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal->cuda_device));
+             else
++#endif
+                 CHECK_CU(cu->cuCtxDestroy(hwctx->cuda_ctx));
+ 
+             hwctx->cuda_ctx = NULL;
+@@ -321,7 +323,7 @@ static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
+     cu = hwctx->internal->cuda_dl;
+ 
+     hwctx->internal->flags = flags;
+-
++#ifdef CUDA_PRIMARY_CTX
+     if (flags & AV_CUDA_USE_PRIMARY_CONTEXT) {
+         ret = CHECK_CU(cu->cuDevicePrimaryCtxGetState(hwctx->internal->cuda_device,
+                        &dev_flags, &dev_active));
+@@ -342,7 +344,9 @@ static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
+                                                     hwctx->internal->cuda_device));
+         if (ret < 0)
+             return ret;
+-    } else {
++    } else
++#endif
++    {
+         ret = CHECK_CU(cu->cuCtxCreate(&hwctx->cuda_ctx, desired_flags,
+                                        hwctx->internal->cuda_device));
+         if (ret < 0)
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patchA b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patchA
new file mode 100644
index 00000000..6d181e3c
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-4.4.patchA
@@ -0,0 +1,24 @@
+diff --git a/libavutil/hwcontext_vdpau.c b/libavutil/hwcontext_vdpau.c
+index dbef5495af..fba06d8ccf 100644
+--- a/libavutil/hwcontext_vdpau.c
++++ b/libavutil/hwcontext_vdpau.c
+@@ -68,6 +68,11 @@ static const VDPAUPixFmtMap pix_fmts_420[] = {
+     { 0,                     AV_PIX_FMT_NONE,   },
+ };
+ 
++static const VDPAUPixFmtMap pix_fmts_420j[] = {
++    { VDP_YCBCR_FORMAT_YV12, AV_PIX_FMT_YUVJ420P },
++    { 0,                     AV_PIX_FMT_NONE,   },
++};
++
+ static const VDPAUPixFmtMap pix_fmts_422[] = {
+     { VDP_YCBCR_FORMAT_NV12, AV_PIX_FMT_NV16    },
+     { VDP_YCBCR_FORMAT_YV12, AV_PIX_FMT_YUV422P },
+@@ -92,6 +97,7 @@ static const struct {
+     const VDPAUPixFmtMap *map;
+ } vdpau_pix_fmts[] = {
+     { VDP_CHROMA_TYPE_420, AV_PIX_FMT_YUV420P, pix_fmts_420 },
++    { VDP_CHROMA_TYPE_420, AV_PIX_FMT_YUVJ420P, pix_fmts_420j },
+     { VDP_CHROMA_TYPE_422, AV_PIX_FMT_YUV422P, pix_fmts_422 },
+     { VDP_CHROMA_TYPE_444, AV_PIX_FMT_YUV444P, pix_fmts_444 },
+ #ifdef VDP_YCBCR_FORMAT_P016
-- 
2.31.1

