-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmplayer-1.5-vaapi.patch
1213 lines (1180 loc) · 40.1 KB
/
mplayer-1.5-vaapi.patch
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
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --color -rupN old/codec-cfg.c new/codec-cfg.c
--- old/codec-cfg.c 2021-01-23 20:05:29.000000000 +0100
+++ new/codec-cfg.c 2023-07-07 08:00:42.159364119 +0200
@@ -265,6 +265,13 @@ static const struct {
{"VDPAU_MPEG4", IMGFMT_VDPAU_MPEG4},
{"VDPAU_HEVC", IMGFMT_VDPAU_HEVC},
+ {"VAAPI_MPEG2", IMGFMT_VAAPI_MPEG2},
+ {"VAAPI_H264", IMGFMT_VAAPI_H264},
+ {"VAAPI_WMV3", IMGFMT_VAAPI_WMV3},
+ {"VAAPI_VC1", IMGFMT_VAAPI_VC1},
+ {"VAAPI_MPEG4", IMGFMT_VAAPI_MPEG4},
+ {"VAAPI_HEVC", IMGFMT_VAAPI_HEVC},
+
{NULL, 0}
};
diff --color -rupN old/configure new/configure
--- old/configure 2023-04-19 21:50:12.000000000 +0200
+++ new/configure 2023-07-07 08:08:00.361657077 +0200
@@ -501,6 +501,7 @@ Video output:
--enable-xvmc enable XvMC acceleration [disable]
--enable-vda enable VDA acceleration [autodetect]
--enable-vdpau enable VDPAU acceleration [autodetect]
+ --enable-vaapi enable VAAPI acceleration [autodetect]
--enable-vm enable XF86VidMode support [autodetect]
--enable-xinerama enable Xinerama support [autodetect]
--enable-x11 enable X11 video output [autodetect]
@@ -702,6 +703,7 @@ _xv=auto
_xvmc=no #auto when complete
_vda=auto
_vdpau=auto
+_vaapi=auto
_sdl=auto
_kva=auto
_direct3d=auto
@@ -1057,6 +1059,8 @@ for ac_option do
--disable-vda) _vda=no ;;
--enable-vdpau) _vdpau=yes ;;
--disable-vdpau) _vdpau=no ;;
+ --enable-vaapi) _vaapi=yes ;;
+ --disable-vaapi) _vaapi=no ;;
--enable-sdl) _sdl=yes ;;
--disable-sdl) _sdl=no ;;
--enable-kva) _kva=yes ;;
@@ -5108,6 +5112,26 @@ fi
echores "$_vdpau"
+echocheck "VAAPI"
+if test "$_vaapi" = auto && test "$_x11" = yes ; then
+ _vaapi=no
+ if test "$_dl" = yes ; then
+ statement_check va/va_x11.h 'vaGetDisplay(0)' -lva -lva-x11 && _vaapi=yes
+ fi
+fi
+if test "$_vaapi" = yes ; then
+ def_vaapi='#define CONFIG_VAAPI 1'
+ libs_mplayer="$libs_mplayer -lva -lva-x11"
+ vomodules="vaapi $vomodules"
+ libavhwaccels="$libavhwaccels H263_VAAPI_HWACCEL H264_VAAPI_HWACCEL HEVC_VAAPI_HWACCEL MPEG2_VAAPI_HWACCEL MPEG4_VAAPI_HWACCEL VC1_VAAPI_HWACCEL WMV3_VAAPI_HWACCEL"
+else
+ def_vaapi='#define CONFIG_VAAPI 0'
+ novomodules="vaapi $novomodules"
+ libavdecoders=$(filter_out_component decoder '[A-Z0-9]*_VAAPI')
+fi
+echores "$_vaapi"
+
+
echocheck "Xinerama"
if test "$_xinerama" = auto && test "$_x11" = yes ; then
_xinerama=no
@@ -8845,6 +8869,7 @@ V4L2 = $_v4l2
VCD = $_vcd
VDA = $_vda
VDPAU = $_vdpau
+VAAPI = $_vaapi
VESA = $_vesa
VIDIX = $_vidix
VIDIX_PCIDB = $_vidix_pcidb_val
@@ -9046,6 +9071,7 @@ CONFIG_RTPDEC = $networking
CONFIG_VF_LAVFI = $_vf_lavfi
CONFIG_VDA = $_vda
CONFIG_VDPAU = $_vdpau
+CONFIG_VAAPI = $_vaapi
CONFIG_XVMC = $_xvmc
CONFIG_ZLIB = $_zlib
@@ -9432,6 +9458,7 @@ $def_tdfxvid
$def_tga
$def_v4l2
$def_vdpau
+$def_vaapi
$def_vesa
$def_vidix
$def_vidix_drv_cyberblade
@@ -9602,7 +9629,6 @@ $def_openssl
#define CONFIG_SWSCALE_ALPHA 1
#define SWS_MAX_FILTER_SIZE 256
#define CONFIG_QSV 0
-#define CONFIG_VAAPI 0
#define CONFIG_VALGRIND_BACKTRACE 0
/* related to HW accelarations */
diff --color -rupN old/etc/codecs.conf new/etc/codecs.conf
--- old/etc/codecs.conf 2022-02-27 16:03:16.000000000 +0100
+++ new/etc/codecs.conf 2023-07-07 08:02:18.519337570 +0200
@@ -504,6 +504,7 @@ videocodec ffmpeg2
out 422P,444P
out IDCT_MPEG2
out MOCO_MPEG2
+ out VAAPI_MPEG2
; for backward compatibility
videocodec ffmpeg12
@@ -1377,6 +1378,7 @@ videocodec ffwmv3
driver ffmpeg
dll wmv3
out YV12,I420,IYUV
+ out VAAPI_WMV3
videocodec ffwvp2
info "FFmpeg WVP2"
@@ -1418,6 +1420,7 @@ videocodec ffvc1
driver ffmpeg
dll vc1
out YV12,I420,IYUV
+ out VAAPI_VC1
videocodec ffvc1vdpau
info "FFmpeg WVC1 (VDPAU)"
@@ -1473,6 +1476,7 @@ videocodec ffhevc
out 422P,422P9,422P10,444P12
out 444P,444P9,444P10,444P12
out GBR24P,GBR10P,GBR12P
+ out VAAPI_HEVC
videocodec ffhevcvdpau
info "FFmpeg HEVC / H.265 (VDPAU)"
@@ -1508,6 +1512,7 @@ videocodec ffh264
out 422P,422P9,422P10,444P12,444P14
out 444P,444P9,444P10,444P12,444P14
out GBR24P,GBR12P,GBR14P
+ out VAAPI_H264
videocodec ffh264vdpau
info "FFmpeg H.264 (VDPAU)"
@@ -1635,6 +1640,7 @@ videocodec ffodivx
driver ffmpeg
dll mpeg4 ;opendivx
out YV12,I420,IYUV
+ out VAAPI_MPEG4
videocodec ffodivxvdpau
info "FFmpeg MPEG-4,DIVX-4/5 (VDPAU)"
diff --color -rupN old/ffmpeg/config.mak new/ffmpeg/config.mak
--- old/ffmpeg/config.mak 1970-01-01 01:00:00.000000000 +0100
+++ new/ffmpeg/config.mak 2023-07-07 08:08:23.018615258 +0200
@@ -0,0 +1,4 @@
+ifndef FFMPEG_CONFIG_MAK
+FFMPEG_CONFIG_MAK = 1
+include ../config.mak
+endif # FFMPEG_CONFIG_MAK
diff --color -rupN old/ffmpeg/libavcodec/Makefile new/ffmpeg/libavcodec/Makefile
--- old/ffmpeg/libavcodec/Makefile 2023-02-27 21:43:45.000000000 +0100
+++ new/ffmpeg/libavcodec/Makefile 2023-07-07 07:55:15.052215925 +0200
@@ -20,6 +20,7 @@ HEADERS = ac3_parser.h
mediacodec.h \
packet.h \
qsv.h \
+ vaapi.h \
vdpau.h \
version.h \
version_major.h \
diff --color -rupN old/ffmpeg/libavcodec/vaapi_decode.c new/ffmpeg/libavcodec/vaapi_decode.c
--- old/ffmpeg/libavcodec/vaapi_decode.c 2023-02-27 21:43:45.000000000 +0100
+++ new/ffmpeg/libavcodec/vaapi_decode.c 2023-07-07 08:26:16.905192037 +0200
@@ -28,6 +28,7 @@
#include "vaapi_decode.h"
#include "vaapi_hevc.h"
+#define CONFIG_VAAPI_1 0
int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
VAAPIDecodePicture *pic,
@@ -661,6 +662,46 @@ int ff_vaapi_decode_init(AVCodecContext
ctx->va_config = VA_INVALID_ID;
ctx->va_context = VA_INVALID_ID;
+#if FF_API_STRUCT_VAAPI_CONTEXT
+ if (avctx->hwaccel_context) {
+ av_log(avctx, AV_LOG_WARNING, "Using deprecated struct "
+ "vaapi_context in decode.\n");
+
+ ctx->have_old_context = 1;
+ ctx->old_context = avctx->hwaccel_context;
+
+ // Really we only want the VAAPI device context, but this
+ // allocates a whole generic device context because we don't
+ // have any other way to determine how big it should be.
+ ctx->device_ref =
+ av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_VAAPI);
+ if (!ctx->device_ref) {
+ err = AVERROR(ENOMEM);
+ goto fail;
+ }
+ ctx->device = (AVHWDeviceContext*)ctx->device_ref->data;
+ ctx->hwctx = ctx->device->hwctx;
+
+ ctx->hwctx->display = ctx->old_context->display;
+
+ // The old VAAPI decode setup assumed this quirk was always
+ // present, so set it here to avoid the behaviour changing.
+ ctx->hwctx->driver_quirks =
+ AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS;
+
+ }
+#endif
+
+#if FF_API_STRUCT_VAAPI_CONTEXT
+ if (ctx->have_old_context) {
+ ctx->va_config = ctx->old_context->config_id;
+ ctx->va_context = ctx->old_context->context_id;
+
+ av_log(avctx, AV_LOG_DEBUG, "Using user-supplied decoder "
+ "context: %#x/%#x.\n", ctx->va_config, ctx->va_context);
+ } else {
+#endif
+
err = ff_decode_get_hw_frames_ctx(avctx, AV_HWDEVICE_TYPE_VAAPI);
if (err < 0)
goto fail;
@@ -690,6 +731,9 @@ int ff_vaapi_decode_init(AVCodecContext
av_log(avctx, AV_LOG_DEBUG, "Decode context initialised: "
"%#x/%#x.\n", ctx->va_config, ctx->va_context);
+#if FF_API_STRUCT_VAAPI_CONTEXT
+ }
+#endif
return 0;
@@ -703,6 +747,12 @@ int ff_vaapi_decode_uninit(AVCodecContex
VAAPIDecodeContext *ctx = avctx->internal->hwaccel_priv_data;
VAStatus vas;
+#if FF_API_STRUCT_VAAPI_CONTEXT
+ if (ctx->have_old_context) {
+ av_buffer_unref(&ctx->device_ref);
+ } else {
+#endif
+
if (ctx->va_context != VA_INVALID_ID) {
vas = vaDestroyContext(ctx->hwctx->display, ctx->va_context);
if (vas != VA_STATUS_SUCCESS) {
@@ -720,5 +770,9 @@ int ff_vaapi_decode_uninit(AVCodecContex
}
}
+#if FF_API_STRUCT_VAAPI_CONTEXT
+ }
+#endif
+
return 0;
}
diff --color -rupN old/ffmpeg/libavcodec/vaapi_decode.h new/ffmpeg/libavcodec/vaapi_decode.h
--- old/ffmpeg/libavcodec/vaapi_decode.h 2022-11-04 21:16:28.000000000 +0100
+++ new/ffmpeg/libavcodec/vaapi_decode.h 2023-07-07 07:55:15.054216003 +0200
@@ -27,6 +27,11 @@
#include "avcodec.h"
+#include "version.h"
+#if FF_API_STRUCT_VAAPI_CONTEXT
+#include "vaapi.h"
+#endif
+
static inline VASurfaceID ff_vaapi_get_surface_id(AVFrame *pic)
{
return (uintptr_t)pic->data[3];
@@ -51,6 +56,14 @@ typedef struct VAAPIDecodeContext {
VAConfigID va_config;
VAContextID va_context;
+#if FF_API_STRUCT_VAAPI_CONTEXT
+FF_DISABLE_DEPRECATION_WARNINGS
+ int have_old_context;
+ struct vaapi_context *old_context;
+ AVBufferRef *device_ref;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
AVHWDeviceContext *device;
AVVAAPIDeviceContext *hwctx;
diff --color -rupN old/ffmpeg/libavcodec/vaapi.h new/ffmpeg/libavcodec/vaapi.h
--- old/ffmpeg/libavcodec/vaapi.h 1970-01-01 01:00:00.000000000 +0100
+++ new/ffmpeg/libavcodec/vaapi.h 2023-07-07 07:55:15.052215925 +0200
@@ -0,0 +1,86 @@
+/*
+ * Video Acceleration API (shared data between FFmpeg and the video player)
+ * HW decode acceleration for MPEG-2, MPEG-4, H.264 and VC-1
+ *
+ * Copyright (C) 2008-2009 Splitted-Desktop Systems
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_VAAPI_H
+#define AVCODEC_VAAPI_H
+
+/**
+ * @file
+ * @ingroup lavc_codec_hwaccel_vaapi
+ * Public libavcodec VA API header.
+ */
+
+#include <stdint.h>
+#include "libavutil/attributes.h"
+#include "version.h"
+
+#if FF_API_STRUCT_VAAPI_CONTEXT
+
+/**
+ * @defgroup lavc_codec_hwaccel_vaapi VA API Decoding
+ * @ingroup lavc_codec_hwaccel
+ * @{
+ */
+
+/**
+ * This structure is used to share data between the FFmpeg library and
+ * the client video application.
+ * This shall be zero-allocated and available as
+ * AVCodecContext.hwaccel_context. All user members can be set once
+ * during initialization or through each AVCodecContext.get_buffer()
+ * function call. In any case, they must be valid prior to calling
+ * decoding functions.
+ *
+ * Deprecated: use AVCodecContext.hw_frames_ctx instead.
+ */
+struct attribute_deprecated vaapi_context {
+ /**
+ * Window system dependent data
+ *
+ * - encoding: unused
+ * - decoding: Set by user
+ */
+ void *display;
+
+ /**
+ * Configuration ID
+ *
+ * - encoding: unused
+ * - decoding: Set by user
+ */
+ uint32_t config_id;
+
+ /**
+ * Context ID (video decode pipeline)
+ *
+ * - encoding: unused
+ * - decoding: Set by user
+ */
+ uint32_t context_id;
+};
+
+/* @} */
+
+#endif /* FF_API_STRUCT_VAAPI_CONTEXT */
+
+#endif /* AVCODEC_VAAPI_H */
diff --color -rupN old/ffmpeg/libavcodec/version_major.h new/ffmpeg/libavcodec/version_major.h
--- old/ffmpeg/libavcodec/version_major.h 2023-02-27 21:43:45.000000000 +0100
+++ new/ffmpeg/libavcodec/version_major.h 2023-07-07 07:58:12.981291943 +0200
@@ -45,6 +45,7 @@
#define FF_API_AVCODEC_CHROMA_POS (LIBAVCODEC_VERSION_MAJOR < 61)
#define FF_API_VT_HWACCEL_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 61)
#define FF_API_AVCTX_FRAME_NUMBER (LIBAVCODEC_VERSION_MAJOR < 61)
+#define FF_API_STRUCT_VAAPI_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 61)
// reminder to remove CrystalHD decoders on next major bump
#define FF_CODEC_CRYSTAL_HD (LIBAVCODEC_VERSION_MAJOR < 61)
diff --color -rupN old/ffmpeg/libavutil/hwcontext_vaapi.c new/ffmpeg/libavutil/hwcontext_vaapi.c
--- old/ffmpeg/libavutil/hwcontext_vaapi.c 2023-02-27 21:43:45.000000000 +0100
+++ new/ffmpeg/libavutil/hwcontext_vaapi.c 2023-07-07 08:22:59.738104684 +0200
@@ -17,6 +17,8 @@
*/
#include "config.h"
+#define HAVE_VAAPI_X11 0
+#define HAVE_VAAPI_DRM 0
#if HAVE_VAAPI_X11
# include <va/va_x11.h>
diff --color -rupN old/fmt-conversion.c new/fmt-conversion.c
--- old/fmt-conversion.c 2016-02-21 01:50:57.000000000 +0100
+++ new/fmt-conversion.c 2023-07-07 08:00:42.161364201 +0200
@@ -147,6 +147,7 @@ enum AVPixelFormat imgfmt2pixfmt(int fmt
int i;
enum AVPixelFormat pix_fmt;
if (IMGFMT_IS_VDPAU(fmt)) return AV_PIX_FMT_VDPAU;
+ if (IMGFMT_IS_VAAPI(fmt)) return AV_PIX_FMT_VAAPI;
for (i = 0; conversion_map[i].fmt; i++)
if (conversion_map[i].fmt == fmt)
break;
diff --color -rupN old/libmpcodecs/img_format.c new/libmpcodecs/img_format.c
--- old/libmpcodecs/img_format.c 2016-02-21 01:50:57.000000000 +0100
+++ new/libmpcodecs/img_format.c 2023-07-07 08:00:42.161364201 +0200
@@ -148,6 +148,12 @@ const char *vo_format_name(int format)
case IMGFMT_VDPAU_WMV3: return "WMV3 VDPAU acceleration";
case IMGFMT_VDPAU_VC1: return "VC1 VDPAU acceleration";
case IMGFMT_VDPAU_HEVC: return "HEVC VDPAU acceleration";
+ case IMGFMT_VAAPI_MPEG2: return "MPEG2 VAAPI acceleration";
+ case IMGFMT_VAAPI_H264: return "H.264 VAAPI acceleration";
+ case IMGFMT_VAAPI_MPEG4: return "MPEG-4 Part 2 VAAPI acceleration";
+ case IMGFMT_VAAPI_WMV3: return "WMV3 VAAPI acceleration";
+ case IMGFMT_VAAPI_VC1: return "VC1 VAAPI acceleration";
+ case IMGFMT_VAAPI_HEVC: return "HEVC VAAPI acceleration";
}
snprintf(unknown_format,20,"Unknown 0x%04x",format);
return unknown_format;
diff --color -rupN old/libmpcodecs/img_format.h new/libmpcodecs/img_format.h
--- old/libmpcodecs/img_format.h 2016-02-21 01:50:57.000000000 +0100
+++ new/libmpcodecs/img_format.h 2023-07-07 08:00:42.161364201 +0200
@@ -304,7 +304,19 @@ static inline int normalize_yuvp16(int f
#define IMGFMT_VDPAU_MPEG4 (IMGFMT_VDPAU|0x06)
#define IMGFMT_VDPAU_HEVC (IMGFMT_VDPAU|0x07)
-#define IMGFMT_IS_HWACCEL(fmt) (IMGFMT_IS_VDPAU(fmt) || IMGFMT_IS_XVMC(fmt))
+#define IMGFMT_VAAPI 0x1DC90000
+#define IMGFMT_VAAPI_MASK 0xFFFF0000
+#define IMGFMT_IS_VAAPI(fmt) (((fmt) & IMGFMT_VAAPI_MASK) == IMGFMT_VAAPI)
+// (Or values match the VAProfile in libva, in case that's ever useful.)
+#define IMGFMT_VAAPI_MPEG2 (IMGFMT_VAAPI | 1)
+#define IMGFMT_VAAPI_MPEG4 (IMGFMT_VAAPI | 3)
+#define IMGFMT_VAAPI_H264 (IMGFMT_VAAPI | 7)
+#define IMGFMT_VAAPI_WMV3 (IMGFMT_VAAPI | 9)
+#define IMGFMT_VAAPI_VC1 (IMGFMT_VAAPI | 10)
+#define IMGFMT_VAAPI_HEVC (IMGFMT_VAAPI | 17)
+
+#define IMGFMT_IS_HWACCEL(fmt) (IMGFMT_IS_VDPAU(fmt) || IMGFMT_IS_XVMC(fmt) || \
+ IMGFMT_IS_VAAPI(fmt))
typedef struct {
void* data;
diff --color -rupN old/libmpcodecs/vd_ffmpeg.c new/libmpcodecs/vd_ffmpeg.c
--- old/libmpcodecs/vd_ffmpeg.c 2022-08-07 20:20:47.000000000 +0200
+++ new/libmpcodecs/vd_ffmpeg.c 2023-07-07 08:00:42.163364283 +0200
@@ -41,6 +41,9 @@
#include "libavcodec/vdpau.h"
#include "vdpau_frame_data.h"
#endif
+#if CONFIG_VAAPI
+#include "libavcodec/vaapi.h"
+#endif
#include "libavutil/pixdesc.h"
static const vd_info_t info = {
@@ -92,7 +95,11 @@ typedef struct {
int b_count;
AVRational last_sample_aspect_ratio;
int palette_sent;
- int use_vdpau;
+ enum {
+ HWACCEL_MODE_NONE,
+ HWACCEL_MODE_VDPAU,
+ HWACCEL_MODE_VAAPI,
+ } hwaccel_mode;
} vd_ffmpeg_ctx;
#include "m_option.h"
@@ -240,6 +247,15 @@ static int pixfmt2imgfmt2(enum AVPixelFo
case AV_CODEC_ID_VC1: return IMGFMT_VDPAU_VC1;
case AV_CODEC_ID_HEVC: return IMGFMT_VDPAU_HEVC;
}
+ if (fmt == AV_PIX_FMT_VAAPI)
+ switch (cid) {
+ case AV_CODEC_ID_H264: return IMGFMT_VAAPI_H264;
+ case AV_CODEC_ID_MPEG2VIDEO: return IMGFMT_VAAPI_MPEG2;
+ case AV_CODEC_ID_MPEG4: return IMGFMT_VAAPI_MPEG4;
+ case AV_CODEC_ID_WMV3: return IMGFMT_VAAPI_WMV3;
+ case AV_CODEC_ID_VC1: return IMGFMT_VAAPI_VC1;
+ case AV_CODEC_ID_HEVC: return IMGFMT_VAAPI_HEVC;
+ }
return pixfmt2imgfmt(fmt);
}
@@ -285,30 +301,55 @@ static void set_format_params(struct AVC
int imgfmt;
if (fmt == AV_PIX_FMT_NONE)
return;
- ctx->use_vdpau = fmt == AV_PIX_FMT_VDPAU;
imgfmt = pixfmt2imgfmt2(fmt, avctx->codec_id);
+ switch(fmt) {
#if CONFIG_VDPAU
- if (!ctx->use_vdpau) {
+ case AV_PIX_FMT_VDPAU:
+ ctx->hwaccel_mode = HWACCEL_MODE_VDPAU;
+ {
+ AVVDPAUContext *vdpc = avctx->hwaccel_context;
+ if (!vdpc)
+ avctx->hwaccel_context = vdpc = av_alloc_vdpaucontext();
+ vdpc->render2 = vdpau_render_wrapper;
+ }
+ break;
+#endif
+#if CONFIG_VAAPI
+ case AV_PIX_FMT_VAAPI:
+ ctx->hwaccel_mode = HWACCEL_MODE_VAAPI;
+ {
+ struct vaapi_context *vctx = avctx->hwaccel_context;
+ if(!vctx) {
+ vctx = calloc(1, sizeof(struct vaapi_context));
+
+ extern void vo_vaapi_set_hwaccel_context(struct vaapi_context *hwaccel);
+ vo_vaapi_set_hwaccel_context(vctx);
+
+ avctx->hwaccel_context = vctx;
+ }
+ }
+ break;
+#endif
+ default:
+ ctx->hwaccel_mode = HWACCEL_MODE_NONE;
av_freep(&avctx->hwaccel_context);
- } else {
- AVVDPAUContext *vdpc = avctx->hwaccel_context;
- if (!vdpc)
- avctx->hwaccel_context = vdpc = av_alloc_vdpaucontext();
- vdpc->render2 = vdpau_render_wrapper;
+ break;
}
-#endif
if (IMGFMT_IS_HWACCEL(imgfmt)) {
ctx->do_dr1 = 1;
ctx->nonref_dr = 0;
avctx->get_buffer2 = get_buffer2;
- mp_msg(MSGT_DECVIDEO, MSGL_V, IMGFMT_IS_XVMC(imgfmt) ?
- MSGTR_MPCODECS_XVMCAcceleratedMPEG2 :
- "[VD_FFMPEG] VDPAU accelerated decoding\n");
- if (ctx->use_vdpau) {
+ if (ctx->hwaccel_mode == HWACCEL_MODE_VDPAU ||
+ ctx->hwaccel_mode == HWACCEL_MODE_VAAPI) {
+ mp_msg(MSGT_DECVIDEO, MSGL_V,
+ ctx->hwaccel_mode == HWACCEL_MODE_VDPAU ?
+ "[VD_FFMPEG] VDPAU accelerated decoding\n" :
+ "[VD_FFMPEG] VAAPI accelerated decoding\n");
avctx->draw_horiz_band = NULL;
avctx->slice_flags = 0;
ctx->do_slices = 0;
} else {
+ mp_msg(MSGT_DECVIDEO, MSGL_V, MSGTR_MPCODECS_XVMCAcceleratedMPEG2);
avctx->draw_horiz_band = draw_slice;
avctx->slice_flags = SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD;
ctx->do_slices = 1;
@@ -546,8 +587,8 @@ static void draw_slice(struct AVCodecCon
mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "BUG in FFmpeg, draw_slice called with NULL pointer!\n");
return;
}
- if (mpi && ctx->use_vdpau) {
- mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "BUG in FFmpeg, draw_slice called for VDPAU!\n");
+ if (mpi && ctx->hwaccel_mode != HWACCEL_MODE_NONE) {
+ mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "BUG in FFmpeg, draw_slice called in hwaccel mode!\n");
return;
}
if (height < 0)
@@ -735,28 +776,41 @@ static int get_buffer(AVCodecContext *av
avctx->draw_horiz_band= draw_slice;
} else
avctx->draw_horiz_band= NULL;
+ switch(ctx->hwaccel_mode) {
#if CONFIG_VDPAU
- if (ctx->use_vdpau) {
- VdpVideoSurface surface = (VdpVideoSurface)mpi->priv;
- avctx->draw_horiz_band= NULL;
- mpi->planes[3] = surface;
- }
+ case HWACCEL_MODE_VDPAU:
+ {
+ VdpVideoSurface surface = (VdpVideoSurface)mpi->priv;
+ avctx->draw_horiz_band= NULL;
+ mpi->planes[3] = surface;
+ }
+ break;
+#endif
+#if CONFIG_VAAPI
+ case HWACCEL_MODE_VAAPI:
+ {
+ // This is the VASurfaceID.
+ mpi->planes[3] = mpi->priv;
+ }
+ break;
#endif
#if CONFIG_XVMC
- if(IMGFMT_IS_XVMC(mpi->imgfmt)) {
- struct xvmc_pix_fmt *render = mpi->priv; //same as data[2]
- if(!(mpi->flags & MP_IMGFLAG_DIRECT)) {
- mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_OnlyBuffersAllocatedByVoXvmcAllowed);
- assert(0);
- return -1;//!!fixme check error conditions in ffmpeg
- }
- if(mp_msg_test(MSGT_DECVIDEO, MSGL_DBG5))
- mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::get_buffer (xvmc render=%p)\n", render);
- assert(render != 0);
- assert(render->xvmc_id == AV_XVMC_ID);
- avctx->draw_horiz_band= draw_slice;
- }
+ case HWACCEL_MODE_XVMC:
+ {
+ struct xvmc_pix_fmt *render = mpi->priv; //same as data[2]
+ if(!(mpi->flags & MP_IMGFLAG_DIRECT)) {
+ mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_OnlyBuffersAllocatedByVoXvmcAllowed);
+ assert(0);
+ return -1;//!!fixme check error conditions in ffmpeg
+ }
+ if(mp_msg_test(MSGT_DECVIDEO, MSGL_DBG5))
+ mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::get_buffer (xvmc render=%p)\n", render);
+ assert(render != 0);
+ assert(render->xvmc_id == AV_XVMC_ID);
+ avctx->draw_horiz_band= draw_slice;
+ }
#endif
+ }
pic->data[0]= mpi->planes[0];
pic->data[1]= mpi->planes[1];
@@ -820,6 +874,14 @@ static void release_buffer(struct AVCode
sh_video_t *sh = avctx->opaque;
vd_ffmpeg_ctx *ctx = sh->context;
int i;
+
+#if CONFIG_VAAPI
+ if(ctx->hwaccel_mode == HWACCEL_MODE_VAAPI) {
+ extern vo_vaapi_release_image(mp_image_t *mpi);
+ vo_vaapi_release_image(mpi);
+ }
+#endif
+
if (pic->opaque == NULL) {
mpcodec_default_release_buffer(avctx, pic);
return;
diff --color -rupN old/libvo/video_out.c new/libvo/video_out.c
--- old/libvo/video_out.c 2020-12-29 22:02:05.000000000 +0100
+++ new/libvo/video_out.c 2023-07-07 08:00:42.163364283 +0200
@@ -102,6 +102,7 @@ extern const vo_functions_t video_out_xm
extern const vo_functions_t video_out_x11;
extern const vo_functions_t video_out_xvmc;
extern const vo_functions_t video_out_vdpau;
+extern const vo_functions_t video_out_vaapi;
extern const vo_functions_t video_out_xv;
extern const vo_functions_t video_out_gl_nosw;
extern const vo_functions_t video_out_gl;
@@ -200,6 +201,9 @@ const vo_functions_t* const video_out_dr
#if CONFIG_VDPAU
&video_out_vdpau,
#endif
+#if CONFIG_VAAPI
+ &video_out_vaapi,
+#endif
#ifdef CONFIG_XV
&video_out_xv,
#endif
diff --color -rupN old/libvo/vo_vaapi.c new/libvo/vo_vaapi.c
--- old/libvo/vo_vaapi.c 1970-01-01 01:00:00.000000000 +0100
+++ new/libvo/vo_vaapi.c 2023-07-07 08:00:42.163364283 +0200
@@ -0,0 +1,522 @@
+/*
+ * VAAPI/X11 video output driver
+ *
+ * Copyright (C) 2015 Mark Thompson <[email protected]>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <va/va.h>
+#include <va/va_x11.h>
+
+#include "libavcodec/vaapi.h"
+
+#include "mp_msg.h"
+#include "subopt-helper.h"
+
+#include "x11_common.h"
+#include "video_out.h"
+
+#define NO_DRAW_FRAME
+#define NO_DRAW_SLICE
+#include "video_out_internal.h"
+
+static vo_info_t info = {
+ "VAAPI/X11",
+ "vaapi",
+ "Mark Thompson <[email protected]>",
+ "VAAPI decode and output in X11 (usable with Intel Quick Sync Video)",
+};
+
+#include "libavcodec/vaapi.h"
+
+const LIBVO_EXTERN(vaapi)
+
+// This needs to be at least the number of reference frames required by the
+// stream, plus two for the current and next output surfaces?
+#define DEFAULT_SURFACES 18
+#define MAX_SURFACES 64
+
+typedef struct {
+ VADisplay *display;
+
+ VAConfigID config_id;
+ VAContextID context_id;
+
+ int surface_count;
+ VASurfaceID surface_ids[MAX_SURFACES];
+ int surface_refs[MAX_SURFACES];
+
+ int current_draw_index, next_draw_index;
+
+ uint32_t video_format;
+ uint32_t video_width, video_height;
+
+ int window_width, window_height;
+
+ struct vaapi_context *hwaccel;
+} vo_vaapi_context;
+
+static vo_vaapi_context static_context;
+
+// Hack - this needs to feed in to libavcodec in vd_ffmpeg.c.
+void vo_vaapi_set_hwaccel_context(struct vaapi_context *hwaccel)
+{
+ vo_vaapi_context *ctx = &static_context;
+ if(ctx->display) {
+ // Fill it in immediately.
+ hwaccel->display = ctx->display;
+ hwaccel->config_id = ctx->config_id;
+ hwaccel->context_id = ctx->context_id;
+ } else {
+ // We will fill it when libva is initialised.
+ }
+ ctx->hwaccel = hwaccel;
+}
+
+static void draw_osd(void)
+{
+ static int osd_warned = 0;
+ if(!osd_warned) {
+ mp_msg(MSGT_VO, MSGL_WARN, "[vaapi] OSD drawing is not supported.\n");
+ osd_warned = 1;
+ }
+}
+
+static void resize(void)
+{
+ vo_vaapi_context *ctx = &static_context;
+
+ if(ctx->window_width != vo_dwidth || ctx->window_height != vo_dheight) {
+ ctx->window_width = vo_dwidth;
+ ctx->window_height = vo_dheight;
+
+ // Also redraw the current frame (if there is one) using the new sizing.
+ if(ctx->current_draw_index >= 0) {
+ VAStatus vas;
+ vas = vaPutSurface(ctx->display,
+ ctx->surface_ids[ctx->current_draw_index],
+ vo_window,
+ 0, 0, ctx->video_width, ctx->video_height,
+ 0, 0, ctx->window_width, ctx->window_height,
+ 0, 0, 0);
+ if(vas != VA_STATUS_SUCCESS) {
+ mp_msg(MSGT_VO, MSGL_ERR, "[vaapi] failed to redraw surface: "
+ "%d (%s).\n", vas, vaErrorStr(vas));
+ }
+ }
+ }
+}
+
+static void check_events(void)
+{
+ int events = vo_x11_check_events(mDisplay);
+
+ if(events & VO_EVENT_RESIZE) {
+ mp_msg(MSGT_VO, MSGL_V, "[vaapi] resize event.\n");
+ resize();
+ }
+
+ // Should we care about any other events?
+}
+
+static void flip_page(void)
+{
+ vo_vaapi_context *ctx = &static_context;
+ VAStatus vas;
+ int current, next;
+
+ current = ctx->current_draw_index;
+ next = ctx->next_draw_index;
+
+ mp_msg(MSGT_VO, MSGL_DBG2, "[vaapi] flip page (%d -> %d).\n",
+ current, next);
+
+ vas = vaPutSurface(ctx->display, ctx->surface_ids[next],
+ vo_window,
+ 0, 0, ctx->video_width, ctx->video_height,
+ 0, 0, ctx->window_width, ctx->window_height,
+ 0, 0, 0);
+ if(vas != VA_STATUS_SUCCESS) {
+ mp_msg(MSGT_VO, MSGL_ERR, "[vaapi] failed to draw surface: %d (%s).\n",
+ vas, vaErrorStr(vas));
+ }
+
+ if(current >= 0) {
+ if(ctx->surface_refs[current] == 0) {
+ mp_msg(MSGT_VO, MSGL_ERR, "[vaapi] current draw surface %#x (%d) "
+ "has no reference?\n", ctx->surface_ids[current], current);
+ } else {
+ --ctx->surface_refs[current];
+ }
+ }
+
+ ctx->current_draw_index = next;
+ ctx->next_draw_index = -1;
+}
+
+static int draw_image(mp_image_t *mpi)
+{
+ vo_vaapi_context *ctx = &static_context;
+ VASurfaceID surface;
+ int i;
+
+ surface = (VASurfaceID)(uintptr_t)mpi->priv;
+ for(i = 0; i < ctx->surface_count; i++) {
+ if(ctx->surface_ids[i] == surface)
+ break;
+ }
+ if(i >= ctx->surface_count) {
+ mp_msg(MSGT_VO, MSGL_WARN, "[vaapi] draw called with unknown surface %#x.\n",
+ surface);
+ return VO_ERROR;
+ }
+
+ if(ctx->next_draw_index >= 0) {
+ mp_msg(MSGT_VO, MSGL_WARN, "[vaapi] discarding never-displayed surface"
+ "%#x (%d) - framerate is incorrect?\n",
+ ctx->surface_ids[ctx->next_draw_index], ctx->next_draw_index);
+ --ctx->surface_refs[ctx->next_draw_index];
+ }
+
+ mp_msg(MSGT_VO, MSGL_DBG2, "[vaapi] draw surface %#x (%d).\n", surface, i);
+ ++ctx->surface_refs[i];
+ ctx->next_draw_index = i;
+
+ return VO_TRUE;
+}
+
+static int get_image(mp_image_t *mpi)
+{
+ vo_vaapi_context *ctx = &static_context;
+ VASurfaceID surface;
+ int i;
+
+ for(i = 0; i < ctx->surface_count; i++) {
+ if(ctx->surface_refs[i] == 0)
+ break;
+ }
+ if(i >= ctx->surface_count) {
+ mp_msg(MSGT_VO, MSGL_WARN, "[vaapi] argh, ran out of surfaces (%d in use); "
+ "maybe this stream needs more reference frames?\n", ctx->surface_count);
+ return VO_ERROR;
+ }
+
+ surface = ctx->surface_ids[i];
+ ++ctx->surface_refs[i];
+ mp_msg(MSGT_VO, MSGL_DBG2, "[vaapi] using surface %#x (%d).\n", surface, i);
+
+ mpi->flags |= MP_IMGFLAG_DIRECT;
+ mpi->planes[0] = mpi->planes[1] = mpi->planes[2] = 0;
+ mpi->stride[0] = mpi->stride[1] = mpi->stride[2] = 0;
+ mpi->planes[0] = (void*)(uintptr_t)surface;
+ mpi->num_planes = 1;
+ mpi->priv = (void*)(uintptr_t)surface;
+ return VO_TRUE;
+}
+
+static int release_image(mp_image_t *mpi)
+{
+ vo_vaapi_context *ctx = &static_context;
+ VASurfaceID surface;
+ int i;
+
+ surface = (VASurfaceID)(uintptr_t)mpi->priv;
+
+ for(i = 0; i < ctx->surface_count; i++)
+ if(surface == ctx->surface_ids[i])
+ break;
+ if(i >= ctx->surface_count) {
+ mp_msg(MSGT_VO, MSGL_ERR, "[vaapi] tried to release unknown image: "
+ "surface %#x.\n", surface);
+ return -1;
+ }
+ if(ctx->surface_refs[i] == 0) {
+ mp_msg(MSGT_VO, MSGL_ERR, "[vaapi] tried to release free image "
+ "(decoder error?): surface %#x.\n", surface);
+ return -1;
+ }
+ mp_msg(MSGT_VO, MSGL_DBG2, "[vaapi] release surface %#x (%d).\n", surface, i);
+ --ctx->surface_refs[i];
+
+ return 0;
+}
+
+// Hack - this needsd to feed back from vd_ffmpeg.c.
+int vo_vaapi_release_image(mp_image_t *mpi)
+{
+ return release_image(mpi);
+}
+
+static int query_format(uint32_t format)
+{
+ int flags = VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VOCAP_NOSLICES;
+
+ switch(format) {
+ case IMGFMT_VAAPI_MPEG2:
+ case IMGFMT_VAAPI_H264:
+ case IMGFMT_VAAPI_WMV3:
+ case IMGFMT_VAAPI_VC1:
+ case IMGFMT_VAAPI_MPEG4:
+ case IMGFMT_VAAPI_HEVC:
+ return flags | VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
+ }
+ return 0;
+}
+
+static int preinit(const char *args)
+{
+ vo_vaapi_context *ctx = &static_context;
+
+ int surface_count = DEFAULT_SURFACES;
+ const opt_t subopts[] = {
+ { "surface_count", OPT_ARG_INT, &surface_count, int_pos },
+ { 0 }
+ };
+
+ if(subopt_parse(args, subopts))
+ return -1;
+
+ if(!vo_init())
+ return -1;
+
+ memset(ctx, 0, sizeof(vo_vaapi_context));
+
+ {
+ VAStatus vas;
+ int major, minor;
+
+ ctx->display = vaGetDisplay(mDisplay);
+ if(!ctx->display) {
+ mp_msg(MSGT_VO, MSGL_ERR, "[vaapi] failed to get VA handle for display\n");
+ return -1;
+ }
+
+ vas = vaInitialize(ctx->display, &major, &minor);
+ if(vas != VA_STATUS_SUCCESS) {
+ mp_msg(MSGT_VO, MSGL_ERR, "[vaapi] failed to initialise VAAPI: %d (%s).\n",
+ vas, vaErrorStr(vas));
+ return -1;
+ }
+
+ mp_msg(MSGT_VO, MSGL_INFO, "[vaapi] initialised (API version %d.%d).\n",
+ major, minor);
+
+ ctx->surface_count = surface_count;
+ }