summaryrefslogtreecommitdiffstats
path: root/debian/patches/workarounds/0004-ffmpeg6.patch
blob: d0c4563d16d6798218153bdab24e50327e2254fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
From c9e25dc15acf1214b079da7021ad89acf85fa77d Mon Sep 17 00:00:00 2001
From: CastagnaIT <gottardo.stefano.83@gmail.com>
Date: Sun, 29 Jan 2023 17:51:51 +0100
Subject: [PATCH] [VideoPlayerVideo] Log an error when codec extradata is
 required

---
 xbmc/cores/VideoPlayer/VideoPlayerVideo.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/xbmc/cores/VideoPlayer/VideoPlayerVideo.cpp b/xbmc/cores/VideoPlayer/VideoPlayerVideo.cpp
index 20f6b3b1cb51d..38f63f0766718 100644
--- a/xbmc/cores/VideoPlayer/VideoPlayerVideo.cpp
+++ b/xbmc/cores/VideoPlayer/VideoPlayerVideo.cpp
@@ -114,8 +114,11 @@ bool CVideoPlayerVideo::OpenStream(CDVDStreamInfo hint)
         hint.codec == AV_CODEC_ID_WMV3 ||
         hint.codec == AV_CODEC_ID_VC1 ||
         hint.codec == AV_CODEC_ID_AV1)
-      // clang-format on
+    {
+      CLog::LogF(LOGERROR, "Codec id {} require extradata.", hint.codec);
       return false;
+    }
+    // clang-format on
   }
 
   CLog::Log(LOGINFO, "Creating video codec with codec id: {}", hint.codec);


From 2559466404d342428d43076bf90fcacc24313af0 Mon Sep 17 00:00:00 2001
From: enen92 <92enen@gmail.com>
Date: Mon, 6 Feb 2023 15:36:11 +0000
Subject: [PATCH] video: remove ffmpeg bsf hack

Manually setting the codecID on the bsf filter is wrong.
avcodec_parameters_copy should be used instead.
---
 xbmc/cores/FFmpeg.cpp                               | 13 ++++++++-----
 xbmc/cores/FFmpeg.h                                 |  3 +--
 .../VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp      | 10 +++++++++-
 .../VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp      |  3 +--
 4 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/xbmc/cores/FFmpeg.cpp b/xbmc/cores/FFmpeg.cpp
index d071f6d8e33a3..73b7ea2ae875c 100644
--- a/xbmc/cores/FFmpeg.cpp
+++ b/xbmc/cores/FFmpeg.cpp
@@ -135,9 +135,7 @@ void ff_avutil_log(void* ptr, int level, const char* format, va_list va)
   buffer.erase(0, start);
 }
 
-std::tuple<uint8_t*, int> GetPacketExtradata(const AVPacket* pkt,
-                                             const AVCodecParserContext* parserCtx,
-                                             AVCodecContext* codecCtx)
+std::tuple<uint8_t*, int> GetPacketExtradata(const AVPacket* pkt, const AVCodecParameters* codecPar)
 {
   constexpr int FF_MAX_EXTRADATA_SIZE = ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE);
 
