This repository has been archived by the owner on Feb 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0085-qsv-libmfx-no-longer-supports-OPAQUE-memory-since-ve.patch
679 lines (607 loc) · 25.8 KB
/
0085-qsv-libmfx-no-longer-supports-OPAQUE-memory-since-ve.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
From 58fcc347294bb6389ab84b61baa86121ecacad71 Mon Sep 17 00:00:00 2001
From: Haihao Xiang <[email protected]>
Date: Wed, 19 Aug 2020 09:43:12 +0800
Subject: [PATCH 6/6] qsv: libmfx no longer supports OPAQUE memory since
version 2.0 (oneVPL)
---
libavcodec/qsv.c | 4 ++
libavcodec/qsv.h | 2 +
libavcodec/qsv_internal.h | 2 +
libavcodec/qsvdec.c | 9 ++++
libavcodec/qsvenc.c | 21 +++++++++
libavcodec/qsvenc.h | 2 +
libavfilter/qsvvpp.c | 24 ++++++++++-
libavfilter/qsvvpp.h | 2 +
libavfilter/vf_deinterlace_qsv.c | 56 +++++++++++++-----------
libavfilter/vf_scale_qsv.c | 74 ++++++++++++++++++--------------
libavutil/hwcontext_qsv.c | 56 +++++++++++++++++-------
11 files changed, 178 insertions(+), 74 deletions(-)
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index fa7c166016..1df0f7c7d2 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -100,10 +100,14 @@ static const struct {
} qsv_iopatterns[] = {
{MFX_IOPATTERN_IN_VIDEO_MEMORY, "input is video memory surface" },
{MFX_IOPATTERN_IN_SYSTEM_MEMORY, "input is system memory surface" },
+#if QSV_HAVE_OPAQUE
{MFX_IOPATTERN_IN_OPAQUE_MEMORY, "input is opaque memory surface" },
+#endif
{MFX_IOPATTERN_OUT_VIDEO_MEMORY, "output is video memory surface" },
{MFX_IOPATTERN_OUT_SYSTEM_MEMORY, "output is system memory surface" },
+#if QSV_HAVE_OPAQUE
{MFX_IOPATTERN_OUT_OPAQUE_MEMORY, "output is opaque memory surface" },
+#endif
};
int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern,
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index 04ae0d6f34..be7b95c724 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -61,6 +61,8 @@ typedef struct AVQSVContext {
* required by the encoder and the user-provided value nb_opaque_surfaces.
* The array of the opaque surfaces will be exported to the caller through
* the opaque_surfaces field.
+ *
+ * The caller must set this field to zero for oneVPL (libmfx 2.0+)
*/
int opaque_alloc;
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 4f0f1dae87..cf7f688f60 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -60,6 +60,8 @@
((MFX_VERSION.Major > (MAJOR)) || \
(MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
+#define QSV_HAVE_OPAQUE !QSV_VERSION_ATLEAST(2, 0)
+
typedef struct QSVMid {
AVBufferRef *hw_frames_ref;
mfxHDLPair handle_pair;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index e49f08a41e..67129f30fb 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -119,7 +119,11 @@ static int qsv_init_session(AVCodecContext *avctx, QSVContext *q, mfxSession ses
ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session,
&q->frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
q->iopattern == MFX_IOPATTERN_OUT_OPAQUE_MEMORY,
+#else
+ 0,
+#endif
q->gpu_copy);
if (ret < 0) {
av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
@@ -201,10 +205,15 @@ static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixel
AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
if (!iopattern) {
+#if QSV_HAVE_OPAQUE
if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
iopattern = MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
else if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#else
+ if (frames_hwctx->frame_type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET)
+ iopattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#endif
}
}
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 34fe552acf..4e22ec82f2 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1028,6 +1028,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
return 0;
}
+#if QSV_HAVE_OPAQUE
static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
{
AVQSVContext *qsv = avctx->hwaccel_context;
@@ -1064,6 +1065,7 @@ static int qsv_init_opaque_alloc(AVCodecContext *avctx, QSVEncContext *q)
return 0;
}
+#endif
static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
{
@@ -1079,7 +1081,11 @@ static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
ret = ff_qsv_init_session_frames(avctx, &q->internal_qs.session,
&q->frames_ctx, q->load_plugins,
+#if QSV_HAVE_OPAQUE
q->param.IOPattern == MFX_IOPATTERN_IN_OPAQUE_MEMORY,
+#else
+ 0,
+#endif
MFX_GPUCOPY_OFF);
if (ret < 0) {
av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
@@ -1141,11 +1147,17 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx;
if (!iopattern) {
+#if QSV_HAVE_OPAQUE
if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
iopattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY;
else if (frames_hwctx->frame_type &
(MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
+#else
+ if (frames_hwctx->frame_type &
+ (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
+ iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
+#endif
}
}
@@ -1218,9 +1230,16 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
"Error querying (IOSurf) the encoding parameters");
if (opaque_alloc) {
+#if QSV_HAVE_OPAQUE
ret = qsv_init_opaque_alloc(avctx, q);
if (ret < 0)
return ret;
+#else
+ av_log(avctx, AV_LOG_ERROR, "User is requesting to allocate OPAQUE surface, "
+ "however libmfx %d.%d doesn't support OPAQUE memory.\n",
+ q->ver.Major, q->ver.Minor);
+ return AVERROR_UNKNOWN;
+#endif
}
ret = MFXVideoENCODE_Init(q->session, &q->param);
@@ -1667,8 +1686,10 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
av_fifo_free(q->async_fifo);
q->async_fifo = NULL;
+#if QSV_HAVE_OPAQUE
av_freep(&q->opaque_surfaces);
av_buffer_unref(&q->opaque_alloc_buf);
+#endif
av_freep(&q->extparam);
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index 7874679a37..9cfbb3fe12 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -135,9 +135,11 @@ typedef struct QSVEncContext {
mfxExtVP9Param extvp9param;
#endif
+#if QSV_HAVE_OPAQUE
mfxExtOpaqueSurfaceAlloc opaque_alloc;
mfxFrameSurface1 **opaque_surfaces;
AVBufferRef *opaque_alloc_buf;
+#endif
mfxExtBuffer *extparam_internal[2 + QSV_HAVE_CO2 + QSV_HAVE_CO3 + (QSV_HAVE_MF * 2)];
int nb_extparam_internal;
diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index c89d4180d0..1b24a4ef81 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -34,7 +34,9 @@
#define IS_VIDEO_MEMORY(mode) (mode & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | \
MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
+#if QSV_HAVE_OPAQUE
#define IS_OPAQUE_MEMORY(mode) (mode & MFX_MEMTYPE_OPAQUE_FRAME)
+#endif
#define IS_SYSTEM_MEMORY(mode) (mode & MFX_MEMTYPE_SYSTEM_MEMORY)
#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
@@ -63,10 +65,12 @@ struct QSVVPPContext {
mfxFrameSurface1 **surface_ptrs_in;
mfxFrameSurface1 **surface_ptrs_out;
+#if QSV_HAVE_OPAQUE
/* MFXVPP extern parameters */
mfxExtOpaqueSurfaceAlloc opaque_alloc;
mfxExtBuffer **ext_buffers;
int nb_ext_buffers;
+#endif
};
static const AVRational default_tb = { 1, 90000 };
@@ -450,9 +454,13 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
if (!out_frames_ref)
return AVERROR(ENOMEM);
+#if QSV_HAVE_OPAQUE
s->out_mem_mode = IS_OPAQUE_MEMORY(s->in_mem_mode) ?
MFX_MEMTYPE_OPAQUE_FRAME :
MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_FROM_VPPOUT;
+#else
+ s->out_mem_mode = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_FROM_VPPOUT;
+#endif
out_frames_ctx = (AVHWFramesContext *)out_frames_ref->data;
out_frames_hwctx = out_frames_ctx->hwctx;
@@ -534,6 +542,7 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
return AVERROR_UNKNOWN;
}
+#if QSV_HAVE_OPAQUE
if (IS_OPAQUE_MEMORY(s->in_mem_mode) || IS_OPAQUE_MEMORY(s->out_mem_mode)) {
s->opaque_alloc.In.Surfaces = s->surface_ptrs_in;
s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs_in;
@@ -545,7 +554,9 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
- } else if (IS_VIDEO_MEMORY(s->in_mem_mode) || IS_VIDEO_MEMORY(s->out_mem_mode)) {
+ } else
+#endif
+ if (IS_VIDEO_MEMORY(s->in_mem_mode) || IS_VIDEO_MEMORY(s->out_mem_mode)) {
mfxFrameAllocator frame_allocator = {
.pthis = s,
.Alloc = frame_alloc,
@@ -617,6 +628,7 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p
goto failed;
}
+#if QSV_HAVE_OPAQUE
if (IS_OPAQUE_MEMORY(s->in_mem_mode) || IS_OPAQUE_MEMORY(s->out_mem_mode)) {
s->nb_ext_buffers = param->num_ext_buf + 1;
s->ext_buffers = av_mallocz_array(s->nb_ext_buffers, sizeof(*s->ext_buffers));
@@ -634,6 +646,10 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p
s->vpp_param.NumExtParam = param->num_ext_buf;
s->vpp_param.ExtParam = param->ext_buf;
}
+#else
+ s->vpp_param.NumExtParam = param->num_ext_buf;
+ s->vpp_param.ExtParam = param->ext_buf;
+#endif
s->vpp_param.AsyncDepth = 1;
@@ -641,15 +657,19 @@ int ff_qsvvpp_create(AVFilterContext *avctx, QSVVPPContext **vpp, QSVVPPParam *p
s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_SYSTEM_MEMORY;
else if (IS_VIDEO_MEMORY(s->in_mem_mode))
s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_VIDEO_MEMORY;
+#if QSV_HAVE_OPAQUE
else if (IS_OPAQUE_MEMORY(s->in_mem_mode))
s->vpp_param.IOPattern |= MFX_IOPATTERN_IN_OPAQUE_MEMORY;
+#endif
if (IS_SYSTEM_MEMORY(s->out_mem_mode))
s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
else if (IS_VIDEO_MEMORY(s->out_mem_mode))
s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_VIDEO_MEMORY;
+#if QSV_HAVE_OPAQUE
else if (IS_OPAQUE_MEMORY(s->out_mem_mode))
s->vpp_param.IOPattern |= MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
+#endif
ret = MFXVideoVPP_Init(s->session, &s->vpp_param);
if (ret < 0) {
@@ -683,7 +703,9 @@ int ff_qsvvpp_free(QSVVPPContext **vpp)
clear_frame_list(&s->out_frame_list);
av_freep(&s->surface_ptrs_in);
av_freep(&s->surface_ptrs_out);
+#if QSV_HAVE_OPAQUE
av_freep(&s->ext_buffers);
+#endif
av_freep(&s->frame_infos);
av_freep(vpp);
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index cd3655b7a3..753d4fa767 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -39,6 +39,8 @@
((MFX_VERSION.Major > (MAJOR)) || \
(MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR)))
+#define QSV_HAVE_OPAQUE !QSV_VERSION_ATLEAST(2, 0)
+
typedef struct QSVVPPContext QSVVPPContext;
typedef struct QSVVPPCrop {
diff --git a/libavfilter/vf_deinterlace_qsv.c b/libavfilter/vf_deinterlace_qsv.c
index 7b61b72599..23d9eb32d8 100644
--- a/libavfilter/vf_deinterlace_qsv.c
+++ b/libavfilter/vf_deinterlace_qsv.c
@@ -70,7 +70,9 @@ typedef struct QSVDeintContext {
mfxFrameSurface1 **surface_ptrs;
int nb_surface_ptrs;
+#if QSV_HAVE_OPAQUE
mfxExtOpaqueSurfaceAlloc opaque_alloc;
+#endif
mfxExtVPPDeinterlacing deint_conf;
mfxExtBuffer *ext_buffers[2];
int num_ext_buffers;
@@ -176,9 +178,7 @@ static int init_out_session(AVFilterContext *ctx)
AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)s->hw_frames_ctx->data;
AVQSVFramesContext *hw_frames_hwctx = hw_frames_ctx->hwctx;
AVQSVDeviceContext *device_hwctx = hw_frames_ctx->device_ctx->hwctx;
-
- int opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
-
+ int opaque = 0;
mfxHDL handle = NULL;
mfxHandleType handle_type;
mfxVersion ver;
@@ -187,6 +187,9 @@ static int init_out_session(AVFilterContext *ctx)
mfxStatus err;
int ret, i;
+#if QSV_HAVE_OPAQUE
+ opaque = !!(hw_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
+#endif
/* extract the properties of the "master" session given to us */
ret = MFXQueryIMPL(device_hwctx->session, &impl);
if (ret == MFX_ERR_NONE)
@@ -241,28 +244,7 @@ static int init_out_session(AVFilterContext *ctx)
s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->deint_conf;
- if (opaque) {
- s->surface_ptrs = av_mallocz_array(hw_frames_hwctx->nb_surfaces,
- sizeof(*s->surface_ptrs));
- if (!s->surface_ptrs)
- return AVERROR(ENOMEM);
- for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
- s->surface_ptrs[i] = hw_frames_hwctx->surfaces + i;
- s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces;
-
- s->opaque_alloc.In.Surfaces = s->surface_ptrs;
- s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs;
- s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type;
-
- s->opaque_alloc.Out = s->opaque_alloc.In;
-
- s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
- s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
-
- s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->opaque_alloc;
-
- par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
- } else {
+ if (!opaque) {
mfxFrameAllocator frame_allocator = {
.pthis = ctx,
.Alloc = frame_alloc,
@@ -286,6 +268,30 @@ static int init_out_session(AVFilterContext *ctx)
par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
}
+#if QSV_HAVE_OPAQUE
+ else {
+ s->surface_ptrs = av_mallocz_array(hw_frames_hwctx->nb_surfaces,
+ sizeof(*s->surface_ptrs));
+ if (!s->surface_ptrs)
+ return AVERROR(ENOMEM);
+ for (i = 0; i < hw_frames_hwctx->nb_surfaces; i++)
+ s->surface_ptrs[i] = hw_frames_hwctx->surfaces + i;
+ s->nb_surface_ptrs = hw_frames_hwctx->nb_surfaces;
+
+ s->opaque_alloc.In.Surfaces = s->surface_ptrs;
+ s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs;
+ s->opaque_alloc.In.Type = hw_frames_hwctx->frame_type;
+
+ s->opaque_alloc.Out = s->opaque_alloc.In;
+
+ s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
+ s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
+
+ s->ext_buffers[s->num_ext_buffers++] = (mfxExtBuffer *)&s->opaque_alloc;
+
+ par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
+ }
+#endif
par.ExtParam = s->ext_buffers;
par.NumExtParam = s->num_ext_buffers;
diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
index 3ddc3acfe0..310972feed 100644
--- a/libavfilter/vf_scale_qsv.c
+++ b/libavfilter/vf_scale_qsv.c
@@ -90,7 +90,9 @@ typedef struct QSVScaleContext {
mfxFrameSurface1 **surface_ptrs_out;
int nb_surface_ptrs_out;
+#if QSV_HAVE_OPAQUE
mfxExtOpaqueSurfaceAlloc opaque_alloc;
+#endif
#if QSV_HAVE_SCALING_CONFIG
mfxExtVPPScaling scale_conf;
@@ -285,7 +287,7 @@ static int init_out_session(AVFilterContext *ctx)
AVQSVFramesContext *out_frames_hwctx = out_frames_ctx->hwctx;
AVQSVDeviceContext *device_hwctx = in_frames_ctx->device_ctx->hwctx;
- int opaque = !!(in_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
+ int opaque = 0;
mfxHDL handle = NULL;
mfxHandleType handle_type;
@@ -295,6 +297,9 @@ static int init_out_session(AVFilterContext *ctx)
mfxStatus err;
int ret, i;
+#if QSV_HAVE_OPAQUE
+ opaque = !!(in_frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
+#endif
s->num_ext_buf = 0;
/* extract the properties of the "master" session given to us */
@@ -345,38 +350,7 @@ static int init_out_session(AVFilterContext *ctx)
memset(&par, 0, sizeof(par));
- if (opaque) {
- s->surface_ptrs_in = av_mallocz_array(in_frames_hwctx->nb_surfaces,
- sizeof(*s->surface_ptrs_in));
- if (!s->surface_ptrs_in)
- return AVERROR(ENOMEM);
- for (i = 0; i < in_frames_hwctx->nb_surfaces; i++)
- s->surface_ptrs_in[i] = in_frames_hwctx->surfaces + i;
- s->nb_surface_ptrs_in = in_frames_hwctx->nb_surfaces;
-
- s->surface_ptrs_out = av_mallocz_array(out_frames_hwctx->nb_surfaces,
- sizeof(*s->surface_ptrs_out));
- if (!s->surface_ptrs_out)
- return AVERROR(ENOMEM);
- for (i = 0; i < out_frames_hwctx->nb_surfaces; i++)
- s->surface_ptrs_out[i] = out_frames_hwctx->surfaces + i;
- s->nb_surface_ptrs_out = out_frames_hwctx->nb_surfaces;
-
- s->opaque_alloc.In.Surfaces = s->surface_ptrs_in;
- s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs_in;
- s->opaque_alloc.In.Type = in_frames_hwctx->frame_type;
-
- s->opaque_alloc.Out.Surfaces = s->surface_ptrs_out;
- s->opaque_alloc.Out.NumSurface = s->nb_surface_ptrs_out;
- s->opaque_alloc.Out.Type = out_frames_hwctx->frame_type;
-
- s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
- s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
-
- s->ext_buffers[s->num_ext_buf++] = (mfxExtBuffer*)&s->opaque_alloc;
-
- par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
- } else {
+ if (!opaque) {
mfxFrameAllocator frame_allocator = {
.pthis = ctx,
.Alloc = frame_alloc,
@@ -408,6 +382,40 @@ static int init_out_session(AVFilterContext *ctx)
par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
}
+#if QSV_HAVE_OPAQUE
+ else {
+ s->surface_ptrs_in = av_mallocz_array(in_frames_hwctx->nb_surfaces,
+ sizeof(*s->surface_ptrs_in));
+ if (!s->surface_ptrs_in)
+ return AVERROR(ENOMEM);
+ for (i = 0; i < in_frames_hwctx->nb_surfaces; i++)
+ s->surface_ptrs_in[i] = in_frames_hwctx->surfaces + i;
+ s->nb_surface_ptrs_in = in_frames_hwctx->nb_surfaces;
+
+ s->surface_ptrs_out = av_mallocz_array(out_frames_hwctx->nb_surfaces,
+ sizeof(*s->surface_ptrs_out));
+ if (!s->surface_ptrs_out)
+ return AVERROR(ENOMEM);
+ for (i = 0; i < out_frames_hwctx->nb_surfaces; i++)
+ s->surface_ptrs_out[i] = out_frames_hwctx->surfaces + i;
+ s->nb_surface_ptrs_out = out_frames_hwctx->nb_surfaces;
+
+ s->opaque_alloc.In.Surfaces = s->surface_ptrs_in;
+ s->opaque_alloc.In.NumSurface = s->nb_surface_ptrs_in;
+ s->opaque_alloc.In.Type = in_frames_hwctx->frame_type;
+
+ s->opaque_alloc.Out.Surfaces = s->surface_ptrs_out;
+ s->opaque_alloc.Out.NumSurface = s->nb_surface_ptrs_out;
+ s->opaque_alloc.Out.Type = out_frames_hwctx->frame_type;
+
+ s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
+ s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
+
+ s->ext_buffers[s->num_ext_buf++] = (mfxExtBuffer*)&s->opaque_alloc;
+
+ par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
+ }
+#endif
#if QSV_HAVE_SCALING_CONFIG
memset(&s->scale_conf, 0, sizeof(mfxExtVPPScaling));
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 011a76dfa9..42363b85be 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -54,6 +54,8 @@
(MFX_VERSION_MAJOR > (MAJOR) || \
MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
+#define QSV_HAVE_OPAQUE !QSV_VERSION_ATLEAST(2, 0)
+
typedef struct QSVDevicePriv {
AVBufferRef *child_device_ctx;
} QSVDevicePriv;
@@ -85,11 +87,13 @@ typedef struct QSVFramesContext {
// used in the frame allocator for non-opaque surfaces
mfxMemId *mem_ids;
+#if QSV_HAVE_OPAQUE
// used in the opaque alloc request for opaque surfaces
mfxFrameSurface1 **surface_ptrs;
mfxExtOpaqueSurfaceAlloc opaque_alloc;
mfxExtBuffer *ext_buffers[1];
+#endif
} QSVFramesContext;
static const struct {
@@ -231,7 +235,9 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
#endif
av_freep(&s->mem_ids);
+#if QSV_HAVE_OPAQUE
av_freep(&s->surface_ptrs);
+#endif
av_freep(&s->surfaces_internal);
av_freep(&s->handle_pairs_internal);
av_buffer_unref(&s->child_frames_ref);
@@ -467,11 +473,17 @@ static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc)
return ret;
}
+#if QSV_HAVE_OPAQUE
if (!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)) {
ret = qsv_init_child_ctx(ctx);
if (ret < 0)
return ret;
}
+#else
+ ret = qsv_init_child_ctx(ctx);
+ if (ret < 0)
+ return ret;
+#endif
ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(mfxFrameSurface1),
ctx, qsv_pool_alloc, NULL);
@@ -542,10 +554,9 @@ static mfxStatus frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
static int qsv_init_internal_session(AVHWFramesContext *ctx,
mfxSession *session, int upload)
{
- QSVFramesContext *s = ctx->internal->priv;
AVQSVFramesContext *frames_hwctx = ctx->hwctx;
QSVDeviceContext *device_priv = ctx->device_ctx->internal->priv;
- int opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
+ int opaque = 0;
mfxFrameAllocator frame_allocator = {
.pthis = ctx,
@@ -559,6 +570,11 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx,
mfxVideoParam par;
mfxStatus err;
+#if QSV_HAVE_OPAQUE
+ QSVFramesContext *s = ctx->internal->priv;
+ opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
+#endif
+
err = MFXInit(device_priv->impl, &device_priv->ver, session);
if (err != MFX_ERR_NONE) {
av_log(ctx, AV_LOG_ERROR, "Error initializing an internal session\n");
@@ -580,15 +596,18 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx,
memset(&par, 0, sizeof(par));
- if (opaque) {
+ if (!opaque) {
+ par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
+ MFX_IOPATTERN_IN_VIDEO_MEMORY;
+ }
+#if QSV_HAVE_OPAQUE
+ else {
par.ExtParam = s->ext_buffers;
par.NumExtParam = FF_ARRAY_ELEMS(s->ext_buffers);
par.IOPattern = upload ? MFX_IOPATTERN_OUT_OPAQUE_MEMORY :
MFX_IOPATTERN_IN_OPAQUE_MEMORY;
- } else {
- par.IOPattern = upload ? MFX_IOPATTERN_OUT_VIDEO_MEMORY :
- MFX_IOPATTERN_IN_VIDEO_MEMORY;
}
+#endif
par.IOPattern |= upload ? MFX_IOPATTERN_IN_SYSTEM_MEMORY :
MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
@@ -620,11 +639,15 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
QSVFramesContext *s = ctx->internal->priv;
AVQSVFramesContext *frames_hwctx = ctx->hwctx;
- int opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
+ int opaque = 0;
uint32_t fourcc;
int i, ret;
+#if QSV_HAVE_OPAQUE
+ opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
+#endif
+
fourcc = qsv_fourcc_from_pix_fmt(ctx->sw_format);
if (!fourcc) {
av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format\n");
@@ -639,7 +662,16 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
}
}
- if (opaque) {
+ if (!opaque) {
+ s->mem_ids = av_mallocz_array(frames_hwctx->nb_surfaces, sizeof(*s->mem_ids));
+ if (!s->mem_ids)
+ return AVERROR(ENOMEM);
+
+ for (i = 0; i < frames_hwctx->nb_surfaces; i++)
+ s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
+ }
+#if QSV_HAVE_OPAQUE
+ else {
s->surface_ptrs = av_mallocz_array(frames_hwctx->nb_surfaces,
sizeof(*s->surface_ptrs));
if (!s->surface_ptrs)
@@ -658,14 +690,8 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
s->ext_buffers[0] = (mfxExtBuffer*)&s->opaque_alloc;
- } else {
- s->mem_ids = av_mallocz_array(frames_hwctx->nb_surfaces, sizeof(*s->mem_ids));
- if (!s->mem_ids)
- return AVERROR(ENOMEM);
-
- for (i = 0; i < frames_hwctx->nb_surfaces; i++)
- s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
}
+#endif
s->session_download = NULL;
s->session_upload = NULL;
--
2.25.1