summaryrefslogtreecommitdiffstats
path: root/recipes-multimedia
diff options
context:
space:
mode:
authorYew, Chang Ching <chang.ching.yew@intel.com>2021-07-02 18:39:10 (GMT)
committerAnuj Mittal <anuj.mittal@intel.com>2021-07-03 14:48:10 (GMT)
commita8195a0a7f7d6f0cf99b2571b18a822d76f0bb55 (patch)
treec42a14b576af909572b13de3a00b6160940a7afa /recipes-multimedia
parentf808528a90bc6fff3f25c69de2103af827c5d7e6 (diff)
downloadmeta-intel-a8195a0a7f7d6f0cf99b2571b18a822d76f0bb55.tar.gz
onevpl: upgrade 2021.2.2 -> 2021.4.0
* Updated dispatcher API to 2.4 * Advanced OpenVINO interop sample w/ remoteBlob support (Linux only) * C++ API and Samples (Preview) * Python API and Samples (Preview) * Added logging capability to Dispatcher * Added new tools: sample_multi_transcode and decvpp_tool * Added debug libraries to Windows package For more information on the preview C++/Python APIs and Samples, see https://software.intel.com/content/www/us/en/develop/articles/onevpl-preview-examples.html For full release notes, see https://github.com/oneapi-src/oneVPL/commit/d5c072584ee6f81305ed85de8759658ab7854606 Signed-off-by: Yew, Chang Ching <chang.ching.yew@intel.com> Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
Diffstat (limited to 'recipes-multimedia')
-rw-r--r--recipes-multimedia/onevpl/onevpl/0001-Add-SMT-and-media_sdk_compatibility_headers.patch12988
-rw-r--r--recipes-multimedia/onevpl/onevpl/0001-Add-X11-support-to-legacy-tools.patch50
-rw-r--r--recipes-multimedia/onevpl/onevpl/0001-Adding-Wayland-support-to-legacy-tools.patch161
-rw-r--r--recipes-multimedia/onevpl/onevpl/0001-Fix-NV12-input-format-in-legacy-samples.patch36
-rw-r--r--recipes-multimedia/onevpl/onevpl/0001-Fix-sample_encode-i010-input.patch62
-rw-r--r--recipes-multimedia/onevpl/onevpl/0001-Fix-sample_vpp-sample_encode-alignment-issue.patch96
-rw-r--r--recipes-multimedia/onevpl/onevpl/0001-Remove-duplicate-MFXVideoDECODE_VPP-from-samples.patch62
-rw-r--r--recipes-multimedia/onevpl/onevpl/0001-Update-headers-to-oneAPI-spec-v2.3-e170992.patch741
-rw-r--r--recipes-multimedia/onevpl/onevpl/0001-cmake-Allow-build-env-to-set-variables.patch65
-rw-r--r--recipes-multimedia/onevpl/onevpl_2021.2.2.bb55
-rw-r--r--recipes-multimedia/onevpl/onevpl_2021.4.0.bb33
11 files changed, 171 insertions, 14178 deletions
diff --git a/recipes-multimedia/onevpl/onevpl/0001-Add-SMT-and-media_sdk_compatibility_headers.patch b/recipes-multimedia/onevpl/onevpl/0001-Add-SMT-and-media_sdk_compatibility_headers.patch
deleted file mode 100644
index fb83238..0000000
--- a/recipes-multimedia/onevpl/onevpl/0001-Add-SMT-and-media_sdk_compatibility_headers.patch
+++ /dev/null
@@ -1,12988 +0,0 @@
1From fffc477d33fb255c83202d68d43b485014f8db4f Mon Sep 17 00:00:00 2001
2From: Jeff McAllister <jeffrey.mcallister@intel.com>
3Date: Wed, 2 Jun 2021 13:20:59 +0800
4Subject: [PATCH] Add SMT and media_sdk_compatibility_headers
5
6Upstream-Status: Submitted
7---
8 tools/legacy/CMakeLists.txt | 2 +
9 .../CMakeLists.txt | 11 +
10 .../mfx_multi_vpp.h | 103 +
11 .../mfxastructures.h | 169 +
12 .../mfxaudio.h | 81 +
13 .../mfxdeprecated.h | 167 +
14 .../mfxplugin.h | 601 +++
15 .../rotate_plugin_api.h | 29 +
16 tools/legacy/sample_common/CMakeLists.txt | 4 +-
17 .../sample_common/include/plugin_utils.h | 1 +
18 .../sample_common/include/sample_utils.h | 5 +-
19 .../sample_common/include/sample_utils.h.orig | 1437 +++++
20 .../include/vpl_implementation_loader.h | 73 +
21 .../legacy/sample_common/src/plugin_utils.cpp | 8 -
22 .../src/vpl_implementation_loader.cpp | 220 +
23 .../sample_multi_transcode/CMakeLists.txt | 42 +
24 .../include/pipeline_transcode.h | 973 ++++
25 .../include/sample_multi_transcode.h | 109 +
26 .../include/transcode_utils.h | 111 +
27 .../src/pipeline_transcode.cpp | 4668 +++++++++++++++++
28 .../src/sample_multi_transcode.cpp | 1162 ++++
29 .../src/transcode_utils.cpp | 2765 ++++++++++
30 22 files changed, 12730 insertions(+), 11 deletions(-)
31 create mode 100644 tools/legacy/media_sdk_compatibility_headers/CMakeLists.txt
32 create mode 100644 tools/legacy/media_sdk_compatibility_headers/mfx_multi_vpp.h
33 create mode 100644 tools/legacy/media_sdk_compatibility_headers/mfxastructures.h
34 create mode 100644 tools/legacy/media_sdk_compatibility_headers/mfxaudio.h
35 create mode 100644 tools/legacy/media_sdk_compatibility_headers/mfxdeprecated.h
36 create mode 100644 tools/legacy/media_sdk_compatibility_headers/mfxplugin.h
37 create mode 100644 tools/legacy/media_sdk_compatibility_headers/rotate_plugin_api.h
38 create mode 100644 tools/legacy/sample_common/include/sample_utils.h.orig
39 create mode 100644 tools/legacy/sample_common/include/vpl_implementation_loader.h
40 create mode 100644 tools/legacy/sample_common/src/vpl_implementation_loader.cpp
41 create mode 100644 tools/legacy/sample_multi_transcode/CMakeLists.txt
42 create mode 100644 tools/legacy/sample_multi_transcode/include/pipeline_transcode.h
43 create mode 100644 tools/legacy/sample_multi_transcode/include/sample_multi_transcode.h
44 create mode 100644 tools/legacy/sample_multi_transcode/include/transcode_utils.h
45 create mode 100644 tools/legacy/sample_multi_transcode/src/pipeline_transcode.cpp
46 create mode 100644 tools/legacy/sample_multi_transcode/src/sample_multi_transcode.cpp
47 create mode 100644 tools/legacy/sample_multi_transcode/src/transcode_utils.cpp
48
49diff --git a/tools/legacy/CMakeLists.txt b/tools/legacy/CMakeLists.txt
50index 1d4af73..34ed0ec 100644
51--- a/tools/legacy/CMakeLists.txt
52+++ b/tools/legacy/CMakeLists.txt
53@@ -7,8 +7,10 @@
54
55 cmake_minimum_required(VERSION 3.10.2)
56
57+add_subdirectory(media_sdk_compatibility_headers)
58 add_subdirectory(sample_common)
59 add_subdirectory(sample_decode)
60 add_subdirectory(sample_vpp)
61 add_subdirectory(sample_encode)
62 add_subdirectory(sample_misc/wayland)
63+add_subdirectory(sample_multi_transcode)
64diff --git a/tools/legacy/media_sdk_compatibility_headers/CMakeLists.txt b/tools/legacy/media_sdk_compatibility_headers/CMakeLists.txt
65new file mode 100644
66index 0000000..343255a
67--- /dev/null
68+++ b/tools/legacy/media_sdk_compatibility_headers/CMakeLists.txt
69@@ -0,0 +1,11 @@
70+# ##############################################################################
71+# Copyright (C) Intel Corporation
72+#
73+# SPDX-License-Identifier: MIT
74+# ##############################################################################
75+cmake_minimum_required(VERSION 3.10.2)
76+
77+set(TARGET media_sdk_compatibility_headers)
78+
79+add_library(${TARGET} INTERFACE)
80+target_include_directories(${TARGET} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
81diff --git a/tools/legacy/media_sdk_compatibility_headers/mfx_multi_vpp.h b/tools/legacy/media_sdk_compatibility_headers/mfx_multi_vpp.h
82new file mode 100644
83index 0000000..d53bbac
84--- /dev/null
85+++ b/tools/legacy/media_sdk_compatibility_headers/mfx_multi_vpp.h
86@@ -0,0 +1,103 @@
87+/******************************************************************************\
88+Copyright (c) 2005-2018, Intel Corporation
89+All rights reserved.
90+
91+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
92+
93+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
94+
95+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
96+
97+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
98+
99+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100+
101+This sample was distributed or derived from the Intel's Media Samples package.
102+The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
103+or https://software.intel.com/en-us/media-client-solutions-support.
104+\**********************************************************************************/
105+
106+#ifndef __MFX_MULTI_VPP_H
107+#define __MFX_MULTI_VPP_H
108+
109+#include "mfxvideo++.h"
110+// An interface for a pipeline consisting of multiple (maximum 3) VPP-like components. Base implementation - for single VPP.
111+// The application should use this interface to be able to seamlessly switch from MFXVideoVPP to MFXVideoVPPPlugin in the pipeline.
112+
113+class MFXVideoMultiVPP : public MFXVideoVPP {
114+public:
115+ MFXVideoMultiVPP(mfxSession session) : MFXVideoVPP(session) {}
116+ virtual ~MFXVideoMultiVPP(void) {
117+ Close();
118+ }
119+
120+ // topology methods
121+ virtual mfxStatus QueryIOSurf(mfxVideoParam *par, mfxFrameAllocRequest *request) override {
122+ return QueryIOSurfMulti(par, request);
123+ }
124+ virtual mfxStatus QueryIOSurfMulti(mfxVideoParam *par,
125+ mfxFrameAllocRequest request[2],
126+ mfxVideoParam * /*par1*/ = NULL,
127+ mfxVideoParam * /*par2*/ = NULL) {
128+ return MFXVideoVPP_QueryIOSurf(m_session, par, request);
129+ }
130+
131+ virtual mfxStatus Init(mfxVideoParam *par) override {
132+ return InitMulti(par);
133+ }
134+ virtual mfxStatus InitMulti(mfxVideoParam *par,
135+ mfxVideoParam * /*par1*/ = NULL,
136+ mfxVideoParam * /*par2*/ = NULL) {
137+ return MFXVideoVPP_Init(m_session, par);
138+ }
139+
140+ virtual mfxStatus Reset(mfxVideoParam *par) override {
141+ return ResetMulti(par);
142+ }
143+ virtual mfxStatus ResetMulti(mfxVideoParam *par,
144+ mfxVideoParam * /*par1*/ = NULL,
145+ mfxVideoParam * /*par2*/ = NULL) {
146+ return MFXVideoVPP_Reset(m_session, par);
147+ }
148+
149+ virtual mfxStatus RunFrameVPPAsync(mfxFrameSurface1 *in,
150+ mfxFrameSurface1 *out,
151+ mfxExtVppAuxData *aux,
152+ mfxSyncPoint *syncp) override {
153+ return MFXVideoVPP_RunFrameVPPAsync(m_session, in, out, aux, syncp);
154+ }
155+
156+ virtual mfxStatus SyncOperation(mfxSyncPoint syncp, mfxU32 wait) {
157+ return MFXVideoCORE_SyncOperation(m_session, syncp, wait);
158+ }
159+
160+ virtual mfxStatus Close(void) override {
161+ return MFXVideoVPP_Close(m_session);
162+ }
163+
164+ // per-component methods
165+ virtual mfxStatus Query(mfxVideoParam *in, mfxVideoParam *out) override {
166+ return QueryMulti(in, out);
167+ }
168+ virtual mfxStatus QueryMulti(mfxVideoParam *in,
169+ mfxVideoParam *out,
170+ mfxU8 /*component_idx*/ = 0) {
171+ return MFXVideoVPP_Query(m_session, in, out);
172+ }
173+
174+ virtual mfxStatus GetVideoParam(mfxVideoParam *par) override {
175+ return GetVideoParamMulti(par);
176+ }
177+ virtual mfxStatus GetVideoParamMulti(mfxVideoParam *par, mfxU8 /*component_idx*/ = 0) {
178+ return MFXVideoVPP_GetVideoParam(m_session, par);
179+ }
180+
181+ virtual mfxStatus GetVPPStat(mfxVPPStat *stat) override {
182+ return GetVPPStatMulti(stat);
183+ }
184+ virtual mfxStatus GetVPPStatMulti(mfxVPPStat *stat, mfxU8 /*component_idx*/ = 0) {
185+ return MFXVideoVPP_GetVPPStat(m_session, stat);
186+ }
187+};
188+
189+#endif //__MFX_MULTI_VPP_H
190diff --git a/tools/legacy/media_sdk_compatibility_headers/mfxastructures.h b/tools/legacy/media_sdk_compatibility_headers/mfxastructures.h
191new file mode 100644
192index 0000000..a66628c
193--- /dev/null
194+++ b/tools/legacy/media_sdk_compatibility_headers/mfxastructures.h
195@@ -0,0 +1,169 @@
196+/*******************************************************************************
197+
198+Copyright (C) 2013-2019 Intel Corporation. All rights reserved.
199+
200+Redistribution and use in source and binary forms, with or without
201+modification, are permitted provided that the following conditions are met:
202+- Redistributions of source code must retain the above copyright notice,
203+this list of conditions and the following disclaimer.
204+- Redistributions in binary form must reproduce the above copyright notice,
205+this list of conditions and the following disclaimer in the documentation
206+and/or other materials provided with the distribution.
207+- Neither the name of Intel Corporation nor the names of its contributors
208+may be used to endorse or promote products derived from this software
209+without specific prior written permission.
210+
211+THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
212+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
213+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
214+IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
215+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
216+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
217+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
218+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
219+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
220+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
221+
222+File Name: mfxastructures.h
223+
224+*******************************************************************************/
225+#ifndef __MFXASTRUCTURES_H__
226+#define __MFXASTRUCTURES_H__
227+#include "vpl/mfxcommon.h"
228+
229+#if !defined(__GNUC__)
230+ #pragma warning(disable : 4201)
231+#endif
232+
233+#ifdef __cplusplus
234+extern "C" {
235+#endif /* __cplusplus */
236+
237+/* CodecId */
238+enum {
239+ MFX_CODEC_AAC = MFX_MAKEFOURCC('A', 'A', 'C', ' '),
240+ MFX_CODEC_MP3 = MFX_MAKEFOURCC('M', 'P', '3', ' ')
241+};
242+
243+enum {
244+ /* AAC Profiles & Levels */
245+ MFX_PROFILE_AAC_LC = 2,
246+ MFX_PROFILE_AAC_LTP = 4,
247+ MFX_PROFILE_AAC_MAIN = 1,
248+ MFX_PROFILE_AAC_SSR = 3,
249+ MFX_PROFILE_AAC_HE = 5,
250+ MFX_PROFILE_AAC_ALS = 0x20,
251+ MFX_PROFILE_AAC_BSAC = 22,
252+ MFX_PROFILE_AAC_PS = 29,
253+
254+ /*MPEG AUDIO*/
255+ MFX_AUDIO_MPEG1_LAYER1 = 0x00000110,
256+ MFX_AUDIO_MPEG1_LAYER2 = 0x00000120,
257+ MFX_AUDIO_MPEG1_LAYER3 = 0x00000140,
258+ MFX_AUDIO_MPEG2_LAYER1 = 0x00000210,
259+ MFX_AUDIO_MPEG2_LAYER2 = 0x00000220,
260+ MFX_AUDIO_MPEG2_LAYER3 = 0x00000240
261+};
262+
263+/*AAC HE decoder down sampling*/
264+enum { MFX_AUDIO_AAC_HE_DWNSMPL_OFF = 0, MFX_AUDIO_AAC_HE_DWNSMPL_ON = 1 };
265+
266+/* AAC decoder support of PS */
267+enum {
268+ MFX_AUDIO_AAC_PS_DISABLE = 0,
269+ MFX_AUDIO_AAC_PS_PARSER = 1,
270+ MFX_AUDIO_AAC_PS_ENABLE_BL = 111,
271+ MFX_AUDIO_AAC_PS_ENABLE_UR = 411
272+};
273+
274+/*AAC decoder SBR support*/
275+enum { MFX_AUDIO_AAC_SBR_DISABLE = 0, MFX_AUDIO_AAC_SBR_ENABLE = 1, MFX_AUDIO_AAC_SBR_UNDEF = 2 };
276+
277+/*AAC header type*/
278+enum {
279+ MFX_AUDIO_AAC_ADTS = 1,
280+ MFX_AUDIO_AAC_ADIF = 2,
281+ MFX_AUDIO_AAC_RAW = 3,
282+};
283+
284+/*AAC encoder stereo mode*/
285+enum {
286+ MFX_AUDIO_AAC_MONO = 0,
287+ MFX_AUDIO_AAC_LR_STEREO = 1,
288+ MFX_AUDIO_AAC_MS_STEREO = 2,
289+ MFX_AUDIO_AAC_JOINT_STEREO = 3
290+};
291+
292+MFX_PACK_BEGIN_USUAL_STRUCT()
293+typedef struct {
294+ mfxU32 CodecId;
295+ mfxU16 CodecProfile;
296+ mfxU16 CodecLevel;
297+
298+ mfxU32 Bitrate;
299+ mfxU32 SampleFrequency;
300+ mfxU16 NumChannel;
301+ mfxU16 BitPerSample;
302+
303+ mfxU16 reserved1[22];
304+
305+ union {
306+ struct { /* AAC Decoding Options */
307+ mfxU16 FlagPSSupportLev;
308+ mfxU16 Layer;
309+ mfxU16 AACHeaderDataSize;
310+ mfxU8 AACHeaderData[64];
311+ };
312+ struct { /* AAC Encoding Options */
313+ mfxU16 OutputFormat;
314+ mfxU16 StereoMode;
315+ mfxU16 reserved2[61];
316+ };
317+ };
318+} mfxAudioInfoMFX;
319+MFX_PACK_END()
320+
321+MFX_PACK_BEGIN_STRUCT_W_PTR()
322+typedef struct {
323+ mfxU16 AsyncDepth;
324+ mfxU16 Protected;
325+ mfxU16 reserved[14];
326+
327+ mfxAudioInfoMFX mfx;
328+ mfxExtBuffer** ExtParam;
329+ mfxU16 NumExtParam;
330+} mfxAudioParam;
331+MFX_PACK_END()
332+
333+MFX_PACK_BEGIN_USUAL_STRUCT()
334+typedef struct {
335+ mfxU32 SuggestedInputSize;
336+ mfxU32 SuggestedOutputSize;
337+ mfxU32 reserved[6];
338+} mfxAudioAllocRequest;
339+MFX_PACK_END()
340+
341+MFX_PACK_BEGIN_STRUCT_W_L_TYPE()
342+typedef struct {
343+ mfxU64 TimeStamp; /* 1/90KHz */
344+ mfxU16 Locked;
345+ mfxU16 NumChannels;
346+ mfxU32 SampleFrequency;
347+ mfxU16 BitPerSample;
348+ mfxU16 reserved1[7];
349+
350+ mfxU8* Data;
351+ mfxU32 reserved2;
352+ mfxU32 DataLength;
353+ mfxU32 MaxLength;
354+
355+ mfxU32 NumExtParam;
356+ mfxExtBuffer** ExtParam;
357+} mfxAudioFrame;
358+MFX_PACK_END()
359+
360+#ifdef __cplusplus
361+}
362+#endif /* __cplusplus */
363+
364+#endif
365diff --git a/tools/legacy/media_sdk_compatibility_headers/mfxaudio.h b/tools/legacy/media_sdk_compatibility_headers/mfxaudio.h
366new file mode 100644
367index 0000000..b252d98
368--- /dev/null
369+++ b/tools/legacy/media_sdk_compatibility_headers/mfxaudio.h
370@@ -0,0 +1,81 @@
371+/*******************************************************************************
372+
373+Copyright (C) 2013 Intel Corporation. All rights reserved.
374+
375+Redistribution and use in source and binary forms, with or without
376+modification, are permitted provided that the following conditions are met:
377+- Redistributions of source code must retain the above copyright notice,
378+this list of conditions and the following disclaimer.
379+- Redistributions in binary form must reproduce the above copyright notice,
380+this list of conditions and the following disclaimer in the documentation
381+and/or other materials provided with the distribution.
382+- Neither the name of Intel Corporation nor the names of its contributors
383+may be used to endorse or promote products derived from this software
384+without specific prior written permission.
385+
386+THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
387+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
388+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
389+IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
390+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
391+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
392+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
393+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
394+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
395+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396+
397+File Name: mfxaudio.h
398+
399+*******************************************************************************/
400+
401+#ifndef __MFXAUDIO_H__
402+#define __MFXAUDIO_H__
403+#include "mfxastructures.h"
404+#include "vpl/mfxsession.h"
405+
406+#define MFX_AUDIO_VERSION_MAJOR 1
407+#define MFX_AUDIO_VERSION_MINOR 15
408+
409+#ifdef __cplusplus
410+extern "C" {
411+#endif
412+
413+/* AudioCORE */
414+mfxStatus MFX_CDECL MFXAudioCORE_SyncOperation(mfxSession session, mfxSyncPoint syncp, mfxU32 wait);
415+
416+/* AudioENCODE */
417+mfxStatus MFX_CDECL MFXAudioENCODE_Query(mfxSession session, mfxAudioParam *in, mfxAudioParam *out);
418+mfxStatus MFX_CDECL MFXAudioENCODE_QueryIOSize(mfxSession session,
419+ mfxAudioParam *par,
420+ mfxAudioAllocRequest *request);
421+mfxStatus MFX_CDECL MFXAudioENCODE_Init(mfxSession session, mfxAudioParam *par);
422+mfxStatus MFX_CDECL MFXAudioENCODE_Reset(mfxSession session, mfxAudioParam *par);
423+mfxStatus MFX_CDECL MFXAudioENCODE_Close(mfxSession session);
424+mfxStatus MFX_CDECL MFXAudioENCODE_GetAudioParam(mfxSession session, mfxAudioParam *par);
425+mfxStatus MFX_CDECL MFXAudioENCODE_EncodeFrameAsync(mfxSession session,
426+ mfxAudioFrame *frame,
427+ mfxBitstream *bs,
428+ mfxSyncPoint *syncp);
429+
430+/* AudioDECODE */
431+mfxStatus MFX_CDECL MFXAudioDECODE_Query(mfxSession session, mfxAudioParam *in, mfxAudioParam *out);
432+mfxStatus MFX_CDECL MFXAudioDECODE_DecodeHeader(mfxSession session,
433+ mfxBitstream *bs,
434+ mfxAudioParam *par);
435+mfxStatus MFX_CDECL MFXAudioDECODE_Init(mfxSession session, mfxAudioParam *par);
436+mfxStatus MFX_CDECL MFXAudioDECODE_Reset(mfxSession session, mfxAudioParam *par);
437+mfxStatus MFX_CDECL MFXAudioDECODE_Close(mfxSession session);
438+mfxStatus MFX_CDECL MFXAudioDECODE_QueryIOSize(mfxSession session,
439+ mfxAudioParam *par,
440+ mfxAudioAllocRequest *request);
441+mfxStatus MFX_CDECL MFXAudioDECODE_GetAudioParam(mfxSession session, mfxAudioParam *par);
442+mfxStatus MFX_CDECL MFXAudioDECODE_DecodeFrameAsync(mfxSession session,
443+ mfxBitstream *bs,
444+ mfxAudioFrame *frame,
445+ mfxSyncPoint *syncp);
446+
447+#ifdef __cplusplus
448+} // extern "C"
449+#endif
450+
451+#endif
452diff --git a/tools/legacy/media_sdk_compatibility_headers/mfxdeprecated.h b/tools/legacy/media_sdk_compatibility_headers/mfxdeprecated.h
453new file mode 100644
454index 0000000..5f0ca24
455--- /dev/null
456+++ b/tools/legacy/media_sdk_compatibility_headers/mfxdeprecated.h
457@@ -0,0 +1,167 @@
458+/*############################################################################
459+ # Copyright (C) 2020 Intel Corporation
460+ #
461+ # SPDX-License-Identifier: MIT
462+ ############################################################################*/
463+
464+#ifndef __MFXDEPRECATED_H__
465+#define __MFXDEPRECATED_H__
466+
467+#include "vpl/mfxcommon.h"
468+#include "vpl/mfxsession.h"
469+#include "vpl/mfxstructures.h"
470+
471+#if defined(MFX_ONEVPL)
472+
473+ #ifdef __cplusplus
474+extern "C" {
475+ #endif /* __cplusplus */
476+
477+enum {
478+ MFX_ERR_INCOMPATIBLE_AUDIO_PARAM = -19, /* incompatible audio parameters */
479+ MFX_ERR_INVALID_AUDIO_PARAM = -20, /* invalid audio parameters */
480+
481+ MFX_WRN_INCOMPATIBLE_AUDIO_PARAM = 11, /* incompatible audio parameters */
482+};
483+
484+mfxStatus MFX_CDECL MFXVideoVPP_RunFrameVPPAsyncEx(mfxSession session,
485+ mfxFrameSurface1 *in,
486+ mfxFrameSurface1 *surface_work,
487+ mfxFrameSurface1 **surface_out,
488+ mfxSyncPoint *syncp);
489+
490+MFX_PACK_BEGIN_STRUCT_W_PTR()
491+typedef struct {
492+ mfxU32 reserved[4];
493+ mfxHDL pthis;
494+ mfxStatus(MFX_CDECL *Alloc)(mfxHDL pthis, mfxU32 nbytes, mfxU16 type, mfxMemId *mid);
495+ mfxStatus(MFX_CDECL *Lock)(mfxHDL pthis, mfxMemId mid, mfxU8 **ptr);
496+ mfxStatus(MFX_CDECL *Unlock)(mfxHDL pthis, mfxMemId mid);
497+ mfxStatus(MFX_CDECL *Free)(mfxHDL pthis, mfxMemId mid);
498+} mfxBufferAllocator;
499+MFX_PACK_END()
500+
501+mfxStatus MFX_CDECL MFXVideoCORE_SetBufferAllocator(mfxSession session,
502+ mfxBufferAllocator *allocator);
503+
504+ #if defined(MFX_ENABLE_OPAQUE_MEMORY)
505+ //Sanity check
506+ #error MFX_ENABLE_OPAQUE_MEMORY should not be defined when 'mfxdeprecated.h' is included
507+ #endif //MFX_ENABLE_OPAQUE_MEMORY
508+
509+/* IOPattern */
510+enum { MFX_IOPATTERN_IN_OPAQUE_MEMORY = 0x04, MFX_IOPATTERN_OUT_OPAQUE_MEMORY = 0x40 };
511+
512+enum { MFX_MEMTYPE_OPAQUE_FRAME = 0x0004 };
513+
514+/* Extended Buffer Ids */
515+enum { MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION = MFX_MAKEFOURCC('O', 'P', 'Q', 'S') };
516+
517+MFX_PACK_BEGIN_STRUCT_W_PTR()
518+typedef struct {
519+ mfxExtBuffer Header;
520+ mfxU32 reserved1[2];
521+ struct {
522+ mfxFrameSurface1 **Surfaces;
523+ mfxU32 reserved2[5];
524+ mfxU16 Type;
525+ mfxU16 NumSurface;
526+ } In, Out;
527+} mfxExtOpaqueSurfaceAlloc;
528+MFX_PACK_END()
529+
530+mfxStatus MFX_CDECL MFXDoWork(mfxSession session);
531+
532+mfxStatus MFX_CDECL MFXVideoENC_Query(mfxSession session, mfxVideoParam *in, mfxVideoParam *out);
533+mfxStatus MFX_CDECL MFXVideoENC_QueryIOSurf(mfxSession session,
534+ mfxVideoParam *par,
535+ mfxFrameAllocRequest *request);
536+mfxStatus MFX_CDECL MFXVideoENC_Init(mfxSession session, mfxVideoParam *par);
537+mfxStatus MFX_CDECL MFXVideoENC_Reset(mfxSession session, mfxVideoParam *par);
538+mfxStatus MFX_CDECL MFXVideoENC_Close(mfxSession session);
539+
540+typedef struct _mfxENCInput {
541+} mfxENCInput;
542+typedef struct _mfxENCOutput {
543+} mfxENCOutput;
544+mfxStatus MFX_CDECL MFXVideoENC_ProcessFrameAsync(mfxSession session,
545+ mfxENCInput *in,
546+ mfxENCOutput *out,
547+ mfxSyncPoint *syncp);
548+
549+mfxStatus MFX_CDECL MFXVideoENC_GetVideoParam(mfxSession session, mfxVideoParam *par);
550+
551+MFX_PACK_BEGIN_STRUCT_W_PTR()
552+typedef struct {
553+} mfxPAKInput;
554+MFX_PACK_END()
555+
556+MFX_PACK_BEGIN_STRUCT_W_PTR()
557+typedef struct {
558+} mfxPAKOutput;
559+MFX_PACK_END()
560+
561+mfxStatus MFX_CDECL MFXVideoPAK_Query(mfxSession session, mfxVideoParam *in, mfxVideoParam *out);
562+mfxStatus MFX_CDECL MFXVideoPAK_QueryIOSurf(mfxSession session,
563+ mfxVideoParam *par,
564+ mfxFrameAllocRequest request[2]);
565+mfxStatus MFX_CDECL MFXVideoPAK_Init(mfxSession session, mfxVideoParam *par);
566+mfxStatus MFX_CDECL MFXVideoPAK_Reset(mfxSession session, mfxVideoParam *par);
567+mfxStatus MFX_CDECL MFXVideoPAK_Close(mfxSession session);
568+
569+mfxStatus MFX_CDECL MFXVideoPAK_ProcessFrameAsync(mfxSession session,
570+ mfxPAKInput *in,
571+ mfxPAKOutput *out,
572+ mfxSyncPoint *syncp);
573+
574+mfxStatus MFX_CDECL MFXVideoPAK_GetVideoParam(mfxSession session, mfxVideoParam *par);
575+
576+enum {
577+ /*!
578+ This extended buffer allow to specify multi-frame submission parameters.
579+ */
580+ MFX_EXTBUFF_MULTI_FRAME_PARAM = MFX_MAKEFOURCC('M', 'F', 'R', 'P'),
581+ /*!
582+ This extended buffer allow to manage multi-frame submission in runtime.
583+ */
584+ MFX_EXTBUFF_MULTI_FRAME_CONTROL = MFX_MAKEFOURCC('M', 'F', 'R', 'C'),
585+};
586+
587+/* Multi-Frame Mode */
588+enum { MFX_MF_DEFAULT = 0, MFX_MF_DISABLED = 1, MFX_MF_AUTO = 2, MFX_MF_MANUAL = 3 };
589+
590+/* Multi-Frame Initialization parameters */
591+MFX_PACK_BEGIN_USUAL_STRUCT()
592+typedef struct {
593+ mfxExtBuffer Header;
594+
595+ mfxU16 MFMode;
596+ mfxU16 MaxNumFrames;
597+
598+ mfxU16 reserved[58];
599+} mfxExtMultiFrameParam;
600+MFX_PACK_END()
601+
602+/* Multi-Frame Run-time controls */
603+MFX_PACK_BEGIN_USUAL_STRUCT()
604+typedef struct {
605+ mfxExtBuffer Header;
606+
607+ mfxU32 Timeout; /* timeout in millisecond */
608+ mfxU16 Flush; /* Flush internal frame buffer, e.g. submit all collected frames. */
609+
610+ mfxU16 reserved[57];
611+} mfxExtMultiFrameControl;
612+MFX_PACK_END()
613+
614+/* RateControlMethod */
615+enum {
616+ MFX_RATECONTROL_LA_EXT = 12,
617+ MFX_RATECONTROL_VME = 15,
618+};
619+ #ifdef __cplusplus
620+}
621+ #endif /* __cplusplus */
622+
623+#endif //MFX_ONEVPL
624+#endif //__MFXDEPRECATED_H__
625diff --git a/tools/legacy/media_sdk_compatibility_headers/mfxplugin.h b/tools/legacy/media_sdk_compatibility_headers/mfxplugin.h
626new file mode 100644
627index 0000000..2c42433
628--- /dev/null
629+++ b/tools/legacy/media_sdk_compatibility_headers/mfxplugin.h
630@@ -0,0 +1,601 @@
631+/******************************************************************************* *\
632+
633+Copyright (C) 2007-2019 Intel Corporation. All rights reserved.
634+
635+Redistribution and use in source and binary forms, with or without
636+modification, are permitted provided that the following conditions are met:
637+- Redistributions of source code must retain the above copyright notice,
638+this list of conditions and the following disclaimer.
639+- Redistributions in binary form must reproduce the above copyright notice,
640+this list of conditions and the following disclaimer in the documentation
641+and/or other materials provided with the distribution.
642+- Neither the name of Intel Corporation nor the names of its contributors
643+may be used to endorse or promote products derived from this software
644+without specific prior written permission.
645+
646+THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
647+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
648+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
649+IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
650+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
651+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
652+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
653+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
654+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
655+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
656+
657+File Name: mfxplugin.h
658+
659+*******************************************************************************/
660+#ifndef __MFXPLUGIN_H__
661+#define __MFXPLUGIN_H__
662+#include "mfxaudio.h"
663+#include "mfxdeprecated.h"
664+#include "vpl/mfxvideo.h"
665+#ifdef __cplusplus
666+extern "C" {
667+#endif /* __cplusplus */
668+
669+MFX_PACK_BEGIN_USUAL_STRUCT()
670+typedef struct {
671+ mfxU8 Data[16];
672+} mfxPluginUID;
673+MFX_PACK_END()
674+
675+static const mfxPluginUID MFX_PLUGINID_HEVCD_SW = { { 0x15,
676+ 0xdd,
677+ 0x93,
678+ 0x68,
679+ 0x25,
680+ 0xad,
681+ 0x47,
682+ 0x5e,
683+ 0xa3,
684+ 0x4e,
685+ 0x35,
686+ 0xf3,
687+ 0xf5,
688+ 0x42,
689+ 0x17,
690+ 0xa6 } };
691+static const mfxPluginUID MFX_PLUGINID_HEVCD_HW = { { 0x33,
692+ 0xa6,
693+ 0x1c,
694+ 0x0b,
695+ 0x4c,
696+ 0x27,
697+ 0x45,
698+ 0x4c,
699+ 0xa8,
700+ 0xd8,
701+ 0x5d,
702+ 0xde,
703+ 0x75,
704+ 0x7c,
705+ 0x6f,
706+ 0x8e } };
707+static const mfxPluginUID MFX_PLUGINID_HEVCE_SW = { { 0x2f,
708+ 0xca,
709+ 0x99,
710+ 0x74,
711+ 0x9f,
712+ 0xdb,
713+ 0x49,
714+ 0xae,
715+ 0xb1,
716+ 0x21,
717+ 0xa5,
718+ 0xb6,
719+ 0x3e,
720+ 0xf5,
721+ 0x68,
722+ 0xf7 } };
723+static const mfxPluginUID MFX_PLUGINID_HEVCE_GACC = { { 0xe5,
724+ 0x40,
725+ 0x0a,
726+ 0x06,
727+ 0xc7,
728+ 0x4d,
729+ 0x41,
730+ 0xf5,
731+ 0xb1,
732+ 0x2d,
733+ 0x43,
734+ 0x0b,
735+ 0xba,
736+ 0xa2,
737+ 0x3d,
738+ 0x0b } };
739+static const mfxPluginUID MFX_PLUGINID_HEVCE_DP_GACC = { { 0x2b,
740+ 0xad,
741+ 0x6f,
742+ 0x9d,
743+ 0x77,
744+ 0x54,
745+ 0x41,
746+ 0x2d,
747+ 0xbf,
748+ 0x63,
749+ 0x03,
750+ 0xed,
751+ 0x4b,
752+ 0xb5,
753+ 0x09,
754+ 0x68 } };
755+static const mfxPluginUID MFX_PLUGINID_HEVCE_HW = { { 0x6f,
756+ 0xad,
757+ 0xc7,
758+ 0x91,
759+ 0xa0,
760+ 0xc2,
761+ 0xeb,
762+ 0x47,
763+ 0x9a,
764+ 0xb6,
765+ 0xdc,
766+ 0xd5,
767+ 0xea,
768+ 0x9d,
769+ 0xa3,
770+ 0x47 } };
771+static const mfxPluginUID MFX_PLUGINID_VP8D_HW = { { 0xf6,
772+ 0x22,
773+ 0x39,
774+ 0x4d,
775+ 0x8d,
776+ 0x87,
777+ 0x45,
778+ 0x2f,
779+ 0x87,
780+ 0x8c,
781+ 0x51,
782+ 0xf2,
783+ 0xfc,
784+ 0x9b,
785+ 0x41,
786+ 0x31 } };
787+static const mfxPluginUID MFX_PLUGINID_VP8E_HW = { { 0xbf,
788+ 0xfc,
789+ 0x51,
790+ 0x8c,
791+ 0xde,
792+ 0x13,
793+ 0x4d,
794+ 0xf9,
795+ 0x8a,
796+ 0x96,
797+ 0xf4,
798+ 0xcf,
799+ 0x81,
800+ 0x6c,
801+ 0x0f,
802+ 0xac } };
803+static const mfxPluginUID MFX_PLUGINID_VP9E_HW = { { 0xce,
804+ 0x44,
805+ 0xef,
806+ 0x6f,
807+ 0x1a,
808+ 0x6d,
809+ 0x22,
810+ 0x46,
811+ 0xb4,
812+ 0x12,
813+ 0xbb,
814+ 0x38,
815+ 0xd6,
816+ 0xe4,
817+ 0x51,
818+ 0x82 } };
819+static const mfxPluginUID MFX_PLUGINID_VP9D_HW = { { 0xa9,
820+ 0x22,
821+ 0x39,
822+ 0x4d,
823+ 0x8d,
824+ 0x87,
825+ 0x45,
826+ 0x2f,
827+ 0x87,
828+ 0x8c,
829+ 0x51,
830+ 0xf2,
831+ 0xfc,
832+ 0x9b,
833+ 0x41,
834+ 0x31 } };
835+static const mfxPluginUID MFX_PLUGINID_CAMERA_HW = { { 0x54,
836+ 0x54,
837+ 0x26,
838+ 0x16,
839+ 0x24,
840+ 0x33,
841+ 0x41,
842+ 0xe6,
843+ 0x93,
844+ 0xae,
845+ 0x89,
846+ 0x99,
847+ 0x42,
848+ 0xce,
849+ 0x73,
850+ 0x55 } };
851+static const mfxPluginUID MFX_PLUGINID_CAPTURE_HW = { { 0x22,
852+ 0xd6,
853+ 0x2c,
854+ 0x07,
855+ 0xe6,
856+ 0x72,
857+ 0x40,
858+ 0x8f,
859+ 0xbb,
860+ 0x4c,
861+ 0xc2,
862+ 0x0e,
863+ 0xd7,
864+ 0xa0,
865+ 0x53,
866+ 0xe4 } };
867+static const mfxPluginUID MFX_PLUGINID_ITELECINE_HW = { { 0xe7,
868+ 0x44,
869+ 0x75,
870+ 0x3a,
871+ 0xcd,
872+ 0x74,
873+ 0x40,
874+ 0x2e,
875+ 0x89,
876+ 0xa2,
877+ 0xee,
878+ 0x06,
879+ 0x35,
880+ 0x49,
881+ 0x61,
882+ 0x79 } };
883+static const mfxPluginUID MFX_PLUGINID_H264LA_HW = { { 0x58,
884+ 0x8f,
885+ 0x11,
886+ 0x85,
887+ 0xd4,
888+ 0x7b,
889+ 0x42,
890+ 0x96,
891+ 0x8d,
892+ 0xea,
893+ 0x37,
894+ 0x7b,
895+ 0xb5,
896+ 0xd0,
897+ 0xdc,
898+ 0xb4 } };
899+static const mfxPluginUID MFX_PLUGINID_AACD = { { 0xe9,
900+ 0x34,
901+ 0x67,
902+ 0x25,
903+ 0xac,
904+ 0x2f,
905+ 0x4c,
906+ 0x93,
907+ 0xaa,
908+ 0x58,
909+ 0x5c,
910+ 0x11,
911+ 0xc7,
912+ 0x08,
913+ 0x7c,
914+ 0xf4 } };
915+static const mfxPluginUID MFX_PLUGINID_AACE = { { 0xb2,
916+ 0xa2,
917+ 0xa0,
918+ 0x5a,
919+ 0x4e,
920+ 0xac,
921+ 0x46,
922+ 0xbf,
923+ 0xa9,
924+ 0xde,
925+ 0x7e,
926+ 0x80,
927+ 0xc9,
928+ 0x8d,
929+ 0x2e,
930+ 0x18 } };
931+static const mfxPluginUID MFX_PLUGINID_HEVCE_FEI_HW = { { 0x87,
932+ 0xe0,
933+ 0xe8,
934+ 0x02,
935+ 0x07,
936+ 0x37,
937+ 0x52,
938+ 0x40,
939+ 0x85,
940+ 0x25,
941+ 0x15,
942+ 0xcf,
943+ 0x4a,
944+ 0x5e,
945+ 0xdd,
946+ 0xe6 } };
947+#if (MFX_VERSION >= 1027)
948+static const mfxPluginUID MFX_PLUGINID_HEVC_FEI_ENCODE = { { 0x54,
949+ 0x18,
950+ 0xa7,
951+ 0x06,
952+ 0x66,
953+ 0xf9,
954+ 0x4d,
955+ 0x5c,
956+ 0xb4,
957+ 0xf7,
958+ 0xb1,
959+ 0xca,
960+ 0xee,
961+ 0x86,
962+ 0x33,
963+ 0x9b } };
964+#endif
965+#if !defined(OPEN_SOURCE)
966+static const mfxPluginUID MFX_PLUGINID_AV1D_SW = { { 0x93,
967+ 0x6c,
968+ 0x26,
969+ 0xe8,
970+ 0xf9,
971+ 0xb5,
972+ 0x45,
973+ 0xdc,
974+ 0xad,
975+ 0xac,
976+ 0xe8,
977+ 0xcc,
978+ 0xeb,
979+ 0x8a,
980+ 0x57,
981+ 0xa9 } };
982+static const mfxPluginUID MFX_PLUGINID_AV1D_HW = { { 0x07,
983+ 0x49,
984+ 0xdf,
985+ 0x10,
986+ 0x72,
987+ 0x66,
988+ 0x4f,
989+ 0x1d,
990+ 0x8d,
991+ 0x77,
992+ 0x29,
993+ 0x8e,
994+ 0xb2,
995+ 0x97,
996+ 0x5c,
997+ 0x3c } };
998+static const mfxPluginUID MFX_PLUGINID_AV1E_GACC = { { 0x34,
999+ 0x3d,
1000+ 0x68,
1001+ 0x96,
1002+ 0x65,
1003+ 0xba,
1004+ 0x45,
1005+ 0x48,
1006+ 0x82,
1007+ 0x99,
1008+ 0x42,
1009+ 0xa3,
1010+ 0x2a,
1011+ 0x38,
1012+ 0x65,
1013+ 0x69 } };
1014+#endif
1015+
1016+typedef enum {
1017+ MFX_PLUGINTYPE_VIDEO_GENERAL = 0,
1018+ MFX_PLUGINTYPE_VIDEO_DECODE = 1,
1019+ MFX_PLUGINTYPE_VIDEO_ENCODE = 2,
1020+ MFX_PLUGINTYPE_VIDEO_VPP = 3,
1021+ MFX_PLUGINTYPE_VIDEO_ENC = 4,
1022+ MFX_PLUGINTYPE_AUDIO_DECODE = 5,
1023+ MFX_PLUGINTYPE_AUDIO_ENCODE = 6
1024+} mfxPluginType;
1025+
1026+typedef enum { MFX_THREADPOLICY_SERIAL = 0, MFX_THREADPOLICY_PARALLEL = 1 } mfxThreadPolicy;
1027+
1028+MFX_PACK_BEGIN_USUAL_STRUCT()
1029+typedef struct mfxPluginParam {
1030+ mfxU32 reserved[6];
1031+ mfxU16 reserved1;
1032+ mfxU16 PluginVersion;
1033+ mfxVersion APIVersion;
1034+ mfxPluginUID PluginUID;
1035+ mfxU32 Type;
1036+ mfxU32 CodecId;
1037+ mfxThreadPolicy ThreadPolicy;
1038+ mfxU32 MaxThreadNum;
1039+} mfxPluginParam;
1040+MFX_PACK_END()
1041+
1042+MFX_PACK_BEGIN_USUAL_STRUCT()
1043+typedef struct mfxCoreParam {
1044+ mfxU32 reserved[13];
1045+ mfxIMPL Impl;
1046+ mfxVersion Version;
1047+ mfxU32 NumWorkingThread;
1048+} mfxCoreParam;
1049+MFX_PACK_END()
1050+
1051+MFX_PACK_BEGIN_STRUCT_W_PTR()
1052+typedef struct mfxCoreInterface {
1053+ mfxHDL pthis;
1054+
1055+ mfxHDL reserved1[2];
1056+ mfxFrameAllocator FrameAllocator;
1057+ //mfxBufferAllocator reserved3;
1058+
1059+ mfxStatus(MFX_CDECL *GetCoreParam)(mfxHDL pthis, mfxCoreParam *par);
1060+ mfxStatus(MFX_CDECL *GetHandle)(mfxHDL pthis, mfxHandleType type, mfxHDL *handle);
1061+ mfxStatus(MFX_CDECL *IncreaseReference)(mfxHDL pthis, mfxFrameData *fd);
1062+ mfxStatus(MFX_CDECL *DecreaseReference)(mfxHDL pthis, mfxFrameData *fd);
1063+ mfxStatus(MFX_CDECL *CopyFrame)(mfxHDL pthis, mfxFrameSurface1 *dst, mfxFrameSurface1 *src);
1064+ mfxStatus(MFX_CDECL *CopyBuffer)(mfxHDL pthis, mfxU8 *dst, mfxU32 size, mfxFrameSurface1 *src);
1065+
1066+ mfxStatus(MFX_CDECL *MapOpaqueSurface)(mfxHDL pthis,
1067+ mfxU32 num,
1068+ mfxU32 type,
1069+ mfxFrameSurface1 **op_surf);
1070+ mfxStatus(MFX_CDECL *UnmapOpaqueSurface)(mfxHDL pthis,
1071+ mfxU32 num,
1072+ mfxU32 type,
1073+ mfxFrameSurface1 **op_surf);
1074+
1075+ mfxStatus(MFX_CDECL *GetRealSurface)(mfxHDL pthis,
1076+ mfxFrameSurface1 *op_surf,
1077+ mfxFrameSurface1 **surf);
1078+ mfxStatus(MFX_CDECL *GetOpaqueSurface)(mfxHDL pthis,
1079+ mfxFrameSurface1 *surf,
1080+ mfxFrameSurface1 **op_surf);
1081+
1082+ mfxStatus(MFX_CDECL *CreateAccelerationDevice)(mfxHDL pthis,
1083+ mfxHandleType type,
1084+ mfxHDL *handle);
1085+ mfxStatus(MFX_CDECL *GetFrameHandle)(mfxHDL pthis, mfxFrameData *fd, mfxHDL *handle);
1086+ mfxStatus(MFX_CDECL *QueryPlatform)(mfxHDL pthis, mfxPlatform *platform);
1087+
1088+ mfxHDL reserved4[1];
1089+} mfxCoreInterface;
1090+MFX_PACK_END()
1091+
1092+MFX_PACK_BEGIN_STRUCT_W_PTR()
1093+/* video codec plugin extension */
1094+typedef struct _mfxENCInput mfxENCInput;
1095+typedef struct _mfxENCOutput mfxENCOutput;
1096+typedef struct mfxVideoCodecPlugin {
1097+ mfxStatus(MFX_CDECL *Query)(mfxHDL pthis, mfxVideoParam *in, mfxVideoParam *out);
1098+ mfxStatus(MFX_CDECL *QueryIOSurf)(mfxHDL pthis,
1099+ mfxVideoParam *par,
1100+ mfxFrameAllocRequest *in,
1101+ mfxFrameAllocRequest *out);
1102+ mfxStatus(MFX_CDECL *Init)(mfxHDL pthis, mfxVideoParam *par);
1103+ mfxStatus(MFX_CDECL *Reset)(mfxHDL pthis, mfxVideoParam *par);
1104+ mfxStatus(MFX_CDECL *Close)(mfxHDL pthis);
1105+ mfxStatus(MFX_CDECL *GetVideoParam)(mfxHDL pthis, mfxVideoParam *par);
1106+
1107+ mfxStatus(MFX_CDECL *EncodeFrameSubmit)(mfxHDL pthis,
1108+ mfxEncodeCtrl *ctrl,
1109+ mfxFrameSurface1 *surface,
1110+ mfxBitstream *bs,
1111+ mfxThreadTask *task);
1112+
1113+ mfxStatus(MFX_CDECL *DecodeHeader)(mfxHDL pthis, mfxBitstream *bs, mfxVideoParam *par);
1114+ mfxStatus(MFX_CDECL *GetPayload)(mfxHDL pthis, mfxU64 *ts, mfxPayload *payload);
1115+ mfxStatus(MFX_CDECL *DecodeFrameSubmit)(mfxHDL pthis,
1116+ mfxBitstream *bs,
1117+ mfxFrameSurface1 *surface_work,
1118+ mfxFrameSurface1 **surface_out,
1119+ mfxThreadTask *task);
1120+
1121+ mfxStatus(MFX_CDECL *VPPFrameSubmit)(mfxHDL pthis,
1122+ mfxFrameSurface1 *in,
1123+ mfxFrameSurface1 *out,
1124+ mfxExtVppAuxData *aux,
1125+ mfxThreadTask *task);
1126+ mfxStatus(MFX_CDECL *VPPFrameSubmitEx)(mfxHDL pthis,
1127+ mfxFrameSurface1 *in,
1128+ mfxFrameSurface1 *surface_work,
1129+ mfxFrameSurface1 **surface_out,
1130+ mfxThreadTask *task);
1131+
1132+ mfxStatus(MFX_CDECL *ENCFrameSubmit)(mfxHDL pthis,
1133+ mfxENCInput *in,
1134+ mfxENCOutput *out,
1135+ mfxThreadTask *task);
1136+
1137+ mfxHDL reserved1[3];
1138+ mfxU32 reserved2[8];
1139+} mfxVideoCodecPlugin;
1140+MFX_PACK_END()
1141+
1142+MFX_PACK_BEGIN_STRUCT_W_PTR()
1143+typedef struct mfxAudioCodecPlugin {
1144+ mfxStatus(MFX_CDECL *Query)(mfxHDL pthis, mfxAudioParam *in, mfxAudioParam *out);
1145+ mfxStatus(MFX_CDECL *QueryIOSize)(mfxHDL pthis,
1146+ mfxAudioParam *par,
1147+ mfxAudioAllocRequest *request);
1148+ mfxStatus(MFX_CDECL *Init)(mfxHDL pthis, mfxAudioParam *par);
1149+ mfxStatus(MFX_CDECL *Reset)(mfxHDL pthis, mfxAudioParam *par);
1150+ mfxStatus(MFX_CDECL *Close)(mfxHDL pthis);
1151+ mfxStatus(MFX_CDECL *GetAudioParam)(mfxHDL pthis, mfxAudioParam *par);
1152+
1153+ mfxStatus(MFX_CDECL *EncodeFrameSubmit)(mfxHDL pthis,
1154+ mfxAudioFrame *aFrame,
1155+ mfxBitstream *out,
1156+ mfxThreadTask *task);
1157+
1158+ mfxStatus(MFX_CDECL *DecodeHeader)(mfxHDL pthis, mfxBitstream *bs, mfxAudioParam *par);
1159+ // mfxStatus (MFX_CDECL *GetPayload)(mfxHDL pthis, mfxU64 *ts, mfxPayload *payload);
1160+ mfxStatus(MFX_CDECL *DecodeFrameSubmit)(mfxHDL pthis,
1161+ mfxBitstream *in,
1162+ mfxAudioFrame *out,
1163+ mfxThreadTask *task);
1164+
1165+ mfxHDL reserved1[6];
1166+ mfxU32 reserved2[8];
1167+} mfxAudioCodecPlugin;
1168+MFX_PACK_END()
1169+
1170+MFX_PACK_BEGIN_STRUCT_W_PTR()
1171+typedef struct mfxPlugin {
1172+ mfxHDL pthis;
1173+
1174+ mfxStatus(MFX_CDECL *PluginInit)(mfxHDL pthis, mfxCoreInterface *core);
1175+ mfxStatus(MFX_CDECL *PluginClose)(mfxHDL pthis);
1176+
1177+ mfxStatus(MFX_CDECL *GetPluginParam)(mfxHDL pthis, mfxPluginParam *par);
1178+
1179+ mfxStatus(MFX_CDECL *Submit)(mfxHDL pthis,
1180+ const mfxHDL *in,
1181+ mfxU32 in_num,
1182+ const mfxHDL *out,
1183+ mfxU32 out_num,
1184+ mfxThreadTask *task);
1185+ mfxStatus(MFX_CDECL *Execute)(mfxHDL pthis, mfxThreadTask task, mfxU32 uid_p, mfxU32 uid_a);
1186+ mfxStatus(MFX_CDECL *FreeResources)(mfxHDL pthis, mfxThreadTask task, mfxStatus sts);
1187+
1188+ union {
1189+ mfxVideoCodecPlugin *Video;
1190+ mfxAudioCodecPlugin *Audio;
1191+ };
1192+
1193+ mfxHDL reserved[8];
1194+} mfxPlugin;
1195+MFX_PACK_END()
1196+
1197+mfxStatus MFX_CDECL MFXVideoUSER_Register(mfxSession session, mfxU32 type, const mfxPlugin *par);
1198+mfxStatus MFX_CDECL MFXVideoUSER_Unregister(mfxSession session, mfxU32 type);
1199+mfxStatus MFX_CDECL MFXVideoUSER_GetPlugin(mfxSession session, mfxU32 type, mfxPlugin *par);
1200+mfxStatus MFX_CDECL MFXVideoUSER_ProcessFrameAsync(mfxSession session,
1201+ const mfxHDL *in,
1202+ mfxU32 in_num,
1203+ const mfxHDL *out,
1204+ mfxU32 out_num,
1205+ mfxSyncPoint *syncp);
1206+
1207+mfxStatus MFX_CDECL MFXVideoUSER_Load(mfxSession session, const mfxPluginUID *uid, mfxU32 version);
1208+mfxStatus MFX_CDECL MFXVideoUSER_LoadByPath(mfxSession session,
1209+ const mfxPluginUID *uid,
1210+ mfxU32 version,
1211+ const mfxChar *path,
1212+ mfxU32 len);
1213+mfxStatus MFX_CDECL MFXVideoUSER_UnLoad(mfxSession session, const mfxPluginUID *uid);
1214+
1215+mfxStatus MFX_CDECL MFXAudioUSER_Register(mfxSession session, mfxU32 type, const mfxPlugin *par);
1216+mfxStatus MFX_CDECL MFXAudioUSER_Unregister(mfxSession session, mfxU32 type);
1217+mfxStatus MFX_CDECL MFXAudioUSER_ProcessFrameAsync(mfxSession session,
1218+ const mfxHDL *in,
1219+ mfxU32 in_num,
1220+ const mfxHDL *out,
1221+ mfxU32 out_num,
1222+ mfxSyncPoint *syncp);
1223+
1224+mfxStatus MFX_CDECL MFXAudioUSER_Load(mfxSession session, const mfxPluginUID *uid, mfxU32 version);
1225+mfxStatus MFX_CDECL MFXAudioUSER_UnLoad(mfxSession session, const mfxPluginUID *uid);
1226+
1227+#ifdef __cplusplus
1228+} // extern "C"
1229+#endif /* __cplusplus */
1230+
1231+#endif /* __MFXPLUGIN_H__ */
1232diff --git a/tools/legacy/media_sdk_compatibility_headers/rotate_plugin_api.h b/tools/legacy/media_sdk_compatibility_headers/rotate_plugin_api.h
1233new file mode 100644
1234index 0000000..928f6c3
1235--- /dev/null
1236+++ b/tools/legacy/media_sdk_compatibility_headers/rotate_plugin_api.h
1237@@ -0,0 +1,29 @@
1238+/******************************************************************************\
1239+Copyright (c) 2005-2018, Intel Corporation
1240+All rights reserved.
1241+
1242+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1243+
1244+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
1245+
1246+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
1247+
1248+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
1249+
1250+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1251+
1252+This sample was distributed or derived from the Intel's Media Samples package.
1253+The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
1254+or https://software.intel.com/en-us/media-client-solutions-support.
1255+\**********************************************************************************/
1256+
1257+#ifndef __MFX_PLUGIN_ROTATE_API_H__
1258+#define __MFX_PLUGIN_ROTATE_API_H__
1259+
1260+#include "mfxdefs.h"
1261+
1262+struct RotateParam {
1263+ mfxU16 Angle; // rotation angle
1264+};
1265+
1266+#endif // __MFX_PLUGIN_ROTATE_API_H__
1267diff --git a/tools/legacy/sample_common/CMakeLists.txt b/tools/legacy/sample_common/CMakeLists.txt
1268index 4f04226..86b5fd8 100644
1269--- a/tools/legacy/sample_common/CMakeLists.txt
1270+++ b/tools/legacy/sample_common/CMakeLists.txt
1271@@ -17,8 +17,10 @@ list(
1272 src/sysmem_allocator.cpp
1273 src/general_allocator.cpp
1274 src/sample_utils.cpp
1275+ src/plugin_utils.cpp
1276 src/preset_manager.cpp
1277 src/parameters_dumper.cpp
1278+ src/vpl_implementation_loader.cpp
1279 src/vm/atomic.cpp
1280 src/vm/time.cpp)
1281
1282@@ -62,7 +64,7 @@ if(POLICY CMP0074)
1283 endif()
1284
1285 find_package(VPL REQUIRED)
1286-target_link_libraries(${TARGET} VPL::dispatcher)
1287+target_link_libraries(${TARGET} VPL::dispatcher media_sdk_compatibility_headers)
1288
1289 if(UNIX)
1290 find_package(PkgConfig REQUIRED)
1291diff --git a/tools/legacy/sample_common/include/plugin_utils.h b/tools/legacy/sample_common/include/plugin_utils.h
1292index 80b7baf..8401c0c 100644
1293--- a/tools/legacy/sample_common/include/plugin_utils.h
1294+++ b/tools/legacy/sample_common/include/plugin_utils.h
1295@@ -7,6 +7,7 @@
1296 #ifndef __PLUGIN_UTILS_H__
1297 #define __PLUGIN_UTILS_H__
1298
1299+#include "mfxplugin.h"
1300 #include "sample_defs.h"
1301 #include "sample_types.h"
1302
1303diff --git a/tools/legacy/sample_common/include/sample_utils.h b/tools/legacy/sample_common/include/sample_utils.h
1304index db9b3fd..b138692 100644
1305--- a/tools/legacy/sample_common/include/sample_utils.h
1306+++ b/tools/legacy/sample_common/include/sample_utils.h
1307@@ -46,6 +46,7 @@
1308 #include "avc_headers.h"
1309 #include "avc_nal_spl.h"
1310 #include "avc_spl.h"
1311+#include "vpl_implementation_loader.h"
1312
1313 // A macro to disallow the copy constructor and operator= functions
1314 // This should be used in the private: declarations for a class
1315@@ -653,7 +654,7 @@ public:
1316 TB* GetExtBuffer(uint32_t fieldId = 0) const {
1317 return (TB*)FindExtBuffer(mfx_ext_buffer_id<TB>::id, fieldId);
1318 }
1319-
1320+#if 0
1321 template <typename TB>
1322 operator TB*() {
1323 return (TB*)FindExtBuffer(mfx_ext_buffer_id<TB>::id, 0);
1324@@ -663,7 +664,7 @@ public:
1325 operator TB*() const {
1326 return (TB*)FindExtBuffer(mfx_ext_buffer_id<TB>::id, 0);
1327 }
1328-
1329+#endif
1330 private:
1331 mfxExtBuffer* AddExtBuffer(mfxU32 id, mfxU32 size, bool isPairedExtBuffer) {
1332 if (!size || !id)
1333diff --git a/tools/legacy/sample_common/include/sample_utils.h.orig b/tools/legacy/sample_common/include/sample_utils.h.orig
1334new file mode 100644
1335index 0000000..db9b3fd
1336--- /dev/null
1337+++ b/tools/legacy/sample_common/include/sample_utils.h.orig
1338@@ -0,0 +1,1437 @@
1339+/*############################################################################
1340+ # Copyright (C) Intel Corporation
1341+ #
1342+ # SPDX-License-Identifier: MIT
1343+ ############################################################################*/
1344+
1345+#ifndef __SAMPLE_UTILS_H__
1346+#define __SAMPLE_UTILS_H__
1347+
1348+#include <stdio.h>
1349+#include <algorithm>
1350+#include <climits>
1351+#include <fstream>
1352+#include <map>
1353+#include <mutex>
1354+#include <sstream>
1355+#include <stdexcept>
1356+#include <string>
1357+#include <vector>
1358+
1359+#include "vpl/mfxbrc.h"
1360+#if (MFX_VERSION < 2000)
1361+ #include "mfxfei.h"
1362+ #include "mfxfeihevc.h"
1363+#endif
1364+#include "vpl/mfxjpeg.h"
1365+#if (MFX_VERSION < 2000)
1366+ #include "mfxla.h"
1367+ #include "mfxmvc.h"
1368+ #include "mfxplugin.h"
1369+#endif
1370+#include "vpl/mfxstructures.h"
1371+#include "vpl/mfxvideo++.h"
1372+#include "vpl/mfxvideo.h"
1373+
1374+#include "vm/atomic_defs.h"
1375+#include "vm/file_defs.h"
1376+#include "vm/strings_defs.h"
1377+#include "vm/thread_defs.h"
1378+#include "vm/time_defs.h"
1379+
1380+#include "sample_types.h"
1381+
1382+#include "abstract_splitter.h"
1383+#include "avc_bitstream.h"
1384+#include "avc_headers.h"
1385+#include "avc_nal_spl.h"
1386+#include "avc_spl.h"
1387+
1388+// A macro to disallow the copy constructor and operator= functions
1389+// This should be used in the private: declarations for a class
1390+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
1391+ TypeName(const TypeName&); \
1392+ void operator=(const TypeName&)
1393+
1394+//! Base class for types that should not be assigned.
1395+class no_assign {
1396+ // Deny assignment
1397+ void operator=(const no_assign&);
1398+
1399+public:
1400+#if __GNUC__
1401+ //! Explicitly define default construction, because otherwise gcc issues gratuitous warning.
1402+ no_assign() {}
1403+#endif /* __GNUC__ */
1404+};
1405+
1406+//! Base class for types that should not be copied or assigned.
1407+class no_copy : no_assign {
1408+ //! Deny copy construction
1409+ no_copy(const no_copy&);
1410+
1411+ // Deny assignment
1412+ void operator=(const no_copy&);
1413+
1414+public:
1415+ //! Allow default construction
1416+ no_copy() {}
1417+};
1418+
1419+enum {
1420+ CODEC_VP8 = MFX_MAKEFOURCC('V', 'P', '8', ' '),
1421+ CODEC_MVC = MFX_MAKEFOURCC('M', 'V', 'C', ' '),
1422+};
1423+
1424+#define MFX_CODEC_DUMP MFX_MAKEFOURCC('D', 'U', 'M', 'P')
1425+#define MFX_CODEC_RGB4 MFX_FOURCC_RGB4
1426+#define MFX_CODEC_NV12 MFX_FOURCC_NV12
1427+#define MFX_CODEC_I420 MFX_FOURCC_I420
1428+#if (MFX_VERSION < 2000)
1429+enum {
1430+ MFX_FOURCC_IMC3 = MFX_MAKEFOURCC('I', 'M', 'C', '3'),
1431+ MFX_FOURCC_YUV400 = MFX_MAKEFOURCC('4', '0', '0', 'P'),
1432+ MFX_FOURCC_YUV411 = MFX_MAKEFOURCC('4', '1', '1', 'P'),
1433+ MFX_FOURCC_YUV422H = MFX_MAKEFOURCC('4', '2', '2', 'H'),
1434+ MFX_FOURCC_YUV422V = MFX_MAKEFOURCC('4', '2', '2', 'V'),
1435+ MFX_FOURCC_YUV444 = MFX_MAKEFOURCC('4', '4', '4', 'P'),
1436+ #if (MFX_VERSION <= 1027)
1437+ MFX_FOURCC_RGBP = MFX_MAKEFOURCC('R', 'G', 'B', 'P'),
1438+ #endif
1439+ MFX_FOURCC_I420 = MFX_MAKEFOURCC('I', '4', '2', '0')
1440+};
1441+#endif
1442+enum ExtBRCType { EXTBRC_DEFAULT, EXTBRC_OFF, EXTBRC_ON, EXTBRC_IMPLICIT };
1443+
1444+namespace QPFile {
1445+
1446+enum ReaderStatus {
1447+ READER_ERR_NONE,
1448+ READER_ERR_NOT_INITIALIZED,
1449+ READER_ERR_CODEC_UNSUPPORTED,
1450+ READER_ERR_FILE_NOT_OPEN,
1451+ READER_ERR_INCORRECT_FILE
1452+};
1453+
1454+struct FrameInfo {
1455+ mfxU32 displayOrder;
1456+ mfxU16 QP;
1457+ mfxU16 frameType;
1458+};
1459+
1460+// QPFile::Reader reads QP and frame type per frame in encoding order
1461+// from external text file (for encoding in qpfile mode)
1462+class Reader {
1463+public:
1464+ mfxStatus Read(const msdk_string& strFileName, mfxU32 codecid);
1465+ void ResetState();
1466+
1467+ mfxU32 GetCurrentEncodedOrder() const;
1468+ mfxU32 GetCurrentDisplayOrder() const;
1469+ mfxU16 GetCurrentQP() const;
1470+ mfxU16 GetCurrentFrameType() const;
1471+ mfxU32 GetFramesNum() const;
1472+ void NextFrame();
1473+ std::string GetErrorMessage() const;
1474+
1475+private:
1476+ void ResetState(ReaderStatus set_sts);
1477+
1478+ ReaderStatus m_ReaderSts = READER_ERR_NOT_INITIALIZED;
1479+ mfxU32 m_nFrames = UINT_MAX;
1480+ mfxU32 m_CurFrameNum = UINT_MAX;
1481+ std::vector<FrameInfo> m_FrameVals{};
1482+};
1483+
1484+inline bool get_line(std::ifstream& ifs, std::string& line) {
1485+ std::getline(ifs, line, '\n');
1486+ if (!line.empty() && line.back() == '\r')
1487+ line.pop_back();
1488+ return !ifs.fail();
1489+}
1490+inline size_t find_nth(const std::string& str, size_t pos, const std::string& needle, mfxU32 nth) {
1491+ size_t found_pos = str.find(needle, pos);
1492+ for (; nth != 0 && std::string::npos != found_pos; --nth)
1493+ found_pos = str.find(needle, found_pos + 1);
1494+ return found_pos;
1495+}
1496+inline mfxU16 StringToFrameType(std::string str) {
1497+ if ("IDR_REF" == str)
1498+ return MFX_FRAMETYPE_I | MFX_FRAMETYPE_IDR | MFX_FRAMETYPE_REF;
1499+ else if ("I_REF" == str)
1500+ return MFX_FRAMETYPE_I | MFX_FRAMETYPE_REF;
1501+ else if ("P_REF" == str)
1502+ return MFX_FRAMETYPE_P | MFX_FRAMETYPE_REF;
1503+ else if ("P" == str)
1504+ return MFX_FRAMETYPE_P;
1505+ else if ("B_REF" == str)
1506+ return MFX_FRAMETYPE_B | MFX_FRAMETYPE_REF;
1507+ else if ("B" == str)
1508+ return MFX_FRAMETYPE_B;
1509+ else
1510+ return MFX_FRAMETYPE_UNKNOWN;
1511+}
1512+inline std::string ReaderStatusToString(ReaderStatus sts) {
1513+ switch (sts) {
1514+ case READER_ERR_NOT_INITIALIZED:
1515+ return std::string("reader not initialized (qpfile has not yet read the file)\n");
1516+ case READER_ERR_FILE_NOT_OPEN:
1517+ return std::string(
1518+ "failed to open file contains frame parameters (check provided path in -qpfile <path>)\n");
1519+ case READER_ERR_INCORRECT_FILE:
1520+ return std::string("incorrect file with frame parameters\n");
1521+ case READER_ERR_CODEC_UNSUPPORTED:
1522+ return std::string("codecs, except h264 and h265, are not supported\n");
1523+ default:
1524+ return std::string();
1525+ }
1526+}
1527+inline mfxU32 ReadDisplayOrder(const std::string& line) {
1528+ return std::stoi(line.substr(0, find_nth(line, 0, ",", 0)));
1529+}
1530+inline mfxU16 ReadQP(const std::string& line) {
1531+ size_t pos = find_nth(line, 0, ",", 0) + 1;
1532+ return static_cast<mfxU16>(std::stoi(line.substr(pos, find_nth(line, 0, ",", 1) - pos)));
1533+}
1534+inline mfxU16 ReadFrameType(const std::string& line) {
1535+ size_t pos = find_nth(line, 0, ",", 1) + 1;
1536+ return StringToFrameType(line.substr(pos, line.length() - pos));
1537+}
1538+} // namespace QPFile
1539+
1540+mfxStatus GetFrameLength(mfxU16 width, mfxU16 height, mfxU32 ColorFormat, mfxU32& length);
1541+
1542+bool IsDecodeCodecSupported(mfxU32 codecFormat);
1543+bool IsEncodeCodecSupported(mfxU32 codecFormat);
1544+bool IsPluginCodecSupported(mfxU32 codecFormat);
1545+
1546+// class is used as custom exception
1547+class mfxError : public std::runtime_error {
1548+public:
1549+ mfxError(mfxStatus status = MFX_ERR_UNKNOWN, std::string msg = "")
1550+ : runtime_error(msg),
1551+ m_Status(status) {}
1552+
1553+ mfxStatus GetStatus() const {
1554+ return m_Status;
1555+ }
1556+
1557+private:
1558+ mfxStatus m_Status;
1559+};
1560+
1561+//declare used extension buffers
1562+template <class T>
1563+struct mfx_ext_buffer_id {};
1564+
1565+template <>
1566+struct mfx_ext_buffer_id<mfxExtCodingOption> {
1567+ enum { id = MFX_EXTBUFF_CODING_OPTION };
1568+};
1569+template <>
1570+struct mfx_ext_buffer_id<mfxExtCodingOption2> {
1571+ enum { id = MFX_EXTBUFF_CODING_OPTION2 };
1572+};
1573+template <>
1574+struct mfx_ext_buffer_id<mfxExtCodingOption3> {
1575+ enum { id = MFX_EXTBUFF_CODING_OPTION3 };
1576+};
1577+template <>
1578+struct mfx_ext_buffer_id<mfxExtAvcTemporalLayers> {
1579+ enum { id = MFX_EXTBUFF_AVC_TEMPORAL_LAYERS };
1580+};
1581+template <>
1582+struct mfx_ext_buffer_id<mfxExtAVCRefListCtrl> {
1583+ enum { id = MFX_EXTBUFF_AVC_REFLIST_CTRL };
1584+};
1585+template <>
1586+struct mfx_ext_buffer_id<mfxExtThreadsParam> {
1587+ enum { id = MFX_EXTBUFF_THREADS_PARAM };
1588+};
1589+#if (MFX_VERSION < 2000)
1590+template <>
1591+struct mfx_ext_buffer_id<mfxExtFeiParam> {
1592+ enum { id = MFX_EXTBUFF_FEI_PARAM };
1593+};
1594+template <>
1595+struct mfx_ext_buffer_id<mfxExtFeiPreEncCtrl> {
1596+ enum { id = MFX_EXTBUFF_FEI_PREENC_CTRL };
1597+};
1598+template <>
1599+struct mfx_ext_buffer_id<mfxExtFeiPreEncMV> {
1600+ enum { id = MFX_EXTBUFF_FEI_PREENC_MV };
1601+};
1602+template <>
1603+struct mfx_ext_buffer_id<mfxExtFeiPreEncMBStat> {
1604+ enum { id = MFX_EXTBUFF_FEI_PREENC_MB };
1605+};
1606+template <>
1607+struct mfx_ext_buffer_id<mfxExtFeiHevcEncFrameCtrl> {
1608+ enum { id = MFX_EXTBUFF_HEVCFEI_ENC_CTRL };
1609+};
1610+template <>
1611+struct mfx_ext_buffer_id<mfxExtFeiHevcEncMVPredictors> {
1612+ enum { id = MFX_EXTBUFF_HEVCFEI_ENC_MV_PRED };
1613+};
1614+template <>
1615+struct mfx_ext_buffer_id<mfxExtFeiHevcEncQP> {
1616+ enum { id = MFX_EXTBUFF_HEVCFEI_ENC_QP };
1617+};
1618+template <>
1619+struct mfx_ext_buffer_id<mfxExtFeiHevcEncCtuCtrl> {
1620+ enum { id = MFX_EXTBUFF_HEVCFEI_ENC_CTU_CTRL };
1621+};
1622+template <>
1623+struct mfx_ext_buffer_id<mfxExtHEVCRefLists> {
1624+ enum { id = MFX_EXTBUFF_HEVC_REFLISTS };
1625+};
1626+template <>
1627+struct mfx_ext_buffer_id<mfxExtFeiHevcRepackCtrl> {
1628+ enum { id = MFX_EXTBUFF_HEVCFEI_REPACK_CTRL };
1629+};
1630+template <>
1631+struct mfx_ext_buffer_id<mfxExtFeiHevcRepackStat> {
1632+ enum { id = MFX_EXTBUFF_HEVCFEI_REPACK_STAT };
1633+};
1634+template <>
1635+struct mfx_ext_buffer_id<mfxExtBRC> {
1636+ enum { id = MFX_EXTBUFF_BRC };
1637+};
1638+#endif
1639+template <>
1640+struct mfx_ext_buffer_id<mfxExtHEVCParam> {
1641+ enum { id = MFX_EXTBUFF_HEVC_PARAM };
1642+};
1643+template <>
1644+struct mfx_ext_buffer_id<mfxExtDecVideoProcessing> {
1645+ enum { id = MFX_EXTBUFF_DEC_VIDEO_PROCESSING };
1646+};
1647+template <>
1648+struct mfx_ext_buffer_id<mfxExtDecodeErrorReport> {
1649+ enum { id = MFX_EXTBUFF_DECODE_ERROR_REPORT };
1650+};
1651+#if (MFX_VERSION < 2000)
1652+template <>
1653+struct mfx_ext_buffer_id<mfxExtMVCSeqDesc> {
1654+ enum { id = MFX_EXTBUFF_MVC_SEQ_DESC };
1655+};
1656+#endif
1657+template <>
1658+struct mfx_ext_buffer_id<mfxExtVPPDoNotUse> {
1659+ enum { id = MFX_EXTBUFF_VPP_DONOTUSE };
1660+};
1661+template <>
1662+struct mfx_ext_buffer_id<mfxExtVPPDoUse> {
1663+ enum { id = MFX_EXTBUFF_VPP_DOUSE };
1664+};
1665+template <>
1666+struct mfx_ext_buffer_id<mfxExtVPPDeinterlacing> {
1667+ enum { id = MFX_EXTBUFF_VPP_DEINTERLACING };
1668+};
1669+template <>
1670+struct mfx_ext_buffer_id<mfxExtCodingOptionSPSPPS> {
1671+ enum { id = MFX_EXTBUFF_CODING_OPTION_SPSPPS };
1672+};
1673+#if (MFX_VERSION < 2000)
1674+template <>
1675+struct mfx_ext_buffer_id<mfxExtOpaqueSurfaceAlloc> {
1676+ enum { id = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION };
1677+};
1678+#endif
1679+template <>
1680+struct mfx_ext_buffer_id<mfxExtVppMctf> {
1681+ enum { id = MFX_EXTBUFF_VPP_MCTF };
1682+};
1683+template <>
1684+struct mfx_ext_buffer_id<mfxExtVPPComposite> {
1685+ enum { id = MFX_EXTBUFF_VPP_COMPOSITE };
1686+};
1687+template <>
1688+struct mfx_ext_buffer_id<mfxExtVPPFieldProcessing> {
1689+ enum { id = MFX_EXTBUFF_VPP_FIELD_PROCESSING };
1690+};
1691+template <>
1692+struct mfx_ext_buffer_id<mfxExtVPPDetail> {
1693+ enum { id = MFX_EXTBUFF_VPP_DETAIL };
1694+};
1695+template <>
1696+struct mfx_ext_buffer_id<mfxExtVPPFrameRateConversion> {
1697+ enum { id = MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION };
1698+};
1699+#if (MFX_VERSION < 2000)
1700+template <>
1701+struct mfx_ext_buffer_id<mfxExtLAControl> {
1702+ enum { id = MFX_EXTBUFF_LOOKAHEAD_CTRL };
1703+};
1704+template <>
1705+struct mfx_ext_buffer_id<mfxExtMultiFrameControl> {
1706+ enum { id = MFX_EXTBUFF_MULTI_FRAME_CONTROL };
1707+};
1708+template <>
1709+struct mfx_ext_buffer_id<mfxExtMultiFrameParam> {
1710+ enum { id = MFX_EXTBUFF_MULTI_FRAME_PARAM };
1711+};
1712+#endif
1713+template <>
1714+struct mfx_ext_buffer_id<mfxExtHEVCTiles> {
1715+ enum { id = MFX_EXTBUFF_HEVC_TILES };
1716+};
1717+template <>
1718+struct mfx_ext_buffer_id<mfxExtVP9Param> {
1719+ enum { id = MFX_EXTBUFF_VP9_PARAM };
1720+};
1721+template <>
1722+struct mfx_ext_buffer_id<mfxExtVideoSignalInfo> {
1723+ enum { id = MFX_EXTBUFF_VIDEO_SIGNAL_INFO };
1724+};
1725+template <>
1726+struct mfx_ext_buffer_id<mfxExtHEVCRegion> {
1727+ enum { id = MFX_EXTBUFF_HEVC_REGION };
1728+};
1729+template <>
1730+struct mfx_ext_buffer_id<mfxExtAVCRoundingOffset> {
1731+ enum { id = MFX_EXTBUFF_AVC_ROUNDING_OFFSET };
1732+};
1733+template <>
1734+struct mfx_ext_buffer_id<mfxExtVPPDenoise> {
1735+ enum { id = MFX_EXTBUFF_VPP_DENOISE };
1736+};
1737+template <>
1738+struct mfx_ext_buffer_id<mfxExtVPPProcAmp> {
1739+ enum { id = MFX_EXTBUFF_VPP_PROCAMP };
1740+};
1741+template <>
1742+struct mfx_ext_buffer_id<mfxExtVPPImageStab> {
1743+ enum { id = MFX_EXTBUFF_VPP_IMAGE_STABILIZATION };
1744+};
1745+template <>
1746+struct mfx_ext_buffer_id<mfxExtVPPVideoSignalInfo> {
1747+ enum { id = MFX_EXTBUFF_VPP_VIDEO_SIGNAL_INFO };
1748+};
1749+template <>
1750+struct mfx_ext_buffer_id<mfxExtVPPMirroring> {
1751+ enum { id = MFX_EXTBUFF_VPP_MIRRORING };
1752+};
1753+template <>
1754+struct mfx_ext_buffer_id<mfxExtVPPColorFill> {
1755+ enum { id = MFX_EXTBUFF_VPP_COLORFILL };
1756+};
1757+template <>
1758+struct mfx_ext_buffer_id<mfxExtVPPRotation> {
1759+ enum { id = MFX_EXTBUFF_VPP_ROTATION };
1760+};
1761+template <>
1762+struct mfx_ext_buffer_id<mfxExtVPPScaling> {
1763+ enum { id = MFX_EXTBUFF_VPP_SCALING };
1764+};
1765+template <>
1766+struct mfx_ext_buffer_id<mfxExtColorConversion> {
1767+ enum { id = MFX_EXTBUFF_VPP_COLOR_CONVERSION };
1768+};
1769+template <>
1770+struct mfx_ext_buffer_id<mfxExtPredWeightTable> {
1771+ enum { id = MFX_EXTBUFF_PRED_WEIGHT_TABLE };
1772+};
1773+#if (MFX_VERSION < 2000)
1774+template <>
1775+struct mfx_ext_buffer_id<mfxExtFeiDecStreamOut> {
1776+ enum { id = MFX_EXTBUFF_FEI_DEC_STREAM_OUT };
1777+};
1778+template <>
1779+struct mfx_ext_buffer_id<mfxExtFeiSliceHeader> {
1780+ enum { id = MFX_EXTBUFF_FEI_SLICE };
1781+};
1782+template <>
1783+struct mfx_ext_buffer_id<mfxExtFeiEncFrameCtrl> {
1784+ enum { id = MFX_EXTBUFF_FEI_ENC_CTRL };
1785+};
1786+template <>
1787+struct mfx_ext_buffer_id<mfxExtFeiEncMVPredictors> {
1788+ enum { id = MFX_EXTBUFF_FEI_ENC_MV_PRED };
1789+};
1790+template <>
1791+struct mfx_ext_buffer_id<mfxExtFeiRepackCtrl> {
1792+ enum { id = MFX_EXTBUFF_FEI_REPACK_CTRL };
1793+};
1794+template <>
1795+struct mfx_ext_buffer_id<mfxExtFeiEncMBCtrl> {
1796+ enum { id = MFX_EXTBUFF_FEI_ENC_MB };
1797+};
1798+template <>
1799+struct mfx_ext_buffer_id<mfxExtFeiEncQP> {
1800+ enum { id = MFX_EXTBUFF_FEI_ENC_QP };
1801+};
1802+template <>
1803+struct mfx_ext_buffer_id<mfxExtFeiEncMBStat> {
1804+ enum { id = MFX_EXTBUFF_FEI_ENC_MB_STAT };
1805+};
1806+template <>
1807+struct mfx_ext_buffer_id<mfxExtFeiEncMV> {
1808+ enum { id = MFX_EXTBUFF_FEI_ENC_MV };
1809+};
1810+template <>
1811+struct mfx_ext_buffer_id<mfxExtFeiPakMBCtrl> {
1812+ enum { id = MFX_EXTBUFF_FEI_PAK_CTRL };
1813+};
1814+template <>
1815+struct mfx_ext_buffer_id<mfxExtFeiRepackStat> {
1816+ enum { id = MFX_EXTBUFF_FEI_REPACK_STAT };
1817+};
1818+template <>
1819+struct mfx_ext_buffer_id<mfxExtFeiSPS> {
1820+ enum { id = MFX_EXTBUFF_FEI_SPS };
1821+};
1822+template <>
1823+struct mfx_ext_buffer_id<mfxExtFeiPPS> {
1824+ enum { id = MFX_EXTBUFF_FEI_PPS };
1825+};
1826+#endif
1827+constexpr uint16_t max_num_ext_buffers =
1828+ 63 * 2; // '*2' is for max estimation if all extBuffer were 'paired'
1829+
1830+//helper function to initialize mfx ext buffer structure
1831+template <class T>
1832+void init_ext_buffer(T& ext_buffer) {
1833+ memset(&ext_buffer, 0, sizeof(ext_buffer));
1834+ reinterpret_cast<mfxExtBuffer*>(&ext_buffer)->BufferId = mfx_ext_buffer_id<T>::id;
1835+ reinterpret_cast<mfxExtBuffer*>(&ext_buffer)->BufferSz = sizeof(ext_buffer);
1836+}
1837+
1838+template <typename T>
1839+struct IsPairedMfxExtBuffer : std::false_type {};
1840+template <>
1841+struct IsPairedMfxExtBuffer<mfxExtAVCRefListCtrl> : std::true_type {};
1842+template <>
1843+struct IsPairedMfxExtBuffer<mfxExtAVCRoundingOffset> : std::true_type {};
1844+template <>
1845+struct IsPairedMfxExtBuffer<mfxExtPredWeightTable> : std::true_type {};
1846+#if (MFX_VERSION < 2000)
1847+template <>
1848+struct IsPairedMfxExtBuffer<mfxExtFeiSliceHeader> : std::true_type {};
1849+template <>
1850+struct IsPairedMfxExtBuffer<mfxExtFeiEncFrameCtrl> : std::true_type {};
1851+template <>
1852+struct IsPairedMfxExtBuffer<mfxExtFeiEncMVPredictors> : std::true_type {};
1853+template <>
1854+struct IsPairedMfxExtBuffer<mfxExtFeiRepackCtrl> : std::true_type {};
1855+template <>
1856+struct IsPairedMfxExtBuffer<mfxExtFeiEncMBCtrl> : std::true_type {};
1857+template <>
1858+struct IsPairedMfxExtBuffer<mfxExtFeiEncQP> : std::true_type {};
1859+template <>
1860+struct IsPairedMfxExtBuffer<mfxExtFeiEncMBStat> : std::true_type {};
1861+template <>
1862+struct IsPairedMfxExtBuffer<mfxExtFeiEncMV> : std::true_type {};
1863+template <>
1864+struct IsPairedMfxExtBuffer<mfxExtFeiPakMBCtrl> : std::true_type {};
1865+template <>
1866+struct IsPairedMfxExtBuffer<mfxExtFeiRepackStat> : std::true_type {};
1867+#endif
1868+
1869+template <typename R>
1870+struct ExtParamAccessor {
1871+private:
1872+ using mfxExtBufferDoublePtr = mfxExtBuffer**;
1873+
1874+public:
1875+ mfxU16& NumExtParam;
1876+ mfxExtBufferDoublePtr& ExtParam;
1877+ ExtParamAccessor(const R& r)
1878+ : NumExtParam(const_cast<mfxU16&>(r.NumExtParam)),
1879+ ExtParam(const_cast<mfxExtBufferDoublePtr&>(r.ExtParam)) {}
1880+};
1881+
1882+template <>
1883+struct ExtParamAccessor<mfxFrameSurface1> {
1884+private:
1885+ using mfxExtBufferDoublePtr = mfxExtBuffer**;
1886+
1887+public:
1888+ mfxU16& NumExtParam;
1889+ mfxExtBufferDoublePtr& ExtParam;
1890+ ExtParamAccessor(const mfxFrameSurface1& r)
1891+ : NumExtParam(const_cast<mfxU16&>(r.Data.NumExtParam)),
1892+ ExtParam(const_cast<mfxExtBufferDoublePtr&>(r.Data.ExtParam)) {}
1893+};
1894+
1895+/** ExtBufHolder is an utility class which
1896+ * provide interface for mfxExtBuffer objects management in any mfx structure (e.g. mfxVideoParam)
1897+ */
1898+template <typename T>
1899+class ExtBufHolder : public T {
1900+public:
1901+ ExtBufHolder() : T(), m_ext_buf() {
1902+ m_ext_buf.reserve(max_num_ext_buffers);
1903+ }
1904+
1905+ ~ExtBufHolder() // only buffers allocated by wrapper can be released
1906+ {
1907+ for (auto it = m_ext_buf.begin(); it != m_ext_buf.end(); it++) {
1908+ delete[](mfxU8*)(*it);
1909+ }
1910+ }
1911+
1912+ ExtBufHolder(const ExtBufHolder& ref) {
1913+ m_ext_buf.reserve(max_num_ext_buffers);
1914+ *this = ref; // call to operator=
1915+ }
1916+
1917+ ExtBufHolder& operator=(const ExtBufHolder& ref) {
1918+ const T* src_base = &ref;
1919+ return operator =(*src_base);
1920+ }
1921+
1922+ ExtBufHolder(const T& ref) {
1923+ *this = ref; // call to operator=
1924+ }
1925+
1926+ ExtBufHolder& operator=(const T& ref) {
1927+ // copy content of main structure type T
1928+ T* dst_base = this;
1929+ const T* src_base = &ref;
1930+ *dst_base = *src_base;
1931+
1932+ //remove all existing extension buffers
1933+ ClearBuffers();
1934+
1935+ const auto ref_ = ExtParamAccessor<T>(ref);
1936+
1937+ //reproduce list of extension buffers and copy its content
1938+ for (size_t i = 0; i < ref_.NumExtParam; ++i) {
1939+ const auto src_buf = ref_.ExtParam[i];
1940+ if (!src_buf)
1941+ throw mfxError(MFX_ERR_NULL_PTR, "Null pointer attached to source ExtParam");
1942+ if (!IsCopyAllowed(src_buf->BufferId)) {
1943+ auto msg =
1944+ "Deep copy of '" + Fourcc2Str(src_buf->BufferId) + "' extBuffer is not allowed";
1945+ throw mfxError(MFX_ERR_UNDEFINED_BEHAVIOR, msg);
1946+ }
1947+
1948+ // 'false' below is because here we just copy extBuffer's one by one
1949+ auto dst_buf = AddExtBuffer(src_buf->BufferId, src_buf->BufferSz, false);
1950+ // copy buffer content w/o restoring its type
1951+ MSDK_MEMCPY((void*)dst_buf, (void*)src_buf, src_buf->BufferSz);
1952+ }
1953+
1954+ return *this;
1955+ }
1956+
1957+ ExtBufHolder(ExtBufHolder&&) = default;
1958+ ExtBufHolder& operator=(ExtBufHolder&&) = default;
1959+
1960+ // Always returns a valid pointer or throws an exception
1961+ template <typename TB>
1962+ TB* AddExtBuffer() {
1963+ mfxExtBuffer* b =
1964+ AddExtBuffer(mfx_ext_buffer_id<TB>::id, sizeof(TB), IsPairedMfxExtBuffer<TB>::value);
1965+ return (TB*)b;
1966+ }
1967+
1968+ template <typename TB>
1969+ void RemoveExtBuffer() {
1970+ auto it = std::find_if(m_ext_buf.begin(),
1971+ m_ext_buf.end(),
1972+ CmpExtBufById(mfx_ext_buffer_id<TB>::id));
1973+ if (it != m_ext_buf.end()) {
1974+ delete[](mfxU8*)(*it);
1975+ it = m_ext_buf.erase(it);
1976+
1977+ if (IsPairedMfxExtBuffer<TB>::value) {
1978+ if (it == m_ext_buf.end() || (*it)->BufferId != mfx_ext_buffer_id<TB>::id)
1979+ throw mfxError(MFX_ERR_NULL_PTR,
1980+ "RemoveExtBuffer: ExtBuffer's parity has been broken");
1981+
1982+ delete[](mfxU8*)(*it);
1983+ m_ext_buf.erase(it);
1984+ }
1985+
1986+ RefreshBuffers();
1987+ }
1988+ }
1989+
1990+ template <typename TB>
1991+ TB* GetExtBuffer(uint32_t fieldId = 0) const {
1992+ return (TB*)FindExtBuffer(mfx_ext_buffer_id<TB>::id, fieldId);
1993+ }
1994+
1995+ template <typename TB>
1996+ operator TB*() {
1997+ return (TB*)FindExtBuffer(mfx_ext_buffer_id<TB>::id, 0);
1998+ }
1999+
2000+ template <typename TB>
2001+ operator TB*() const {
2002+ return (TB*)FindExtBuffer(mfx_ext_buffer_id<TB>::id, 0);
2003+ }
2004+
2005+private:
2006+ mfxExtBuffer* AddExtBuffer(mfxU32 id, mfxU32 size, bool isPairedExtBuffer) {
2007+ if (!size || !id)
2008+ throw mfxError(MFX_ERR_NULL_PTR, "AddExtBuffer: wrong size or id!");
2009+
2010+ auto it = std::find_if(m_ext_buf.begin(), m_ext_buf.end(), CmpExtBufById(id));
2011+ if (it == m_ext_buf.end()) {
2012+ auto buf = (mfxExtBuffer*)new mfxU8[size];
2013+ memset(buf, 0, size);
2014+ m_ext_buf.push_back(buf);
2015+
2016+ buf->BufferId = id;
2017+ buf->BufferSz = size;
2018+
2019+ if (isPairedExtBuffer) {
2020+ // Allocate the other mfxExtBuffer _right_after_ the first one ...
2021+ buf = (mfxExtBuffer*)new mfxU8[size];
2022+ memset(buf, 0, size);
2023+ m_ext_buf.push_back(buf);
2024+
2025+ buf->BufferId = id;
2026+ buf->BufferSz = size;
2027+
2028+ RefreshBuffers();
2029+ return m_ext_buf[m_ext_buf.size() - 2]; // ... and return a pointer to the first one
2030+ }
2031+
2032+ RefreshBuffers();
2033+ return m_ext_buf.back();
2034+ }
2035+
2036+ return *it;
2037+ }
2038+
2039+ mfxExtBuffer* FindExtBuffer(mfxU32 id, uint32_t fieldId) const {
2040+ auto it = std::find_if(m_ext_buf.begin(), m_ext_buf.end(), CmpExtBufById(id));
2041+ if (fieldId && it != m_ext_buf.end()) {
2042+ ++it;
2043+ return it != m_ext_buf.end() ? *it : nullptr;
2044+ }
2045+ return it != m_ext_buf.end() ? *it : nullptr;
2046+ }
2047+
2048+ void RefreshBuffers() {
2049+ auto this_ = ExtParamAccessor<T>(*this);
2050+ this_.NumExtParam = static_cast<mfxU16>(m_ext_buf.size());
2051+ this_.ExtParam = this_.NumExtParam ? m_ext_buf.data() : nullptr;
2052+ }
2053+
2054+ void ClearBuffers() {
2055+ if (m_ext_buf.size()) {
2056+ for (auto it = m_ext_buf.begin(); it != m_ext_buf.end(); it++) {
2057+ delete[](mfxU8*)(*it);
2058+ }
2059+ m_ext_buf.clear();
2060+ }
2061+ RefreshBuffers();
2062+ }
2063+
2064+ bool IsCopyAllowed(mfxU32 id) {
2065+ static const mfxU32 allowed[] = {
2066+ MFX_EXTBUFF_CODING_OPTION,
2067+ MFX_EXTBUFF_CODING_OPTION2,
2068+ MFX_EXTBUFF_CODING_OPTION3,
2069+#if (MFX_VERSION < 2000)
2070+ MFX_EXTBUFF_FEI_PARAM,
2071+ MFX_EXTBUFF_BRC,
2072+#endif
2073+ MFX_EXTBUFF_HEVC_PARAM,
2074+ MFX_EXTBUFF_VP9_PARAM,
2075+#if (MFX_VERSION < 2000)
2076+ MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION,
2077+ MFX_EXTBUFF_FEI_PPS,
2078+ MFX_EXTBUFF_FEI_SPS,
2079+ MFX_EXTBUFF_LOOKAHEAD_CTRL,
2080+ MFX_EXTBUFF_LOOKAHEAD_STAT
2081+#endif
2082+ };
2083+
2084+ auto it =
2085+ std::find_if(std::begin(allowed), std::end(allowed), [&id](const mfxU32 allowed_id) {
2086+ return allowed_id == id;
2087+ });
2088+ return it != std::end(allowed);
2089+ }
2090+
2091+ struct CmpExtBufById {
2092+ mfxU32 id;
2093+
2094+ CmpExtBufById(mfxU32 _id) : id(_id){};
2095+
2096+ bool operator()(mfxExtBuffer* b) {
2097+ return (b && b->BufferId == id);
2098+ };
2099+ };
2100+
2101+ static std::string Fourcc2Str(mfxU32 fourcc) {
2102+ std::string s;
2103+ for (size_t i = 0; i < 4; i++) {
2104+ s.push_back(*(i + (char*)&fourcc));
2105+ }
2106+ return s;
2107+ }
2108+
2109+ std::vector<mfxExtBuffer*> m_ext_buf;
2110+};
2111+
2112+using MfxVideoParamsWrapper = ExtBufHolder<mfxVideoParam>;
2113+using mfxEncodeCtrlWrap = ExtBufHolder<mfxEncodeCtrl>;
2114+using mfxInitParamlWrap = ExtBufHolder<mfxInitParam>;
2115+using mfxFrameSurfaceWrap = ExtBufHolder<mfxFrameSurface1>;
2116+
2117+class mfxBitstreamWrapper : public ExtBufHolder<mfxBitstream> {
2118+ typedef ExtBufHolder<mfxBitstream> base;
2119+
2120+public:
2121+ mfxBitstreamWrapper() : base(), m_data() {}
2122+
2123+ mfxBitstreamWrapper(mfxU32 n_bytes) : base() {
2124+ Extend(n_bytes);
2125+ }
2126+
2127+ mfxBitstreamWrapper(const mfxBitstreamWrapper& bs_wrapper)
2128+ : base(bs_wrapper),
2129+ m_data(bs_wrapper.m_data) {
2130+ Data = m_data.data();
2131+ }
2132+
2133+ mfxBitstreamWrapper& operator=(mfxBitstreamWrapper const& bs_wrapper) {
2134+ mfxBitstreamWrapper tmp(bs_wrapper);
2135+
2136+ *this = std::move(tmp);
2137+
2138+ return *this;
2139+ }
2140+
2141+ mfxBitstreamWrapper(mfxBitstreamWrapper&& bs_wrapper) = default;
2142+ mfxBitstreamWrapper& operator=(mfxBitstreamWrapper&& bs_wrapper) = default;
2143+ ~mfxBitstreamWrapper() = default;
2144+
2145+ void Extend(mfxU32 n_bytes) {
2146+ if (MaxLength >= n_bytes)
2147+ return;
2148+
2149+ m_data.resize(n_bytes);
2150+
2151+ Data = m_data.data();
2152+ MaxLength = n_bytes;
2153+ }
2154+
2155+private:
2156+ std::vector<mfxU8> m_data;
2157+};
2158+
2159+class CSmplYUVReader {
2160+public:
2161+ typedef std::list<msdk_string>::iterator ls_iterator;
2162+ CSmplYUVReader();
2163+ virtual ~CSmplYUVReader();
2164+
2165+ virtual void Close();
2166+ virtual mfxStatus Init(std::list<msdk_string> inputs,
2167+ mfxU32 ColorFormat,
2168+ bool shouldShiftP010 = false);
2169+ virtual mfxStatus SkipNframesFromBeginning(mfxU16 w, mfxU16 h, mfxU32 viewId, mfxU32 nframes);
2170+ virtual mfxStatus LoadNextFrame(mfxFrameSurface1* pSurface);
2171+ virtual void Reset();
2172+ mfxU32 m_ColorFormat; // color format of input YUV data, YUV420 or NV12
2173+
2174+protected:
2175+ std::vector<FILE*> m_files;
2176+
2177+ bool shouldShift10BitsHigh;
2178+ bool m_bInited;
2179+};
2180+
2181+class CSmplBitstreamWriter {
2182+public:
2183+ CSmplBitstreamWriter();
2184+ virtual ~CSmplBitstreamWriter();
2185+
2186+ virtual mfxStatus Init(const msdk_char* strFileName);
2187+ virtual mfxStatus WriteNextFrame(mfxBitstream* pMfxBitstream, bool isPrint = true);
2188+ virtual mfxStatus Reset();
2189+ virtual void Close();
2190+ mfxU32 m_nProcessedFramesNum;
2191+
2192+protected:
2193+ FILE* m_fSink;
2194+ bool m_bInited;
2195+ msdk_string m_sFile;
2196+};
2197+
2198+class CSmplYUVWriter {
2199+public:
2200+ CSmplYUVWriter();
2201+ virtual ~CSmplYUVWriter();
2202+
2203+ virtual void Close();
2204+ virtual mfxStatus Init(const msdk_char* strFileName, const mfxU32 numViews);
2205+ virtual mfxStatus Reset();
2206+ virtual mfxStatus WriteNextFrame(mfxFrameSurface1* pSurface);
2207+ virtual mfxStatus WriteNextFrameI420(mfxFrameSurface1* pSurface);
2208+
2209+ void SetMultiView() {
2210+ m_bIsMultiView = true;
2211+ }
2212+
2213+protected:
2214+ FILE *m_fDest, **m_fDestMVC;
2215+ bool m_bInited, m_bIsMultiView;
2216+ mfxU32 m_numCreatedFiles;
2217+ msdk_string m_sFile;
2218+ mfxU32 m_nViews;
2219+};
2220+
2221+class CSmplBitstreamReader {
2222+public:
2223+ CSmplBitstreamReader();
2224+ virtual ~CSmplBitstreamReader();
2225+
2226+ //resets position to file begin
2227+ virtual void Reset();
2228+ virtual void Close();
2229+ virtual mfxStatus Init(const msdk_char* strFileName);
2230+ virtual mfxStatus ReadNextFrame(mfxBitstream* pBS);
2231+
2232+protected:
2233+ FILE* m_fSource;
2234+ bool m_bInited;
2235+};
2236+
2237+class CH264FrameReader : public CSmplBitstreamReader {
2238+public:
2239+ CH264FrameReader();
2240+ virtual ~CH264FrameReader();
2241+
2242+ /** Free resources.*/
2243+ virtual void Close();
2244+ virtual mfxStatus Init(const msdk_char* strFileName);
2245+ virtual mfxStatus ReadNextFrame(mfxBitstream* pBS);
2246+
2247+private:
2248+ mfxBitstream* m_processedBS;
2249+ // input bit stream
2250+ mfxBitstreamWrapper m_originalBS;
2251+
2252+ mfxStatus PrepareNextFrame(mfxBitstream* in, mfxBitstream** out);
2253+
2254+ // is stream ended
2255+ bool m_isEndOfStream;
2256+
2257+ std::unique_ptr<AbstractSplitter> m_pNALSplitter;
2258+ FrameSplitterInfo* m_frame;
2259+ mfxU8* m_plainBuffer;
2260+ mfxU32 m_plainBufferSize;
2261+ mfxBitstream m_outBS;
2262+};
2263+
2264+//provides output bistream with at least 1 frame, reports about error
2265+class CJPEGFrameReader : public CSmplBitstreamReader {
2266+ enum JPEGMarker { SOI = 0xD8FF, EOI = 0xD9FF };
2267+
2268+public:
2269+ virtual mfxStatus ReadNextFrame(mfxBitstream* pBS);
2270+
2271+protected:
2272+ mfxU32 FindMarker(mfxBitstream* pBS, mfxU32 startOffset, JPEGMarker marker);
2273+};
2274+
2275+//appends output bistream with exactly 1 frame, reports about error
2276+class CIVFFrameReader : public CSmplBitstreamReader {
2277+public:
2278+ CIVFFrameReader();
2279+ virtual void Reset();
2280+ virtual mfxStatus Init(const msdk_char* strFileName);
2281+ virtual mfxStatus ReadNextFrame(mfxBitstream* pBS);
2282+
2283+protected:
2284+ /*bytes 0-3 signature: 'DKIF'
2285+ bytes 4-5 version (should be 0)
2286+ bytes 6-7 length of header in bytes
2287+ bytes 8-11 codec FourCC (e.g., 'VP80')
2288+ bytes 12-13 width in pixels
2289+ bytes 14-15 height in pixels
2290+ bytes 16-19 frame rate
2291+ bytes 20-23 time scale
2292+ bytes 24-27 number of frames in file
2293+ bytes 28-31 unused*/
2294+
2295+ struct DKIFHrd {
2296+ mfxU32 dkif;
2297+ mfxU16 version;
2298+ mfxU16 header_len;
2299+ mfxU32 codec_FourCC;
2300+ mfxU16 width;
2301+ mfxU16 height;
2302+ mfxU32 frame_rate;
2303+ mfxU32 time_scale;
2304+ mfxU32 num_frames;
2305+ mfxU32 unused;
2306+ } m_hdr;
2307+ mfxStatus ReadHeader();
2308+};
2309+
2310+// writes bitstream to duplicate-file & supports joining
2311+// (for ViewOutput encoder mode)
2312+class CSmplBitstreamDuplicateWriter : public CSmplBitstreamWriter {
2313+public:
2314+ CSmplBitstreamDuplicateWriter();
2315+
2316+ virtual mfxStatus InitDuplicate(const msdk_char* strFileName);
2317+ virtual mfxStatus JoinDuplicate(CSmplBitstreamDuplicateWriter* pJoinee);
2318+ virtual mfxStatus WriteNextFrame(mfxBitstream* pMfxBitstream, bool isPrint = true);
2319+ virtual void Close();
2320+
2321+protected:
2322+ FILE* m_fSinkDuplicate;
2323+ bool m_bJoined;
2324+};
2325+
2326+#if (MFX_VERSION >= 2000)
2327+class CIVFFrameWriter : public CSmplBitstreamWriter {
2328+public:
2329+ CIVFFrameWriter();
2330+
2331+ virtual mfxStatus Reset();
2332+ virtual mfxStatus Init(const msdk_char* strFileName,
2333+ const mfxU16 w,
2334+ const mfxU16 h,
2335+ const mfxU32 fr_nom,
2336+ const mfxU32 fr_denom);
2337+ virtual mfxStatus WriteNextFrame(mfxBitstream* pMfxBitstream, bool isPrint = true);
2338+ virtual void Close();
2339+
2340+protected:
2341+ /* 32 bytes for stream header
2342+ bytes 0-3 signature: 'DKIF'
2343+ bytes 4-5 version (should be 0)
2344+ bytes 6-7 length of header in bytes
2345+ bytes 8-11 codec FourCC (e.g., 'VP80')
2346+ bytes 12-13 width in pixels
2347+ bytes 14-15 height in pixels
2348+ bytes 16-19 frame rate
2349+ bytes 20-23 time scale
2350+ bytes 24-27 number of frames in file
2351+ bytes 28-31 unused
2352+ */
2353+ struct streamHeader {
2354+ mfxU32 dkif;
2355+ mfxU16 version;
2356+ mfxU16 header_len;
2357+ mfxU32 codec_FourCC;
2358+ mfxU16 width;
2359+ mfxU16 height;
2360+ mfxU32 frame_rate;
2361+ mfxU32 time_scale;
2362+ mfxU32 num_frames;
2363+ mfxU32 unused;
2364+ } m_streamHeader;
2365+
2366+ /* 12 bytes for frame header
2367+ bytes 0-3 frame size
2368+ bytes 4-11 pts
2369+ */
2370+ struct frameHeader {
2371+ mfxU32 frame_size;
2372+ mfxU32 pts_high;
2373+ mfxU32 pts_low;
2374+ } m_frameHeader;
2375+
2376+ mfxU64 m_frameNum;
2377+ mfxStatus WriteStreamHeader();
2378+ mfxStatus WriteFrameHeader();
2379+ void UpdateNumberOfFrames();
2380+};
2381+#endif
2382+
2383+//timeinterval calculation helper
2384+
2385+template <int tag = 0>
2386+class CTimeInterval : private no_copy {
2387+ static double g_Freq;
2388+ double& m_start;
2389+ double m_own; //reference to this if external counter not required
2390+ //since QPC functions are quite slow it makes sense to optionally enable them
2391+ bool m_bEnable;
2392+ msdk_tick m_StartTick;
2393+
2394+public:
2395+ CTimeInterval(double& dRef, bool bEnable = true)
2396+ : m_start(dRef),
2397+ m_bEnable(bEnable),
2398+ m_StartTick(0) {
2399+ if (!m_bEnable)
2400+ return;
2401+ Initialize();
2402+ }
2403+ CTimeInterval(bool bEnable = true)
2404+ : m_start(m_own),
2405+ m_own(),
2406+ m_bEnable(bEnable),
2407+ m_StartTick(0) {
2408+ if (!m_bEnable)
2409+ return;
2410+ Initialize();
2411+ }
2412+
2413+ //updates external value with current time
2414+ double Commit() {
2415+ if (!m_bEnable)
2416+ return 0.0;
2417+
2418+ if (0.0 != g_Freq) {
2419+ m_start = MSDK_GET_TIME(msdk_time_get_tick(), m_StartTick, g_Freq);
2420+ }
2421+ return m_start;
2422+ }
2423+ //last comitted value
2424+ double Last() {
2425+ return m_start;
2426+ }
2427+ ~CTimeInterval() {
2428+ Commit();
2429+ }
2430+
2431+private:
2432+ void Initialize() {
2433+ if (0.0 == g_Freq) {
2434+ g_Freq = (double)msdk_time_get_frequency();
2435+ }
2436+ m_StartTick = msdk_time_get_tick();
2437+ }
2438+};
2439+
2440+template <int tag>
2441+double CTimeInterval<tag>::g_Freq = 0.0f;
2442+
2443+/** Helper class to measure execution time of some code. Use this class
2444+ * if you need manual measurements.
2445+ *
2446+ * Usage example:
2447+ * {
2448+ * CTimer timer;
2449+ * msdk_tick summary_tick;
2450+ *
2451+ * timer.Start()
2452+ * function_to_measure();
2453+ * summary_tick = timer.GetDelta();
2454+ * printf("Elapsed time 1: %f\n", timer.GetTime());
2455+ * ...
2456+ * if (condition) timer.Start();
2457+ function_to_measure();
2458+ * if (condition) {
2459+ * summary_tick += timer.GetDelta();
2460+ * printf("Elapsed time 2: %f\n", timer.GetTime();
2461+ * }
2462+ * printf("Overall time: %f\n", CTimer::ConvertToSeconds(summary_tick);
2463+ * }
2464+ */
2465+class CTimer {
2466+public:
2467+ CTimer() : start(0) {}
2468+ static msdk_tick GetFrequency() {
2469+ if (!frequency)
2470+ frequency = msdk_time_get_frequency();
2471+ return frequency;
2472+ }
2473+ static mfxF64 ConvertToSeconds(msdk_tick elapsed) {
2474+ return MSDK_GET_TIME(elapsed, 0, GetFrequency());
2475+ }
2476+
2477+ inline void Start() {
2478+ start = msdk_time_get_tick();
2479+ }
2480+ inline msdk_tick GetDelta() {
2481+ return msdk_time_get_tick() - start;
2482+ }
2483+ inline mfxF64 GetTime() {
2484+ return MSDK_GET_TIME(msdk_time_get_tick(), start, GetFrequency());
2485+ }
2486+
2487+protected:
2488+ static msdk_tick frequency;
2489+ msdk_tick start;
2490+
2491+private:
2492+ CTimer(const CTimer&);
2493+ void operator=(const CTimer&);
2494+};
2495+
2496+/** Helper class to measure overall execution time of some code. Use this
2497+ * class if you want to measure execution time of the repeatedly executed
2498+ * code.
2499+ *
2500+ * Usage example 1:
2501+ *
2502+ * msdk_tick summary_tick = 0;
2503+ *
2504+ * void function() {
2505+ *
2506+ * {
2507+ * CAutoTimer timer(&summary_tick);
2508+ * ...
2509+ * }
2510+ * ...
2511+ * int main() {
2512+ * for (;condition;) {
2513+ * function();
2514+ * }
2515+ * printf("Elapsed time: %f\n", CTimer::ConvertToSeconds(summary_tick);
2516+ * return 0;
2517+ * }
2518+ *
2519+ * Usage example 2:
2520+ * {
2521+ * msdk_tick summary_tick = 0;
2522+ *
2523+ * {
2524+ * CAutoTimer timer(&summary_tick);
2525+ *
2526+ * for (;condition;) {
2527+ * ...
2528+ * {
2529+ * function_to_measure();
2530+ * timer.Sync();
2531+ * printf("Progress: %f\n", CTimer::ConvertToSeconds(summary_tick);
2532+ * }
2533+ * ...
2534+ * }
2535+ * }
2536+ * printf("Elapsed time: %f\n", CTimer::ConvertToSeconds(summary_tick);
2537+ * }
2538+ *
2539+ */
2540+class CAutoTimer {
2541+public:
2542+ CAutoTimer(msdk_tick& _elapsed) : elapsed(_elapsed), start(0) {
2543+ elapsed = _elapsed;
2544+ start = msdk_time_get_tick();
2545+ }
2546+ ~CAutoTimer() {
2547+ elapsed += msdk_time_get_tick() - start;
2548+ }
2549+ msdk_tick Sync() {
2550+ msdk_tick cur = msdk_time_get_tick();
2551+ elapsed += cur - start;
2552+ start = cur;
2553+ return elapsed;
2554+ }
2555+
2556+protected:
2557+ msdk_tick& elapsed;
2558+ msdk_tick start;
2559+
2560+private:
2561+ CAutoTimer(const CAutoTimer&);
2562+ void operator=(const CAutoTimer&);
2563+};
2564+
2565+mfxStatus ConvertFrameRate(mfxF64 dFrameRate, mfxU32* pnFrameRateExtN, mfxU32* pnFrameRateExtD);
2566+mfxF64 CalculateFrameRate(mfxU32 nFrameRateExtN, mfxU32 nFrameRateExtD);
2567+
2568+template <class T>
2569+mfxU16 GetFreeSurfaceIndex(T* pSurfacesPool, mfxU16 nPoolSize) {
2570+ constexpr mfxU16 MSDK_INVALID_SURF_IDX = 0xffff;
2571+
2572+ if (pSurfacesPool) {
2573+ for (mfxU16 i = 0; i < nPoolSize; i++) {
2574+ if (0 == pSurfacesPool[i].Data.Locked) {
2575+ return i;
2576+ }
2577+ }
2578+ }
2579+ return MSDK_INVALID_SURF_IDX;
2580+}
2581+
2582+mfxU16 GetFreeSurface(mfxFrameSurface1* pSurfacesPool, mfxU16 nPoolSize);
2583+void FreeSurfacePool(mfxFrameSurface1* pSurfacesPool, mfxU16 nPoolSize);
2584+
2585+mfxU16 CalculateDefaultBitrate(mfxU32 nCodecId,
2586+ mfxU32 nTargetUsage,
2587+ mfxU32 nWidth,
2588+ mfxU32 nHeight,
2589+ mfxF64 dFrameRate);
2590+
2591+//serialization fnc set
2592+std::basic_string<msdk_char> CodecIdToStr(mfxU32 nFourCC);
2593+mfxU16 StrToTargetUsage(msdk_string strInput);
2594+const msdk_char* TargetUsageToStr(mfxU16 tu);
2595+const msdk_char* ColorFormatToStr(mfxU32 format);
2596+const msdk_char* MfxStatusToStr(mfxStatus sts);
2597+
2598+// sets bitstream->PicStruct parsing first APP0 marker in bitstream
2599+mfxStatus MJPEG_AVI_ParsePicStruct(mfxBitstream* bitstream);
2600+
2601+// For MVC encoding/decoding purposes
2602+std::basic_string<msdk_char> FormMVCFileName(const msdk_char* strFileName, const mfxU32 numView);
2603+
2604+//piecewise linear function for bitrate approximation
2605+class PartiallyLinearFNC {
2606+ mfxF64* m_pX;
2607+ mfxF64* m_pY;
2608+ mfxU32 m_nPoints;
2609+ mfxU32 m_nAllocated;
2610+
2611+public:
2612+ PartiallyLinearFNC();
2613+ ~PartiallyLinearFNC();
2614+
2615+ void AddPair(mfxF64 x, mfxF64 y);
2616+ mfxF64 at(mfxF64);
2617+
2618+private:
2619+ DISALLOW_COPY_AND_ASSIGN(PartiallyLinearFNC);
2620+};
2621+
2622+// function for getting a pointer to a specific external buffer from the array
2623+mfxExtBuffer* GetExtBuffer(mfxExtBuffer** ebuffers, mfxU32 nbuffers, mfxU32 BufferId);
2624+
2625+// returns false if buf length is insufficient, otherwise
2626+// skips step bytes in buf with specified length and returns true
2627+template <typename Buf_t, typename Length_t>
2628+bool skip(const Buf_t*& buf, Length_t& length, Length_t step) {
2629+ if (length < step)
2630+ return false;
2631+
2632+ buf += step;
2633+ length -= step;
2634+
2635+ return true;
2636+}
2637+
2638+//do not link MediaSDK dispatched if class not used
2639+struct MSDKAdapter {
2640+ // returns the number of adapter associated with MSDK session, 0 for SW session
2641+ static mfxU32 GetNumber(mfxSession session, mfxIMPL implVia = 0) {
2642+ mfxU32 adapterNum = 0; // default
2643+ mfxIMPL impl = MFX_IMPL_SOFTWARE; // default in case no HW IMPL is found
2644+
2645+ // we don't care for error codes in further code; if something goes wrong we fall back to the default adapter
2646+ if (session) {
2647+ MFXQueryIMPL(session, &impl);
2648+ }
2649+ else {
2650+ // an auxiliary session, internal for this function
2651+ mfxSession auxSession;
2652+ memset(&auxSession, 0, sizeof(auxSession));
2653+
2654+ mfxVersion ver = { { 1, 1 } }; // minimum API version which supports multiple devices
2655+ MFXInit(MFX_IMPL_HARDWARE_ANY | implVia, &ver, &auxSession);
2656+ MFXQueryIMPL(auxSession, &impl);
2657+ MFXClose(auxSession);
2658+ }
2659+
2660+ // extract the base implementation type
2661+ mfxIMPL baseImpl = MFX_IMPL_BASETYPE(impl);
2662+
2663+ const struct {
2664+ // actual implementation
2665+ mfxIMPL impl;
2666+ // adapter's number
2667+ mfxU32 adapterID;
2668+
2669+ } implTypes[] = { { MFX_IMPL_HARDWARE, 0 },
2670+ { MFX_IMPL_SOFTWARE, 0 },
2671+ { MFX_IMPL_HARDWARE2, 1 },
2672+ { MFX_IMPL_HARDWARE3, 2 },
2673+ { MFX_IMPL_HARDWARE4, 3 } };
2674+
2675+ // get corresponding adapter number
2676+ for (mfxU8 i = 0; i < sizeof(implTypes) / sizeof(*implTypes); i++) {
2677+ if (implTypes[i].impl == baseImpl) {
2678+ adapterNum = implTypes[i].adapterID;
2679+ break;
2680+ }
2681+ }
2682+
2683+ return adapterNum;
2684+ }
2685+};
2686+
2687+struct APIChangeFeatures {
2688+ bool JpegDecode;
2689+ bool JpegEncode;
2690+ bool MVCDecode;
2691+ bool MVCEncode;
2692+ bool IntraRefresh;
2693+ bool LowLatency;
2694+ bool ViewOutput;
2695+ bool LookAheadBRC;
2696+ bool AudioDecode;
2697+ bool SupportCodecPluginAPI;
2698+};
2699+
2700+mfxVersion getMinimalRequiredVersion(const APIChangeFeatures& features);
2701+
2702+enum msdkAPIFeature {
2703+ MSDK_FEATURE_NONE,
2704+ MSDK_FEATURE_MVC,
2705+ MSDK_FEATURE_JPEG_DECODE,
2706+ MSDK_FEATURE_LOW_LATENCY,
2707+ MSDK_FEATURE_MVC_VIEWOUTPUT,
2708+ MSDK_FEATURE_JPEG_ENCODE,
2709+ MSDK_FEATURE_LOOK_AHEAD,
2710+ MSDK_FEATURE_PLUGIN_API
2711+};
2712+
2713+/* Returns true if feature is supported in the given API version */
2714+bool CheckVersion(mfxVersion* version, msdkAPIFeature feature);
2715+
2716+void ConfigureAspectRatioConversion(mfxInfoVPP* pVppInfo);
2717+
2718+void SEICalcSizeType(std::vector<mfxU8>& data, mfxU16 type, mfxU32 size);
2719+
2720+mfxU8 Char2Hex(msdk_char ch);
2721+
2722+enum MsdkTraceLevel {
2723+ MSDK_TRACE_LEVEL_SILENT = -1,
2724+ MSDK_TRACE_LEVEL_CRITICAL = 0,
2725+ MSDK_TRACE_LEVEL_ERROR = 1,
2726+ MSDK_TRACE_LEVEL_WARNING = 2,
2727+ MSDK_TRACE_LEVEL_INFO = 3,
2728+ MSDK_TRACE_LEVEL_DEBUG = 4,
2729+};
2730+
2731+msdk_string NoFullPath(const msdk_string&);
2732+int msdk_trace_get_level();
2733+void msdk_trace_set_level(int);
2734+bool msdk_trace_is_printable(int);
2735+
2736+msdk_ostream& operator<<(msdk_ostream& os, MsdkTraceLevel tt);
2737+
2738+template <typename T>
2739+mfxStatus msdk_opt_read(const msdk_char* string, T& value);
2740+
2741+template <size_t S>
2742+mfxStatus msdk_opt_read(const msdk_char* string, msdk_char (&value)[S]) {
2743+ if (!S) {
2744+ return MFX_ERR_UNKNOWN;
2745+ }
2746+ value[0] = 0;
2747+#if defined(_WIN32) || defined(_WIN64)
2748+ value[S - 1] = 0;
2749+ return (0 == _tcsncpy_s(value, string, S - 1)) ? MFX_ERR_NONE : MFX_ERR_UNKNOWN;
2750+#else
2751+ if (strlen(string) < S) {
2752+ strncpy(value, string, S - 1);
2753+ value[S - 1] = 0;
2754+ return MFX_ERR_NONE;
2755+ }
2756+ return MFX_ERR_UNKNOWN;
2757+#endif
2758+}
2759+
2760+template <typename T>
2761+inline mfxStatus msdk_opt_read(const msdk_string& string, T& value) {
2762+ return msdk_opt_read(string.c_str(), value);
2763+}
2764+
2765+mfxStatus StrFormatToCodecFormatFourCC(msdk_char* strInput, mfxU32& codecFormat);
2766+msdk_string StatusToString(mfxStatus sts);
2767+mfxI32 getMonitorType(msdk_char* str);
2768+
2769+void WaitForDeviceToBecomeFree(MFXVideoSession& session,
2770+ mfxSyncPoint& syncPoint,
2771+ mfxStatus& currentStatus);
2772+
2773+mfxU16 FourCCToChroma(mfxU32 fourCC);
2774+
2775+#endif //__SAMPLE_UTILS_H__
2776diff --git a/tools/legacy/sample_common/include/vpl_implementation_loader.h b/tools/legacy/sample_common/include/vpl_implementation_loader.h
2777new file mode 100644
2778index 0000000..d5f8fe5
2779--- /dev/null
2780+++ b/tools/legacy/sample_common/include/vpl_implementation_loader.h
2781@@ -0,0 +1,73 @@
2782+/******************************************************************************\
2783+Copyright (c) 2021, Intel Corporation
2784+All rights reserved.
2785+
2786+Redistribution and use in source and binary forms, with or without modification,
2787+are permitted provided that the following conditions are met:
2788+
2789+1. Redistributions of source code must retain the above copyright notice, this
2790+list of conditions and the following disclaimer.
2791+
2792+2. Redistributions in binary form must reproduce the above copyright notice,
2793+this list of conditions and the following disclaimer in the documentation and/or
2794+other materials provided with the distribution.
2795+
2796+3. Neither the name of the copyright holder nor the names of its contributors
2797+may be used to endorse or promote products derived from this software without
2798+specific prior written permission.
2799+
2800+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2801+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2802+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2803+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
2804+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2805+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2806+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
2807+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2808+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2809+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2810+
2811+This sample was distributed or derived from the Intel's Media Samples package.
2812+The original version of this sample may be obtained from
2813+https://software.intel.com/en-us/intel-media-server-studio or
2814+https://software.intel.com/en-us/media-client-solutions-support.
2815+\**********************************************************************************/
2816+
2817+#ifndef __VPL_IMPLEMENTATION_LOADER_H__
2818+#define __VPL_IMPLEMENTATION_LOADER_H__
2819+
2820+#include <vector>
2821+#include "vpl/mfxdispatcher.h"
2822+#include "vpl/mfxvideo++.h"
2823+
2824+class VPLImplementationLoader {
2825+ mfxLoader m_Loader;
2826+ std::vector<mfxConfig> m_Configs;
2827+ mfxImplDescription *m_idesc;
2828+ mfxU32 m_ImplIndex;
2829+
2830+public:
2831+ VPLImplementationLoader();
2832+ ~VPLImplementationLoader();
2833+
2834+ mfxStatus CreateConfig(mfxU16 data, const char *propertyName);
2835+ mfxStatus CreateConfig(mfxU32 data, const char *propertyName);
2836+ mfxStatus ConfigureImplementation(mfxIMPL impl);
2837+ mfxStatus ConfigureAccelerationMode(mfxAccelerationMode accelerationMode, mfxIMPL impl);
2838+ mfxStatus ConfigureVersion(mfxVersion const &version);
2839+ mfxStatus EnumImplementations();
2840+ mfxStatus EnumImplementations(mfxU16 deviceID, mfxU32 adapterNum);
2841+ mfxStatus ConfigureAndEnumImplementations(mfxIMPL impl,
2842+ mfxAccelerationMode accelerationMode,
2843+ mfxVersion const &version);
2844+ mfxLoader GetLoader();
2845+ mfxU32 GetImplIndex() const;
2846+ mfxStatus GetVersion(mfxVersion *version);
2847+};
2848+
2849+class MainVideoSession : public MFXVideoSession {
2850+public:
2851+ mfxStatus CreateSession(VPLImplementationLoader *Loader);
2852+};
2853+
2854+#endif //__VPL_IMPLEMENTATION_LOADER_H__
2855diff --git a/tools/legacy/sample_common/src/plugin_utils.cpp b/tools/legacy/sample_common/src/plugin_utils.cpp
2856index 1db329e..03e3e73 100644
2857--- a/tools/legacy/sample_common/src/plugin_utils.cpp
2858+++ b/tools/legacy/sample_common/src/plugin_utils.cpp
2859@@ -8,7 +8,6 @@
2860
2861 #include <map>
2862 #include <sstream>
2863-#include "mfxvp8.h"
2864 #include "plugin_utils.h"
2865
2866 bool AreGuidsEqual(const mfxPluginUID& guid1, const mfxPluginUID& guid2) {
2867@@ -31,9 +30,6 @@ mfxStatus ConvertStringToGuid(const msdk_string& strGuid, mfxPluginUID& mfxGuid)
2868 uid[MSDK_STRING("hevce_gacc")] = MFX_PLUGINID_HEVCE_GACC;
2869 uid[MSDK_STRING("hevce_hw")] = MFX_PLUGINID_HEVCE_HW;
2870
2871- uid[MSDK_STRING("vp8d_hw")] = MFX_PLUGINID_VP8D_HW;
2872- uid[MSDK_STRING("vp8e_hw")] = MFX_PLUGINID_VP8E_HW;
2873-
2874 uid[MSDK_STRING("vp9d_hw")] = MFX_PLUGINID_VP9D_HW;
2875 uid[MSDK_STRING("vp9e_hw")] = MFX_PLUGINID_VP9E_HW;
2876
2877@@ -96,10 +92,6 @@ const mfxPluginUID& msdkGetPluginUID(mfxIMPL impl, msdkComponentType type, mfxU3
2878 else {
2879 switch (type) {
2880 case MSDK_VENCODE:
2881- switch (uCodecid) {
2882- case MFX_CODEC_VP8:
2883- return MFX_PLUGINID_VP8E_HW;
2884- }
2885 break;
2886 #if MFX_VERSION >= 1027
2887 case (MSDK_VENCODE | MSDK_FEI):
2888diff --git a/tools/legacy/sample_common/src/vpl_implementation_loader.cpp b/tools/legacy/sample_common/src/vpl_implementation_loader.cpp
2889new file mode 100644
2890index 0000000..2edb0d7
2891--- /dev/null
2892+++ b/tools/legacy/sample_common/src/vpl_implementation_loader.cpp
2893@@ -0,0 +1,220 @@
2894+/******************************************************************************\
2895+Copyright (c) 2021, Intel Corporation
2896+All rights reserved.
2897+
2898+Redistribution and use in source and binary forms, with or without modification,
2899+are permitted provided that the following conditions are met:
2900+
2901+1. Redistributions of source code must retain the above copyright notice, this
2902+list of conditions and the following disclaimer.
2903+
2904+2. Redistributions in binary form must reproduce the above copyright notice,
2905+this list of conditions and the following disclaimer in the documentation and/or
2906+other materials provided with the distribution.
2907+
2908+3. Neither the name of the copyright holder nor the names of its contributors
2909+may be used to endorse or promote products derived from this software without
2910+specific prior written permission.
2911+
2912+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2913+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2914+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2915+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
2916+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2917+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2918+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
2919+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2920+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2921+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2922+
2923+This sample was distributed or derived from the Intel's Media Samples package.
2924+The original version of this sample may be obtained from
2925+https://software.intel.com/en-us/intel-media-server-studio or
2926+https://software.intel.com/en-us/media-client-solutions-support.
2927+\**********************************************************************************/
2928+
2929+#include "vpl_implementation_loader.h"
2930+#include "sample_defs.h"
2931+#include "vpl/mfxdispatcher.h"
2932+
2933+VPLImplementationLoader::VPLImplementationLoader() {
2934+ m_Loader = MFXLoad();
2935+ m_idesc = nullptr;
2936+ m_ImplIndex = 0;
2937+}
2938+
2939+VPLImplementationLoader::~VPLImplementationLoader() {
2940+ if (m_idesc) {
2941+ MFXDispReleaseImplDescription(m_Loader, m_idesc);
2942+ }
2943+ MFXUnload(m_Loader);
2944+}
2945+
2946+mfxStatus VPLImplementationLoader::CreateConfig(mfxU16 data, const char *propertyName) {
2947+ mfxConfig cfg = MFXCreateConfig(m_Loader);
2948+ mfxVariant variant;
2949+ variant.Type = MFX_VARIANT_TYPE_U16;
2950+ variant.Data.U32 = data;
2951+ mfxStatus sts = MFXSetConfigFilterProperty(cfg, (mfxU8 *)propertyName, variant);
2952+ MSDK_CHECK_STATUS(sts, "MFXSetConfigFilterProperty failed");
2953+ m_Configs.push_back(cfg);
2954+
2955+ return sts;
2956+}
2957+
2958+mfxStatus VPLImplementationLoader::CreateConfig(mfxU32 data, const char *propertyName) {
2959+ mfxConfig cfg = MFXCreateConfig(m_Loader);
2960+ mfxVariant variant;
2961+ variant.Type = MFX_VARIANT_TYPE_U32;
2962+ variant.Data.U32 = data;
2963+ mfxStatus sts = MFXSetConfigFilterProperty(cfg, (mfxU8 *)propertyName, variant);
2964+ MSDK_CHECK_STATUS(sts, "MFXSetConfigFilterProperty failed");
2965+ m_Configs.push_back(cfg);
2966+
2967+ return sts;
2968+}
2969+
2970+mfxStatus VPLImplementationLoader::ConfigureImplementation(mfxIMPL impl) {
2971+ mfxConfig cfgImpl = MFXCreateConfig(m_Loader);
2972+
2973+ mfxVariant ImplVariant;
2974+ ImplVariant.Type = MFX_VARIANT_TYPE_U32;
2975+
2976+ std::vector<mfxU32> hwImpls = { MFX_IMPL_HARDWARE, MFX_IMPL_HARDWARE_ANY, MFX_IMPL_HARDWARE2,
2977+ MFX_IMPL_HARDWARE3, MFX_IMPL_HARDWARE4, MFX_IMPL_VIA_D3D9,
2978+ MFX_IMPL_VIA_D3D11 };
2979+
2980+ std::vector<mfxU32>::iterator hwImplsIt =
2981+ std::find_if(hwImpls.begin(), hwImpls.end(), [impl](const mfxU32 &val) {
2982+ return (val == MFX_IMPL_VIA_MASK(impl) || val == MFX_IMPL_BASETYPE(impl));
2983+ });
2984+
2985+ if (MFX_IMPL_BASETYPE(impl) == MFX_IMPL_SOFTWARE) {
2986+ ImplVariant.Data.U32 = MFX_IMPL_TYPE_SOFTWARE;
2987+ }
2988+ else if (hwImplsIt != hwImpls.end()) {
2989+ ImplVariant.Data.U32 = MFX_IMPL_TYPE_HARDWARE;
2990+ }
2991+ else {
2992+ return MFX_ERR_UNSUPPORTED;
2993+ }
2994+
2995+ mfxStatus sts =
2996+ MFXSetConfigFilterProperty(cfgImpl, (mfxU8 *)"mfxImplDescription.Impl", ImplVariant);
2997+ MSDK_CHECK_STATUS(sts, "MFXSetConfigFilterProperty failed");
2998+ m_Configs.push_back(cfgImpl);
2999+ return sts;
3000+}
3001+
3002+mfxStatus VPLImplementationLoader::ConfigureAccelerationMode(mfxAccelerationMode accelerationMode,
3003+ mfxIMPL impl) {
3004+ mfxStatus sts = MFX_ERR_NONE;
3005+ bool isHW = impl == MFX_IMPL_SOFTWARE ? false : true;
3006+
3007+ // configure accelerationMode, except when required implementation is
3008+ // MFX_IMPL_TYPE_HARDWARE, but m_accelerationMode not set
3009+ if (accelerationMode != MFX_ACCEL_MODE_NA || !isHW) {
3010+ sts = CreateConfig((mfxU32)accelerationMode, "mfxImplDescription.AccelerationMode");
3011+ }
3012+
3013+ return sts;
3014+}
3015+
3016+mfxStatus VPLImplementationLoader::ConfigureVersion(mfxVersion const &version) {
3017+ mfxStatus sts = MFX_ERR_NONE;
3018+
3019+ sts = CreateConfig(version.Version, "mfxImplDescription.ApiVersion.Version");