@@ -151,7 +149,7 @@ std::tuple<uint8_t*, int> GetPacketExtradata(const AVPacket* pkt,
    * for certain codecs, as noted in discussion of PR#21248
    */
 
-  AVCodecID codecId = codecCtx->codec_id;
+  AVCodecID codecId = codecPar->codec_id;
 
   // clang-format off
   if (
@@ -178,7 +176,12 @@ std::tuple<uint8_t*, int> GetPacketExtradata(const AVPacket* pkt,
   if (ret < 0)
     return std::make_tuple(nullptr, 0);
 
-  bsf->par_in->codec_id = codecId;
+  ret = avcodec_parameters_copy(bsf->par_in, codecPar);
+  if (ret < 0)
+  {
+    av_bsf_free(&bsf);
+    return std::make_tuple(nullptr, 0);
+  }
 
   ret = av_bsf_init(bsf);
   if (ret < 0)
diff --git a/xbmc/cores/FFmpeg.h b/xbmc/cores/FFmpeg.h
index 05547a0ba2b5f..5e35d58c6b0a6 100644
--- a/xbmc/cores/FFmpeg.h
+++ b/xbmc/cores/FFmpeg.h
@@ -73,5 +73,4 @@ class CFFmpegLog
 };
 
 std::tuple<uint8_t*, int> GetPacketExtradata(const AVPacket* pkt,
-                                             const AVCodecParserContext* parserCtx,
-                                             AVCodecContext* codecCtx);
+                                             const AVCodecParameters* codecPar);
diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp
index 052332331702a..9ca07b9a2dd39 100644
--- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp
+++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp
@@ -162,7 +162,15 @@ bool CDVDDemuxClient::ParsePacket(DemuxPacket* pkt)
     avpkt->size = pkt->iSize;
     avpkt->dts = avpkt->pts = AV_NOPTS_VALUE;
 
-    auto [retExtraData, len] = GetPacketExtradata(avpkt, stream->m_parser, stream->m_context);
+    AVCodecParameters* codecPar = nullptr;
+    int ret = avcodec_parameters_from_context(codecPar, stream->m_context);
+    if (ret < 0)
+    {
+      CLog::LogF(LOGERROR, "avcodec_parameters_from_context failed");
+      return false;
+    }
+
+    auto [retExtraData, len] = GetPacketExtradata(avpkt, codecPar);
     if (len > 0)
     {
       st->changes++;
diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
index 7e6a2e10616d7..bc6b54c87235d 100644
--- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
+++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
@@ -2290,8 +2290,7 @@ void CDVDDemuxFFmpeg::ParsePacket(AVPacket* pkt)
         parser->second->m_parserCtx->parser &&
         !st->codecpar->extradata)
     {
-      auto [retExtraData, i] =
-          GetPacketExtradata(pkt, parser->second->m_parserCtx, parser->second->m_codecCtx);
+      auto [retExtraData, i] = GetPacketExtradata(pkt, st->codecpar);
       if (i > 0)
       {
         st->codecpar->extradata_size = i;


From 3ad9588656e30abd421e48147b23aee9fb4b3557 Mon Sep 17 00:00:00 2001
From: Miguel Borges de Freitas <92enen@gmail.com>
Date: Sun, 12 Feb 2023 12:08:36 +0000
Subject: [PATCH] [video] fix crash in avcodec_parameters_from_context

---
 xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp
index 9ca07b9a2dd39..26fa9522eea7a 100644
--- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp
+++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxClient.cpp
@@ -162,11 +162,12 @@ bool CDVDDemuxClient::ParsePacket(DemuxPacket* pkt)
     avpkt->size = pkt->iSize;
     avpkt->dts = avpkt->pts = AV_NOPTS_VALUE;
 
-    AVCodecParameters* codecPar = nullptr;
+    AVCodecParameters* codecPar = avcodec_parameters_alloc();
     int ret = avcodec_parameters_from_context(codecPar, stream->m_context);
     if (ret < 0)
     {
       CLog::LogF(LOGERROR, "avcodec_parameters_from_context failed");
+      avcodec_parameters_free(&codecPar);
       return false;
     }
 
@@ -188,7 +189,7 @@ bool CDVDDemuxClient::ParsePacket(DemuxPacket* pkt)
         avcodec_close(stream->m_context);
       }
     }
-
+    avcodec_parameters_free(&codecPar);
     av_packet_free(&avpkt);
   }



From f30f1e6418ea60bc7cb081c59f5f1d9431d264e6 Mon Sep 17 00:00:00 2001
From: Lukas Rusak <lorusak@gmail.com>
Date: Sat, 11 Mar 2023 13:28:38 -0800
Subject: [PATCH 01/10] CDVDAudioCodecFFmpeg: ifdef use of
 AV_CODEC_FLAG_TRUNCATED for ffmpeg 6.0

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
---
 xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
index b2849c797dbc4..325bb0b7549ab 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
@@ -73,8 +73,10 @@ bool CDVDAudioCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options
   m_pCodecContext->debug = 0;
   m_pCodecContext->workaround_bugs = 1;
 
+#if LIBAVCODEC_VERSION_MAJOR < 60
   if (pCodec->capabilities & AV_CODEC_CAP_TRUNCATED)
     m_pCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
+#endif
 
   m_matrixEncoding = AV_MATRIX_ENCODING_NONE;
   m_channels = 0;

From 3b71910ee0bb650816456ecc9a21251aff650c4d Mon Sep 17 00:00:00 2001
From: Lukas Rusak <lorusak@gmail.com>
Date: Sat, 11 Mar 2023 13:29:18 -0800
Subject: [PATCH 02/10] CDVDAudioCodecFFmpeg: fix setting channel layout mask
 when opening codec

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
---
 .../DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp     | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
index 325bb0b7549ab..d1fb2cfe96afc 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
@@ -80,13 +80,21 @@
   m_channels = 0;
 #if LIBAVCODEC_BUILD >= AV_VERSION_INT(59, 37, 100) && \
     LIBAVUTIL_BUILD >= AV_VERSION_INT(57, 28, 100)
-  av_channel_layout_uninit(&m_pCodecContext->ch_layout);
-  m_pCodecContext->ch_layout.order = AV_CHANNEL_ORDER_NATIVE;
-  m_pCodecContext->ch_layout.nb_channels = hints.channels;
+  if (hints.channels > 0 && hints.channellayout > 0)
+  {
+    m_pCodecContext->ch_layout.order = AV_CHANNEL_ORDER_NATIVE;
+    m_pCodecContext->ch_layout.nb_channels = hints.channels;
+    m_pCodecContext->ch_layout.u.mask = hints.channellayout;
+  }
+  else if (hints.channels > 0)
+  {
+    av_channel_layout_default(&m_pCodecContext->ch_layout, hints.channels);
+  }
+
+  m_hint_layout = m_pCodecContext->ch_layout.u.mask;
 #else
   m_pCodecContext->channels = hints.channels;
 #endif
-  m_hint_layout = hints.channellayout;
   m_pCodecContext->sample_rate = hints.samplerate;
   m_pCodecContext->block_align = hints.blockalign;
   m_pCodecContext->bit_rate = hints.bitrate;

From f4fadb3ba4583c45fb06908a3eb352be8c29f235 Mon Sep 17 00:00:00 2001
From: Lukas Rusak <lorusak@gmail.com>
Date: Sat, 11 Mar 2023 13:29:34 -0800
Subject: [PATCH 03/10] CDVDAudioCodecFFmpeg: drop unneeded use of
 AVFMT_FLAG_PRIV_OPT

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
---
 xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
index bc6b54c87235d..016d198206716 100644
--- a/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
+++ b/xbmc/cores/VideoPlayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
@@ -323,7 +323,6 @@ bool CDVDDemuxFFmpeg::Open(const std::shared_ptr<CDVDInputStream>& pInput, bool
     }
     if (result < 0)
     {
-      m_pFormatContext->flags |= AVFMT_FLAG_PRIV_OPT;
       if (avformat_open_input(&m_pFormatContext, strFile.c_str(), iformat, &options) < 0)
       {
         CLog::Log(LOGDEBUG, "Error, could not open file {}", CURL::GetRedacted(strFile));
@@ -335,7 +334,6 @@ bool CDVDDemuxFFmpeg::Open(const std::shared_ptr<CDVDInputStream>& pInput, bool
       avformat_close_input(&m_pFormatContext);
       m_pFormatContext = avformat_alloc_context();
       m_pFormatContext->interrupt_callback = int_cb;
-      m_pFormatContext->flags &= ~AVFMT_FLAG_PRIV_OPT;
       AVDictionary* options = GetFFMpegOptionsFromInput();
       av_dict_set_int(&options, "load_all_variants", 0, AV_OPT_SEARCH_CHILDREN);
       if (avformat_open_input(&m_pFormatContext, strFile.c_str(), iformat, &options) < 0)

From 7d03f33b83e5fb127a7495798a20c3b63ac06795 Mon Sep 17 00:00:00 2001
From: Lukas Rusak <lorusak@gmail.com>
Date: Wed, 15 Mar 2023 19:58:56 -0700
Subject: [PATCH 04/10] CDVDVideoCodecFFmpeg: update filter args to use
 key/value pairs

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
---
 .../VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp      | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
index bb9c20bf9d06e..c080589896ce7 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
@@ -1164,8 +1164,9 @@ int CDVDVideoCodecFFmpeg::FilterOpen(const std::string& filters, bool scale)
   const AVFilter* outFilter = avfilter_get_by_name("buffersink"); // should be last filter in the graph for now
 
   std::string args = StringUtils::Format(
-      "{}:{}:{}:{}:{}:{}:{}", m_pCodecContext->width, m_pCodecContext->height,
-      m_pCodecContext->pix_fmt, m_pCodecContext->time_base.num ? m_pCodecContext->time_base.num : 1,
+      "video_size={}x{}:pix_fmt={}:time_base={}/{}:pixel_aspect={}/{}", m_pCodecContext->width,
+      m_pCodecContext->height, m_pCodecContext->pix_fmt,
+      m_pCodecContext->time_base.num ? m_pCodecContext->time_base.num : 1,
       m_pCodecContext->time_base.num ? m_pCodecContext->time_base.den : 1,
       m_pCodecContext->sample_aspect_ratio.num != 0 ? m_pCodecContext->sample_aspect_ratio.num : 1,
       m_pCodecContext->sample_aspect_ratio.num != 0 ? m_pCodecContext->sample_aspect_ratio.den : 1);

From 30bd7912802cf0f608751c452c48fc1a2eb8d91b Mon Sep 17 00:00:00 2001
From: Lukas Rusak <lorusak@gmail.com>
Date: Wed, 15 Mar 2023 19:59:27 -0700
Subject: [PATCH 05/10] CFFmpegPostproc: update filter args to use key/value
 pairs

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
---
 xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp
index 81b969d119667..6c4f664591a04 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp
@@ -2962,10 +2962,11 @@ bool CFFmpegPostproc::Init(EINTERLACEMETHOD method)
   const AVFilter* srcFilter = avfilter_get_by_name("buffer");
   const AVFilter* outFilter = avfilter_get_by_name("buffersink");
 
-  std::string args = StringUtils::Format("{}:{}:{}:{}:{}:{}:{}", m_config.vidWidth,
-                                         m_config.vidHeight, AV_PIX_FMT_NV12, 1, 1,
-                                         (m_config.aspect.num != 0) ? m_config.aspect.num : 1,
-                                         (m_config.aspect.num != 0) ? m_config.aspect.den : 1);
+  std::string args =
+      StringUtils::Format("video_size={}x{}:pix_fmt={}:time_base={}/{}:pixel_aspect={}/{}",
+                          m_config.vidWidth, m_config.vidHeight, AV_PIX_FMT_NV12, 1, 1,
+                          (m_config.aspect.num != 0) ? m_config.aspect.num : 1,
+                          (m_config.aspect.num != 0) ? m_config.aspect.den : 1);
 
   if (avfilter_graph_create_filter(&m_pFilterIn, srcFilter, "src", args.c_str(), NULL, m_pFilterGraph) < 0)
   {

From 54a21151374a2d40a2a452fae2709205ed8e8836 Mon Sep 17 00:00:00 2001
From: Lukas Rusak <lorusak@gmail.com>
Date: Sat, 11 Mar 2023 19:32:09 -0800
Subject: [PATCH 08/10] DXVA: CDecoder: replace removed av_mallocz_array with
 av_calloc

ref: https://ffmpeg.org/doxygen/5.0/group__lavu__mem__funcs.html\#ga6627f140c3f70847bc6d9690a2fd001f

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
---
 xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp
index a1bc3761c59d1..c06bd1ac0c7e6 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp
@@ -972,7 +972,8 @@ CDecoder::CDecoder(CProcessInfo& processInfo)
   m_event.Set();
   m_avD3D11Context = av_d3d11va_alloc_context();
   m_avD3D11Context->cfg = reinterpret_cast<D3D11_VIDEO_DECODER_CONFIG*>(av_mallocz(sizeof(D3D11_VIDEO_DECODER_CONFIG)));
-  m_avD3D11Context->surface = reinterpret_cast<ID3D11VideoDecoderOutputView**>(av_mallocz_array(32, sizeof(ID3D11VideoDecoderOutputView*)));
+  m_avD3D11Context->surface = reinterpret_cast<ID3D11VideoDecoderOutputView**>(
+      av_calloc(32, sizeof(ID3D11VideoDecoderOutputView*)));
   m_bufferPool.reset();
 
   DX::Windowing()->Register(this);

From be1247d627cee6561174467094f1e8a46357df79 Mon Sep 17 00:00:00 2001
From: Lukas Rusak <lorusak@gmail.com>
Date: Sat, 11 Mar 2023 19:45:46 -0800
Subject: [PATCH 09/10] CFFmpegImage: remove deprecated use of pkt_duration

ref: https://ffmpeg.org/doxygen/6.0/structAVFrame.html\#a91725a40000e348b0607adf7f577e646

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
---
 xbmc/guilib/FFmpegImage.cpp | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/xbmc/guilib/FFmpegImage.cpp b/xbmc/guilib/FFmpegImage.cpp
index e71980998b2e5..7171c046a9ce5 100644
--- a/xbmc/guilib/FFmpegImage.cpp
+++ b/xbmc/guilib/FFmpegImage.cpp
@@ -294,7 +294,15 @@ AVFrame* CFFmpegImage::ExtractFrame()
     return nullptr;
   }
   //we need milliseconds
-  frame->pkt_duration = av_rescale_q(frame->pkt_duration, m_fctx->streams[0]->time_base, AVRational{ 1, 1000 });
+
+#if LIBAVCODEC_VERSION_MAJOR < 60
+  frame->pkt_duration =
+      av_rescale_q(frame->pkt_duration, m_fctx->streams[0]->time_base, AVRational{1, 1000});
+#else
+  frame->duration =
+      av_rescale_q(frame->duration, m_fctx->streams[0]->time_base, AVRational{1, 1000});
+#endif
+
   m_height = frame->height;
   m_width = frame->width;
   m_originalWidth = m_width;
@@ -745,7 +753,13 @@ std::shared_ptr<Frame> CFFmpegImage::ReadFrame()
   if (avframe == nullptr)
     return nullptr;
   std::shared_ptr<Frame> frame(new Frame());
+
+#if LIBAVCODEC_VERSION_MAJOR < 60
   frame->m_delay = (unsigned int)avframe->pkt_duration;
+#else
+  frame->m_delay = (unsigned int)avframe->duration;
+#endif
+
   frame->m_pitch = avframe->width * 4;
   frame->m_pImage = (unsigned char*) av_malloc(avframe->height * frame->m_pitch);
   DecodeFrame(avframe, avframe->width, avframe->height, frame->m_pitch, frame->m_pImage);

From c12af890b0973f7c86316087e823f8a31c6b2ed3 Mon Sep 17 00:00:00 2001
From: Lukas Rusak <lorusak@gmail.com>
Date: Sat, 11 Mar 2023 19:45:01 -0800
Subject: [PATCH 10/10] CDVDVideoCodecFFmpeg: remove deprecated use of
 reordered_opaque

ref: https://ffmpeg.org/doxygen/6.0/structAVFrame.html#a12f572ed19a2cba6be3790393cee76b5

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
---
 .../DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp           | 11 ++++++++++-
 xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp       |  6 ++++--
 xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp      |  3 +++
 xbmc/cores/VideoPlayer/DVDCodecs/Video/VDPAU.cpp      |  5 ++++-
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
index c080589896ce7..6a53ade4a7351 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
@@ -370,6 +370,10 @@ bool CDVDVideoCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options
   m_pCodecContext->get_format = GetFormat;
   m_pCodecContext->codec_tag = hints.codec_tag;
 
+#if LIBAVCODEC_VERSION_MAJOR >= 60
+  m_pCodecContext->flags = AV_CODEC_FLAG_COPY_OPAQUE;
+#endif
+
   // setup threading model
   if (!(hints.codecOptions & CODEC_FORCE_SOFTWARE))
   {
@@ -545,9 +549,10 @@ void CDVDVideoCodecFFmpeg::UpdateName()
   CLog::Log(LOGDEBUG, "CDVDVideoCodecFFmpeg - Updated codec: {}", m_name);
 }
 
+#if LIBAVCODEC_VERSION_MAJOR < 60
 union pts_union
 {
-  double  pts_d;
+  double pts_d;
   int64_t pts_i;
 };
 
@@ -557,6 +562,7 @@ static int64_t pts_dtoi(double pts)
   u.pts_d = pts;
   return u.pts_i;
 }
+#endif
 
 bool CDVDVideoCodecFFmpeg::AddData(const DemuxPacket &packet)
 {
@@ -575,7 +581,10 @@ bool CDVDVideoCodecFFmpeg::AddData(const DemuxPacket &packet)
     m_started = true;
 
   m_dts = packet.dts;
+
+#if LIBAVCODEC_VERSION_MAJOR < 60
   m_pCodecContext->reordered_opaque = pts_dtoi(packet.pts);
+#endif
 
   AVPacket* avpkt = av_packet_alloc();
   if (!avpkt)
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp
index c06bd1ac0c7e6..81451995ca1db 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp
@@ -1538,8 +1538,6 @@ int CDecoder::GetBuffer(AVCodecContext* avctx, AVFrame* pic)
     return -1;
   }
 
-  pic->reordered_opaque = avctx->reordered_opaque;
-
   for (unsigned i = 0; i < 4; i++)
   {
     pic->data[i] = nullptr;
@@ -1556,6 +1554,10 @@ int CDecoder::GetBuffer(AVCodecContext* avctx, AVFrame* pic)
   }
   pic->buf[0] = buffer;
 
+#if LIBAVCODEC_VERSION_MAJOR < 60
+  pic->reordered_opaque = avctx->reordered_opaque;
+#endif
+
   Acquire();
 
   return 0;
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp
index 6c4f664591a04..447a13495d4e8 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/VAAPI.cpp
@@ -867,7 +867,10 @@ int CDecoder::FFGetBuffer(AVCodecContext *avctx, AVFrame *pic, int flags)
   }
   pic->buf[0] = buffer;
 
+#if LIBAVCODEC_VERSION_MAJOR < 60
   pic->reordered_opaque = avctx->reordered_opaque;
+#endif
+
   va->Acquire();
   return 0;
 }
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/VDPAU.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/VDPAU.cpp
index ec07af79de819..50e16d492ebc7 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/VDPAU.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/VDPAU.cpp
@@ -1041,7 +1041,10 @@ int CDecoder::FFGetBuffer(AVCodecContext *avctx, AVFrame *pic, int flags)
   }
   pic->buf[0] = buffer;
 
-  pic->reordered_opaque= avctx->reordered_opaque;
+#if LIBAVCODEC_VERSION_MAJOR < 60
+  pic->reordered_opaque = avctx->reordered_opaque;
+#endif
+
   return 0;
 }
 

From 928a7e4196046154419727a23c734d904e5e1b6c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Markus=20H=C3=A4rer?= <markus.haerer@gmx.net>
Date: Sun, 23 Apr 2023 23:29:28 +0200
Subject: [PATCH] FFmpegImage: Switch back to jpeg_pipe for FFmpeg>=6.0

---
 xbmc/guilib/FFmpegImage.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/xbmc/guilib/FFmpegImage.cpp b/xbmc/guilib/FFmpegImage.cpp
index 7171c046a9ce5..429037740a7d2 100644
--- a/xbmc/guilib/FFmpegImage.cpp
+++ b/xbmc/guilib/FFmpegImage.cpp
@@ -198,9 +198,16 @@ bool CFFmpegImage::Initialize(unsigned char* buffer, size_t bufSize)
   bool is_png = (bufSize > 3 && buffer[1] == 'P' && buffer[2] == 'N' && buffer[3] == 'G');
   bool is_tiff = (bufSize > 2 && buffer[0] == 'I' && buffer[1] == 'I' && buffer[2] == '*');
 
+  // See Github #19113
+#if LIBAVCODEC_VERSION_MAJOR < 60
+  constexpr char jpegFormat[] = "image2";
+#else
+  constexpr char jpegFormat[] = "jpeg_pipe";
+#endif
+
   FFMPEG_FMT_CONST AVInputFormat* inp = nullptr;
   if (is_jpeg)
-    inp = av_find_input_format("image2");
+    inp = av_find_input_format(jpegFormat);
   else if (m_strMimeType == "image/apng")
     inp = av_find_input_format("apng");
   else if (is_png)
@@ -213,7 +220,7 @@ bool CFFmpegImage::Initialize(unsigned char* buffer, size_t bufSize)
     inp = av_find_input_format("webp_pipe");
   // brute force parse if above check already failed
   else if (m_strMimeType == "image/jpeg" || m_strMimeType == "image/jpg")
-    inp = av_find_input_format("image2");
+    inp = av_find_input_format(jpegFormat);
   else if (m_strMimeType == "image/png")
     inp = av_find_input_format("png_pipe");
   else if (m_strMimeType == "image/tiff")


From 9d7f4dfd00d89d4a5d6d8095ee9b0b746051b30c Mon Sep 17 00:00:00 2001
From: CrystalP <crystalp@kodi.tv>
Date: Mon, 1 May 2023 13:26:56 -0400
Subject: [PATCH] [fix] extern C for ffmpeg includes

---
 xbmc/cores/RetroPlayer/process/RPProcessInfo.h                | 3 +++
 xbmc/cores/RetroPlayer/rendering/RenderTranslator.h           | 3 +++
 xbmc/cores/VideoPlayer/DVDFileInfo.cpp                        | 4 ++--
 xbmc/cores/VideoPlayer/VideoRenderers/windows/RendererDXVA.h  | 4 ++++
 .../VideoPlayer/VideoRenderers/windows/RendererShaders.h      | 4 ++++
 5 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/xbmc/cores/RetroPlayer/process/RPProcessInfo.h b/xbmc/cores/RetroPlayer/process/RPProcessInfo.h
index 9f930e78e9d84..f5ffe670d68aa 100644
--- a/xbmc/cores/RetroPlayer/process/RPProcessInfo.h
+++ b/xbmc/cores/RetroPlayer/process/RPProcessInfo.h
@@ -17,7 +17,10 @@
 #include <string>
 #include <vector>
 
+extern "C"
+{
 #include <libavutil/pixfmt.h>
+}
 
 class CDataCacheCore;
 
diff --git a/xbmc/cores/RetroPlayer/rendering/RenderTranslator.h b/xbmc/cores/RetroPlayer/rendering/RenderTranslator.h
index 575ad814fc125..d78e1c25e4070 100644
--- a/xbmc/cores/RetroPlayer/rendering/RenderTranslator.h
+++ b/xbmc/cores/RetroPlayer/rendering/RenderTranslator.h
@@ -10,7 +10,10 @@
 
 #include "cores/GameSettings.h"
 
+extern "C"
+{
 #include <libavutil/pixfmt.h>
+}
 
 namespace KODI
 {
diff --git a/xbmc/cores/VideoPlayer/DVDFileInfo.cpp b/xbmc/cores/VideoPlayer/DVDFileInfo.cpp
index 0860b40475b18..c7253bbd5497f 100644
--- a/xbmc/cores/VideoPlayer/DVDFileInfo.cpp
+++ b/xbmc/cores/VideoPlayer/DVDFileInfo.cpp
@@ -32,8 +32,6 @@
 #include "DVDDemuxers/DVDDemuxVobsub.h"
 #include "Process/ProcessInfo.h"
 
-#include <libavcodec/avcodec.h>
-#include <libswscale/swscale.h>
 #include "filesystem/File.h"
 #include "cores/FFmpeg.h"
 #include "TextureCache.h"
@@ -44,7 +42,9 @@
 #include <memory>
 
 extern "C" {
+#include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
+#include <libswscale/swscale.h>
 }
 
 bool CDVDFileInfo::GetFileDuration(const std::string &path, int& duration)
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/windows/RendererDXVA.h b/xbmc/cores/VideoPlayer/VideoRenderers/windows/RendererDXVA.h
index 9412377157f94..0eed9503dc9ac 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/windows/RendererDXVA.h
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/windows/RendererDXVA.h
@@ -13,7 +13,11 @@
 #include <map>
 
 #include <d3d11_4.h>
+
+extern "C"
+{
 #include <libavutil/pixfmt.h>
+}
 
 enum RenderMethod;
 
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/windows/RendererShaders.h b/xbmc/cores/VideoPlayer/VideoRenderers/windows/RendererShaders.h
index 945cadda76841..af4d677aae923 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/windows/RendererShaders.h
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/windows/RendererShaders.h
@@ -13,7 +13,11 @@
 #include <map>
 
 #include <d3d11_4.h>
+
+extern "C"
+{
 #include <libavutil/pixfmt.h>
+}
 
 #define PLANE_Y 0
 #define PLANE_U 1