summaryrefslogtreecommitdiffstats
path: root/recipes-multimedia
diff options
context:
space:
mode:
authorYew, Chang Ching <chang.ching.yew@intel.com>2021-07-03 02:39:10 +0800
committerAnuj Mittal <anuj.mittal@intel.com>2021-07-03 22:48:10 +0800
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 fb832380..00000000
--- 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");
3020+ sts = CreateConfig(version.Major, "mfxImplDescription.ApiVersion.Major");
3021+ sts = CreateConfig(version.Minor, "mfxImplDescription.ApiVersion.Minor");
3022+
3023+ return sts;
3024+}
3025+
3026+mfxStatus VPLImplementationLoader::EnumImplementations() {
3027+ // pick the first available implementation, m_desc is checked only for being
3028+ // non-equal to NULL potentially may be needed loop by implementations, set
3029+ // implIndex corresponding better implementation and add meaningful validation
3030+ // for the m_idesc
3031+ mfxImplDescription *idesc;
3032+ mfxStatus sts =
3033+ MFXEnumImplementations(m_Loader, 0, MFX_IMPLCAPS_IMPLDESCSTRUCTURE, (mfxHDL *)&idesc);
3034+ MSDK_CHECK_STATUS(sts, "MFXEnumImplementations failed");
3035+ MSDK_CHECK_POINTER(idesc, MFX_ERR_NULL_PTR);
3036+ m_idesc = idesc;
3037+
3038+ m_ImplIndex = 0;
3039+
3040+ return sts;
3041+}
3042+
3043+mfxStatus VPLImplementationLoader::EnumImplementations(mfxU16 deviceID, mfxU32 adapterNum) {
3044+ mfxImplDescription *idesc;
3045+ mfxStatus sts = MFX_ERR_NONE;
3046+ mfxChar devIDAndAdapter[MFX_STRFIELD_LEN] = {};
3047+ snprintf(devIDAndAdapter, sizeof(devIDAndAdapter), "%x/%d", deviceID, adapterNum);
3048+
3049+ int impl = 0;
3050+ while (sts == MFX_ERR_NONE) {
3051+ sts = MFXEnumImplementations(m_Loader,
3052+ impl,
3053+ MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
3054+ (mfxHDL *)&idesc);
3055+ if (!idesc) {
3056+ sts = MFX_ERR_NULL_PTR;
3057+ break;
3058+ }
3059+ else if (strncmp(idesc->Dev.DeviceID, devIDAndAdapter, sizeof(devIDAndAdapter)) == 0) {
3060+ m_idesc = idesc;
3061+ m_ImplIndex = impl;
3062+ break;
3063+ }
3064+ impl++;
3065+ }
3066+
3067+ return sts;
3068+}
3069+
3070+mfxStatus VPLImplementationLoader::ConfigureAndEnumImplementations(
3071+ mfxIMPL impl,
3072+ mfxAccelerationMode accelerationMode,
3073+ mfxVersion const &version) {
3074+ mfxStatus sts;
3075+
3076+ sts = ConfigureImplementation(impl);
3077+ MSDK_CHECK_STATUS(sts, "ConfigureImplementation failed");
3078+
3079+ sts = ConfigureAccelerationMode(accelerationMode, impl);
3080+ MSDK_CHECK_STATUS(sts, "ConfigureAccelerationMode failed");
3081+
3082+ sts = EnumImplementations();
3083+ MSDK_CHECK_STATUS(sts, "EnumImplementations failed");
3084+
3085+ return sts;
3086+}
3087+
3088+mfxLoader VPLImplementationLoader::GetLoader() {
3089+ return m_Loader;
3090+}
3091+
3092+mfxU32 VPLImplementationLoader::GetImplIndex() const {
3093+ return m_ImplIndex;
3094+};
3095+
3096+mfxStatus VPLImplementationLoader::GetVersion(mfxVersion *version) {
3097+ if (!m_idesc) {
3098+ EnumImplementations();
3099+ }
3100+
3101+ if (m_idesc) {
3102+ version->Major = m_idesc->ApiVersion.Major;
3103+ version->Minor = m_idesc->ApiVersion.Minor;
3104+ version->Version = m_idesc->ApiVersion.Version;
3105+ return MFX_ERR_NONE;
3106+ }
3107+
3108+ return MFX_ERR_UNKNOWN;
3109+}
3110+
3111+mfxStatus MainVideoSession::CreateSession(VPLImplementationLoader *Loader) {
3112+ return MFXCreateSession(Loader->GetLoader(), Loader->GetImplIndex(), &m_session);
3113+}
3114diff --git a/tools/legacy/sample_multi_transcode/CMakeLists.txt b/tools/legacy/sample_multi_transcode/CMakeLists.txt
3115new file mode 100644
3116index 0000000..2121c57
3117--- /dev/null
3118+++ b/tools/legacy/sample_multi_transcode/CMakeLists.txt
3119@@ -0,0 +1,42 @@
3120+# ##############################################################################
3121+# Copyright (C) 2021 Intel Corporation
3122+#
3123+# SPDX-License-Identifier: MIT
3124+# ##############################################################################
3125+cmake_minimum_required(VERSION 3.10.2)
3126+
3127+set(TARGET sample_multi_transcode)
3128+
3129+set(SOURCES "")
3130+list(APPEND SOURCES src/pipeline_transcode.cpp src/sample_multi_transcode.cpp
3131+ src/transcode_utils.cpp)
3132+
3133+add_executable(${TARGET} ${SOURCES})
3134+
3135+if(MSVC)
3136+ add_definitions(-D_CRT_SECURE_NO_WARNINGS)
3137+endif()
3138+
3139+if(POLICY CMP0074)
3140+ # ignore warning of VPL_ROOT in find_package search path
3141+ cmake_policy(SET CMP0074 OLD)
3142+endif()
3143+
3144+target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
3145+ ${CMAKE_SOURCE_DIR}/api/vpl)
3146+find_package(VPL REQUIRED)
3147+target_link_libraries(${TARGET} sample_common media_sdk_compatibility_headers)
3148+add_definitions(-DMFX_ONEVPL)
3149+if(UNIX)
3150+ target_link_libraries(${TARGET} ${PKG_LIBVA_LIBRARIES} ${CMAKE_DL_LIBS}
3151+ pthread)
3152+ add_definitions(-DLIBVA_SUPPORT -DLIBVA_DRM_SUPPORT -DLINUX64)
3153+ target_include_directories(${TARGET} PRIVATE ${PKG_LIBVA_INCLUDE_DIRS}
3154+ ${PKG_LIBDRM_INCLUDE_DIRS})
3155+else()
3156+ target_link_libraries(${TARGET} DXGI D3D11 D3D9 DXVA2)
3157+ add_definitions(-DMFX_D3D11_SUPPORT)
3158+endif()
3159+
3160+install(TARGETS ${TARGET} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
3161+ COMPONENT runtime)
3162diff --git a/tools/legacy/sample_multi_transcode/include/pipeline_transcode.h b/tools/legacy/sample_multi_transcode/include/pipeline_transcode.h
3163new file mode 100644
3164index 0000000..457d72c
3165--- /dev/null
3166+++ b/tools/legacy/sample_multi_transcode/include/pipeline_transcode.h
3167@@ -0,0 +1,973 @@
3168+/******************************************************************************\
3169+Copyright (c) 2005-2019, Intel Corporation
3170+All rights reserved.
3171+
3172+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
3173+
3174+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
3175+
3176+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.
3177+
3178+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.
3179+
3180+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.
3181+
3182+This sample was distributed or derived from the Intel's Media Samples package.
3183+The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
3184+or https://software.intel.com/en-us/media-client-solutions-support.
3185+\**********************************************************************************/
3186+
3187+#ifndef __SAMPLE_PIPELINE_TRANSCODE_H__
3188+#define __SAMPLE_PIPELINE_TRANSCODE_H__
3189+
3190+#include <stddef.h>
3191+
3192+#include <chrono>
3193+#include <ctime>
3194+#include <future>
3195+#include <list>
3196+#include <map>
3197+#include <memory>
3198+#include <mutex>
3199+#include <vector>
3200+
3201+#include "base_allocator.h"
3202+#include "mfx_multi_vpp.h"
3203+#include "rotate_plugin_api.h"
3204+#include "sample_defs.h"
3205+#include "sample_utils.h"
3206+#include "sysmem_allocator.h"
3207+
3208+#include "mfxdispatcher.h"
3209+#include "mfxjpeg.h"
3210+#include "mfxmvc.h"
3211+#include "mfxvideo++.h"
3212+#include "mfxvideo.h"
3213+#if !defined(MFX_ONEVPL)
3214+ #include "mfxla.h"
3215+#endif
3216+#include "mfxvp8.h"
3217+
3218+#if defined(MFX_ONEVPL)
3219+ #include "mfxdeprecated.h"
3220+#endif
3221+
3222+#include "mfxplugin.h"
3223+
3224+#if !defined(MFX_ONEVPL)
3225+ #include "mfxplugin++.h"
3226+ #include "plugin_loader.h"
3227+#endif
3228+
3229+#include "hw_device.h"
3230+#include "plugin_utils.h"
3231+#include "preset_manager.h"
3232+#include "sample_defs.h"
3233+
3234+#if (MFX_VERSION >= 1024)
3235+ #include "brc_routines.h"
3236+#endif
3237+
3238+#define TIME_STATS 1 // Enable statistics processing
3239+#include "time_statistics.h"
3240+
3241+#if defined(_WIN32) || defined(_WIN64)
3242+ #include "decode_render.h"
3243+#endif
3244+
3245+#if defined(_WIN32) || defined(_WIN64)
3246+ #define MSDK_CPU_ROTATE_PLUGIN MSDK_STRING("sample_rotate_plugin.dll")
3247+ #define MSDK_OCL_ROTATE_PLUGIN MSDK_STRING("sample_plugin_opencl.dll")
3248+#else
3249+ #define MSDK_CPU_ROTATE_PLUGIN MSDK_STRING("libsample_rotate_plugin.so")
3250+ #define MSDK_OCL_ROTATE_PLUGIN MSDK_STRING("libsample_plugin_opencl.so")
3251+#endif
3252+
3253+#define MAX_PREF_LEN 256
3254+
3255+#ifndef MFX_VERSION
3256+ #error MFX_VERSION not defined
3257+#endif
3258+
3259+#ifdef ENABLE_MCTF
3260+const mfxU16 MCTF_MID_FILTER_STRENGTH = 10;
3261+const mfxF64 MCTF_LOSSLESS_BPP = 0.0;
3262+#endif
3263+
3264+namespace TranscodingSample {
3265+enum PipelineMode {
3266+ Native =
3267+ 0, // means that pipeline is based depends on the cmd parameters (decode/encode/transcode)
3268+ Sink, // means that pipeline makes decode only and put data to shared buffer
3269+ Source, // means that pipeline makes vpp + encode and get data from shared buffer
3270+ VppComp, // means that pipeline makes vpp composition + encode and get data from shared buffer
3271+ VppCompOnly, // means that pipeline makes vpp composition and get data from shared buffer
3272+ VppCompOnlyEncode // means that pipeline makes vpp composition + encode and get data from shared buffer
3273+};
3274+
3275+enum VppCompDumpMode { NULL_RENDER_VPP_COMP = 1, DUMP_FILE_VPP_COMP = 2 };
3276+
3277+enum EFieldCopyMode { FC_NONE = 0, FC_T2T = 1, FC_T2B = 2, FC_B2T = 4, FC_B2B = 8, FC_FR2FR = 16 };
3278+
3279+struct sVppCompDstRect {
3280+ mfxU32 DstX;
3281+ mfxU32 DstY;
3282+ mfxU32 DstW;
3283+ mfxU32 DstH;
3284+ mfxU16 TileId;
3285+};
3286+
3287+#ifdef ENABLE_MCTF
3288+typedef enum {
3289+ VPP_FILTER_DISABLED = 0,
3290+ VPP_FILTER_ENABLED_DEFAULT = 1,
3291+ VPP_FILTER_ENABLED_CONFIGURED = 7
3292+
3293+} VPPFilterMode;
3294+
3295+// this is a structure with mctf-parameteres
3296+// that can be changed in run-time;
3297+struct sMctfRunTimeParam {
3298+ #ifdef ENABLE_MCTF_EXT
3299+ #if 0
3300+ mfxU32 BitsPerPixelx100k;
3301+ mfxU16 Deblock;
3302+ #endif
3303+ #endif
3304+ mfxU16 FilterStrength;
3305+};
3306+
3307+struct sMctfRunTimeParams {
3308+ sMctfRunTimeParams() : CurIdx(0) {}
3309+
3310+ mfxU32 CurIdx;
3311+ std::vector<sMctfRunTimeParam> RunTimeParams;
3312+ // returns rt-param corresponding to CurIdx or NULL if
3313+ // CurIdx is behind available info
3314+ const sMctfRunTimeParam *GetCurParam();
3315+ // move CurIdx forward
3316+ void MoveForward();
3317+ // set CurIdx to the begining; restart indexing;
3318+ void Restart();
3319+ // reset vector & index
3320+ void Reset();
3321+ // test for emptiness
3322+ bool Empty() {
3323+ return RunTimeParams.empty();
3324+ };
3325+};
3326+
3327+struct sMCTFParam {
3328+ sMctfRunTimeParams rtParams;
3329+ mfxExtVppMctf params;
3330+ VPPFilterMode mode;
3331+};
3332+#endif
3333+
3334+enum ExtBRCType { EXTBRC_DEFAULT, EXTBRC_OFF, EXTBRC_ON, EXTBRC_IMPLICIT };
3335+
3336+enum MemoryModel {
3337+ UNKNOWN_ALLOC = 0, // GENERAL_ALLOC will be used by default
3338+ GENERAL_ALLOC = 1,
3339+ VISIBLE_INT_ALLOC = 2,
3340+ HIDDEN_INT_ALLOC = 3
3341+};
3342+
3343+struct __sInputParams {
3344+ // session parameters
3345+ bool bIsJoin;
3346+ mfxPriority priority;
3347+ // common parameters
3348+ mfxIMPL libType; // Type of used mediaSDK library
3349+#if defined(LINUX32) || defined(LINUX64)
3350+ std::string strDevicePath;
3351+#endif
3352+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
3353+ //Adapter type
3354+ bool bPrefferiGfx;
3355+ bool bPrefferdGfx;
3356+#endif
3357+ bool bIsPerf; // special performance mode. Use pre-allocated bitstreams, output
3358+ mfxU16 nThreadsNum; // number of internal session threads number
3359+ bool bRobustFlag; // Robust transcoding mode. Allows auto-recovery after hardware errors
3360+ bool bSoftRobustFlag;
3361+
3362+ mfxU32 EncodeId; // type of output coded video
3363+ mfxU32 DecodeId; // type of input coded video
3364+
3365+ msdk_char strSrcFile[MSDK_MAX_FILENAME_LEN]; // source bitstream file
3366+ msdk_char strDstFile[MSDK_MAX_FILENAME_LEN]; // destination bitstream file
3367+ msdk_char strDumpVppCompFile[MSDK_MAX_FILENAME_LEN]; // VPP composition output dump file
3368+ msdk_char strMfxParamsDumpFile[MSDK_MAX_FILENAME_LEN];
3369+
3370+ // specific encode parameters
3371+ mfxU16 nTargetUsage;
3372+ mfxF64 dDecoderFrameRateOverride;
3373+ mfxF64 dEncoderFrameRateOverride;
3374+ mfxU16 EncoderPicstructOverride;
3375+ mfxF64 dVPPOutFramerate;
3376+ mfxU16 nBitRate;
3377+ mfxU16 nBitRateMultiplier;
3378+ mfxU16 nQuality; // quality parameter for JPEG encoder
3379+ mfxU16 nDstWidth; // destination picture width, specified if resizing required
3380+ mfxU16 nDstHeight; // destination picture height, specified if resizing required
3381+
3382+ mfxU16 nEncTileRows; // number of rows for encoding tiling
3383+ mfxU16 nEncTileCols; // number of columns for encoding tiling
3384+
3385+ bool bEnableDeinterlacing;
3386+ mfxU16 DeinterlacingMode;
3387+ int DenoiseLevel;
3388+ int DetailLevel;
3389+ mfxU16 FRCAlgorithm;
3390+ EFieldCopyMode fieldProcessingMode;
3391+ mfxU16 ScalingMode;
3392+
3393+ mfxU16 nAsyncDepth; // asyncronous queue
3394+
3395+ PipelineMode eMode;
3396+ PipelineMode eModeExt;
3397+
3398+ mfxU32 FrameNumberPreference; // how many surfaces user wants
3399+ mfxU32 MaxFrameNumber; // maximum frames for transcoding
3400+ mfxU32 numSurf4Comp;
3401+ mfxU16 numTiles4Comp;
3402+
3403+ mfxU16 nSlices; // number of slices for encoder initialization
3404+ mfxU16 nMaxSliceSize; //maximum size of slice
3405+
3406+ mfxU16 WinBRCMaxAvgKbps;
3407+ mfxU16 WinBRCSize;
3408+ mfxU16 BufferSizeInKB;
3409+ mfxU16 GopPicSize;
3410+ mfxU16 GopRefDist;
3411+ mfxU16 NumRefFrame;
3412+ mfxU16 nBRefType;
3413+ mfxU16 RepartitionCheckMode;
3414+ mfxU16 GPB;
3415+ mfxU16 nTransformSkip;
3416+
3417+ mfxU16 CodecLevel;
3418+ mfxU16 CodecProfile;
3419+ mfxU16 MaxKbps;
3420+ mfxU16 InitialDelayInKB;
3421+ mfxU16 GopOptFlag;
3422+ mfxU16 AdaptiveI;
3423+ mfxU16 AdaptiveB;
3424+
3425+ mfxU16 WeightedPred;
3426+ mfxU16 WeightedBiPred;
3427+ mfxU16 ExtBrcAdaptiveLTR;
3428+
3429+ bool bExtMBQP;
3430+
3431+ // MVC Specific Options
3432+ bool bIsMVC; // true if Multi-View-Codec is in use
3433+ mfxU32 numViews; // number of views for Multi-View-Codec
3434+
3435+ mfxU16 nRotationAngle; // if specified, enables rotation plugin in mfx pipeline
3436+ msdk_char strVPPPluginDLLPath[MSDK_MAX_FILENAME_LEN]; // plugin dll path and name
3437+
3438+ sPluginParams decoderPluginParams;
3439+ sPluginParams encoderPluginParams;
3440+
3441+ mfxU32 nTimeout; // how long transcoding works in seconds
3442+ mfxU32 nFPS; // limit transcoding to the number of frames per second
3443+
3444+ mfxU32 statisticsWindowSize;
3445+ FILE *statisticsLogFile;
3446+
3447+ bool bLABRC; // use look ahead bitrate control algorithm
3448+ mfxU16 nLADepth; // depth of the look ahead bitrate control algorithm
3449+ bool bEnableExtLA;
3450+ bool bEnableBPyramid;
3451+ mfxU16 nRateControlMethod;
3452+ mfxU16 nQPI;
3453+ mfxU16 nQPP;
3454+ mfxU16 nQPB;
3455+ bool bDisableQPOffset;
3456+
3457+ mfxU16 nAvcTemp;
3458+ mfxU16 nBaseLayerPID;
3459+ mfxU16 nAvcTemporalLayers[8];
3460+ mfxU16 nSPSId;
3461+ mfxU16 nPPSId;
3462+ mfxU16 nPicTimingSEI;
3463+ mfxU16 nNalHrdConformance;
3464+ mfxU16 nVuiNalHrdParameters;
3465+
3466+ bool bOpenCL;
3467+ mfxU16 reserved[4];
3468+
3469+ mfxU16 nVppCompDstX;
3470+ mfxU16 nVppCompDstY;
3471+ mfxU16 nVppCompDstW;
3472+ mfxU16 nVppCompDstH;
3473+ mfxU16 nVppCompSrcW;
3474+ mfxU16 nVppCompSrcH;
3475+ mfxU16 nVppCompTileId;
3476+
3477+ mfxU32 DecoderFourCC;
3478+ mfxU32 EncoderFourCC;
3479+
3480+ sVppCompDstRect *pVppCompDstRects;
3481+
3482+ bool bForceSysMem;
3483+ mfxU16 DecOutPattern;
3484+ mfxU16 VppOutPattern;
3485+ mfxU16 nGpuCopyMode;
3486+
3487+ mfxU16 nRenderColorForamt; /*0 NV12 - default, 1 is ARGB*/
3488+
3489+ mfxI32 monitorType;
3490+ bool shouldUseGreedyFormula;
3491+ bool enableQSVFF;
3492+ bool bSingleTexture;
3493+
3494+ ExtBRCType nExtBRC;
3495+
3496+ mfxU16 nAdaptiveMaxFrameSize;
3497+ mfxU16 LowDelayBRC;
3498+
3499+ mfxU16 IntRefType;
3500+ mfxU16 IntRefCycleSize;
3501+ mfxU16 IntRefQPDelta;
3502+ mfxU16 IntRefCycleDist;
3503+
3504+ mfxU32 nMaxFrameSize;
3505+
3506+ mfxU16 BitrateLimit;
3507+
3508+#if (MFX_VERSION >= 1025)
3509+ mfxU16 numMFEFrames;
3510+ mfxU16 MFMode;
3511+ mfxU32 mfeTimeout;
3512+#endif
3513+
3514+#if (MFX_VERSION >= 1027)
3515+ mfxU16 TargetBitDepthLuma;
3516+ mfxU16 TargetBitDepthChroma;
3517+#endif
3518+
3519+#if defined(LIBVA_WAYLAND_SUPPORT)
3520+ mfxU16 nRenderWinX;
3521+ mfxU16 nRenderWinY;
3522+ bool bPerfMode;
3523+#endif
3524+
3525+#if defined(LIBVA_SUPPORT)
3526+ mfxI32 libvaBackend;
3527+#endif // defined(MFX_LIBVA_SUPPORT)
3528+
3529+ CHWDevice *m_hwdev;
3530+
3531+ EPresetModes PresetMode;
3532+ bool shouldPrintPresets;
3533+
3534+ bool rawInput;
3535+
3536+ mfxU16 nMemoryModel;
3537+};
3538+
3539+struct sInputParams : public __sInputParams {
3540+ sInputParams();
3541+ msdk_string DumpLogFileName;
3542+#if MFX_VERSION >= 1022
3543+ std::vector<mfxExtEncoderROI> m_ROIData;
3544+
3545+ bool bDecoderPostProcessing;
3546+ bool bROIasQPMAP;
3547+#endif //MFX_VERSION >= 1022
3548+#ifdef ENABLE_MCTF
3549+ sMCTFParam mctfParam;
3550+#endif
3551+};
3552+
3553+struct PreEncAuxBuffer {
3554+ mfxEncodeCtrl encCtrl;
3555+ mfxU16 Locked;
3556+ mfxENCInput encInput;
3557+ mfxENCOutput encOutput;
3558+};
3559+
3560+struct ExtendedSurface {
3561+ mfxFrameSurface1 *pSurface;
3562+ PreEncAuxBuffer *pAuxCtrl;
3563+ mfxEncodeCtrl *pEncCtrl;
3564+ mfxSyncPoint Syncp;
3565+};
3566+
3567+struct ExtendedBS {
3568+ bool IsFree = true;
3569+ mfxBitstreamWrapper Bitstream;
3570+ mfxSyncPoint Syncp = nullptr;
3571+ PreEncAuxBuffer *pCtrl = nullptr;
3572+};
3573+
3574+class CIOStat : public CTimeStatistics {
3575+public:
3576+ CIOStat() : CTimeStatistics(), ofile(stdout) {
3577+ MSDK_ZERO_MEMORY(bufDir);
3578+ DumpLogFileName.clear();
3579+ }
3580+
3581+ CIOStat(const msdk_char *dir) : CTimeStatistics(), ofile(stdout) {
3582+ msdk_strncopy_s(bufDir, MAX_PREF_LEN, dir, MAX_PREF_LEN - 1);
3583+ bufDir[MAX_PREF_LEN - 1] = 0;
3584+ }
3585+
3586+ ~CIOStat() {}
3587+
3588+ inline void SetOutputFile(FILE *file) {
3589+ ofile = file;
3590+ }
3591+
3592+ inline void SetDumpName(const msdk_char *name) {
3593+ DumpLogFileName = name;
3594+ if (!DumpLogFileName.empty()) {
3595+ TurnOnDumping();
3596+ }
3597+ else {
3598+ TurnOffDumping();
3599+ }
3600+ }
3601+
3602+ inline void SetDirection(const msdk_char *dir) {
3603+ if (dir) {
3604+ msdk_strncopy_s(bufDir, MAX_PREF_LEN, dir, MAX_PREF_LEN - 1);
3605+ bufDir[MAX_PREF_LEN - 1] = 0;
3606+ }
3607+ }
3608+
3609+ inline void PrintStatistics(mfxU32 numPipelineid,
3610+ mfxF64 target_framerate = -1 /*default stands for infinite*/) {
3611+ // print timings in ms
3612+ msdk_fprintf(
3613+ ofile,
3614+ MSDK_STRING(
3615+ "stat[%u.%llu]: %s=%d;Framerate=%.3f;Total=%.3lf;Samples=%lld;StdDev=%.3lf;Min=%.3lf;Max=%.3lf;Avg=%.3lf\n"),
3616+ msdk_get_current_pid(),
3617+ rdtsc(),
3618+ bufDir,
3619+ numPipelineid,
3620+ target_framerate,
3621+ GetTotalTime(false),
3622+ GetNumMeasurements(),
3623+ GetTimeStdDev(false),
3624+ GetMinTime(false),
3625+ GetMaxTime(false),
3626+ GetAvgTime(false));
3627+ fflush(ofile);
3628+
3629+ if (!DumpLogFileName.empty()) {
3630+ msdk_char buf[MSDK_MAX_FILENAME_LEN];
3631+ msdk_sprintf(buf, MSDK_STRING("%s_ID_%d.log"), DumpLogFileName.c_str(), numPipelineid);
3632+ DumpDeltas(buf);
3633+ }
3634+ }
3635+
3636+ inline void DumpDeltas(msdk_char *file_name) {
3637+ if (m_time_deltas.empty())
3638+ return;
3639+
3640+ FILE *dump_file = NULL;
3641+ if (!MSDK_FOPEN(dump_file, file_name, MSDK_STRING("a"))) {
3642+ for (std::vector<mfxF64>::const_iterator it = m_time_deltas.begin();
3643+ it != m_time_deltas.end();
3644+ ++it) {
3645+ fprintf(dump_file, "%.3f, ", (*it));
3646+ }
3647+ fclose(dump_file);
3648+ }
3649+ else {
3650+ perror("DumpDeltas: file cannot be open");
3651+ }
3652+ }
3653+
3654+protected:
3655+ msdk_tstring DumpLogFileName;
3656+ FILE *ofile;
3657+ msdk_char bufDir[MAX_PREF_LEN];
3658+};
3659+
3660+class ExtendedBSStore {
3661+public:
3662+ explicit ExtendedBSStore(mfxU32 size) {
3663+ m_pExtBS.resize(size);
3664+ }
3665+ virtual ~ExtendedBSStore() {
3666+ m_pExtBS.clear();
3667+ }
3668+ ExtendedBS *GetNext() {
3669+ for (mfxU32 i = 0; i < m_pExtBS.size(); i++) {
3670+ if (m_pExtBS[i].IsFree) {
3671+ m_pExtBS[i].IsFree = false;
3672+ return &m_pExtBS[i];
3673+ }
3674+ }
3675+ return NULL;
3676+ }
3677+ void Release(ExtendedBS *pBS) {
3678+ for (mfxU32 i = 0; i < m_pExtBS.size(); i++) {
3679+ if (&m_pExtBS[i] == pBS) {
3680+ m_pExtBS[i].IsFree = true;
3681+ return;
3682+ }
3683+ }
3684+ return;
3685+ }
3686+ void ReleaseAll() {
3687+ for (mfxU32 i = 0; i < m_pExtBS.size(); i++) {
3688+ m_pExtBS[i].IsFree = true;
3689+ }
3690+ return;
3691+ }
3692+ void FlushAll() {
3693+ for (mfxU32 i = 0; i < m_pExtBS.size(); i++) {
3694+ m_pExtBS[i].Bitstream.DataLength = 0;
3695+ m_pExtBS[i].Bitstream.DataOffset = 0;
3696+ }
3697+ return;
3698+ }
3699+
3700+protected:
3701+ std::vector<ExtendedBS> m_pExtBS;
3702+
3703+private:
3704+ DISALLOW_COPY_AND_ASSIGN(ExtendedBSStore);
3705+};
3706+
3707+class CTranscodingPipeline;
3708+// thread safety buffer heterogeneous pipeline
3709+// only for join sessions
3710+class SafetySurfaceBuffer {
3711+public:
3712+ struct SurfaceDescriptor {
3713+ ExtendedSurface ExtSurface;
3714+ mfxU32 Locked;
3715+ };
3716+
3717+ SafetySurfaceBuffer(SafetySurfaceBuffer *pNext);
3718+ virtual ~SafetySurfaceBuffer();
3719+
3720+ mfxU32 GetLength();
3721+ mfxStatus WaitForSurfaceRelease(mfxU32 msec);
3722+ mfxStatus WaitForSurfaceInsertion(mfxU32 msec);
3723+ void AddSurface(ExtendedSurface Surf);
3724+ mfxStatus GetSurface(ExtendedSurface &Surf);
3725+ mfxStatus ReleaseSurface(mfxFrameSurface1 *pSurf);
3726+ mfxStatus ReleaseSurfaceAll();
3727+ void CancelBuffering();
3728+
3729+ SafetySurfaceBuffer *m_pNext;
3730+
3731+protected:
3732+ std::mutex m_mutex;
3733+ std::list<SurfaceDescriptor> m_SList;
3734+ bool m_IsBufferingAllowed;
3735+ MSDKEvent *pRelEvent;
3736+ MSDKEvent *pInsEvent;
3737+
3738+private:
3739+ DISALLOW_COPY_AND_ASSIGN(SafetySurfaceBuffer);
3740+};
3741+
3742+class FileBitstreamProcessor {
3743+public:
3744+ FileBitstreamProcessor();
3745+ virtual ~FileBitstreamProcessor();
3746+ virtual mfxStatus SetReader(std::unique_ptr<CSmplBitstreamReader> &reader);
3747+ virtual mfxStatus SetReader(std::unique_ptr<CSmplYUVReader> &reader);
3748+ virtual mfxStatus SetWriter(std::unique_ptr<CSmplBitstreamWriter> &writer);
3749+ virtual mfxStatus GetInputBitstream(mfxBitstreamWrapper **pBitstream);
3750+ virtual mfxStatus GetInputFrame(mfxFrameSurface1 *pSurface);
3751+ virtual mfxStatus ProcessOutputBitstream(mfxBitstreamWrapper *pBitstream);
3752+ virtual mfxStatus ResetInput();
3753+ virtual mfxStatus ResetOutput();
3754+
3755+protected:
3756+ std::unique_ptr<CSmplBitstreamReader> m_pFileReader;
3757+ std::unique_ptr<CSmplYUVReader> m_pYUVFileReader;
3758+ // for performance options can be zero
3759+ std::unique_ptr<CSmplBitstreamWriter> m_pFileWriter;
3760+ mfxBitstreamWrapper m_Bitstream;
3761+
3762+private:
3763+ DISALLOW_COPY_AND_ASSIGN(FileBitstreamProcessor);
3764+};
3765+
3766+// Bitstream is external via BitstreamProcessor
3767+class CTranscodingPipeline {
3768+public:
3769+ CTranscodingPipeline();
3770+ virtual ~CTranscodingPipeline();
3771+
3772+ virtual mfxStatus Init(sInputParams *pParams,
3773+ MFXFrameAllocator *pMFXAllocator,
3774+ void *hdl,
3775+ CTranscodingPipeline *pParentPipeline,
3776+ SafetySurfaceBuffer *pBuffer,
3777+ FileBitstreamProcessor *pBSProc,
3778+ VPLImplementationLoader *mfxLoader);
3779+
3780+ // frames allocation is suspended for heterogeneous pipeline
3781+ virtual mfxStatus CompleteInit();
3782+ virtual void Close();
3783+ virtual mfxStatus Reset(VPLImplementationLoader *mfxLoader);
3784+ virtual mfxStatus Join(MFXVideoSession *pChildSession);
3785+ virtual mfxStatus Run();
3786+ virtual mfxStatus FlushLastFrames() {
3787+ return MFX_ERR_NONE;
3788+ }
3789+
3790+ mfxU32 GetProcessFrames() {
3791+ return m_nProcessedFramesNum;
3792+ }
3793+
3794+ bool GetJoiningFlag() {
3795+ return m_bIsJoinSession;
3796+ }
3797+
3798+ mfxStatus QueryMFXVersion(mfxVersion *version) {
3799+ MSDK_CHECK_POINTER(m_pmfxSession.get(), MFX_ERR_NULL_PTR);
3800+ return m_pmfxSession->QueryVersion(version);
3801+ };
3802+ inline mfxU32 GetPipelineID() {
3803+ return m_nID;
3804+ }
3805+ inline void SetPipelineID(mfxU32 id) {
3806+ m_nID = id;
3807+ }
3808+ void StopSession();
3809+ bool IsOverlayUsed();
3810+ size_t GetRobustFlag();
3811+
3812+ msdk_string GetSessionText() {
3813+ msdk_stringstream ss;
3814+ ss << m_pmfxSession->operator mfxSession();
3815+
3816+ return ss.str();
3817+ }
3818+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
3819+ //Adapter type
3820+ void SetPrefferiGfx(bool prefferiGfx) {
3821+ bPrefferiGfx = prefferiGfx;
3822+ };
3823+ void SetPrefferdGfx(bool prefferdGfx) {
3824+ bPrefferdGfx = prefferdGfx;
3825+ };
3826+ bool IsPrefferiGfx() {
3827+ return bPrefferiGfx;
3828+ };
3829+ bool IsPrefferdGfx() {
3830+ return bPrefferdGfx;
3831+ };
3832+#endif
3833+protected:
3834+ virtual mfxStatus CheckRequiredAPIVersion(mfxVersion &version, sInputParams *pParams);
3835+
3836+ virtual mfxStatus Decode();
3837+ virtual mfxStatus Encode();
3838+ virtual mfxStatus Transcode();
3839+ virtual mfxStatus DecodeOneFrame(ExtendedSurface *pExtSurface);
3840+ virtual mfxStatus DecodeLastFrame(ExtendedSurface *pExtSurface);
3841+ virtual mfxStatus VPPOneFrame(ExtendedSurface *pSurfaceIn, ExtendedSurface *pExtSurface);
3842+ virtual mfxStatus EncodeOneFrame(ExtendedSurface *pExtSurface, mfxBitstreamWrapper *pBS);
3843+#if !defined(MFX_ONEVPL)
3844+ virtual mfxStatus PreEncOneFrame(ExtendedSurface *pInSurface, ExtendedSurface *pOutSurface);
3845+#endif
3846+ virtual mfxStatus DecodePreInit(sInputParams *pParams);
3847+ virtual mfxStatus VPPPreInit(sInputParams *pParams);
3848+ virtual mfxStatus EncodePreInit(sInputParams *pParams);
3849+#if !defined(MFX_ONEVPL)
3850+ virtual mfxStatus PreEncPreInit(sInputParams *pParams);
3851+#endif
3852+ mfxVideoParam GetDecodeParam();
3853+
3854+#if !defined(MFX_ONEVPL)
3855+ mfxExtMVCSeqDesc GetDecMVCSeqDesc() {
3856+ mfxExtMVCSeqDesc *mvc = m_mfxDecParams;
3857+ return mvc ? *mvc : mfxExtMVCSeqDesc();
3858+ }
3859+#endif
3860+ static void ModifyParamsUsingPresets(sInputParams &params,
3861+ mfxF64 fps,
3862+ mfxU32 width,
3863+ mfxU32 height);
3864+
3865+ // alloc frames for all component
3866+ mfxStatus AllocFrames(mfxFrameAllocRequest *pRequest, bool isDecAlloc);
3867+ mfxStatus AllocFrames();
3868+
3869+#if !defined(MFX_ONEVPL)
3870+ mfxStatus CorrectPreEncAuxPool(mfxU32 num_frames_in_pool);
3871+ mfxStatus AllocPreEncAuxPool();
3872+ void FreePreEncAuxPool();
3873+#endif //!MFX_ONEVPL
3874+
3875+ // need for heterogeneous pipeline
3876+ mfxStatus CalculateNumberOfReqFrames(mfxFrameAllocRequest &pRequestDecOut,
3877+ mfxFrameAllocRequest &pRequestVPPOut);
3878+ void CorrectNumberOfAllocatedFrames(mfxFrameAllocRequest *pNewReq);
3879+ void FreeFrames();
3880+
3881+ mfxStatus LoadStaticSurface();
3882+
3883+ mfxFrameSurface1 *GetFreeSurface(bool isDec, mfxU64 timeout);
3884+ mfxU32 GetFreeSurfacesCount(bool isDec);
3885+ PreEncAuxBuffer *GetFreePreEncAuxBuffer();
3886+ void SetEncCtrlRT(ExtendedSurface &extSurface, bool bInsertIDR);
3887+
3888+ // parameters configuration functions
3889+ mfxStatus InitDecMfxParams(sInputParams *pInParams);
3890+ mfxStatus InitVppMfxParams(sInputParams *pInParams);
3891+ virtual mfxStatus InitEncMfxParams(sInputParams *pInParams);
3892+ mfxStatus InitPluginMfxParams(sInputParams *pInParams);
3893+#if !defined(MFX_ONEVPL)
3894+ mfxStatus InitPreEncMfxParams(sInputParams *pInParams);
3895+#endif
3896+ virtual mfxU32 FileFourCC2EncFourCC(mfxU32 fcc);
3897+ void FillFrameInfoForEncoding(mfxFrameInfo &info, sInputParams *pInParams);
3898+
3899+ mfxStatus AllocAndInitVppDoNotUse(sInputParams *pInParams);
3900+ mfxStatus AllocMVCSeqDesc();
3901+
3902+ void FreeVppDoNotUse();
3903+ void FreeMVCSeqDesc();
3904+
3905+ mfxStatus AllocateSufficientBuffer(mfxBitstreamWrapper *pBS);
3906+ mfxStatus PutBS();
3907+
3908+ mfxStatus DumpSurface2File(mfxFrameSurface1 *pSurface);
3909+ mfxStatus Surface2BS(ExtendedSurface *pSurf, mfxBitstreamWrapper *pBS, mfxU32 fourCC);
3910+ mfxStatus NV12toBS(mfxFrameSurface1 *pSurface, mfxBitstreamWrapper *pBS);
3911+ mfxStatus NV12asI420toBS(mfxFrameSurface1 *pSurface, mfxBitstreamWrapper *pBS);
3912+ mfxStatus RGB4toBS(mfxFrameSurface1 *pSurface, mfxBitstreamWrapper *pBS);
3913+ mfxStatus YUY2toBS(mfxFrameSurface1 *pSurface, mfxBitstreamWrapper *pBS);
3914+
3915+ void NoMoreFramesSignal();
3916+ mfxStatus AddLaStreams(mfxU16 width, mfxU16 height);
3917+
3918+ void LockPreEncAuxBuffer(PreEncAuxBuffer *pBuff);
3919+ void UnPreEncAuxBuffer(PreEncAuxBuffer *pBuff);
3920+
3921+ mfxU32 GetNumFramesForReset();
3922+ void SetNumFramesForReset(mfxU32 nFrames);
3923+
3924+ void HandlePossibleGpuHang(mfxStatus &sts);
3925+
3926+ mfxStatus SetAllocatorAndHandleIfRequired();
3927+ mfxStatus LoadGenericPlugin();
3928+
3929+ mfxBitstreamWrapper *m_pmfxBS; // contains encoded input data
3930+
3931+ mfxVersion m_Version; // real API version with which library is initialized
3932+
3933+ mfxLoader m_mfxLoader;
3934+
3935+ std::unique_ptr<MainVideoSession> m_pmfxSession;
3936+ std::unique_ptr<MFXVideoDECODE> m_pmfxDEC;
3937+ std::unique_ptr<MFXVideoENCODE> m_pmfxENC;
3938+ std::unique_ptr<MFXVideoMultiVPP>
3939+ m_pmfxVPP; // either VPP or VPPPlugin which wraps [VPP]-Plugin-[VPP] pipeline
3940+#if !defined(MFX_ONEVPL)
3941+ std::unique_ptr<MFXVideoENC> m_pmfxPreENC;
3942+ std::unique_ptr<MFXVideoUSER> m_pUserDecoderModule;
3943+ std::unique_ptr<MFXVideoUSER> m_pUserEncoderModule;
3944+ std::unique_ptr<MFXVideoUSER> m_pUserEncModule;
3945+ std::unique_ptr<MFXPlugin> m_pUserDecoderPlugin;
3946+ std::unique_ptr<MFXPlugin> m_pUserEncoderPlugin;
3947+ std::unique_ptr<MFXPlugin> m_pUserEncPlugin;
3948+#endif //!MFX_ONEVPL
3949+ mfxFrameAllocResponse m_mfxDecResponse; // memory allocation response for decoder
3950+ mfxFrameAllocResponse m_mfxEncResponse; // memory allocation response for encoder
3951+
3952+ MFXFrameAllocator *m_pMFXAllocator;
3953+ void *m_hdl; // Diret3D device manager
3954+ bool m_bIsInterOrJoined;
3955+
3956+ mfxU32 m_numEncoders;
3957+ mfxU32 m_encoderFourCC;
3958+
3959+ CSmplYUVWriter m_dumpVppCompFileWriter;
3960+ mfxU32 m_vppCompDumpRenderMode;
3961+
3962+#if defined(_WIN32) || defined(_WIN64)
3963+ CDecodeD3DRender *m_hwdev4Rendering;
3964+#else
3965+ CHWDevice *m_hwdev4Rendering;
3966+#endif
3967+
3968+ typedef std::vector<mfxFrameSurface1 *> SurfPointersArray;
3969+ SurfPointersArray m_pSurfaceDecPool;
3970+ SurfPointersArray m_pSurfaceEncPool;
3971+ mfxU16 m_EncSurfaceType; // actual type of encoder surface pool
3972+ mfxU16 m_DecSurfaceType; // actual type of decoder surface pool
3973+
3974+ typedef std::vector<PreEncAuxBuffer> PreEncAuxArray;
3975+ PreEncAuxArray m_pPreEncAuxPool;
3976+
3977+ // transcoding pipeline specific
3978+ typedef std::list<ExtendedBS *> BSList;
3979+ BSList m_BSPool;
3980+
3981+ mfxInitParamlWrap m_initPar;
3982+
3983+ volatile bool m_bForceStop;
3984+
3985+ sPluginParams m_decoderPluginParams;
3986+ sPluginParams m_encoderPluginParams;
3987+
3988+ MfxVideoParamsWrapper m_mfxDecParams;
3989+ MfxVideoParamsWrapper m_mfxEncParams;
3990+ MfxVideoParamsWrapper m_mfxVppParams;
3991+ MfxVideoParamsWrapper m_mfxPluginParams;
3992+ bool m_bIsVpp; // true if there's VPP in the pipeline
3993+ bool m_bIsFieldWeaving;
3994+ bool m_bIsFieldSplitting;
3995+ bool m_bIsPlugin; //true if there's Plugin in the pipeline
3996+ RotateParam m_RotateParam;
3997+ MfxVideoParamsWrapper m_mfxPreEncParams;
3998+ mfxU32 m_nTimeout;
3999+ bool m_bUseOverlay;
4000+
4001+ bool m_bROIasQPMAP;
4002+ bool m_bExtMBQP;
4003+ // various external buffers
4004+ bool
4005+ m_bOwnMVCSeqDescMemory; // true if the pipeline owns memory allocated for MVCSeqDesc structure fields
4006+
4007+ // to enable to-do list
4008+ // number of video enhancement filters (denoise, procamp, detail, video_analysis, multi_view, ste, istab, tcc, ace, svc)
4009+ constexpr static uint32_t ENH_FILTERS_COUNT = 20;
4010+ mfxU32 m_tabDoUseAlg[ENH_FILTERS_COUNT];
4011+
4012+ mfxU32 m_nID;
4013+ mfxU16 m_AsyncDepth;
4014+ mfxU32 m_nProcessedFramesNum;
4015+
4016+ bool m_bIsJoinSession;
4017+
4018+ bool m_bDecodeEnable;
4019+ bool m_bEncodeEnable;
4020+ mfxU32 m_nVPPCompEnable;
4021+ mfxI32 m_libvaBackend;
4022+
4023+ mfxU16 m_MemoryModel;
4024+
4025+ mfxSyncPoint m_LastDecSyncPoint;
4026+
4027+ SafetySurfaceBuffer *m_pBuffer;
4028+ CTranscodingPipeline *m_pParentPipeline;
4029+
4030+ mfxFrameAllocRequest m_Request;
4031+ bool m_bIsInit;
4032+
4033+ mfxU32 m_NumFramesForReset;
4034+ std::mutex m_mReset;
4035+ std::mutex m_mStopSession;
4036+ bool m_bRobustFlag;
4037+ bool m_bSoftGpuHangRecovery;
4038+
4039+ bool isHEVCSW;
4040+
4041+ bool m_bInsertIDR;
4042+
4043+ bool m_rawInput;
4044+
4045+ std::unique_ptr<ExtendedBSStore> m_pBSStore;
4046+
4047+ mfxU32 m_FrameNumberPreference;
4048+ mfxU32 m_MaxFramesForTranscode;
4049+
4050+ // pointer to already extended bs processor
4051+ FileBitstreamProcessor *m_pBSProcessor;
4052+
4053+ msdk_tick m_nReqFrameTime; // time required to transcode one frame
4054+
4055+ mfxU32 statisticsWindowSize; // Sliding window size for Statistics
4056+ mfxU32 m_nOutputFramesNum;
4057+
4058+ CIOStat inputStatistics;
4059+ CIOStat outputStatistics;
4060+
4061+ bool shouldUseGreedyFormula;
4062+
4063+#if MFX_VERSION >= 1022
4064+ // ROI data
4065+ std::vector<mfxExtEncoderROI> m_ROIData;
4066+ mfxU32 m_nSubmittedFramesNum;
4067+
4068+ // ROI with MBQP map data
4069+ bool m_bUseQPMap;
4070+
4071+ std::map<void *, mfxExtMBQP> m_bufExtMBQP;
4072+ std::map<void *, std::vector<mfxU8>> m_qpMapStorage;
4073+ std::map<void *, std::vector<mfxExtBuffer *>> m_extBuffPtrStorage;
4074+ std::map<void *, mfxEncodeCtrl> encControlStorage;
4075+
4076+ mfxU32 m_QPmapWidth;
4077+ mfxU32 m_QPmapHeight;
4078+ mfxU32 m_GOPSize;
4079+ mfxU32 m_QPforI;
4080+ mfxU32 m_QPforP;
4081+
4082+ msdk_string m_sGenericPluginPath;
4083+ mfxU16 m_nRotationAngle;
4084+
4085+ msdk_string m_strMfxParamsDumpFile;
4086+
4087+ void FillMBQPBuffer(mfxExtMBQP &qpMap, mfxU16 pictStruct);
4088+#endif //MFX_VERSION >= 1022
4089+
4090+#ifdef ENABLE_MCTF
4091+ sMctfRunTimeParams m_MctfRTParams;
4092+#endif
4093+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
4094+ //Adapter type
4095+ bool bPrefferiGfx;
4096+ bool bPrefferdGfx;
4097+#endif
4098+private:
4099+ DISALLOW_COPY_AND_ASSIGN(CTranscodingPipeline);
4100+};
4101+
4102+struct ThreadTranscodeContext {
4103+ // Pointer to the session's pipeline
4104+ std::unique_ptr<CTranscodingPipeline> pPipeline;
4105+ // Pointer to bitstream handling object
4106+ FileBitstreamProcessor *pBSProcessor = nullptr;
4107+ // Session implementation type
4108+ mfxIMPL implType = MFX_IMPL_AUTO;
4109+
4110+ // Session's starting status
4111+ mfxStatus startStatus = MFX_ERR_NONE;
4112+ // Session's working time
4113+ mfxF64 working_time = 0;
4114+
4115+ // Number of processed frames
4116+ mfxU32 numTransFrames = 0;
4117+ // Status of the finished session
4118+ mfxStatus transcodingSts = MFX_ERR_NONE;
4119+
4120+ // Thread handle
4121+ std::future<void> handle;
4122+
4123+ void TranscodeRoutine() {
4124+ using namespace std::chrono;
4125+ MSDK_CHECK_POINTER_NO_RET(pPipeline);
4126+ transcodingSts = MFX_ERR_NONE;
4127+
4128+ auto start_time = system_clock::now();
4129+ while (MFX_ERR_NONE == transcodingSts) {
4130+ transcodingSts = pPipeline->Run();
4131+ }
4132+ working_time = duration_cast<duration<mfxF64>>(system_clock::now() - start_time).count();
4133+
4134+ MSDK_IGNORE_MFX_STS(transcodingSts, MFX_WRN_VALUE_NOT_CHANGED);
4135+ numTransFrames = pPipeline->GetProcessFrames();
4136+ }
4137+};
4138+} // namespace TranscodingSample
4139+
4140+#endif
4141diff --git a/tools/legacy/sample_multi_transcode/include/sample_multi_transcode.h b/tools/legacy/sample_multi_transcode/include/sample_multi_transcode.h
4142new file mode 100644
4143index 0000000..7bba85a
4144--- /dev/null
4145+++ b/tools/legacy/sample_multi_transcode/include/sample_multi_transcode.h
4146@@ -0,0 +1,109 @@
4147+/******************************************************************************\
4148+Copyright (c) 2005-2019, Intel Corporation
4149+All rights reserved.
4150+
4151+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4152+
4153+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
4154+
4155+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.
4156+
4157+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.
4158+
4159+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.
4160+
4161+This sample was distributed or derived from the Intel's Media Samples package.
4162+The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
4163+or https://software.intel.com/en-us/media-client-solutions-support.
4164+\**********************************************************************************/
4165+
4166+#ifndef __SAMPLE_MULTI_TRANSCODE_H__
4167+#define __SAMPLE_MULTI_TRANSCODE_H__
4168+
4169+#include "mfxdefs.h"
4170+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
4171+ #include "mfxadapter.h"
4172+#endif
4173+
4174+#include "pipeline_transcode.h"
4175+#include "sample_utils.h"
4176+#include "transcode_utils.h"
4177+#include "vpl_implementation_loader.h"
4178+
4179+#include "d3d11_allocator.h"
4180+#include "d3d11_device.h"
4181+#include "d3d_allocator.h"
4182+#include "d3d_device.h"
4183+#include "general_allocator.h"
4184+#include "hw_device.h"
4185+
4186+#ifdef LIBVA_SUPPORT
4187+ #include "vaapi_allocator.h"
4188+ #include "vaapi_device.h"
4189+ #include "vaapi_utils.h"
4190+#endif
4191+
4192+#ifndef MFX_VERSION
4193+ #error MFX_VERSION not defined
4194+#endif
4195+
4196+namespace TranscodingSample {
4197+class Launcher {
4198+public:
4199+ Launcher();
4200+ virtual ~Launcher();
4201+
4202+ virtual mfxStatus Init(int argc, msdk_char *argv[]);
4203+ virtual void Run();
4204+ virtual mfxStatus ProcessResult();
4205+
4206+protected:
4207+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
4208+ mfxStatus QueryAdapters();
4209+ void ForceImplForSession(mfxU32 idxSession);
4210+ mfxStatus CheckAndFixAdapterDependency(mfxU32 idxSession,
4211+ CTranscodingPipeline *pParentPipeline);
4212+#endif
4213+ virtual mfxStatus VerifyCrossSessionsOptions();
4214+ virtual mfxStatus CreateSafetyBuffers();
4215+ virtual void DoTranscoding();
4216+ virtual void DoRobustTranscoding();
4217+
4218+ virtual void Close();
4219+
4220+ // command line parser
4221+ CmdProcessor m_parser;
4222+ // threads contexts to process playlist
4223+ std::vector<std::unique_ptr<ThreadTranscodeContext>> m_pThreadContextArray;
4224+ // allocator for each session
4225+ std::vector<std::unique_ptr<GeneralAllocator>> m_pAllocArray;
4226+ // input parameters for each session
4227+ std::vector<sInputParams> m_InputParamsArray;
4228+ // safety buffers
4229+ // needed for heterogeneous pipeline
4230+ std::vector<std::unique_ptr<SafetySurfaceBuffer>> m_pBufferArray;
4231+
4232+ std::vector<std::unique_ptr<FileBitstreamProcessor>> m_pExtBSProcArray;
4233+ std::vector<std::shared_ptr<mfxAllocatorParams>> m_pAllocParams;
4234+ std::vector<std::unique_ptr<CHWDevice>> m_hwdevs;
4235+ msdk_tick m_StartTime;
4236+ // need to work with HW pipeline
4237+ mfxHandleType m_eDevType;
4238+ mfxAccelerationMode m_accelerationMode;
4239+ mfxU32 m_adapterNum;
4240+ mfxU16 m_deviceID;
4241+ std::unique_ptr<VPLImplementationLoader> m_pLoader;
4242+
4243+ std::vector<sVppCompDstRect> m_VppDstRects;
4244+
4245+private:
4246+ DISALLOW_COPY_AND_ASSIGN(Launcher);
4247+
4248+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
4249+ std::vector<mfxAdapterInfo> m_DisplaysData;
4250+ mfxAdaptersInfo m_Adapters;
4251+#endif
4252+};
4253+} // namespace TranscodingSample
4254+
4255+#endif
4256diff --git a/tools/legacy/sample_multi_transcode/include/transcode_utils.h b/tools/legacy/sample_multi_transcode/include/transcode_utils.h
4257new file mode 100644
4258index 0000000..f69aebe
4259--- /dev/null
4260+++ b/tools/legacy/sample_multi_transcode/include/transcode_utils.h
4261@@ -0,0 +1,111 @@
4262+/******************************************************************************\
4263+Copyright (c) 2005-2019, Intel Corporation
4264+All rights reserved.
4265+
4266+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4267+
4268+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
4269+
4270+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.
4271+
4272+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.
4273+
4274+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.
4275+
4276+This sample was distributed or derived from the Intel's Media Samples package.
4277+The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
4278+or https://software.intel.com/en-us/media-client-solutions-support.
4279+\**********************************************************************************/
4280+
4281+#ifndef __TRANSCODE_UTILS_H__
4282+#define __TRANSCODE_UTILS_H__
4283+
4284+#if defined(_WIN32) || defined(_WIN64)
4285+ #include <process.h>
4286+ #pragma warning(disable : 4201)
4287+ #include <d3d9.h>
4288+ #include <dxva2api.h>
4289+#endif
4290+
4291+#include <map>
4292+#include <vector>
4293+#include "pipeline_transcode.h"
4294+
4295+struct D3DAllocatorParams;
4296+
4297+#ifdef _MSC_VER
4298+ #pragma warning(disable : 4127) // constant expression
4299+#endif
4300+
4301+// Extensions for internal use, normally these macros are blank
4302+#ifdef MOD_SMT
4303+ #include "extension_macros.h"
4304+#else
4305+ #define MOD_SMT_CREATE_PIPELINE
4306+ #define MOD_SMT_PRINT_HELP
4307+ #define MOD_SMT_PARSE_INPUT
4308+#endif
4309+
4310+#ifndef MFX_VERSION
4311+ #error MFX_VERSION not defined
4312+#endif
4313+
4314+namespace TranscodingSample {
4315+struct sInputParams;
4316+
4317+msdk_tick GetTick();
4318+mfxF64 GetTime(msdk_tick start);
4319+
4320+void PrintHelp();
4321+void PrintError(const msdk_char *strErrorMessage, ...);
4322+void PrintInfo(mfxU32 session_number, sInputParams *pParams, mfxVersion *pVer);
4323+
4324+bool PrintDllInfo(msdk_char *buf, mfxU32 buf_size, sInputParams *pParams);
4325+
4326+class CmdProcessor {
4327+public:
4328+ CmdProcessor();
4329+ virtual ~CmdProcessor();
4330+ mfxStatus ParseCmdLine(int argc, msdk_char *argv[]);
4331+ bool GetNextSessionParams(TranscodingSample::sInputParams &InputParams);
4332+ FILE *GetPerformanceFile() {
4333+ return m_PerfFILE;
4334+ };
4335+ void PrintParFileName();
4336+ msdk_string GetLine(mfxU32 n);
4337+
4338+protected:
4339+ mfxStatus ParseParFile(FILE *file);
4340+ mfxStatus TokenizeLine(msdk_char *pLine, mfxU32 length);
4341+ mfxU32 GetStringLength(msdk_char *pTempLine, mfxU32 length);
4342+
4343+#if MFX_VERSION >= 1022
4344+ static bool isspace(char a);
4345+ static bool is_not_allowed_char(char a);
4346+ bool ParseROIFile(msdk_char const *roi_file_name, std::vector<mfxExtEncoderROI> &m_ROIData);
4347+#endif //MFX_VERSION >= 1022
4348+
4349+ mfxStatus ParseParamsForOneSession(mfxU32 argc, msdk_char *argv[]);
4350+ mfxStatus ParseOption__set(msdk_char *strCodecType, msdk_char *strPluginPath);
4351+ mfxStatus VerifyAndCorrectInputParams(TranscodingSample::sInputParams &InputParams);
4352+ mfxU32 m_SessionParamId;
4353+ std::vector<TranscodingSample::sInputParams> m_SessionArray;
4354+ std::map<mfxU32, sPluginParams> m_decoderPlugins;
4355+ std::map<mfxU32, sPluginParams> m_encoderPlugins;
4356+ FILE *m_PerfFILE;
4357+ msdk_char *m_parName;
4358+ mfxU32 statisticsWindowSize;
4359+ FILE *statisticsLogFile;
4360+ //store a name of a Logfile
4361+ msdk_tstring DumpLogFileName;
4362+ mfxU32 m_nTimeout;
4363+ bool bRobustFlag;
4364+ bool bSoftRobustFlag;
4365+ bool shouldUseGreedyFormula;
4366+ std::vector<msdk_string> m_lines;
4367+
4368+private:
4369+ DISALLOW_COPY_AND_ASSIGN(CmdProcessor);
4370+};
4371+} // namespace TranscodingSample
4372+#endif //__TRANSCODE_UTILS_H__
4373diff --git a/tools/legacy/sample_multi_transcode/src/pipeline_transcode.cpp b/tools/legacy/sample_multi_transcode/src/pipeline_transcode.cpp
4374new file mode 100644
4375index 0000000..5815df1
4376--- /dev/null
4377+++ b/tools/legacy/sample_multi_transcode/src/pipeline_transcode.cpp
4378@@ -0,0 +1,4668 @@
4379+/******************************************************************************\
4380+Copyright (c) 2005-2020, Intel Corporation
4381+All rights reserved.
4382+
4383+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4384+
4385+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
4386+
4387+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.
4388+
4389+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.
4390+
4391+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.
4392+
4393+This sample was distributed or derived from the Intel's Media Samples package.
4394+The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
4395+or https://software.intel.com/en-us/media-client-solutions-support.
4396+\**********************************************************************************/
4397+
4398+#include "mfx_samples_config.h"
4399+
4400+#if defined(_WIN32) || defined(_WIN64)
4401+ #include <windows.h>
4402+#endif
4403+
4404+#include "mfxdispatcher.h"
4405+#include "pipeline_transcode.h"
4406+#include "sample_utils.h"
4407+#include "transcode_utils.h"
4408+#if !defined(MFX_ONEVPL)
4409+ #include "mfx_vpp_plugin.h"
4410+#endif
4411+#include <assert.h>
4412+#include <algorithm>
4413+#include <cstring>
4414+#include "mfx_itt_trace.h"
4415+
4416+#include "parameters_dumper.h"
4417+
4418+#include "sample_utils.h"
4419+
4420+// let's use std::max and std::min instead
4421+#undef max
4422+#undef min
4423+
4424+#ifndef MFX_VERSION
4425+ #error MFX_VERSION not defined
4426+#endif
4427+
4428+using namespace TranscodingSample;
4429+
4430+#ifdef ENABLE_MCTF
4431+namespace TranscodingSample {
4432+const sMctfRunTimeParam *sMctfRunTimeParams::GetCurParam() {
4433+ if (CurIdx >= RunTimeParams.size())
4434+ return NULL;
4435+ else
4436+ return &(RunTimeParams[CurIdx]);
4437+}
4438+
4439+void sMctfRunTimeParams::MoveForward() {
4440+ if (CurIdx < RunTimeParams.size())
4441+ ++CurIdx;
4442+}
4443+
4444+void sMctfRunTimeParams::Restart() {
4445+ CurIdx = 0;
4446+}
4447+
4448+void sMctfRunTimeParams::Reset() {
4449+ CurIdx = 0;
4450+ RunTimeParams.clear();
4451+}
4452+} // namespace TranscodingSample
4453+#endif
4454+
4455+mfxFrameInfo GetFrameInfo(const MfxVideoParamsWrapper &param) {
4456+ mfxFrameInfo frameInfo = param.mfx.FrameInfo;
4457+ auto decPostProc = param.GetExtBuffer<mfxExtDecVideoProcessing>();
4458+ if (decPostProc) {
4459+ frameInfo.Width = decPostProc->Out.Width;
4460+ frameInfo.Height = decPostProc->Out.Height;
4461+ frameInfo.CropW = decPostProc->Out.CropW;
4462+ frameInfo.CropH = decPostProc->Out.CropH;
4463+ }
4464+
4465+ return frameInfo;
4466+}
4467+
4468+// set structure to define values
4469+sInputParams::sInputParams() : __sInputParams() {
4470+#ifdef ENABLE_MCTF
4471+ mctfParam.mode = VPP_FILTER_DISABLED;
4472+ mctfParam.params.FilterStrength = 0;
4473+ mctfParam.rtParams.Reset();
4474+ #ifdef ENABLE_MCTF_EXT
4475+ mctfParam.params.BitsPerPixelx100k = 0;
4476+ mctfParam.params.Deblocking = MFX_CODINGOPTION_OFF;
4477+ mctfParam.params.Overlap = MFX_CODINGOPTION_OFF;
4478+ mctfParam.params.TemporalMode = MFX_MCTF_TEMPORAL_MODE_2REF;
4479+ mctfParam.params.MVPrecision = MFX_MVPRECISION_INTEGER;
4480+ #endif
4481+#endif
4482+ priority = MFX_PRIORITY_NORMAL;
4483+ libType = MFX_IMPL_SOFTWARE;
4484+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
4485+ //Adapter type
4486+ bPrefferiGfx = false;
4487+ bPrefferdGfx = false;
4488+#endif
4489+ MaxFrameNumber = MFX_INFINITE;
4490+ pVppCompDstRects = NULL;
4491+ m_hwdev = NULL;
4492+ DenoiseLevel = -1;
4493+ DetailLevel = -1;
4494+
4495+#if (MFX_VERSION >= 1025)
4496+ MFMode = MFX_MF_DEFAULT;
4497+ numMFEFrames = 0;
4498+ mfeTimeout = 0;
4499+#endif
4500+
4501+#if MFX_VERSION >= 1022
4502+ bDecoderPostProcessing = false;
4503+ bROIasQPMAP = false;
4504+#endif
4505+}
4506+
4507+CTranscodingPipeline::CTranscodingPipeline()
4508+ : m_pmfxBS(NULL),
4509+ m_pMFXAllocator(NULL),
4510+ m_hdl(NULL),
4511+ m_encoderFourCC(0),
4512+ m_vppCompDumpRenderMode(0),
4513+ m_hwdev4Rendering(NULL),
4514+ m_EncSurfaceType(0),
4515+ m_DecSurfaceType(0),
4516+ m_bIsVpp(false),
4517+ m_bIsPlugin(false),
4518+ m_nTimeout(0),
4519+ m_bOwnMVCSeqDescMemory(true),
4520+ m_nID(0),
4521+ m_AsyncDepth(0),
4522+ m_nProcessedFramesNum(0),
4523+ m_bIsJoinSession(false),
4524+ m_bDecodeEnable(true),
4525+ m_bEncodeEnable(true),
4526+ m_nVPPCompEnable(0),
4527+ m_MemoryModel(UNKNOWN_ALLOC),
4528+ m_LastDecSyncPoint(0),
4529+ m_pBuffer(NULL),
4530+ m_pParentPipeline(NULL),
4531+ m_bIsInit(false),
4532+ m_NumFramesForReset(0),
4533+ isHEVCSW(false),
4534+ m_bInsertIDR(false),
4535+ m_rawInput(false),
4536+ m_FrameNumberPreference(0xFFFFFFFF),
4537+ m_MaxFramesForTranscode(0xFFFFFFFF),
4538+ m_pBSProcessor(NULL),
4539+ m_nReqFrameTime(0),
4540+ m_nOutputFramesNum(0),
4541+ shouldUseGreedyFormula(false),
4542+ m_nRotationAngle(0) {
4543+ MSDK_ZERO_MEMORY(m_RotateParam);
4544+ MSDK_ZERO_MEMORY(m_mfxDecResponse);
4545+ MSDK_ZERO_MEMORY(m_mfxEncResponse);
4546+ MSDK_ZERO_MEMORY(m_Request);
4547+
4548+#if MFX_VERSION >= 1022
4549+ m_bUseQPMap = 0;
4550+ m_QPmapWidth = 0;
4551+ m_QPmapHeight = 0;
4552+ m_GOPSize = 0;
4553+ m_QPforI = 0;
4554+ m_QPforP = 0;
4555+ m_nSubmittedFramesNum = 0;
4556+#endif //MFX_VERSION >= 1022
4557+
4558+ inputStatistics.SetDirection(MSDK_STRING("Input"));
4559+ outputStatistics.SetDirection(MSDK_STRING("Output"));
4560+
4561+ m_numEncoders = 0;
4562+ m_encoderFourCC = 0;
4563+ m_libvaBackend = 0;
4564+ statisticsWindowSize = 0;
4565+ m_bIsFieldWeaving = false;
4566+ m_bIsFieldSplitting = false;
4567+ m_bUseOverlay = false;
4568+ m_bForceStop = false;
4569+ m_bIsInterOrJoined = false;
4570+ m_bRobustFlag = false;
4571+ m_bSoftGpuHangRecovery = false;
4572+ m_nRotationAngle = 0;
4573+ m_bROIasQPMAP = false;
4574+ m_bExtMBQP = false;
4575+} //CTranscodingPipeline::CTranscodingPipeline()
4576+
4577+CTranscodingPipeline::~CTranscodingPipeline() {
4578+ Close();
4579+} //CTranscodingPipeline::CTranscodingPipeline()
4580+
4581+mfxStatus CTranscodingPipeline::CheckRequiredAPIVersion(mfxVersion &version,
4582+ sInputParams *pParams) {
4583+ MSDK_CHECK_POINTER(pParams, MFX_ERR_NULL_PTR);
4584+
4585+ if (pParams->bIsMVC && !CheckVersion(&version, MSDK_FEATURE_MVC)) {
4586+ msdk_printf(MSDK_STRING("error: MVC is not supported in the %d.%d API version\n"),
4587+ version.Major,
4588+ version.Minor);
4589+ return MFX_ERR_UNSUPPORTED;
4590+ }
4591+ if ((pParams->DecodeId == MFX_CODEC_JPEG) &&
4592+ !CheckVersion(&version, MSDK_FEATURE_JPEG_DECODE)) {
4593+ msdk_printf(MSDK_STRING("error: Jpeg decoder is not supported in the %d.%d API version\n"),
4594+ version.Major,
4595+ version.Minor);
4596+ return MFX_ERR_UNSUPPORTED;
4597+ }
4598+ if ((pParams->EncodeId == MFX_CODEC_JPEG) &&
4599+ !CheckVersion(&version, MSDK_FEATURE_JPEG_ENCODE)) {
4600+ msdk_printf(MSDK_STRING("error: Jpeg encoder is not supported in the %d.%d API version\n"),
4601+ version.Major,
4602+ version.Minor);
4603+ return MFX_ERR_UNSUPPORTED;
4604+ }
4605+
4606+ if ((pParams->bLABRC || pParams->nLADepth) &&
4607+ !CheckVersion(&version, MSDK_FEATURE_LOOK_AHEAD)) {
4608+ msdk_printf(MSDK_STRING("error: Look Ahead is not supported in the %d.%d API version\n"),
4609+ version.Major,
4610+ version.Minor);
4611+ return MFX_ERR_UNSUPPORTED;
4612+ }
4613+
4614+ return MFX_ERR_NONE;
4615+}
4616+
4617+// initialize decode part
4618+mfxStatus CTranscodingPipeline::DecodePreInit(sInputParams *pParams) {
4619+ // initialize decode pert
4620+ mfxStatus sts = MFX_ERR_NONE;
4621+
4622+ if (m_bDecodeEnable) {
4623+#if !defined(MFX_ONEVPL)
4624+ if (CheckVersion(&m_Version, MSDK_FEATURE_PLUGIN_API)) {
4625+ /* Here we actually define the following codec initialization scheme:
4626+ * 1. If plugin path or guid is specified: we load user-defined plugin (example: VP9 sample decoder plugin)
4627+ * 2. If plugin path not specified:
4628+ * 2.a) we check if codec is distributed as a mediasdk plugin and load it if yes
4629+ * 2.b) if codec is not in the list of mediasdk plugins, we assume, that it is supported inside mediasdk library
4630+ */
4631+ if (pParams->decoderPluginParams.type == MFX_PLUGINLOAD_TYPE_FILE &&
4632+ msdk_strnlen(pParams->decoderPluginParams.strPluginPath,
4633+ sizeof(pParams->decoderPluginParams.strPluginPath))) {
4634+ m_pUserDecoderModule.reset(new MFXVideoUSER(*m_pmfxSession.get()));
4635+ m_pUserDecoderPlugin.reset(LoadPlugin(
4636+ MFX_PLUGINTYPE_VIDEO_DECODE,
4637+ *m_pmfxSession.get(),
4638+ pParams->decoderPluginParams.pluginGuid,
4639+ 1,
4640+ pParams->decoderPluginParams.strPluginPath,
4641+ (mfxU32)msdk_strnlen(pParams->decoderPluginParams.strPluginPath,
4642+ sizeof(pParams->decoderPluginParams.strPluginPath))));
4643+ if (m_pUserDecoderPlugin.get() == NULL)
4644+ sts = MFX_ERR_UNSUPPORTED;
4645+ }
4646+ else {
4647+ bool isDefaultPlugin = false;
4648+ if (AreGuidsEqual(pParams->decoderPluginParams.pluginGuid, MSDK_PLUGINGUID_NULL)) {
4649+ pParams->decoderPluginParams.pluginGuid =
4650+ msdkGetPluginUID(pParams->libType, MSDK_VDECODE, pParams->DecodeId);
4651+ isDefaultPlugin = true;
4652+ }
4653+ if (!AreGuidsEqual(pParams->decoderPluginParams.pluginGuid, MSDK_PLUGINGUID_NULL)) {
4654+ m_pUserDecoderPlugin.reset(LoadPlugin(MFX_PLUGINTYPE_VIDEO_DECODE,
4655+ *m_pmfxSession.get(),
4656+ pParams->decoderPluginParams.pluginGuid,
4657+ 1));
4658+ if (m_pUserDecoderPlugin.get() == NULL)
4659+ sts = MFX_ERR_UNSUPPORTED;
4660+ }
4661+ if (sts == MFX_ERR_UNSUPPORTED) {
4662+ msdk_printf(
4663+ isDefaultPlugin
4664+ ? MSDK_STRING(
4665+ "Default plugin cannot be loaded (possibly you have to define plugin explicitly)\n")
4666+ : MSDK_STRING("Explicitly specified plugin cannot be loaded.\n"));
4667+ }
4668+ }
4669+ MSDK_CHECK_STATUS(sts, "LoadPlugin failed");
4670+ }
4671+#endif //!MFX_ONEVPL
4672+
4673+ // create decoder
4674+ if (!m_bUseOverlay) {
4675+ m_pmfxDEC.reset(new MFXVideoDECODE(*m_pmfxSession.get()));
4676+ }
4677+
4678+ // set video type in parameters
4679+ m_mfxDecParams.mfx.CodecId = pParams->DecodeId;
4680+
4681+ // configure specific decoder parameters
4682+ sts = InitDecMfxParams(pParams);
4683+ if (MFX_ERR_MORE_DATA == sts) {
4684+ m_pmfxDEC.reset(NULL);
4685+ return sts;
4686+ }
4687+ else {
4688+ MSDK_CHECK_STATUS(sts, "InitDecMfxParams failed");
4689+ }
4690+ }
4691+#if !defined(MFX_ONEVPL)
4692+ else {
4693+ m_mfxDecParams = m_pParentPipeline->GetDecodeParam();
4694+ auto mvc = m_mfxDecParams.AddExtBuffer<mfxExtMVCSeqDesc>();
4695+ *mvc = m_pParentPipeline->GetDecMVCSeqDesc();
4696+ m_bOwnMVCSeqDescMemory = false;
4697+ }
4698+#endif
4699+
4700+ if (pParams->nFPS) {
4701+ this->m_nReqFrameTime = 1000000 / pParams->nFPS;
4702+ }
4703+
4704+ return sts;
4705+
4706+} //mfxStatus CTranscodingPipeline::Init(sInputParams *pParams)
4707+
4708+mfxStatus CTranscodingPipeline::VPPPreInit(sInputParams *pParams) {
4709+ mfxStatus sts = MFX_ERR_NONE;
4710+ bool bVppCompInitRequire = false;
4711+ m_bIsFieldWeaving = false;
4712+ m_bIsFieldSplitting = false;
4713+
4714+ if (((pParams->eModeExt == VppComp) || (pParams->eModeExt == VppCompOnly)) &&
4715+ (pParams->eMode == Source))
4716+ bVppCompInitRequire = true;
4717+
4718+ // Obtaining decoder output FourCC - in case of inter-session, just take it from params, in intra-session case, take it from parent session
4719+ // In inter-session case, we'll enable chroma-changing VPP only in encoding session, and only if decoderFourCC!=encoderFourCC
4720+ mfxU32 decoderFourCC = m_bDecodeEnable
4721+ ? m_mfxDecParams.mfx.FrameInfo.FourCC
4722+ : m_pParentPipeline->GetDecodeParam().mfx.FrameInfo.FourCC;
4723+
4724+ if (m_bEncodeEnable || m_bDecodeEnable) {
4725+ if (m_mfxDecParams.mfx.FrameInfo.PicStruct == MFX_PICSTRUCT_FIELD_SINGLE &&
4726+ pParams->EncodeId != MFX_CODEC_HEVC && !pParams->bEnableDeinterlacing) {
4727+ m_bIsFieldWeaving = true;
4728+ m_bIsVpp = true;
4729+ }
4730+
4731+ if ((m_mfxDecParams.mfx.FrameInfo.PicStruct & MFX_PICSTRUCT_FIELD_TFF ||
4732+ m_mfxDecParams.mfx.FrameInfo.PicStruct & MFX_PICSTRUCT_FIELD_BFF ||
4733+ m_mfxDecParams.mfx.FrameInfo.PicStruct == MFX_PICSTRUCT_UNKNOWN) &&
4734+ pParams->EncodeId == MFX_CODEC_HEVC && pParams->DecodeId != MFX_CODEC_HEVC &&
4735+ !pParams->bEnableDeinterlacing) {
4736+ m_bIsFieldSplitting = true;
4737+ m_bIsVpp = true;
4738+ m_mfxVppParams.vpp.In.PicStruct = MFX_PICSTRUCT_UNKNOWN;
4739+ }
4740+
4741+ if ((GetFrameInfo(m_mfxDecParams).CropW != pParams->nDstWidth && pParams->nDstWidth) ||
4742+ (GetFrameInfo(m_mfxDecParams).CropH != pParams->nDstHeight && pParams->nDstHeight) ||
4743+ (pParams->bEnableDeinterlacing) || (pParams->DenoiseLevel != -1) ||
4744+ (pParams->DetailLevel != -1) || (pParams->FRCAlgorithm) || (bVppCompInitRequire) ||
4745+ (pParams->fieldProcessingMode) ||
4746+#ifdef ENABLE_MCTF
4747+ (VPP_FILTER_DISABLED != pParams->mctfParam.mode) ||
4748+#endif
4749+ (pParams->EncoderFourCC && decoderFourCC && pParams->EncoderFourCC != decoderFourCC &&
4750+ m_bEncodeEnable)) {
4751+ if (m_bIsFieldWeaving || m_bIsFieldSplitting) {
4752+ msdk_printf(MSDK_STRING(
4753+ "ERROR: Field weaving or Field Splitting is enabled according to streams parameters. Other VPP filters cannot be used in this mode, please remove corresponding options.\n"));
4754+ return MFX_ERR_UNSUPPORTED;
4755+ }
4756+
4757+ m_bIsVpp = true;
4758+ }
4759+
4760+ if (m_bIsVpp) {
4761+ sts = InitVppMfxParams(pParams);
4762+ MSDK_CHECK_STATUS(sts, "InitVppMfxParams failed");
4763+ }
4764+
4765+#if !defined(MFX_ONEVPL)
4766+ if (pParams->nRotationAngle) // plugin was requested
4767+ {
4768+ m_bIsPlugin = true;
4769+ sts = InitPluginMfxParams(pParams);
4770+ MSDK_CHECK_STATUS(sts, "InitPluginMfxParams failed");
4771+ sts = LoadGenericPlugin();
4772+ MSDK_CHECK_STATUS(sts, "LoadGenericPlugin failed");
4773+ }
4774+#endif //!MFX_ONEVPL
4775+
4776+ if (!m_bIsPlugin && m_bIsVpp) // only VPP was requested
4777+ {
4778+ m_pmfxVPP.reset(new MFXVideoMultiVPP(*m_pmfxSession.get()));
4779+ }
4780+ }
4781+
4782+ return sts;
4783+
4784+} //mfxStatus CTranscodingPipeline::VPPInit(sInputParams *pParams)
4785+
4786+mfxStatus CTranscodingPipeline::EncodePreInit(sInputParams *pParams) {
4787+ mfxStatus sts = MFX_ERR_NONE;
4788+
4789+ if (m_bEncodeEnable) {
4790+ if (pParams->EncodeId != MFX_CODEC_DUMP) {
4791+#if !defined(MFX_ONEVPL)
4792+ if (CheckVersion(&m_Version, MSDK_FEATURE_PLUGIN_API) &&
4793+ (m_pUserEncPlugin.get() == NULL)) {
4794+ /* Here we actually define the following codec initialization scheme:
4795+ * 1. If plugin path or guid is specified: we load user-defined plugin (example: HEVC encoder plugin)
4796+ * 2. If plugin path not specified:
4797+ * 2.a) we check if codec is distributed as a mediasdk plugin and load it if yes
4798+ * 2.b) if codec is not in the list of mediasdk plugins, we assume, that it is supported inside mediasdk library
4799+ */
4800+ if (pParams->encoderPluginParams.type == MFX_PLUGINLOAD_TYPE_FILE &&
4801+ msdk_strnlen(pParams->encoderPluginParams.strPluginPath,
4802+ sizeof(pParams->encoderPluginParams.strPluginPath))) {
4803+ m_pUserEncoderModule.reset(new MFXVideoUSER(*m_pmfxSession.get()));
4804+ m_pUserEncoderPlugin.reset(LoadPlugin(
4805+ MFX_PLUGINTYPE_VIDEO_ENCODE,
4806+ *m_pmfxSession.get(),
4807+ pParams->encoderPluginParams.pluginGuid,
4808+ 1,
4809+ pParams->encoderPluginParams.strPluginPath,
4810+ (mfxU32)msdk_strnlen(pParams->encoderPluginParams.strPluginPath,
4811+ sizeof(pParams->encoderPluginParams.strPluginPath))));
4812+ if (m_pUserEncoderPlugin.get() == NULL)
4813+ sts = MFX_ERR_UNSUPPORTED;
4814+ }
4815+ else {
4816+ bool isDefaultPlugin = false;
4817+ if (AreGuidsEqual(pParams->encoderPluginParams.pluginGuid,
4818+ MSDK_PLUGINGUID_NULL)) {
4819+ pParams->encoderPluginParams.pluginGuid =
4820+ msdkGetPluginUID(pParams->libType, MSDK_VENCODE, pParams->EncodeId);
4821+ isDefaultPlugin = true;
4822+ }
4823+ if (!AreGuidsEqual(pParams->encoderPluginParams.pluginGuid,
4824+ MSDK_PLUGINGUID_NULL)) {
4825+ m_pUserEncoderPlugin.reset(
4826+ LoadPlugin(MFX_PLUGINTYPE_VIDEO_ENCODE,
4827+ *m_pmfxSession.get(),
4828+ pParams->encoderPluginParams.pluginGuid,
4829+ 1));
4830+ if (m_pUserEncoderPlugin.get() == NULL)
4831+ sts = MFX_ERR_UNSUPPORTED;
4832+ }
4833+ if (sts == MFX_ERR_UNSUPPORTED) {
4834+ msdk_printf(
4835+ MSDK_STRING("%s"),
4836+ isDefaultPlugin
4837+ ? MSDK_STRING(
4838+ "Default plugin cannot be loaded (possibly you have to define plugin explicitly)\n")
4839+ : MSDK_STRING("Explicitly specified plugin cannot be loaded.\n"));
4840+ }
4841+ }
4842+ MSDK_CHECK_STATUS(sts, "LoadPlugin failed");
4843+ }
4844+#endif //!MFX_ONEVPL
4845+
4846+ // create encoder
4847+ m_pmfxENC.reset(new MFXVideoENCODE(*m_pmfxSession.get()));
4848+
4849+ if (m_nVPPCompEnable == VppCompOnlyEncode) {
4850+ pParams->EncoderFourCC = MFX_FOURCC_NV12;
4851+ }
4852+
4853+ sts = InitEncMfxParams(pParams);
4854+ MSDK_CHECK_STATUS(sts, "InitEncMfxParams failed");
4855+
4856+ // Querying parameters
4857+ mfxU16 ioPattern = m_mfxEncParams.IOPattern;
4858+ mfxU16 initialTargetKbps = m_mfxEncParams.mfx.TargetKbps;
4859+ auto co2 = m_mfxEncParams.GetExtBuffer<mfxExtCodingOption2>();
4860+
4861+ msdk_stringstream str1, str2;
4862+ CParametersDumper().SerializeVideoParamStruct(str1, MSDK_STRING(""), m_mfxEncParams);
4863+
4864+ sts = m_pmfxENC->Query(&m_mfxEncParams, &m_mfxEncParams);
4865+
4866+ CParametersDumper().SerializeVideoParamStruct(str2, MSDK_STRING(""), m_mfxEncParams);
4867+
4868+ m_mfxEncParams.IOPattern =
4869+ ioPattern; // Workaround for a problem: Query changes IOPattern incorrectly
4870+
4871+ if (sts == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM) {
4872+ if (co2 && co2->BitrateLimit != MFX_CODINGOPTION_OFF &&
4873+ initialTargetKbps != m_mfxEncParams.mfx.TargetKbps) {
4874+ msdk_printf(
4875+ MSDK_STRING("[WARNING] -BitrateLimit:on, target bitrate was changed\n"));
4876+ }
4877+
4878+ msdk_printf(MSDK_STRING("[WARNING] Configuration changed on the Query() call\n"));
4879+
4880+ CParametersDumper().ShowConfigurationDiff(str1, str2);
4881+ MSDK_IGNORE_MFX_STS(sts, MFX_WRN_INCOMPATIBLE_VIDEO_PARAM);
4882+ }
4883+
4884+ MSDK_CHECK_STATUS(sts, "m_pmfxENC->Query failed");
4885+ }
4886+ else {
4887+ //--- This one is required for YUV output
4888+ m_mfxEncParams.mfx.CodecId = pParams->EncodeId;
4889+ }
4890+ }
4891+ return sts;
4892+
4893+} // mfxStatus CTranscodingPipeline::EncodeInit(sInputParams *pParams)
4894+
4895+#if !defined(MFX_ONEVPL)
4896+mfxStatus CTranscodingPipeline::PreEncPreInit(sInputParams *pParams) {
4897+ mfxStatus sts = MFX_ERR_NONE;
4898+ // PreInit is allowed in decoder session only
4899+ if (pParams->bEnableExtLA && m_bDecodeEnable) {
4900+ /* Here we actually define the following codec initialization scheme:
4901+ * a) we check if codec is distributed as a user plugin and load it if yes
4902+ * b) we check if codec is distributed as a mediasdk plugin and load it if yes
4903+ * c) if codec is not in the list of user plugins or mediasdk plugins, we assume, that it is supported inside mediasdk library
4904+ */
4905+
4906+ m_pUserEncPlugin.reset(LoadPlugin(MFX_PLUGINTYPE_VIDEO_ENCODE,
4907+ *m_pmfxSession.get(),
4908+ MFX_PLUGINID_H264LA_HW,
4909+ 1));
4910+ if (m_pUserEncPlugin.get() == NULL)
4911+ sts = MFX_ERR_UNSUPPORTED;
4912+
4913+ // create encoder
4914+ m_pmfxPreENC.reset(new MFXVideoENC(*m_pmfxSession.get()));
4915+
4916+ sts = InitPreEncMfxParams(pParams);
4917+ MSDK_CHECK_STATUS(sts, "InitPreEncMfxParams failed");
4918+ }
4919+
4920+ return sts;
4921+}
4922+#endif //!MFX_ONEVPL
4923+
4924+mfxVideoParam CTranscodingPipeline::GetDecodeParam() {
4925+ if (m_bIsVpp) {
4926+ mfxVideoParam tmp = m_mfxDecParams;
4927+ tmp.mfx.FrameInfo = m_mfxVppParams.vpp.Out;
4928+ return tmp;
4929+ }
4930+ else if (m_bIsPlugin) {
4931+ mfxVideoParam tmp = m_mfxDecParams;
4932+ tmp.mfx.FrameInfo = m_mfxPluginParams.mfx.FrameInfo;
4933+ return tmp;
4934+ }
4935+
4936+ return m_mfxDecParams;
4937+};
4938+// 1 ms provides better result in range [0..5] ms
4939+enum { TIME_TO_SLEEP = 1 };
4940+
4941+mfxStatus CTranscodingPipeline::DecodeOneFrame(ExtendedSurface *pExtSurface) {
4942+ MFX_ITT_TASK("DecodeOneFrame");
4943+ MSDK_CHECK_POINTER(pExtSurface, MFX_ERR_NULL_PTR);
4944+
4945+ mfxStatus sts = MFX_ERR_MORE_SURFACE;
4946+ mfxFrameSurface1 *pmfxSurface = NULL;
4947+ pExtSurface->pSurface = NULL;
4948+
4949+ //--- Time measurements
4950+ if (statisticsWindowSize) {
4951+ inputStatistics.StopTimeMeasurementWithCheck();
4952+ inputStatistics.StartTimeMeasurement();
4953+ }
4954+
4955+ CTimer DevBusyTimer;
4956+ DevBusyTimer.Start();
4957+ while (MFX_ERR_MORE_DATA == sts || MFX_ERR_MORE_SURFACE == sts || MFX_ERR_NONE < sts) {
4958+ if (m_rawInput) {
4959+ pExtSurface->pSurface = GetFreeSurface(false, MSDK_SURFACE_WAIT_INTERVAL);
4960+ sts = m_pBSProcessor->GetInputFrame(pExtSurface->pSurface);
4961+ if (sts != MFX_ERR_NONE)
4962+ return sts;
4963+ }
4964+ else if (MFX_WRN_DEVICE_BUSY == sts) {
4965+ WaitForDeviceToBecomeFree(*m_pmfxSession, m_LastDecSyncPoint, sts);
4966+ }
4967+ else if (MFX_ERR_MORE_DATA == sts) {
4968+ sts =
4969+ m_pBSProcessor->GetInputBitstream(&m_pmfxBS); // read more data to input bit stream
4970+ MSDK_BREAK_ON_ERROR(sts);
4971+ }
4972+
4973+ if (m_MemoryModel == GENERAL_ALLOC) {
4974+ // Find new working surface
4975+ pmfxSurface = GetFreeSurface(true, MSDK_SURFACE_WAIT_INTERVAL);
4976+ {
4977+ std::unique_lock<std::mutex> lock(m_mStopSession);
4978+ if (m_bForceStop) {
4979+ lock.unlock();
4980+ m_nTimeout = 0;
4981+ // add surfaces in queue for all sinks
4982+ NoMoreFramesSignal();
4983+ return MFX_WRN_VALUE_NOT_CHANGED;
4984+ }
4985+ }
4986+ MSDK_CHECK_POINTER_SAFE(
4987+ pmfxSurface,
4988+ MFX_ERR_MEMORY_ALLOC,
4989+ msdk_printf(MSDK_STRING(
4990+ "ERROR: No free surfaces in decoder pool (during long period)\n"))); // return an error if a free surface wasn't found
4991+ }
4992+#if defined(MFX_ONEVPL)
4993+ else if (m_MemoryModel == VISIBLE_INT_ALLOC) {
4994+ sts = m_pmfxDEC->GetSurface(&pmfxSurface);
4995+ MSDK_BREAK_ON_ERROR(sts);
4996+ }
4997+#endif //MFX_ONEVPL
4998+
4999+ if (!m_rawInput) {
5000+ sts = m_pmfxDEC->DecodeFrameAsync(m_pmfxBS,
5001+ pmfxSurface,
5002+ &pExtSurface->pSurface,
5003+ &pExtSurface->Syncp);
5004+#if defined(MFX_ONEVPL)
5005+ if (m_MemoryModel == VISIBLE_INT_ALLOC) {
5006+ mfxStatus sts_release = pmfxSurface->FrameInterface->Release(pmfxSurface);
5007+ MSDK_CHECK_STATUS(sts_release, "FrameInterface->Release failed");
5008+ }
5009+#endif //MFX_ONEVPL
5010+ }
5011+
5012+ if ((MFX_WRN_DEVICE_BUSY == sts) && (DevBusyTimer.GetTime() > MSDK_WAIT_INTERVAL / 1000)) {
5013+ msdk_printf(MSDK_STRING("ERROR: Decoder device busy (during long period)\n"));
5014+ return MFX_ERR_DEVICE_FAILED;
5015+ }
5016+
5017+ if (sts == MFX_ERR_NONE) {
5018+ m_LastDecSyncPoint = pExtSurface->Syncp;
5019+ }
5020+ // ignore warnings if output is available,
5021+ if (MFX_ERR_NONE < sts && pExtSurface->Syncp) {
5022+ sts = MFX_ERR_NONE;
5023+ }
5024+
5025+ } //while processing
5026+
5027+ // HEVC SW requires additional synchronization
5028+ if (MFX_ERR_NONE == sts && isHEVCSW) {
5029+ sts = m_pmfxSession->SyncOperation(pExtSurface->Syncp, MSDK_WAIT_INTERVAL);
5030+ HandlePossibleGpuHang(sts);
5031+ MSDK_CHECK_ERR_NONE_STATUS(sts, MFX_ERR_ABORTED, "Decode: SyncOperation failed");
5032+ }
5033+ return sts;
5034+
5035+} // mfxStatus CTranscodingPipeline::DecodeOneFrame(ExtendedSurface *pExtSurface)
5036+mfxStatus CTranscodingPipeline::DecodeLastFrame(ExtendedSurface *pExtSurface) {
5037+ MFX_ITT_TASK("DecodeLastFrame");
5038+ mfxFrameSurface1 *pmfxSurface = NULL;
5039+ mfxStatus sts = MFX_ERR_MORE_SURFACE;
5040+
5041+ //--- Time measurements
5042+ if (statisticsWindowSize) {
5043+ inputStatistics.StopTimeMeasurementWithCheck();
5044+ inputStatistics.StartTimeMeasurement();
5045+ }
5046+
5047+ CTimer DevBusyTimer;
5048+ DevBusyTimer.Start();
5049+ // retrieve the buffered decoded frames
5050+ while (MFX_ERR_MORE_SURFACE == sts || MFX_WRN_DEVICE_BUSY == sts) {
5051+ if (m_rawInput) {
5052+ pExtSurface->pSurface = GetFreeSurface(false, MSDK_SURFACE_WAIT_INTERVAL);
5053+ sts = m_pBSProcessor->GetInputFrame(pExtSurface->pSurface);
5054+ }
5055+ else if (MFX_WRN_DEVICE_BUSY == sts) {
5056+ WaitForDeviceToBecomeFree(*m_pmfxSession, m_LastDecSyncPoint, sts);
5057+ }
5058+
5059+ if (!m_rawInput) {
5060+ if (m_MemoryModel == GENERAL_ALLOC) {
5061+ // find new working surface
5062+ pmfxSurface = GetFreeSurface(true, MSDK_SURFACE_WAIT_INTERVAL);
5063+ MSDK_CHECK_POINTER_SAFE(
5064+ pmfxSurface,
5065+ MFX_ERR_MEMORY_ALLOC,
5066+ msdk_printf(MSDK_STRING(
5067+ "ERROR: No free surfaces in decoder pool (during long period)\n"))); // return an error if a free surface wasn't found
5068+
5069+ sts = m_pmfxDEC->DecodeFrameAsync(nullptr,
5070+ pmfxSurface,
5071+ &pExtSurface->pSurface,
5072+ &pExtSurface->Syncp);
5073+ }
5074+#if defined(MFX_ONEVPL)
5075+ else if (m_MemoryModel == VISIBLE_INT_ALLOC) {
5076+ sts = m_pmfxDEC->GetSurface(&pmfxSurface);
5077+ MSDK_BREAK_ON_ERROR(sts);
5078+
5079+ sts = m_pmfxDEC->DecodeFrameAsync(nullptr,
5080+ pmfxSurface,
5081+ &pExtSurface->pSurface,
5082+ &pExtSurface->Syncp);
5083+
5084+ mfxStatus sts_release = pmfxSurface->FrameInterface->Release(pmfxSurface);
5085+ MSDK_CHECK_STATUS(sts_release, "FrameInterface->Release failed");
5086+ }
5087+#endif //MFX_ONEVPL
5088+ else {
5089+ sts = m_pmfxDEC->DecodeFrameAsync(nullptr,
5090+ pmfxSurface,
5091+ &pExtSurface->pSurface,
5092+ &pExtSurface->Syncp);
5093+ }
5094+ }
5095+
5096+ if ((MFX_WRN_DEVICE_BUSY == sts) && (DevBusyTimer.GetTime() > MSDK_WAIT_INTERVAL / 1000)) {
5097+ msdk_printf(MSDK_STRING("ERROR: Decoder device busy (during long period)\n"));
5098+ return MFX_ERR_DEVICE_FAILED;
5099+ }
5100+ }
5101+
5102+ // HEVC SW requires additional synchronization
5103+ if (MFX_ERR_NONE == sts && isHEVCSW) {
5104+ sts = m_pmfxSession->SyncOperation(pExtSurface->Syncp, MSDK_WAIT_INTERVAL);
5105+ HandlePossibleGpuHang(sts);
5106+ MSDK_CHECK_ERR_NONE_STATUS(sts, MFX_ERR_ABORTED, "Decode: SyncOperation failed");
5107+ }
5108+
5109+ return sts;
5110+}
5111+
5112+mfxStatus CTranscodingPipeline::VPPOneFrame(ExtendedSurface *pSurfaceIn,
5113+ ExtendedSurface *pExtSurface) {
5114+ MFX_ITT_TASK("VPPOneFrame");
5115+ MSDK_CHECK_POINTER(pExtSurface, MFX_ERR_NULL_PTR);
5116+ mfxFrameSurface1 *out_surface = NULL;
5117+ mfxStatus sts = MFX_ERR_NONE;
5118+
5119+ if (m_MemoryModel == GENERAL_ALLOC || m_MemoryModel == VISIBLE_INT_ALLOC) {
5120+ if (m_MemoryModel == GENERAL_ALLOC) {
5121+ // find/wait for a free working surface
5122+ out_surface = GetFreeSurface(false, MSDK_SURFACE_WAIT_INTERVAL);
5123+ MSDK_CHECK_POINTER_SAFE(
5124+ out_surface,
5125+ MFX_ERR_MEMORY_ALLOC,
5126+ msdk_printf(MSDK_STRING(
5127+ "ERROR: No free surfaces for VPP in encoder pool (during long period)\n"))); // return an error if a free surface wasn't found
5128+ }
5129+#if defined(MFX_ONEVPL)
5130+ else if (m_MemoryModel == VISIBLE_INT_ALLOC) {
5131+ sts = m_pmfxVPP->GetSurfaceOut(&out_surface);
5132+ MFX_CHECK_STS(sts);
5133+ }
5134+#endif //MFX_ONEVPL
5135+
5136+ // make sure picture structure has the initial value
5137+ // surfaces are reused and VPP may change this parameter in certain configurations
5138+ out_surface->Info.PicStruct =
5139+ m_mfxVppParams.vpp.Out.PicStruct
5140+ ? m_mfxVppParams.vpp.Out.PicStruct
5141+ : (m_bEncodeEnable ? m_mfxEncParams : m_mfxDecParams).mfx.FrameInfo.PicStruct;
5142+ pExtSurface->pSurface = out_surface;
5143+ }
5144+
5145+#ifdef ENABLE_MCTF
5146+ const auto MCTFCurParam = m_MctfRTParams.GetCurParam();
5147+ bool applyMCTF = !!MCTFCurParam;
5148+
5149+ if (applyMCTF && pSurfaceIn->pSurface) {
5150+ auto surface = static_cast<mfxFrameSurfaceWrap *>(pSurfaceIn->pSurface);
5151+
5152+ auto mctf = surface->AddExtBuffer<mfxExtVppMctf>();
5153+ mctf->FilterStrength = MCTFCurParam->FilterStrength;
5154+ #if defined ENABLE_MCTF_EXT
5155+ mctf->BitsPerPixelx100k = mfxU32(MCTF_LOSSLESS_BPP * MCTF_BITRATE_MULTIPLIER);
5156+ mctf->Deblocking = MFX_CODINGOPTION_OFF;
5157+ #endif
5158+ m_MctfRTParams.MoveForward();
5159+ }
5160+#endif
5161+
5162+ for (;;) {
5163+ if (m_MemoryModel == GENERAL_ALLOC || m_MemoryModel == VISIBLE_INT_ALLOC) {
5164+ sts = m_pmfxVPP->RunFrameVPPAsync(pSurfaceIn->pSurface,
5165+ out_surface,
5166+ NULL,
5167+ &pExtSurface->Syncp);
5168+ }
5169+#if defined(MFX_ONEVPL)
5170+ else {
5171+ sts = m_pmfxVPP->ProcessFrameAsync(pSurfaceIn->pSurface, &pExtSurface->pSurface);
5172+ }
5173+#endif
5174+
5175+ if (MFX_ERR_NONE < sts) {
5176+ if ((m_MemoryModel != HIDDEN_INT_ALLOC && !pExtSurface->Syncp) ||
5177+ (m_MemoryModel == HIDDEN_INT_ALLOC &&
5178+ !out_surface)) // repeat the call if warning and no output
5179+ {
5180+ if (MFX_WRN_DEVICE_BUSY == sts)
5181+ MSDK_SLEEP(1); // wait if device is busy
5182+ }
5183+ else {
5184+ sts = MFX_ERR_NONE; // ignore warnings if output is available
5185+ break;
5186+ }
5187+ }
5188+ else {
5189+ break;
5190+ }
5191+ }
5192+
5193+ return sts;
5194+
5195+} // mfxStatus CTranscodingPipeline::DecodeOneFrame(ExtendedSurface *pExtSurface)
5196+
5197+mfxStatus CTranscodingPipeline::EncodeOneFrame(ExtendedSurface *pExtSurface,
5198+ mfxBitstreamWrapper *pBS) {
5199+ mfxStatus sts = MFX_ERR_NONE;
5200+
5201+ if (!pBS->Data) {
5202+ sts = AllocateSufficientBuffer(pBS);
5203+ MSDK_CHECK_STATUS(sts, "AllocateSufficientBuffer failed");
5204+ }
5205+
5206+ for (;;) {
5207+ // at this point surface for encoder contains either a frame from file or a frame processed by vpp
5208+ sts = m_pmfxENC->EncodeFrameAsync(pExtSurface->pEncCtrl,
5209+ pExtSurface->pSurface,
5210+ pBS,
5211+ &pExtSurface->Syncp);
5212+
5213+ if (MFX_ERR_NONE < sts && !pExtSurface->Syncp) // repeat the call if warning and no output
5214+ {
5215+ if (MFX_WRN_DEVICE_BUSY == sts)
5216+ MSDK_SLEEP(TIME_TO_SLEEP); // wait if device is busy
5217+ }
5218+ else if (MFX_ERR_NONE < sts && pExtSurface->Syncp) {
5219+ sts = MFX_ERR_NONE; // ignore warnings if output is available
5220+ break;
5221+ }
5222+ else if (MFX_ERR_NOT_ENOUGH_BUFFER == sts) {
5223+ sts = AllocateSufficientBuffer(pBS);
5224+ MSDK_CHECK_STATUS(sts, "AllocateSufficientBuffer failed");
5225+ }
5226+ else {
5227+ break;
5228+ }
5229+ }
5230+
5231+ return sts;
5232+
5233+} //CTranscodingPipeline::EncodeOneFrame(ExtendedSurface *pExtSurface)
5234+
5235+#if !defined(MFX_ONEVPL)
5236+mfxStatus CTranscodingPipeline::PreEncOneFrame(ExtendedSurface *pInSurface,
5237+ ExtendedSurface *pOutSurface) {
5238+ mfxStatus sts = MFX_ERR_NONE;
5239+ PreEncAuxBuffer *pAux = NULL;
5240+
5241+ for (mfxU32 i = 0; i < MSDK_WAIT_INTERVAL; i += TIME_TO_SLEEP) {
5242+ pAux = GetFreePreEncAuxBuffer();
5243+ if (pAux) {
5244+ break;
5245+ }
5246+ else {
5247+ MSDK_SLEEP(TIME_TO_SLEEP);
5248+ }
5249+ }
5250+ MSDK_CHECK_POINTER(pAux, MFX_ERR_MEMORY_ALLOC);
5251+ for (;;) {
5252+ pAux->encInput.InSurface = pInSurface->pSurface;
5253+ // at this point surface for encoder contains either a frame from file or a frame processed by vpp
5254+ sts =
5255+ m_pmfxPreENC->ProcessFrameAsync(&pAux->encInput, &pAux->encOutput, &pOutSurface->Syncp);
5256+
5257+ if (MFX_ERR_NONE < sts && !pOutSurface->Syncp) // repeat the call if warning and no output
5258+ {
5259+ if (MFX_WRN_DEVICE_BUSY == sts)
5260+ MSDK_SLEEP(TIME_TO_SLEEP); // wait if device is busy
5261+ }
5262+ else if (MFX_ERR_NONE <= sts && pOutSurface->Syncp) {
5263+ LockPreEncAuxBuffer(pAux);
5264+ pOutSurface->pAuxCtrl = pAux;
5265+ MSDK_CHECK_POINTER(pAux->encOutput.ExtParam, MFX_ERR_NULL_PTR);
5266+ MSDK_CHECK_NOT_EQUAL(pAux->encOutput.NumExtParam, 1, MFX_ERR_UNSUPPORTED);
5267+ pOutSurface->pSurface =
5268+ ((mfxExtLAFrameStatistics *)pAux->encOutput.ExtParam[0])->OutSurface;
5269+ sts = MFX_ERR_NONE; // ignore warnings if output is available
5270+ break;
5271+ }
5272+ else {
5273+ break;
5274+ }
5275+ }
5276+ return sts;
5277+}
5278+#endif //!MFX_ONEVPL
5279+
5280+// signal that there are no more frames
5281+void CTranscodingPipeline::NoMoreFramesSignal() {
5282+ SafetySurfaceBuffer *pNextBuffer = m_pBuffer;
5283+
5284+ // For transcoding pipelines (PipelineMode::Native) this pointer is null
5285+ if (!pNextBuffer)
5286+ return;
5287+
5288+ ExtendedSurface surf = {};
5289+ pNextBuffer->AddSurface(surf);
5290+
5291+ /*if 1_to_N mode */
5292+ if (0 == m_nVPPCompEnable) {
5293+ while (pNextBuffer->m_pNext) {
5294+ pNextBuffer = pNextBuffer->m_pNext;
5295+ pNextBuffer->AddSurface(surf);
5296+ }
5297+ }
5298+}
5299+
5300+void CTranscodingPipeline::StopSession() {
5301+ std::lock_guard<std::mutex> guard(m_mStopSession);
5302+ m_bForceStop = true;
5303+
5304+ msdk_stringstream ss;
5305+ ss << MSDK_STRING("session [") << GetSessionText() << MSDK_STRING("] m_bForceStop is set")
5306+ << std::endl;
5307+ msdk_printf(MSDK_STRING("%s"), ss.str().c_str());
5308+}
5309+
5310+bool CTranscodingPipeline::IsOverlayUsed() {
5311+ return m_bUseOverlay;
5312+}
5313+
5314+mfxStatus CTranscodingPipeline::Decode() {
5315+ mfxStatus sts = MFX_ERR_NONE;
5316+
5317+ ExtendedSurface DecExtSurface = { 0 };
5318+ ExtendedSurface VppExtSurface = { 0 };
5319+ ExtendedSurface PreEncExtSurface = { 0 };
5320+ bool shouldReadNextFrame = true;
5321+
5322+ SafetySurfaceBuffer *pNextBuffer = m_pBuffer;
5323+ bool bEndOfFile = false;
5324+ bool bLastCycle = false;
5325+ time_t start = time(0);
5326+
5327+ {
5328+ std::unique_lock<std::mutex> lock(m_mStopSession);
5329+ if (m_bForceStop) {
5330+ lock.unlock();
5331+ // add surfaces in queue for all sinks
5332+ NoMoreFramesSignal();
5333+ return MFX_WRN_VALUE_NOT_CHANGED;
5334+ }
5335+ }
5336+
5337+ if (m_bUseOverlay) {
5338+ PreEncExtSurface.pSurface = m_pSurfaceDecPool[0];
5339+
5340+ if (pNextBuffer->GetLength() == 0) {
5341+ // add surfaces in queue for all sinks
5342+ pNextBuffer->AddSurface(PreEncExtSurface);
5343+ m_nProcessedFramesNum++;
5344+ }
5345+ return MFX_ERR_NONE;
5346+ }
5347+
5348+ while (MFX_ERR_NONE == sts) {
5349+ pNextBuffer = m_pBuffer;
5350+
5351+ if (time(0) - start >= m_nTimeout)
5352+ bLastCycle = true;
5353+
5354+ if (bLastCycle)
5355+ SetNumFramesForReset(0);
5356+
5357+ msdk_tick nBeginTime = msdk_time_get_tick(); // microseconds.
5358+
5359+ if (shouldReadNextFrame) {
5360+ if (!bEndOfFile) {
5361+ if (!m_bUseOverlay) {
5362+ sts = DecodeOneFrame(&DecExtSurface);
5363+ if (MFX_ERR_MORE_DATA == sts) {
5364+ sts = bLastCycle ? DecodeLastFrame(&DecExtSurface) : MFX_ERR_MORE_DATA;
5365+ bEndOfFile = bLastCycle ? true : false;
5366+ }
5367+ }
5368+ else {
5369+ // Use preloaded overlay frame
5370+ DecExtSurface.pSurface = m_pSurfaceDecPool[0];
5371+ sts = MFX_ERR_NONE;
5372+ }
5373+ }
5374+ else {
5375+ sts = DecodeLastFrame(&DecExtSurface);
5376+ }
5377+
5378+ if (sts == MFX_ERR_NONE) {
5379+ // print statistics if m_nProcessedFramesNum is multiple of
5380+ // statisticsWindowSize OR we at the end of file AND
5381+ // statisticsWindowSize is not zero
5382+ if (statisticsWindowSize && m_nProcessedFramesNum &&
5383+ ((0 == m_nProcessedFramesNum % statisticsWindowSize) || bEndOfFile)) {
5384+ inputStatistics.PrintStatistics(GetPipelineID());
5385+ inputStatistics.ResetStatistics();
5386+ }
5387+ }
5388+ if (sts == MFX_ERR_MORE_DATA && (m_pmfxVPP.get()
5389+#if !defined(MFX_ONEVPL)
5390+ || m_pmfxPreENC.get()
5391+#endif
5392+ )) {
5393+ DecExtSurface.pSurface = NULL; // to get buffered VPP or ENC frames
5394+ sts = MFX_ERR_NONE;
5395+ }
5396+ if (!bLastCycle && (DecExtSurface.pSurface == NULL)) {
5397+ m_pBSProcessor->ResetInput();
5398+
5399+ if (!GetNumFramesForReset())
5400+ SetNumFramesForReset(m_nProcessedFramesNum);
5401+ sts = MFX_ERR_NONE;
5402+ continue;
5403+ }
5404+ MSDK_BREAK_ON_ERROR(sts);
5405+ }
5406+
5407+ if (m_pmfxVPP.get() && !m_rawInput) {
5408+ if (m_bIsFieldWeaving) {
5409+ // We might have 2 cases: decoder gives us pairs (TF BF)... or (BF)(TF). In first case we should set TFF for output, in second - BFF.
5410+ // So, if even input surface is BF, we set TFF for output and vise versa. For odd input surface - no matter what we set.
5411+ if (!(m_nProcessedFramesNum % 2)) {
5412+ if (DecExtSurface.pSurface) {
5413+ if ((DecExtSurface.pSurface->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF)) {
5414+ m_mfxVppParams.vpp.Out.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
5415+ }
5416+ if (DecExtSurface.pSurface->Info.PicStruct & MFX_PICSTRUCT_FIELD_BFF) {
5417+ m_mfxVppParams.vpp.Out.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
5418+ }
5419+ }
5420+ }
5421+ sts = VPPOneFrame(&DecExtSurface, &VppExtSurface);
5422+ }
5423+ else {
5424+ if (m_bIsFieldSplitting) {
5425+ if (DecExtSurface.pSurface) {
5426+ if (DecExtSurface.pSurface->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF ||
5427+ DecExtSurface.pSurface->Info.PicStruct & MFX_PICSTRUCT_FIELD_BFF) {
5428+ m_mfxVppParams.vpp.Out.PicStruct = MFX_PICSTRUCT_FIELD_SINGLE;
5429+ sts = VPPOneFrame(&DecExtSurface, &VppExtSurface);
5430+ }
5431+ else {
5432+ VppExtSurface.pSurface = DecExtSurface.pSurface;
5433+ VppExtSurface.pAuxCtrl = DecExtSurface.pAuxCtrl;
5434+ VppExtSurface.Syncp = DecExtSurface.Syncp;
5435+ }
5436+ }
5437+ else {
5438+ sts = VPPOneFrame(&DecExtSurface, &VppExtSurface);
5439+ }
5440+ }
5441+ else {
5442+ sts = VPPOneFrame(&DecExtSurface, &VppExtSurface);
5443+ }
5444+ }
5445+ // check for interlaced stream
5446+
5447+#if defined(MFX_ONEVPL)
5448+ if (m_MemoryModel != GENERAL_ALLOC && DecExtSurface.pSurface) {
5449+ mfxStatus sts_release =
5450+ DecExtSurface.pSurface->FrameInterface->Release(DecExtSurface.pSurface);
5451+ MSDK_CHECK_STATUS(sts_release, "FrameInterface->Release failed");
5452+ }
5453+#endif //MFX_ONEVPL
5454+ }
5455+ else // no VPP - just copy pointers
5456+ {
5457+ VppExtSurface.pSurface = DecExtSurface.pSurface;
5458+ VppExtSurface.Syncp = DecExtSurface.Syncp;
5459+ }
5460+
5461+ //--- Sometimes VPP may return 2 surfaces on output, for the first one it'll return status MFX_ERR_MORE_SURFACE - we have to call VPPOneFrame again in this case
5462+ if (MFX_ERR_MORE_SURFACE == sts) {
5463+ shouldReadNextFrame = false;
5464+ sts = MFX_ERR_NONE;
5465+ }
5466+ else {
5467+ shouldReadNextFrame = true;
5468+ }
5469+
5470+ if (sts == MFX_ERR_MORE_DATA || !VppExtSurface.pSurface) {
5471+ if (!bEndOfFile) {
5472+ sts = MFX_ERR_NONE;
5473+ continue; // go get next frame from Decode
5474+ }
5475+ }
5476+#if !defined(MFX_ONEVPL)
5477+ if (sts == MFX_ERR_MORE_DATA && m_pmfxPreENC.get()) {
5478+ VppExtSurface.pSurface = NULL; // to get buffered VPP or ENC frames
5479+ sts = MFX_ERR_NONE;
5480+ }
5481+#endif //!MFX_ONEVPL
5482+
5483+ MSDK_BREAK_ON_ERROR(sts);
5484+
5485+#if !defined(MFX_ONEVPL)
5486+ if (m_pmfxPreENC.get()) {
5487+ sts = PreEncOneFrame(&VppExtSurface, &PreEncExtSurface);
5488+ }
5489+ else // no VPP - just copy pointers
5490+#endif //!MFX_ONEVPL
5491+ {
5492+ PreEncExtSurface.pSurface = VppExtSurface.pSurface;
5493+ PreEncExtSurface.Syncp = VppExtSurface.Syncp;
5494+ }
5495+
5496+ if (sts == MFX_ERR_MORE_DATA || !PreEncExtSurface.pSurface) {
5497+ if (!bEndOfFile) {
5498+ sts = MFX_ERR_NONE;
5499+ continue; // go get next frame from Decode
5500+ }
5501+ }
5502+ if (!bLastCycle) {
5503+ sts = MFX_ERR_NONE;
5504+ }
5505+ MSDK_BREAK_ON_ERROR(sts);
5506+
5507+ // If session is not joined and it is not parent - synchronize.
5508+ // If there was PreENC plugin in the pipeline - synchronize, because
5509+ // plugin will output data to the extended buffers and mediasdk can't
5510+ // track such dependency on its own.
5511+ if ((!m_bIsJoinSession && m_pParentPipeline)
5512+#if !defined(MFX_ONEVPL)
5513+ || m_pmfxPreENC.get()
5514+#endif
5515+ ) {
5516+ MFX_ITT_TASK("SyncOperation");
5517+ sts = m_pmfxSession->SyncOperation(PreEncExtSurface.Syncp, MSDK_WAIT_INTERVAL);
5518+ HandlePossibleGpuHang(sts);
5519+ PreEncExtSurface.Syncp = NULL;
5520+ MSDK_CHECK_ERR_NONE_STATUS(sts, MFX_ERR_ABORTED, "PreEnc: SyncOperation failed");
5521+ }
5522+
5523+ // add surfaces in queue for all sinks
5524+ pNextBuffer->AddSurface(PreEncExtSurface);
5525+ /* one of key parts for N_to_1 mode:
5526+ * decoded frame should be in one buffer only as we have only 1 (one!) sink
5527+ * */
5528+ if (0 == m_nVPPCompEnable) {
5529+ while (pNextBuffer->m_pNext) {
5530+ pNextBuffer = pNextBuffer->m_pNext;
5531+ pNextBuffer->AddSurface(PreEncExtSurface);
5532+ }
5533+ }
5534+
5535+#if defined(MFX_ONEVPL)
5536+ if (m_MemoryModel != GENERAL_ALLOC && PreEncExtSurface.pSurface) {
5537+ mfxStatus sts_release =
5538+ PreEncExtSurface.pSurface->FrameInterface->Release(PreEncExtSurface.pSurface);
5539+ MSDK_CHECK_STATUS(sts_release, "FrameInterface->Release failed");
5540+ }
5541+#endif //MFX_ONEVPL
5542+
5543+ // We need to synchronize oldest stored surface if we've already stored enough surfaces in buffer (buffer length >= AsyncDepth)
5544+ // Because we have to wait for decoder to finish processing and free some internally used surfaces
5545+ //mfxU32 len = pNextBuffer->GetLength();
5546+ if (pNextBuffer->GetLength() >= m_AsyncDepth) {
5547+ ExtendedSurface frontSurface;
5548+ pNextBuffer->GetSurface(frontSurface);
5549+
5550+ if (frontSurface.Syncp) {
5551+ sts = m_pmfxSession->SyncOperation(frontSurface.Syncp, MSDK_WAIT_INTERVAL);
5552+ HandlePossibleGpuHang(sts);
5553+ MSDK_CHECK_ERR_NONE_STATUS(sts, MFX_ERR_ABORTED, "SyncOperation failed");
5554+ frontSurface.Syncp = NULL;
5555+ }
5556+ }
5557+
5558+ if (!statisticsWindowSize && 0 == (m_nProcessedFramesNum - 1) % 100) {
5559+ msdk_printf(MSDK_STRING("."));
5560+ }
5561+
5562+ if (bEndOfFile && m_nTimeout) {
5563+ break;
5564+ }
5565+
5566+ msdk_tick nFrameTime = msdk_time_get_tick() - nBeginTime;
5567+ if (nFrameTime < m_nReqFrameTime) {
5568+ MSDK_USLEEP((mfxU32)(m_nReqFrameTime - nFrameTime));
5569+ }
5570+ if (++m_nProcessedFramesNum >= m_MaxFramesForTranscode) {
5571+ break;
5572+ }
5573+ }
5574+
5575+ MSDK_IGNORE_MFX_STS(sts, MFX_ERR_MORE_DATA);
5576+
5577+ NoMoreFramesSignal();
5578+
5579+ if (MFX_ERR_NONE == sts)
5580+ sts = MFX_WRN_VALUE_NOT_CHANGED;
5581+
5582+ return sts;
5583+} // mfxStatus CTranscodingPipeline::Decode()
5584+
5585+mfxStatus CTranscodingPipeline::Encode() {
5586+ mfxStatus sts = MFX_ERR_NONE;
5587+ ExtendedSurface DecExtSurface = {};
5588+ ExtendedSurface VppExtSurface = {};
5589+ ExtendedBS *pBS = NULL;
5590+ bool isQuit = false;
5591+ bool bPollFlag = false;
5592+ int nFramesAlreadyPut = 0;
5593+ SafetySurfaceBuffer *curBuffer = m_pBuffer;
5594+
5595+ bool shouldReadNextFrame = true;
5596+ while (MFX_ERR_NONE == sts || MFX_ERR_MORE_DATA == sts) {
5597+ msdk_tick nBeginTime = msdk_time_get_tick(); // microseconds
5598+ if (shouldReadNextFrame) {
5599+ if (isQuit) {
5600+ // We're here because one of decoders has reported that there're no any more frames ready.
5601+ //So, let's pass null surface to extract data from the VPP and encoder caches.
5602+
5603+ MSDK_ZERO_MEMORY(DecExtSurface);
5604+ }
5605+ else {
5606+ // Getting next frame
5607+ while (MFX_ERR_MORE_SURFACE == curBuffer->GetSurface(DecExtSurface)) {
5608+ if (MFX_ERR_NONE !=
5609+ curBuffer->WaitForSurfaceInsertion(MSDK_SURFACE_WAIT_INTERVAL)) {
5610+ msdk_printf(MSDK_STRING(
5611+ "ERROR: timed out waiting surface from upstream component\n"));
5612+ return MFX_ERR_NOT_FOUND;
5613+ }
5614+ }
5615+ }
5616+
5617+ // if session is not joined and it is not parent - synchronize
5618+ if (!m_bIsJoinSession && m_pParentPipeline) {
5619+ // if it is not already synchronized
5620+ if (DecExtSurface.Syncp) {
5621+ MFX_ITT_TASK("SyncOperation");
5622+ sts = m_pParentPipeline->m_pmfxSession->SyncOperation(DecExtSurface.Syncp,
5623+ MSDK_WAIT_INTERVAL);
5624+ HandlePossibleGpuHang(sts);
5625+ MSDK_CHECK_ERR_NONE_STATUS(sts,
5626+ MFX_ERR_ABORTED,
5627+ "Encode: SyncOperation failed");
5628+ }
5629+ }
5630+
5631+ mfxU32 NumFramesForReset =
5632+ m_pParentPipeline ? m_pParentPipeline->GetNumFramesForReset() : 0;
5633+ if (NumFramesForReset && !(nFramesAlreadyPut % NumFramesForReset)) {
5634+ m_bInsertIDR = true;
5635+ }
5636+
5637+ if (NULL == DecExtSurface.pSurface) {
5638+ isQuit = true;
5639+ }
5640+ }
5641+
5642+ if (m_pmfxVPP.get()) {
5643+ sts = VPPOneFrame(&DecExtSurface, &VppExtSurface);
5644+ VppExtSurface.pAuxCtrl = DecExtSurface.pAuxCtrl;
5645+ }
5646+ else // no VPP - just copy pointers
5647+ {
5648+ VppExtSurface.pSurface = DecExtSurface.pSurface;
5649+ VppExtSurface.pAuxCtrl = DecExtSurface.pAuxCtrl;
5650+ VppExtSurface.Syncp = DecExtSurface.Syncp;
5651+ }
5652+
5653+ if (MFX_ERR_MORE_SURFACE == sts) {
5654+ shouldReadNextFrame = false;
5655+ sts = MFX_ERR_NONE;
5656+ }
5657+ else {
5658+ shouldReadNextFrame = true;
5659+ }
5660+
5661+ if (MFX_ERR_MORE_DATA == sts) {
5662+ if (isQuit) {
5663+ // to get buffered VPP or ENC frames
5664+ VppExtSurface.pSurface = NULL;
5665+ sts = MFX_ERR_NONE;
5666+ }
5667+ else {
5668+ curBuffer->ReleaseSurface(DecExtSurface.pSurface);
5669+
5670+ //--- We should switch to another buffer ONLY in case of Composition
5671+ if (curBuffer->m_pNext != NULL && m_nVPPCompEnable > 0) {
5672+ curBuffer = curBuffer->m_pNext;
5673+ continue;
5674+ }
5675+ else {
5676+ curBuffer = m_pBuffer;
5677+ continue; /* No more buffer from decoders */
5678+ }
5679+ }
5680+ }
5681+
5682+ MSDK_CHECK_STATUS(sts, "Unexpected error!!");
5683+
5684+ if (m_nVPPCompEnable > 0)
5685+ curBuffer->ReleaseSurface(DecExtSurface.pSurface);
5686+
5687+ // Do RenderFrame before Encode to improves on-screen performance
5688+ // Presentation packet would now precedes "ENC" packet within the EU
5689+ if ((m_nVPPCompEnable == VppCompOnly) || (m_nVPPCompEnable == VppCompOnlyEncode)) {
5690+ if (VppExtSurface.pSurface) {
5691+ // Sync to ensure VPP is completed to avoid flicker
5692+ sts = m_pmfxSession->SyncOperation(VppExtSurface.Syncp, MSDK_WAIT_INTERVAL);
5693+ HandlePossibleGpuHang(sts);
5694+ MSDK_CHECK_ERR_NONE_STATUS(sts, MFX_ERR_ABORTED, "VPP: SyncOperation failed");
5695+
5696+ /* in case if enabled dumping into file for after VPP composition */
5697+ if (DUMP_FILE_VPP_COMP == m_vppCompDumpRenderMode) {
5698+ sts = DumpSurface2File(VppExtSurface.pSurface);
5699+ MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
5700+ }
5701+ /* Rendering may be explicitly disabled for performance measurements */
5702+ if (NULL_RENDER_VPP_COMP != m_vppCompDumpRenderMode) {
5703+#if defined(_WIN32) || defined(_WIN64)
5704+ sts = m_hwdev4Rendering->RenderFrame(VppExtSurface.pSurface, m_pMFXAllocator);
5705+#else
5706+ sts = m_hwdev4Rendering->RenderFrame(VppExtSurface.pSurface, NULL);
5707+#endif
5708+ MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
5709+ } // if (NULL_RENDER_VPP_COMP != m_vppCompDumpRenderMode)
5710+ }
5711+ }
5712+
5713+ curBuffer = m_pBuffer;
5714+
5715+ pBS = m_pBSStore->GetNext();
5716+ if (!pBS)
5717+ return MFX_ERR_NOT_FOUND;
5718+
5719+ m_BSPool.push_back(pBS);
5720+
5721+ mfxU32 NumFramesForReset =
5722+ m_pParentPipeline ? m_pParentPipeline->GetNumFramesForReset() : 0;
5723+ if (NumFramesForReset && !(m_nProcessedFramesNum % NumFramesForReset)) {
5724+ m_pBSProcessor->ResetOutput();
5725+ }
5726+
5727+ SetEncCtrlRT(VppExtSurface, m_bInsertIDR);
5728+ m_bInsertIDR = false;
5729+
5730+ if ((m_nVPPCompEnable != VppCompOnly) || (m_nVPPCompEnable == VppCompOnlyEncode)) {
5731+ if (m_mfxEncParams.mfx.CodecId != MFX_CODEC_DUMP) {
5732+ if (bPollFlag) {
5733+ VppExtSurface.pSurface = 0;
5734+ }
5735+ sts = EncodeOneFrame(&VppExtSurface, &m_BSPool.back()->Bitstream);
5736+
5737+ // Count only real surfaces
5738+ if (VppExtSurface.pSurface) {
5739+ m_nProcessedFramesNum++;
5740+ }
5741+
5742+ if (m_nProcessedFramesNum >= m_MaxFramesForTranscode) {
5743+ bPollFlag = true;
5744+ }
5745+
5746+ if (!sts)
5747+ nFramesAlreadyPut++;
5748+ }
5749+ else {
5750+ sts = Surface2BS(&VppExtSurface, &m_BSPool.back()->Bitstream, m_encoderFourCC);
5751+ }
5752+
5753+#if defined(MFX_ONEVPL)
5754+ if (m_MemoryModel != GENERAL_ALLOC && VppExtSurface.pSurface && m_pmfxVPP) {
5755+ mfxStatus sts_release =
5756+ VppExtSurface.pSurface->FrameInterface->Release(VppExtSurface.pSurface);
5757+ MSDK_CHECK_STATUS(sts_release, "FrameInterface->Release failed");
5758+ }
5759+#endif //MFX_ONEVPL
5760+ }
5761+
5762+ if (shouldReadNextFrame) // Release current decoded surface only if we're going to read next one during next iteration
5763+ {
5764+ m_pBuffer->ReleaseSurface(DecExtSurface.pSurface);
5765+ }
5766+
5767+ // check if we need one more frame from decode
5768+ if (MFX_ERR_MORE_DATA == sts) {
5769+ // the task in not in Encode queue
5770+ m_BSPool.pop_back();
5771+ m_pBSStore->Release(pBS);
5772+
5773+ if (NULL == VppExtSurface.pSurface) // there are no more buffered frames in encoder
5774+ {
5775+ break;
5776+ }
5777+ else {
5778+ // get next frame from Decode
5779+ sts = MFX_ERR_NONE;
5780+ continue;
5781+ }
5782+ }
5783+
5784+ // check encoding result
5785+ MSDK_CHECK_STATUS(sts, "<EncodeOneFrame|Surface2BS> failed");
5786+
5787+ // output statistics if several conditions are true OR we've approached
5788+ // the end, and statisticsWindowSize is not 0, but number of frames is
5789+ // not multiple of statisticsWindowSize; should use m_nProcessedFramesNum
5790+ // as it simplifies conditions
5791+ if ((statisticsWindowSize && m_nOutputFramesNum &&
5792+ 0 == m_nProcessedFramesNum % statisticsWindowSize) ||
5793+ (statisticsWindowSize && (m_nProcessedFramesNum >= m_MaxFramesForTranscode))) {
5794+ outputStatistics.PrintStatistics(GetPipelineID());
5795+ outputStatistics.ResetStatistics();
5796+ }
5797+
5798+ m_BSPool.back()->Syncp = VppExtSurface.Syncp;
5799+ m_BSPool.back()->pCtrl = VppExtSurface.pAuxCtrl;
5800+
5801+ /* Actually rendering... if enabled
5802+ * SYNC have not done by driver !!! */
5803+ if ((m_nVPPCompEnable == VppCompOnly) || (m_nVPPCompEnable == VppCompOnlyEncode)) {
5804+ if (m_BSPool.size()) {
5805+ ExtendedBS *pBitstreamEx_temp = m_BSPool.front();
5806+
5807+ // get result coded stream
5808+ ////Note! Better to do rendering before encode
5809+ // if(VppExtSurface.pSurface)
5810+ // {
5811+ // if(m_nVPPCompEnable != VppCompOnlyEncode)
5812+ // {
5813+ // sts = m_pmfxSession->SyncOperation(VppExtSurface.Syncp, MSDK_WAIT_INTERVAL);
5814+ // MSDK_CHECK_ERR_NONE_STATUS(sts, MFX_ERR_ABORTED, "VPP: SyncOperation failed");
5815+ // }
5816+ //#if defined(_WIN32) || defined(_WIN64)
5817+ // sts = m_hwdev4Rendering->RenderFrame(VppExtSurface.pSurface, m_pMFXAllocator);
5818+ //#else
5819+ // sts = m_hwdev4Rendering->RenderFrame(VppExtSurface.pSurface, NULL);
5820+ //#endif
5821+ // MSDK_CHECK_STATUS(sts, "m_hwdev4Rendering->RenderFrame failed");
5822+ // }
5823+
5824+ UnPreEncAuxBuffer(pBitstreamEx_temp->pCtrl);
5825+
5826+ if (m_nVPPCompEnable != VppCompOnlyEncode) {
5827+ pBitstreamEx_temp->Bitstream.DataLength = 0;
5828+ pBitstreamEx_temp->Bitstream.DataOffset = 0;
5829+
5830+ m_BSPool.pop_front();
5831+ m_pBSStore->Release(pBitstreamEx_temp);
5832+ }
5833+ }
5834+
5835+ //--- If there's no data coming out from VPP and there's no data coming from decoders (isQuit==true),
5836+ // then we should quit, otherwise we may stuck here forever (cause there's no new data coming)
5837+ if (!VppExtSurface.pSurface && isQuit) {
5838+ break;
5839+ }
5840+ }
5841+
5842+ if ((m_nVPPCompEnable != VppCompOnly) || (m_nVPPCompEnable == VppCompOnlyEncode)) {
5843+ if (m_BSPool.size() == m_AsyncDepth) {
5844+ sts = PutBS();
5845+ MSDK_CHECK_STATUS(sts, "PutBS failed");
5846+ }
5847+ else {
5848+ continue;
5849+ }
5850+ } // if (m_nVPPCompEnable != VppCompOnly)
5851+
5852+ msdk_tick nFrameTime = msdk_time_get_tick() - nBeginTime;
5853+ if (nFrameTime < m_nReqFrameTime) {
5854+ MSDK_USLEEP((mfxU32)(m_nReqFrameTime - nFrameTime));
5855+ }
5856+ }
5857+ MSDK_IGNORE_MFX_STS(sts, MFX_ERR_MORE_DATA);
5858+
5859+ if (m_nVPPCompEnable != VppCompOnly || (m_nVPPCompEnable == VppCompOnlyEncode)) {
5860+ // need to get buffered bitstream
5861+ if (MFX_ERR_NONE == sts) {
5862+ while (m_BSPool.size()) {
5863+ sts = PutBS();
5864+ MSDK_CHECK_STATUS(sts, "PutBS failed");
5865+ }
5866+ }
5867+ }
5868+
5869+ // Clean up decoder buffers to avoid locking them (if some decoder still have some data to decode, but does not have enough surfaces)
5870+ if (m_nVPPCompEnable != 0) {
5871+ // Composition case - we have to clean up all buffers (all of them have data from decoders)
5872+ for (SafetySurfaceBuffer *buf = m_pBuffer; buf != NULL; buf = buf->m_pNext) {
5873+ while (buf->GetSurface(DecExtSurface) != MFX_ERR_MORE_SURFACE) {
5874+ buf->ReleaseSurface(DecExtSurface.pSurface);
5875+ buf->CancelBuffering();
5876+ }
5877+ }
5878+ }
5879+ else {
5880+ // Clean up only current buffer
5881+ m_pBuffer->CancelBuffering();
5882+ while (m_pBuffer->GetSurface(DecExtSurface) != MFX_ERR_MORE_SURFACE) {
5883+ m_pBuffer->ReleaseSurface(DecExtSurface.pSurface);
5884+ }
5885+ }
5886+
5887+ // Close encoder and decoder and clean up buffers
5888+ if (m_pmfxENC.get())
5889+ m_pmfxENC->Close();
5890+
5891+ if (m_pmfxVPP.get())
5892+ m_pmfxVPP->Close();
5893+
5894+ if (MFX_ERR_NONE == sts)
5895+ sts = MFX_WRN_VALUE_NOT_CHANGED;
5896+ return sts;
5897+
5898+} // mfxStatus CTranscodingPipeline::Encode()
5899+
5900+#if MFX_VERSION >= 1022
5901+void CTranscodingPipeline::FillMBQPBuffer(mfxExtMBQP &qpMap, mfxU16 pictStruct) {
5902+ // External MBQP case
5903+ if (m_bExtMBQP) {
5904+ // Use simplistic approach to fill in QP buffer
5905+ for (size_t i = 0; i < qpMap.NumQPAlloc; i++) {
5906+ qpMap.QP[i] = i % 52;
5907+ }
5908+ return;
5909+ }
5910+
5911+ // External MBQP with ROI case
5912+ if (pictStruct == MFX_PICSTRUCT_PROGRESSIVE) {
5913+ mfxI8 fQP = (m_nSubmittedFramesNum % m_GOPSize) ? (mfxI8)m_QPforP : (mfxI8)m_QPforI;
5914+ std::memset(qpMap.QP, fQP, qpMap.NumQPAlloc);
5915+
5916+ // printf("QP expectation: %d, map PTR %lld\n",fQP,(long long int)qpMap.QP);
5917+
5918+ if (m_ROIData.size() > m_nSubmittedFramesNum) {
5919+ mfxExtEncoderROI &roi = m_ROIData[m_nSubmittedFramesNum];
5920+ for (mfxI32 i = roi.NumROI - 1; i >= 0; i--) {
5921+ mfxU32 l = (roi.ROI[i].Left) >> 4, t = (roi.ROI[i].Top) >> 4,
5922+ r = (roi.ROI[i].Right + 15) >> 4, b = (roi.ROI[i].Bottom + 15) >> 4;
5923+
5924+ //Additional 32x32 block alignment for HEVC VDEnc, using caps could be better
5925+ if (m_mfxEncParams.mfx.CodecId == MFX_CODEC_HEVC &&
5926+ m_mfxEncParams.mfx.LowPower == MFX_CODINGOPTION_ON) {
5927+ l = ((roi.ROI[i].Left) >> 5) << 1;
5928+ t = ((roi.ROI[i].Top) >> 5) << 1;
5929+ r = ((roi.ROI[i].Right + 31) >> 5) << 1;
5930+ b = ((roi.ROI[i].Bottom + 31) >> 5) << 1;
5931+ }
5932+
5933+ if (l > m_QPmapWidth)
5934+ l = m_QPmapWidth;
5935+ if (r > m_QPmapWidth)
5936+ r = m_QPmapWidth;
5937+ if (t > m_QPmapHeight)
5938+ t = m_QPmapHeight;
5939+ if (b > m_QPmapHeight)
5940+ b = m_QPmapHeight;
5941+
5942+ mfxI8 qp_value = (mfxI8)std::min(std::max(fQP + (mfxI8)roi.ROI[i].DeltaQP, 0), 51);
5943+
5944+ for (mfxU32 k = t; k < b; k++)
5945+ std::memset(qpMap.QP + k * m_QPmapWidth + l, qp_value, r - l);
5946+ }
5947+ }
5948+ }
5949+ else if (pictStruct == MFX_PICSTRUCT_FIELD_TFF || pictStruct == MFX_PICSTRUCT_FIELD_BFF) {
5950+ mfxU32 fQP[2] = { (m_nSubmittedFramesNum % m_GOPSize) ? m_QPforP : m_QPforI,
5951+ (m_GOPSize > 1) ? m_QPforP : m_QPforI };
5952+ mfxU32 fIdx[2] = { 2 * m_nSubmittedFramesNum, 2 * m_nSubmittedFramesNum + 1 };
5953+ mfxU32 fOff[2] = { 0, 0 };
5954+
5955+ fOff[(pictStruct == MFX_PICSTRUCT_FIELD_BFF) ? 0 : 1] = qpMap.NumQPAlloc / 2;
5956+
5957+ for (int fld = 0; fld <= 1; fld++) {
5958+ std::memset(qpMap.QP + fOff[fld], fQP[fld], qpMap.NumQPAlloc / 2);
5959+ if (m_ROIData.size() > fIdx[fld]) {
5960+ mfxExtEncoderROI &roi = m_ROIData[fIdx[fld]];
5961+ for (mfxI32 i = roi.NumROI - 1; i >= 0; i--) {
5962+ mfxU32 l = (roi.ROI[i].Left) >> 4, t = (roi.ROI[i].Top) >> 5,
5963+ r = (roi.ROI[i].Right + 15) >> 4, b = (roi.ROI[i].Bottom + 31) >> 5;
5964+ mfxI8 qp_delta = (mfxI8)roi.ROI[i].DeltaQP;
5965+ mfxU8 roi_qp = (mfxU8)std::min(std::max(mfxI8(fQP[fld]) + qp_delta, 0), 51);
5966+
5967+ if (l > m_QPmapWidth)
5968+ l = m_QPmapWidth;
5969+ if (r > m_QPmapWidth)
5970+ r = m_QPmapWidth;
5971+ if (t > m_QPmapHeight / 2)
5972+ t = m_QPmapHeight / 2;
5973+ if (b > m_QPmapHeight / 2)
5974+ b = m_QPmapHeight / 2;
5975+
5976+ for (mfxU32 k = t; k < b; k++)
5977+ std::memset(qpMap.QP + fOff[fld] + k * m_QPmapWidth + l, roi_qp, r - l);
5978+ }
5979+ }
5980+ }
5981+ }
5982+ else {
5983+ mfxI8 fQP = (m_nSubmittedFramesNum % m_GOPSize) ? (mfxI8)m_QPforP : (mfxI8)m_QPforI;
5984+ std::memset(qpMap.QP, fQP, qpMap.NumQPAlloc);
5985+ }
5986+}
5987+#endif //MFX_VERSION >= 1022
5988+
5989+void CTranscodingPipeline::SetEncCtrlRT(ExtendedSurface &extSurface, bool bInsertIDR) {
5990+ extSurface.pEncCtrl = NULL;
5991+ if (extSurface.pAuxCtrl) {
5992+ extSurface.pEncCtrl = &extSurface.pAuxCtrl->encCtrl;
5993+ }
5994+
5995+#if MFX_VERSION >= 1022
5996+
5997+ if (extSurface.pSurface) {
5998+ void *keyId = (void *)extSurface.pSurface;
5999+
6000+ // Use encoded surface pointer to find placeholders for run-time structures in maps
6001+ if (m_bUseQPMap && m_bufExtMBQP.find(keyId) == m_bufExtMBQP.end()) {
6002+ m_extBuffPtrStorage[keyId] = std::vector<mfxExtBuffer *>();
6003+
6004+ m_qpMapStorage[keyId] = std::vector<mfxU8>();
6005+ m_qpMapStorage[keyId].resize(m_QPmapWidth * m_QPmapHeight);
6006+
6007+ m_bufExtMBQP[keyId] = mfxExtMBQP();
6008+ m_bufExtMBQP[keyId].Header.BufferId = MFX_EXTBUFF_MBQP;
6009+ m_bufExtMBQP[keyId].Header.BufferSz = sizeof(mfxExtMBQP);
6010+ m_bufExtMBQP[keyId].NumQPAlloc = m_QPmapWidth * m_QPmapHeight;
6011+ m_bufExtMBQP[keyId].QP =
6012+ m_QPmapWidth && m_QPmapHeight ? &(m_qpMapStorage[keyId][0]) : NULL;
6013+ }
6014+
6015+ // Initialize *pCtrl optionally copying content of the pExtSurface.pAuxCtrl.encCtrl
6016+ mfxEncodeCtrl &ctrl = encControlStorage[keyId];
6017+ MSDK_ZERO_MEMORY(ctrl);
6018+
6019+ if (extSurface.pEncCtrl) {
6020+ ctrl = *extSurface.pEncCtrl;
6021+ }
6022+
6023+ // Copy all extended buffer pointers from pExtSurface.pAuxCtrl.encCtrl
6024+ m_extBuffPtrStorage[keyId].clear();
6025+ if (extSurface.pAuxCtrl) {
6026+ for (unsigned int i = 0; i < ctrl.NumExtParam; i++) {
6027+ m_extBuffPtrStorage[keyId].push_back(extSurface.pAuxCtrl->encCtrl.ExtParam[i]);
6028+ }
6029+ }
6030+
6031+ // Attach additional buffer with either MBQP or ROI information
6032+ if (m_bUseQPMap) {
6033+ #if (MFX_VERSION >= 1022)
6034+ FillMBQPBuffer(m_bufExtMBQP[keyId], extSurface.pSurface->Info.PicStruct);
6035+ m_extBuffPtrStorage[keyId].push_back((mfxExtBuffer *)&m_bufExtMBQP[keyId]);
6036+ #endif
6037+ }
6038+ else {
6039+ if (m_ROIData.size() > m_nSubmittedFramesNum)
6040+ m_extBuffPtrStorage[keyId].push_back(
6041+ (mfxExtBuffer *)&m_ROIData[m_nSubmittedFramesNum]);
6042+ }
6043+
6044+ // Replace the buffers pointer to pre-allocated storage
6045+ ctrl.NumExtParam = (mfxU16)m_extBuffPtrStorage[keyId].size();
6046+ if (ctrl.NumExtParam) {
6047+ ctrl.ExtParam = &(m_extBuffPtrStorage[keyId][0]);
6048+ }
6049+
6050+ extSurface.pEncCtrl = &ctrl;
6051+ m_nSubmittedFramesNum++;
6052+ }
6053+#endif //MFX_VERSION >= 1022
6054+
6055+ if (bInsertIDR && extSurface.pSurface) {
6056+ if (extSurface.pEncCtrl == NULL) {
6057+ mfxEncodeCtrl &ctrl = encControlStorage[(void *)extSurface.pSurface];
6058+ MSDK_ZERO_MEMORY(ctrl);
6059+ extSurface.pEncCtrl = &ctrl;
6060+ }
6061+ extSurface.pEncCtrl->FrameType = MFX_FRAMETYPE_I | MFX_FRAMETYPE_IDR | MFX_FRAMETYPE_REF;
6062+ }
6063+ else {
6064+ if (extSurface.pEncCtrl) {
6065+ extSurface.pEncCtrl->FrameType = 0;
6066+ }
6067+ }
6068+}
6069+
6070+mfxStatus CTranscodingPipeline::Transcode() {
6071+ mfxStatus sts = MFX_ERR_NONE;
6072+ ExtendedSurface DecExtSurface = { 0 };
6073+ ExtendedSurface VppExtSurface = { 0 };
6074+ ExtendedBS *pBS = NULL;
6075+ bool bNeedDecodedFrames = true; // indicates if we need to decode frames
6076+ bool bEndOfFile = false;
6077+ bool bLastCycle = false;
6078+ bool shouldReadNextFrame = true;
6079+
6080+ time_t start = time(0);
6081+ while (MFX_ERR_NONE == sts) {
6082+ msdk_tick nBeginTime = msdk_time_get_tick(); // microseconds.
6083+
6084+ if (time(0) - start >= m_nTimeout)
6085+ bLastCycle = true;
6086+ if (m_MaxFramesForTranscode == m_nProcessedFramesNum) {
6087+ DecExtSurface.pSurface = NULL; // to get buffered VPP or ENC frames
6088+ bNeedDecodedFrames = false; // no more decoded frames needed
6089+ }
6090+
6091+ // if need more decoded frames
6092+ // decode a frame
6093+ if (bNeedDecodedFrames && shouldReadNextFrame) {
6094+ if (!bEndOfFile) {
6095+ sts = DecodeOneFrame(&DecExtSurface);
6096+ if (MFX_ERR_MORE_DATA == sts) {
6097+ if (!bLastCycle) {
6098+ m_bInsertIDR = true;
6099+
6100+ m_pBSProcessor->ResetInput();
6101+ m_pBSProcessor->ResetOutput();
6102+ bNeedDecodedFrames = true;
6103+
6104+ bEndOfFile = false;
6105+ sts = MFX_ERR_NONE;
6106+ continue;
6107+ }
6108+ else {
6109+ bEndOfFile = true;
6110+ }
6111+ }
6112+ }
6113+
6114+ if (bEndOfFile) {
6115+ sts = DecodeLastFrame(&DecExtSurface);
6116+ }
6117+
6118+ if (sts == MFX_ERR_MORE_DATA) {
6119+ DecExtSurface.pSurface = NULL; // to get buffered VPP or ENC frames
6120+ sts = MFX_ERR_NONE;
6121+ }
6122+ MSDK_CHECK_STATUS(sts, "Decode<One|Last>Frame failed");
6123+ }
6124+ if (m_bIsFieldWeaving && DecExtSurface.pSurface != NULL) {
6125+ m_mfxDecParams.mfx.FrameInfo.PicStruct = DecExtSurface.pSurface->Info.PicStruct;
6126+ }
6127+ if (m_bIsFieldSplitting && DecExtSurface.pSurface != NULL) {
6128+ m_mfxDecParams.mfx.FrameInfo.PicStruct = DecExtSurface.pSurface->Info.PicStruct;
6129+ }
6130+ // pre-process a frame
6131+ if (m_pmfxVPP.get() && bNeedDecodedFrames && !m_rawInput) {
6132+ if (m_bIsFieldWeaving) {
6133+ // In case of field weaving output surface's parameters for ODD calls to VPPOneFrame will be ignored (because VPP will return ERR_MORE_DATA).
6134+ // So, we need to set output surface picstruct properly for EVEN calls (no matter what will be set for ODD calls).
6135+ // We might have 2 cases: decoder gives us pairs (TF BF)... or (BF)(TF). In first case we should set TFF for output, in second - BFF.
6136+ // So, if even input surface is BF, we set TFF for output and vise versa. For odd input surface - no matter what we set.
6137+ if (DecExtSurface.pSurface) {
6138+ if ((DecExtSurface.pSurface->Info.PicStruct &
6139+ MFX_PICSTRUCT_FIELD_TFF)) // Incoming Top Field in a single surface
6140+ {
6141+ m_mfxVppParams.vpp.Out.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
6142+ }
6143+ if (DecExtSurface.pSurface->Info.PicStruct &
6144+ MFX_PICSTRUCT_FIELD_BFF) // Incoming Bottom Field in a single surface
6145+ {
6146+ m_mfxVppParams.vpp.Out.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
6147+ }
6148+ }
6149+ sts = VPPOneFrame(&DecExtSurface, &VppExtSurface);
6150+ }
6151+ else {
6152+ if (m_bIsFieldSplitting) {
6153+ if (DecExtSurface.pSurface) {
6154+ if (DecExtSurface.pSurface->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF ||
6155+ DecExtSurface.pSurface->Info.PicStruct & MFX_PICSTRUCT_FIELD_BFF) {
6156+ m_mfxVppParams.vpp.Out.PicStruct = MFX_PICSTRUCT_FIELD_SINGLE;
6157+ sts = VPPOneFrame(&DecExtSurface, &VppExtSurface);
6158+ }
6159+ else {
6160+ VppExtSurface.pSurface = DecExtSurface.pSurface;
6161+ VppExtSurface.pAuxCtrl = DecExtSurface.pAuxCtrl;
6162+ VppExtSurface.Syncp = DecExtSurface.Syncp;
6163+ }
6164+ }
6165+ else {
6166+ sts = VPPOneFrame(&DecExtSurface, &VppExtSurface);
6167+ }
6168+ }
6169+ else {
6170+ sts = VPPOneFrame(&DecExtSurface, &VppExtSurface);
6171+ }
6172+ }
6173+ // check for interlaced stream
6174+
6175+#if defined(MFX_ONEVPL)
6176+ if (m_MemoryModel != GENERAL_ALLOC && DecExtSurface.pSurface) {
6177+ mfxStatus sts_release =
6178+ DecExtSurface.pSurface->FrameInterface->Release(DecExtSurface.pSurface);
6179+ MSDK_CHECK_STATUS(sts_release, "FrameInterface->Release failed");
6180+ }
6181+#endif //MFX_ONEVPL
6182+ }
6183+ else // no VPP - just copy pointers
6184+ {
6185+ VppExtSurface.pSurface = DecExtSurface.pSurface;
6186+ VppExtSurface.pAuxCtrl = DecExtSurface.pAuxCtrl;
6187+ VppExtSurface.Syncp = DecExtSurface.Syncp;
6188+ }
6189+
6190+ if (MFX_ERR_MORE_SURFACE == sts) {
6191+ shouldReadNextFrame = false;
6192+ sts = MFX_ERR_NONE;
6193+ }
6194+ else {
6195+ shouldReadNextFrame = true;
6196+ }
6197+
6198+ if (sts == MFX_ERR_MORE_DATA) {
6199+ sts = MFX_ERR_NONE;
6200+ if (NULL == DecExtSurface.pSurface) // there are no more buffered frames in VPP
6201+ {
6202+ VppExtSurface.pSurface = NULL; // to get buffered ENC frames
6203+ }
6204+ else {
6205+ continue; // go get next frame from Decode
6206+ }
6207+ }
6208+
6209+ MSDK_CHECK_STATUS(sts, "Unexpected error!!");
6210+
6211+ // encode frame
6212+ pBS = m_pBSStore->GetNext();
6213+ if (!pBS)
6214+ return MFX_ERR_NOT_FOUND;
6215+
6216+ m_BSPool.push_back(pBS);
6217+
6218+ // Set Encoding control if it is required.
6219+
6220+ SetEncCtrlRT(VppExtSurface, m_bInsertIDR);
6221+ m_bInsertIDR = false;
6222+
6223+ if (DecExtSurface.pSurface)
6224+ m_nProcessedFramesNum++;
6225+
6226+ if (m_mfxEncParams.mfx.CodecId != MFX_CODEC_DUMP) {
6227+ sts = EncodeOneFrame(&VppExtSurface, &m_BSPool.back()->Bitstream);
6228+ }
6229+ else {
6230+ sts = Surface2BS(&VppExtSurface, &m_BSPool.back()->Bitstream, m_encoderFourCC);
6231+ }
6232+
6233+#if defined(MFX_ONEVPL)
6234+ if (m_MemoryModel != GENERAL_ALLOC && VppExtSurface.pSurface) {
6235+ mfxStatus sts_release =
6236+ VppExtSurface.pSurface->FrameInterface->Release(VppExtSurface.pSurface);
6237+ MSDK_CHECK_STATUS(sts_release, "FrameInterface->Release failed");
6238+ }
6239+#endif //MFX_ONEVPL
6240+
6241+ // check if we need one more frame from decode
6242+ if (MFX_ERR_MORE_DATA == sts) {
6243+ // the task in not in Encode queue
6244+ m_BSPool.pop_back();
6245+ m_pBSStore->Release(pBS);
6246+
6247+ if (NULL == VppExtSurface.pSurface) // there are no more buffered frames in encoder
6248+ {
6249+ break;
6250+ }
6251+ sts = MFX_ERR_NONE;
6252+ continue;
6253+ }
6254+
6255+ // check encoding result
6256+ MSDK_CHECK_STATUS(sts, "<EncodeOneFrame|Surface2BS> failed");
6257+
6258+ if (statisticsWindowSize) {
6259+ if ((statisticsWindowSize && m_nOutputFramesNum &&
6260+ 0 == m_nProcessedFramesNum % statisticsWindowSize) ||
6261+ (statisticsWindowSize && (m_nProcessedFramesNum >= m_MaxFramesForTranscode))) {
6262+ inputStatistics.PrintStatistics(GetPipelineID());
6263+ outputStatistics.PrintStatistics(
6264+ GetPipelineID(),
6265+ (m_mfxEncParams.mfx.FrameInfo.FrameRateExtD)
6266+ ? (mfxF64)m_mfxEncParams.mfx.FrameInfo.FrameRateExtN /
6267+ (mfxF64)m_mfxEncParams.mfx.FrameInfo.FrameRateExtD
6268+ : -1);
6269+ inputStatistics.ResetStatistics();
6270+ outputStatistics.ResetStatistics();
6271+ }
6272+ }
6273+ else if (0 == (m_nProcessedFramesNum - 1) % 100) {
6274+ msdk_printf(MSDK_STRING("."));
6275+ }
6276+
6277+ m_BSPool.back()->Syncp = VppExtSurface.Syncp;
6278+
6279+ if (m_BSPool.size() == m_AsyncDepth) {
6280+ sts = PutBS();
6281+ MSDK_CHECK_STATUS(sts, "PutBS failed");
6282+ }
6283+
6284+ msdk_tick nFrameTime = msdk_time_get_tick() - nBeginTime;
6285+ if (nFrameTime < m_nReqFrameTime) {
6286+ MSDK_USLEEP((mfxU32)(m_nReqFrameTime - nFrameTime));
6287+ }
6288+ }
6289+ MSDK_IGNORE_MFX_STS(sts, MFX_ERR_MORE_DATA);
6290+
6291+ // need to get buffered bitstream
6292+ if (MFX_ERR_NONE == sts) {
6293+ while (m_BSPool.size()) {
6294+ sts = PutBS();
6295+ MSDK_CHECK_STATUS(sts, "PutBS failed");
6296+ }
6297+ }
6298+
6299+ if (MFX_ERR_NONE == sts)
6300+ sts = MFX_WRN_VALUE_NOT_CHANGED;
6301+
6302+ return sts;
6303+} // mfxStatus CTranscodingPipeline::Transcode()
6304+
6305+mfxStatus CTranscodingPipeline::PutBS() {
6306+ mfxStatus sts = MFX_ERR_NONE;
6307+ ExtendedBS *pBitstreamEx = m_BSPool.front();
6308+ MSDK_CHECK_POINTER(pBitstreamEx, MFX_ERR_NULL_PTR);
6309+
6310+ // get result coded stream, synchronize only if we still have sync point
6311+ if (pBitstreamEx->Syncp) {
6312+ sts = m_pmfxSession->SyncOperation(pBitstreamEx->Syncp, MSDK_WAIT_INTERVAL);
6313+ HandlePossibleGpuHang(sts);
6314+ MSDK_CHECK_ERR_NONE_STATUS(sts, MFX_ERR_ABORTED, "Encode: SyncOperation failed");
6315+ }
6316+
6317+ m_nOutputFramesNum++;
6318+
6319+ //--- Time measurements
6320+ if (statisticsWindowSize) {
6321+ outputStatistics.StopTimeMeasurementWithCheck();
6322+ outputStatistics.StartTimeMeasurement();
6323+ }
6324+
6325+ sts = m_pBSProcessor->ProcessOutputBitstream(&pBitstreamEx->Bitstream);
6326+ MSDK_CHECK_STATUS(sts, "m_pBSProcessor->ProcessOutputBitstream failed");
6327+
6328+ UnPreEncAuxBuffer(pBitstreamEx->pCtrl);
6329+
6330+ pBitstreamEx->Bitstream.DataLength = 0;
6331+ pBitstreamEx->Bitstream.DataOffset = 0;
6332+
6333+ if (m_BSPool.size())
6334+ m_BSPool.pop_front();
6335+ m_pBSStore->Release(pBitstreamEx);
6336+
6337+ return sts;
6338+} //mfxStatus CTranscodingPipeline::PutBS()
6339+
6340+mfxStatus CTranscodingPipeline::DumpSurface2File(mfxFrameSurface1 *pSurf) {
6341+ mfxStatus sts = MFX_ERR_NONE;
6342+
6343+ if (m_MemoryModel == GENERAL_ALLOC) {
6344+ sts = m_pMFXAllocator->Lock(m_pMFXAllocator->pthis, pSurf->Data.MemId, &pSurf->Data);
6345+ MSDK_CHECK_STATUS(sts, "m_pMFXAllocator->Lock failed");
6346+ }
6347+#if defined(MFX_ONEVPL)
6348+ else {
6349+ sts = pSurf->FrameInterface->Map(pSurf, MFX_MAP_READ);
6350+ MSDK_CHECK_STATUS(sts, "FrameInterface->Map failed");
6351+ }
6352+#endif //MFX_ONEVPL
6353+
6354+ sts = m_dumpVppCompFileWriter.WriteNextFrame(pSurf);
6355+ MSDK_CHECK_STATUS(sts, "m_dumpVppCompFileWriter.WriteNextFrame failed");
6356+
6357+ if (m_MemoryModel == GENERAL_ALLOC) {
6358+ sts = m_pMFXAllocator->Unlock(m_pMFXAllocator->pthis, pSurf->Data.MemId, &pSurf->Data);
6359+ MSDK_CHECK_STATUS(sts, "m_pMFXAllocator->Unlock failed");
6360+ }
6361+#if defined(MFX_ONEVPL)
6362+ else {
6363+ sts = pSurf->FrameInterface->Unmap(pSurf);
6364+ MSDK_CHECK_STATUS(sts, "FrameInterface->Unmap failed");
6365+ }
6366+#endif //MFX_ONEVPL
6367+
6368+ return sts;
6369+} // mfxStatus CTranscodingPipeline::DumpSurface2File(ExtendedSurface* pSurf)
6370+
6371+mfxStatus CTranscodingPipeline::Surface2BS(ExtendedSurface *pSurf,
6372+ mfxBitstreamWrapper *pBS,
6373+ mfxU32 fourCC) {
6374+ mfxStatus sts = MFX_ERR_MORE_DATA;
6375+ // get result coded stream
6376+ if (!pSurf->pSurface) {
6377+ return MFX_ERR_MORE_DATA;
6378+ }
6379+
6380+ if (pSurf->Syncp) {
6381+ sts = m_pmfxSession->SyncOperation(pSurf->Syncp, MSDK_WAIT_INTERVAL);
6382+ HandlePossibleGpuHang(sts);
6383+ MSDK_CHECK_ERR_NONE_STATUS(sts, MFX_ERR_ABORTED, "SyncOperation failed");
6384+ pSurf->Syncp = 0;
6385+
6386+ //--- Copying data from surface to bitstream
6387+ if (m_MemoryModel == GENERAL_ALLOC) {
6388+ sts = m_pMFXAllocator->Lock(m_pMFXAllocator->pthis,
6389+ pSurf->pSurface->Data.MemId,
6390+ &pSurf->pSurface->Data);
6391+ MSDK_CHECK_STATUS(sts, "m_pMFXAllocator->Lock failed");
6392+ }
6393+#if defined(MFX_ONEVPL)
6394+ else {
6395+ sts = pSurf->pSurface->FrameInterface->Map(pSurf->pSurface, MFX_MAP_READ);
6396+ MSDK_CHECK_STATUS(sts, "FrameInterface->Map failed");
6397+ }
6398+#endif //MFX_ONEVPL
6399+
6400+ switch (fourCC) {
6401+ case 0: // Default value is MFX_FOURCC_I420
6402+ case MFX_FOURCC_I420:
6403+ sts = NV12asI420toBS(pSurf->pSurface, pBS);
6404+ break;
6405+ case MFX_FOURCC_NV12:
6406+ sts = NV12toBS(pSurf->pSurface, pBS);
6407+ break;
6408+ case MFX_FOURCC_RGB4:
6409+ sts = RGB4toBS(pSurf->pSurface, pBS);
6410+ break;
6411+ case MFX_FOURCC_YUY2:
6412+ sts = YUY2toBS(pSurf->pSurface, pBS);
6413+ break;
6414+ }
6415+ MSDK_CHECK_STATUS(sts, "<FourCC>toBS failed");
6416+
6417+ if (m_MemoryModel == GENERAL_ALLOC) {
6418+ sts = m_pMFXAllocator->Unlock(m_pMFXAllocator->pthis,
6419+ pSurf->pSurface->Data.MemId,
6420+ &pSurf->pSurface->Data);
6421+ MSDK_CHECK_STATUS(sts, "m_pMFXAllocator->Unlock failed");
6422+ }
6423+#if defined(MFX_ONEVPL)
6424+ else {
6425+ sts = pSurf->pSurface->FrameInterface->Unmap(pSurf->pSurface);
6426+ MSDK_CHECK_STATUS(sts, "FrameInterface->Unmap failed");
6427+ }
6428+#endif //MFX_ONEVPL
6429+ }
6430+
6431+ return sts;
6432+}
6433+
6434+mfxStatus CTranscodingPipeline::NV12asI420toBS(mfxFrameSurface1 *pSurface,
6435+ mfxBitstreamWrapper *pBS) {
6436+ mfxFrameInfo &info = pSurface->Info;
6437+ mfxFrameData &data = pSurface->Data;
6438+ if ((int)pBS->MaxLength - (int)pBS->DataLength < (int)(info.CropH * info.CropW * 3 / 2)) {
6439+ pBS->Extend(pBS->DataLength + (int)(info.CropH * info.CropW * 3 / 2));
6440+ }
6441+
6442+ for (mfxU16 i = 0; i < info.CropH; i++) {
6443+ MSDK_MEMCPY(pBS->Data + pBS->DataLength,
6444+ data.Y + (info.CropY * data.Pitch + info.CropX) + i * data.Pitch,
6445+ info.CropW);
6446+ pBS->DataLength += info.CropW;
6447+ }
6448+
6449+ mfxU16 h = info.CropH / 2;
6450+ mfxU16 w = info.CropW;
6451+
6452+ for (mfxU16 offset = 0; offset < 2; offset++) {
6453+ for (mfxU16 i = 0; i < h; i++) {
6454+ for (mfxU16 j = offset; j < w; j += 2) {
6455+ pBS->Data[pBS->DataLength] =
6456+ *(data.UV + (info.CropY * data.Pitch / 2 + info.CropX) + i * data.Pitch + j);
6457+ pBS->DataLength++;
6458+ }
6459+ }
6460+ }
6461+
6462+ return MFX_ERR_NONE;
6463+}
6464+
6465+mfxStatus CTranscodingPipeline::NV12toBS(mfxFrameSurface1 *pSurface, mfxBitstreamWrapper *pBS) {
6466+ mfxFrameInfo &info = pSurface->Info;
6467+ mfxFrameData &data = pSurface->Data;
6468+ if ((int)pBS->MaxLength - (int)pBS->DataLength < (int)(info.CropH * info.CropW * 3 / 2)) {
6469+ pBS->Extend(pBS->DataLength + (int)(info.CropH * info.CropW * 3 / 2));
6470+ }
6471+
6472+ for (mfxU16 i = 0; i < info.CropH; i++) {
6473+ MSDK_MEMCPY(pBS->Data + pBS->DataLength,
6474+ data.Y + (info.CropY * data.Pitch + info.CropX) + i * data.Pitch,
6475+ info.CropW);
6476+ pBS->DataLength += info.CropW;
6477+ }
6478+
6479+ for (mfxU16 i = 0; i < info.CropH / 2; i++) {
6480+ MSDK_MEMCPY(pBS->Data + pBS->DataLength,
6481+ data.UV + (info.CropY * data.Pitch + info.CropX) + i * data.Pitch,
6482+ info.CropW);
6483+ pBS->DataLength += info.CropW;
6484+ }
6485+
6486+ return MFX_ERR_NONE;
6487+}
6488+
6489+mfxStatus CTranscodingPipeline::RGB4toBS(mfxFrameSurface1 *pSurface, mfxBitstreamWrapper *pBS) {
6490+ mfxFrameInfo &info = pSurface->Info;
6491+ mfxFrameData &data = pSurface->Data;
6492+ if ((int)pBS->MaxLength - (int)pBS->DataLength < (int)(info.CropH * info.CropW * 4)) {
6493+ pBS->Extend(pBS->DataLength + (int)(info.CropH * info.CropW * 4));
6494+ }
6495+
6496+ for (mfxU16 i = 0; i < info.CropH; i++) {
6497+ MSDK_MEMCPY(pBS->Data + pBS->DataLength,
6498+ data.B + (info.CropY * data.Pitch + info.CropX * 4) + i * data.Pitch,
6499+ info.CropW * 4);
6500+ pBS->DataLength += info.CropW * 4;
6501+ }
6502+
6503+ return MFX_ERR_NONE;
6504+}
6505+
6506+mfxStatus CTranscodingPipeline::YUY2toBS(mfxFrameSurface1 *pSurface, mfxBitstreamWrapper *pBS) {
6507+ mfxFrameInfo &info = pSurface->Info;
6508+ mfxFrameData &data = pSurface->Data;
6509+ if ((int)pBS->MaxLength - (int)pBS->DataLength < (int)(info.CropH * info.CropW * 4)) {
6510+ pBS->Extend(pBS->DataLength + (int)(info.CropH * info.CropW * 4));
6511+ }
6512+
6513+ for (mfxU16 i = 0; i < info.CropH; i++) {
6514+ MSDK_MEMCPY(pBS->Data + pBS->DataLength,
6515+ data.Y + (info.CropY * data.Pitch + info.CropX / 2 * 4) + i * data.Pitch,
6516+ info.CropW * 2);
6517+ pBS->DataLength += info.CropW * 2;
6518+ }
6519+
6520+ return MFX_ERR_NONE;
6521+}
6522+
6523+#if !defined(MFX_ONEVPL)
6524+mfxStatus CTranscodingPipeline::AllocMVCSeqDesc() {
6525+ auto mvc = m_mfxDecParams.AddExtBuffer<mfxExtMVCSeqDesc>();
6526+ mvc->View = new mfxMVCViewDependency[mvc->NumView];
6527+ mvc->NumViewAlloc = mvc->NumView;
6528+
6529+ mvc->ViewId = new mfxU16[mvc->NumViewId];
6530+ mvc->NumViewIdAlloc = mvc->NumViewId;
6531+
6532+ mvc->OP = new mfxMVCOperationPoint[mvc->NumOP];
6533+ mvc->NumOPAlloc = mvc->NumOP;
6534+
6535+ return MFX_ERR_NONE;
6536+}
6537+
6538+void CTranscodingPipeline::FreeMVCSeqDesc() {
6539+ mfxExtMVCSeqDesc *mvc = m_mfxDecParams;
6540+ if (m_bOwnMVCSeqDescMemory && mvc) {
6541+ MSDK_SAFE_DELETE_ARRAY(mvc->View);
6542+ MSDK_SAFE_DELETE_ARRAY(mvc->ViewId);
6543+ MSDK_SAFE_DELETE_ARRAY(mvc->OP);
6544+ }
6545+}
6546+#endif
6547+mfxStatus CTranscodingPipeline::InitDecMfxParams(sInputParams *pInParams) {
6548+ mfxStatus sts = MFX_ERR_NONE;
6549+ MSDK_CHECK_POINTER(pInParams, MFX_ERR_NULL_PTR);
6550+
6551+ m_mfxDecParams.AsyncDepth = m_AsyncDepth;
6552+
6553+#if !defined(MFX_ONEVPL)
6554+ if (pInParams->bIsMVC)
6555+ m_mfxDecParams.AddExtBuffer<mfxExtMVCSeqDesc>();
6556+#endif
6557+ if (!m_bUseOverlay) {
6558+ // read a portion of data for DecodeHeader function
6559+ sts = m_pBSProcessor->GetInputBitstream(&m_pmfxBS);
6560+ if (MFX_ERR_MORE_DATA == sts)
6561+ return sts;
6562+ else
6563+ MSDK_CHECK_STATUS(sts, "m_pBSProcessor->GetInputBitstream failed");
6564+
6565+ // try to find a sequence header in the stream
6566+ // if header is not found this function exits with error (e.g. if device was lost and there's no header in the remaining stream)
6567+ for (;;) {
6568+ // trying to find PicStruct information in AVI headers
6569+ if (pInParams->DecodeId == MFX_CODEC_JPEG)
6570+ MJPEG_AVI_ParsePicStruct(m_pmfxBS);
6571+
6572+ // parse bit stream and fill mfx params
6573+ sts = m_pmfxDEC->DecodeHeader(m_pmfxBS, &m_mfxDecParams);
6574+
6575+ if (MFX_ERR_MORE_DATA == sts) {
6576+ if (m_pmfxBS->MaxLength == m_pmfxBS->DataLength) {
6577+ m_pmfxBS->Extend(m_pmfxBS->MaxLength * 2);
6578+ }
6579+
6580+ // read a portion of data for DecodeHeader function
6581+ sts = m_pBSProcessor->GetInputBitstream(&m_pmfxBS);
6582+ if (MFX_ERR_MORE_DATA == sts)
6583+ return sts;
6584+ else
6585+ MSDK_CHECK_STATUS(sts, "m_pBSProcessor->GetInputBitstream failed");
6586+
6587+ continue;
6588+ }
6589+#if !defined(MFX_ONEVPL)
6590+ else if (MFX_ERR_NOT_ENOUGH_BUFFER == sts && pInParams->bIsMVC) {
6591+ sts = AllocMVCSeqDesc();
6592+ MSDK_CHECK_STATUS(sts, "m_pmfxDEC->DecodeHeader failed");
6593+
6594+ continue;
6595+ }
6596+#endif
6597+ else
6598+ break;
6599+ }
6600+
6601+ // to enable decorative flags, has effect with 1.3 API libraries only
6602+ // (in case of JPEG decoder - it is not valid to use this field)
6603+ if (m_mfxDecParams.mfx.CodecId != MFX_CODEC_JPEG)
6604+ m_mfxDecParams.mfx.ExtendedPicStruct = 1;
6605+
6606+ // check DecodeHeader status
6607+ if (MFX_WRN_PARTIAL_ACCELERATION == sts) {
6608+ msdk_printf(MSDK_STRING("WARNING: partial acceleration\n"));
6609+ MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION);
6610+ }
6611+ MSDK_CHECK_STATUS(sts, "m_pmfxDEC->DecodeHeader failed");
6612+
6613+ // if input is interlaced JPEG stream
6614+ if (((pInParams->DecodeId == MFX_CODEC_JPEG) &&
6615+ (m_pmfxBS->PicStruct == MFX_PICSTRUCT_FIELD_TFF)) ||
6616+ (m_pmfxBS->PicStruct == MFX_PICSTRUCT_FIELD_BFF)) {
6617+ m_mfxDecParams.mfx.FrameInfo.CropH *= 2;
6618+ m_mfxDecParams.mfx.FrameInfo.Height = MSDK_ALIGN16(m_mfxDecParams.mfx.FrameInfo.CropH);
6619+ m_mfxDecParams.mfx.FrameInfo.PicStruct = m_pmfxBS->PicStruct;
6620+ }
6621+ }
6622+ else {
6623+ m_mfxDecParams.mfx.FrameInfo.Width = MSDK_ALIGN32(pInParams->nVppCompSrcW);
6624+ m_mfxDecParams.mfx.FrameInfo.Height = MSDK_ALIGN32(pInParams->nVppCompSrcH);
6625+ m_mfxDecParams.mfx.FrameInfo.CropW = pInParams->nVppCompSrcW;
6626+ m_mfxDecParams.mfx.FrameInfo.CropH = pInParams->nVppCompSrcH;
6627+
6628+ m_mfxDecParams.mfx.FrameInfo.AspectRatioW = m_mfxDecParams.mfx.FrameInfo.AspectRatioH = 1;
6629+ m_mfxDecParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
6630+ m_mfxDecParams.mfx.FrameInfo.FourCC = MFX_FOURCC_RGB4;
6631+ }
6632+
6633+ // set memory pattern
6634+ if (pInParams->bForceSysMem || (MFX_IMPL_SOFTWARE == pInParams->libType) ||
6635+ (pInParams->DecOutPattern == MFX_IOPATTERN_OUT_SYSTEM_MEMORY))
6636+ m_mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
6637+ else
6638+ m_mfxDecParams.IOPattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
6639+
6640+ // if frame rate specified by user set it for decoder output
6641+ if (pInParams->dDecoderFrameRateOverride) {
6642+ ConvertFrameRate(pInParams->dDecoderFrameRateOverride,
6643+ &m_mfxDecParams.mfx.FrameInfo.FrameRateExtN,
6644+ &m_mfxDecParams.mfx.FrameInfo.FrameRateExtD);
6645+ }
6646+ // if frame rate not specified and input stream header doesn't contain valid values use default (30.0)
6647+ else if (0 == (m_mfxDecParams.mfx.FrameInfo.FrameRateExtN *
6648+ m_mfxDecParams.mfx.FrameInfo.FrameRateExtD)) {
6649+ m_mfxDecParams.mfx.FrameInfo.FrameRateExtN = 30;
6650+ m_mfxDecParams.mfx.FrameInfo.FrameRateExtD = 1;
6651+ }
6652+ else {
6653+ // use the value from input stream header
6654+ }
6655+
6656+ //--- Force setting fourcc type if required
6657+ if (pInParams->DecoderFourCC) {
6658+ m_mfxDecParams.mfx.FrameInfo.FourCC = pInParams->DecoderFourCC;
6659+ m_mfxDecParams.mfx.FrameInfo.ChromaFormat = FourCCToChroma(pInParams->DecoderFourCC);
6660+ }
6661+
6662+#if MFX_VERSION >= 1022
6663+ /* SFC usage if enabled */
6664+ if (pInParams->bDecoderPostProcessing) {
6665+ auto decPostProc = m_mfxDecParams.AddExtBuffer<mfxExtDecVideoProcessing>();
6666+ decPostProc->In.CropX = 0;
6667+ decPostProc->In.CropY = 0;
6668+ decPostProc->In.CropW = m_mfxDecParams.mfx.FrameInfo.CropW;
6669+ decPostProc->In.CropH = m_mfxDecParams.mfx.FrameInfo.CropH;
6670+
6671+ decPostProc->Out.FourCC = m_mfxDecParams.mfx.FrameInfo.FourCC;
6672+ decPostProc->Out.ChromaFormat = m_mfxDecParams.mfx.FrameInfo.ChromaFormat;
6673+ decPostProc->Out.CropX = 0;
6674+ decPostProc->Out.CropY = 0;
6675+ decPostProc->Out.CropW =
6676+ pInParams->eModeExt == VppComp ? pInParams->nVppCompDstW : pInParams->nDstWidth;
6677+ decPostProc->Out.CropH =
6678+ pInParams->eModeExt == VppComp ? pInParams->nVppCompDstH : pInParams->nDstHeight;
6679+ decPostProc->Out.Width = MSDK_ALIGN16(decPostProc->Out.CropW);
6680+ decPostProc->Out.Height = MSDK_ALIGN16(decPostProc->Out.CropH);
6681+ }
6682+#endif
6683+
6684+ return MFX_ERR_NONE;
6685+} // mfxStatus CTranscodingPipeline::InitDecMfxParams()
6686+
6687+void CTranscodingPipeline::FillFrameInfoForEncoding(mfxFrameInfo &info, sInputParams *pInParams) {
6688+ // Getting parameters from previous blocks
6689+ if (m_bIsVpp) {
6690+ MSDK_MEMCPY_VAR(info, &m_mfxVppParams.vpp.Out, sizeof(mfxFrameInfo));
6691+ }
6692+ else if (m_bIsPlugin) {
6693+ info = m_mfxPluginParams.vpp.Out;
6694+ }
6695+ else {
6696+ info = GetFrameInfo(m_mfxDecParams);
6697+ }
6698+
6699+ if (pInParams->dEncoderFrameRateOverride) {
6700+ ConvertFrameRate(pInParams->dEncoderFrameRateOverride,
6701+ &info.FrameRateExtN,
6702+ &info.FrameRateExtD);
6703+ }
6704+ else if (pInParams->dVPPOutFramerate) {
6705+ ConvertFrameRate(pInParams->dVPPOutFramerate, &info.FrameRateExtN, &info.FrameRateExtD);
6706+ }
6707+}
6708+
6709+mfxStatus CTranscodingPipeline::InitEncMfxParams(sInputParams *pInParams) {
6710+ MSDK_CHECK_POINTER(pInParams, MFX_ERR_NULL_PTR);
6711+
6712+ FillFrameInfoForEncoding(m_mfxEncParams.mfx.FrameInfo, pInParams);
6713+
6714+ MSDK_CHECK_ERROR(
6715+ m_mfxEncParams.mfx.FrameInfo.FrameRateExtN * m_mfxEncParams.mfx.FrameInfo.FrameRateExtD,
6716+ 0,
6717+ MFX_ERR_INVALID_VIDEO_PARAM);
6718+
6719+ m_mfxEncParams.mfx.CodecId = pInParams->EncodeId;
6720+ m_mfxEncParams.mfx.TargetUsage = pInParams->nTargetUsage; // trade-off between quality and speed
6721+ m_mfxEncParams.AsyncDepth = m_AsyncDepth;
6722+
6723+#if !defined(MFX_ONEVPL)
6724+ #if (MFX_VERSION >= 1025)
6725+ if (pInParams->numMFEFrames || pInParams->MFMode) {
6726+ auto mfePar = m_mfxEncParams.AddExtBuffer<mfxExtMultiFrameParam>();
6727+ mfePar->MaxNumFrames = pInParams->numMFEFrames;
6728+ mfePar->MFMode = pInParams->MFMode;
6729+ }
6730+
6731+ if (pInParams->mfeTimeout) {
6732+ auto mfeCtrl = m_mfxEncParams.AddExtBuffer<mfxExtMultiFrameControl>();
6733+ mfeCtrl->Timeout = pInParams->mfeTimeout;
6734+ }
6735+ #endif
6736+#endif //!MFX_ONEVPL
6737+
6738+#if !defined(MFX_ONEVPL)
6739+ if (m_pParentPipeline && m_pParentPipeline->m_pmfxPreENC.get()) {
6740+ m_mfxEncParams.mfx.RateControlMethod = MFX_RATECONTROL_LA_EXT;
6741+ m_mfxEncParams.mfx.EncodedOrder =
6742+ 1; // binary flag, 0 signals encoder to take frames in display order
6743+ m_mfxEncParams.AsyncDepth = m_mfxEncParams.AsyncDepth == 0 ? 2 : m_mfxEncParams.AsyncDepth;
6744+ }
6745+ else
6746+#endif //!MFX_ONEVPL
6747+ {
6748+ m_mfxEncParams.mfx.RateControlMethod = pInParams->nRateControlMethod;
6749+ }
6750+ m_mfxEncParams.mfx.NumSlice = pInParams->nSlices;
6751+
6752+ if (pInParams->nRateControlMethod == MFX_RATECONTROL_CQP) {
6753+ m_mfxEncParams.mfx.QPI = pInParams->nQPI;
6754+ m_mfxEncParams.mfx.QPP = pInParams->nQPP;
6755+ m_mfxEncParams.mfx.QPB = pInParams->nQPB;
6756+ }
6757+
6758+ if (pInParams->enableQSVFF) {
6759+ m_mfxEncParams.mfx.LowPower = MFX_CODINGOPTION_ON;
6760+ }
6761+
6762+ // leave PAR unset to avoid MPEG2 encoder rejecting streams with unsupported DAR
6763+ m_mfxEncParams.mfx.FrameInfo.AspectRatioW = m_mfxEncParams.mfx.FrameInfo.AspectRatioH = 0;
6764+
6765+ // calculate default bitrate based on resolution and framerate
6766+ if (pInParams->EncoderPicstructOverride) {
6767+ m_mfxEncParams.mfx.FrameInfo.PicStruct = pInParams->EncoderPicstructOverride;
6768+ }
6769+
6770+ MSDK_CHECK_ERROR(
6771+ m_mfxEncParams.mfx.FrameInfo.FrameRateExtN * m_mfxEncParams.mfx.FrameInfo.FrameRateExtD,
6772+ 0,
6773+ MFX_ERR_INVALID_VIDEO_PARAM);
6774+
6775+ if (pInParams->nRateControlMethod != MFX_RATECONTROL_CQP) {
6776+ if (pInParams->nBitRate == 0) {
6777+ pInParams->nBitRate =
6778+ CalculateDefaultBitrate(pInParams->EncodeId,
6779+ pInParams->nTargetUsage,
6780+ m_mfxEncParams.mfx.FrameInfo.Width,
6781+ m_mfxEncParams.mfx.FrameInfo.Height,
6782+ 1.0 * m_mfxEncParams.mfx.FrameInfo.FrameRateExtN /
6783+ m_mfxEncParams.mfx.FrameInfo.FrameRateExtD);
6784+ }
6785+ m_mfxEncParams.mfx.TargetKbps = pInParams->nBitRate; // in Kbps
6786+ m_mfxEncParams.mfx.BRCParamMultiplier = pInParams->nBitRateMultiplier;
6787+ }
6788+
6789+ // In case of HEVC when height and/or width divided with 8 but not divided with 16
6790+ // add extended parameter to increase performance
6791+ if ((!((m_mfxEncParams.mfx.FrameInfo.CropW & 15) ^ 8) ||
6792+ !((m_mfxEncParams.mfx.FrameInfo.CropH & 15) ^ 8)) &&
6793+ (m_mfxEncParams.mfx.CodecId == MFX_CODEC_HEVC)) {
6794+ auto hevcPar = m_mfxEncParams.AddExtBuffer<mfxExtHEVCParam>();
6795+ hevcPar->PicWidthInLumaSamples = m_mfxEncParams.mfx.FrameInfo.CropW;
6796+ hevcPar->PicHeightInLumaSamples = m_mfxEncParams.mfx.FrameInfo.CropH;
6797+ }
6798+
6799+#if !defined(MFX_ONEVPL)
6800+ #if (MFX_VERSION >= 1024)
6801+ // This is for explicit extbrc only. In case of implicit (built-into-library) version - we don't need this extended buffer
6802+ if (pInParams->nExtBRC == EXTBRC_ON &&
6803+ (pInParams->EncodeId == MFX_CODEC_HEVC || pInParams->EncodeId == MFX_CODEC_AVC)) {
6804+ auto extbrc = m_mfxEncParams.AddExtBuffer<mfxExtBRC>();
6805+ HEVCExtBRC::Create(*extbrc);
6806+ }
6807+ #endif
6808+#endif
6809+
6810+ m_mfxEncParams.mfx.FrameInfo.CropX = 0;
6811+ m_mfxEncParams.mfx.FrameInfo.CropY = 0;
6812+
6813+ mfxU16 InPatternFromParent =
6814+ (mfxU16)((MFX_IOPATTERN_OUT_VIDEO_MEMORY == m_mfxDecParams.IOPattern)
6815+ ? MFX_IOPATTERN_IN_VIDEO_MEMORY
6816+ : MFX_IOPATTERN_IN_SYSTEM_MEMORY);
6817+
6818+ // set memory pattern
6819+ m_mfxEncParams.IOPattern = InPatternFromParent;
6820+
6821+ if (pInParams->nEncTileRows && pInParams->nEncTileCols) {
6822+ if (m_mfxEncParams.mfx.CodecId == MFX_CODEC_HEVC) {
6823+ auto tiles = m_mfxEncParams.AddExtBuffer<mfxExtHEVCTiles>();
6824+ tiles->NumTileRows = pInParams->nEncTileRows;
6825+ tiles->NumTileColumns = pInParams->nEncTileCols;
6826+ }
6827+#if MFX_VERSION >= 1029
6828+ else if (m_mfxEncParams.mfx.CodecId == MFX_CODEC_VP9) {
6829+ auto vp9par = m_mfxEncParams.AddExtBuffer<mfxExtVP9Param>();
6830+ vp9par->NumTileRows = pInParams->nEncTileRows;
6831+ vp9par->NumTileColumns = pInParams->nEncTileCols;
6832+ }
6833+#endif
6834+ }
6835+
6836+ if (pInParams->nAvcTemp) {
6837+ if (pInParams->EncodeId == MFX_CODEC_HEVC) {
6838+ auto tl = m_mfxEncParams.AddExtBuffer<mfxExtAvcTemporalLayers>();
6839+ tl->BaseLayerPID = pInParams->nBaseLayerPID;
6840+ for (int i = 0; i < 8; i++) {
6841+ tl->Layer[i].Scale = pInParams->nAvcTemporalLayers[i];
6842+ }
6843+ }
6844+ }
6845+
6846+ if (pInParams->nSPSId || pInParams->nPPSId) {
6847+ if (pInParams->EncodeId == MFX_CODEC_HEVC) {
6848+ auto spspps = m_mfxEncParams.AddExtBuffer<mfxExtCodingOptionSPSPPS>();
6849+ spspps->SPSId = pInParams->nSPSId;
6850+ spspps->PPSId = pInParams->nPPSId;
6851+ }
6852+ }
6853+
6854+ if (pInParams->nPicTimingSEI || pInParams->nNalHrdConformance ||
6855+ pInParams->nVuiNalHrdParameters) {
6856+ auto co = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption>();
6857+ co->PicTimingSEI = pInParams->nPicTimingSEI;
6858+ co->NalHrdConformance = pInParams->nNalHrdConformance;
6859+ co->VuiNalHrdParameters = pInParams->nVuiNalHrdParameters;
6860+ }
6861+
6862+#if !defined(MFX_ONEVPL)
6863+ // we don't specify profile and level and let the encoder choose those basing on parameters
6864+ // we must specify profile only for MVC codec
6865+ if (pInParams->bIsMVC) {
6866+ m_mfxEncParams.mfx.CodecProfile = m_mfxDecParams.mfx.CodecProfile;
6867+ }
6868+#endif
6869+
6870+ // JPEG encoder settings overlap nasc other encoders settings in mfxInfoMFX structure
6871+ if (MFX_CODEC_JPEG == pInParams->EncodeId) {
6872+ m_mfxEncParams.mfx.Interleaved = 1;
6873+ m_mfxEncParams.mfx.Quality = pInParams->nQuality;
6874+ m_mfxEncParams.mfx.RestartInterval = 0;
6875+ MSDK_ZERO_MEMORY(m_mfxEncParams.mfx.reserved5);
6876+ }
6877+
6878+ // configure and attach external parameters
6879+ if (pInParams->bLABRC || pInParams->nMaxSliceSize || pInParams->nBRefType ||
6880+ (pInParams->BitrateLimit && pInParams->EncodeId == MFX_CODEC_AVC) ||
6881+ (pInParams->nExtBRC &&
6882+ (pInParams->EncodeId == MFX_CODEC_HEVC || pInParams->EncodeId == MFX_CODEC_AVC)) ||
6883+ pInParams->IntRefType || pInParams->IntRefCycleSize || pInParams->IntRefQPDelta ||
6884+ pInParams->nMaxFrameSize || pInParams->AdaptiveI || pInParams->AdaptiveB) {
6885+ auto co2 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption2>();
6886+ co2->LookAheadDepth = pInParams->nLADepth;
6887+ co2->MaxSliceSize = pInParams->nMaxSliceSize;
6888+ co2->MaxFrameSize = pInParams->nMaxFrameSize;
6889+ co2->BRefType = pInParams->nBRefType;
6890+ co2->BitrateLimit = pInParams->BitrateLimit;
6891+
6892+ co2->IntRefType = pInParams->IntRefType;
6893+ co2->IntRefCycleSize = pInParams->IntRefCycleSize;
6894+ co2->IntRefQPDelta = pInParams->IntRefQPDelta;
6895+ co2->AdaptiveI = pInParams->AdaptiveI;
6896+ co2->AdaptiveB = pInParams->AdaptiveB;
6897+
6898+ if (pInParams->nExtBRC != EXTBRC_DEFAULT &&
6899+ (pInParams->EncodeId == MFX_CODEC_HEVC || pInParams->EncodeId == MFX_CODEC_AVC)) {
6900+ co2->ExtBRC = (mfxU16)(pInParams->nExtBRC == EXTBRC_OFF ? MFX_CODINGOPTION_OFF
6901+ : MFX_CODINGOPTION_ON);
6902+ }
6903+ else {
6904+ co2->ExtBRC = MFX_CODINGOPTION_UNKNOWN;
6905+ }
6906+ }
6907+
6908+ if (pInParams->WinBRCMaxAvgKbps || pInParams->WinBRCSize) {
6909+ auto co3 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption3>();
6910+ co3->WinBRCMaxAvgKbps = pInParams->WinBRCMaxAvgKbps;
6911+ co3->WinBRCSize = pInParams->WinBRCSize;
6912+ }
6913+#if MFX_VERSION >= 1022
6914+ if (pInParams->bROIasQPMAP || pInParams->bExtMBQP) {
6915+ auto co3 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption3>();
6916+ // QP map defines QP value for every 16x16 sub-block of a frame
6917+ m_QPmapWidth = (m_mfxEncParams.mfx.FrameInfo.Width + 15) >> 4;
6918+ m_QPmapHeight = (m_mfxEncParams.mfx.FrameInfo.Height + 15) >> 4;
6919+ co3->EnableMBQP = MFX_CODINGOPTION_ON;
6920+ }
6921+#endif
6922+
6923+ if (pInParams->WeightedPred || pInParams->WeightedBiPred || pInParams->IntRefCycleDist ||
6924+ pInParams->nAdaptiveMaxFrameSize || pInParams->LowDelayBRC) {
6925+ auto co3 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption3>();
6926+ co3->WeightedPred = pInParams->WeightedPred;
6927+ co3->WeightedBiPred = pInParams->WeightedBiPred;
6928+ co3->LowDelayBRC = pInParams->LowDelayBRC;
6929+ co3->IntRefCycleDist = pInParams->IntRefCycleDist;
6930+ co3->AdaptiveMaxFrameSize = pInParams->nAdaptiveMaxFrameSize;
6931+ }
6932+#if (MFX_VERSION >= 1026)
6933+ if (pInParams->ExtBrcAdaptiveLTR) {
6934+ auto co3 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption3>();
6935+ co3->ExtBrcAdaptiveLTR = pInParams->ExtBrcAdaptiveLTR;
6936+ }
6937+#endif
6938+#if MFX_VERSION >= 1023
6939+ if (pInParams->RepartitionCheckMode) {
6940+ auto co3 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption3>();
6941+ co3->RepartitionCheckEnable = pInParams->RepartitionCheckMode;
6942+ }
6943+#endif
6944+
6945+ if (pInParams->GPB) {
6946+ auto co3 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption3>();
6947+ co3->GPB = pInParams->GPB;
6948+ }
6949+#if (MFX_VERSION >= 1026)
6950+ if (pInParams->nTransformSkip) {
6951+ auto co3 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption3>();
6952+ co3->TransformSkip = pInParams->nTransformSkip;
6953+ }
6954+#endif
6955+ if (pInParams->bDisableQPOffset) {
6956+ auto co3 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption3>();
6957+ co3->EnableQPOffset = MFX_CODINGOPTION_OFF;
6958+ }
6959+
6960+#if !defined(MFX_ONEVPL)
6961+ if (pInParams->bIsMVC)
6962+ m_mfxEncParams.AddExtBuffer<mfxExtMVCSeqDesc>();
6963+#endif
6964+
6965+#if (MFX_VERSION >= 1027)
6966+ if (pInParams->TargetBitDepthLuma) {
6967+ auto co3 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption3>();
6968+ co3->TargetBitDepthLuma = pInParams->TargetBitDepthLuma;
6969+ }
6970+ if (pInParams->TargetBitDepthChroma) {
6971+ auto co3 = m_mfxEncParams.AddExtBuffer<mfxExtCodingOption3>();
6972+ co3->TargetBitDepthChroma = pInParams->TargetBitDepthChroma;
6973+ }
6974+#endif
6975+
6976+#if !defined(MFX_ONEVPL)
6977+ if (m_pParentPipeline) {
6978+ m_pParentPipeline->AddLaStreams(m_mfxEncParams.mfx.FrameInfo.Width,
6979+ m_mfxEncParams.mfx.FrameInfo.Height);
6980+ }
6981+#endif //!MFX_ONEVPL
6982+
6983+ //--- Settings HRD buffer size
6984+ if (pInParams->BufferSizeInKB) {
6985+ m_mfxEncParams.mfx.BufferSizeInKB = pInParams->BufferSizeInKB;
6986+ }
6987+
6988+ //--- Force setting fourcc type if required
6989+ if (pInParams->EncoderFourCC) {
6990+ m_mfxEncParams.mfx.FrameInfo.FourCC = pInParams->EncoderFourCC;
6991+ m_mfxEncParams.mfx.FrameInfo.ChromaFormat = FourCCToChroma(pInParams->EncoderFourCC);
6992+ }
6993+
6994+ // GopPicSize and GopRefDist values are always set using presets manager, but do not set them for JPEG
6995+ if (MFX_CODEC_JPEG != pInParams->EncodeId) {
6996+ m_mfxEncParams.mfx.GopPicSize = pInParams->GopPicSize;
6997+ m_mfxEncParams.mfx.GopRefDist = pInParams->GopRefDist;
6998+ }
6999+
7000+ if (pInParams->NumRefFrame) {
7001+ m_mfxEncParams.mfx.NumRefFrame = pInParams->NumRefFrame;
7002+ }
7003+
7004+ if (pInParams->CodecLevel) {
7005+ m_mfxEncParams.mfx.CodecLevel = pInParams->CodecLevel;
7006+ }
7007+
7008+ if (pInParams->CodecProfile) {
7009+ m_mfxEncParams.mfx.CodecProfile = pInParams->CodecProfile;
7010+ }
7011+
7012+ if (pInParams->GopOptFlag) {
7013+ m_mfxEncParams.mfx.GopOptFlag = pInParams->GopOptFlag;
7014+ }
7015+
7016+ if (pInParams->MaxKbps) {
7017+ m_mfxEncParams.mfx.MaxKbps = pInParams->MaxKbps;
7018+ }
7019+
7020+ if (pInParams->InitialDelayInKB) {
7021+ m_mfxEncParams.mfx.InitialDelayInKB = pInParams->InitialDelayInKB;
7022+ }
7023+
7024+ return MFX_ERR_NONE;
7025+} // mfxStatus CTranscodingPipeline::InitEncMfxParams(sInputParams *pInParams)
7026+
7027+#if !defined(MFX_ONEVPL)
7028+mfxStatus CTranscodingPipeline::CorrectPreEncAuxPool(mfxU32 num_frames_in_pool) {
7029+ if (!m_pmfxPreENC)
7030+ return MFX_ERR_NONE;
7031+
7032+ if (m_pPreEncAuxPool.size() < num_frames_in_pool) {
7033+ m_pPreEncAuxPool.resize(num_frames_in_pool);
7034+ }
7035+ return MFX_ERR_NONE;
7036+}
7037+
7038+mfxStatus CTranscodingPipeline::AllocPreEncAuxPool() {
7039+ if (!m_pmfxPreENC)
7040+ return MFX_ERR_NONE;
7041+
7042+ auto laCtrl = m_mfxPreEncParams.AddExtBuffer<mfxExtLAControl>();
7043+ mfxU16 num_resolutions = laCtrl->NumOutStream;
7044+ int buff_size = sizeof(mfxExtLAFrameStatistics) +
7045+ sizeof(mfxLAFrameInfo) * num_resolutions * laCtrl->LookAheadDepth;
7046+
7047+ for (size_t i = 0; i < m_pPreEncAuxPool.size(); i++) {
7048+ memset(&m_pPreEncAuxPool[i], 0, sizeof(m_pPreEncAuxPool[i]));
7049+
7050+ m_pPreEncAuxPool[i].encCtrl.NumExtParam = 1;
7051+ m_pPreEncAuxPool[i].encCtrl.ExtParam = new mfxExtBuffer *[1];
7052+
7053+ char *pBuff = new char[buff_size];
7054+ memset(pBuff, 0, buff_size);
7055+
7056+ m_pPreEncAuxPool[i].encCtrl.ExtParam[0] = (mfxExtBuffer *)pBuff;
7057+ mfxExtLAFrameStatistics *pExtBuffer = (mfxExtLAFrameStatistics *)pBuff;
7058+
7059+ pExtBuffer = (mfxExtLAFrameStatistics *)pBuff;
7060+ pExtBuffer->Header.BufferId = MFX_EXTBUFF_LOOKAHEAD_STAT;
7061+ pExtBuffer->Header.BufferSz = buff_size;
7062+ pExtBuffer->NumAlloc = num_resolutions * laCtrl->LookAheadDepth;
7063+ pExtBuffer->FrameStat = (mfxLAFrameInfo *)(pBuff + sizeof(mfxExtLAFrameStatistics));
7064+
7065+ m_pPreEncAuxPool[i].encOutput.NumExtParam = 1;
7066+ m_pPreEncAuxPool[i].encOutput.ExtParam = m_pPreEncAuxPool[i].encCtrl.ExtParam;
7067+ }
7068+ return MFX_ERR_NONE;
7069+}
7070+
7071+void CTranscodingPipeline::FreePreEncAuxPool() {
7072+ for (size_t i = 0; i < m_pPreEncAuxPool.size(); i++) {
7073+ if (m_pPreEncAuxPool[i].encCtrl.ExtParam) {
7074+ delete[] m_pPreEncAuxPool[i].encCtrl.ExtParam[0];
7075+ delete[] m_pPreEncAuxPool[i].encCtrl.ExtParam;
7076+ }
7077+ }
7078+ m_pPreEncAuxPool.resize(0);
7079+}
7080+#endif //!MFX_ONEVPL
7081+
7082+mfxStatus TranscodingSample::CTranscodingPipeline::LoadStaticSurface() {
7083+ if (m_bUseOverlay) {
7084+ mfxFrameSurface1 *pSurf = m_pSurfaceDecPool[0];
7085+ mfxStatus sts = m_pMFXAllocator->LockFrame(pSurf->Data.MemId, &pSurf->Data);
7086+ MSDK_CHECK_STATUS(sts, "m_pMFXAllocator->LockFrame failed");
7087+ sts = m_pBSProcessor->GetInputFrame(pSurf);
7088+ MSDK_CHECK_STATUS(sts, "m_YUVReader->LoadNextFrame failed");
7089+ sts = m_pMFXAllocator->UnlockFrame(pSurf->Data.MemId, &pSurf->Data);
7090+ MSDK_CHECK_STATUS(sts, "m_pMFXAllocator->UnlockFrame failed");
7091+ }
7092+ return MFX_ERR_NONE;
7093+}
7094+
7095+#if !defined(MFX_ONEVPL)
7096+mfxStatus CTranscodingPipeline::InitPreEncMfxParams(sInputParams *pInParams) {
7097+ MSDK_CHECK_ERROR(pInParams->bEnableExtLA, false, MFX_ERR_INVALID_VIDEO_PARAM);
7098+ MSDK_CHECK_POINTER(pInParams, MFX_ERR_NULL_PTR);
7099+
7100+ mfxVideoParam &param = m_mfxPreEncParams;
7101+
7102+ param.AsyncDepth = m_AsyncDepth;
7103+
7104+ MSDK_ZERO_MEMORY(param.mfx);
7105+ param.mfx.CodecId = MFX_CODEC_AVC;
7106+ param.mfx.TargetUsage = pInParams->nTargetUsage;
7107+
7108+ if (m_bIsVpp) {
7109+ MSDK_MEMCPY_VAR(param.mfx.FrameInfo, &m_mfxVppParams.vpp.Out, sizeof(mfxFrameInfo));
7110+ }
7111+ else if (m_bIsPlugin) {
7112+ MSDK_MEMCPY_VAR(param.mfx.FrameInfo, &m_mfxPluginParams.vpp.Out, sizeof(mfxFrameInfo));
7113+ }
7114+ else {
7115+ param.mfx.FrameInfo = GetFrameInfo(m_mfxDecParams);
7116+ }
7117+
7118+ mfxU16 InPatternFromParent =
7119+ (mfxU16)((MFX_IOPATTERN_OUT_VIDEO_MEMORY == m_mfxDecParams.IOPattern)
7120+ ? MFX_IOPATTERN_IN_VIDEO_MEMORY
7121+ : MFX_IOPATTERN_IN_SYSTEM_MEMORY);
7122+
7123+ // set memory pattern
7124+ param.IOPattern = InPatternFromParent;
7125+
7126+ auto laCtrl = m_mfxPreEncParams.AddExtBuffer<mfxExtLAControl>();
7127+ laCtrl->LookAheadDepth = pInParams->nLADepth ? pInParams->nLADepth : 40;
7128+ laCtrl->NumOutStream = 0;
7129+ laCtrl->BPyramid =
7130+ (mfxU16)(pInParams->bEnableBPyramid ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF);
7131+
7132+ m_mfxPreEncParams.mfx.GopPicSize = pInParams->GopPicSize ? pInParams->GopPicSize : 1500;
7133+
7134+ if (pInParams->GopRefDist) {
7135+ m_mfxPreEncParams.mfx.GopRefDist = pInParams->GopRefDist;
7136+ }
7137+
7138+ if (pInParams->nTargetUsage) {
7139+ m_mfxPreEncParams.mfx.TargetUsage = pInParams->nTargetUsage;
7140+ }
7141+
7142+ return MFX_ERR_NONE;
7143+}
7144+
7145+mfxStatus CTranscodingPipeline::AddLaStreams(mfxU16 width, mfxU16 height) {
7146+ if (m_pmfxPreENC.get() != NULL) {
7147+ auto laCtrl = m_mfxPreEncParams.AddExtBuffer<mfxExtLAControl>();
7148+ mfxU32 num = laCtrl->NumOutStream;
7149+ m_numEncoders++;
7150+ for (mfxU32 i = 0; i < num; i++) {
7151+ if (laCtrl->OutStream[i].Width == width && laCtrl->OutStream[i].Height == height)
7152+ return MFX_ERR_NONE;
7153+ }
7154+ if ((sizeof(laCtrl->OutStream) / sizeof(laCtrl->OutStream[0])) < (num + 1))
7155+ return MFX_ERR_UNSUPPORTED;
7156+
7157+ laCtrl->OutStream[num].Width = width;
7158+ laCtrl->OutStream[num].Height = height;
7159+ laCtrl->NumOutStream = (mfxU16)num + 1;
7160+ }
7161+ return MFX_ERR_NONE;
7162+}
7163+#endif //!MFX_ONEVPL
7164+
7165+mfxU32 CTranscodingPipeline::FileFourCC2EncFourCC(mfxU32 fcc) {
7166+ if (fcc == MFX_FOURCC_I420)
7167+ return MFX_FOURCC_NV12;
7168+ else
7169+ return fcc;
7170+}
7171+
7172+mfxStatus CTranscodingPipeline::InitVppMfxParams(sInputParams *pInParams) {
7173+ MSDK_CHECK_POINTER(pInParams, MFX_ERR_NULL_PTR);
7174+ m_mfxVppParams.AsyncDepth = m_AsyncDepth;
7175+
7176+ mfxU16 InPatternFromParent =
7177+ (mfxU16)((MFX_IOPATTERN_OUT_VIDEO_MEMORY == m_mfxDecParams.IOPattern)
7178+ ? MFX_IOPATTERN_IN_VIDEO_MEMORY
7179+ : MFX_IOPATTERN_IN_SYSTEM_MEMORY);
7180+
7181+ // set memory pattern
7182+ if (pInParams->VppOutPattern) {
7183+ m_mfxVppParams.IOPattern = (mfxU16)(InPatternFromParent | pInParams->VppOutPattern);
7184+ }
7185+ else if (pInParams->bForceSysMem || (MFX_IMPL_SOFTWARE == pInParams->libType)) {
7186+ m_mfxVppParams.IOPattern = (mfxU16)(InPatternFromParent | MFX_IOPATTERN_OUT_SYSTEM_MEMORY);
7187+ }
7188+ else {
7189+ m_mfxVppParams.IOPattern = (mfxU16)(InPatternFromParent | MFX_IOPATTERN_OUT_VIDEO_MEMORY);
7190+ }
7191+
7192+ // input frame info
7193+ m_mfxVppParams.vpp.In = GetFrameInfo(m_mfxDecParams);
7194+
7195+ if (m_mfxVppParams.vpp.In.Width * m_mfxVppParams.vpp.In.Height == 0) {
7196+ m_mfxVppParams.vpp.In.Width = MSDK_ALIGN32(pInParams->nDstWidth);
7197+ m_mfxVppParams.vpp.In.Height = MSDK_ALIGN32(pInParams->nDstHeight);
7198+ }
7199+
7200+ if (m_mfxVppParams.vpp.In.CropW * m_mfxVppParams.vpp.In.CropH == 0) {
7201+ m_mfxVppParams.vpp.In.CropW = pInParams->nDstWidth;
7202+ m_mfxVppParams.vpp.In.CropH = pInParams->nDstHeight;
7203+ }
7204+
7205+ if (m_mfxVppParams.vpp.In.FrameRateExtN * m_mfxVppParams.vpp.In.FrameRateExtD == 0) {
7206+ m_mfxVppParams.vpp.In.FrameRateExtN = 30;
7207+ m_mfxVppParams.vpp.In.FrameRateExtD = 1;
7208+ }
7209+
7210+ if (m_mfxVppParams.vpp.In.FourCC == 0) {
7211+ m_mfxVppParams.vpp.In.FourCC = FileFourCC2EncFourCC(pInParams->DecodeId);
7212+ m_mfxVppParams.mfx.FrameInfo.ChromaFormat = FourCCToChroma(pInParams->DecoderFourCC);
7213+ }
7214+
7215+ if (m_rawInput) {
7216+ m_mfxVppParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
7217+ }
7218+
7219+ // fill output frame info
7220+ MSDK_MEMCPY_VAR(m_mfxVppParams.vpp.Out, &m_mfxVppParams.vpp.In, sizeof(mfxFrameInfo));
7221+
7222+ if (m_bIsFieldWeaving) {
7223+ m_mfxVppParams.vpp.Out.PicStruct = MFX_PICSTRUCT_UNKNOWN;
7224+ m_mfxVppParams.vpp.Out.Height = m_mfxVppParams.vpp.In.Height << 1;
7225+ m_mfxVppParams.vpp.Out.CropH = m_mfxVppParams.vpp.In.CropH << 1;
7226+ }
7227+
7228+ if (m_bIsFieldSplitting) {
7229+ m_mfxVppParams.vpp.Out.PicStruct = MFX_PICSTRUCT_FIELD_SINGLE;
7230+ m_mfxVppParams.vpp.Out.Height = m_mfxVppParams.vpp.In.Height >> 1;
7231+ m_mfxVppParams.vpp.Out.CropH = m_mfxVppParams.vpp.In.CropH >> 1;
7232+ }
7233+ if (pInParams->bEnableDeinterlacing)
7234+ m_mfxVppParams.vpp.Out.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
7235+
7236+ // Resizing
7237+ if (pInParams->nDstWidth) {
7238+ m_mfxVppParams.vpp.Out.CropW = pInParams->nDstWidth;
7239+ m_mfxVppParams.vpp.Out.Width = MSDK_ALIGN16(pInParams->nDstWidth);
7240+ }
7241+
7242+ // Framerate conversion
7243+ if (pInParams->dVPPOutFramerate) {
7244+ ConvertFrameRate(pInParams->dVPPOutFramerate,
7245+ &m_mfxVppParams.vpp.Out.FrameRateExtN,
7246+ &m_mfxVppParams.vpp.Out.FrameRateExtD);
7247+ }
7248+
7249+ if (pInParams->nDstHeight) {
7250+ m_mfxVppParams.vpp.Out.CropH = pInParams->nDstHeight;
7251+ m_mfxVppParams.vpp.Out.Height =
7252+ (MFX_PICSTRUCT_PROGRESSIVE == m_mfxVppParams.vpp.Out.PicStruct)
7253+ ? MSDK_ALIGN16(pInParams->nDstHeight)
7254+ : MSDK_ALIGN32(pInParams->nDstHeight);
7255+ }
7256+
7257+ if (pInParams->bEnableDeinterlacing) {
7258+ // If stream were interlaced before then 32 bit alignment were applied.
7259+ // Discard 32 bit alignment as progressive doesn't require it.
7260+ m_mfxVppParams.vpp.Out.Height = MSDK_ALIGN16(m_mfxVppParams.vpp.Out.CropH);
7261+ m_mfxVppParams.vpp.Out.Width = MSDK_ALIGN16(m_mfxVppParams.vpp.Out.CropW);
7262+ }
7263+
7264+ // configure and attach external parameters
7265+ mfxStatus sts = AllocAndInitVppDoNotUse(pInParams);
7266+ MSDK_CHECK_STATUS(sts, "AllocAndInitVppDoNotUse failed");
7267+
7268+ //--- Setting output FourCC type (input type is taken from m_mfxDecParams)
7269+ if (pInParams->EncoderFourCC) {
7270+ m_mfxVppParams.vpp.Out.FourCC = pInParams->EncoderFourCC;
7271+ m_mfxVppParams.vpp.Out.ChromaFormat = FourCCToChroma(pInParams->EncoderFourCC);
7272+
7273+ // set bit depth according to FourCC, it must be not inherited from m_mfxVppParams.vpp.In
7274+ switch (m_mfxVppParams.vpp.Out.FourCC) {
7275+ case MFX_FOURCC_RGB4:
7276+ case MFX_FOURCC_YUY2:
7277+ case MFX_FOURCC_NV12:
7278+ case MFX_FOURCC_NV16:
7279+ m_mfxVppParams.vpp.Out.BitDepthLuma = m_mfxVppParams.vpp.Out.BitDepthChroma = 8;
7280+ break;
7281+ case MFX_FOURCC_P010:
7282+ case MFX_FOURCC_P210:
7283+#if (MFX_VERSION >= 1027)
7284+ case MFX_FOURCC_Y210:
7285+ case MFX_FOURCC_Y410:
7286+#endif
7287+ m_mfxVppParams.vpp.Out.BitDepthLuma = m_mfxVppParams.vpp.Out.BitDepthChroma = 10;
7288+ break;
7289+ default:
7290+ assert(0);
7291+ MSDK_CHECK_STATUS(MFX_ERR_UNSUPPORTED, "Unexpected encoder FourCC");
7292+ }
7293+ }
7294+
7295+ /* VPP Comp Init */
7296+ if (((pInParams->eModeExt == VppComp) || (pInParams->eModeExt == VppCompOnly)) &&
7297+ (pInParams->numSurf4Comp != 0)) {
7298+ if (m_nVPPCompEnable != VppCompOnlyEncode)
7299+ m_nVPPCompEnable = pInParams->eModeExt;
7300+
7301+ auto vppCompPar = m_mfxVppParams.AddExtBuffer<mfxExtVPPComposite>();
7302+ vppCompPar->NumInputStream = (mfxU16)pInParams->numSurf4Comp;
7303+ vppCompPar->InputStream = (mfxVPPCompInputStream *)malloc(sizeof(mfxVPPCompInputStream) *
7304+ vppCompPar->NumInputStream);
7305+ MSDK_CHECK_POINTER(vppCompPar->InputStream, MFX_ERR_NULL_PTR);
7306+
7307+ // stream params
7308+ /* if input streams in NV12 format background color should be in YUV format too
7309+ * The same for RGB4 input, background color should be in ARGB format
7310+ * */
7311+
7312+ switch (pInParams->EncoderFourCC) {
7313+ case MFX_FOURCC_RGB4:
7314+ /* back color in RGB */
7315+ vppCompPar->R = 0x00;
7316+ vppCompPar->G = 0x00;
7317+ vppCompPar->B = 0x00;
7318+ break;
7319+ case MFX_FOURCC_NV12:
7320+ case MFX_FOURCC_P010:
7321+ case MFX_FOURCC_NV16:
7322+ case MFX_FOURCC_P210:
7323+ case MFX_FOURCC_YUY2:
7324+ default:
7325+ /* back color in YUV */
7326+ vppCompPar->Y = 0x10;
7327+ vppCompPar->U = 0x80;
7328+ vppCompPar->V = 0x80;
7329+ break;
7330+ }
7331+
7332+#if MFX_VERSION >= 1024
7333+ vppCompPar->NumTiles = pInParams->numTiles4Comp;
7334+#endif
7335+
7336+ MSDK_CHECK_POINTER(pInParams->pVppCompDstRects, MFX_ERR_NULL_PTR);
7337+ for (mfxU32 i = 0; i < pInParams->numSurf4Comp; i++) {
7338+ vppCompPar->InputStream[i].DstX = pInParams->pVppCompDstRects[i].DstX;
7339+ vppCompPar->InputStream[i].DstY = pInParams->pVppCompDstRects[i].DstY;
7340+ vppCompPar->InputStream[i].DstW = pInParams->pVppCompDstRects[i].DstW;
7341+ vppCompPar->InputStream[i].DstH = pInParams->pVppCompDstRects[i].DstH;
7342+#if MFX_VERSION >= 1024
7343+ vppCompPar->InputStream[i].TileId = pInParams->pVppCompDstRects[i].TileId;
7344+#endif
7345+ vppCompPar->InputStream[i].GlobalAlpha = 0;
7346+ vppCompPar->InputStream[i].GlobalAlphaEnable = 0;
7347+ vppCompPar->InputStream[i].PixelAlphaEnable = 0;
7348+
7349+ vppCompPar->InputStream[i].LumaKeyEnable = 0;
7350+ vppCompPar->InputStream[i].LumaKeyMin = 0;
7351+ vppCompPar->InputStream[i].LumaKeyMax = 0;
7352+ }
7353+ }
7354+
7355+#if !defined(MFX_ONEVPL)
7356+ if (pInParams->bIsMVC)
7357+ m_mfxVppParams.AddExtBuffer<mfxExtMVCSeqDesc>();
7358+#endif
7359+
7360+ mfxU32 enhFilterCount = 0;
7361+
7362+#ifdef ENABLE_MCTF
7363+ if (VPP_FILTER_ENABLED_CONFIGURED == pInParams->mctfParam.mode) {
7364+ auto mctf = m_mfxVppParams.AddExtBuffer<mfxExtVppMctf>();
7365+ mctf->FilterStrength = pInParams->mctfParam.params.FilterStrength;
7366+ // If an external file is given & at least 1 value is given, use it
7367+ if (!pInParams->mctfParam.rtParams.Empty() && pInParams->mctfParam.rtParams.GetCurParam()) {
7368+ mctf->FilterStrength = pInParams->mctfParam.rtParams.GetCurParam()->FilterStrength;
7369+ }
7370+ #if defined ENABLE_MCTF_EXT
7371+ mctf->Overlap = pInParams->mctfParam.pInParams.Overlap;
7372+ mctf->TemporalMode = pInParams->mctfParam.params.TemporalMode;
7373+ mctf->MVPrecision = pInParams->mctfParam.params.MVPrecision;
7374+ mctf->BitsPerPixelx100k = pInParams->mctfParam.params.BitsPerPixelx100k;
7375+ mctf->Deblocking = pInParams->mctfParam.params.Deblocking;
7376+ #endif
7377+ }
7378+ else if (VPP_FILTER_ENABLED_DEFAULT == pInParams->mctfParam.mode) {
7379+ // MCTF enabling through do-use list:
7380+ m_tabDoUseAlg[enhFilterCount++] = MFX_EXTBUFF_VPP_MCTF;
7381+ }
7382+#endif //ENABLE_MCTF
7383+
7384+ if (pInParams->DenoiseLevel != -1) {
7385+ auto denoise = m_mfxVppParams.AddExtBuffer<mfxExtVPPDenoise>();
7386+ denoise->DenoiseFactor = (mfxU16)pInParams->DenoiseLevel;
7387+ }
7388+
7389+ if (pInParams->DetailLevel != -1) {
7390+ auto detail = m_mfxVppParams.AddExtBuffer<mfxExtVPPDetail>();
7391+ detail->DetailFactor = (mfxU16)pInParams->DetailLevel;
7392+ }
7393+
7394+ if (pInParams->FRCAlgorithm) {
7395+ auto frc = m_mfxVppParams.AddExtBuffer<mfxExtVPPFrameRateConversion>();
7396+ frc->Algorithm = pInParams->FRCAlgorithm;
7397+ }
7398+
7399+ if (pInParams->bEnableDeinterlacing && pInParams->DeinterlacingMode) {
7400+ auto di = m_mfxVppParams.AddExtBuffer<mfxExtVPPDeinterlacing>();
7401+ di->Mode = pInParams->DeinterlacingMode;
7402+ }
7403+
7404+ //--- Field Copy Mode
7405+ if (pInParams->fieldProcessingMode) {
7406+ auto fieldProc = m_mfxVppParams.AddExtBuffer<mfxExtVPPFieldProcessing>();
7407+
7408+ //--- To check first is we do copy frame of field
7409+ fieldProc->Mode = (mfxU16)(pInParams->fieldProcessingMode == FC_FR2FR ? MFX_VPP_COPY_FRAME
7410+ : MFX_VPP_COPY_FIELD);
7411+
7412+ fieldProc->InField = (mfxU16)(
7413+ (pInParams->fieldProcessingMode == FC_T2T || pInParams->fieldProcessingMode == FC_T2B)
7414+ ? MFX_PICSTRUCT_FIELD_TFF
7415+ : MFX_PICSTRUCT_FIELD_BFF);
7416+
7417+ fieldProc->OutField = (mfxU16)(
7418+ (pInParams->fieldProcessingMode == FC_T2T || pInParams->fieldProcessingMode == FC_B2T)
7419+ ? MFX_PICSTRUCT_FIELD_TFF
7420+ : MFX_PICSTRUCT_FIELD_BFF);
7421+ }
7422+
7423+ if (pInParams->ScalingMode) {
7424+ auto par = m_mfxVppParams.AddExtBuffer<mfxExtVPPScaling>();
7425+ par->ScalingMode = pInParams->ScalingMode;
7426+ }
7427+
7428+ if (enhFilterCount) {
7429+ auto doUse = m_mfxVppParams.AddExtBuffer<mfxExtVPPDoUse>();
7430+ doUse->NumAlg = enhFilterCount;
7431+ doUse->AlgList = m_tabDoUseAlg;
7432+ }
7433+
7434+#ifdef ENABLE_MCTF
7435+ // would it be more efficienct to get a pointer?
7436+ m_MctfRTParams = pInParams->mctfParam.rtParams;
7437+ m_MctfRTParams.Restart();
7438+#endif
7439+
7440+ return MFX_ERR_NONE;
7441+
7442+} //mfxStatus CTranscodingPipeline::InitMfxVppParams(sInputParams *pInParams)
7443+
7444+mfxStatus CTranscodingPipeline::InitPluginMfxParams(sInputParams *pInParams) {
7445+ MSDK_CHECK_POINTER(pInParams, MFX_ERR_NULL_PTR);
7446+
7447+ mfxU16 parentPattern = m_bIsVpp ? m_mfxVppParams.IOPattern : m_mfxDecParams.IOPattern;
7448+ mfxU16 InPatternFromParent =
7449+ (mfxU16)((MFX_IOPATTERN_OUT_VIDEO_MEMORY & parentPattern) ? MFX_IOPATTERN_IN_VIDEO_MEMORY
7450+ : MFX_IOPATTERN_IN_SYSTEM_MEMORY);
7451+
7452+ // set memory pattern
7453+ if (pInParams->bForceSysMem || (MFX_IMPL_SOFTWARE == pInParams->libType))
7454+ m_mfxPluginParams.IOPattern =
7455+ (mfxU16)(InPatternFromParent | MFX_IOPATTERN_OUT_SYSTEM_MEMORY);
7456+ else
7457+ m_mfxPluginParams.IOPattern =
7458+ (mfxU16)(InPatternFromParent | MFX_IOPATTERN_OUT_VIDEO_MEMORY);
7459+
7460+ m_mfxPluginParams.AsyncDepth = m_AsyncDepth;
7461+
7462+ // input frame info
7463+ if (m_bIsVpp) {
7464+ MSDK_MEMCPY_VAR(m_mfxPluginParams.vpp.In, &m_mfxVppParams.vpp.Out, sizeof(mfxFrameInfo));
7465+ }
7466+ else {
7467+ m_mfxPluginParams.vpp.In = GetFrameInfo(m_mfxDecParams);
7468+ }
7469+
7470+ // fill output frame info
7471+ // in case of rotation plugin sample output frameinfo is same as input
7472+ MSDK_MEMCPY_VAR(m_mfxPluginParams.vpp.Out, &m_mfxPluginParams.vpp.In, sizeof(mfxFrameInfo));
7473+
7474+ return MFX_ERR_NONE;
7475+
7476+} //mfxStatus CTranscodingPipeline::InitMfxVppParams(sInputParams *pInParams)
7477+
7478+mfxStatus CTranscodingPipeline::AllocFrames(mfxFrameAllocRequest *pRequest, bool isDecAlloc) {
7479+ mfxStatus sts = MFX_ERR_NONE;
7480+
7481+ mfxU16 nSurfNum = 0; // number of surfaces
7482+ mfxU16 i;
7483+
7484+ nSurfNum = pRequest->NumFrameMin = pRequest->NumFrameSuggested;
7485+ msdk_printf(MSDK_STRING("Pipeline surfaces number (%s): %d\n"),
7486+ isDecAlloc ? MSDK_STRING("DecPool") : MSDK_STRING("EncPool"),
7487+ nSurfNum);
7488+
7489+ mfxFrameAllocResponse *pResponse = isDecAlloc ? &m_mfxDecResponse : &m_mfxEncResponse;
7490+
7491+ sts = m_pMFXAllocator->Alloc(m_pMFXAllocator->pthis, pRequest, pResponse);
7492+ MSDK_CHECK_STATUS(sts, "m_pMFXAllocator->Alloc failed");
7493+
7494+ for (i = 0; i < nSurfNum; i++) {
7495+ auto surface = std::unique_ptr<mfxFrameSurfaceWrap>(new mfxFrameSurfaceWrap());
7496+ surface->Info = pRequest->Info;
7497+
7498+ if (m_rawInput) {
7499+ sts =
7500+ m_pMFXAllocator->Lock(m_pMFXAllocator->pthis, pResponse->mids[i], &(surface->Data));
7501+ MSDK_CHECK_STATUS(sts, "m_pMFXAllocator->Lock failed");
7502+ }
7503+ else {
7504+ surface->Data.MemId = pResponse->mids[i];
7505+ }
7506+
7507+ (isDecAlloc) ? m_pSurfaceDecPool.push_back(surface.get())
7508+ : m_pSurfaceEncPool.push_back(surface.get());
7509+
7510+ std::ignore = surface.release();
7511+ }
7512+
7513+ (isDecAlloc) ? m_DecSurfaceType = pRequest->Type : m_EncSurfaceType = pRequest->Type;
7514+
7515+ return MFX_ERR_NONE;
7516+
7517+} // mfxStatus CTranscodingPipeline::AllocFrames(Component* pComp, mfxFrameAllocResponse* pMfxResponse, mfxVideoParam* pMfxVideoParam)
7518+
7519+//return true if correct
7520+static bool CheckAsyncDepth(mfxFrameAllocRequest &curReq, mfxU16 asyncDepth) {
7521+ return (curReq.NumFrameSuggested >= asyncDepth);
7522+}
7523+
7524+static mfxStatus CorrectAsyncDepth(mfxFrameAllocRequest &curReq, mfxU16 asyncDepth) {
7525+ mfxStatus sts = MFX_ERR_NONE;
7526+ if (!CheckAsyncDepth(curReq, asyncDepth)) {
7527+ sts = MFX_ERR_MEMORY_ALLOC;
7528+ }
7529+ else {
7530+ // The request holds summary of required surfaces numbers from 2 components and
7531+ // asyncDepth is included twice. Here we patch surfaces number removing
7532+ // one asyncDepth.
7533+ curReq.NumFrameSuggested = curReq.NumFrameSuggested - asyncDepth;
7534+ curReq.NumFrameMin = curReq.NumFrameSuggested;
7535+ }
7536+
7537+ return sts;
7538+}
7539+
7540+static void SumAllocRequest(mfxFrameAllocRequest &curReq, mfxFrameAllocRequest &newReq) {
7541+ curReq.NumFrameSuggested = curReq.NumFrameSuggested + newReq.NumFrameSuggested;
7542+ curReq.NumFrameMin = curReq.NumFrameSuggested;
7543+ curReq.Type = curReq.Type | newReq.Type;
7544+
7545+ if ((curReq.Type & MFX_MEMTYPE_SYSTEM_MEMORY) &&
7546+ ((curReq.Type & 0xf0) != MFX_MEMTYPE_SYSTEM_MEMORY))
7547+ curReq.Type = (mfxU16)(curReq.Type & (~MFX_MEMTYPE_SYSTEM_MEMORY));
7548+ if ((curReq.Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) &&
7549+ ((curReq.Type & 0xf0) != MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
7550+ curReq.Type = (mfxU16)(curReq.Type & (~MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET));
7551+
7552+ if (curReq.Info.Width == 0) {
7553+ curReq.Info = newReq.Info;
7554+ }
7555+ else {
7556+ curReq.Info.Width =
7557+ curReq.Info.Width < newReq.Info.Width ? newReq.Info.Width : curReq.Info.Width;
7558+ curReq.Info.Height =
7559+ curReq.Info.Height < newReq.Info.Height ? newReq.Info.Height : curReq.Info.Height;
7560+ }
7561+}
7562+
7563+mfxStatus CTranscodingPipeline::AllocFrames() {
7564+ mfxStatus sts = MFX_ERR_NONE;
7565+ bool bAddFrames = true; // correct shared pool between session
7566+
7567+ mfxFrameAllocRequest DecOut;
7568+ mfxFrameAllocRequest VPPOut;
7569+
7570+ MSDK_ZERO_MEMORY(DecOut);
7571+ MSDK_ZERO_MEMORY(VPPOut);
7572+
7573+ sts = CalculateNumberOfReqFrames(DecOut, VPPOut);
7574+ MSDK_CHECK_STATUS(sts, "CalculateNumberOfReqFrames failed");
7575+
7576+ if (VPPOut.NumFrameSuggested) {
7577+ if (bAddFrames) {
7578+ SumAllocRequest(VPPOut, m_Request);
7579+ bAddFrames = false;
7580+ }
7581+
7582+ // Do not correct anything if we're using raw output - we'll need those surfaces for storing data for writer
7583+ if (m_mfxEncParams.mfx.CodecId != MFX_CODEC_DUMP) {
7584+ // In case of rendering enabled we need to add 1 additional surface for renderer
7585+ if ((m_nVPPCompEnable == VppCompOnly) || (m_nVPPCompEnable == VppCompOnlyEncode)) {
7586+ VPPOut.NumFrameSuggested++;
7587+ VPPOut.NumFrameMin++;
7588+ }
7589+ sts = CorrectAsyncDepth(VPPOut, m_AsyncDepth);
7590+ MSDK_CHECK_STATUS(sts, "CorrectAsyncDepth failed");
7591+ /* WA for rendering: VPP should have at least 2 frames on output (for front & back buffer accordinally) */
7592+ if ((VPPOut.NumFrameSuggested <= 1) || (VPPOut.NumFrameMin <= 1)) {
7593+ VPPOut.NumFrameSuggested = 2;
7594+ VPPOut.NumFrameMin = 2;
7595+ }
7596+ }
7597+
7598+#ifdef LIBVA_SUPPORT
7599+ if (((m_nVPPCompEnable == VppCompOnly) || (m_nVPPCompEnable == VppCompOnlyEncode)) &&
7600+ ((m_libvaBackend == MFX_LIBVA_DRM_MODESET) ||
7601+ #if defined(X11_DRI3_SUPPORT)
7602+ (m_libvaBackend == MFX_LIBVA_X11) ||
7603+ #endif // X11_DRI3_SUPPORT
7604+ (m_libvaBackend == MFX_LIBVA_WAYLAND))) {
7605+ VPPOut.Type |= MFX_MEMTYPE_EXPORT_FRAME;
7606+ }
7607+#endif
7608+ sts = AllocFrames(&VPPOut, false);
7609+ MSDK_CHECK_STATUS(sts, "AllocFrames failed");
7610+ }
7611+
7612+ if (DecOut.NumFrameSuggested) {
7613+ if (bAddFrames) {
7614+ SumAllocRequest(DecOut, m_Request);
7615+ bAddFrames = false;
7616+ }
7617+
7618+ if (m_bDecodeEnable) {
7619+ if (0 == m_nVPPCompEnable && m_mfxEncParams.mfx.CodecId != MFX_CODEC_DUMP) {
7620+ //--- Make correction to number of surfaces only if composition is not enabled. In case of composition we need all the surfaces QueryIOSurf has requested to pass them to another session's VPP
7621+ // In other inter-session cases, other sessions request additional surfaces using additional calls to AllocFrames
7622+ sts = CorrectAsyncDepth(DecOut, m_AsyncDepth);
7623+ MSDK_CHECK_STATUS(sts, "CorrectAsyncDepth failed");
7624+ }
7625+
7626+ // AllocId just opaque handle which allow separate decoder requests in case of VPP Composition with external allocator
7627+ static mfxU32 mark_alloc = 0;
7628+ m_mfxDecParams.AllocId = mark_alloc;
7629+ DecOut.AllocId = mark_alloc;
7630+ if (m_nVPPCompEnable) // WORKAROUND: Remove this if clause after problem with AllocID is fixed in library (mark_alloc++ should be left here)
7631+ {
7632+ mark_alloc++;
7633+ }
7634+
7635+ if ((DecOut.NumFrameSuggested <= 1) || (DecOut.NumFrameMin <= 1)) {
7636+ DecOut.NumFrameSuggested = 2;
7637+ DecOut.NumFrameMin = 2;
7638+ }
7639+
7640+ sts = AllocFrames(&DecOut, true);
7641+ MSDK_CHECK_STATUS(sts, "AllocFrames failed");
7642+#if !defined(MFX_ONEVPL)
7643+ sts = CorrectPreEncAuxPool(
7644+ (VPPOut.NumFrameSuggested ? VPPOut.NumFrameSuggested : DecOut.NumFrameSuggested) +
7645+ m_AsyncDepth);
7646+ MSDK_CHECK_STATUS(sts, "CorrectPreEncAuxPool failed");
7647+ sts = AllocPreEncAuxPool();
7648+ MSDK_CHECK_STATUS(sts, "AllocPreEncAuxPool failed");
7649+#endif //!MFX_ONEVPL
7650+ }
7651+ else {
7652+ if ((m_pParentPipeline) && (0 == m_nVPPCompEnable) /* case if 1_to_N */) {
7653+ m_pParentPipeline->CorrectNumberOfAllocatedFrames(&DecOut);
7654+#if !defined(MFX_ONEVPL)
7655+ sts = m_pParentPipeline->CorrectPreEncAuxPool(
7656+ VPPOut.NumFrameSuggested + DecOut.NumFrameSuggested + m_AsyncDepth);
7657+ MSDK_CHECK_STATUS(sts, "m_pParentPipeline->CorrectPreEncAuxPool failed");
7658+#endif //!MFX_ONEVPL
7659+ }
7660+ }
7661+ }
7662+
7663+ return MFX_ERR_NONE;
7664+}
7665+
7666+mfxStatus CTranscodingPipeline::CalculateNumberOfReqFrames(mfxFrameAllocRequest &pDecOut,
7667+ mfxFrameAllocRequest &pVPPOut) {
7668+ mfxStatus sts = MFX_ERR_NONE;
7669+ mfxFrameAllocRequest *pSumRequest = &pDecOut;
7670+
7671+ memset(&pDecOut, 0, sizeof(pDecOut));
7672+ memset(&pVPPOut, 0, sizeof(pVPPOut));
7673+
7674+ mfxFrameAllocRequest DecRequest;
7675+ MSDK_ZERO_MEMORY(DecRequest);
7676+
7677+ if (m_pmfxDEC.get()) {
7678+ sts = m_pmfxDEC.get()->QueryIOSurf(&m_mfxDecParams, &DecRequest);
7679+ MSDK_CHECK_STATUS(sts, "m_pmfxDEC.get failed");
7680+
7681+ if (!CheckAsyncDepth(DecRequest, m_mfxDecParams.AsyncDepth))
7682+ return MFX_ERR_MEMORY_ALLOC;
7683+ SumAllocRequest(*pSumRequest, DecRequest);
7684+ }
7685+ else if (m_bUseOverlay) {
7686+ // It takes 1 surface for overlay
7687+ DecRequest.NumFrameMin = DecRequest.NumFrameSuggested = 1;
7688+ DecRequest.Type = MFX_MEMTYPE_FROM_DECODE | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET |
7689+ MFX_MEMTYPE_EXTERNAL_FRAME;
7690+ DecRequest.Info = GetFrameInfo(m_mfxDecParams);
7691+ SumAllocRequest(*pSumRequest, DecRequest);
7692+ }
7693+
7694+ if (m_pmfxVPP.get()) {
7695+ mfxFrameAllocRequest VppRequest[2];
7696+
7697+ MSDK_ZERO_MEMORY(VppRequest);
7698+ if (m_bIsPlugin && m_bIsVpp) {
7699+ sts = m_pmfxVPP.get()->QueryIOSurfMulti(&m_mfxPluginParams,
7700+ &(VppRequest[0]),
7701+ &m_mfxVppParams);
7702+ if (!CheckAsyncDepth(VppRequest[0], m_mfxPluginParams.AsyncDepth) ||
7703+ !CheckAsyncDepth(VppRequest[1], m_mfxPluginParams.AsyncDepth) ||
7704+ !CheckAsyncDepth(VppRequest[0], m_mfxVppParams.AsyncDepth) ||
7705+ !CheckAsyncDepth(VppRequest[1], m_mfxVppParams.AsyncDepth))
7706+ return MFX_ERR_MEMORY_ALLOC;
7707+ }
7708+ else if (m_bIsPlugin) {
7709+ sts = m_pmfxVPP.get()->QueryIOSurf(&m_mfxPluginParams, &(VppRequest[0]));
7710+ if (!CheckAsyncDepth(VppRequest[0], m_mfxPluginParams.AsyncDepth) ||
7711+ !CheckAsyncDepth(VppRequest[1], m_mfxPluginParams.AsyncDepth))
7712+ return MFX_ERR_MEMORY_ALLOC;
7713+ }
7714+ else {
7715+ sts = m_pmfxVPP.get()->QueryIOSurf(&m_mfxVppParams, &(VppRequest[0]));
7716+ if (!CheckAsyncDepth(VppRequest[0], m_mfxVppParams.AsyncDepth) ||
7717+ !CheckAsyncDepth(VppRequest[1], m_mfxVppParams.AsyncDepth))
7718+ return MFX_ERR_MEMORY_ALLOC;
7719+ }
7720+
7721+ MSDK_CHECK_STATUS(sts, "m_pmfxVPP.get()->QueryIOSurf failed");
7722+
7723+ SumAllocRequest(*pSumRequest, VppRequest[0]);
7724+ pSumRequest = &pVPPOut;
7725+ SumAllocRequest(*pSumRequest, VppRequest[1]);
7726+ }
7727+
7728+#if !defined(MFX_ONEVPL)
7729+ if (m_pmfxPreENC.get()) {
7730+ mfxFrameAllocRequest PreEncRequest;
7731+
7732+ MSDK_ZERO_MEMORY(PreEncRequest);
7733+ sts = m_pmfxPreENC.get()->QueryIOSurf(&m_mfxPreEncParams, &PreEncRequest);
7734+ MSDK_CHECK_STATUS(sts, "m_pmfxPreENC.get()->QueryIOSurf failed");
7735+
7736+ if (!CheckAsyncDepth(PreEncRequest, m_mfxPreEncParams.AsyncDepth))
7737+ return MFX_ERR_MEMORY_ALLOC;
7738+ SumAllocRequest(*pSumRequest, PreEncRequest);
7739+ }
7740+#endif //!MFX_ONEVPL
7741+
7742+ if (m_pmfxENC.get()) {
7743+ mfxFrameAllocRequest EncRequest;
7744+
7745+ MSDK_ZERO_MEMORY(EncRequest);
7746+
7747+ sts = m_pmfxENC.get()->QueryIOSurf(&m_mfxEncParams, &EncRequest);
7748+ MSDK_CHECK_STATUS(sts, "m_pmfxENC.get()->QueryIOSurf failed");
7749+
7750+ if (!CheckAsyncDepth(EncRequest, m_mfxEncParams.AsyncDepth))
7751+ return MFX_ERR_MEMORY_ALLOC;
7752+ SumAllocRequest(*pSumRequest, EncRequest);
7753+ }
7754+
7755+ if (!pSumRequest->Type && m_pmfxDEC.get()) {
7756+ //--- If noone has set type to VPP request type yet, set it now basing on decoder request type
7757+ pSumRequest->Type = MFX_MEMTYPE_BASE(DecRequest.Type) | MFX_MEMTYPE_FROM_VPPOUT;
7758+ }
7759+
7760+ return MFX_ERR_NONE;
7761+}
7762+void CTranscodingPipeline::CorrectNumberOfAllocatedFrames(mfxFrameAllocRequest *pNewReq) {
7763+ if (shouldUseGreedyFormula) {
7764+ m_Request.NumFrameSuggested += pNewReq->NumFrameSuggested;
7765+ }
7766+ else {
7767+ m_Request.NumFrameSuggested =
7768+ std::max(m_Request.NumFrameSuggested, pNewReq->NumFrameSuggested);
7769+ }
7770+
7771+ m_Request.NumFrameMin = m_Request.NumFrameSuggested;
7772+ m_Request.Type = m_Request.Type | pNewReq->Type;
7773+
7774+ if ((m_Request.Type & MFX_MEMTYPE_SYSTEM_MEMORY) &&
7775+ ((m_Request.Type & 0xf0) != MFX_MEMTYPE_SYSTEM_MEMORY))
7776+ m_Request.Type = (mfxU16)(m_Request.Type & (~MFX_MEMTYPE_SYSTEM_MEMORY));
7777+ if ((m_Request.Type & MFX_MEMTYPE_DXVA2_PROCESSOR_TARGET) &&
7778+ ((m_Request.Type & 0xf0) != MFX_MEMTYPE_DXVA2_PROCESSOR_TARGET))
7779+ m_Request.Type = (mfxU16)(m_Request.Type & (~MFX_MEMTYPE_DXVA2_PROCESSOR_TARGET));
7780+
7781+ if (m_Request.Info.Width == 0) {
7782+ m_Request.Info = pNewReq->Info;
7783+ }
7784+ else {
7785+ m_Request.Info.Width =
7786+ m_Request.Info.Width < pNewReq->Info.Width ? pNewReq->Info.Width : m_Request.Info.Width;
7787+ m_Request.Info.Height = m_Request.Info.Height < pNewReq->Info.Height
7788+ ? pNewReq->Info.Height
7789+ : m_Request.Info.Height;
7790+ }
7791+}
7792+
7793+void CTranscodingPipeline::FreeFrames() {
7794+ std::for_each(m_pSurfaceDecPool.begin(), m_pSurfaceDecPool.end(), [](mfxFrameSurface1 *s) {
7795+ auto surface = static_cast<mfxFrameSurfaceWrap *>(s);
7796+ delete surface;
7797+ });
7798+ m_pSurfaceDecPool.clear();
7799+
7800+ std::for_each(m_pSurfaceEncPool.begin(), m_pSurfaceEncPool.end(), [](mfxFrameSurface1 *s) {
7801+ auto surface = static_cast<mfxFrameSurfaceWrap *>(s);
7802+ delete surface;
7803+ });
7804+ m_pSurfaceEncPool.clear();
7805+
7806+ if (m_pMFXAllocator) {
7807+ m_pMFXAllocator->Free(m_pMFXAllocator->pthis, &m_mfxEncResponse);
7808+ m_pMFXAllocator->Free(m_pMFXAllocator->pthis, &m_mfxDecResponse);
7809+ }
7810+} // CTranscodingPipeline::FreeFrames()
7811+
7812+mfxStatus CTranscodingPipeline::Init(sInputParams *pParams,
7813+ MFXFrameAllocator *pMFXAllocator,
7814+ void *hdl,
7815+ CTranscodingPipeline *pParentPipeline,
7816+ SafetySurfaceBuffer *pBuffer,
7817+ FileBitstreamProcessor *pBSProc,
7818+ VPLImplementationLoader *mfxLoader) {
7819+ MSDK_CHECK_POINTER(pParams, MFX_ERR_NULL_PTR);
7820+ MSDK_CHECK_POINTER(pMFXAllocator, MFX_ERR_NULL_PTR);
7821+ MSDK_CHECK_POINTER(pBSProc, MFX_ERR_NULL_PTR);
7822+ mfxStatus sts = MFX_ERR_NONE;
7823+ m_MaxFramesForTranscode = pParams->MaxFrameNumber;
7824+ // if no number of frames for a particular session is undefined, default
7825+ // value is 0xFFFFFFFF. Thus, use it as a marker to assign parent
7826+ // MaxFramesForTranscode to m_MaxFramesForTranscode
7827+ if (pParentPipeline && (0xFFFFFFFF == m_MaxFramesForTranscode) &&
7828+ pParentPipeline->m_MaxFramesForTranscode)
7829+ m_MaxFramesForTranscode = pParentPipeline->m_MaxFramesForTranscode;
7830+
7831+ // use external allocator
7832+ m_pMFXAllocator = pMFXAllocator;
7833+ m_pBSProcessor = pBSProc;
7834+ m_hdl = hdl;
7835+
7836+ m_pParentPipeline = pParentPipeline;
7837+ shouldUseGreedyFormula = pParams->shouldUseGreedyFormula;
7838+
7839+ m_nTimeout = pParams->nTimeout;
7840+
7841+ m_AsyncDepth = (0 == pParams->nAsyncDepth) ? 1 : pParams->nAsyncDepth;
7842+ m_FrameNumberPreference = pParams->FrameNumberPreference;
7843+ m_numEncoders = 0;
7844+ m_bUseOverlay = pParams->DecodeId == MFX_CODEC_RGB4 ? true : false;
7845+ m_bRobustFlag = pParams->bRobustFlag;
7846+ m_bSoftGpuHangRecovery = pParams->bSoftRobustFlag;
7847+ m_nRotationAngle = pParams->nRotationAngle;
7848+ m_sGenericPluginPath = pParams->strVPPPluginDLLPath;
7849+ m_decoderPluginParams = pParams->decoderPluginParams;
7850+ m_encoderPluginParams = pParams->encoderPluginParams;
7851+
7852+ m_encoderFourCC = pParams->EncoderFourCC;
7853+
7854+ m_rawInput = pParams->rawInput;
7855+
7856+ m_bExtMBQP = pParams->bExtMBQP;
7857+ m_bROIasQPMAP = pParams->bROIasQPMAP;
7858+
7859+ m_MemoryModel =
7860+ (UNKNOWN_ALLOC == pParams->nMemoryModel) ? GENERAL_ALLOC : pParams->nMemoryModel;
7861+
7862+#if MFX_VERSION >= 1022
7863+ m_ROIData = pParams->m_ROIData;
7864+#endif //MFX_VERSION >= 1022
7865+
7866+ statisticsWindowSize = pParams->statisticsWindowSize;
7867+ if (statisticsWindowSize > m_MaxFramesForTranscode)
7868+ statisticsWindowSize = m_MaxFramesForTranscode;
7869+
7870+ m_strMfxParamsDumpFile.assign(pParams->strMfxParamsDumpFile);
7871+
7872+ if (pParams->statisticsLogFile) {
7873+ //same log file for intput/output
7874+ inputStatistics.SetOutputFile(pParams->statisticsLogFile);
7875+ outputStatistics.SetOutputFile(pParams->statisticsLogFile);
7876+ }
7877+
7878+ if (!pParams->DumpLogFileName.empty()) {
7879+ inputStatistics.SetDumpName((pParams->DumpLogFileName + MSDK_STRING("_input")).c_str());
7880+ outputStatistics.SetDumpName((pParams->DumpLogFileName + MSDK_STRING("_output")).c_str());
7881+ }
7882+
7883+ // if no statistic-window is passed but overall stat-log exist:
7884+ // is requested, set statisticsWindowSize to m_MaxFramesForTranscode
7885+ if ((pParams->statisticsLogFile || !pParams->DumpLogFileName.empty()) &&
7886+ 0 == statisticsWindowSize)
7887+ statisticsWindowSize = m_MaxFramesForTranscode;
7888+
7889+ if (m_bEncodeEnable) {
7890+ m_pBSStore.reset(new ExtendedBSStore(m_AsyncDepth));
7891+ }
7892+
7893+ // Determine processing mode
7894+ switch (pParams->eMode) {
7895+ case Native:
7896+ break;
7897+ case Sink:
7898+ if ((VppComp == pParams->eModeExt) || (VppCompOnly == pParams->eModeExt)) {
7899+ if ((NULL != pParentPipeline) && (NULL != pParentPipeline->m_pMFXAllocator))
7900+ m_pMFXAllocator = pParentPipeline->m_pMFXAllocator;
7901+ }
7902+
7903+ m_bEncodeEnable = false; // decode only
7904+ break;
7905+ case Source:
7906+ // for heterogeneous pipeline use parent allocator
7907+ MSDK_CHECK_POINTER(pParentPipeline, MFX_ERR_NULL_PTR);
7908+ m_pMFXAllocator = pParentPipeline->m_pMFXAllocator;
7909+ m_bDecodeEnable = false; // encode only
7910+ /**/
7911+ if ((pParams->m_hwdev != NULL) && (VppCompOnly == pParams->eModeExt)) {
7912+#if defined(_WIN32) || defined(_WIN64)
7913+ m_hwdev4Rendering = new CDecodeD3DRender;
7914+ m_hwdev4Rendering->SetHWDevice(pParams->m_hwdev);
7915+
7916+ sWindowParams RenderParam;
7917+
7918+ memset(&RenderParam, 0, sizeof(sWindowParams));
7919+
7920+ RenderParam.lpWindowName = MSDK_STRING("sample_multi_transcode");
7921+ RenderParam.nx = 0;
7922+ RenderParam.ny = 0;
7923+ RenderParam.nWidth = pParams->nDstWidth;
7924+ RenderParam.nHeight = pParams->nDstHeight;
7925+ RenderParam.ncell = 0;
7926+ RenderParam.nAdapter = 0;
7927+
7928+ RenderParam.lpClassName = MSDK_STRING("Render Window Class");
7929+ RenderParam.dwStyle = WS_OVERLAPPEDWINDOW;
7930+ RenderParam.hWndParent = NULL;
7931+ RenderParam.hMenu = NULL;
7932+ RenderParam.hInstance = GetModuleHandle(NULL);
7933+ RenderParam.lpParam = NULL;
7934+ RenderParam.bFullScreen = TRUE;
7935+
7936+ m_hwdev4Rendering->Init(RenderParam);
7937+#else
7938+ if (pParams->EncodeId) {
7939+ m_nVPPCompEnable = VppCompOnlyEncode;
7940+ }
7941+ m_hwdev4Rendering = pParams->m_hwdev;
7942+#endif
7943+ }
7944+ break;
7945+ default:
7946+ // unknown mode
7947+ return MFX_ERR_UNSUPPORTED;
7948+ }
7949+
7950+ if ((VppComp == pParams->eModeExt) || (VppCompOnly == pParams->eModeExt)) {
7951+ if (m_nVPPCompEnable != VppCompOnlyEncode)
7952+ m_nVPPCompEnable = pParams->eModeExt;
7953+ }
7954+
7955+#ifdef LIBVA_SUPPORT
7956+ m_libvaBackend = pParams->libvaBackend;
7957+#endif
7958+
7959+ m_pBuffer = pBuffer;
7960+
7961+#if defined(MFX_ONEVPL)
7962+ m_initPar.Version.Major = 2;
7963+ m_initPar.Version.Minor = 2;
7964+#else
7965+ // we set version to 1.0 and later we will query actual version of the library which will got leaded
7966+ m_initPar.Version.Major = 1;
7967+ m_initPar.Version.Minor = 0;
7968+#endif
7969+ m_initPar.Implementation = pParams->libType;
7970+
7971+ if (pParams->nThreadsNum) {
7972+ auto threadsPar = m_initPar.AddExtBuffer<mfxExtThreadsParam>();
7973+ threadsPar->NumThread = pParams->nThreadsNum;
7974+ }
7975+
7976+ //--- GPU Copy settings
7977+ m_initPar.GPUCopy = pParams->nGpuCopyMode;
7978+
7979+ // init session
7980+ m_pmfxSession.reset(new MainVideoSession);
7981+
7982+ sts = m_pmfxSession->CreateSession(mfxLoader);
7983+ MSDK_CHECK_STATUS(sts, "m_pmfxSession->CreateSession failed");
7984+
7985+ // check the API version of actually loaded library
7986+ sts = m_pmfxSession->QueryVersion(&m_Version);
7987+ MSDK_CHECK_STATUS(sts, "m_pmfxSession->QueryVersion failed");
7988+ // check the implementation version of actually loaded library
7989+ sts = m_pmfxSession->QueryIMPL(&pParams->libType);
7990+ MSDK_CHECK_STATUS(sts, "m_pmfxSession->QueryIMPL failed");
7991+
7992+#if defined(_WIN32) || defined(_WIN64)
7993+ if (MFX_CODEC_AV1 == pParams->DecodeId &&
7994+ MFX_IMPL_VIA_MASK(pParams->libType) == MFX_IMPL_VIA_D3D9) {
7995+ sts = MFX_ERR_UNSUPPORTED;
7996+ MSDK_CHECK_STATUS(sts, "AV1d have no DX9 support \n");
7997+ }
7998+#endif
7999+
8000+ sts = CheckRequiredAPIVersion(m_Version, pParams);
8001+ MSDK_CHECK_STATUS(sts, "CheckRequiredAPIVersion failed");
8002+
8003+ // common session settings
8004+ if (MFX_VERSION >= 1001)
8005+ sts = m_pmfxSession->SetPriority(pParams->priority);
8006+
8007+ m_bIsInterOrJoined = pParams->eMode == Sink || pParams->eMode == Source || pParams->bIsJoin;
8008+
8009+ sts = SetAllocatorAndHandleIfRequired();
8010+ MSDK_CHECK_STATUS(sts, "SetAllocatorAndHandleIfRequired failed");
8011+
8012+ // Joining sessions if required
8013+ if (pParams->bIsJoin && pParentPipeline) {
8014+ sts = pParentPipeline->Join(m_pmfxSession.get());
8015+ MSDK_CHECK_STATUS(sts, "pParentPipeline->Join failed");
8016+ m_bIsJoinSession = true;
8017+ }
8018+
8019+ // Initialize pipeline components following downstream direction
8020+ // Pre-init methods fill parameters and create components
8021+
8022+ if (!m_rawInput) {
8023+ // Decode component initialization
8024+ sts = DecodePreInit(pParams);
8025+ if (MFX_ERR_MORE_DATA == sts)
8026+ return sts;
8027+ else
8028+ MSDK_CHECK_STATUS(sts, "DecodePreInit failed");
8029+ }
8030+ else {
8031+ m_mfxDecParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
8032+ }
8033+
8034+ // VPP component initialization
8035+ sts = VPPPreInit(pParams);
8036+ MSDK_CHECK_STATUS(sts, "VPPPreInit failed");
8037+
8038+ // Adjusting encoding settings according to selected preset
8039+ if (Sink != pParams->eMode) {
8040+ mfxFrameInfo eInfo;
8041+ FillFrameInfoForEncoding(eInfo, pParams);
8042+ ModifyParamsUsingPresets(*pParams,
8043+ ((double)eInfo.FrameRateExtN) / eInfo.FrameRateExtD,
8044+ eInfo.Width,
8045+ eInfo.Height);
8046+ }
8047+
8048+#if !defined(MFX_ONEVPL)
8049+ // LA component initialization
8050+ sts = PreEncPreInit(pParams);
8051+ MSDK_CHECK_STATUS(sts, "PreEncPreInit failed");
8052+#endif //MFX_ONEVPL
8053+
8054+ // Encode component initialization
8055+ if ((m_nVPPCompEnable != VppCompOnly) || (m_nVPPCompEnable == VppCompOnlyEncode)) {
8056+ sts = EncodePreInit(pParams);
8057+ MSDK_CHECK_STATUS(sts, "EncodePreInit failed");
8058+ }
8059+
8060+ if ((pParams->eMode == Source) &&
8061+ ((m_nVPPCompEnable == VppCompOnly) || (m_nVPPCompEnable == VppCompOnlyEncode) ||
8062+ (m_nVPPCompEnable == VppComp))) {
8063+ if ((0 == msdk_strncmp(MSDK_STRING("null_render"),
8064+ pParams->strDumpVppCompFile,
8065+ msdk_strlen(MSDK_STRING("null_render")))))
8066+ m_vppCompDumpRenderMode = NULL_RENDER_VPP_COMP; // null_render case
8067+ else if (0 != msdk_strlen(pParams->strDumpVppCompFile)) {
8068+ sts = m_dumpVppCompFileWriter.Init(pParams->strDumpVppCompFile, 0);
8069+ MSDK_CHECK_STATUS(sts, "VPP COMP DUMP File Init failed");
8070+ m_vppCompDumpRenderMode = DUMP_FILE_VPP_COMP;
8071+ }
8072+ }
8073+
8074+ if (m_MemoryModel == GENERAL_ALLOC) {
8075+ // Frames allocation for all component
8076+ if (Native == pParams->eMode) {
8077+ sts = AllocFrames();
8078+ MSDK_CHECK_STATUS(sts, "AllocFrames failed");
8079+ }
8080+ else if (Source ==
8081+ pParams->eMode) // need allocate frames only for VPP and Encode if VPP exist
8082+ {
8083+ if (!m_bDecodeEnable) {
8084+ sts = AllocFrames();
8085+ MSDK_CHECK_STATUS(sts, "AllocFrames failed");
8086+ }
8087+ }
8088+ }
8089+
8090+ isHEVCSW = AreGuidsEqual(pParams->decoderPluginParams.pluginGuid, MFX_PLUGINID_HEVCD_SW);
8091+
8092+ // if sink - suspended allocation
8093+
8094+ // common session settings
8095+ if (m_Version.Major >= 1 && m_Version.Minor >= 1)
8096+ sts = m_pmfxSession->SetPriority(pParams->priority);
8097+
8098+ // if sink - suspended allocation
8099+ if (Native != pParams->eMode)
8100+ return sts;
8101+
8102+ // Init decode
8103+ if (m_pmfxDEC.get()) {
8104+ sts = m_pmfxDEC->Init(&m_mfxDecParams);
8105+ MSDK_CHECK_STATUS(sts, "m_pmfxDEC->Init failed");
8106+ }
8107+
8108+ // Init VPP
8109+ if (m_pmfxVPP.get()) {
8110+ if (m_bIsPlugin && m_bIsVpp)
8111+ sts = m_pmfxVPP->InitMulti(&m_mfxPluginParams, &m_mfxVppParams);
8112+ else if (m_bIsPlugin)
8113+ sts = m_pmfxVPP->Init(&m_mfxPluginParams);
8114+ else
8115+ sts = m_pmfxVPP->Init(&m_mfxVppParams);
8116+ MSDK_CHECK_STATUS(sts, "m_pmfxVPP->Init failed");
8117+
8118+ if (MFX_WRN_PARTIAL_ACCELERATION == sts) {
8119+ msdk_printf(MSDK_STRING("WARNING: partial acceleration\n"));
8120+ MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION);
8121+ }
8122+ MSDK_CHECK_STATUS(sts, "m_pmfxVPP->Init failed");
8123+ }
8124+#if !defined(MFX_ONEVPL)
8125+ // LA initialization
8126+ if (m_pmfxPreENC.get()) {
8127+ sts = m_pmfxPreENC->Init(&m_mfxPreEncParams);
8128+ MSDK_CHECK_STATUS(sts, "m_pmfxPreENC->Init failed");
8129+ }
8130+#endif //!MFX_ONEVPL
8131+
8132+ // Init encode
8133+ if (m_pmfxENC.get()) {
8134+ sts = m_pmfxENC->Init(&m_mfxEncParams);
8135+ MSDK_CHECK_STATUS(sts, "m_pmfxENC->Init failed");
8136+
8137+#if MFX_VERSION >= 1022
8138+ if (pParams->bExtMBQP) {
8139+ m_bUseQPMap = true;
8140+ }
8141+
8142+ if (pParams->bROIasQPMAP) {
8143+ mfxVideoParam enc_par;
8144+ MSDK_ZERO_MEMORY(enc_par);
8145+ mfxStatus sts1 = m_pmfxENC->GetVideoParam(&enc_par);
8146+ MSDK_CHECK_STATUS(sts1, "m_pmfxENC->GetVideoParam failed");
8147+
8148+ if (enc_par.mfx.GopRefDist != 1) {
8149+ printf(
8150+ "INFO: Sample implementation of ROI through MBQP map require B-frames to be disabled.\n");
8151+ m_bUseQPMap = false;
8152+ }
8153+ else if (enc_par.mfx.RateControlMethod != MFX_RATECONTROL_CQP) {
8154+ printf("INFO: MBQP map require ConstQP mode to operate.\n");
8155+ m_bUseQPMap = false;
8156+ }
8157+ else {
8158+ m_GOPSize = (enc_par.mfx.GopPicSize) ? enc_par.mfx.GopPicSize : 1;
8159+ m_QPforI = enc_par.mfx.QPI;
8160+ m_QPforP = enc_par.mfx.QPP;
8161+ m_bUseQPMap = true;
8162+ }
8163+ }
8164+#endif //MFX_VERSION >= 1022
8165+ }
8166+
8167+ // Dumping components configuration if required
8168+ if (m_strMfxParamsDumpFile.size()) {
8169+ CParametersDumper::DumpLibraryConfiguration(m_strMfxParamsDumpFile,
8170+ m_pmfxDEC.get(),
8171+ m_pmfxVPP.get(),
8172+ m_pmfxENC.get(),
8173+ &m_mfxDecParams,
8174+ &m_mfxVppParams,
8175+ &m_mfxEncParams);
8176+ }
8177+
8178+ m_bIsInit = true;
8179+
8180+ return sts;
8181+} //mfxStatus CTranscodingPipeline::Init(sInputParams *pParams)
8182+
8183+mfxStatus CTranscodingPipeline::CompleteInit() {
8184+ mfxStatus sts = MFX_ERR_NONE;
8185+
8186+ if (m_bIsInit)
8187+ return MFX_ERR_NONE;
8188+
8189+ if (m_MemoryModel == GENERAL_ALLOC) {
8190+ // need to allocate remaining frames
8191+ if (m_bDecodeEnable) {
8192+ sts = AllocFrames();
8193+ MSDK_CHECK_STATUS(sts, "AllocFrames failed");
8194+ LoadStaticSurface();
8195+ MSDK_CHECK_STATUS(sts, "LoadStaticSurface failed");
8196+ }
8197+ }
8198+
8199+ // Init decode
8200+ if (m_pmfxDEC.get()) {
8201+ sts = m_pmfxDEC->Init(&m_mfxDecParams);
8202+ if (MFX_WRN_PARTIAL_ACCELERATION == sts) {
8203+ msdk_printf(MSDK_STRING("WARNING: partial acceleration\n"));
8204+ MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION);
8205+ }
8206+ MSDK_CHECK_STATUS(sts, "m_pmfxDEC->Init failed");
8207+ }
8208+
8209+ // Init vpp
8210+ if (m_pmfxVPP.get()) {
8211+ if (m_bIsPlugin && m_bIsVpp)
8212+ sts = m_pmfxVPP->InitMulti(&m_mfxPluginParams, &m_mfxVppParams);
8213+ else if (m_bIsPlugin)
8214+ sts = m_pmfxVPP->Init(&m_mfxPluginParams);
8215+ else
8216+ sts = m_pmfxVPP->Init(&m_mfxVppParams);
8217+ MSDK_CHECK_STATUS(sts, "m_pmfxVPP->Init failed");
8218+ }
8219+
8220+#if !defined(MFX_ONEVPL)
8221+ // Pre init encode
8222+ if (m_pmfxPreENC.get()) {
8223+ sts = m_pmfxPreENC->Init(&m_mfxPreEncParams);
8224+ if (MFX_WRN_PARTIAL_ACCELERATION == sts) {
8225+ msdk_printf(MSDK_STRING("WARNING: partial acceleration\n"));
8226+ MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION);
8227+ }
8228+ MSDK_CHECK_STATUS(sts, "m_pmfxPreENC->Init failed");
8229+ }
8230+#endif //!MFX_ONEVPL
8231+
8232+ // Init encode
8233+ if (m_pmfxENC.get()) {
8234+ sts = m_pmfxENC->Init(&m_mfxEncParams);
8235+ if (MFX_WRN_PARTIAL_ACCELERATION == sts) {
8236+ msdk_printf(MSDK_STRING("WARNING: partial acceleration\n"));
8237+ MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION);
8238+ }
8239+ MSDK_CHECK_STATUS(sts, "m_pmfxENC->Init failed");
8240+ }
8241+
8242+ m_bIsInit = true;
8243+
8244+ return sts;
8245+} // mfxStatus CTranscodingPipeline::CompleteInit()
8246+mfxFrameSurface1 *CTranscodingPipeline::GetFreeSurface(bool isDec, mfxU64 timeout) {
8247+ mfxFrameSurface1 *pSurf = NULL;
8248+
8249+ CTimer t;
8250+ t.Start();
8251+ do {
8252+ {
8253+ std::lock_guard<std::mutex> lock(m_mStopSession);
8254+ if (m_bForceStop) {
8255+ msdk_printf(MSDK_STRING(
8256+ "WARNING: m_bForceStop is set, returning NULL ptr from GetFreeSurface\n"));
8257+ break;
8258+ }
8259+ }
8260+
8261+ SurfPointersArray &workArray = isDec ? m_pSurfaceDecPool : m_pSurfaceEncPool;
8262+
8263+ for (mfxU32 i = 0; i < workArray.size(); i++) {
8264+ if (!workArray[i]->Data.Locked) {
8265+ pSurf = workArray[i];
8266+ break;
8267+ }
8268+ }
8269+ if (pSurf) {
8270+ break;
8271+ }
8272+ else {
8273+ MSDK_SLEEP(TIME_TO_SLEEP);
8274+ }
8275+ } while (t.GetTime() < timeout / 1000);
8276+
8277+ return pSurf;
8278+} // mfxFrameSurface1* CTranscodingPipeline::GetFreeSurface(bool isDec)
8279+
8280+mfxU32 CTranscodingPipeline::GetFreeSurfacesCount(bool isDec) {
8281+ SurfPointersArray &workArray = isDec ? m_pSurfaceDecPool : m_pSurfaceEncPool;
8282+ mfxU32 count = 0;
8283+ for (mfxU32 i = 0; i < workArray.size(); i++) {
8284+ if (!workArray[i]->Data.Locked) {
8285+ count++;
8286+ }
8287+ }
8288+ return count;
8289+}
8290+
8291+PreEncAuxBuffer *CTranscodingPipeline::GetFreePreEncAuxBuffer() {
8292+ for (mfxU32 i = 0; i < m_pPreEncAuxPool.size(); i++) {
8293+ if (!m_pPreEncAuxPool[i].Locked)
8294+ return &(m_pPreEncAuxPool[i]);
8295+ }
8296+ return NULL;
8297+}
8298+
8299+void CTranscodingPipeline::LockPreEncAuxBuffer(PreEncAuxBuffer *pBuff) {
8300+ if (!pBuff)
8301+ return;
8302+ for (mfxU32 i = 0; i < m_numEncoders; i++) {
8303+ msdk_atomic_inc16(&pBuff->Locked);
8304+ }
8305+}
8306+
8307+void CTranscodingPipeline::UnPreEncAuxBuffer(PreEncAuxBuffer *pBuff) {
8308+ if (!pBuff)
8309+ return;
8310+ msdk_atomic_dec16(&pBuff->Locked);
8311+}
8312+
8313+mfxU32 CTranscodingPipeline::GetNumFramesForReset() {
8314+ std::lock_guard<std::mutex> guard(m_mReset);
8315+ return m_NumFramesForReset;
8316+}
8317+
8318+void CTranscodingPipeline::SetNumFramesForReset(mfxU32 nFrames) {
8319+ std::lock_guard<std::mutex> guard(m_mReset);
8320+ m_NumFramesForReset = nFrames;
8321+}
8322+
8323+void CTranscodingPipeline::HandlePossibleGpuHang(mfxStatus &sts) {
8324+ if (sts == MFX_ERR_GPU_HANG && m_bSoftGpuHangRecovery) {
8325+ msdk_printf(MSDK_STRING(
8326+ "[WARNING] GPU hang happened. Inserting an IDR and continuing transcoding.\n"));
8327+ m_bInsertIDR = true;
8328+ for (BSList::iterator it = m_BSPool.begin(); it != m_BSPool.end(); it++) {
8329+ (*it)->IsFree = true;
8330+ (*it)->Bitstream.DataOffset = 0;
8331+ (*it)->Bitstream.DataLength = 0;
8332+ }
8333+ m_BSPool.clear();
8334+ sts = MFX_ERR_NONE;
8335+ }
8336+}
8337+
8338+mfxStatus CTranscodingPipeline::SetAllocatorAndHandleIfRequired() {
8339+ mfxStatus sts = MFX_ERR_NONE;
8340+ mfxIMPL impl = 0;
8341+ m_pmfxSession->QueryIMPL(&impl);
8342+
8343+ bool bIsMustSetExternalHandle = false;
8344+ mfxHandleType handleType = (mfxHandleType)0;
8345+
8346+ if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(impl)) {
8347+ handleType = MFX_HANDLE_D3D11_DEVICE;
8348+ bIsMustSetExternalHandle = false;
8349+ }
8350+ else if (MFX_IMPL_VIA_D3D9 == MFX_IMPL_VIA_MASK(impl)) {
8351+ handleType = MFX_HANDLE_D3D9_DEVICE_MANAGER;
8352+ bIsMustSetExternalHandle = false;
8353+ }
8354+#ifdef LIBVA_SUPPORT
8355+ else if (MFX_IMPL_VIA_VAAPI == MFX_IMPL_VIA_MASK(impl)) {
8356+ handleType = MFX_HANDLE_VA_DISPLAY;
8357+ bIsMustSetExternalHandle = true;
8358+ }
8359+#endif
8360+
8361+ bool ext_allocator_exists = m_MemoryModel == GENERAL_ALLOC;
8362+ if (m_hdl && (bIsMustSetExternalHandle || (m_bIsInterOrJoined || ext_allocator_exists))) {
8363+ sts = m_pmfxSession->SetHandle(handleType, m_hdl);
8364+ MSDK_CHECK_STATUS(sts, "m_pmfxSession->SetHandle failed");
8365+ }
8366+
8367+ if (ext_allocator_exists) {
8368+ sts = m_pmfxSession->SetFrameAllocator(m_pMFXAllocator);
8369+ MSDK_CHECK_STATUS(sts, "m_pmfxSession->SetFrameAllocator failed");
8370+ }
8371+
8372+ return sts;
8373+}
8374+
8375+#if !defined(MFX_ONEVPL)
8376+mfxStatus CTranscodingPipeline::LoadGenericPlugin() {
8377+ mfxStatus sts = MFX_ERR_NONE;
8378+
8379+ std::unique_ptr<MFXVideoVPPPlugin> pVPPPlugin(new MFXVideoVPPPlugin(*m_pmfxSession.get()));
8380+ MSDK_CHECK_POINTER(pVPPPlugin.get(), MFX_ERR_NULL_PTR);
8381+
8382+ sts = pVPPPlugin->LoadDLL((msdk_char *)m_sGenericPluginPath.c_str());
8383+ MSDK_CHECK_STATUS(sts, "pVPPPlugin->LoadDLL failed");
8384+
8385+ m_RotateParam.Angle = m_nRotationAngle;
8386+ sts = pVPPPlugin->SetAuxParam(&m_RotateParam, sizeof(m_RotateParam));
8387+ MSDK_CHECK_STATUS(sts, "pVPPPlugin->SetAuxParam failed");
8388+
8389+ sts = pVPPPlugin->SetFrameAllocator(m_pMFXAllocator);
8390+ MSDK_CHECK_STATUS(sts, "pVPPPlugin->SetFrameAllocator failed");
8391+
8392+ m_pmfxVPP.reset(pVPPPlugin.release());
8393+ return MFX_ERR_NONE;
8394+}
8395+#endif //!MFX_ONEVPL
8396+
8397+size_t CTranscodingPipeline::GetRobustFlag() {
8398+ return m_bRobustFlag;
8399+}
8400+
8401+void CTranscodingPipeline::Close() {
8402+ m_pmfxDEC.reset();
8403+
8404+ m_pmfxENC.reset();
8405+
8406+ m_pmfxVPP.reset();
8407+
8408+ m_pmfxSession.reset();
8409+
8410+#if !defined(MFX_ONEVPL)
8411+ if (m_pUserDecoderPlugin.get())
8412+ m_pUserDecoderPlugin.reset();
8413+
8414+ if (m_pUserEncoderPlugin.get())
8415+ m_pUserEncoderPlugin.reset();
8416+
8417+ if (m_pUserEncPlugin.get())
8418+ m_pUserEncPlugin.reset();
8419+#endif //!MFX_ONEVPL
8420+
8421+ FreeVppDoNotUse();
8422+#if !defined(MFX_ONEVPL)
8423+ FreeMVCSeqDesc();
8424+ FreePreEncAuxPool();
8425+
8426+ mfxExtVPPComposite *vppCompPar = m_mfxVppParams;
8427+ if (vppCompPar && vppCompPar->InputStream)
8428+ free(vppCompPar->InputStream);
8429+#endif
8430+
8431+ if (m_bIsJoinSession) {
8432+ //m_pmfxSession->DisjoinSession();
8433+ m_bIsJoinSession = false;
8434+ }
8435+
8436+ //Destroy renderer
8437+#if defined(_WIN32) || defined(_WIN64)
8438+ if (m_hwdev4Rendering) {
8439+ delete m_hwdev4Rendering;
8440+ m_hwdev4Rendering = NULL;
8441+ }
8442+#endif
8443+
8444+ // free allocated surfaces AFTER closing components
8445+ FreeFrames();
8446+
8447+ m_bIsInit = false;
8448+
8449+} // void CTranscodingPipeline::Close()
8450+
8451+mfxStatus CTranscodingPipeline::Reset(VPLImplementationLoader *mfxLoader) {
8452+ mfxStatus sts = MFX_ERR_NONE;
8453+ bool isDec = m_pmfxDEC.get() ? true : false, isEnc = m_pmfxENC.get() ? true : false,
8454+ isVPP = m_pmfxVPP.get() ? true : false, isGenericPLugin = m_nRotationAngle ? true : false
8455+#if !defined(MFX_ONEVPL)
8456+ ,
8457+ isPreEnc = m_pmfxPreENC.get() ? true : false,
8458+ isDecoderPlugin = m_pUserDecoderPlugin.get() ? true : false,
8459+ isEncoderPlugin = m_pUserEncoderPlugin.get() ? true : false,
8460+ isPreEncPlugin = m_pUserEncPlugin.get() ? true : false
8461+#endif //!MFX_ONEVPL
8462+ ;
8463+
8464+ // Close components being used
8465+ if (isDec) {
8466+ m_pmfxDEC->Close();
8467+ m_pmfxDEC.reset();
8468+ }
8469+
8470+ if (isVPP) {
8471+ m_pmfxVPP->Close();
8472+ m_pmfxVPP.reset();
8473+ }
8474+
8475+ if (isEnc) {
8476+ m_pmfxENC->Close();
8477+ m_pmfxENC.reset();
8478+ }
8479+
8480+#if !defined(MFX_ONEVPL)
8481+ if (isPreEnc) {
8482+ m_pmfxPreENC->Close();
8483+ m_pmfxPreENC.reset();
8484+ }
8485+
8486+ if (isDecoderPlugin) {
8487+ m_pUserDecoderPlugin.reset();
8488+ m_pUserDecoderModule.reset();
8489+ }
8490+
8491+ if (isEncoderPlugin) {
8492+ m_pUserEncoderPlugin.reset();
8493+ m_pUserEncoderModule.reset();
8494+ }
8495+#endif //!MFX_ONEVPL
8496+
8497+ m_pmfxSession->Close();
8498+
8499+ m_pmfxSession.reset(new MainVideoSession());
8500+
8501+ sts = m_pmfxSession->CreateSession(mfxLoader);
8502+ MSDK_CHECK_STATUS(sts, "CreateSession failed");
8503+
8504+ // Release dec and enc surface pools
8505+ for (size_t i = 0; i < m_pSurfaceDecPool.size(); i++) {
8506+ m_pSurfaceDecPool[i]->Data.Locked = 0;
8507+ }
8508+ for (size_t i = 0; i < m_pSurfaceEncPool.size(); i++) {
8509+ m_pSurfaceEncPool[i]->Data.Locked = 0;
8510+ }
8511+
8512+ // Release all safety buffers
8513+ SafetySurfaceBuffer *sptr = m_pBuffer;
8514+ while (sptr) {
8515+ sptr->ReleaseSurfaceAll();
8516+ sptr = sptr->m_pNext;
8517+ }
8518+
8519+ // Release output bitstram pools
8520+ m_BSPool.clear();
8521+ m_pBSStore->ReleaseAll();
8522+ m_pBSStore->FlushAll();
8523+
8524+#if !defined(MFX_ONEVPL)
8525+ // Load external decoder plugin
8526+ if (isDecoderPlugin) {
8527+ if (m_decoderPluginParams.type == MFX_PLUGINLOAD_TYPE_FILE &&
8528+ msdk_strnlen(m_decoderPluginParams.strPluginPath,
8529+ sizeof(m_decoderPluginParams.strPluginPath))) {
8530+ m_pUserDecoderModule.reset(new MFXVideoUSER(*m_pmfxSession.get()));
8531+ m_pUserDecoderPlugin.reset(
8532+ LoadPlugin(MFX_PLUGINTYPE_VIDEO_DECODE,
8533+ *m_pmfxSession.get(),
8534+ m_decoderPluginParams.pluginGuid,
8535+ 1,
8536+ m_decoderPluginParams.strPluginPath,
8537+ (mfxU32)msdk_strnlen(m_decoderPluginParams.strPluginPath,
8538+ sizeof(m_decoderPluginParams.strPluginPath))));
8539+ if (m_pUserDecoderPlugin.get() == NULL)
8540+ sts = MFX_ERR_UNSUPPORTED;
8541+ }
8542+ else {
8543+ if (AreGuidsEqual(m_decoderPluginParams.pluginGuid, MSDK_PLUGINGUID_NULL)) {
8544+ m_decoderPluginParams.pluginGuid = msdkGetPluginUID(m_initPar.Implementation,
8545+ MSDK_VDECODE,
8546+ m_mfxDecParams.mfx.CodecId);
8547+ }
8548+ if (!AreGuidsEqual(m_decoderPluginParams.pluginGuid, MSDK_PLUGINGUID_NULL)) {
8549+ m_pUserDecoderPlugin.reset(LoadPlugin(MFX_PLUGINTYPE_VIDEO_DECODE,
8550+ *m_pmfxSession.get(),
8551+ m_decoderPluginParams.pluginGuid,
8552+ 1));
8553+ if (m_pUserDecoderPlugin.get() == NULL)
8554+ sts = MFX_ERR_UNSUPPORTED;
8555+ }
8556+ }
8557+ MSDK_CHECK_STATUS(sts, "LoadPlugin failed");
8558+ }
8559+
8560+ // Load external encoder plugin
8561+ if (isEncoderPlugin) {
8562+ if (m_encoderPluginParams.type == MFX_PLUGINLOAD_TYPE_FILE &&
8563+ msdk_strnlen(m_encoderPluginParams.strPluginPath,
8564+ sizeof(m_encoderPluginParams.strPluginPath))) {
8565+ m_pUserEncoderModule.reset(new MFXVideoUSER(*m_pmfxSession.get()));
8566+ m_pUserEncoderPlugin.reset(
8567+ LoadPlugin(MFX_PLUGINTYPE_VIDEO_ENCODE,
8568+ *m_pmfxSession.get(),
8569+ m_encoderPluginParams.pluginGuid,
8570+ 1,
8571+ m_encoderPluginParams.strPluginPath,
8572+ (mfxU32)msdk_strnlen(m_encoderPluginParams.strPluginPath,
8573+ sizeof(m_encoderPluginParams.strPluginPath))));
8574+ if (m_pUserEncoderPlugin.get() == NULL)
8575+ sts = MFX_ERR_UNSUPPORTED;
8576+ }
8577+ else {
8578+ if (AreGuidsEqual(m_encoderPluginParams.pluginGuid, MSDK_PLUGINGUID_NULL)) {
8579+ m_decoderPluginParams.pluginGuid = msdkGetPluginUID(m_initPar.Implementation,
8580+ MSDK_VENCODE,
8581+ m_mfxEncParams.mfx.CodecId);
8582+ }
8583+ if (!AreGuidsEqual(m_encoderPluginParams.pluginGuid, MSDK_PLUGINGUID_NULL)) {
8584+ m_pUserEncoderPlugin.reset(LoadPlugin(MFX_PLUGINTYPE_VIDEO_ENCODE,
8585+ *m_pmfxSession.get(),
8586+ m_encoderPluginParams.pluginGuid,
8587+ 1));
8588+ if (m_pUserEncoderPlugin.get() == NULL)
8589+ sts = MFX_ERR_UNSUPPORTED;
8590+ }
8591+ }
8592+ MSDK_CHECK_STATUS(sts, "LoadPlugin failed");
8593+ }
8594+
8595+ // Load external pre-enc plugin
8596+ if (isPreEncPlugin) {
8597+ m_pUserEncPlugin.reset(LoadPlugin(MFX_PLUGINTYPE_VIDEO_ENCODE,
8598+ *m_pmfxSession.get(),
8599+ MFX_PLUGINID_H264LA_HW,
8600+ 1));
8601+ if (m_pUserEncPlugin.get() == NULL)
8602+ sts = MFX_ERR_UNSUPPORTED;
8603+ MSDK_CHECK_STATUS(sts, "LoadPlugin failed");
8604+ }
8605+#endif //!MFX_ONEVPL
8606+
8607+ sts = SetAllocatorAndHandleIfRequired();
8608+ MSDK_CHECK_STATUS(sts, "SetAllocatorAndHandleIfRequired failed");
8609+
8610+ if (isDec)
8611+ m_pmfxDEC.reset(new MFXVideoDECODE((mfxSession)*m_pmfxSession));
8612+ if (isVPP)
8613+ m_pmfxVPP.reset(new MFXVideoMultiVPP((mfxSession)*m_pmfxSession));
8614+#if !defined(MFX_ONEVPL)
8615+ if (isPreEnc)
8616+ m_pmfxPreENC.reset(new MFXVideoENC((mfxSession)*m_pmfxSession));
8617+#endif //!MFX_ONEVPL
8618+
8619+ if (isEnc)
8620+ m_pmfxENC.reset(new MFXVideoENCODE((mfxSession)*m_pmfxSession));
8621+
8622+ if (isDec) {
8623+ sts = m_pmfxDEC->Init(&m_mfxDecParams);
8624+ MSDK_CHECK_STATUS(sts, "m_pmfxDEC->Init failed");
8625+ }
8626+
8627+#if !defined(MFX_ONEVPL)
8628+ if (isGenericPLugin) {
8629+ sts = LoadGenericPlugin();
8630+ MSDK_CHECK_STATUS(sts, "LoadGenericPlugin failed");
8631+ }
8632+#endif //!MFX_ONEVPL
8633+
8634+ if (isVPP) {
8635+ if (m_bIsPlugin && m_bIsVpp) {
8636+ mfxFrameAllocRequest request[2] = {};
8637+ sts = m_pmfxVPP->QueryIOSurfMulti(&m_mfxPluginParams, request, &m_mfxVppParams);
8638+ MSDK_CHECK_STATUS(sts, "m_pmfxVPP->QueryIOSurf failed");
8639+
8640+ sts = m_pmfxVPP->InitMulti(&m_mfxPluginParams, &m_mfxVppParams);
8641+ }
8642+ else if (m_bIsPlugin)
8643+ sts = m_pmfxVPP->Init(&m_mfxPluginParams);
8644+ else
8645+ sts = m_pmfxVPP->Init(&m_mfxVppParams);
8646+ MSDK_CHECK_STATUS(sts, "m_pmfxVPP->Init failed");
8647+ }
8648+
8649+#if !defined(MFX_ONEVPL)
8650+ if (isPreEnc) {
8651+ sts = m_pmfxPreENC->Init(&m_mfxPreEncParams);
8652+ MSDK_CHECK_STATUS(sts, "m_pmfxPreENC->Init failed");
8653+ }
8654+#endif //!MFX_ONEVPL
8655+
8656+ if (isEnc) {
8657+ sts = m_pmfxENC->Init(&m_mfxEncParams);
8658+ MSDK_CHECK_STATUS(sts, "m_pmfxENC->Init failed");
8659+ }
8660+
8661+ // Joining sessions if required
8662+ if (m_bIsJoinSession && m_pParentPipeline) {
8663+ sts = m_pParentPipeline->Join(m_pmfxSession.get());
8664+ MSDK_CHECK_STATUS(sts, "m_pParentPipeline->Join failed");
8665+ m_bIsJoinSession = true;
8666+ }
8667+ return sts;
8668+}
8669+
8670+mfxStatus CTranscodingPipeline::AllocAndInitVppDoNotUse(sInputParams *pInParams) {
8671+ std::vector<mfxU32> filtersDisabled;
8672+ if (pInParams->DenoiseLevel == -1) {
8673+ filtersDisabled.push_back(MFX_EXTBUFF_VPP_DENOISE); // turn off denoising (on by default)
8674+ }
8675+ filtersDisabled.push_back(
8676+ MFX_EXTBUFF_VPP_SCENE_ANALYSIS); // turn off scene analysis (on by default)
8677+
8678+ if (filtersDisabled.size()) {
8679+ auto doNotUse = m_mfxVppParams.AddExtBuffer<mfxExtVPPDoNotUse>();
8680+ delete[] doNotUse->AlgList;
8681+
8682+ doNotUse->NumAlg = (mfxU32)filtersDisabled.size();
8683+ doNotUse->AlgList = new mfxU32[doNotUse->NumAlg];
8684+ MSDK_MEMCPY(doNotUse->AlgList,
8685+ filtersDisabled.data(),
8686+ sizeof(mfxU32) * filtersDisabled.size());
8687+ }
8688+
8689+ return MFX_ERR_NONE;
8690+} // CTranscodingPipeline::AllocAndInitVppDoNotUse()
8691+
8692+void CTranscodingPipeline::FreeVppDoNotUse() {
8693+#if 0
8694+ mfxExtVPPDoNotUse* doNotUse = m_mfxVppParams;
8695+ if (doNotUse)
8696+ MSDK_SAFE_DELETE_ARRAY(doNotUse->AlgList);
8697+#endif
8698+}
8699+
8700+mfxStatus CTranscodingPipeline::AllocateSufficientBuffer(mfxBitstreamWrapper *pBS) {
8701+ MSDK_CHECK_POINTER(pBS, MFX_ERR_NULL_PTR);
8702+
8703+ mfxVideoParam par;
8704+ MSDK_ZERO_MEMORY(par);
8705+
8706+ // find out the required buffer size
8707+ mfxStatus sts = m_pmfxENC->GetVideoParam(&par);
8708+ MSDK_CHECK_STATUS(sts, "m_pmfxENC->GetVideoParam failed");
8709+
8710+ mfxU32 new_size = 0;
8711+
8712+ // if encoder provided us information about buffer size
8713+ if (0 != par.mfx.BufferSizeInKB) {
8714+ //--- If value calculated basing on par.mfx.BufferSizeInKB is too low, just double the buffer size
8715+ new_size = par.mfx.BufferSizeInKB * 1000u > pBS->MaxLength ? par.mfx.BufferSizeInKB * 1000u
8716+ : pBS->MaxLength * 2;
8717+ }
8718+ else {
8719+ // trying to guess the size (e.g. for JPEG encoder)
8720+ new_size = (0 == pBS->MaxLength)
8721+ // some heuristic init value
8722+ ? 4 + (par.mfx.FrameInfo.Width * par.mfx.FrameInfo.Height * 3 + 1023)
8723+ // double existing size
8724+ : 2 * pBS->MaxLength;
8725+ }
8726+
8727+ pBS->Extend(new_size);
8728+
8729+ return MFX_ERR_NONE;
8730+} // CTranscodingPipeline::AllocateSufficientBuffer(mfxBitstreamWrapper* pBS)
8731+
8732+mfxStatus CTranscodingPipeline::Join(MFXVideoSession *pChildSession) {
8733+ mfxStatus sts = MFX_ERR_NONE;
8734+ MSDK_CHECK_POINTER(pChildSession, MFX_ERR_NULL_PTR);
8735+ sts = m_pmfxSession->JoinSession(*pChildSession);
8736+ m_bIsJoinSession = (MFX_ERR_NONE == sts);
8737+ return sts;
8738+} // CTranscodingPipeline::Join(MFXVideoSession *pChildSession)
8739+
8740+mfxStatus CTranscodingPipeline::Run() {
8741+ mfxStatus sts = MFX_ERR_NONE;
8742+
8743+ msdk_stringstream ss;
8744+ if (m_bDecodeEnable && m_bEncodeEnable) {
8745+ sts = Transcode();
8746+ ss << MSDK_STRING("CTranscodingPipeline::Run::Transcode() [") << GetSessionText()
8747+ << MSDK_STRING("] failed");
8748+ MSDK_CHECK_STATUS(sts, ss.str());
8749+ }
8750+ else if (m_bDecodeEnable) {
8751+ sts = Decode();
8752+ ss << MSDK_STRING("CTranscodingPipeline::Run::Decode() [") << GetSessionText()
8753+ << MSDK_STRING("] failed");
8754+ MSDK_CHECK_STATUS(sts, ss.str());
8755+ }
8756+ else if (m_bEncodeEnable) {
8757+ sts = Encode();
8758+ ss << MSDK_STRING("CTranscodingPipeline::Run::Encode() [") << GetSessionText()
8759+ << MSDK_STRING("] failed");
8760+ MSDK_CHECK_STATUS(sts, ss.str());
8761+ }
8762+ else
8763+ return MFX_ERR_UNSUPPORTED;
8764+
8765+ return sts;
8766+}
8767+
8768+void IncreaseReference(mfxFrameSurface1 &surf) {
8769+ msdk_atomic_inc16((volatile mfxU16 *)(&surf.Data.Locked));
8770+#if defined(MFX_ONEVPL)
8771+ if (surf.FrameInterface) {
8772+ std::ignore = surf.FrameInterface->AddRef(&surf);
8773+ }
8774+#endif
8775+}
8776+
8777+void DecreaseReference(mfxFrameSurface1 &surf) {
8778+ msdk_atomic_dec16((volatile mfxU16 *)&surf.Data.Locked);
8779+#if defined(MFX_ONEVPL)
8780+ if (surf.FrameInterface) {
8781+ std::ignore = surf.FrameInterface->Release(&surf);
8782+ }
8783+#endif
8784+}
8785+
8786+SafetySurfaceBuffer::SafetySurfaceBuffer(SafetySurfaceBuffer *pNext)
8787+ : m_pNext(pNext),
8788+ m_IsBufferingAllowed(true),
8789+ pInsEvent(nullptr) {
8790+ mfxStatus sts = MFX_ERR_NONE;
8791+ pRelEvent = new MSDKEvent(sts, false, false);
8792+ MSDK_CHECK_POINTER_NO_RET(pRelEvent);
8793+
8794+ pInsEvent = new MSDKEvent(sts, false, false);
8795+ MSDK_CHECK_POINTER_NO_RET(pInsEvent);
8796+
8797+} // SafetySurfaceBuffer::SafetySurfaceBuffer
8798+
8799+SafetySurfaceBuffer::~SafetySurfaceBuffer() {
8800+ delete pRelEvent;
8801+ delete pInsEvent;
8802+} //SafetySurfaceBuffer::~SafetySurfaceBuffer()
8803+
8804+mfxU32 SafetySurfaceBuffer::GetLength() {
8805+ std::lock_guard<std::mutex> guard(m_mutex);
8806+ return (mfxU32)m_SList.size();
8807+}
8808+
8809+mfxStatus SafetySurfaceBuffer::WaitForSurfaceRelease(mfxU32 msec) {
8810+ return pRelEvent->TimedWait(msec);
8811+}
8812+
8813+mfxStatus SafetySurfaceBuffer::WaitForSurfaceInsertion(mfxU32 msec) {
8814+ return pInsEvent->TimedWait(msec);
8815+}
8816+
8817+void SafetySurfaceBuffer::AddSurface(ExtendedSurface Surf) {
8818+ bool isBufferingAllowed = false;
8819+
8820+ {
8821+ std::lock_guard<std::mutex> guard(m_mutex);
8822+
8823+ isBufferingAllowed = m_IsBufferingAllowed;
8824+ if (isBufferingAllowed) {
8825+ SurfaceDescriptor sDescriptor;
8826+ // Locked is used to signal when we can free surface
8827+ sDescriptor.Locked = 1;
8828+ sDescriptor.ExtSurface = Surf;
8829+
8830+ if (Surf.pSurface) {
8831+ IncreaseReference(*Surf.pSurface);
8832+ }
8833+
8834+ m_SList.push_back(sDescriptor);
8835+ }
8836+ }
8837+
8838+ if (isBufferingAllowed) {
8839+ pInsEvent->Signal();
8840+ }
8841+
8842+} // SafetySurfaceBuffer::AddSurface(mfxFrameSurface1 *pSurf)
8843+
8844+mfxStatus SafetySurfaceBuffer::GetSurface(ExtendedSurface &Surf) {
8845+ std::lock_guard<std::mutex> guard(m_mutex);
8846+
8847+ // no ready surfaces
8848+ if (0 == m_SList.size()) {
8849+ MSDK_ZERO_MEMORY(Surf)
8850+ return MFX_ERR_MORE_SURFACE;
8851+ }
8852+
8853+ SurfaceDescriptor sDescriptor = m_SList.front();
8854+
8855+ Surf = sDescriptor.ExtSurface;
8856+
8857+ return MFX_ERR_NONE;
8858+
8859+} // SafetySurfaceBuffer::GetSurface()
8860+
8861+mfxStatus SafetySurfaceBuffer::ReleaseSurface(mfxFrameSurface1 *pSurf) {
8862+ std::unique_lock<std::mutex> lock(m_mutex);
8863+
8864+ std::list<SurfaceDescriptor>::iterator it;
8865+ for (it = m_SList.begin(); it != m_SList.end(); it++) {
8866+ if (pSurf == it->ExtSurface.pSurface) {
8867+ it->Locked--;
8868+ if (it->ExtSurface.pSurface)
8869+ DecreaseReference(*it->ExtSurface.pSurface);
8870+ if (0 == it->Locked) {
8871+ m_SList.erase(it);
8872+ lock.unlock();
8873+
8874+ // event operation should be out of synced context
8875+ pRelEvent->Signal();
8876+ }
8877+
8878+ return MFX_ERR_NONE;
8879+ }
8880+ }
8881+
8882+ return MFX_ERR_UNKNOWN;
8883+} // mfxStatus SafetySurfaceBuffer::ReleaseSurface(mfxFrameSurface1* pSurf)
8884+
8885+mfxStatus SafetySurfaceBuffer::ReleaseSurfaceAll() {
8886+ std::lock_guard<std::mutex> guard(m_mutex);
8887+
8888+ m_SList.clear();
8889+ m_IsBufferingAllowed = true;
8890+ return MFX_ERR_NONE;
8891+
8892+} // mfxStatus SafetySurfaceBuffer::ReleaseSurface(mfxFrameSurface1* pSurf)
8893+
8894+void SafetySurfaceBuffer::CancelBuffering() {
8895+ std::lock_guard<std::mutex> guard(m_mutex);
8896+ m_IsBufferingAllowed = false;
8897+}
8898+
8899+FileBitstreamProcessor::FileBitstreamProcessor() {
8900+ m_Bitstream.TimeStamp = (mfxU64)-1;
8901+}
8902+
8903+FileBitstreamProcessor::~FileBitstreamProcessor() {
8904+ if (m_pFileReader.get())
8905+ m_pFileReader->Close();
8906+ if (m_pFileWriter.get())
8907+ m_pFileWriter->Close();
8908+}
8909+
8910+mfxStatus FileBitstreamProcessor::SetReader(std::unique_ptr<CSmplYUVReader> &reader) {
8911+ m_pYUVFileReader = std::move(reader);
8912+
8913+ return MFX_ERR_NONE;
8914+}
8915+
8916+mfxStatus FileBitstreamProcessor::SetReader(std::unique_ptr<CSmplBitstreamReader> &reader) {
8917+ m_pFileReader = std::move(reader);
8918+ m_Bitstream.Extend(1024 * 1024);
8919+
8920+ return MFX_ERR_NONE;
8921+}
8922+
8923+mfxStatus FileBitstreamProcessor::SetWriter(std::unique_ptr<CSmplBitstreamWriter> &writer) {
8924+ m_pFileWriter = std::move(writer);
8925+
8926+ return MFX_ERR_NONE;
8927+}
8928+
8929+mfxStatus FileBitstreamProcessor::GetInputBitstream(mfxBitstreamWrapper **pBitstream) {
8930+ if (!m_pFileReader.get()) {
8931+ return MFX_ERR_UNSUPPORTED;
8932+ }
8933+ mfxStatus sts = m_pFileReader->ReadNextFrame(&m_Bitstream);
8934+ if (MFX_ERR_NONE == sts) {
8935+ *pBitstream = &m_Bitstream;
8936+ return sts;
8937+ }
8938+ return sts;
8939+}
8940+
8941+mfxStatus FileBitstreamProcessor::GetInputFrame(mfxFrameSurface1 *pSurface) {
8942+ //MSDK_CHECK_POINTER(pSurface);
8943+ if (!m_pYUVFileReader.get()) {
8944+ return MFX_ERR_UNSUPPORTED;
8945+ }
8946+ return m_pYUVFileReader->LoadNextFrame(pSurface);
8947+}
8948+
8949+mfxStatus FileBitstreamProcessor::ProcessOutputBitstream(mfxBitstreamWrapper *pBitstream) {
8950+ if (m_pFileWriter.get())
8951+ return m_pFileWriter->WriteNextFrame(pBitstream, false);
8952+
8953+ return MFX_ERR_NONE;
8954+}
8955+
8956+mfxStatus FileBitstreamProcessor::ResetInput() {
8957+ if (m_pFileReader.get()) {
8958+ m_pFileReader->Reset();
8959+
8960+ // Reset input bitstream state
8961+ m_Bitstream.DataFlag = 0;
8962+ }
8963+ if (m_pYUVFileReader.get()) {
8964+ m_pYUVFileReader->Reset();
8965+ }
8966+ return MFX_ERR_NONE;
8967+}
8968+
8969+mfxStatus FileBitstreamProcessor::ResetOutput() {
8970+ if (m_pFileWriter.get()) {
8971+ m_pFileWriter->Reset();
8972+ }
8973+ return MFX_ERR_NONE;
8974+}
8975+
8976+void CTranscodingPipeline::ModifyParamsUsingPresets(sInputParams &params,
8977+ mfxF64 fps,
8978+ mfxU32 width,
8979+ mfxU32 height) {
8980+ COutputPresetParameters presetParams =
8981+ CPresetManager::Inst.GetPreset(params.PresetMode,
8982+ params.EncodeId,
8983+ fps,
8984+ width,
8985+ height,
8986+ params.libType != MFX_IMPL_SOFTWARE);
8987+
8988+ if (params.shouldPrintPresets) {
8989+ msdk_printf(MSDK_STRING("Preset-controlled parameters (%s):\n"),
8990+ presetParams.PresetName.c_str());
8991+ }
8992+
8993+ if (!params.nRateControlMethod) {
8994+ MODIFY_AND_PRINT_PARAM_EXT(params.nExtBRC,
8995+ ExtBRCUsage,
8996+ (ExtBRCType)presetParams.ExtBRCUsage,
8997+ params.shouldPrintPresets);
8998+ }
8999+ if (presetParams.RateControlMethod == MFX_RATECONTROL_LA_EXT) {
9000+ // Use external LA
9001+ params.bEnableExtLA = true;
9002+ params.nRateControlMethod = 0;
9003+ if (params.shouldPrintPresets) {
9004+ msdk_printf(MSDK_STRING("RateControlMethod: ExtLA\n"));
9005+ }
9006+ }
9007+ else {
9008+ MODIFY_AND_PRINT_PARAM(params.nRateControlMethod,
9009+ RateControlMethod,
9010+ params.shouldPrintPresets);
9011+ }
9012+
9013+ MODIFY_AND_PRINT_PARAM(params.nAdaptiveMaxFrameSize,
9014+ AdaptiveMaxFrameSize,
9015+ params.shouldPrintPresets);
9016+ MODIFY_AND_PRINT_PARAM(params.nAsyncDepth, AsyncDepth, params.shouldPrintPresets);
9017+ MODIFY_AND_PRINT_PARAM(params.nBRefType, BRefType, params.shouldPrintPresets);
9018+ MODIFY_AND_PRINT_PARAM(params.bEnableBPyramid, EnableBPyramid, params.shouldPrintPresets);
9019+ // MODIFY_AND_PRINT_PARAM(params., EnablePPyramid, params.shouldPrintPresets);
9020+ MODIFY_AND_PRINT_PARAM(params.GopRefDist, GopRefDist, params.shouldPrintPresets);
9021+ MODIFY_AND_PRINT_PARAM(params.IntRefCycleDist, IntRefCycleDist, params.shouldPrintPresets);
9022+ MODIFY_AND_PRINT_PARAM(params.IntRefCycleSize, IntRefCycleSize, params.shouldPrintPresets);
9023+ MODIFY_AND_PRINT_PARAM(params.IntRefQPDelta, IntRefQPDelta, params.shouldPrintPresets);
9024+ MODIFY_AND_PRINT_PARAM(params.IntRefType, IntRefType, params.shouldPrintPresets);
9025+ MODIFY_AND_PRINT_PARAM(params.LowDelayBRC, LowDelayBRC, params.shouldPrintPresets);
9026+ MODIFY_AND_PRINT_PARAM(params.nTargetUsage, TargetUsage, params.shouldPrintPresets);
9027+ MODIFY_AND_PRINT_PARAM(params.WeightedBiPred, WeightedBiPred, params.shouldPrintPresets);
9028+ MODIFY_AND_PRINT_PARAM(params.WeightedPred, WeightedPred, params.shouldPrintPresets);
9029+
9030+ MODIFY_AND_PRINT_PARAM(params.GopPicSize, GopPicSize, params.shouldPrintPresets);
9031+
9032+ if (params.nRateControlMethod != MFX_RATECONTROL_CQP) {
9033+ MODIFY_AND_PRINT_PARAM(params.MaxKbps, MaxKbps, params.shouldPrintPresets);
9034+ MODIFY_AND_PRINT_PARAM(params.nBitRate, TargetKbps, params.shouldPrintPresets);
9035+ presetParams.BufferSizeInKB =
9036+ params
9037+ .nBitRate; // Update bitrate to reflect manually set bitrate. BufferSize should be enough for 1 second of video
9038+ MODIFY_AND_PRINT_PARAM(params.BufferSizeInKB, BufferSizeInKB, params.shouldPrintPresets);
9039+ }
9040+
9041+ MODIFY_AND_PRINT_PARAM(params.nMaxFrameSize, MaxFrameSize, params.shouldPrintPresets);
9042+ MODIFY_AND_PRINT_PARAM(params.nLADepth, LookAheadDepth, params.shouldPrintPresets);
9043+ if (params.shouldPrintPresets) {
9044+ msdk_printf(MSDK_STRING("\n"));
9045+ }
9046+}
9047diff --git a/tools/legacy/sample_multi_transcode/src/sample_multi_transcode.cpp b/tools/legacy/sample_multi_transcode/src/sample_multi_transcode.cpp
9048new file mode 100644
9049index 0000000..81ccb73
9050--- /dev/null
9051+++ b/tools/legacy/sample_multi_transcode/src/sample_multi_transcode.cpp
9052@@ -0,0 +1,1162 @@
9053+/******************************************************************************\
9054+Copyright (c) 2005-2020, Intel Corporation
9055+All rights reserved.
9056+
9057+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9058+
9059+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9060+
9061+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.
9062+
9063+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.
9064+
9065+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.
9066+
9067+This sample was distributed or derived from the Intel's Media Samples package.
9068+The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
9069+or https://software.intel.com/en-us/media-client-solutions-support.
9070+\**********************************************************************************/
9071+
9072+#include "mfx_samples_config.h"
9073+#if defined(_WIN32) || defined(_WIN64)
9074+ #include <windows.h>
9075+#endif
9076+
9077+#include "sample_multi_transcode.h"
9078+
9079+#if defined(LIBVA_WAYLAND_SUPPORT)
9080+ #include "class_wayland.h"
9081+#endif
9082+
9083+#ifndef MFX_VERSION
9084+ #error MFX_VERSION not defined
9085+#endif
9086+
9087+#include <future>
9088+#include <iomanip>
9089+using namespace std;
9090+using namespace TranscodingSample;
9091+
9092+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
9093+mfxU32 GetPreferredAdapterNum(const mfxAdaptersInfo& adapters, const sInputParams& params) {
9094+ if (adapters.NumActual == 0 || !adapters.Adapters)
9095+ return 0;
9096+
9097+ if (params.bPrefferdGfx) {
9098+ // Find dGfx adapter in list and return it's index
9099+
9100+ auto idx = std::find_if(adapters.Adapters,
9101+ adapters.Adapters + adapters.NumActual,
9102+ [](const mfxAdapterInfo info) {
9103+ return info.Platform.MediaAdapterType ==
9104+ mfxMediaAdapterType::MFX_MEDIA_DISCRETE;
9105+ });
9106+
9107+ // No dGfx in list
9108+ if (idx == adapters.Adapters + adapters.NumActual) {
9109+ msdk_printf(
9110+ MSDK_STRING("Warning: No dGfx detected on machine. Will pick another adapter\n"));
9111+ return 0;
9112+ }
9113+
9114+ return static_cast<mfxU32>(std::distance(adapters.Adapters, idx));
9115+ }
9116+
9117+ if (params.bPrefferiGfx) {
9118+ // Find iGfx adapter in list and return it's index
9119+
9120+ auto idx = std::find_if(adapters.Adapters,
9121+ adapters.Adapters + adapters.NumActual,
9122+ [](const mfxAdapterInfo info) {
9123+ return info.Platform.MediaAdapterType ==
9124+ mfxMediaAdapterType::MFX_MEDIA_INTEGRATED;
9125+ });
9126+
9127+ // No iGfx in list
9128+ if (idx == adapters.Adapters + adapters.NumActual) {
9129+ msdk_printf(
9130+ MSDK_STRING("Warning: No iGfx detected on machine. Will pick another adapter\n"));
9131+ return 0;
9132+ }
9133+
9134+ return static_cast<mfxU32>(std::distance(adapters.Adapters, idx));
9135+ }
9136+
9137+ // Other ways return 0, i.e. best suitable detected by dispatcher
9138+ return 0;
9139+}
9140+#endif
9141+
9142+Launcher::Launcher()
9143+ : m_StartTime(0),
9144+ m_eDevType(static_cast<mfxHandleType>(0)),
9145+ m_accelerationMode(MFX_ACCEL_MODE_NA) {} // Launcher::Launcher()
9146+
9147+Launcher::~Launcher() {
9148+ Close();
9149+} // Launcher::~Launcher()
9150+
9151+CTranscodingPipeline* CreatePipeline() {
9152+ MOD_SMT_CREATE_PIPELINE;
9153+
9154+ return new CTranscodingPipeline;
9155+}
9156+
9157+mfxStatus Launcher::Init(int argc, msdk_char* argv[]) {
9158+ mfxStatus sts;
9159+ mfxU32 i = 0;
9160+ SafetySurfaceBuffer* pBuffer = NULL;
9161+ mfxU32 BufCounter = 0;
9162+ mfxHDL hdl = NULL;
9163+ std::vector<mfxHDL> hdls;
9164+ sInputParams InputParams;
9165+ bool bNeedToCreateDevice = true;
9166+
9167+ //parent transcode pipeline
9168+ CTranscodingPipeline* pParentPipeline = NULL;
9169+ // source transcode pipeline use instead parent in heterogeneous pipeline
9170+ CTranscodingPipeline* pSinkPipeline = NULL;
9171+
9172+ // parse input par file
9173+ sts = m_parser.ParseCmdLine(argc, argv);
9174+ MSDK_CHECK_PARSE_RESULT(sts, MFX_ERR_NONE, sts);
9175+ if (sts == MFX_WRN_OUT_OF_RANGE) {
9176+ // There's no error in parameters parsing, but we should not continue further. For instance, in case of -? option
9177+ return sts;
9178+ }
9179+
9180+ // get parameters for each session from parser
9181+ while (m_parser.GetNextSessionParams(InputParams)) {
9182+ m_InputParamsArray.push_back(InputParams);
9183+ }
9184+
9185+ // check correctness of input parameters
9186+ sts = VerifyCrossSessionsOptions();
9187+ MSDK_CHECK_STATUS(sts, "VerifyCrossSessionsOptions failed");
9188+
9189+ mfxVersion ver = { { MFX_VERSION_MINOR, MFX_VERSION_MAJOR } };
9190+
9191+ m_pLoader.reset(new VPLImplementationLoader);
9192+ sts = m_pLoader->ConfigureAndEnumImplementations(m_InputParamsArray[0].libType,
9193+ m_accelerationMode,
9194+ ver);
9195+ MSDK_CHECK_STATUS(sts, "pLoader->ConfigureAndEnumImplementations failed");
9196+
9197+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
9198+ // check available adapters
9199+ sts = QueryAdapters();
9200+ MSDK_CHECK_STATUS(sts, "QueryAdapters failed");
9201+
9202+ if (m_eDevType && m_DisplaysData.empty()) {
9203+ msdk_printf(MSDK_STRING("No adapters found. HW-accelerated transcoding is impossible.\n"));
9204+ return MFX_ERR_UNSUPPORTED;
9205+ }
9206+#endif
9207+
9208+ for (i = 0; i < m_InputParamsArray.size(); i++) {
9209+ /* In the case of joined sessions, need to create device only for a zero session
9210+ * In the case of a shared buffer, need to create device only for decode */
9211+ if ((m_InputParamsArray[i].bIsJoin && i != 0) || m_InputParamsArray[i].eMode == Source)
9212+ bNeedToCreateDevice = false;
9213+
9214+#if defined(_WIN32) || defined(_WIN64)
9215+ ForceImplForSession(i);
9216+ sts = m_pLoader->EnumImplementations(m_deviceID, m_adapterNum);
9217+ MSDK_CHECK_STATUS(sts, "EnumImplementations(m_deviceID, m_adapterNum) failed");
9218+
9219+ if (m_eDevType == MFX_HANDLE_D3D9_DEVICE_MANAGER) {
9220+ if (bNeedToCreateDevice) {
9221+ mfxAllocatorParams* pAllocParam(new D3DAllocatorParams());
9222+ D3DAllocatorParams* pD3DParams = dynamic_cast<D3DAllocatorParams*>(pAllocParam);
9223+ std::unique_ptr<CHWDevice> hwdev(new CD3D9Device());
9224+
9225+ /* The last param set in vector always describe VPP+ENCODE or Only VPP
9226+ * So, if we want to do rendering we need to do pass HWDev to CTranscodingPipeline */
9227+ if (m_InputParamsArray[m_InputParamsArray.size() - 1].eModeExt == VppCompOnly) {
9228+ /* Rendering case */
9229+ //sts = hwdev->Init(NULL, 1, MSDKAdapter::GetNumber(0, m_pLoader.get()));
9230+ sts = hwdev->Init(NULL, 1, 0);
9231+ m_InputParamsArray[m_InputParamsArray.size() - 1].m_hwdev = hwdev.get();
9232+ }
9233+ else /* NO RENDERING */
9234+ {
9235+ //sts = hwdev->Init(NULL, 0, MSDKAdapter::GetNumber(0, m_pLoader.get()));
9236+ sts = hwdev->Init(NULL, 0, 0);
9237+ }
9238+ MSDK_CHECK_STATUS(sts, "hwdev->Init failed");
9239+ sts = hwdev->GetHandle(MFX_HANDLE_D3D9_DEVICE_MANAGER, (mfxHDL*)&hdl);
9240+ MSDK_CHECK_STATUS(sts, "hwdev->GetHandle failed");
9241+ // set Device Manager to external dx9 allocator
9242+ pD3DParams->pManager = (IDirect3DDeviceManager9*)hdl;
9243+
9244+ m_pAllocParams.push_back(std::shared_ptr<mfxAllocatorParams>(pAllocParam));
9245+ m_hwdevs.push_back(std::move(hwdev));
9246+ hdls.push_back(hdl);
9247+ }
9248+ else {
9249+ if (!m_pAllocParams.empty() && !hdls.empty()) {
9250+ m_pAllocParams.push_back(m_pAllocParams.back());
9251+ hdls.push_back(hdls.back());
9252+ }
9253+ else {
9254+ msdk_printf(MSDK_STRING("error: failed to initialize alloc parameters\n"));
9255+ return MFX_ERR_MEMORY_ALLOC;
9256+ }
9257+ }
9258+ }
9259+ #if MFX_D3D11_SUPPORT
9260+ else if (m_eDevType == MFX_HANDLE_D3D11_DEVICE) {
9261+ if (bNeedToCreateDevice) {
9262+ mfxAllocatorParams* pAllocParam(new D3D11AllocatorParams());
9263+ D3D11AllocatorParams* pD3D11Params =
9264+ dynamic_cast<D3D11AllocatorParams*>(pAllocParam);
9265+ std::unique_ptr<CHWDevice> hwdev(new CD3D11Device());
9266+
9267+ /* The last param set in vector always describe VPP+ENCODE or Only VPP
9268+ * So, if we want to do rendering we need to do pass HWDev to CTranscodingPipeline */
9269+ if (m_InputParamsArray[m_InputParamsArray.size() - 1].eModeExt == VppCompOnly) {
9270+ /* Rendering case */
9271+ //sts = hwdev->Init(NULL, 1, MSDKAdapter::GetNumber(0, m_pLoader.get()));
9272+ sts = hwdev->Init(NULL, 1, 0);
9273+ m_InputParamsArray[m_InputParamsArray.size() - 1].m_hwdev = hwdev.get();
9274+ }
9275+ else /* NO RENDERING */
9276+ {
9277+ //sts = hwdev->Init(NULL, 0, MSDKAdapter::GetNumber(0, m_pLoader.get()));
9278+ sts = hwdev->Init(NULL, 0, 0);
9279+ }
9280+ MSDK_CHECK_STATUS(sts, "hwdev->Init failed");
9281+ sts = hwdev->GetHandle(MFX_HANDLE_D3D11_DEVICE, (mfxHDL*)&hdl);
9282+ MSDK_CHECK_STATUS(sts, "hwdev->GetHandle failed");
9283+
9284+ pD3D11Params->bUseSingleTexture = m_InputParamsArray[i].bSingleTexture;
9285+ // set Device to external dx11 allocator
9286+ pD3D11Params->pDevice = (ID3D11Device*)hdl;
9287+
9288+ m_pAllocParams.push_back(std::shared_ptr<mfxAllocatorParams>(pAllocParam));
9289+ m_hwdevs.push_back(std::move(hwdev));
9290+ hdls.push_back(hdl);
9291+ }
9292+ else {
9293+ if (!m_pAllocParams.empty() && !hdls.empty()) {
9294+ m_pAllocParams.push_back(m_pAllocParams.back());
9295+ hdls.push_back(hdls.back());
9296+ }
9297+ else {
9298+ msdk_printf(MSDK_STRING("error: failed to initialize alloc parameters\n"));
9299+ return MFX_ERR_MEMORY_ALLOC;
9300+ }
9301+ }
9302+ }
9303+ #endif
9304+#elif defined(LIBVA_X11_SUPPORT) || defined(LIBVA_DRM_SUPPORT) || defined(ANDROID)
9305+ if (m_eDevType == MFX_HANDLE_VA_DISPLAY) {
9306+ if (bNeedToCreateDevice) {
9307+ mfxI32 libvaBackend = 0;
9308+ mfxAllocatorParams* pAllocParam(new vaapiAllocatorParams);
9309+ std::unique_ptr<CHWDevice> hwdev;
9310+
9311+ vaapiAllocatorParams* pVAAPIParams =
9312+ dynamic_cast<vaapiAllocatorParams*>(pAllocParam);
9313+ /* The last param set in vector always describe VPP+ENCODE or Only VPP
9314+ * So, if we want to do rendering we need to do pass HWDev to CTranscodingPipeline */
9315+ if (m_InputParamsArray[m_InputParamsArray.size() - 1].eModeExt == VppCompOnly) {
9316+ sInputParams& params = m_InputParamsArray[m_InputParamsArray.size() - 1];
9317+ libvaBackend = params.libvaBackend;
9318+
9319+ /* Rendering case */
9320+ hwdev.reset(CreateVAAPIDevice(InputParams.strDevicePath, params.libvaBackend));
9321+ if (!hwdev.get()) {
9322+ msdk_printf(MSDK_STRING("error: failed to initialize VAAPI device\n"));
9323+ return MFX_ERR_DEVICE_FAILED;
9324+ }
9325+ //sts = hwdev->Init(&params.monitorType, 1, MSDKAdapter::GetNumber(0, m_pLoader.get()));
9326+ sts = hwdev->Init(&params.monitorType, 1, 0);
9327+ #if defined(LIBVA_X11_SUPPORT) || defined(LIBVA_DRM_SUPPORT)
9328+ if (params.libvaBackend == MFX_LIBVA_DRM_MODESET) {
9329+ CVAAPIDeviceDRM* drmdev = dynamic_cast<CVAAPIDeviceDRM*>(hwdev.get());
9330+ pVAAPIParams->m_export_mode = vaapiAllocatorParams::CUSTOM_FLINK;
9331+ pVAAPIParams->m_exporter =
9332+ dynamic_cast<vaapiAllocatorParams::Exporter*>(drmdev->getRenderer());
9333+ }
9334+ else if (params.libvaBackend == MFX_LIBVA_X11) {
9335+ pVAAPIParams->m_export_mode = vaapiAllocatorParams::PRIME;
9336+ }
9337+ #endif
9338+ #if defined(LIBVA_WAYLAND_SUPPORT)
9339+ else if (params.libvaBackend == MFX_LIBVA_WAYLAND) {
9340+ VADisplay va_dpy = NULL;
9341+ sts = hwdev->GetHandle(MFX_HANDLE_VA_DISPLAY, (mfxHDL*)&va_dpy);
9342+ MSDK_CHECK_STATUS(sts, "hwdev->GetHandle failed");
9343+ hdl = pVAAPIParams->m_dpy = (VADisplay)va_dpy;
9344+
9345+ CVAAPIDeviceWayland* w_dev =
9346+ dynamic_cast<CVAAPIDeviceWayland*>(hwdev.get());
9347+ if (!w_dev) {
9348+ MSDK_CHECK_STATUS(MFX_ERR_DEVICE_FAILED,
9349+ "Failed to reach Wayland VAAPI device");
9350+ }
9351+ Wayland* wld = w_dev->GetWaylandHandle();
9352+ if (!wld) {
9353+ MSDK_CHECK_STATUS(MFX_ERR_DEVICE_FAILED,
9354+ "Failed to reach Wayland VAAPI device");
9355+ }
9356+
9357+ wld->SetRenderWinPos(params.nRenderWinX, params.nRenderWinY);
9358+ wld->SetPerfMode(params.bPerfMode);
9359+
9360+ pVAAPIParams->m_export_mode = vaapiAllocatorParams::PRIME;
9361+ }
9362+ #endif // LIBVA_WAYLAND_SUPPORT
9363+ params.m_hwdev = hwdev.get();
9364+ }
9365+ else /* NO RENDERING*/
9366+ {
9367+ hwdev.reset(CreateVAAPIDevice(InputParams.strDevicePath));
9368+
9369+ if (!hwdev.get()) {
9370+ msdk_printf(MSDK_STRING("error: failed to initialize VAAPI device\n"));
9371+ return MFX_ERR_DEVICE_FAILED;
9372+ }
9373+ //sts = hwdev->Init(NULL, 0, MSDKAdapter::GetNumber(0, m_pLoader.get()));
9374+ sts = hwdev->Init(NULL, 0, 0);
9375+ }
9376+ if (libvaBackend != MFX_LIBVA_WAYLAND) {
9377+ MSDK_CHECK_STATUS(sts, "hwdev->Init failed");
9378+ sts = hwdev->GetHandle(MFX_HANDLE_VA_DISPLAY, (mfxHDL*)&hdl);
9379+ MSDK_CHECK_STATUS(sts, "hwdev->GetHandle failed");
9380+ // set Device to external vaapi allocator
9381+ pVAAPIParams->m_dpy = (VADisplay)hdl;
9382+ }
9383+
9384+ m_pAllocParams.push_back(std::shared_ptr<mfxAllocatorParams>(pAllocParam));
9385+ m_hwdevs.push_back(std::move(hwdev));
9386+ hdls.push_back(hdl);
9387+ }
9388+ else {
9389+ if (!m_pAllocParams.empty() && !hdls.empty()) {
9390+ m_pAllocParams.push_back(m_pAllocParams.back());
9391+ hdls.push_back(hdls.back());
9392+ }
9393+ else {
9394+ msdk_printf(MSDK_STRING("error: failed to initialize alloc parameters\n"));
9395+ return MFX_ERR_MEMORY_ALLOC;
9396+ }
9397+ }
9398+ }
9399+#endif
9400+ }
9401+ if (m_pAllocParams.empty()) {
9402+ m_pAllocParams.push_back(std::shared_ptr<mfxAllocatorParams>(new SysMemAllocatorParams));
9403+ hdls.push_back(NULL);
9404+
9405+ for (i = 1; i < m_InputParamsArray.size(); i++) {
9406+ m_pAllocParams.push_back(m_pAllocParams.back());
9407+ hdls.push_back(NULL);
9408+ }
9409+ }
9410+
9411+ // each pair of source and sink has own safety buffer
9412+ sts = CreateSafetyBuffers();
9413+ MSDK_CHECK_STATUS(sts, "CreateSafetyBuffers failed");
9414+
9415+ /* One more hint. Example you have 3 dec + 1 enc sessions
9416+ * (enc means vpp_comp call invoked. m_InputParamsArray.size() is 4.
9417+ * You don't need take vpp comp params from last one session as it is enc session.
9418+ * But you need process {0, 1, 2} sessions - totally 3.
9419+ * So, you need start from 0 and end at 2.
9420+ * */
9421+ for (mfxI32 jj = 0; jj < (mfxI32)m_InputParamsArray.size() - 1; jj++) {
9422+ /* Save params for VPP composition */
9423+ sVppCompDstRect tempDstRect;
9424+ tempDstRect.DstX = m_InputParamsArray[jj].nVppCompDstX;
9425+ tempDstRect.DstY = m_InputParamsArray[jj].nVppCompDstY;
9426+ tempDstRect.DstW = m_InputParamsArray[jj].nVppCompDstW;
9427+ tempDstRect.DstH = m_InputParamsArray[jj].nVppCompDstH;
9428+ tempDstRect.TileId = m_InputParamsArray[jj].nVppCompTileId;
9429+ m_VppDstRects.push_back(tempDstRect);
9430+ }
9431+
9432+ // create sessions, allocators
9433+ for (i = 0; i < m_InputParamsArray.size(); i++) {
9434+ msdk_printf(MSDK_STRING("Session %d:\n"), i);
9435+ std::unique_ptr<GeneralAllocator> pAllocator(new GeneralAllocator);
9436+ sts = pAllocator->Init(m_pAllocParams[i].get());
9437+ MSDK_CHECK_STATUS(sts, "pAllocator->Init failed");
9438+
9439+ m_pAllocArray.push_back(std::move(pAllocator));
9440+
9441+ std::unique_ptr<ThreadTranscodeContext> pThreadPipeline(new ThreadTranscodeContext);
9442+ // extend BS processing init
9443+ m_pExtBSProcArray.push_back(
9444+ std::unique_ptr<FileBitstreamProcessor>(new FileBitstreamProcessor));
9445+
9446+ pThreadPipeline->pPipeline.reset(CreatePipeline());
9447+
9448+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
9449+ pThreadPipeline->pPipeline->SetPrefferiGfx(m_InputParamsArray[i].bPrefferiGfx);
9450+ pThreadPipeline->pPipeline->SetPrefferdGfx(m_InputParamsArray[i].bPrefferdGfx);
9451+#endif
9452+
9453+ pThreadPipeline->pBSProcessor = m_pExtBSProcArray.back().get();
9454+
9455+ std::unique_ptr<CSmplBitstreamReader> reader;
9456+ std::unique_ptr<CSmplYUVReader> yuvreader;
9457+ if (m_InputParamsArray[i].DecodeId == MFX_CODEC_VP9 ||
9458+ m_InputParamsArray[i].DecodeId == MFX_CODEC_VP8 ||
9459+ m_InputParamsArray[i].DecodeId == MFX_CODEC_AV1) {
9460+ reader.reset(new CIVFFrameReader());
9461+ }
9462+ else if (m_InputParamsArray[i].DecodeId == MFX_CODEC_RGB4 ||
9463+ m_InputParamsArray[i].DecodeId == MFX_CODEC_I420 ||
9464+ m_InputParamsArray[i].DecodeId == MFX_CODEC_NV12) {
9465+ // YUV reader for RGB4 overlay and raw input
9466+ yuvreader.reset(new CSmplYUVReader());
9467+ }
9468+ else {
9469+ reader.reset(new CSmplBitstreamReader());
9470+ }
9471+
9472+ if (reader.get()) {
9473+ sts = reader->Init(m_InputParamsArray[i].strSrcFile);
9474+ MSDK_CHECK_STATUS(sts, "reader->Init failed");
9475+ sts = m_pExtBSProcArray.back()->SetReader(reader);
9476+ MSDK_CHECK_STATUS(sts, "m_pExtBSProcArray.back()->SetReader failed");
9477+ }
9478+ else if (yuvreader.get()) {
9479+ std::list<msdk_string> input;
9480+ input.push_back(m_InputParamsArray[i].strSrcFile);
9481+ sts = yuvreader->Init(input, m_InputParamsArray[i].DecodeId);
9482+ MSDK_CHECK_STATUS(sts, "m_YUVReader->Init failed");
9483+ sts = m_pExtBSProcArray.back()->SetReader(yuvreader);
9484+ MSDK_CHECK_STATUS(sts, "m_pExtBSProcArray.back()->SetReader failed");
9485+ }
9486+
9487+ std::unique_ptr<CSmplBitstreamWriter> writer(new CSmplBitstreamWriter());
9488+ sts = writer->Init(m_InputParamsArray[i].strDstFile);
9489+
9490+ sts = m_pExtBSProcArray.back()->SetWriter(writer);
9491+ MSDK_CHECK_STATUS(sts, "m_pExtBSProcArray.back()->SetWriter failed");
9492+
9493+ if (Sink == m_InputParamsArray[i].eMode) {
9494+ /* N_to_1 mode */
9495+ if ((VppComp == m_InputParamsArray[i].eModeExt) ||
9496+ (VppCompOnly == m_InputParamsArray[i].eModeExt)) {
9497+ // Taking buffers from tail because they are stored in m_pBufferArray in reverse order
9498+ // So, by doing this we'll fill buffers properly according to order from par file
9499+ pBuffer = m_pBufferArray[m_pBufferArray.size() - 1 - BufCounter].get();
9500+ BufCounter++;
9501+ }
9502+ else /* 1_to_N mode*/
9503+ {
9504+ pBuffer = m_pBufferArray[m_pBufferArray.size() - 1].get();
9505+ }
9506+ pSinkPipeline = pThreadPipeline->pPipeline.get();
9507+ }
9508+ else if (Source == m_InputParamsArray[i].eMode) {
9509+ /* N_to_1 mode */
9510+ if ((VppComp == m_InputParamsArray[i].eModeExt) ||
9511+ (VppCompOnly == m_InputParamsArray[i].eModeExt)) {
9512+ pBuffer = m_pBufferArray[m_pBufferArray.size() - 1].get();
9513+ }
9514+ else /* 1_to_N mode*/
9515+ {
9516+ pBuffer = m_pBufferArray[BufCounter].get();
9517+ BufCounter++;
9518+ }
9519+ }
9520+ else {
9521+ pBuffer = NULL;
9522+ }
9523+
9524+ /**/
9525+ /* Vector stored linearly in the memory !*/
9526+ m_InputParamsArray[i].pVppCompDstRects = m_VppDstRects.empty() ? NULL : &m_VppDstRects[0];
9527+
9528+ // if session has VPP plus ENCODE only (-i::source option)
9529+ // use decode source session as input
9530+ sts = MFX_ERR_MORE_DATA;
9531+ if (Source == m_InputParamsArray[i].eMode) {
9532+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
9533+ sts = CheckAndFixAdapterDependency(i, pSinkPipeline);
9534+ MSDK_CHECK_STATUS(sts, "CheckAndFixAdapterDependency failed");
9535+ // force implementation type based on iGfx/dGfx parameters
9536+ if (m_InputParamsArray[i].libType != MFX_IMPL_SOFTWARE) {
9537+ ForceImplForSession(i);
9538+ sts = m_pLoader->EnumImplementations(m_deviceID, m_adapterNum);
9539+ MSDK_CHECK_STATUS(sts, "EnumImplementations(m_deviceID, m_adapterNum) failed");
9540+ }
9541+#endif
9542+ sts = pThreadPipeline->pPipeline->Init(&m_InputParamsArray[i],
9543+ m_pAllocArray[i].get(),
9544+ hdls[i],
9545+ pSinkPipeline,
9546+ pBuffer,
9547+ m_pExtBSProcArray.back().get(),
9548+ m_pLoader.get());
9549+ }
9550+ else {
9551+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
9552+ sts = CheckAndFixAdapterDependency(i, pParentPipeline);
9553+ MSDK_CHECK_STATUS(sts, "CheckAndFixAdapterDependency failed");
9554+ // force implementation type based on iGfx/dGfx parameters
9555+ if (m_InputParamsArray[i].libType != MFX_IMPL_SOFTWARE) {
9556+ ForceImplForSession(i);
9557+ sts = m_pLoader->EnumImplementations(m_deviceID, m_adapterNum);
9558+ MSDK_CHECK_STATUS(sts, "EnumImplementations(m_deviceID, m_adapterNum) failed");
9559+ }
9560+#endif
9561+ sts = pThreadPipeline->pPipeline->Init(&m_InputParamsArray[i],
9562+ m_pAllocArray[i].get(),
9563+ hdls[i],
9564+ pParentPipeline,
9565+ pBuffer,
9566+ m_pExtBSProcArray.back().get(),
9567+ m_pLoader.get());
9568+ }
9569+
9570+ MSDK_CHECK_STATUS(sts, "pThreadPipeline->pPipeline->Init failed");
9571+
9572+ if (!pParentPipeline && m_InputParamsArray[i].bIsJoin)
9573+ pParentPipeline = pThreadPipeline->pPipeline.get();
9574+
9575+ // set the session's start status (like it is waiting)
9576+ pThreadPipeline->startStatus = MFX_WRN_DEVICE_BUSY;
9577+ // set other session's parameters
9578+ pThreadPipeline->implType = m_InputParamsArray[i].libType;
9579+ m_pThreadContextArray.push_back(std::move(pThreadPipeline));
9580+
9581+ mfxVersion ver = { { 0, 0 } };
9582+ sts = m_pThreadContextArray[i]->pPipeline->QueryMFXVersion(&ver);
9583+ MSDK_CHECK_STATUS(sts, "m_pThreadContextArray[i]->pPipeline->QueryMFXVersion failed");
9584+
9585+ PrintInfo(i, &m_InputParamsArray[i], &ver);
9586+ }
9587+
9588+ for (i = 0; i < m_InputParamsArray.size(); i++) {
9589+ sts = m_pThreadContextArray[i]->pPipeline->CompleteInit();
9590+ MSDK_CHECK_STATUS(sts, "m_pThreadContextArray[i]->pPipeline->CompleteInit failed");
9591+
9592+ if (m_pThreadContextArray[i]->pPipeline->GetJoiningFlag())
9593+ msdk_printf(MSDK_STRING("Session %d was joined with other sessions\n"), i);
9594+ else
9595+ msdk_printf(MSDK_STRING("Session %d was NOT joined with other sessions\n"), i);
9596+
9597+ m_pThreadContextArray[i]->pPipeline->SetPipelineID(i);
9598+ }
9599+
9600+ msdk_printf(MSDK_STRING("\n"));
9601+
9602+ return sts;
9603+
9604+} // mfxStatus Launcher::Init()
9605+
9606+void Launcher::Run() {
9607+ msdk_printf(MSDK_STRING("Transcoding started\n"));
9608+
9609+ // mark start time
9610+ m_StartTime = GetTick();
9611+
9612+ // Robust flag is applied to every seession if enabled in one
9613+ if (m_pThreadContextArray[0]->pPipeline->GetRobustFlag()) {
9614+ DoRobustTranscoding();
9615+ }
9616+ else {
9617+ DoTranscoding();
9618+ }
9619+
9620+ msdk_printf(MSDK_STRING("\nTranscoding finished\n"));
9621+
9622+} // mfxStatus Launcher::Init()
9623+
9624+void Launcher::DoTranscoding() {
9625+ auto RunTranscodeRoutine = [](ThreadTranscodeContext* context) {
9626+ context->handle = std::async(std::launch::async, [context]() {
9627+ context->TranscodeRoutine();
9628+ });
9629+ };
9630+
9631+ bool isOverlayUsed = false;
9632+ for (const auto& context : m_pThreadContextArray) {
9633+ MSDK_CHECK_POINTER_NO_RET(context);
9634+ RunTranscodeRoutine(context.get());
9635+
9636+ MSDK_CHECK_POINTER_NO_RET(context->pPipeline);
9637+ isOverlayUsed = isOverlayUsed || context->pPipeline->IsOverlayUsed();
9638+ }
9639+
9640+ // Transcoding threads waiting cycle
9641+ bool aliveNonOverlaySessions = true;
9642+ while (aliveNonOverlaySessions) {
9643+ aliveNonOverlaySessions = false;
9644+
9645+ for (size_t i = 0; i < m_pThreadContextArray.size(); ++i) {
9646+ if (!m_pThreadContextArray[i]->handle.valid())
9647+ continue;
9648+
9649+ //Payslip interval to check the state of working threads:
9650+ //such interval is usually a realtime, i.e. for 30 fps this would be 33ms,
9651+ //66ms typically mean either 1/fps or 2/fps payslip checks.
9652+ auto waitSts = m_pThreadContextArray[i]->handle.wait_for(std::chrono::milliseconds(66));
9653+ if (waitSts == std::future_status::ready) {
9654+ // Invoke get() of the handle just to reset the valid state.
9655+ // This allows to skip already processed sessions
9656+ m_pThreadContextArray[i]->handle.get();
9657+
9658+ // Session is completed, let's check for its status
9659+ if (m_pThreadContextArray[i]->transcodingSts < MFX_ERR_NONE) {
9660+ // Stop all the sessions if an error happened in one
9661+ // But do not stop in robust mode when gpu hang's happened
9662+ if (m_pThreadContextArray[i]->transcodingSts != MFX_ERR_GPU_HANG ||
9663+ !m_pThreadContextArray[i]->pPipeline->GetRobustFlag()) {
9664+ msdk_stringstream ss;
9665+ ss << MSDK_STRING("\n\n session ") << i << MSDK_STRING(" [")
9666+ << m_pThreadContextArray[i]->pPipeline->GetSessionText()
9667+ << MSDK_STRING("] failed with status ")
9668+ << StatusToString(m_pThreadContextArray[i]->transcodingSts)
9669+ << MSDK_STRING(" shutting down the application...") << std::endl
9670+ << std::endl;
9671+ msdk_printf(MSDK_STRING("%s"), ss.str().c_str());
9672+
9673+ for (const auto& context : m_pThreadContextArray) {
9674+ context->pPipeline->StopSession();
9675+ }
9676+ }
9677+ }
9678+ else if (m_pThreadContextArray[i]->transcodingSts > MFX_ERR_NONE) {
9679+ msdk_stringstream ss;
9680+ ss << MSDK_STRING("\n\n session ") << i << MSDK_STRING(" [")
9681+ << m_pThreadContextArray[i]->pPipeline->GetSessionText()
9682+ << MSDK_STRING("] returned warning status ")
9683+ << StatusToString(m_pThreadContextArray[i]->transcodingSts) << std::endl
9684+ << std::endl;
9685+ msdk_printf(MSDK_STRING("%s"), ss.str().c_str());
9686+ }
9687+ }
9688+ else {
9689+ aliveNonOverlaySessions = aliveNonOverlaySessions ||
9690+ !m_pThreadContextArray[i]->pPipeline->IsOverlayUsed();
9691+ }
9692+ }
9693+
9694+ // Stop overlay sessions
9695+ // Note: Overlay sessions never stop themselves so they should be forcibly stopped
9696+ // after stopping of all non-overlay sessions
9697+ if (!aliveNonOverlaySessions && isOverlayUsed) {
9698+ // Sending stop message
9699+ for (const auto& context : m_pThreadContextArray) {
9700+ if (context->pPipeline->IsOverlayUsed()) {
9701+ context->pPipeline->StopSession();
9702+ }
9703+ }
9704+
9705+ // Waiting for them to be stopped
9706+ for (const auto& context : m_pThreadContextArray) {
9707+ if (!context->handle.valid())
9708+ continue;
9709+
9710+ context->handle.wait();
9711+ }
9712+ }
9713+ }
9714+}
9715+
9716+void Launcher::DoRobustTranscoding() {
9717+ mfxStatus sts = MFX_ERR_NONE;
9718+
9719+ // Cycle for handling MFX_ERR_GPU_HANG during transcoding
9720+ // If it's returned, reset all the pipelines and start over from the last point
9721+ bool bGPUHang = false;
9722+ for (;;) {
9723+ if (bGPUHang) {
9724+ for (size_t i = 0; i < m_pThreadContextArray.size(); i++) {
9725+ sts = m_pThreadContextArray[i]->pPipeline->Reset(m_pLoader.get());
9726+ if (sts) {
9727+ msdk_printf(
9728+ MSDK_STRING("\n[WARNING] GPU Hang recovery wasn't succeed. Exiting...\n"));
9729+ return;
9730+ }
9731+ }
9732+ bGPUHang = false;
9733+ msdk_printf(MSDK_STRING("\n[WARNING] Successfully recovered. Continue transcoding.\n"));
9734+ }
9735+
9736+ DoTranscoding();
9737+
9738+ for (size_t i = 0; i < m_pThreadContextArray.size(); i++) {
9739+ if (m_pThreadContextArray[i]->transcodingSts == MFX_ERR_GPU_HANG) {
9740+ bGPUHang = true;
9741+ }
9742+ }
9743+ if (!bGPUHang)
9744+ break;
9745+ msdk_printf(MSDK_STRING("\n[WARNING] GPU Hang has happened. Trying to recover...\n"));
9746+ }
9747+}
9748+
9749+mfxStatus Launcher::ProcessResult() {
9750+ FILE* pPerfFile = m_parser.GetPerformanceFile();
9751+
9752+ msdk_stringstream ssTranscodingTime;
9753+ ssTranscodingTime << std::endl
9754+ << MSDK_STRING("Common transcoding time is ") << GetTime(m_StartTime)
9755+ << MSDK_STRING(" sec") << std::endl;
9756+
9757+ m_parser.PrintParFileName();
9758+
9759+ msdk_printf(MSDK_STRING("%s"), ssTranscodingTime.str().c_str());
9760+ if (pPerfFile) {
9761+ msdk_fprintf(pPerfFile, MSDK_STRING("%s"), ssTranscodingTime.str().c_str());
9762+ }
9763+
9764+ mfxStatus FinalSts = MFX_ERR_NONE;
9765+ msdk_printf(MSDK_STRING(
9766+ "-------------------------------------------------------------------------------\n"));
9767+
9768+ for (mfxU32 i = 0; i < m_pThreadContextArray.size(); i++) {
9769+ mfxStatus transcodingSts = m_pThreadContextArray[i]->transcodingSts;
9770+ mfxF64 workTime = m_pThreadContextArray[i]->working_time;
9771+ mfxU32 framesNum = m_pThreadContextArray[i]->numTransFrames;
9772+
9773+ if (!FinalSts)
9774+ FinalSts = transcodingSts;
9775+
9776+ msdk_string SessionStsStr = transcodingSts ? msdk_string(MSDK_STRING("FAILED"))
9777+ : msdk_string((MSDK_STRING("PASSED")));
9778+
9779+ msdk_stringstream ss;
9780+ ss << MSDK_STRING("*** session ") << i << MSDK_STRING(" [")
9781+ << m_pThreadContextArray[i]->pPipeline->GetSessionText() << MSDK_STRING("] ")
9782+ << SessionStsStr << MSDK_STRING(" (") << StatusToString(transcodingSts)
9783+ << MSDK_STRING(") ") << workTime << MSDK_STRING(" sec, ") << framesNum
9784+ << MSDK_STRING(" frames, ") << std::fixed << std::setprecision(3) << framesNum / workTime
9785+ << MSDK_STRING(" fps") << std::endl
9786+ << m_parser.GetLine(i) << std::endl
9787+ << std::endl;
9788+
9789+ msdk_printf(MSDK_STRING("%s"), ss.str().c_str());
9790+ if (pPerfFile) {
9791+ msdk_fprintf(pPerfFile, MSDK_STRING("%s"), ss.str().c_str());
9792+ }
9793+ }
9794+ msdk_printf(MSDK_STRING(
9795+ "-------------------------------------------------------------------------------\n"));
9796+
9797+ msdk_stringstream ssTest;
9798+ ssTest << std::endl
9799+ << MSDK_STRING("The test ")
9800+ << (FinalSts ? msdk_string(MSDK_STRING("FAILED")) : msdk_string(MSDK_STRING("PASSED")))
9801+ << std::endl;
9802+
9803+ msdk_printf(MSDK_STRING("%s"), ssTest.str().c_str());
9804+ if (pPerfFile) {
9805+ msdk_fprintf(pPerfFile, MSDK_STRING("%s"), ssTest.str().c_str());
9806+ }
9807+ return FinalSts;
9808+} // mfxStatus Launcher::ProcessResult()
9809+
9810+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
9811+mfxStatus Launcher::QueryAdapters() {
9812+ mfxU32 num_adapters_available;
9813+
9814+ mfxStatus sts = MFXQueryAdaptersNumber(&num_adapters_available);
9815+ MFX_CHECK_STS(sts);
9816+
9817+ // no adapters on the machine, able to use software implementation
9818+ if (!num_adapters_available) {
9819+ return MFX_ERR_NONE;
9820+ }
9821+
9822+ m_DisplaysData.resize(num_adapters_available);
9823+ m_Adapters = { m_DisplaysData.data(), mfxU32(m_DisplaysData.size()), 0u };
9824+
9825+ sts = MFXQueryAdapters(nullptr, &m_Adapters);
9826+ MFX_CHECK_STS(sts);
9827+
9828+ return MFX_ERR_NONE;
9829+}
9830+
9831+void Launcher::ForceImplForSession(mfxU32 idxSession) {
9832+ if (m_InputParamsArray[idxSession].libType == MFX_IMPL_SOFTWARE)
9833+ return;
9834+
9835+ //change only 8 bit of the implementation. Don't touch type of frames
9836+ mfxIMPL impl = m_InputParamsArray[idxSession].libType & mfxI32(~0xFF);
9837+
9838+ mfxU32 idx = GetPreferredAdapterNum(m_Adapters, m_InputParamsArray[idxSession]);
9839+ switch (m_Adapters.Adapters[idx].Number) {
9840+ case 0:
9841+ impl |= MFX_IMPL_HARDWARE;
9842+ break;
9843+ case 1:
9844+ impl |= MFX_IMPL_HARDWARE2;
9845+ break;
9846+ case 2:
9847+ impl |= MFX_IMPL_HARDWARE3;
9848+ break;
9849+ case 3:
9850+ impl |= MFX_IMPL_HARDWARE4;
9851+ break;
9852+
9853+ default:
9854+ // try searching on all display adapters
9855+ impl |= MFX_IMPL_HARDWARE_ANY;
9856+ break;
9857+ }
9858+
9859+ m_InputParamsArray[idxSession].libType = impl;
9860+ m_adapterNum = m_Adapters.Adapters[idx].Number;
9861+ m_deviceID = m_Adapters.Adapters[idx].Platform.DeviceId;
9862+}
9863+
9864+mfxStatus Launcher::CheckAndFixAdapterDependency(mfxU32 idxSession,
9865+ CTranscodingPipeline* pParentPipeline) {
9866+ if (!pParentPipeline)
9867+ return MFX_ERR_NONE;
9868+
9869+ // Inherited sessions must have the same adapter as parent
9870+ if ((pParentPipeline->IsPrefferiGfx() || pParentPipeline->IsPrefferdGfx()) &&
9871+ !m_InputParamsArray[idxSession].bPrefferiGfx &&
9872+ !m_InputParamsArray[idxSession].bPrefferdGfx) {
9873+ m_InputParamsArray[idxSession].bPrefferiGfx = pParentPipeline->IsPrefferiGfx();
9874+ m_InputParamsArray[idxSession].bPrefferdGfx = pParentPipeline->IsPrefferdGfx();
9875+ msdk_stringstream ss;
9876+ ss << MSDK_STRING("\n\n session with index: ") << idxSession
9877+ << MSDK_STRING(" adapter type was forced to ")
9878+ << (pParentPipeline->IsPrefferiGfx() ? MSDK_STRING("integrated")
9879+ : MSDK_STRING("discrete"))
9880+ << std::endl
9881+ << std::endl;
9882+ msdk_printf(MSDK_STRING("%s"), ss.str().c_str());
9883+
9884+ return MFX_ERR_NONE;
9885+ }
9886+
9887+ // App can't change initialization of the previous session (parent session)
9888+ if (!pParentPipeline->IsPrefferiGfx() && !pParentPipeline->IsPrefferdGfx() &&
9889+ (m_InputParamsArray[idxSession].bPrefferiGfx ||
9890+ m_InputParamsArray[idxSession].bPrefferdGfx)) {
9891+ msdk_stringstream ss;
9892+ ss << MSDK_STRING("\n\n session with index: ") << idxSession
9893+ << MSDK_STRING(" failed because parent session [") << pParentPipeline->GetSessionText()
9894+ << MSDK_STRING("] doesn't have explicit adapter setting") << std::endl
9895+ << std::endl;
9896+ msdk_printf(MSDK_STRING("%s"), ss.str().c_str());
9897+
9898+ return MFX_ERR_UNSUPPORTED;
9899+ }
9900+
9901+ // Inherited sessions must have the same adapter as parent
9902+ if (pParentPipeline->IsPrefferiGfx() && !m_InputParamsArray[idxSession].bPrefferiGfx) {
9903+ msdk_stringstream ss;
9904+ ss << MSDK_STRING("\n\n session with index: ") << idxSession
9905+ << MSDK_STRING(" failed because it has different adapter type with parent session [")
9906+ << pParentPipeline->GetSessionText() << MSDK_STRING("]") << std::endl
9907+ << std::endl;
9908+ msdk_printf(MSDK_STRING("%s"), ss.str().c_str());
9909+
9910+ return MFX_ERR_UNSUPPORTED;
9911+ }
9912+
9913+ // Inherited sessions must have the same adapter as parent
9914+ if (pParentPipeline->IsPrefferdGfx() && !m_InputParamsArray[idxSession].bPrefferdGfx) {
9915+ msdk_stringstream ss;
9916+ ss << MSDK_STRING("\n\n session with index: ") << idxSession
9917+ << MSDK_STRING(" failed because it has different adapter type with parent session [")
9918+ << pParentPipeline->GetSessionText() << MSDK_STRING("]") << std::endl
9919+ << std::endl;
9920+ msdk_printf(MSDK_STRING("%s"), ss.str().c_str());
9921+
9922+ return MFX_ERR_UNSUPPORTED;
9923+ }
9924+
9925+ return MFX_ERR_NONE;
9926+}
9927+#endif //(_WIN32 || _WIN64) && (MFX_VERSION >= 1031)
9928+
9929+mfxStatus Launcher::VerifyCrossSessionsOptions() {
9930+ bool IsSinkPresence = false;
9931+ bool IsSourcePresence = false;
9932+ bool IsHeterSessionJoin = false;
9933+ bool IsFirstInTopology = true;
9934+
9935+ mfxU16 minAsyncDepth = 0;
9936+ bool bUseExternalAllocator = false;
9937+ bool bSingleTexture = false;
9938+
9939+#if (MFX_VERSION >= 1025)
9940+ bool allMFEModesEqual = true;
9941+ bool allMFEFramesEqual = true;
9942+ bool allMFESessionsJoined = true;
9943+
9944+ mfxU16 usedMFEMaxFrames = 0;
9945+ mfxU16 usedMFEMode = 0;
9946+
9947+ for (mfxU32 i = 0; i < m_InputParamsArray.size(); i++) {
9948+ // loop over all sessions and check mfe-specific params
9949+ // for mfe is required to have sessions joined, HW impl
9950+ if (m_InputParamsArray[i].numMFEFrames > 1) {
9951+ usedMFEMaxFrames = m_InputParamsArray[i].numMFEFrames;
9952+ for (mfxU32 j = 0; j < m_InputParamsArray.size(); j++) {
9953+ if (m_InputParamsArray[j].numMFEFrames &&
9954+ m_InputParamsArray[j].numMFEFrames != usedMFEMaxFrames) {
9955+ m_InputParamsArray[j].numMFEFrames = usedMFEMaxFrames;
9956+ allMFEFramesEqual = false;
9957+ m_InputParamsArray[j].MFMode = m_InputParamsArray[j].MFMode < MFX_MF_AUTO
9958+ ? MFX_MF_AUTO
9959+ : m_InputParamsArray[j].MFMode;
9960+ }
9961+ if (m_InputParamsArray[j].bIsJoin == false) {
9962+ allMFESessionsJoined = false;
9963+ m_InputParamsArray[j].bIsJoin = true;
9964+ }
9965+ }
9966+ }
9967+ if (m_InputParamsArray[i].MFMode >= MFX_MF_AUTO) {
9968+ usedMFEMode = m_InputParamsArray[i].MFMode;
9969+ for (mfxU32 j = 0; j < m_InputParamsArray.size(); j++) {
9970+ if (m_InputParamsArray[j].MFMode && m_InputParamsArray[j].MFMode != usedMFEMode) {
9971+ m_InputParamsArray[j].MFMode = usedMFEMode;
9972+ allMFEModesEqual = false;
9973+ }
9974+ if (m_InputParamsArray[j].bIsJoin == false) {
9975+ allMFESessionsJoined = false;
9976+ m_InputParamsArray[j].bIsJoin = true;
9977+ }
9978+ }
9979+ }
9980+ }
9981+ if (!allMFEFramesEqual)
9982+ msdk_printf(
9983+ MSDK_STRING(
9984+ "WARNING: All sessions for MFE should have the same number of MFE frames!\n used ammount of frame for MFE: %d\n"),
9985+ (int)usedMFEMaxFrames);
9986+ if (!allMFEModesEqual)
9987+ msdk_printf(
9988+ MSDK_STRING(
9989+ "WARNING: All sessions for MFE should have the same mode!\n, used mode: %d\n"),
9990+ (int)usedMFEMode);
9991+ if (!allMFESessionsJoined)
9992+ msdk_printf(MSDK_STRING(
9993+ "WARNING: Sessions for MFE should be joined! All sessions forced to be joined\n"));
9994+#endif
9995+
9996+ for (mfxU32 i = 0; i < m_InputParamsArray.size(); i++) {
9997+ // Any plugin or static frame alpha blending
9998+ // CPU rotate plugin works with opaq frames in native mode
9999+ if ((m_InputParamsArray[i].nRotationAngle && m_InputParamsArray[i].eMode != Native) ||
10000+ m_InputParamsArray[i].bOpenCL || m_InputParamsArray[i].EncoderFourCC ||
10001+ m_InputParamsArray[i].DecoderFourCC || m_InputParamsArray[i].nVppCompSrcH ||
10002+ m_InputParamsArray[i].nVppCompSrcW) {
10003+ bUseExternalAllocator = true;
10004+ }
10005+
10006+ if (m_InputParamsArray[i].bSingleTexture) {
10007+ bSingleTexture = true;
10008+ }
10009+
10010+ // All sessions have to know about timeout
10011+ if (m_InputParamsArray[i].nTimeout && (m_InputParamsArray[i].eMode == Sink)) {
10012+ for (mfxU32 j = 0; j < m_InputParamsArray.size(); j++) {
10013+ if (m_InputParamsArray[j].MaxFrameNumber != MFX_INFINITE) {
10014+ msdk_printf(MSDK_STRING(
10015+ "\"-timeout\" option isn't compatible with \"-n\". \"-n\" will be ignored.\n"));
10016+ for (mfxU32 k = 0; k < m_InputParamsArray.size(); k++) {
10017+ m_InputParamsArray[k].MaxFrameNumber = MFX_INFINITE;
10018+ }
10019+ break;
10020+ }
10021+ }
10022+ msdk_printf(MSDK_STRING("Timeout %d seconds has been set to all sessions\n"),
10023+ m_InputParamsArray[i].nTimeout);
10024+ for (mfxU32 j = 0; j < m_InputParamsArray.size(); j++) {
10025+ m_InputParamsArray[j].nTimeout = m_InputParamsArray[i].nTimeout;
10026+ }
10027+ }
10028+
10029+ // All sessions have to know if robust mode enabled
10030+ if (m_InputParamsArray[i].bRobustFlag) {
10031+ for (mfxU32 j = 0; j < m_InputParamsArray.size(); j++) {
10032+ m_InputParamsArray[j].bRobustFlag = m_InputParamsArray[i].bRobustFlag;
10033+ }
10034+ }
10035+
10036+ if (Source == m_InputParamsArray[i].eMode) {
10037+ if (m_InputParamsArray[i].nAsyncDepth < minAsyncDepth) {
10038+ minAsyncDepth = m_InputParamsArray[i].nAsyncDepth;
10039+ }
10040+ // topology definition
10041+ if (!IsSinkPresence) {
10042+ PrintError(MSDK_STRING(
10043+ "Error in par file. Decode source session must be declared BEFORE encode sinks \n"));
10044+ return MFX_ERR_UNSUPPORTED;
10045+ }
10046+ IsSourcePresence = true;
10047+
10048+ if (IsFirstInTopology) {
10049+ if (m_InputParamsArray[i].bIsJoin)
10050+ IsHeterSessionJoin = true;
10051+ else
10052+ IsHeterSessionJoin = false;
10053+ }
10054+ else {
10055+ if (m_InputParamsArray[i].bIsJoin && !IsHeterSessionJoin) {
10056+ PrintError(MSDK_STRING(
10057+ "Error in par file. All heterogeneous sessions must be joined \n"));
10058+ return MFX_ERR_UNSUPPORTED;
10059+ }
10060+ if (!m_InputParamsArray[i].bIsJoin && IsHeterSessionJoin) {
10061+ PrintError(MSDK_STRING(
10062+ "Error in par file. All heterogeneous sessions must be NOT joined \n"));
10063+ return MFX_ERR_UNSUPPORTED;
10064+ }
10065+ }
10066+
10067+ if (IsFirstInTopology)
10068+ IsFirstInTopology = false;
10069+ }
10070+ else if (Sink == m_InputParamsArray[i].eMode) {
10071+ minAsyncDepth = m_InputParamsArray[i].nAsyncDepth;
10072+ IsSinkPresence = true;
10073+
10074+ if (IsFirstInTopology) {
10075+ if (m_InputParamsArray[i].bIsJoin)
10076+ IsHeterSessionJoin = true;
10077+ else
10078+ IsHeterSessionJoin = false;
10079+ }
10080+ else {
10081+ if (m_InputParamsArray[i].bIsJoin && !IsHeterSessionJoin) {
10082+ PrintError(MSDK_STRING(
10083+ "Error in par file. All heterogeneous sessions must be joined \n"));
10084+ return MFX_ERR_UNSUPPORTED;
10085+ }
10086+ if (!m_InputParamsArray[i].bIsJoin && IsHeterSessionJoin) {
10087+ PrintError(MSDK_STRING(
10088+ "Error in par file. All heterogeneous sessions must be NOT joined \n"));
10089+ return MFX_ERR_UNSUPPORTED;
10090+ }
10091+ }
10092+
10093+ if (IsFirstInTopology)
10094+ IsFirstInTopology = false;
10095+ }
10096+ if (MFX_IMPL_SOFTWARE != m_InputParamsArray[i].libType) {
10097+ // TODO: can we avoid ifdef and use MFX_IMPL_VIA_VAAPI?
10098+#if defined(_WIN32) || defined(_WIN64)
10099+ if (MFX_IMPL_VIA_D3D11 == MFX_IMPL_VIA_MASK(m_InputParamsArray[i].libType)) {
10100+ m_eDevType = MFX_HANDLE_D3D11_DEVICE;
10101+ m_accelerationMode = MFX_ACCEL_MODE_VIA_D3D11;
10102+ }
10103+ else {
10104+ m_eDevType = MFX_HANDLE_D3D9_DEVICE_MANAGER;
10105+ m_accelerationMode = MFX_ACCEL_MODE_VIA_D3D9;
10106+ }
10107+#elif defined(LIBVA_SUPPORT)
10108+ m_eDevType = MFX_HANDLE_VA_DISPLAY;
10109+ m_accelerationMode = MFX_ACCEL_MODE_VIA_VAAPI;
10110+#endif
10111+ }
10112+ }
10113+
10114+ // Async depth between inter-sessions should be equal to the minimum async depth of all these sessions.
10115+ for (mfxU32 i = 0; i < m_InputParamsArray.size(); i++) {
10116+ if ((m_InputParamsArray[i].eMode == Source) || (m_InputParamsArray[i].eMode == Sink)) {
10117+ m_InputParamsArray[i].nAsyncDepth = minAsyncDepth;
10118+ }
10119+ }
10120+
10121+ if (IsSinkPresence && !IsSourcePresence) {
10122+ PrintError(MSDK_STRING("Error: Sink must be defined"));
10123+ return MFX_ERR_UNSUPPORTED;
10124+ }
10125+
10126+ if (bSingleTexture) {
10127+ bool showWarning = false;
10128+ for (mfxU32 j = 0; j < m_InputParamsArray.size(); j++) {
10129+ if (!m_InputParamsArray[j].bSingleTexture) {
10130+ showWarning = true;
10131+ }
10132+ m_InputParamsArray[j].bSingleTexture = true;
10133+ }
10134+ if (showWarning) {
10135+ msdk_printf(MSDK_STRING(
10136+ "WARNING: At least one session has -single_texture_d3d11 option, all other sessions are modified to have this setting enabled al well.\n"));
10137+ }
10138+ }
10139+
10140+ return MFX_ERR_NONE;
10141+
10142+} // mfxStatus Launcher::VerifyCrossSessionsOptions()
10143+
10144+mfxStatus Launcher::CreateSafetyBuffers() {
10145+ SafetySurfaceBuffer* pBuffer = NULL;
10146+
10147+ for (mfxU32 i = 0; i < m_InputParamsArray.size(); i++) {
10148+ /* this is for 1 to N case*/
10149+ if ((Source == m_InputParamsArray[i].eMode) && (Native == m_InputParamsArray[0].eModeExt)) {
10150+ pBuffer = new SafetySurfaceBuffer(pBuffer);
10151+ m_pBufferArray.push_back(std::unique_ptr<SafetySurfaceBuffer>(pBuffer));
10152+ }
10153+
10154+ /* And N_to_1 case: composition should be enabled!
10155+ * else it is logic error */
10156+ if ((Source != m_InputParamsArray[i].eMode) &&
10157+ ((VppComp == m_InputParamsArray[0].eModeExt) ||
10158+ (VppCompOnly == m_InputParamsArray[0].eModeExt))) {
10159+ pBuffer = new SafetySurfaceBuffer(pBuffer);
10160+ m_pBufferArray.push_back(std::unique_ptr<SafetySurfaceBuffer>(pBuffer));
10161+ }
10162+ }
10163+ return MFX_ERR_NONE;
10164+
10165+} // mfxStatus Launcher::CreateSafetyBuffers
10166+
10167+void Launcher::Close() {
10168+ while (m_pThreadContextArray.size()) {
10169+ m_pThreadContextArray[m_pThreadContextArray.size() - 1].reset();
10170+ m_pThreadContextArray.pop_back();
10171+ }
10172+
10173+ m_pAllocArray.clear();
10174+ m_pBufferArray.clear();
10175+ m_pExtBSProcArray.clear();
10176+ m_pAllocParams.clear();
10177+ m_hwdevs.clear();
10178+
10179+} // void Launcher::Close()
10180+
10181+#if defined(_WIN32) || defined(_WIN64)
10182+int _tmain(int argc, TCHAR* argv[])
10183+#else
10184+int main(int argc, char* argv[])
10185+#endif
10186+{
10187+ mfxStatus sts;
10188+ Launcher transcode;
10189+ if (argc < 2) {
10190+ msdk_printf(MSDK_STRING(
10191+ "[ERROR] Command line is empty. Use -? for getting help on available options.\n"));
10192+ return 0;
10193+ }
10194+
10195+ sts = transcode.Init(argc, argv);
10196+ if (sts == MFX_WRN_OUT_OF_RANGE) {
10197+ // There's no error in parameters parsing, but we should not continue further. For instance, in case of -? option
10198+ return MFX_ERR_NONE;
10199+ }
10200+
10201+ fflush(stdout);
10202+ fflush(stderr);
10203+
10204+ MSDK_CHECK_STATUS(sts, "transcode.Init failed");
10205+
10206+ transcode.Run();
10207+
10208+ sts = transcode.ProcessResult();
10209+ fflush(stdout);
10210+ fflush(stderr);
10211+ MSDK_CHECK_STATUS(sts, "transcode.ProcessResult failed");
10212+
10213+ return 0;
10214+}
10215diff --git a/tools/legacy/sample_multi_transcode/src/transcode_utils.cpp b/tools/legacy/sample_multi_transcode/src/transcode_utils.cpp
10216new file mode 100644
10217index 0000000..db26c82
10218--- /dev/null
10219+++ b/tools/legacy/sample_multi_transcode/src/transcode_utils.cpp
10220@@ -0,0 +1,2765 @@
10221+/******************************************************************************\
10222+Copyright (c) 2005-2020, Intel Corporation
10223+All rights reserved.
10224+
10225+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
10226+
10227+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10228+
10229+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.
10230+
10231+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.
10232+
10233+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.
10234+
10235+This sample was distributed or derived from the Intel's Media Samples package.
10236+The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
10237+or https://software.intel.com/en-us/media-client-solutions-support.
10238+\**********************************************************************************/
10239+
10240+#include "mfx_samples_config.h"
10241+#include "plugin_utils.h"
10242+
10243+#if defined(_WIN32) || defined(_WIN64)
10244+ #include <d3d9.h>
10245+ #include <psapi.h>
10246+ #include <windows.h>
10247+ #include "d3d11_allocator.h"
10248+ #include "d3d_allocator.h"
10249+#else
10250+ #include <stdarg.h>
10251+ #include "vaapi_allocator.h"
10252+#endif
10253+
10254+#include "sysmem_allocator.h"
10255+#include "transcode_utils.h"
10256+
10257+#include "version.h"
10258+
10259+#include <algorithm>
10260+#include <cctype>
10261+#include <cstdlib>
10262+#include <cstring>
10263+#include <fstream>
10264+#include <iterator>
10265+#include <sstream>
10266+#include <string>
10267+#include <vector>
10268+
10269+using namespace TranscodingSample;
10270+
10271+// parsing defines
10272+#define IS_SEPARATOR(ch) ((ch) <= ' ' || (ch) == '=')
10273+#define VAL_CHECK(val, argIdx, argName) \
10274+ { \
10275+ if (val) { \
10276+ PrintError(MSDK_STRING("Input argument number %d \"%s\" require more parameters"), \
10277+ argIdx, \
10278+ argName); \
10279+ return MFX_ERR_UNSUPPORTED; \
10280+ } \
10281+ }
10282+
10283+#define SIZE_CHECK(cond) \
10284+ { \
10285+ if (cond) { \
10286+ PrintError(MSDK_STRING("Buffer is too small")); \
10287+ return MFX_ERR_UNSUPPORTED; \
10288+ } \
10289+ }
10290+
10291+#ifndef MFX_VERSION
10292+ #error MFX_VERSION not defined
10293+#endif
10294+
10295+msdk_tick TranscodingSample::GetTick() {
10296+ return msdk_time_get_tick();
10297+}
10298+
10299+mfxF64 TranscodingSample::GetTime(msdk_tick start) {
10300+ static msdk_tick frequency = msdk_time_get_frequency();
10301+
10302+ return MSDK_GET_TIME(msdk_time_get_tick(), start, frequency);
10303+}
10304+
10305+void TranscodingSample::PrintError(const msdk_char* strErrorMessage, ...) {
10306+ if (strErrorMessage) {
10307+ msdk_printf(MSDK_STRING("ERROR: "));
10308+ va_list args;
10309+ va_start(args, strErrorMessage);
10310+ msdk_vprintf(strErrorMessage, args);
10311+ va_end(args);
10312+ msdk_printf(
10313+ MSDK_STRING("\nUsage: sample_multi_transcode [options] [--] pipeline-description\n"));
10314+ msdk_printf(MSDK_STRING(" or: sample_multi_transcode [options] -par ParFile\n"));
10315+ msdk_printf(MSDK_STRING("\n"));
10316+ msdk_printf(MSDK_STRING("Run application with -? option to get full help text.\n\n"));
10317+ }
10318+}
10319+
10320+void TranscodingSample::PrintHelp() {
10321+ msdk_printf(MSDK_STRING("Multi Transcoding Sample Version %s\n\n"),
10322+ GetMSDKSampleVersion().c_str());
10323+ msdk_printf(MSDK_STRING("Command line parameters\n"));
10324+
10325+ msdk_printf(MSDK_STRING("Usage: sample_multi_transcode [options] [--] pipeline-description\n"));
10326+ msdk_printf(MSDK_STRING(" or: sample_multi_transcode [options] -par ParFile\n"));
10327+ msdk_printf(MSDK_STRING("\n"));
10328+ msdk_printf(MSDK_STRING(" -stat <N>\n"));
10329+ msdk_printf(MSDK_STRING(" Output statistic every N transcoding cycles\n"));
10330+ msdk_printf(MSDK_STRING(" -stat-log <name>\n"));
10331+ msdk_printf(MSDK_STRING(
10332+ " Output statistic to the specified file (opened in append mode)\n"));
10333+ msdk_printf(MSDK_STRING(" -stat-per-frame <name>\n"));
10334+ msdk_printf(MSDK_STRING(
10335+ " Output per-frame latency values to a file (opened in append mode). The file name will be for an input sesssion: <name>_input_ID_<N>.log\n"));
10336+ msdk_printf(MSDK_STRING(
10337+ " or, for output session: <name>_output_ID_<N>.log; <N> - a number of a session.\n"));
10338+
10339+ msdk_printf(MSDK_STRING("Options:\n"));
10340+ // (" ............xx
10341+ msdk_printf(MSDK_STRING(" -? Print this help and exit\n"));
10342+ msdk_printf(MSDK_STRING(" -p <file-name>\n"));
10343+ msdk_printf(MSDK_STRING(" Collect performance statistics in specified file\n"));
10344+ msdk_printf(MSDK_STRING(" -timeout <seconds>\n"));
10345+ msdk_printf(MSDK_STRING(" Set time to run transcoding in seconds\n"));
10346+ msdk_printf(MSDK_STRING(" -greedy \n"));
10347+ msdk_printf(
10348+ MSDK_STRING(" Use greedy formula to calculate number of surfaces\n"));
10349+ msdk_printf(MSDK_STRING("\n"));
10350+ msdk_printf(MSDK_STRING("Pipeline description (general options):\n"));
10351+ msdk_printf(MSDK_STRING(" -i::h265|h264|mpeg2|vc1|mvc|jpeg|vp9|av1 <file-name>\n"));
10352+ msdk_printf(MSDK_STRING(" Set input file and decoder type\n"));
10353+ msdk_printf(MSDK_STRING(" -i::i420|nv12 <file-name>\n"));
10354+ msdk_printf(MSDK_STRING(" Set raw input file and color format\n"));
10355+ msdk_printf(MSDK_STRING(
10356+ " -i::rgb4_frame Set input rgb4 file for compositon. File should contain just one single frame (-vpp_comp_src_h and -vpp_comp_src_w should be specified as well).\n"));
10357+ msdk_printf(MSDK_STRING(" -o::h265|h264|mpeg2|mvc|jpeg|vp9|raw <file-name>\n"));
10358+ msdk_printf(MSDK_STRING(" Set output file and encoder type\n"));
10359+ msdk_printf(MSDK_STRING(" -sw|-hw|-hw_d3d11|-hw_d3d9\n"));
10360+ msdk_printf(MSDK_STRING(" SDK implementation to use: \n"));
10361+ msdk_printf(MSDK_STRING(
10362+ " -hw - platform-specific on default display adapter (default)\n"));
10363+ msdk_printf(MSDK_STRING(
10364+ " -hw_d3d11 - platform-specific via d3d11 (d3d11 is default for win)\n"));
10365+ msdk_printf(MSDK_STRING(" -hw_d3d9 - platform-specific via d3d9\n"));
10366+ msdk_printf(MSDK_STRING(" -sw - software\n"));
10367+#if defined(LINUX32) || defined(LINUX64)
10368+ msdk_printf(MSDK_STRING(" -device /path/to/device - set graphics device for processing\n"));
10369+ msdk_printf(
10370+ MSDK_STRING(" For example: '-device /dev/dri/card0'\n"));
10371+ msdk_printf(
10372+ MSDK_STRING(" '-device /dev/dri/renderD128'\n"));
10373+ msdk_printf(MSDK_STRING(
10374+ " If not specified, defaults to the first Intel device found on the system\n"));
10375+#endif
10376+#if (defined(_WIN64) || defined(_WIN32)) && (MFX_VERSION >= 1031)
10377+ msdk_printf(
10378+ MSDK_STRING(" [-dGfx] - preffer processing on dGfx (by default system decides)\n"));
10379+ msdk_printf(
10380+ MSDK_STRING(" [-iGfx] - preffer processing on iGfx (by default system decides)\n"));
10381+#endif
10382+#if (MFX_VERSION >= 1025)
10383+ msdk_printf(MSDK_STRING(
10384+ " -mfe_frames <N> maximum number of frames to be combined in multi-frame encode pipeline"));
10385+ msdk_printf(MSDK_STRING(" 0 - default for platform will be used\n"));
10386+ msdk_printf(MSDK_STRING(
10387+ " -mfe_mode 0|1|2|3 multi-frame encode operation mode - should be the same for all sessions\n"));
10388+ msdk_printf(MSDK_STRING(
10389+ " 0, MFE operates as DEFAULT mode, decided by SDK if MFE enabled\n"));
10390+ msdk_printf(MSDK_STRING(" 1, MFE is disabled\n"));
10391+ msdk_printf(MSDK_STRING(" 2, MFE operates as AUTO mode\n"));
10392+ msdk_printf(MSDK_STRING(" 3, MFE operates as MANUAL mode\n"));
10393+
10394+ msdk_printf(MSDK_STRING(
10395+ " -mfe_timeout <N> multi-frame encode timeout in milliseconds - set per sessions control\n"));
10396+#endif
10397+
10398+#ifdef ENABLE_MCTF
10399+ #if !defined ENABLE_MCTF_EXT
10400+ msdk_printf(MSDK_STRING(" -mctf [Strength]\n"));
10401+ msdk_printf(MSDK_STRING(" Strength is an optional value; it is in range [0...20]\n"));
10402+ msdk_printf(MSDK_STRING(" value 0 makes MCTF operates in auto mode;\n"));
10403+ msdk_printf(MSDK_STRING(
10404+ " Strength: integer, [0...20]. Default value is 0.Might be a CSV filename (upto 15 symbols); if a string is convertable to an integer, integer has a priority over filename\n"));
10405+ msdk_printf(MSDK_STRING(
10406+ " In fixed-strength mode, MCTF strength can be adjusted at framelevel;\n"));
10407+ msdk_printf(MSDK_STRING(" If no Strength is given, MCTF operates in auto mode.\n"));
10408+ #else
10409+ msdk_printf(MSDK_STRING(" -mctf MctfMode:BitsPerPixel:Strength:ME:Overlap:DB\n"));
10410+ msdk_printf(MSDK_STRING(
10411+ " every parameter may be missed; in this case default value is used.\n"));
10412+ msdk_printf(MSDK_STRING(" MctfMode: 0 - spatial filter\n"));
10413+ msdk_printf(MSDK_STRING(" MctfMode: 1- temporal filtering, 1 backward reference\n"));
10414+ msdk_printf(
10415+ MSDK_STRING(" MctfMode: 2- temporal filtering, 1 backward & 1 forward reference\n"));
10416+ msdk_printf(MSDK_STRING(
10417+ " MctfMode: 3- temporal filtering, 2 backward & 2 forward references\n"));
10418+ msdk_printf(MSDK_STRING(" MctfMode: other values: force default mode to be used\n"));
10419+ msdk_printf(MSDK_STRING(
10420+ " BitsPerPixel: float, valid range [0...12.0]; if exists, is used for automatic filter strength adaptation. Default is 0.0\n"));
10421+ msdk_printf(MSDK_STRING(
10422+ " Strength: integer, [0...20]. Default value is 0.Might be a CSV filename (upto 15 symbols); if a string is convertable to an integer, integer has a priority over filename\n"));
10423+ msdk_printf(MSDK_STRING(
10424+ " ME: Motion Estimation precision; 0 - integer ME (default); 1 - quater-pel ME\n"));
10425+ msdk_printf(MSDK_STRING(
10426+ " Overlap: 0 - do not apply overlap ME (default); 1 - to apply overlap ME\n"));
10427+ msdk_printf(MSDK_STRING(
10428+ " DB: 0 - do not apply deblock Filter (default); 1 - to apply Deblock Filter\n"));
10429+ #endif //ENABLE_MCTF_EXT
10430+#endif //ENABLE_MCTF
10431+
10432+ msdk_printf(MSDK_STRING(
10433+ " -robust Recover from gpu hang errors as they come (by resetting components)\n"));
10434+ msdk_printf(MSDK_STRING(" -robust:soft Recover from gpu hang errors by inserting an IDR\n"));
10435+
10436+ msdk_printf(MSDK_STRING(" -async Depth of asynchronous pipeline. default value 1\n"));
10437+ msdk_printf(MSDK_STRING(
10438+ " -join Join session with other session(s), by default sessions are not joined\n"));
10439+ msdk_printf(MSDK_STRING(
10440+ " -priority Use priority for join sessions. 0 - Low, 1 - Normal, 2 - High. Normal by default\n"));
10441+ msdk_printf(MSDK_STRING(" -threads num Number of session internal threads to create\n"));
10442+ msdk_printf(
10443+ MSDK_STRING(" -n Number of frames to transcode\n") MSDK_STRING(
10444+ " (session ends after this number of frames is reached). \n")
10445+ MSDK_STRING(
10446+ " In decoding sessions (-o::sink) this parameter limits number\n")
10447+ MSDK_STRING(" of frames acquired from decoder.\n") MSDK_STRING(
10448+ " In encoding sessions (-o::source) and transcoding sessions \n")
10449+ MSDK_STRING(
10450+ " this parameter limits number of frames sent to encoder.\n"));
10451+
10452+ msdk_printf(
10453+ MSDK_STRING(" -MemType::video Force usage of external video allocator (default)\n"));
10454+ msdk_printf(MSDK_STRING(" -MemType::system Force usage of external system allocator\n"));
10455+ msdk_printf(MSDK_STRING(" -MemType::opaque Force usage of internal allocator\n"));
10456+
10457+ msdk_printf(MSDK_STRING(" -MemModel::GeneralAlloc (default)\n"));
10458+ msdk_printf(MSDK_STRING(" Force usage of:\n"));
10459+ msdk_printf(
10460+ MSDK_STRING(" External allocator in the case of video/system memory type\n"));
10461+ msdk_printf(
10462+ MSDK_STRING(" Internal allocator in the case of opaque memory type\n"));
10463+ msdk_printf(MSDK_STRING(
10464+ " -MemModel::VisibleIntAlloc Force usage of internal allocation with manual surfaces control\n"));
10465+ msdk_printf(MSDK_STRING(
10466+ " -MemModel::HiddenIntAlloc Force usage of internal allocation without manual surfaces control\n"));
10467+
10468+ msdk_printf(MSDK_STRING(" -dec::sys Set dec output to system memory\n"));
10469+ msdk_printf(MSDK_STRING(" -vpp::sys Set vpp output to system memory\n"));
10470+ msdk_printf(MSDK_STRING(" -vpp::vid Set vpp output to video memory\n"));
10471+ msdk_printf(MSDK_STRING(" -fps <frames per second>\n"));
10472+ msdk_printf(MSDK_STRING(" Transcoding frame rate limit\n"));
10473+ msdk_printf(MSDK_STRING(" -pe Set encoding plugin for this particular session.\n"));
10474+ msdk_printf(MSDK_STRING(
10475+ " This setting overrides plugin settings defined by SET clause.\n"));
10476+ msdk_printf(MSDK_STRING(" -pd Set decoding plugin for this particular session.\n"));
10477+ msdk_printf(MSDK_STRING(
10478+ " This setting overrides plugin settings defined by SET clause.\n"));
10479+ msdk_printf(MSDK_STRING(
10480+ " Supported values: hevcd_sw, hevcd_hw, hevce_sw, hevce_gacc, hevce_hw, vp8d_hw, vp8e_hw, vp9d_hw, vp9e_hw, camera_hw, capture_hw, h264_la_hw, ptir_hw, hevce_fei_hw\n"));
10481+ msdk_printf(MSDK_STRING(" Direct GUID number can be used as well\n"));
10482+ msdk_printf(MSDK_STRING("\n"));
10483+ msdk_printf(MSDK_STRING("Pipeline description (encoding options):\n"));
10484+ MOD_SMT_PRINT_HELP;
10485+ msdk_printf(MSDK_STRING(" -b <Kbits per second>\n"));
10486+ msdk_printf(
10487+ MSDK_STRING(" Encoded bit rate, valid for H.264, MPEG2 and MVC encoders\n"));
10488+ msdk_printf(MSDK_STRING(
10489+ " -bm Bitrate multiplier. Use it when required bitrate isn't fit into 16-bit\n"));
10490+ msdk_printf(MSDK_STRING(
10491+ " Affects following parameters: InitialDelayInKB, BufferSizeInKB, TargetKbps, MaxKbps\n"));
10492+ msdk_printf(MSDK_STRING(" -f <frames per second>\n"));
10493+ msdk_printf(
10494+ MSDK_STRING(" Video frame rate for the FRC and deinterlace options\n"));
10495+ msdk_printf(MSDK_STRING(" -fe <frames per second>\n"));
10496+ msdk_printf(MSDK_STRING(
10497+ " Video frame rate for the FRC and deinterlace options (deprecated, will be removed in next versions).\n"));
10498+ msdk_printf(MSDK_STRING(" -override_decoder_framerate <framerate> \n"));
10499+ msdk_printf(MSDK_STRING(
10500+ " Forces decoder output framerate to be set to provided value (overwriting actual framerate from decoder)\n"));
10501+ msdk_printf(MSDK_STRING(" -override_encoder_framerate <framerate> \n"));
10502+ msdk_printf(MSDK_STRING(
10503+ " Overwrites framerate of stream going into encoder input with provided value (this option does not enable FRC, it just ovewrites framerate value)\n"));
10504+ msdk_printf(MSDK_STRING(" -override_encoder_picstruct <picstruct> \n"));
10505+ msdk_printf(MSDK_STRING(" Overwrites encoder picstruct with specific value"));
10506+ msdk_printf(MSDK_STRING(
10507+ " -u <usage> Target usage. Valid for H.265, H.264, MPEG2 and MVC encoders. Expected values:\n"));
10508+ msdk_printf(MSDK_STRING(
10509+ " veryslow(quality), slower, slow, medium(balanced), fast, faster, veryfast(speed)\n"));
10510+ msdk_printf(MSDK_STRING(
10511+ " -q <quality> Quality parameter for JPEG encoder; in range [1,100], 100 is the best quality\n"));
10512+ msdk_printf(MSDK_STRING(" -l numSlices Number of slices for encoder; default value 0 \n"));
10513+ msdk_printf(MSDK_STRING(" -mss maxSliceSize \n"));
10514+ msdk_printf(MSDK_STRING(
10515+ " Maximum slice size in bytes. Supported only with -hw and h264 codec. This option is not compatible with -l option.\n"));
10516+ msdk_printf(MSDK_STRING(" -BitrateLimit:<on,off>\n"));
10517+ msdk_printf(MSDK_STRING(
10518+ " Turn this flag ON to set bitrate limitations imposed by the SDK encoder. Off by default.\n"));
10519+ msdk_printf(MSDK_STRING(
10520+ " -la Use the look ahead bitrate control algorithm (LA BRC) for H.264 encoder. Supported only with -hw option on 4th Generation Intel Core processors. \n"));
10521+ msdk_printf(MSDK_STRING(
10522+ " -lad depth Depth parameter for the LA BRC, the number of frames to be analyzed before encoding. In range [0,100] (0 - default: auto-select by mediasdk library).\n"));
10523+ msdk_printf(
10524+ MSDK_STRING(" May be 1 in the case when -mss option is specified \n"));
10525+ msdk_printf(MSDK_STRING(
10526+ " -la_ext Use external LA plugin (compatible with h264 & hevc encoders)\n"));
10527+ msdk_printf(MSDK_STRING(" -vbr Variable bitrate control\n"));
10528+ msdk_printf(MSDK_STRING(" -cbr Constant bitrate control\n"));
10529+ msdk_printf(MSDK_STRING(" -vcm Video Conferencing Mode (VCM) bitrate control\n"));
10530+ msdk_printf(MSDK_STRING(" -hrd <KBytes> Maximum possible size of any compressed frames \n"));
10531+ msdk_printf(MSDK_STRING(" -wb <Kbits per second>\n"));
10532+ msdk_printf(MSDK_STRING(" Maximum bitrate for sliding window\n"));
10533+ msdk_printf(MSDK_STRING(" -ws Sliding window size in frames\n"));
10534+ msdk_printf(MSDK_STRING(" -gop_size Size of GOP structure in frames \n"));
10535+ msdk_printf(MSDK_STRING(" -dist Distance between I- or P- key frames \n"));
10536+ msdk_printf(MSDK_STRING(" -num_ref Number of reference frames\n"));
10537+ msdk_printf(MSDK_STRING(" -bref Arrange B frames in B pyramid reference structure\n"));
10538+ msdk_printf(MSDK_STRING(
10539+ " -nobref Do not use B-pyramid (by default the decision is made by library)\n"));
10540+ msdk_printf(MSDK_STRING(" -bpyr Enable B pyramid\n"));
10541+ msdk_printf(
10542+ MSDK_STRING(" -gpb:<on,off> - Enable or disable Generalized P/B frames\n"));
10543+#if (MFX_VERSION >= 1026)
10544+ msdk_printf(MSDK_STRING(" -TransformSkip:<on,off>- Enable or disable TransformSkip\n"));
10545+#endif
10546+ msdk_printf(MSDK_STRING(" -trows <rows> - Number of rows for tiled encoding\n"));
10547+ msdk_printf(MSDK_STRING(" -tcols <cols> - Number of columns for tiled encoding\n"));
10548+ msdk_printf(MSDK_STRING(" -CodecProfile - Specifies codec profile\n"));
10549+ msdk_printf(MSDK_STRING(" -CodecLevel - Specifies codec level\n"));
10550+ msdk_printf(MSDK_STRING(" -GopOptFlag:closed - Closed gop\n"));
10551+ msdk_printf(MSDK_STRING(" -GopOptFlag:strict - Strict gop\n"));
10552+ msdk_printf(MSDK_STRING(" -AdaptiveI:<on,off> - Turn Adaptive I frames on/off\n"));
10553+ msdk_printf(MSDK_STRING(" -AdaptiveB:<on,off> - Turn Adaptive B frames on/off\n"));
10554+ msdk_printf(MSDK_STRING(
10555+ " -InitialDelayInKB - The decoder starts decoding after the buffer reaches the initial size InitialDelayInKB, \n\
10556+ which is equivalent to reaching an initial delay of InitialDelayInKB*8000/TargetKbps ms\n"));
10557+ msdk_printf(MSDK_STRING(
10558+ " -MaxKbps - For variable bitrate control, specifies the maximum bitrate at which \n\
10559+ the encoded data enters the Video Buffering Verifier buffer\n"));
10560+ msdk_printf(MSDK_STRING(" -gpucopy::<on,off> Enable or disable GPU copy mode\n"));
10561+ msdk_printf(MSDK_STRING(
10562+ " -repartitioncheck::<on,off> Enable or disable RepartitionCheckEnable mode\n"));
10563+ msdk_printf(MSDK_STRING(
10564+ " -cqp Constant quantization parameter (CQP BRC) bitrate control method\n"));
10565+ msdk_printf(MSDK_STRING(
10566+ " (by default constant bitrate control method is used), should be used along with -qpi, -qpp, -qpb.\n"));
10567+#if (MFX_VERSION >= 1022)
10568+ msdk_printf(MSDK_STRING(
10569+ " -qpi Constant quantizer for I frames (if bitrace control method is CQP). In range [1,51]. 0 by default, i.e.no limitations on QP.\n"));
10570+ msdk_printf(MSDK_STRING(
10571+ " -qpp Constant quantizer for P frames (if bitrace control method is CQP). In range [1,51]. 0 by default, i.e.no limitations on QP.\n"));
10572+ msdk_printf(MSDK_STRING(
10573+ " -qpb Constant quantizer for B frames (if bitrace control method is CQP). In range [1,51]. 0 by default, i.e.no limitations on QP.\n"));
10574+#endif
10575+ msdk_printf(MSDK_STRING(
10576+ " -DisableQPOffset Disable QP adjustment for GOP pyramid-level frames\n"));
10577+ msdk_printf(MSDK_STRING(
10578+ " -lowpower:<on,off> Turn this option ON to enable QuickSync Fixed Function (low-power HW) encoding mode\n"));
10579+#if (MFX_VERSION >= 1027)
10580+ msdk_printf(MSDK_STRING(
10581+ " [-TargetBitDepthLuma] - Encoding target bit depth for luma samples, by default same as source one.\n"));
10582+ msdk_printf(MSDK_STRING(
10583+ " [-TargetBitDepthChroma] - Encoding target bit depth for chroma samples, by default same as source one.\n"));
10584+#endif
10585+#if MFX_VERSION >= 1022
10586+ msdk_printf(MSDK_STRING(" -roi_file <roi-file-name>\n"));
10587+ msdk_printf(MSDK_STRING(
10588+ " Set Regions of Interest for each frame from <roi-file-name>\n"));
10589+ msdk_printf(MSDK_STRING(" -roi_qpmap Use QP map to emulate ROI for CQP mode\n"));
10590+ msdk_printf(MSDK_STRING(" -extmbqp Use external MBQP map\n"));
10591+#endif //MFX_VERSION >= 1022
10592+ msdk_printf(MSDK_STRING(
10593+ " -AvcTemporalLayers [array:Layer.Scale] Configures the temporal layers hierarchy\n"));
10594+ msdk_printf(MSDK_STRING(
10595+ " -BaseLayerPID <pid> Sets priority ID for the base layer\n"));
10596+ msdk_printf(MSDK_STRING(
10597+ " -SPSId <pid> Sets sequence parameter set ID\n"));
10598+ msdk_printf(
10599+ MSDK_STRING(" -PPSId <pid> Sets picture parameter set ID\n"));
10600+ msdk_printf(MSDK_STRING(
10601+ " -PicTimingSEI:<on,off> Enables or disables picture timing SEI\n"));
10602+ msdk_printf(MSDK_STRING(
10603+ " -NalHrdConformance:<on,off> Enables or disables picture HRD conformance\n"));
10604+ msdk_printf(MSDK_STRING(
10605+ " -VuiNalHrdParameters:<on,off> Enables or disables NAL HRD parameters in VUI header\n"));
10606+
10607+ msdk_printf(MSDK_STRING("\n"));
10608+ msdk_printf(MSDK_STRING("Pipeline description (vpp options):\n"));
10609+ msdk_printf(MSDK_STRING(" -deinterlace Forces VPP to deinterlace input stream\n"));
10610+ msdk_printf(MSDK_STRING(
10611+ " -deinterlace::ADI Forces VPP to deinterlace input stream using ADI algorithm\n"));
10612+ msdk_printf(MSDK_STRING(
10613+ " -deinterlace::ADI_SCD Forces VPP to deinterlace input stream using ADI_SCD algorithm\n"));
10614+ msdk_printf(MSDK_STRING(
10615+ " -deinterlace::ADI_NO_REF Forces VPP to deinterlace input stream using ADI no ref algorithm\n"));
10616+ msdk_printf(MSDK_STRING(
10617+ " -deinterlace::BOB Forces VPP to deinterlace input stream using BOB algorithm\n"));
10618+ msdk_printf(MSDK_STRING(
10619+ " -detail <level> Enables detail (edge enhancement) filter with provided level(0..100)\n"));
10620+ msdk_printf(MSDK_STRING(
10621+ " -denoise <level> Enables denoise filter with provided level (0..100)\n"));
10622+ msdk_printf(
10623+ MSDK_STRING(" -FRC::PT Enables FRC filter with Preserve Timestamp algorithm\n"));
10624+ msdk_printf(
10625+ MSDK_STRING(" -FRC::DT Enables FRC filter with Distributed Timestamp algorithm\n"));
10626+ msdk_printf(
10627+ MSDK_STRING(" -FRC::INTERP Enables FRC filter with Frame Interpolation algorithm\n"));
10628+ msdk_printf(MSDK_STRING(" -scaling_mode <mode> Specifies scaling mode (lowpower/quality)\n"));
10629+ msdk_printf(MSDK_STRING(
10630+ " -ec::nv12|rgb4|yuy2|nv16|p010|p210|y210|y410|p016|y216|y416 Forces encoder input to use provided chroma mode\n"));
10631+ msdk_printf(MSDK_STRING(
10632+ " -dc::nv12|rgb4|yuy2|p010|y210|y410|p016|y216 Forces decoder output to use provided chroma mode\n"));
10633+ msdk_printf(MSDK_STRING(
10634+ " NOTE: chroma transform VPP may be automatically enabled if -ec/-dc parameters are provided\n"));
10635+ msdk_printf(MSDK_STRING(
10636+ " -angle 180 Enables 180 degrees picture rotation user module before encoding\n"));
10637+ msdk_printf(MSDK_STRING(
10638+ " -opencl Uses implementation of rotation plugin (enabled with -angle option) through Intel(R) OpenCL\n"));
10639+ msdk_printf(MSDK_STRING(
10640+ " -w Destination picture width, invokes VPP resize or decoder fixed function resize engine (if -dec_postproc specified)\n"));
10641+ msdk_printf(MSDK_STRING(
10642+ " -h Destination picture height, invokes VPP resize or decoder fixed function resize engine (if -dec_postproc specified)\n"));
10643+ msdk_printf(MSDK_STRING(" -field_processing t2t|t2b|b2t|b2b|fr2fr - Field Copy feature\n"));
10644+ msdk_printf(MSDK_STRING(
10645+ " -WeightedPred::default|implicit Enambles weighted prediction usage\n"));
10646+ msdk_printf(MSDK_STRING(
10647+ " -WeightedBiPred::default|implicit Enambles weighted bi-prediction usage\n"));
10648+ msdk_printf(MSDK_STRING(
10649+ " -ir_type - Intra refresh type. 0 - no refresh, 1 - vertical refresh, 2 - horisontal refresh, 3 - slice refresh\n"));
10650+ msdk_printf(MSDK_STRING(
10651+ " -ir_cycle_size - Number of pictures within refresh cycle starting from 2\n"));
10652+ msdk_printf(MSDK_STRING(
10653+ " -ir_qp_delta - QP difference for inserted intra MBs. This is signed value in [-51, 51] range\n"));
10654+ msdk_printf(MSDK_STRING(
10655+ " -ir_cycle_dist - Distance between the beginnings of the intra-refresh cycles in frames\n"));
10656+ msdk_printf(MSDK_STRING(
10657+ " -LowDelayBRC - strictly obey average frame size set by MaxKbps\n"));
10658+ msdk_printf(MSDK_STRING(
10659+ " -amfs:<on,off> - adaptive max frame size. If set on, P or B frame size can exceed MaxFrameSize when the scene change is detected.\
10660+ It can benefit the video quality \n"));
10661+ msdk_printf(MSDK_STRING(
10662+ " -mfs - maximum frame size in bytes. Supported only with h264 and hevc codec for VBR mode.\n"));
10663+
10664+#if (MFX_VERSION >= 1024)
10665+ msdk_printf(MSDK_STRING(
10666+ " -extbrc::<on,off,implicit> Enables external BRC for AVC and HEVC encoders\n"));
10667+#endif
10668+#if (MFX_VERSION >= 1026)
10669+ msdk_printf(
10670+ MSDK_STRING(" -ExtBrcAdaptiveLTR:<on,off> Set AdaptiveLTR for implicit extbrc"));
10671+#endif
10672+ msdk_printf(MSDK_STRING(
10673+ " -vpp_comp <sourcesNum> Enables composition from several decoding sessions. Result is written to the file\n"));
10674+ msdk_printf(MSDK_STRING(
10675+ " -vpp_comp_only <sourcesNum> Enables composition from several decoding sessions. Result is shown on screen\n"));
10676+ msdk_printf(MSDK_STRING(
10677+ " -vpp_comp_num_tiles <Num> Quantity of tiles for composition. if equal to 0 tiles processing ignored\n"));
10678+ msdk_printf(MSDK_STRING(
10679+ " -vpp_comp_dst_x X position of this stream in composed stream (should be used in decoder session)\n"));
10680+ msdk_printf(MSDK_STRING(
10681+ " -vpp_comp_dst_y Y position of this stream in composed stream (should be used in decoder session)\n"));
10682+ msdk_printf(MSDK_STRING(
10683+ " -vpp_comp_dst_h Height of this stream in composed stream (should be used in decoder session)\n"));
10684+ msdk_printf(MSDK_STRING(
10685+ " -vpp_comp_dst_w Width of this stream in composed stream (should be used in decoder session)\n"));
10686+ msdk_printf(MSDK_STRING(
10687+ " -vpp_comp_src_h Width of this stream in composed stream (should be used in decoder session)\n"));
10688+ msdk_printf(MSDK_STRING(
10689+ " -vpp_comp_src_w Width of this stream in composed stream (should be used in decoder session)\n"));
10690+#if MFX_VERSION >= 1023
10691+ msdk_printf(MSDK_STRING(
10692+ " -vpp_comp_tile_id Tile_id for current channel of composition (should be used in decoder session)\n"));
10693+#endif
10694+ msdk_printf(MSDK_STRING(
10695+ " -vpp_comp_dump <file-name> Dump of VPP Composition's output into file. Valid if with -vpp_comp* options\n"));
10696+ msdk_printf(MSDK_STRING(
10697+ " -vpp_comp_dump null_render Disabling rendering after VPP Composition. This is for performance measurements\n"));
10698+#if MFX_VERSION >= 1022
10699+ msdk_printf(MSDK_STRING(
10700+ " -dec_postproc Resize after decoder using direct pipe (should be used in decoder session)\n"));
10701+ msdk_printf(
10702+ MSDK_STRING(" -single_texture_d3d11 single texture mode for d3d11 allocator \n"));
10703+#endif //MFX_VERSION >= 1022
10704+ msdk_printf(MSDK_STRING(
10705+ " -preset <default,dss,conference,gaming> Use particular preset for encoding parameters\n"));
10706+ msdk_printf(MSDK_STRING(" -pp Print preset parameters\n"));
10707+
10708+ msdk_printf(MSDK_STRING("\n"));
10709+ msdk_printf(MSDK_STRING("ParFile format:\n"));
10710+ msdk_printf(MSDK_STRING(
10711+ " ParFile is extension of what can be achieved by setting pipeline in the command\n"));
10712+ msdk_printf(MSDK_STRING(
10713+ "line. For more information on ParFile format see readme-multi-transcode.pdf\n"));
10714+ msdk_printf(MSDK_STRING("\n"));
10715+ msdk_printf(MSDK_STRING("Examples:\n"));
10716+ msdk_printf(MSDK_STRING(" sample_multi_transcode -i::mpeg2 in.mpeg2 -o::h264 out.h264\n"));
10717+ msdk_printf(
10718+ MSDK_STRING(" sample_multi_transcode -i::mvc in.mvc -o::mvc out.mvc -w 320 -h 240\n"));
10719+}
10720+
10721+void TranscodingSample::PrintInfo(mfxU32 session_number, sInputParams* pParams, mfxVersion* pVer) {
10722+ msdk_char buf[2048];
10723+ MSDK_CHECK_POINTER_NO_RET(pVer);
10724+
10725+ if ((MFX_IMPL_AUTO <= pParams->libType) && (MFX_IMPL_HARDWARE4 >= pParams->libType)) {
10726+ msdk_printf(MSDK_STRING("MFX %s Session %d API ver %d.%d parameters: \n"),
10727+ (MFX_IMPL_SOFTWARE == pParams->libType) ? MSDK_STRING("SOFTWARE")
10728+ : MSDK_STRING("HARDWARE"),
10729+ session_number,
10730+ pVer->Major,
10731+ pVer->Minor);
10732+ }
10733+
10734+ if (0 == pParams->DecodeId)
10735+ msdk_printf(MSDK_STRING("Input video: From parent session\n"));
10736+ else
10737+ msdk_printf(MSDK_STRING("Input video: %s\n"), CodecIdToStr(pParams->DecodeId).c_str());
10738+
10739+ // means that source is parent session
10740+ if (0 == pParams->EncodeId)
10741+ msdk_printf(MSDK_STRING("Output video: To child session\n"));
10742+ else
10743+ msdk_printf(MSDK_STRING("Output video: %s\n"), CodecIdToStr(pParams->EncodeId).c_str());
10744+ if (PrintDllInfo(buf, MSDK_ARRAY_LEN(buf), pParams))
10745+ msdk_printf(MSDK_STRING("MFX dll: %s\n"), buf);
10746+ msdk_printf(MSDK_STRING("\n"));
10747+}
10748+
10749+bool TranscodingSample::PrintDllInfo(msdk_char* buf, mfxU32 buf_size, sInputParams* pParams) {
10750+#if defined(_WIN32) || defined(_WIN64)
10751+ HANDLE hCurrent = GetCurrentProcess();
10752+ HMODULE* pModules;
10753+ DWORD cbNeeded;
10754+ int nModules;
10755+ if (NULL == EnumProcessModules(hCurrent, NULL, 0, &cbNeeded))
10756+ return false;
10757+
10758+ nModules = cbNeeded / sizeof(HMODULE);
10759+
10760+ pModules = new HMODULE[nModules];
10761+ if (NULL == pModules) {
10762+ return false;
10763+ }
10764+ if (NULL == EnumProcessModules(hCurrent, pModules, cbNeeded, &cbNeeded)) {
10765+ delete[] pModules;
10766+ return false;
10767+ }
10768+
10769+ for (int i = 0; i < nModules; i++) {
10770+ GetModuleFileName(pModules[i], buf, buf_size);
10771+ if (_tcsstr(buf, MSDK_STRING("libmfxhw")) && (MFX_IMPL_SOFTWARE != pParams->libType)) {
10772+ delete[] pModules;
10773+ return true;
10774+ }
10775+ else if (_tcsstr(buf, MSDK_STRING("libmfxsw")) && (MFX_IMPL_SOFTWARE == pParams->libType)) {
10776+ delete[] pModules;
10777+ return true;
10778+ }
10779+ }
10780+ delete[] pModules;
10781+ return false;
10782+#else
10783+ return false;
10784+#endif
10785+}
10786+
10787+CmdProcessor::CmdProcessor() {
10788+ m_SessionParamId = 0;
10789+ m_SessionArray.clear();
10790+ m_decoderPlugins.clear();
10791+ m_encoderPlugins.clear();
10792+ m_PerfFILE = NULL;
10793+ m_parName = NULL;
10794+ m_nTimeout = 0;
10795+ statisticsWindowSize = 0;
10796+ statisticsLogFile = NULL;
10797+ DumpLogFileName.clear();
10798+ shouldUseGreedyFormula = false;
10799+ bRobustFlag = false;
10800+ bSoftRobustFlag = false;
10801+
10802+} //CmdProcessor::CmdProcessor()
10803+
10804+CmdProcessor::~CmdProcessor() {
10805+ m_SessionArray.clear();
10806+ m_decoderPlugins.clear();
10807+ m_encoderPlugins.clear();
10808+ if (m_PerfFILE)
10809+ fclose(m_PerfFILE);
10810+ if (statisticsLogFile)
10811+ fclose(statisticsLogFile);
10812+
10813+} //CmdProcessor::~CmdProcessor()
10814+
10815+void CmdProcessor::PrintParFileName() {
10816+ if (m_parName && m_PerfFILE) {
10817+ msdk_fprintf(m_PerfFILE, MSDK_STRING("Input par file: %s\n\n"), m_parName);
10818+ }
10819+}
10820+
10821+msdk_string CmdProcessor::GetLine(mfxU32 n) {
10822+ if (m_lines.size() > n)
10823+ return m_lines[n];
10824+ return msdk_string();
10825+}
10826+
10827+mfxStatus CmdProcessor::ParseCmdLine(int argc, msdk_char* argv[]) {
10828+ FILE* parFile = NULL;
10829+ mfxStatus sts = MFX_ERR_UNSUPPORTED;
10830+
10831+ if (1 == argc) {
10832+ PrintError(MSDK_STRING("Too few parameters"), NULL);
10833+ return MFX_ERR_UNSUPPORTED;
10834+ }
10835+
10836+ --argc;
10837+ ++argv;
10838+
10839+ while (argv[0]) {
10840+ if (0 == msdk_strcmp(argv[0], MSDK_STRING("-par"))) {
10841+ --argc;
10842+ ++argv;
10843+ if (!argv[0]) {
10844+ msdk_printf(MSDK_STRING("error: no argument given for '-par' option\n"));
10845+ }
10846+ m_parName = argv[0];
10847+ }
10848+ else if (0 == msdk_strcmp(argv[0], MSDK_STRING("-timeout"))) {
10849+ --argc;
10850+ ++argv;
10851+ if (!argv[0]) {
10852+ msdk_printf(MSDK_STRING("error: no argument given for '-timeout' option\n"));
10853+ }
10854+ if (MFX_ERR_NONE != msdk_opt_read(argv[0], m_nTimeout)) {
10855+ msdk_printf(MSDK_STRING("error: -timeout \"%s\" is invalid"), argv[0]);
10856+ return MFX_ERR_UNSUPPORTED;
10857+ }
10858+ }
10859+ else if (0 == msdk_strcmp(argv[0], MSDK_STRING("-robust"))) {
10860+ bRobustFlag = true;
10861+ }
10862+ else if (0 == msdk_strcmp(argv[0], MSDK_STRING("-robust:soft"))) {
10863+ bSoftRobustFlag = true;
10864+ }
10865+ else if (0 == msdk_strcmp(argv[0], MSDK_STRING("-?"))) {
10866+ PrintHelp();
10867+ return MFX_WRN_OUT_OF_RANGE;
10868+ }
10869+ else if (0 == msdk_strcmp(argv[0], MSDK_STRING("-greedy"))) {
10870+ shouldUseGreedyFormula = true;
10871+ }
10872+ else if (0 == msdk_strcmp(argv[0], MSDK_STRING("-p"))) {
10873+ if (m_PerfFILE) {
10874+ msdk_printf(MSDK_STRING("error: only one performance file is supported"));
10875+ return MFX_ERR_UNSUPPORTED;
10876+ }
10877+ --argc;
10878+ ++argv;
10879+ if (!argv[0]) {
10880+ msdk_printf(MSDK_STRING("error: no argument given for '-p' option\n"));
10881+ }
10882+ MSDK_FOPEN(m_PerfFILE, argv[0], MSDK_STRING("w"));
10883+ if (NULL == m_PerfFILE) {
10884+ msdk_printf(MSDK_STRING("error: performance file \"%s\" not found"), argv[0]);
10885+ return MFX_ERR_UNSUPPORTED;
10886+ }
10887+ }
10888+ else if (0 == msdk_strcmp(argv[0], MSDK_STRING("--"))) {
10889+ // just skip separator "--" which delimits cmd options and pipeline settings
10890+ break;
10891+ }
10892+ else if (0 == msdk_strcmp(argv[0], MSDK_STRING("-stat"))) {
10893+ --argc;
10894+ ++argv;
10895+ if (!argv[0]) {
10896+ msdk_printf(MSDK_STRING("error: no argument given for 'stat' option\n"));
10897+ }
10898+ if (MFX_ERR_NONE != msdk_opt_read(argv[0], statisticsWindowSize)) {
10899+ msdk_printf(MSDK_STRING("error: stat \"%s\" is invalid"), argv[0]);
10900+ return MFX_ERR_UNSUPPORTED;
10901+ }
10902+ }
10903+ else if (0 == msdk_strcmp(argv[0], MSDK_STRING("-stat-log"))) {
10904+ if (statisticsLogFile) {
10905+ msdk_printf(MSDK_STRING("error: only one statistics file is supported"));
10906+ return MFX_ERR_UNSUPPORTED;
10907+ }
10908+ --argc;
10909+ ++argv;
10910+ if (!argv[0]) {
10911+ msdk_printf(MSDK_STRING("error: no argument given for 'stat-log' option\n"));
10912+ }
10913+ MSDK_FOPEN(statisticsLogFile, argv[0], MSDK_STRING("w"));
10914+ if (NULL == statisticsLogFile) {
10915+ msdk_printf(MSDK_STRING("error: statistics file \"%s\" not found"), argv[0]);
10916+ return MFX_ERR_UNSUPPORTED;
10917+ }
10918+ }
10919+ else if (0 == msdk_strcmp(argv[0], MSDK_STRING("-stat-per-frame"))) {
10920+ if (!DumpLogFileName.empty()) {
10921+ msdk_printf(MSDK_STRING("error: only one dump file is supported"));
10922+ return MFX_ERR_UNSUPPORTED;
10923+ }
10924+ --argc;
10925+ ++argv;
10926+ if (!argv[0]) {
10927+ msdk_printf(MSDK_STRING("error: no argument given for 'stat-dump' option\n"));
10928+ }
10929+ DumpLogFileName = argv[0];
10930+ }
10931+ else {
10932+ break;
10933+ }
10934+ --argc;
10935+ ++argv;
10936+ }
10937+
10938+ msdk_printf(MSDK_STRING("Multi Transcoding Sample Version %s\n\n"),
10939+ GetMSDKSampleVersion().c_str());
10940+
10941+ //Read pipeline from par file
10942+ if (m_parName && !argv[0]) {
10943+ MSDK_FOPEN(parFile, m_parName, MSDK_STRING("r"));
10944+ if (NULL == parFile) {
10945+ msdk_printf(MSDK_STRING("error: ParFile \"%s\" not found\n"), m_parName);
10946+ return MFX_ERR_UNSUPPORTED;
10947+ }
10948+
10949+ if (NULL != m_parName)
10950+ msdk_printf(MSDK_STRING("Par file is: %s\n\n"), m_parName);
10951+
10952+ sts = ParseParFile(parFile);
10953+
10954+ if (MFX_ERR_NONE != sts) {
10955+ fclose(parFile);
10956+ return sts;
10957+ }
10958+
10959+ fclose(parFile);
10960+ }
10961+ //Read pipeline from cmd line
10962+ else if (!argv[0]) {
10963+ msdk_printf(MSDK_STRING("error: pipeline description not found\n"));
10964+ return MFX_ERR_UNSUPPORTED;
10965+ }
10966+ else if (argv[0] && m_parName) {
10967+ msdk_printf(MSDK_STRING(
10968+ "error: simultaneously enabling parfile and description pipeline from command line forbidden\n"));
10969+ return MFX_ERR_UNSUPPORTED;
10970+ }
10971+ else {
10972+ sts = ParseParamsForOneSession(argc, argv);
10973+ if (MFX_ERR_NONE != sts) {
10974+ msdk_printf(MSDK_STRING("error: pipeline description is invalid\n"));
10975+ return sts;
10976+ }
10977+ }
10978+
10979+ return sts;
10980+
10981+} //mfxStatus CmdProcessor::ParseCmdLine(int argc, msdk_char *argv[])
10982+
10983+mfxStatus CmdProcessor::ParseParFile(FILE* parFile) {
10984+ mfxStatus sts = MFX_ERR_UNSUPPORTED;
10985+ if (!parFile)
10986+ return MFX_ERR_UNSUPPORTED;
10987+
10988+ mfxU32 currPos = 0;
10989+ mfxU32 lineIndex = 0;
10990+
10991+ // calculate file size
10992+ fseek(parFile, 0, SEEK_END);
10993+ mfxU32 fileSize = ftell(parFile) + 1;
10994+ fseek(parFile, 0, SEEK_SET);
10995+
10996+ // allocate buffer for parsing
10997+ std::unique_ptr<msdk_char[]> parBuf(new msdk_char[fileSize]);
10998+ msdk_char* pCur;
10999+
11000+ while (currPos < fileSize) {
11001+ pCur = /*_fgetts*/ msdk_fgets(parBuf.get(), fileSize, parFile);
11002+ if (!pCur)
11003+ return MFX_ERR_NONE;
11004+ while (pCur[currPos] != '\n' && pCur[currPos] != 0) {
11005+ currPos++;
11006+ if (pCur + currPos >= parBuf.get() + fileSize)
11007+ return sts;
11008+ }
11009+ // zero string
11010+ if (!currPos)
11011+ continue;
11012+
11013+ sts = TokenizeLine(pCur, currPos);
11014+ MSDK_CHECK_STATUS(sts, "TokenizeLine failed");
11015+
11016+ currPos = 0;
11017+ lineIndex++;
11018+ }
11019+
11020+ return MFX_ERR_NONE;
11021+
11022+} //mfxStatus CmdProcessor::ParseParFile(FILE *parFile)
11023+
11024+// calculate length of string literal, including leading and trailing "
11025+// pTempLine = start of string (must begin with ")
11026+// length = remaining characters in pTempLine
11027+// returns length of string, or 0 if error
11028+mfxU32 CmdProcessor::GetStringLength(msdk_char* pTempLine, mfxU32 length) {
11029+ mfxU32 i;
11030+
11031+ // error - no leading " found
11032+ if (pTempLine[0] != '\"')
11033+ return 0;
11034+
11035+ for (i = 1; i < length; i++) {
11036+ if (pTempLine[i] == '\"')
11037+ break;
11038+ }
11039+
11040+ // error - no closing " found
11041+ if (i == length)
11042+ return 0;
11043+
11044+ return i + 1;
11045+}
11046+
11047+mfxStatus CmdProcessor::TokenizeLine(msdk_char* pLine, mfxU32 length) {
11048+ mfxU32 i, strArgLen;
11049+ const mfxU8 maxArgNum = 255;
11050+ msdk_char* argv[maxArgNum + 1];
11051+ mfxU32 argc = 0;
11052+ std::unique_ptr<msdk_char[]> pMemLine(new msdk_char[length + 2]);
11053+
11054+ msdk_char* pTempLine = pMemLine.get();
11055+ pTempLine[0] = ' ';
11056+ pTempLine++;
11057+
11058+ MSDK_MEMCPY_BUF(pTempLine, 0, length * sizeof(msdk_char), pLine, length * sizeof(msdk_char));
11059+
11060+ // parse into command streams
11061+ for (i = 0; i < length; i++) {
11062+ // check if separator
11063+ if (IS_SEPARATOR(pTempLine[-1]) && !IS_SEPARATOR(pTempLine[0])) {
11064+ argv[argc++] = pTempLine;
11065+ if (argc > maxArgNum) {
11066+ PrintError(MSDK_STRING("Too many parameters (reached maximum of %d)"), maxArgNum);
11067+ return MFX_ERR_UNSUPPORTED;
11068+ }
11069+ }
11070+
11071+ if (*pTempLine == '\"') {
11072+ strArgLen = GetStringLength(pTempLine, length - i);
11073+ if (!strArgLen) {
11074+ PrintError(MSDK_STRING("Error parsing string literal"));
11075+ return MFX_ERR_UNSUPPORTED;
11076+ }
11077+
11078+ // remove leading and trailing ", bump pointer ahead to next argument
11079+ pTempLine[0] = ' ';
11080+ pTempLine[strArgLen - 1] = ' ';
11081+ pTempLine += strArgLen;
11082+ i += strArgLen;
11083+ }
11084+
11085+ if (*pTempLine == ' ' || *pTempLine == '\r' || *pTempLine == '\n') {
11086+ *pTempLine = 0;
11087+ }
11088+ pTempLine++;
11089+ }
11090+
11091+ // EOL for last parameter
11092+ pTempLine[0] = 0;
11093+
11094+ return ParseParamsForOneSession(argc, argv);
11095+}
11096+
11097+#if MFX_VERSION >= 1022
11098+bool CmdProcessor::isspace(char a) {
11099+ return (std::isspace(a) != 0);
11100+}
11101+
11102+bool CmdProcessor::is_not_allowed_char(char a) {
11103+ return (std::isdigit(a) == 0) && (std::isspace(a) == 0) && (a != ';') && (a != '-');
11104+}
11105+
11106+bool CmdProcessor::ParseROIFile(const msdk_char* roi_file_name,
11107+ std::vector<mfxExtEncoderROI>& m_ROIData) {
11108+ FILE* roi_file = NULL;
11109+ MSDK_FOPEN(roi_file, roi_file_name, MSDK_STRING("rb"));
11110+
11111+ m_ROIData.clear();
11112+
11113+ if (roi_file) {
11114+ // read file to buffer
11115+ fseek(roi_file, 0, SEEK_END);
11116+ long file_size = ftell(roi_file);
11117+ rewind(roi_file);
11118+ std::vector<char> buffer(file_size);
11119+ char* roi_data = &buffer[0];
11120+ if (file_size < 0 || (size_t)file_size != fread(roi_data, 1, file_size, roi_file)) {
11121+ fclose(roi_file);
11122+ return false;
11123+ }
11124+ fclose(roi_file);
11125+
11126+ // search for not allowed characters
11127+ char* not_allowed_char = std::find_if(roi_data, roi_data + file_size, is_not_allowed_char);
11128+ if (not_allowed_char != (roi_data + file_size)) {
11129+ return false;
11130+ }
11131+
11132+ // get unformatted roi data
11133+ std::string unformatted_roi_data;
11134+ unformatted_roi_data.clear();
11135+ std::remove_copy_if(roi_data,
11136+ roi_data + file_size,
11137+ std::inserter(unformatted_roi_data, unformatted_roi_data.end()),
11138+ isspace);
11139+
11140+ // split data to items
11141+ std::stringstream unformatted_roi_data_ss(unformatted_roi_data);
11142+ std::vector<std::string> items;
11143+ items.clear();
11144+ std::string item;
11145+ while (std::getline(unformatted_roi_data_ss, item, ';')) {
11146+ items.push_back(item);
11147+ }
11148+
11149+ // parse data and store roi data for each frame
11150+ unsigned int item_ind = 0;
11151+ while (1) {
11152+ if (item_ind >= items.size())
11153+ break;
11154+
11155+ mfxExtEncoderROI frame_roi;
11156+ std::memset(&frame_roi, 0, sizeof(frame_roi));
11157+ frame_roi.Header.BufferId = MFX_EXTBUFF_ENCODER_ROI;
11158+ #if (MFX_VERSION >= 1022)
11159+ frame_roi.ROIMode = MFX_ROI_MODE_QP_DELTA;
11160+ #endif
11161+
11162+ int roi_num = std::atoi(items[item_ind].c_str());
11163+ if (roi_num < 0 || roi_num > (int)(sizeof(frame_roi.ROI) / sizeof(frame_roi.ROI[0]))) {
11164+ m_ROIData.clear();
11165+ return false;
11166+ }
11167+ if ((item_ind + 5 * roi_num) >= items.size()) {
11168+ m_ROIData.clear();
11169+ return false;
11170+ }
11171+
11172+ for (int i = 0; i < roi_num; i++) {
11173+ // do not handle out of range integer errors
11174+ frame_roi.ROI[i].Left = std::atoi(items[item_ind + i * 5 + 1].c_str());
11175+ frame_roi.ROI[i].Top = std::atoi(items[item_ind + i * 5 + 2].c_str());
11176+ frame_roi.ROI[i].Right = std::atoi(items[item_ind + i * 5 + 3].c_str());
11177+ frame_roi.ROI[i].Bottom = std::atoi(items[item_ind + i * 5 + 4].c_str());
11178+ #if (MFX_VERSION >= 1022)
11179+ frame_roi.ROI[i].DeltaQP = (mfxI16)std::atoi(items[item_ind + i * 5 + 5].c_str());
11180+ #endif
11181+ }
11182+ frame_roi.NumROI = (mfxU16)roi_num;
11183+ m_ROIData.push_back(frame_roi);
11184+ item_ind = item_ind + roi_num * 5 + 1;
11185+ }
11186+ }
11187+ else {
11188+ return false;
11189+ }
11190+ return true;
11191+}
11192+#endif //MFX_VERSION >= 1022
11193+#ifdef ENABLE_MCTF
11194+
11195+// returns a pointer to start of argument with a number argn;
11196+// if failes to find argn, returns NULL
11197+msdk_char* ParseArgn(msdk_char* pIn, mfxU32 argn, msdk_char separator) {
11198+ msdk_char* pstr = pIn;
11199+ if (!argn)
11200+ return pIn;
11201+ else {
11202+ for (mfxU32 n = 0; n != argn; ++n) {
11203+ while (separator != *pstr && msdk_char('\0') != *pstr)
11204+ ++pstr;
11205+ if (msdk_char('\0') == *pstr)
11206+ return NULL;
11207+ else
11208+ ++pstr;
11209+ }
11210+ return pstr;
11211+ }
11212+};
11213+
11214+template <typename T>
11215+bool ArgConvert(msdk_char* pIn,
11216+ mfxU32 argn,
11217+ const msdk_char* pattern,
11218+ T* pArg,
11219+ const T& ArgDefault,
11220+ mfxU32& NumOfGoodConverts) {
11221+ bool bConvertIsOk = false;
11222+ msdk_char* pargs = ParseArgn(pIn, argn, msdk_char(':'));
11223+ if (pargs) {
11224+ if (!msdk_sscanf(pargs, pattern, pArg))
11225+ *pArg = ArgDefault;
11226+ else {
11227+ ++NumOfGoodConverts;
11228+ bConvertIsOk = true;
11229+ }
11230+ };
11231+ return bConvertIsOk;
11232+}
11233+
11234+//template <typename T=msdk_string>
11235+bool ArgConvert(msdk_char* pIn,
11236+ mfxU32 argn,
11237+ const msdk_char* pattern,
11238+ msdk_char* pArg,
11239+ mfxU32 MaxChars2Read,
11240+ mfxU32& NumOfGoodConverts) {
11241+ bool bConvertIsOk = false;
11242+ msdk_char* pargs = ParseArgn(pIn, argn, msdk_char(':'));
11243+ if (pargs) {
11244+ // lets calculate length of potential name:
11245+ msdk_char* temp(pargs);
11246+ while (*temp != msdk_char(':') && *temp != msdk_char('\0'))
11247+ ++temp;
11248+ std::iterator_traits<msdk_char*>::difference_type distance = std::distance(pargs, temp);
11249+ if (distance < std::iterator_traits<msdk_char*>::difference_type(MaxChars2Read)) {
11250+ if (msdk_sscanf(pargs, pattern, pArg, MaxChars2Read)) {
11251+ ++NumOfGoodConverts;
11252+ bConvertIsOk = true;
11253+ }
11254+ };
11255+ };
11256+ return bConvertIsOk;
11257+}
11258+
11259+void ParseMCTFParams(msdk_char* strInput[], mfxU32 nArgNum, mfxU32& curArg, sInputParams* pParams) {
11260+ mfxU32& i = curArg;
11261+ if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-mctf"))) {
11262+ pParams->mctfParam.mode = VPP_FILTER_ENABLED_DEFAULT;
11263+ pParams->mctfParam.params.FilterStrength = 0;
11264+ pParams->mctfParam.rtParams.Reset();
11265+ bool bFSByValue = true;
11266+ #if defined ENABLE_MCTF_EXT
11267+ pParams->mctfParam.params.TemporalMode = MFX_MCTF_TEMPORAL_MODE_2REF; // default
11268+ pParams->mctfParam.params.BitsPerPixelx100k = 0;
11269+ pParams->mctfParam.params.Deblocking = MFX_CODINGOPTION_OFF;
11270+ pParams->mctfParam.params.Overlap = MFX_CODINGOPTION_OFF;
11271+ pParams->mctfParam.params.MVPrecision = MFX_MVPRECISION_INTEGER;
11272+ #endif
11273+
11274+ if (i + 1 < nArgNum) {
11275+ mfxU16 _strength(0);
11276+ mfxU32 strength_idx = 0;
11277+ mfxU32 ParsedArgsNumber = 0;
11278+ const mfxU32 max_name_len = 15;
11279+ const mfxU32 max_elems_in_file = 10000;
11280+ msdk_stringstream file_pattern;
11281+ file_pattern << MSDK_STRING("%") << max_name_len << MSDK_STRING("ls:%*c") << std::ends;
11282+ msdk_char _tmp_str[max_name_len + 1];
11283+ memset(_tmp_str, 0, sizeof(_tmp_str));
11284+ #if defined ENABLE_MCTF_EXT
11285+ strength_idx = 2;
11286+ #endif
11287+ //the order of arguments is:
11288+ // MctfMode:BitsPerPixel:Strength:ME:Overlap:DB
11289+ // try to read fs defined as a value:
11290+ bool res = ArgConvert(strInput[i + 1],
11291+ strength_idx,
11292+ MSDK_STRING("%hd:%*c"),
11293+ &_strength,
11294+ _strength,
11295+ ParsedArgsNumber);
11296+ if (!res) {
11297+ bFSByValue = false;
11298+ // if it was not possible, try to get a file-name (upto 15 chars):
11299+ res = ArgConvert(strInput[i + 1],
11300+ strength_idx,
11301+ file_pattern.str().c_str(),
11302+ &(_tmp_str[0]),
11303+ max_name_len,
11304+ ParsedArgsNumber);
11305+ if (res) {
11306+ msdk_fstream fs_file(_tmp_str, std::ios_base::in);
11307+ if (!fs_file.is_open()) {
11308+ msdk_printf(MSDK_STRING(
11309+ "MCTF Filter-strength file is not exist; decay to default FS value;.\n"));
11310+ bFSByValue = true;
11311+ }
11312+ else {
11313+ mfxU32 nOfRTParams(0);
11314+ for (msdk_string line; std::getline(fs_file, line, msdk_char(',')) &&
11315+ nOfRTParams < max_elems_in_file;
11316+ ++nOfRTParams) {
11317+ // currently, there is just 1 param in the file;
11318+ sMctfRunTimeParam tmp;
11319+ if (msdk_sscanf(line.c_str(),
11320+ MSDK_STRING("%hu:%*c"),
11321+ &(tmp.FilterStrength)))
11322+ pParams->mctfParam.rtParams.RunTimeParams.push_back(tmp);
11323+ else {
11324+ msdk_printf(MSDK_STRING(
11325+ "there was an error met during parsing FS file;.only a few values were parsed.\n"));
11326+ break;
11327+ }
11328+ }
11329+ }
11330+ }
11331+ else
11332+ bFSByValue = true;
11333+ }
11334+ #if defined ENABLE_MCTF_EXT
11335+ mfxU16 _refnum(2);
11336+ mfxF64 _bitsperpixel(0.0);
11337+ mfxU16 _me_precision(0);
11338+ mfxU16 _overlap(0);
11339+ mfxU16 _deblock(0);
11340+
11341+ ArgConvert(strInput[i + 1],
11342+ 0,
11343+ MSDK_STRING("%hd:%*c"),
11344+ &_refnum,
11345+ _refnum,
11346+ ParsedArgsNumber);
11347+ ArgConvert(strInput[i + 1],
11348+ 1,
11349+ MSDK_STRING("%lf:%*c"),
11350+ &_bitsperpixel,
11351+ _bitsperpixel,
11352+ ParsedArgsNumber);
11353+ ArgConvert(strInput[i + 1],
11354+ 3,
11355+ MSDK_STRING("%hd:%*c"),
11356+ &_me_precision,
11357+ _me_precision,
11358+ ParsedArgsNumber);
11359+ ArgConvert(strInput[i + 1],
11360+ 4,
11361+ MSDK_STRING("%hd:%*c"),
11362+ &_overlap,
11363+ _overlap,
11364+ ParsedArgsNumber);
11365+ ArgConvert(strInput[i + 1],
11366+ 5,
11367+ MSDK_STRING("%hd:%*c"),
11368+ &_deblock,
11369+ _deblock,
11370+ ParsedArgsNumber);
11371+ #endif
11372+ if (0 == ParsedArgsNumber) {
11373+ pParams->mctfParam.mode = VPP_FILTER_ENABLED_DEFAULT;
11374+ msdk_printf(MSDK_STRING("MCTF works in default mode; no parameters are passed.\n"));
11375+ }
11376+ else {
11377+ pParams->mctfParam.mode = VPP_FILTER_ENABLED_CONFIGURED;
11378+ pParams->mctfParam.rtParams.Restart();
11379+ if (bFSByValue) {
11380+ pParams->mctfParam.params.FilterStrength = _strength;
11381+ }
11382+ else {
11383+ // take very first FS value from the file and use it as a value for FilterStrength
11384+ if (pParams->mctfParam.rtParams.GetCurParam()) {
11385+ pParams->mctfParam.params.FilterStrength =
11386+ pParams->mctfParam.rtParams.GetCurParam()->FilterStrength;
11387+ }
11388+ }
11389+ #if defined ENABLE_MCTF_EXT
11390+ pParams->mctfParam.params.BitsPerPixelx100k =
11391+ mfxU32(_bitsperpixel * MCTF_BITRATE_MULTIPLIER);
11392+ switch (_refnum) {
11393+ case 0:
11394+ pParams->mctfParam.params.TemporalMode = MFX_MCTF_TEMPORAL_MODE_SPATIAL;
11395+ break;
11396+ case 1:
11397+ pParams->mctfParam.params.TemporalMode = MFX_MCTF_TEMPORAL_MODE_1REF;
11398+ break;
11399+ case 2:
11400+ pParams->mctfParam.params.TemporalMode = MFX_MCTF_TEMPORAL_MODE_2REF;
11401+ break;
11402+ case 3:
11403+ pParams->mctfParam.params.TemporalMode = MFX_MCTF_TEMPORAL_MODE_4REF;
11404+ break;
11405+ default:
11406+ pParams->mctfParam.params.TemporalMode = MFX_MCTF_TEMPORAL_MODE_UNKNOWN;
11407+ };
11408+ switch (_deblock) {
11409+ case 0:
11410+ pParams->mctfParam.params.Deblocking = MFX_CODINGOPTION_OFF;
11411+ break;
11412+ case 1:
11413+ pParams->mctfParam.params.Deblocking = MFX_CODINGOPTION_ON;
11414+ break;
11415+ default:
11416+ pParams->mctfParam.params.Deblocking = MFX_CODINGOPTION_UNKNOWN;
11417+ };
11418+ switch (_overlap) {
11419+ case 0:
11420+ pParams->mctfParam.params.Overlap = MFX_CODINGOPTION_OFF;
11421+ break;
11422+ case 1:
11423+ pParams->mctfParam.params.Overlap = MFX_CODINGOPTION_ON;
11424+ break;
11425+ default:
11426+ pParams->mctfParam.params.Overlap = MFX_CODINGOPTION_UNKNOWN;
11427+ };
11428+ switch (_me_precision) {
11429+ case 0:
11430+ pParams->mctfParam.params.MVPrecision = MFX_MVPRECISION_INTEGER;
11431+ break;
11432+ case 1:
11433+ pParams->mctfParam.params.MVPrecision = MFX_MVPRECISION_QUARTERPEL;
11434+ break;
11435+ default:
11436+ pParams->mctfParam.params.MVPrecision = MFX_MVPRECISION_UNKNOWN;
11437+ };
11438+ #endif
11439+ }
11440+ if (ParsedArgsNumber)
11441+ i++;
11442+ }
11443+ else {
11444+ msdk_printf(MSDK_STRING("MCTF works in default mode; no parameters are passed.\n"));
11445+ }
11446+ }
11447+}
11448+#endif
11449+
11450+// return values:
11451+// 0 if argv[i] is processed successfully (MFX_ERR_NONE)
11452+// < 1 if argv[i] is processed and generates an error OR argv[i] is not processed (no match)
11453+mfxStatus ParseAdditionalParams(msdk_char* argv[],
11454+ mfxU32 argc,
11455+ mfxU32& i,
11456+ TranscodingSample::sInputParams& InputParams) {
11457+ if (0 == msdk_strcmp(argv[i], MSDK_STRING("-AvcTemporalLayers"))) {
11458+ InputParams.nAvcTemp = 1;
11459+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
11460+ mfxU16 arr[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
11461+ int j, k;
11462+ k = msdk_sscanf(argv[i + 1],
11463+ MSDK_STRING("%hu %hu %hu %hu %hu %hu %hu %hu"),
11464+ &arr[0],
11465+ &arr[1],
11466+ &arr[2],
11467+ &arr[3],
11468+ &arr[4],
11469+ &arr[5],
11470+ &arr[6],
11471+ &arr[7]);
11472+ if (k != 8) {
11473+ PrintError(argv[0], MSDK_STRING("Invalid number of layers for AvcTemporalLayers"));
11474+ return MFX_ERR_UNSUPPORTED;
11475+ }
11476+
11477+ for (j = 0; j < 8; j++) {
11478+ InputParams.nAvcTemporalLayers[j] = arr[j];
11479+ }
11480+ i += 1;
11481+ }
11482+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-BaseLayerPID"))) {
11483+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
11484+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.nBaseLayerPID)) {
11485+ PrintError(argv[0], MSDK_STRING("BaseLayerPID is invalid"));
11486+ return MFX_ERR_UNSUPPORTED;
11487+ }
11488+ }
11489+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-SPSId"))) {
11490+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
11491+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.nSPSId)) {
11492+ PrintError(argv[0], MSDK_STRING("SPSId is invalid"));
11493+ return MFX_ERR_UNSUPPORTED;
11494+ }
11495+ }
11496+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-PPSId"))) {
11497+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
11498+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.nPPSId)) {
11499+ PrintError(argv[0], MSDK_STRING("PPSId is invalid"));
11500+ return MFX_ERR_UNSUPPORTED;
11501+ }
11502+ }
11503+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-lowpower:on"))) {
11504+ InputParams.enableQSVFF = true;
11505+ }
11506+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-lowpower:off"))) {
11507+ InputParams.enableQSVFF = false;
11508+ }
11509+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-PicTimingSEI:on"))) {
11510+ InputParams.nPicTimingSEI = MFX_CODINGOPTION_ON;
11511+ }
11512+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-PicTimingSEI:off"))) {
11513+ InputParams.nPicTimingSEI = MFX_CODINGOPTION_OFF;
11514+ }
11515+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-NalHrdConformance:on"))) {
11516+ InputParams.nNalHrdConformance = MFX_CODINGOPTION_ON;
11517+ }
11518+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-NalHrdConformance:off"))) {
11519+ InputParams.nNalHrdConformance = MFX_CODINGOPTION_OFF;
11520+ }
11521+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-VuiNalHrdParameters:on"))) {
11522+ InputParams.nVuiNalHrdParameters = MFX_CODINGOPTION_ON;
11523+ }
11524+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-VuiNalHrdParameters:off"))) {
11525+ InputParams.nVuiNalHrdParameters = MFX_CODINGOPTION_OFF;
11526+ }
11527+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-BitrateLimit:on"))) {
11528+ InputParams.BitrateLimit = MFX_CODINGOPTION_ON;
11529+ }
11530+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-BitrateLimit:off"))) {
11531+ InputParams.BitrateLimit = MFX_CODINGOPTION_OFF;
11532+ }
11533+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-AdaptiveI:on"))) {
11534+ InputParams.AdaptiveI = MFX_CODINGOPTION_ON;
11535+ }
11536+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-AdaptiveI:off"))) {
11537+ InputParams.AdaptiveI = MFX_CODINGOPTION_OFF;
11538+ }
11539+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-AdaptiveB:on"))) {
11540+ InputParams.AdaptiveB = MFX_CODINGOPTION_ON;
11541+ }
11542+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-AdaptiveB:off"))) {
11543+ InputParams.AdaptiveB = MFX_CODINGOPTION_OFF;
11544+ }
11545+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
11546+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-iGfx"))) {
11547+ InputParams.bPrefferiGfx = true;
11548+ }
11549+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-dGfx"))) {
11550+ InputParams.bPrefferdGfx = true;
11551+ }
11552+#endif
11553+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-dec::sys"))) {
11554+ InputParams.DecOutPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
11555+ }
11556+#ifdef ENABLE_MCTF
11557+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-mctf"))) {
11558+ ParseMCTFParams(argv, argc, i, &InputParams);
11559+ }
11560+#endif
11561+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-ext_allocator")) ||
11562+ 0 == msdk_strcmp(argv[i], MSDK_STRING("-MemType::video"))) {
11563+ InputParams.bForceSysMem = false;
11564+ }
11565+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-sys")) ||
11566+ 0 == msdk_strcmp(argv[i], MSDK_STRING("-MemType::system"))) {
11567+ InputParams.bForceSysMem = true;
11568+ }
11569+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-opaq")) ||
11570+ 0 == msdk_strcmp(argv[i], MSDK_STRING("-MemType::opaque"))) {
11571+ msdk_printf(MSDK_STRING(
11572+ "WARNING: -opaq option is ignored, opaque memory support is disabled in opeVPL.\n"));
11573+ }
11574+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-memory"))) {
11575+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
11576+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.nMemoryModel)) {
11577+ PrintError(MSDK_STRING("-memory %s is invalid"), argv[i]);
11578+ return MFX_ERR_UNSUPPORTED;
11579+ }
11580+ if (InputParams.nMemoryModel < 1 || InputParams.nMemoryModel > 3) {
11581+ PrintError(MSDK_STRING(" \"%s\" memory type is invalid. Default (1) will be used."),
11582+ argv[i]);
11583+ InputParams.nMemoryModel = GENERAL_ALLOC;
11584+ }
11585+ }
11586+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-MemModel::GeneralAlloc"))) {
11587+ InputParams.nMemoryModel = GENERAL_ALLOC;
11588+ }
11589+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-MemModel::VisibleIntAlloc"))) {
11590+ InputParams.nMemoryModel = VISIBLE_INT_ALLOC;
11591+ }
11592+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-MemModel::HiddenIntAlloc"))) {
11593+ InputParams.nMemoryModel = HIDDEN_INT_ALLOC;
11594+ }
11595+#if (MFX_VERSION >= 1027)
11596+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-TargetBitDepthLuma"))) {
11597+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
11598+
11599+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.TargetBitDepthLuma)) {
11600+ PrintError(MSDK_STRING("TargetBitDepthLuma param is invalid"));
11601+ return MFX_ERR_UNSUPPORTED;
11602+ }
11603+ }
11604+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-TargetBitDepthChroma"))) {
11605+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
11606+
11607+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.TargetBitDepthChroma)) {
11608+ PrintError(MSDK_STRING("TargetBitDepthChroma param is invalid"));
11609+ return MFX_ERR_UNSUPPORTED;
11610+ }
11611+ }
11612+#endif
11613+ else {
11614+ // no matching argument was found
11615+ return MFX_ERR_NOT_FOUND;
11616+ }
11617+
11618+ return MFX_ERR_NONE;
11619+}
11620+
11621+mfxStatus ParseVPPCmdLine(msdk_char* argv[],
11622+ mfxU32 argc,
11623+ mfxU32& index,
11624+ TranscodingSample::sInputParams* params,
11625+ mfxU32& skipped) {
11626+ if (0 == msdk_strcmp(argv[index], MSDK_STRING("-denoise"))) {
11627+ VAL_CHECK(index + 1 == argc, index, argv[index]);
11628+ index++;
11629+ if (MFX_ERR_NONE != msdk_opt_read(argv[index], params->DenoiseLevel) ||
11630+ !(params->DenoiseLevel >= 0 && params->DenoiseLevel <= 100)) {
11631+ PrintError(NULL, MSDK_STRING("-denoise \"%s\" is invalid"), argv[index]);
11632+ return MFX_ERR_UNSUPPORTED;
11633+ }
11634+ skipped += 2;
11635+ return MFX_ERR_NONE;
11636+ }
11637+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-detail"))) {
11638+ VAL_CHECK(index + 1 == argc, index, argv[index]);
11639+ index++;
11640+ if (MFX_ERR_NONE != msdk_opt_read(argv[index], params->DetailLevel) ||
11641+ !(params->DetailLevel >= 0 && params->DetailLevel <= 100)) {
11642+ PrintError(NULL, MSDK_STRING("-detail \"%s\" is invalid"), argv[index]);
11643+ return MFX_ERR_UNSUPPORTED;
11644+ }
11645+ skipped += 2;
11646+ return MFX_ERR_NONE;
11647+ }
11648+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-FRC::PT"))) {
11649+ params->FRCAlgorithm = MFX_FRCALGM_PRESERVE_TIMESTAMP;
11650+ return MFX_ERR_NONE;
11651+ }
11652+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-FRC::DT"))) {
11653+ params->FRCAlgorithm = MFX_FRCALGM_DISTRIBUTED_TIMESTAMP;
11654+ return MFX_ERR_NONE;
11655+ }
11656+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-FRC::INTERP"))) {
11657+ params->FRCAlgorithm = MFX_FRCALGM_FRAME_INTERPOLATION;
11658+ return MFX_ERR_NONE;
11659+ }
11660+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-deinterlace"))) {
11661+ params->bEnableDeinterlacing = true;
11662+ params->DeinterlacingMode = 0;
11663+ return MFX_ERR_NONE;
11664+ }
11665+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-deinterlace::ADI"))) {
11666+ params->bEnableDeinterlacing = true;
11667+ params->DeinterlacingMode = MFX_DEINTERLACING_ADVANCED;
11668+ return MFX_ERR_NONE;
11669+ }
11670+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-deinterlace::ADI_SCD"))) {
11671+ params->bEnableDeinterlacing = true;
11672+ params->DeinterlacingMode = MFX_DEINTERLACING_ADVANCED_SCD;
11673+ return MFX_ERR_NONE;
11674+ }
11675+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-deinterlace::BOB"))) {
11676+ params->bEnableDeinterlacing = true;
11677+ params->DeinterlacingMode = MFX_DEINTERLACING_BOB;
11678+ return MFX_ERR_NONE;
11679+ }
11680+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-deinterlace::ADI_NO_REF"))) {
11681+ params->bEnableDeinterlacing = true;
11682+ params->DeinterlacingMode = MFX_DEINTERLACING_ADVANCED_NOREF;
11683+ return MFX_ERR_NONE;
11684+ }
11685+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-scaling_mode"))) {
11686+ VAL_CHECK(index + 1 == argc, index, argv[index]);
11687+ index++;
11688+ if (0 == msdk_strcmp(argv[index], MSDK_STRING("lowpower")))
11689+ params->ScalingMode = MFX_SCALING_MODE_LOWPOWER;
11690+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("quality")))
11691+ params->ScalingMode = MFX_SCALING_MODE_QUALITY;
11692+ else {
11693+ PrintError(NULL, MSDK_STRING("-scaling_mode \"%s\" is invalid"), argv[index]);
11694+ return MFX_ERR_UNSUPPORTED;
11695+ }
11696+ return MFX_ERR_NONE;
11697+ }
11698+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-ec::rgb4"))) {
11699+ params->EncoderFourCC = MFX_FOURCC_RGB4;
11700+ return MFX_ERR_NONE;
11701+ }
11702+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-ec::yuy2"))) {
11703+ params->EncoderFourCC = MFX_FOURCC_YUY2;
11704+ return MFX_ERR_NONE;
11705+ }
11706+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-ec::nv12"))) {
11707+ params->EncoderFourCC = MFX_FOURCC_NV12;
11708+ return MFX_ERR_NONE;
11709+ }
11710+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-ec::nv16"))) {
11711+ params->EncoderFourCC = MFX_FOURCC_NV16;
11712+ return MFX_ERR_NONE;
11713+ }
11714+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-ec::p010"))) {
11715+ params->EncoderFourCC = MFX_FOURCC_P010;
11716+ return MFX_ERR_NONE;
11717+ }
11718+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-ec::p210"))) {
11719+ params->EncoderFourCC = MFX_FOURCC_P210;
11720+ return MFX_ERR_NONE;
11721+ }
11722+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-dc::p010"))) {
11723+ params->DecoderFourCC = MFX_FOURCC_P010;
11724+ return MFX_ERR_NONE;
11725+ }
11726+#if (MFX_VERSION >= 1031)
11727+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-dc::p016"))) {
11728+ params->DecoderFourCC = MFX_FOURCC_P016;
11729+ return MFX_ERR_NONE;
11730+ }
11731+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-dc::y216"))) {
11732+ params->DecoderFourCC = MFX_FOURCC_Y216;
11733+ return MFX_ERR_NONE;
11734+ }
11735+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-dc::y416"))) {
11736+ params->DecoderFourCC = MFX_FOURCC_Y216;
11737+ return MFX_ERR_NONE;
11738+ }
11739+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-ec::p016"))) {
11740+ params->EncoderFourCC = MFX_FOURCC_P016;
11741+ return MFX_ERR_NONE;
11742+ }
11743+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-ec::y216"))) {
11744+ params->EncoderFourCC = MFX_FOURCC_Y216;
11745+ return MFX_ERR_NONE;
11746+ }
11747+#endif
11748+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-dc::rgb4"))) {
11749+ params->DecoderFourCC = MFX_FOURCC_RGB4;
11750+ return MFX_ERR_NONE;
11751+ }
11752+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-dc::yuy2"))) {
11753+ params->DecoderFourCC = MFX_FOURCC_YUY2;
11754+ return MFX_ERR_NONE;
11755+ }
11756+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-dc::nv12"))) {
11757+ params->DecoderFourCC = MFX_FOURCC_NV12;
11758+ return MFX_ERR_NONE;
11759+ }
11760+#if (MFX_VERSION >= 1027)
11761+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-dc::y210"))) {
11762+ params->DecoderFourCC = MFX_FOURCC_Y210;
11763+ return MFX_ERR_NONE;
11764+ }
11765+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-dc::y410"))) {
11766+ params->DecoderFourCC = MFX_FOURCC_Y410;
11767+ return MFX_ERR_NONE;
11768+ }
11769+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-ec::y210"))) {
11770+ params->EncoderFourCC = MFX_FOURCC_Y210;
11771+ return MFX_ERR_NONE;
11772+ }
11773+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-ec::y410"))) {
11774+ params->EncoderFourCC = MFX_FOURCC_Y410;
11775+ return MFX_ERR_NONE;
11776+ }
11777+#endif
11778+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("-field_processing"))) {
11779+ VAL_CHECK(index + 1 == argc, index, argv[index]);
11780+ index++;
11781+ if (0 == msdk_strcmp(argv[index], MSDK_STRING("t2t")))
11782+ params->fieldProcessingMode = FC_T2T;
11783+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("t2b")))
11784+ params->fieldProcessingMode = FC_T2B;
11785+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("b2t")))
11786+ params->fieldProcessingMode = FC_B2T;
11787+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("b2b")))
11788+ params->fieldProcessingMode = FC_B2B;
11789+ else if (0 == msdk_strcmp(argv[index], MSDK_STRING("fr2fr")))
11790+ params->fieldProcessingMode = FC_FR2FR;
11791+ else {
11792+ PrintError(NULL, MSDK_STRING("-field_processing \"%s\" is invalid"), argv[index]);
11793+ return MFX_ERR_UNSUPPORTED;
11794+ }
11795+ return MFX_ERR_NONE;
11796+ }
11797+
11798+ return MFX_ERR_MORE_DATA;
11799+}
11800+
11801+mfxStatus CmdProcessor::ParseParamsForOneSession(mfxU32 argc, msdk_char* argv[]) {
11802+ mfxStatus sts = MFX_ERR_NONE;
11803+ mfxStatus stsExtBuf = MFX_ERR_NONE;
11804+ mfxStatus stsAddlParams = MFX_ERR_NONE;
11805+ mfxU32 skipped = 0;
11806+
11807+ // save original cmd line for debug purpose
11808+ msdk_stringstream cmd;
11809+ for (mfxU32 i = 0; i < argc; i++)
11810+ cmd << argv[i] << MSDK_STRING(" ");
11811+ m_lines.push_back(cmd.str());
11812+
11813+ TranscodingSample::sInputParams InputParams;
11814+ if (m_nTimeout)
11815+ InputParams.nTimeout = m_nTimeout;
11816+ if (bRobustFlag)
11817+ InputParams.bRobustFlag = true;
11818+ if (bSoftRobustFlag)
11819+ InputParams.bSoftRobustFlag = true;
11820+
11821+ InputParams.shouldUseGreedyFormula = shouldUseGreedyFormula;
11822+
11823+ InputParams.statisticsWindowSize = statisticsWindowSize;
11824+ InputParams.statisticsLogFile = statisticsLogFile;
11825+
11826+ //bind to a dump-log-file name
11827+ InputParams.DumpLogFileName = DumpLogFileName;
11828+
11829+ if (0 == msdk_strcmp(argv[0], MSDK_STRING("set"))) {
11830+ if (argc != 3) {
11831+ msdk_printf(MSDK_STRING("error: number of arguments for 'set' options is wrong"));
11832+ return MFX_ERR_UNSUPPORTED;
11833+ }
11834+ sts = ParseOption__set(argv[1], argv[2]);
11835+ return sts;
11836+ }
11837+ // default implementation
11838+ InputParams.libType = MFX_IMPL_HARDWARE_ANY;
11839+#if defined(_WIN32) || defined(_WIN64)
11840+ InputParams.libType = MFX_IMPL_HARDWARE_ANY | MFX_IMPL_VIA_D3D11;
11841+#endif
11842+ InputParams.eModeExt = Native;
11843+
11844+ for (mfxU32 i = 0; i < argc; i++) {
11845+ // process multi-character options
11846+ if ((0 == msdk_strncmp(MSDK_STRING("-i::"), argv[i], msdk_strlen(MSDK_STRING("-i::")))) &&
11847+ (0 != msdk_strncmp(argv[i] + 4,
11848+ MSDK_STRING("source"),
11849+ msdk_strlen(MSDK_STRING("source"))))) {
11850+ sts = StrFormatToCodecFormatFourCC(argv[i] + 4, InputParams.DecodeId);
11851+ if (sts != MFX_ERR_NONE) {
11852+ return MFX_ERR_UNSUPPORTED;
11853+ }
11854+ VAL_CHECK(i + 1 == argc, i, argv[i]);
11855+ i++;
11856+ SIZE_CHECK((msdk_strlen(argv[i]) + 1) > MSDK_ARRAY_LEN(InputParams.strSrcFile));
11857+ msdk_opt_read(argv[i], InputParams.strSrcFile);
11858+ if (InputParams.eMode == Source) {
11859+ switch (InputParams.DecodeId) {
11860+ case MFX_CODEC_MPEG2:
11861+ case MFX_CODEC_HEVC:
11862+ case MFX_CODEC_AVC:
11863+ case MFX_CODEC_VC1:
11864+ case MFX_CODEC_VP9:
11865+ case MFX_CODEC_AV1:
11866+ case CODEC_MVC:
11867+ case MFX_CODEC_JPEG:
11868+ return MFX_ERR_UNSUPPORTED;
11869+ }
11870+ }
11871+ if (InputParams.DecodeId == CODEC_MVC) {
11872+ InputParams.DecodeId = MFX_CODEC_AVC;
11873+ InputParams.bIsMVC = true;
11874+ }
11875+ }
11876+ else if ((0 ==
11877+ msdk_strncmp(MSDK_STRING("-o::"), argv[i], msdk_strlen(MSDK_STRING("-o::")))) &&
11878+ (0 != msdk_strncmp(argv[i] + 4,
11879+ MSDK_STRING("sink"),
11880+ msdk_strlen(MSDK_STRING("sink"))))) {
11881+ sts = StrFormatToCodecFormatFourCC(argv[i] + 4, InputParams.EncodeId);
11882+
11883+ if (sts != MFX_ERR_NONE) {
11884+ return MFX_ERR_UNSUPPORTED;
11885+ }
11886+ VAL_CHECK(i + 1 == argc, i, argv[i]);
11887+ i++;
11888+ SIZE_CHECK((msdk_strlen(argv[i]) + 1) > MSDK_ARRAY_LEN(InputParams.strDstFile));
11889+ msdk_opt_read(argv[i], InputParams.strDstFile);
11890+ if (InputParams.eMode == Sink || InputParams.bIsMVC) {
11891+ switch (InputParams.EncodeId) {
11892+ case MFX_CODEC_MPEG2:
11893+ case MFX_CODEC_HEVC:
11894+ case MFX_CODEC_AVC:
11895+ case MFX_CODEC_JPEG:
11896+ case MFX_CODEC_DUMP:
11897+ return MFX_ERR_UNSUPPORTED;
11898+ }
11899+ }
11900+ if (InputParams.EncodeId == CODEC_MVC) {
11901+ if (InputParams.eMode == Sink)
11902+ return MFX_ERR_UNSUPPORTED;
11903+
11904+ InputParams.EncodeId = MFX_CODEC_AVC;
11905+ InputParams.bIsMVC = true;
11906+ }
11907+ }
11908+#if MFX_VERSION >= 1022
11909+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-roi_file"))) {
11910+ VAL_CHECK(i + 1 == argc, i, argv[i]);
11911+ i++;
11912+
11913+ msdk_char strRoiFile[MSDK_MAX_FILENAME_LEN];
11914+ SIZE_CHECK((msdk_strlen(argv[i]) + 1) > MSDK_ARRAY_LEN(strRoiFile));
11915+ msdk_opt_read(argv[i], strRoiFile);
11916+
11917+ if (!ParseROIFile(strRoiFile, InputParams.m_ROIData)) {
11918+ PrintError(MSDK_STRING("Incorrect ROI file: \"%s\" "), argv[i]);
11919+ return MFX_ERR_UNSUPPORTED;
11920+ }
11921+ }
11922+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-p"))) {
11923+ if (m_PerfFILE) {
11924+ msdk_printf(MSDK_STRING("error: only one performance file is supported"));
11925+ return MFX_ERR_UNSUPPORTED;
11926+ }
11927+ --argc;
11928+ ++argv;
11929+ if (!argv[i]) {
11930+ msdk_printf(MSDK_STRING("error: no argument given for '-p' option\n"));
11931+ }
11932+ MSDK_FOPEN(m_PerfFILE, argv[i], MSDK_STRING("w"));
11933+ if (NULL == m_PerfFILE) {
11934+ msdk_printf(MSDK_STRING("error: performance file \"%s\" not found"), argv[i]);
11935+ return MFX_ERR_UNSUPPORTED;
11936+ }
11937+ }
11938+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-roi_qpmap"))) {
11939+ InputParams.bROIasQPMAP = true;
11940+ }
11941+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-extmbqp"))) {
11942+ InputParams.bExtMBQP = true;
11943+ }
11944+#endif //MFX_VERSION >= 1022
11945+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-sw"))) {
11946+ InputParams.libType = MFX_IMPL_SOFTWARE;
11947+ }
11948+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-hw"))) {
11949+#if defined(_WIN32) || defined(_WIN64)
11950+ InputParams.libType = MFX_IMPL_HARDWARE_ANY | MFX_IMPL_VIA_D3D11;
11951+#elif defined(LIBVA_SUPPORT)
11952+ InputParams.libType = MFX_IMPL_HARDWARE_ANY;
11953+#endif
11954+ }
11955+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-hw_d3d11"))) {
11956+ InputParams.libType = MFX_IMPL_HARDWARE_ANY | MFX_IMPL_VIA_D3D11;
11957+ }
11958+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-hw_d3d9"))) {
11959+ InputParams.libType = MFX_IMPL_HARDWARE_ANY | MFX_IMPL_VIA_D3D9;
11960+ }
11961+#if (defined(LINUX32) || defined(LINUX64))
11962+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-device"))) {
11963+ if (!InputParams.strDevicePath.empty()) {
11964+ msdk_printf(MSDK_STRING("error: you can specify only one device\n"));
11965+ return MFX_ERR_UNSUPPORTED;
11966+ }
11967+
11968+ VAL_CHECK(i + 1 == argc, i, argv[i]);
11969+ InputParams.strDevicePath = argv[++i];
11970+ }
11971+#endif
11972+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-perf_opt"))) {
11973+ InputParams.bIsPerf = true;
11974+ }
11975+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-robust"))) {
11976+ InputParams.bRobustFlag = true;
11977+ }
11978+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-robust:soft"))) {
11979+ InputParams.bSoftRobustFlag = true;
11980+ }
11981+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-threads"))) {
11982+ VAL_CHECK(i + 1 == argc, i, argv[i]);
11983+ i++;
11984+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nThreadsNum)) {
11985+ PrintError(MSDK_STRING("Threads number is invalid"));
11986+ return MFX_ERR_UNSUPPORTED;
11987+ }
11988+ }
11989+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-f"))) {
11990+ VAL_CHECK(i + 1 == argc, i, argv[i]);
11991+ i++;
11992+ // Temporary check for giving priority to -fe option
11993+ if (!InputParams.dVPPOutFramerate) {
11994+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.dVPPOutFramerate)) {
11995+ PrintError(MSDK_STRING("FrameRate \"%s\" is invalid"), argv[i]);
11996+ return MFX_ERR_UNSUPPORTED;
11997+ }
11998+ }
11999+ }
12000+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-fe"))) {
12001+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12002+ i++;
12003+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.dVPPOutFramerate)) {
12004+ PrintError(MSDK_STRING("FrameRate \"%s\" is invalid"), argv[i]);
12005+ return MFX_ERR_UNSUPPORTED;
12006+ }
12007+ }
12008+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-fps"))) {
12009+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12010+ i++;
12011+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nFPS)) {
12012+ PrintError(MSDK_STRING("FPS limit \"%s\" is invalid"), argv[i]);
12013+ return MFX_ERR_UNSUPPORTED;
12014+ }
12015+ }
12016+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-b"))) {
12017+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12018+ i++;
12019+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nBitRate)) {
12020+ PrintError(MSDK_STRING("BitRate \"%s\" is invalid"), argv[i]);
12021+ return MFX_ERR_UNSUPPORTED;
12022+ }
12023+ }
12024+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-bm"))) {
12025+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12026+ i++;
12027+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nBitRateMultiplier)) {
12028+ PrintError(MSDK_STRING("Bitrate multiplier \"%s\" is invalid"), argv[i]);
12029+ return MFX_ERR_UNSUPPORTED;
12030+ }
12031+ }
12032+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-wb"))) {
12033+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12034+ i++;
12035+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.WinBRCMaxAvgKbps)) {
12036+ PrintError(MSDK_STRING("Maximum bitrate for sliding window \"%s\" is invalid"),
12037+ argv[i]);
12038+ return MFX_ERR_UNSUPPORTED;
12039+ }
12040+ }
12041+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-ws"))) {
12042+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12043+ i++;
12044+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.WinBRCSize)) {
12045+ PrintError(MSDK_STRING("Sliding window size \"%s\" is invalid"), argv[i]);
12046+ return MFX_ERR_UNSUPPORTED;
12047+ }
12048+ }
12049+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-hrd"))) {
12050+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12051+ i++;
12052+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.BufferSizeInKB)) {
12053+ PrintError(MSDK_STRING("Frame buffer size \"%s\" is invalid"), argv[i]);
12054+ return MFX_ERR_UNSUPPORTED;
12055+ }
12056+ }
12057+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-dist"))) {
12058+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12059+ i++;
12060+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.GopRefDist)) {
12061+ PrintError(MSDK_STRING("GOP reference distance \"%s\" is invalid"), argv[i]);
12062+ return MFX_ERR_UNSUPPORTED;
12063+ }
12064+ }
12065+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-gop_size"))) {
12066+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12067+ i++;
12068+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.GopPicSize)) {
12069+ PrintError(MSDK_STRING("GOP size \"%s\" is invalid"), argv[i]);
12070+ return MFX_ERR_UNSUPPORTED;
12071+ }
12072+ }
12073+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-num_ref"))) {
12074+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12075+ i++;
12076+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.NumRefFrame)) {
12077+ PrintError(MSDK_STRING("Number of reference frames \"%s\" is invalid"), argv[i]);
12078+ return MFX_ERR_UNSUPPORTED;
12079+ }
12080+ }
12081+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-trows"))) {
12082+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12083+ i++;
12084+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nEncTileRows)) {
12085+ PrintError(MSDK_STRING("Encoding tile row count \"%s\" is invalid"), argv[i]);
12086+ return MFX_ERR_UNSUPPORTED;
12087+ }
12088+ }
12089+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-tcols"))) {
12090+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12091+ i++;
12092+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nEncTileCols)) {
12093+ PrintError(MSDK_STRING("Encoding tile column count \"%s\" is invalid"), argv[i]);
12094+ return MFX_ERR_UNSUPPORTED;
12095+ }
12096+ }
12097+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-CodecLevel"))) {
12098+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12099+ i++;
12100+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.CodecLevel)) {
12101+ PrintError(MSDK_STRING("CodecLevel \"%s\" is invalid"), argv[i]);
12102+ return MFX_ERR_UNSUPPORTED;
12103+ }
12104+ }
12105+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-CodecProfile"))) {
12106+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12107+ i++;
12108+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.CodecProfile)) {
12109+ PrintError(MSDK_STRING("CodecProfile \"%s\" is invalid"), argv[i]);
12110+ return MFX_ERR_UNSUPPORTED;
12111+ }
12112+ }
12113+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-MaxKbps"))) {
12114+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12115+ i++;
12116+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.MaxKbps)) {
12117+ PrintError(MSDK_STRING("MaxKbps \"%s\" is invalid"), argv[i]);
12118+ return MFX_ERR_UNSUPPORTED;
12119+ }
12120+ }
12121+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-InitialDelayInKB"))) {
12122+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12123+ i++;
12124+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.InitialDelayInKB)) {
12125+ PrintError(MSDK_STRING("InitialDelayInKB \"%s\" is invalid"), argv[i]);
12126+ return MFX_ERR_UNSUPPORTED;
12127+ }
12128+ }
12129+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-GopOptFlag:closed"))) {
12130+ InputParams.GopOptFlag = MFX_GOP_CLOSED;
12131+ }
12132+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-GopOptFlag:strict"))) {
12133+ InputParams.GopOptFlag = MFX_GOP_STRICT;
12134+ }
12135+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-bref"))) {
12136+ InputParams.nBRefType = MFX_B_REF_PYRAMID;
12137+ }
12138+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-nobref"))) {
12139+ InputParams.nBRefType = MFX_B_REF_OFF;
12140+ }
12141+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-gpb:on"))) {
12142+ InputParams.GPB = MFX_CODINGOPTION_ON;
12143+ }
12144+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-gpb:off"))) {
12145+ InputParams.GPB = MFX_CODINGOPTION_OFF;
12146+ }
12147+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-TransformSkip:on"))) {
12148+ InputParams.nTransformSkip = MFX_CODINGOPTION_ON;
12149+ }
12150+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-TransformSkip:off"))) {
12151+ InputParams.nTransformSkip = MFX_CODINGOPTION_OFF;
12152+ }
12153+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-u"))) {
12154+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12155+ i++;
12156+ InputParams.nTargetUsage = StrToTargetUsage(argv[i]);
12157+ if (!InputParams.nTargetUsage) {
12158+ PrintError(MSDK_STRING(" \"%s\" target usage is invalid. Balanced will be used."),
12159+ argv[i]);
12160+ InputParams.nTargetUsage = MFX_TARGETUSAGE_BALANCED;
12161+ }
12162+ }
12163+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-WeightedPred::default"))) {
12164+ InputParams.WeightedPred = MFX_WEIGHTED_PRED_DEFAULT;
12165+ }
12166+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-WeightedPred::implicit"))) {
12167+ InputParams.WeightedPred = MFX_WEIGHTED_PRED_IMPLICIT;
12168+ }
12169+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-WeightedBiPred::default"))) {
12170+ InputParams.WeightedBiPred = MFX_WEIGHTED_PRED_DEFAULT;
12171+ }
12172+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-WeightedBiPred::implicit"))) {
12173+ InputParams.WeightedBiPred = MFX_WEIGHTED_PRED_IMPLICIT;
12174+ }
12175+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-q"))) {
12176+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12177+ i++;
12178+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nQuality)) {
12179+ PrintError(MSDK_STRING(" \"%s\" quality is invalid"), argv[i]);
12180+ return MFX_ERR_UNSUPPORTED;
12181+ }
12182+ }
12183+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-w"))) {
12184+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12185+ i++;
12186+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nDstWidth)) {
12187+ PrintError(MSDK_STRING("width \"%s\" is invalid"), argv[i]);
12188+ return MFX_ERR_UNSUPPORTED;
12189+ }
12190+ }
12191+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-h"))) {
12192+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12193+ i++;
12194+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nDstHeight)) {
12195+ PrintError(MSDK_STRING("height \"%s\" is invalid"), argv[i]);
12196+ return MFX_ERR_UNSUPPORTED;
12197+ }
12198+ }
12199+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-l"))) {
12200+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12201+ i++;
12202+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nSlices)) {
12203+ PrintError(MSDK_STRING("numSlices \"%s\" is invalid"), argv[i]);
12204+ return MFX_ERR_UNSUPPORTED;
12205+ }
12206+ }
12207+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-mss"))) {
12208+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12209+ i++;
12210+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nMaxSliceSize)) {
12211+ PrintError(MSDK_STRING("maxSliceSize \"%s\" is invalid"), argv[i]);
12212+ return MFX_ERR_UNSUPPORTED;
12213+ }
12214+ }
12215+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-async"))) {
12216+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12217+ i++;
12218+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nAsyncDepth)) {
12219+ PrintError(MSDK_STRING("async \"%s\" is invalid"), argv[i]);
12220+ return MFX_ERR_UNSUPPORTED;
12221+ }
12222+ }
12223+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-join"))) {
12224+ InputParams.bIsJoin = true;
12225+ }
12226+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-priority"))) {
12227+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12228+ i++;
12229+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.priority)) {
12230+ PrintError(MSDK_STRING("priority \"%s\" is invalid"), argv[i]);
12231+ return MFX_ERR_UNSUPPORTED;
12232+ }
12233+ }
12234+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-i::source"))) {
12235+ if (InputParams.eMode != Native) {
12236+ PrintError(NULL, "-i::source cannot be used here");
12237+ return MFX_ERR_UNSUPPORTED;
12238+ }
12239+
12240+ InputParams.eMode = Source;
12241+ }
12242+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-o::sink"))) {
12243+ if (InputParams.eMode != Native) {
12244+ PrintError(NULL, "-o::sink cannot be used here");
12245+ return MFX_ERR_UNSUPPORTED;
12246+ }
12247+
12248+ InputParams.eMode = Sink;
12249+ }
12250+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp"))) {
12251+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12252+ i++;
12253+ /* NB! numSurf4Comp should be equal to Number of decoding session */
12254+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.numSurf4Comp)) {
12255+ PrintError(MSDK_STRING("-n \"%s\" is invalid"), argv[i]);
12256+ return MFX_ERR_UNSUPPORTED;
12257+ }
12258+ /* This is can init early */
12259+ if (InputParams.eModeExt == Native)
12260+ InputParams.eModeExt = VppComp;
12261+ }
12262+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp_only"))) {
12263+ /* for VPP comp with rendering we have to use ext allocator */
12264+#ifdef LIBVA_SUPPORT
12265+ InputParams.libvaBackend = MFX_LIBVA_DRM;
12266+#endif
12267+
12268+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12269+ i++;
12270+ /* NB! numSurf4Comp should be equal to Number of decoding session */
12271+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.numSurf4Comp)) {
12272+ PrintError(MSDK_STRING("-n \"%s\" is invalid"), argv[i]);
12273+ return MFX_ERR_UNSUPPORTED;
12274+ }
12275+ /* This is can init early */
12276+ if (InputParams.eModeExt == Native)
12277+ InputParams.eModeExt = VppCompOnly;
12278+ }
12279+ else if (0 == msdk_strncmp(MSDK_STRING("-vpp_comp_dump"),
12280+ argv[i],
12281+ msdk_strlen(MSDK_STRING("-vpp_comp_dump")))) {
12282+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12283+ i++;
12284+ SIZE_CHECK((msdk_strlen(argv[i]) + 1) > MSDK_ARRAY_LEN(InputParams.strDumpVppCompFile));
12285+ msdk_opt_read(argv[i], InputParams.strDumpVppCompFile);
12286+ }
12287+#if defined(LIBVA_X11_SUPPORT)
12288+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-rx11"))) {
12289+ InputParams.libvaBackend = MFX_LIBVA_X11;
12290+ }
12291+#endif
12292+
12293+#if defined(LIBVA_WAYLAND_SUPPORT)
12294+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-rwld"))) {
12295+ InputParams.nRenderWinX = 0;
12296+ InputParams.nRenderWinY = 0;
12297+ InputParams.bPerfMode = false;
12298+ InputParams.libvaBackend = MFX_LIBVA_WAYLAND;
12299+ }
12300+#endif
12301+
12302+#if defined(LIBVA_DRM_SUPPORT)
12303+ else if (0 == msdk_strncmp(argv[i], MSDK_STRING("-rdrm"), 5)) {
12304+ InputParams.libvaBackend = MFX_LIBVA_DRM_MODESET;
12305+ InputParams.monitorType = getMonitorType(&argv[i][5]);
12306+ if (argv[i][5]) {
12307+ if (argv[i][5] != '-') {
12308+ PrintError(MSDK_STRING("unsupported monitor type"));
12309+ return MFX_ERR_UNSUPPORTED;
12310+ }
12311+ InputParams.monitorType = getMonitorType(&argv[i][6]);
12312+ if (InputParams.monitorType >= MFX_MONITOR_MAXNUMBER) {
12313+ PrintError(MSDK_STRING("unsupported monitor type"));
12314+ return MFX_ERR_UNSUPPORTED;
12315+ }
12316+ }
12317+ else {
12318+ InputParams.monitorType = MFX_MONITOR_AUTO; // that's case of "-rdrm" pure option
12319+ }
12320+ }
12321+#endif
12322+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp::sys"))) {
12323+ InputParams.VppOutPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
12324+ }
12325+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp::vid"))) {
12326+ InputParams.VppOutPattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
12327+ }
12328+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp_dst_x"))) {
12329+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12330+ i++;
12331+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nVppCompDstX)) {
12332+ PrintError(MSDK_STRING("vpp_comp_dst_x %s is invalid"), argv[i]);
12333+ return MFX_ERR_UNSUPPORTED;
12334+ }
12335+ if (InputParams.eModeExt != VppComp)
12336+ InputParams.eModeExt = VppComp;
12337+ }
12338+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp_dst_y"))) {
12339+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12340+ i++;
12341+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nVppCompDstY)) {
12342+ PrintError(MSDK_STRING("-vpp_comp_dst_y %s is invalid"), argv[i]);
12343+ return MFX_ERR_UNSUPPORTED;
12344+ }
12345+ if (InputParams.eModeExt != VppComp)
12346+ InputParams.eModeExt = VppComp;
12347+ }
12348+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp_dst_w"))) {
12349+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12350+ i++;
12351+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nVppCompDstW)) {
12352+ PrintError(MSDK_STRING("-vpp_comp_dst_w %s is invalid"), argv[i]);
12353+ return MFX_ERR_UNSUPPORTED;
12354+ }
12355+ if (InputParams.eModeExt != VppComp)
12356+ InputParams.eModeExt = VppComp;
12357+ }
12358+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp_dst_h"))) {
12359+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12360+ i++;
12361+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nVppCompDstH)) {
12362+ PrintError(MSDK_STRING("-vpp_comp_dst_h %s is invalid"), argv[i]);
12363+ return MFX_ERR_UNSUPPORTED;
12364+ }
12365+ if (InputParams.eModeExt != VppComp)
12366+ InputParams.eModeExt = VppComp;
12367+ }
12368+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp_src_w"))) {
12369+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12370+ i++;
12371+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nVppCompSrcW)) {
12372+ PrintError(MSDK_STRING("-vpp_comp_src_w %s is invalid"), argv[i]);
12373+ return MFX_ERR_UNSUPPORTED;
12374+ }
12375+ if (InputParams.eModeExt != VppComp)
12376+ InputParams.eModeExt = VppComp;
12377+ }
12378+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp_src_h"))) {
12379+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12380+ i++;
12381+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nVppCompSrcH)) {
12382+ PrintError(MSDK_STRING("-vpp_comp_src_h %s is invalid"), argv[i]);
12383+ return MFX_ERR_UNSUPPORTED;
12384+ }
12385+ if (InputParams.eModeExt != VppComp)
12386+ InputParams.eModeExt = VppComp;
12387+ }
12388+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp_num_tiles"))) {
12389+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12390+ i++;
12391+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.numTiles4Comp)) {
12392+ PrintError(MSDK_STRING("-vpp_comp_num_tiles %s is invalid"), argv[i]);
12393+ return MFX_ERR_UNSUPPORTED;
12394+ }
12395+ if (InputParams.eModeExt != VppCompOnly)
12396+ InputParams.eModeExt = VppCompOnly;
12397+ }
12398+#if MFX_VERSION >= 1023
12399+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp_tile_id"))) {
12400+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12401+ i++;
12402+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nVppCompTileId)) {
12403+ PrintError(MSDK_STRING("-vpp_comp_tile_id %s is invalid"), argv[i]);
12404+ return MFX_ERR_UNSUPPORTED;
12405+ }
12406+ }
12407+#endif
12408+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vpp_comp_render"))) {
12409+ if (InputParams.eModeExt != VppComp)
12410+ InputParams.eModeExt = VppComp;
12411+ }
12412+#if MFX_VERSION >= 1022
12413+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-dec_postproc"))) {
12414+ InputParams.bDecoderPostProcessing = true;
12415+ }
12416+#endif //MFX_VERSION >= 1022
12417+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-n"))) {
12418+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12419+ i++;
12420+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.MaxFrameNumber)) {
12421+ PrintError(MSDK_STRING("-n %s is invalid"), argv[i]);
12422+ return MFX_ERR_UNSUPPORTED;
12423+ }
12424+ }
12425+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-angle"))) {
12426+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12427+ i++;
12428+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nRotationAngle)) {
12429+ PrintError(MSDK_STRING("-angle %s is invalid"), argv[i]);
12430+ return MFX_ERR_UNSUPPORTED;
12431+ }
12432+ if (InputParams.strVPPPluginDLLPath[0] == '\0') {
12433+ msdk_opt_read(MSDK_CPU_ROTATE_PLUGIN, InputParams.strVPPPluginDLLPath);
12434+ }
12435+ }
12436+#if (MFX_VERSION >= 1025)
12437+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-mfe_frames"))) {
12438+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12439+ i++;
12440+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.numMFEFrames)) {
12441+ PrintError(MSDK_STRING("-mfe_frames %s num frames is invalid"), argv[i]);
12442+ return MFX_ERR_UNSUPPORTED;
12443+ }
12444+ }
12445+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-mfe_mode"))) {
12446+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12447+ i++;
12448+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.MFMode)) {
12449+ PrintError(MSDK_STRING("-mfe_mode %s is invalid"), argv[i]);
12450+ return MFX_ERR_UNSUPPORTED;
12451+ }
12452+ }
12453+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-mfe_timeout"))) {
12454+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12455+ i++;
12456+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.mfeTimeout)) {
12457+ PrintError(MSDK_STRING("-mfe_timeout %s is invalid"), argv[i]);
12458+ return MFX_ERR_UNSUPPORTED;
12459+ }
12460+ }
12461+#endif
12462+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-timeout"))) {
12463+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12464+ i++;
12465+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nTimeout)) {
12466+ PrintError(MSDK_STRING("-timeout %s is invalid"), argv[i]);
12467+ return MFX_ERR_UNSUPPORTED;
12468+ }
12469+ skipped += 2;
12470+ }
12471+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-dump"))) {
12472+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12473+ i++;
12474+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.strMfxParamsDumpFile)) {
12475+ PrintError(MSDK_STRING("Dump file name \"%s\" is invalid"), argv[i]);
12476+ return MFX_ERR_UNSUPPORTED;
12477+ }
12478+ }
12479+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-robust"))) {
12480+ InputParams.bRobustFlag = true;
12481+ }
12482+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-opencl"))) {
12483+ msdk_opt_read(MSDK_OCL_ROTATE_PLUGIN, InputParams.strVPPPluginDLLPath);
12484+ InputParams.bOpenCL = true;
12485+ }
12486+
12487+ // output PicStruct
12488+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-la_ext"))) {
12489+ InputParams.bEnableExtLA = true;
12490+ }
12491+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-la"))) {
12492+ InputParams.bLABRC = true;
12493+ InputParams.nRateControlMethod = MFX_RATECONTROL_LA;
12494+ }
12495+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vbr"))) {
12496+ InputParams.nRateControlMethod = MFX_RATECONTROL_VBR;
12497+ }
12498+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-cbr"))) {
12499+ InputParams.nRateControlMethod = MFX_RATECONTROL_CBR;
12500+ }
12501+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-bpyr"))) {
12502+ InputParams.bEnableBPyramid = true;
12503+ }
12504+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-vcm"))) {
12505+ InputParams.nRateControlMethod = MFX_RATECONTROL_VCM;
12506+ }
12507+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-lad"))) {
12508+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12509+ InputParams.nRateControlMethod = MFX_RATECONTROL_LA;
12510+ i++;
12511+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.nLADepth)) {
12512+ PrintError(MSDK_STRING("look ahead depth \"%s\" is invalid"), argv[i]);
12513+ return MFX_ERR_UNSUPPORTED;
12514+ }
12515+ }
12516+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-pe"))) {
12517+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12518+ InputParams.encoderPluginParams = ParsePluginGuid(argv[i + 1]);
12519+ if (AreGuidsEqual(InputParams.encoderPluginParams.pluginGuid, MSDK_PLUGINGUID_NULL)) {
12520+ PrintError(MSDK_STRING("Invalid encoder guid"), argv[i]);
12521+ return MFX_ERR_UNSUPPORTED;
12522+ }
12523+ i++;
12524+ }
12525+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-pd"))) {
12526+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12527+ InputParams.decoderPluginParams = ParsePluginGuid(argv[i + 1]);
12528+ if (AreGuidsEqual(InputParams.decoderPluginParams.pluginGuid, MSDK_PLUGINGUID_NULL)) {
12529+ PrintError(MSDK_STRING("Invalid decoder guid"), argv[i]);
12530+ return MFX_ERR_UNSUPPORTED;
12531+ }
12532+ i++;
12533+ }
12534+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-override_decoder_framerate"))) {
12535+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12536+ i++;
12537+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.dDecoderFrameRateOverride)) {
12538+ PrintError(MSDK_STRING("Framerate \"%s\" is invalid"), argv[i]);
12539+ return MFX_ERR_UNSUPPORTED;
12540+ }
12541+ }
12542+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-override_encoder_framerate"))) {
12543+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12544+ i++;
12545+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.dEncoderFrameRateOverride)) {
12546+ PrintError(MSDK_STRING("Framerate \"%s\" is invalid"), argv[i]);
12547+ return MFX_ERR_UNSUPPORTED;
12548+ }
12549+ }
12550+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-override_encoder_picstruct"))) {
12551+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12552+ i++;
12553+ if (MFX_ERR_NONE != msdk_opt_read(argv[i], InputParams.EncoderPicstructOverride)) {
12554+ PrintError(MSDK_STRING("Picstruct \"%s\" is invalid"), argv[i]);
12555+ return MFX_ERR_UNSUPPORTED;
12556+ }
12557+ }
12558+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-gpucopy::on"))) {
12559+ InputParams.nGpuCopyMode = MFX_GPUCOPY_ON;
12560+ }
12561+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-gpucopy::off"))) {
12562+ InputParams.nGpuCopyMode = MFX_GPUCOPY_OFF;
12563+ }
12564+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-repartitioncheck::on"))) {
12565+ InputParams.RepartitionCheckMode = MFX_CODINGOPTION_ON;
12566+ }
12567+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-repartitioncheck::off"))) {
12568+ InputParams.RepartitionCheckMode = MFX_CODINGOPTION_OFF;
12569+ }
12570+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-cqp"))) {
12571+ InputParams.nRateControlMethod = MFX_RATECONTROL_CQP;
12572+ }
12573+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-qpi"))) {
12574+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12575+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.nQPI)) {
12576+ PrintError(MSDK_STRING("Quantizer for I frames is invalid"));
12577+ return MFX_ERR_UNSUPPORTED;
12578+ }
12579+ }
12580+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-qpp"))) {
12581+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12582+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.nQPP)) {
12583+ PrintError(MSDK_STRING("Quantizer for P frames is invalid"));
12584+ return MFX_ERR_UNSUPPORTED;
12585+ }
12586+ }
12587+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-qpb"))) {
12588+ VAL_CHECK(i + 1 == argc, i, argv[i]);
12589+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.nQPB)) {
12590+ PrintError(MSDK_STRING("Quantizer for B frames is invalid"));
12591+ return MFX_ERR_UNSUPPORTED;
12592+ }
12593+ }
12594+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-DisableQPOffset"))) {
12595+ InputParams.bDisableQPOffset = true;
12596+ }
12597+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-qsv-ff"))) {
12598+ InputParams.enableQSVFF = true;
12599+ }
12600+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-single_texture_d3d11"))) {
12601+ InputParams.bSingleTexture = true;
12602+ }
12603+#if (MFX_VERSION >= 1024)
12604+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-extbrc::on"))) {
12605+ InputParams.nExtBRC = EXTBRC_ON;
12606+ }
12607+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-extbrc::off"))) {
12608+ InputParams.nExtBRC = EXTBRC_OFF;
12609+ }
12610+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-extbrc::implicit"))) {
12611+ InputParams.nExtBRC = EXTBRC_IMPLICIT;
12612+ }
12613+#endif
12614+#if (MFX_VERSION >= 1026)
12615+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-ExtBrcAdaptiveLTR:on"))) {
12616+ InputParams.ExtBrcAdaptiveLTR = MFX_CODINGOPTION_ON;
12617+ }
12618+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-ExtBrcAdaptiveLTR:off"))) {
12619+ InputParams.ExtBrcAdaptiveLTR = MFX_CODINGOPTION_OFF;
12620+ }
12621+
12622+#endif
12623+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-pp"))) {
12624+ InputParams.shouldPrintPresets = true;
12625+ }
12626+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-preset"))) {
12627+ msdk_char presetName[MSDK_MAX_FILENAME_LEN];
12628+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
12629+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], presetName)) {
12630+ PrintError(MSDK_STRING("Preset Name is not defined"));
12631+ return MFX_ERR_UNSUPPORTED;
12632+ }
12633+
12634+ InputParams.PresetMode = CPresetManager::PresetNameToMode(presetName);
12635+ if (InputParams.PresetMode == PRESET_MAX_MODES) {
12636+ PrintError(MSDK_STRING("Preset Name is invalid"));
12637+ return MFX_ERR_UNSUPPORTED;
12638+ }
12639+ }
12640+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-ir_type"))) {
12641+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
12642+
12643+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.IntRefType)) {
12644+ PrintError(MSDK_STRING("Intra refresh type is invalid"));
12645+ return MFX_ERR_UNSUPPORTED;
12646+ }
12647+ }
12648+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-ir_cycle_size"))) {
12649+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
12650+
12651+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.IntRefCycleSize)) {
12652+ PrintError(MSDK_STRING("IR refresh cycle size param is invalid"));
12653+ return MFX_ERR_UNSUPPORTED;
12654+ }
12655+ }
12656+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-ir_qp_delta"))) {
12657+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
12658+
12659+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.IntRefQPDelta)) {
12660+ PrintError(MSDK_STRING("IR QP delta param is invalid"));
12661+ return MFX_ERR_UNSUPPORTED;
12662+ }
12663+ }
12664+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-ir_cycle_dist"))) {
12665+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
12666+
12667+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.IntRefCycleDist)) {
12668+ PrintError(MSDK_STRING("IR cycle distance param is invalid"));
12669+ return MFX_ERR_UNSUPPORTED;
12670+ }
12671+ }
12672+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-LowDelayBRC"))) {
12673+ InputParams.LowDelayBRC = MFX_CODINGOPTION_ON;
12674+ }
12675+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-amfs:on"))) {
12676+ InputParams.nAdaptiveMaxFrameSize = MFX_CODINGOPTION_ON;
12677+ }
12678+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-amfs:off"))) {
12679+ InputParams.nAdaptiveMaxFrameSize = MFX_CODINGOPTION_OFF;
12680+ }
12681+ else if (0 == msdk_strcmp(argv[i], MSDK_STRING("-mfs"))) {
12682+ VAL_CHECK(i + 1 >= argc, i, argv[i]);
12683+ if (MFX_ERR_NONE != msdk_opt_read(argv[++i], InputParams.nMaxFrameSize)) {
12684+ PrintError(MSDK_STRING("MaxFrameSize is invalid"));
12685+ return MFX_ERR_UNSUPPORTED;
12686+ }
12687+ }
12688+ MOD_SMT_PARSE_INPUT
12689+ else if ((stsExtBuf = ParseVPPCmdLine(argv, argc, i, &InputParams, skipped)) !=
12690+ MFX_ERR_MORE_DATA) {
12691+ if (stsExtBuf == MFX_ERR_UNSUPPORTED) {
12692+ return MFX_ERR_UNSUPPORTED;
12693+ }
12694+ }
12695+ else {
12696+ // WA for compiler error C1061 (too many chained else-if clauses)
12697+ // ParseAdditionalParams returns:
12698+ // 0 if argv[i] is processed successfully by this function
12699+ // < 1 if argv[i] is processed and generates an error
12700+ // OR
12701+ // if argv[i] was not processed (did not match any switches)
12702+ stsAddlParams = ParseAdditionalParams(argv, argc, i, InputParams);
12703+
12704+ // either unrecognized parameter, or parse error with recognized parameter
12705+ if (stsAddlParams) {
12706+ if (stsAddlParams == MFX_ERR_NOT_FOUND)
12707+ PrintError(MSDK_STRING("Invalid input argument number %d %s"), i, argv[i]);
12708+ return MFX_ERR_UNSUPPORTED;
12709+ }
12710+ }
12711+ }
12712+
12713+ if (skipped < argc) {
12714+ sts = VerifyAndCorrectInputParams(InputParams);
12715+ MSDK_CHECK_STATUS(sts, "VerifyAndCorrectInputParams failed");
12716+ m_SessionArray.push_back(InputParams);
12717+ }
12718+
12719+ return MFX_ERR_NONE;
12720+
12721+} //mfxStatus CmdProcessor::ParseParamsForOneSession(msdk_char *pLine, mfxU32 length)
12722+
12723+mfxStatus CmdProcessor::ParseOption__set(msdk_char* strCodecType, msdk_char* strPluginGuid) {
12724+ mfxU32 codecid = 0;
12725+ mfxU32 type = 0;
12726+ sPluginParams pluginParams;
12727+
12728+ //Parse codec type - decoder or encoder
12729+ if (0 == msdk_strncmp(MSDK_STRING("-i::"), strCodecType, 4)) {
12730+ type = MSDK_VDECODE;
12731+ }
12732+ else if (0 == msdk_strncmp(MSDK_STRING("-o::"), strCodecType, 4)) {
12733+ type = MSDK_VENCODE;
12734+ }
12735+ else {
12736+ msdk_printf(MSDK_STRING("error: incorrect definition codec type (must be -i:: or -o::)\n"));
12737+ return MFX_ERR_UNSUPPORTED;
12738+ }
12739+
12740+ if (StrFormatToCodecFormatFourCC(strCodecType + 4, codecid) != MFX_ERR_NONE) {
12741+ msdk_printf(MSDK_STRING("error: codec is unknown\n"));
12742+ return MFX_ERR_UNSUPPORTED;
12743+ }
12744+
12745+ if (!IsPluginCodecSupported(codecid)) {
12746+ msdk_printf(MSDK_STRING("error: codec is unsupported\n"));
12747+ return MFX_ERR_UNSUPPORTED;
12748+ }
12749+
12750+ pluginParams = ParsePluginGuid(strPluginGuid);
12751+ if (AreGuidsEqual(pluginParams.pluginGuid, MSDK_PLUGINGUID_NULL)) {
12752+ msdk_printf(MSDK_STRING("error: invalid codec guid\n"));
12753+ return MFX_ERR_UNSUPPORTED;
12754+ }
12755+
12756+ if (type == MSDK_VDECODE)
12757+ m_decoderPlugins.insert(std::pair<mfxU32, sPluginParams>(codecid, pluginParams));
12758+ else
12759+ m_encoderPlugins.insert(std::pair<mfxU32, sPluginParams>(codecid, pluginParams));
12760+
12761+ return MFX_ERR_NONE;
12762+};
12763+
12764+mfxStatus CmdProcessor::VerifyAndCorrectInputParams(TranscodingSample::sInputParams& InputParams) {
12765+ if (0 == msdk_strlen(InputParams.strSrcFile) &&
12766+ (InputParams.eMode == Sink || InputParams.eMode == Native)) {
12767+ PrintError(MSDK_STRING("Source file name not found"));
12768+ return MFX_ERR_UNSUPPORTED;
12769+ };
12770+
12771+ if (0 == msdk_strlen(InputParams.strDstFile) &&
12772+ (InputParams.eMode == Source || InputParams.eMode == Native ||
12773+ InputParams.eMode == VppComp) &&
12774+ InputParams.eModeExt != VppCompOnly) {
12775+ PrintError(MSDK_STRING("Destination file name not found"));
12776+ return MFX_ERR_UNSUPPORTED;
12777+ };
12778+
12779+ if (MFX_CODEC_JPEG != InputParams.EncodeId && MFX_CODEC_MPEG2 != InputParams.EncodeId &&
12780+ MFX_CODEC_AVC != InputParams.EncodeId && MFX_CODEC_HEVC != InputParams.EncodeId &&
12781+ MFX_CODEC_VP9 != InputParams.EncodeId && MFX_CODEC_DUMP != InputParams.EncodeId &&
12782+ InputParams.eMode != Sink && InputParams.eModeExt != VppCompOnly) {
12783+ PrintError(MSDK_STRING("Unknown encoder\n"));
12784+ return MFX_ERR_UNSUPPORTED;
12785+ }
12786+
12787+ if (MFX_CODEC_MPEG2 != InputParams.DecodeId && MFX_CODEC_AVC != InputParams.DecodeId &&
12788+ MFX_CODEC_HEVC != InputParams.DecodeId && MFX_CODEC_VC1 != InputParams.DecodeId &&
12789+ MFX_CODEC_JPEG != InputParams.DecodeId && MFX_CODEC_VP9 != InputParams.DecodeId &&
12790+ MFX_CODEC_VP8 != InputParams.DecodeId && MFX_CODEC_AV1 != InputParams.DecodeId &&
12791+ MFX_CODEC_RGB4 != InputParams.DecodeId && MFX_CODEC_NV12 != InputParams.DecodeId &&
12792+ MFX_CODEC_I420 != InputParams.DecodeId && InputParams.eMode != Source) {
12793+ PrintError(MSDK_STRING("Unknown decoder\n"));
12794+ return MFX_ERR_UNSUPPORTED;
12795+ }
12796+
12797+ if (MFX_CODEC_I420 == InputParams.DecodeId || MFX_CODEC_NV12 == InputParams.DecodeId) {
12798+ InputParams.rawInput = true;
12799+ }
12800+ else {
12801+ InputParams.rawInput = false;
12802+ }
12803+
12804+ if (MFX_CODEC_RGB4 == InputParams.DecodeId &&
12805+ (!InputParams.nVppCompSrcH || !InputParams.nVppCompSrcW)) {
12806+ PrintError(MSDK_STRING(
12807+ "VppCompSrcH and VppCompSrcW must be specified in case of -i::rgb4_frame\n"));
12808+ return MFX_ERR_UNSUPPORTED;
12809+ }
12810+
12811+ if ((!InputParams.FRCAlgorithm && !InputParams.bEnableDeinterlacing) &&
12812+ InputParams.dVPPOutFramerate) {
12813+ msdk_printf(MSDK_STRING(
12814+ "-f option is ignored, it can be used with FRC or deinterlace options only. \n"));
12815+ InputParams.dVPPOutFramerate = 0;
12816+ }
12817+
12818+ if (InputParams.FRCAlgorithm && InputParams.bEnableExtLA) {
12819+ PrintError(MSDK_STRING("-la_ext and FRC options cannot be used together\n"));
12820+ return MFX_ERR_UNSUPPORTED;
12821+ }
12822+
12823+ if (InputParams.nQuality && InputParams.EncodeId && (MFX_CODEC_JPEG != InputParams.EncodeId)) {
12824+ PrintError(MSDK_STRING("-q option is supported only for JPEG encoder\n"));
12825+ return MFX_ERR_UNSUPPORTED;
12826+ }
12827+
12828+ if ((InputParams.nTargetUsage || InputParams.nBitRate) &&
12829+ (MFX_CODEC_JPEG == InputParams.EncodeId)) {
12830+ PrintError(MSDK_STRING(
12831+ "-b and -u options are supported only for H.264, MPEG2 and MVC encoders. For JPEG encoder use -q\n"));
12832+ return MFX_ERR_UNSUPPORTED;
12833+ }
12834+
12835+ // valid target usage range is: [MFX_TARGETUSAGE_BEST_QUALITY .. MFX_TARGETUSAGE_BEST_SPEED] (at the moment [1..7])
12836+ // If target usage is kept unknown - presets manager will fill in proper value
12837+ if ((InputParams.nTargetUsage < MFX_TARGETUSAGE_UNKNOWN) ||
12838+ (InputParams.nTargetUsage > MFX_TARGETUSAGE_BEST_SPEED)) {
12839+ PrintError(NULL, "Unsupported target usage");
12840+ return MFX_ERR_UNSUPPORTED;
12841+ }
12842+
12843+ // Ignoring user-defined Async Depth for LA
12844+ if (InputParams.nMaxSliceSize) {
12845+ InputParams.nAsyncDepth = 1;
12846+ }
12847+
12848+ // For decoder session of inter-session case, let's set AsyncDepth to 4 by default
12849+ if (InputParams.eMode == Sink && !InputParams.nAsyncDepth) {
12850+ InputParams.nAsyncDepth = 4;
12851+ }
12852+
12853+ if (InputParams.bLABRC && !(InputParams.libType & MFX_IMPL_HARDWARE_ANY)) {
12854+ PrintError(MSDK_STRING("Look ahead BRC is supported only with -hw option!"));
12855+ return MFX_ERR_UNSUPPORTED;
12856+ }
12857+
12858+ if (InputParams.bLABRC && (InputParams.EncodeId != MFX_CODEC_AVC) &&
12859+ (InputParams.eMode == Source)) {
12860+ PrintError(MSDK_STRING("Look ahead BRC is supported only with H.264 encoder!"));
12861+ return MFX_ERR_UNSUPPORTED;
12862+ }
12863+
12864+ if ((InputParams.nRateControlMethod == MFX_RATECONTROL_LA ||
12865+ InputParams.nRateControlMethod == MFX_RATECONTROL_LA_EXT ||
12866+ InputParams.nRateControlMethod == MFX_RATECONTROL_LA_ICQ ||
12867+ InputParams.nRateControlMethod == MFX_RATECONTROL_LA_HRD) &&
12868+ (InputParams.nLADepth > 100)) {
12869+ PrintError(MSDK_STRING(
12870+ "Unsupported value of -lad parameter, must be in range [1,100] or 0 for automatic selection"));
12871+ return MFX_ERR_UNSUPPORTED;
12872+ }
12873+
12874+ if ((InputParams.nMaxSliceSize) && !(InputParams.libType & MFX_IMPL_HARDWARE_ANY)) {
12875+ PrintError(MSDK_STRING("MaxSliceSize option is supported only with -hw option!"));
12876+ return MFX_ERR_UNSUPPORTED;
12877+ }
12878+ if ((InputParams.nMaxSliceSize) && (InputParams.nSlices)) {
12879+ PrintError(MSDK_STRING("-mss and -l options are not compatible!"));
12880+ }
12881+ if ((InputParams.nMaxSliceSize) && (InputParams.EncodeId != MFX_CODEC_AVC)) {
12882+ PrintError(MSDK_STRING("MaxSliceSize option is supported only with H.264 encoder!"));
12883+ return MFX_ERR_UNSUPPORTED;
12884+ }
12885+
12886+ if (InputParams.BitrateLimit == MFX_CODINGOPTION_UNKNOWN) {
12887+ InputParams.BitrateLimit = MFX_CODINGOPTION_OFF;
12888+ }
12889+
12890+ if (InputParams.enableQSVFF && InputParams.eMode == Sink) {
12891+ msdk_printf(MSDK_STRING(
12892+ "WARNING: -lowpower(-qsv-ff) option is not valid for decoder-only sessions, this parameter will be ignored.\n"));
12893+ }
12894+
12895+ std::map<mfxU32, sPluginParams>::iterator it;
12896+
12897+ // Set decoder plugins parameters only if they were not set before
12898+ if (!memcmp(InputParams.decoderPluginParams.pluginGuid.Data,
12899+ MSDK_PLUGINGUID_NULL.Data,
12900+ sizeof(MSDK_PLUGINGUID_NULL)) &&
12901+ !strcmp(InputParams.decoderPluginParams.strPluginPath, "")) {
12902+ it = m_decoderPlugins.find(InputParams.DecodeId);
12903+ if (it != m_decoderPlugins.end())
12904+ InputParams.decoderPluginParams = it->second;
12905+ }
12906+ else {
12907+ // Decoding plugin was set manually, so let's check if codec supports plugins
12908+ if (!IsPluginCodecSupported(InputParams.DecodeId)) {
12909+ msdk_printf(MSDK_STRING("error: decoder does not support plugins\n"));
12910+ return MFX_ERR_UNSUPPORTED;
12911+ }
12912+ }
12913+
12914+ // Set encoder plugins parameters only if they were not set before
12915+ if (!memcmp(InputParams.encoderPluginParams.pluginGuid.Data,
12916+ MSDK_PLUGINGUID_NULL.Data,
12917+ sizeof(MSDK_PLUGINGUID_NULL)) &&
12918+ !strcmp(InputParams.encoderPluginParams.strPluginPath, "")) {
12919+ it = m_encoderPlugins.find(InputParams.EncodeId);
12920+ if (it != m_encoderPlugins.end())
12921+ InputParams.encoderPluginParams = it->second;
12922+ }
12923+ else {
12924+ // Encoding plugin was set manually, so let's check if codec supports plugins
12925+ if (!IsPluginCodecSupported(InputParams.EncodeId)) {
12926+ msdk_printf(MSDK_STRING("error: encoder does not support plugins\n"));
12927+ return MFX_ERR_UNSUPPORTED;
12928+ }
12929+ }
12930+
12931+ if (InputParams.EncoderFourCC && InputParams.eMode == Sink) {
12932+ msdk_printf(MSDK_STRING(
12933+ "WARNING: -ec option is used in session without encoder, this parameter will be ignored \n"));
12934+ }
12935+
12936+ if (InputParams.DecoderFourCC && InputParams.eMode != Native && InputParams.eMode != Sink) {
12937+ msdk_printf(MSDK_STRING(
12938+ "WARNING: -dc option is used in session without decoder, this parameter will be ignored \n"));
12939+ }
12940+
12941+ if (InputParams.EncoderFourCC && InputParams.EncoderFourCC != MFX_FOURCC_NV12 &&
12942+ InputParams.EncoderFourCC != MFX_FOURCC_RGB4 &&
12943+ InputParams.EncoderFourCC != MFX_FOURCC_YUY2 && InputParams.EncodeId == MFX_CODEC_DUMP) {
12944+ PrintError(MSDK_STRING(
12945+ "-o::raw option can be used with NV12, RGB4 and YUY2 color formats only.\n"));
12946+ return MFX_ERR_UNSUPPORTED;
12947+ }
12948+
12949+ if ((InputParams.nEncTileRows || InputParams.nEncTileCols) &&
12950+ (InputParams.EncodeId != MFX_CODEC_HEVC)
12951+#if (MFX_VERSION >= 1029)
12952+ && (InputParams.EncodeId != MFX_CODEC_VP9)
12953+#endif
12954+ ) {
12955+ msdk_printf(MSDK_STRING("WARNING: -trows and -tcols are only supported for")
12956+#if (MFX_VERSION >= 1029)
12957+ MSDK_STRING(" VP9 and")
12958+#endif
12959+ MSDK_STRING(" HEVC encoder, these parameters will be ignored.\n"));
12960+ InputParams.nEncTileRows = 0;
12961+ InputParams.nEncTileCols = 0;
12962+ }
12963+
12964+#if (defined(_WIN32) || defined(_WIN64)) && (MFX_VERSION >= 1031)
12965+ if (InputParams.bPrefferiGfx && InputParams.bPrefferdGfx) {
12966+ msdk_printf(MSDK_STRING("WARNING: both dGfx and iGfx flags set. iGfx will be preffered\n"));
12967+ InputParams.bPrefferdGfx = false;
12968+ }
12969+#endif
12970+
12971+ return MFX_ERR_NONE;
12972+} //mfxStatus CmdProcessor::VerifyAndCorrectInputParams(TranscodingSample::sInputParams &InputParams)
12973+
12974+bool CmdProcessor::GetNextSessionParams(TranscodingSample::sInputParams& InputParams) {
12975+ if (!m_SessionArray.size())
12976+ return false;
12977+ if (m_SessionParamId == m_SessionArray.size()) {
12978+ return false;
12979+ }
12980+ InputParams = m_SessionArray[m_SessionParamId];
12981+
12982+ m_SessionParamId++;
12983+ return true;
12984+
12985+} //bool CmdProcessor::GetNextSessionParams(TranscodingSample::sInputParams &InputParams)
12986--
129872.31.1
12988
diff --git a/recipes-multimedia/onevpl/onevpl/0001-Add-X11-support-to-legacy-tools.patch b/recipes-multimedia/onevpl/onevpl/0001-Add-X11-support-to-legacy-tools.patch
deleted file mode 100644
index fd7faa82..00000000
--- a/recipes-multimedia/onevpl/onevpl/0001-Add-X11-support-to-legacy-tools.patch
+++ /dev/null
@@ -1,50 +0,0 @@
1From 3c485ba902da0a4a2e9fc43b34eb9174c739929e Mon Sep 17 00:00:00 2001
2From: "Yew, Chang Ching" <chang.ching.yew@intel.com>
3Date: Fri, 21 May 2021 14:11:44 +0800
4Subject: [PATCH] Add X11 support to legacy tools
5
6Upstream-Status: Pending
7
8Signed-off-by: jinchung <jin.chung.teng@intel.com>
9Signed-off-by: Yew, Chang Ching <chang.ching.yew@intel.com>
10---
11 tools/legacy/sample_common/CMakeLists.txt | 9 +++++++++
12 1 file changed, 9 insertions(+)
13
14diff --git a/tools/legacy/sample_common/CMakeLists.txt b/tools/legacy/sample_common/CMakeLists.txt
15index 5cf69d3..db4de3d 100644
16--- a/tools/legacy/sample_common/CMakeLists.txt
17+++ b/tools/legacy/sample_common/CMakeLists.txt
18@@ -32,6 +32,7 @@ if(UNIX)
19 src/vm/time_linux.cpp
20 src/vm/atomic_linux.cpp
21 src/vm/thread_linux.cpp
22+ src/vaapi_utils_x11.cpp
23 src/vaapi_utils_drm.cpp)
24 else()
25 list(
26@@ -67,6 +68,8 @@ if(UNIX)
27 find_package(PkgConfig REQUIRED)
28 pkg_check_modules(PKG_LIBVA libva libva-drm)
29 pkg_check_modules(PKG_LIBDRM libdrm)
30+ pkg_check_modules(PKG_X11 x11)
31+ pkg_check_modules(PKG_LIBVA_X11 libva-x11>=1.10.0)
32 if(PKG_LIBVA_FOUND)
33 target_compile_definitions(${TARGET} PUBLIC -DLIBVA_SUPPORT)
34 target_include_directories(${TARGET} PUBLIC ${PKG_LIBVA_INCLUDE_DIRS})
35@@ -79,6 +82,12 @@ if(UNIX)
36 else()
37 message(WARNING "libva-drm not found: building without libVA DRM support")
38 endif()
39+ if(PKG_X11_FOUND)
40+ target_compile_definitions(${TARGET} PUBLIC -DLIBVA_X11_SUPPORT)
41+ target_include_directories(${TARGET} PUBLIC ${PKG_X11_LIBRARY_DIRS})
42+ else()
43+ message(WARNING "x11 modules not found: building without libVA X11 support")
44+ endif()
45
46 target_link_libraries(${TARGET} ${CMAKE_DL_LIBS})
47
48--
492.31.1
50
diff --git a/recipes-multimedia/onevpl/onevpl/0001-Adding-Wayland-support-to-legacy-tools.patch b/recipes-multimedia/onevpl/onevpl/0001-Adding-Wayland-support-to-legacy-tools.patch
index 857626b4..69d4a417 100644
--- a/recipes-multimedia/onevpl/onevpl/0001-Adding-Wayland-support-to-legacy-tools.patch
+++ b/recipes-multimedia/onevpl/onevpl/0001-Adding-Wayland-support-to-legacy-tools.patch
@@ -1,24 +1,27 @@
1From 64250fb3e73c1977067381c70aeffbaa980f4136 Mon Sep 17 00:00:00 2001 1From 2d72bd9c295ac84654e0f24b64675d3c95a15c2e Mon Sep 17 00:00:00 2001
2From: jinchung <jin.chung.teng@intel.com> 2From: "Yew, Chang Ching" <chang.ching.yew@intel.com>
3Date: Fri, 28 May 2021 11:34:01 +0800 3Date: Tue, 29 Jun 2021 15:51:41 +0800
4Subject: [PATCH] Adding Wayland support to legacy tools 4Subject: [PATCH] Adding Wayland support to legacy tools
5 5
6Upstream-Status: Submitted 6Upstream-Status: Submitted
7https://github.com/oneapi-src/oneVPL/pull/6 7https://github.com/oneapi-src/oneVPL/pull/6
8 8
9Signed-off-by: jinchung <jin.chung.teng@intel.com> 9Signed-off-by: jinchung <jin.chung.teng@intel.com>
10Signed-off-by: Yew, Chang Ching <chang.ching.yew@intel.com>
10--- 11---
11 tools/legacy/CMakeLists.txt | 1 + 12 tools/legacy/CMakeLists.txt | 1 +
12 tools/legacy/sample_common/CMakeLists.txt | 8 + 13 tools/legacy/sample_common/CMakeLists.txt | 8 +
13 tools/legacy/sample_common/src/vaapi_device.cpp | 2 +- 14 .../legacy/sample_common/CMakeLists.txt.orig | 105 ++++
14 tools/legacy/sample_misc/wayland/CMakeLists.txt | 29 ++ 15 .../legacy/sample_common/src/vaapi_device.cpp | 2 +-
15 .../sample_misc/wayland/include/class_wayland.h | 160 +++++++ 16 .../legacy/sample_misc/wayland/CMakeLists.txt | 29 +
16 .../sample_misc/wayland/include/listener_wayland.h | 66 +++ 17 .../wayland/include/class_wayland.h | 160 ++++++
17 .../wayland/include/wayland-drm-client-protocol.h | 235 ++++++++++ 18 .../wayland/include/listener_wayland.h | 66 +++
18 .../sample_misc/wayland/src/class_wayland.cpp | 500 +++++++++++++++++++++ 19 .../include/wayland-drm-client-protocol.h | 235 ++++++++
19 .../sample_misc/wayland/src/listener_wayland.cpp | 105 +++++ 20 .../sample_misc/wayland/src/class_wayland.cpp | 500 ++++++++++++++++++
20 .../sample_misc/wayland/src/wayland-drm-protocol.c | 84 ++++ 21 .../wayland/src/listener_wayland.cpp | 105 ++++
21 10 files changed, 1189 insertions(+), 1 deletion(-) 22 .../wayland/src/wayland-drm-protocol.c | 84 +++
23 11 files changed, 1294 insertions(+), 1 deletion(-)
24 create mode 100644 tools/legacy/sample_common/CMakeLists.txt.orig
22 create mode 100644 tools/legacy/sample_misc/wayland/CMakeLists.txt 25 create mode 100644 tools/legacy/sample_misc/wayland/CMakeLists.txt
23 create mode 100644 tools/legacy/sample_misc/wayland/include/class_wayland.h 26 create mode 100644 tools/legacy/sample_misc/wayland/include/class_wayland.h
24 create mode 100644 tools/legacy/sample_misc/wayland/include/listener_wayland.h 27 create mode 100644 tools/legacy/sample_misc/wayland/include/listener_wayland.h
@@ -28,27 +31,28 @@ Signed-off-by: jinchung <jin.chung.teng@intel.com>
28 create mode 100644 tools/legacy/sample_misc/wayland/src/wayland-drm-protocol.c 31 create mode 100644 tools/legacy/sample_misc/wayland/src/wayland-drm-protocol.c
29 32
30diff --git a/tools/legacy/CMakeLists.txt b/tools/legacy/CMakeLists.txt 33diff --git a/tools/legacy/CMakeLists.txt b/tools/legacy/CMakeLists.txt
31index 165a5b2..1d4af73 100644 34index 59e1ad2..de7c452 100644
32--- a/tools/legacy/CMakeLists.txt 35--- a/tools/legacy/CMakeLists.txt
33+++ b/tools/legacy/CMakeLists.txt 36+++ b/tools/legacy/CMakeLists.txt
34@@ -11,3 +11,4 @@ add_subdirectory(sample_common) 37@@ -11,4 +11,5 @@ add_subdirectory(sample_common)
35 add_subdirectory(sample_decode) 38 add_subdirectory(sample_decode)
36 add_subdirectory(sample_vpp) 39 add_subdirectory(sample_vpp)
37 add_subdirectory(sample_encode) 40 add_subdirectory(sample_encode)
38+add_subdirectory(sample_misc/wayland) 41+add_subdirectory(sample_misc/wayland)
42 add_subdirectory(sample_multi_transcode)
39diff --git a/tools/legacy/sample_common/CMakeLists.txt b/tools/legacy/sample_common/CMakeLists.txt 43diff --git a/tools/legacy/sample_common/CMakeLists.txt b/tools/legacy/sample_common/CMakeLists.txt
40index db4de3d..4f04226 100644 44index 32b7944..b4710f6 100644
41--- a/tools/legacy/sample_common/CMakeLists.txt 45--- a/tools/legacy/sample_common/CMakeLists.txt
42+++ b/tools/legacy/sample_common/CMakeLists.txt 46+++ b/tools/legacy/sample_common/CMakeLists.txt
43@@ -70,6 +70,7 @@ if(UNIX) 47@@ -73,6 +73,7 @@ if(UNIX)
44 pkg_check_modules(PKG_LIBDRM libdrm) 48 pkg_check_modules(PKG_LIBDRM libdrm)
45 pkg_check_modules(PKG_X11 x11) 49 pkg_check_modules(PKG_X11 x11)
46 pkg_check_modules(PKG_LIBVA_X11 libva-x11>=1.10.0) 50 pkg_check_modules(PKG_LIBVA_X11 libva-x11>=1.10.0)
47+ pkg_check_modules(PKG_WAYLAND_CLIENT wayland-client) 51+ pkg_check_modules(PKG_WAYLAND_CLIENT wayland-client)
48 if(PKG_LIBVA_FOUND) 52 if(PKG_LIBVA_FOUND)
49 target_compile_definitions(${TARGET} PUBLIC -DLIBVA_SUPPORT) 53 target_compile_definitions(${TARGET} PUBLIC -DLIBVA_SUPPORT)
50 target_include_directories(${TARGET} PUBLIC ${PKG_LIBVA_INCLUDE_DIRS}) 54 target_compile_definitions(${TARGET} PUBLIC -DLIBVA_DRM_SUPPORT)
51@@ -88,6 +89,13 @@ if(UNIX) 55@@ -91,6 +92,13 @@ if(UNIX)
52 else() 56 else()
53 message(WARNING "x11 modules not found: building without libVA X11 support") 57 message(WARNING "x11 modules not found: building without libVA X11 support")
54 endif() 58 endif()
@@ -62,6 +66,117 @@ index db4de3d..4f04226 100644
62 66
63 target_link_libraries(${TARGET} ${CMAKE_DL_LIBS}) 67 target_link_libraries(${TARGET} ${CMAKE_DL_LIBS})
64 68
69diff --git a/tools/legacy/sample_common/CMakeLists.txt.orig b/tools/legacy/sample_common/CMakeLists.txt.orig
70new file mode 100644
71index 0000000..32b7944
72--- /dev/null
73+++ b/tools/legacy/sample_common/CMakeLists.txt.orig
74@@ -0,0 +1,105 @@
75+# ##############################################################################
76+# Copyright (C) Intel Corporation
77+#
78+# SPDX-License-Identifier: MIT
79+# ##############################################################################
80+cmake_minimum_required(VERSION 3.10.2)
81+
82+set(TARGET sample_common)
83+
84+set(sources "")
85+list(
86+ APPEND
87+ sources
88+ src/base_allocator.cpp
89+ src/decode_render.cpp
90+ src/mfx_buffering.cpp
91+ src/sysmem_allocator.cpp
92+ src/general_allocator.cpp
93+ src/sample_utils.cpp
94+ src/plugin_utils.cpp
95+ src/preset_manager.cpp
96+ src/parameters_dumper.cpp
97+ src/vpl_implementation_loader.cpp
98+ src/vm/atomic.cpp
99+ src/vm/time.cpp)
100+
101+if(UNIX)
102+ list(
103+ APPEND
104+ sources
105+ src/vaapi_utils.cpp
106+ src/vaapi_device.cpp
107+ src/vaapi_allocator.cpp
108+ src/vm/time_linux.cpp
109+ src/vm/atomic_linux.cpp
110+ src/vm/thread_linux.cpp
111+ src/vaapi_utils_x11.cpp
112+ src/vaapi_utils_drm.cpp)
113+else()
114+ list(
115+ APPEND
116+ sources
117+ src/d3d11_allocator.cpp
118+ src/d3d11_device.cpp
119+ src/d3d_allocator.cpp
120+ src/vm/thread_windows.cpp
121+ src/d3d_device.cpp)
122+endif()
123+
124+set(CMAKE_POSITION_INDEPENDENT_CODE true)
125+add_library(${TARGET} STATIC ${sources})
126+target_include_directories(
127+ ${TARGET} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
128+
129+if(MSVC)
130+ add_definitions(-D_CRT_SECURE_NO_WARNINGS)
131+endif()
132+
133+add_definitions(-DMFX_DEPRECATED_OFF)
134+
135+if(POLICY CMP0074)
136+ # ignore warning of VPL_ROOT in find_package search path
137+ cmake_policy(SET CMP0074 OLD)
138+endif()
139+
140+find_package(VPL REQUIRED)
141+target_link_libraries(${TARGET} VPL::dispatcher media_sdk_compatibility_headers)
142+
143+if(UNIX)
144+ find_package(PkgConfig REQUIRED)
145+ # note: pkg-config version for libva is *API* version
146+ pkg_check_modules(PKG_LIBVA libva>=1.2 libva-drm>=1.2)
147+ pkg_check_modules(PKG_LIBDRM libdrm)
148+ pkg_check_modules(PKG_X11 x11)
149+ pkg_check_modules(PKG_LIBVA_X11 libva-x11>=1.10.0)
150+ if(PKG_LIBVA_FOUND)
151+ target_compile_definitions(${TARGET} PUBLIC -DLIBVA_SUPPORT)
152+ target_compile_definitions(${TARGET} PUBLIC -DLIBVA_DRM_SUPPORT)
153+ target_include_directories(${TARGET} PUBLIC ${PKG_LIBVA_INCLUDE_DIRS})
154+ else()
155+ message(WARNING "libva not found: building without libVA support")
156+ endif()
157+ if(PKG_LIBDRM_FOUND)
158+ target_include_directories(${TARGET} PUBLIC ${PKG_LIBDRM_INCLUDE_DIRS})
159+ else()
160+ message(WARNING "libva-drm not found: building without libVA DRM support")
161+ endif()
162+ if(PKG_X11_FOUND)
163+ target_compile_definitions(${TARGET} PUBLIC -DLIBVA_X11_SUPPORT)
164+ target_include_directories(${TARGET} PUBLIC ${PKG_X11_LIBRARY_DIRS})
165+ else()
166+ message(WARNING "x11 modules not found: building without libVA X11 support")
167+ endif()
168+
169+ target_link_libraries(${TARGET} ${CMAKE_DL_LIBS})
170+
171+ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
172+ set(THREADS_PREFER_PTHREAD_FLAG TRUE)
173+ find_package(Threads REQUIRED)
174+ target_link_libraries(${TARGET} Threads::Threads)
175+
176+else()
177+ target_compile_definitions(${TARGET} PUBLIC -DMFX_D3D11_SUPPORT)
178+ target_link_libraries(${TARGET} DXGI D3D11 D3D9 DXVA2)
179+endif()
65diff --git a/tools/legacy/sample_common/src/vaapi_device.cpp b/tools/legacy/sample_common/src/vaapi_device.cpp 180diff --git a/tools/legacy/sample_common/src/vaapi_device.cpp b/tools/legacy/sample_common/src/vaapi_device.cpp
66index 3f6d3ba..b034376 100644 181index 3f6d3ba..b034376 100644
67--- a/tools/legacy/sample_common/src/vaapi_device.cpp 182--- a/tools/legacy/sample_common/src/vaapi_device.cpp
@@ -350,7 +465,7 @@ index 0000000..1bbaa91
350+#endif /* LISTENER_WAYLAND_H */ 465+#endif /* LISTENER_WAYLAND_H */
351diff --git a/tools/legacy/sample_misc/wayland/include/wayland-drm-client-protocol.h b/tools/legacy/sample_misc/wayland/include/wayland-drm-client-protocol.h 466diff --git a/tools/legacy/sample_misc/wayland/include/wayland-drm-client-protocol.h b/tools/legacy/sample_misc/wayland/include/wayland-drm-client-protocol.h
352new file mode 100644 467new file mode 100644
353index 0000000..e11b35d 468index 0000000..e8f33c0
354--- /dev/null 469--- /dev/null
355+++ b/tools/legacy/sample_misc/wayland/include/wayland-drm-client-protocol.h 470+++ b/tools/legacy/sample_misc/wayland/include/wayland-drm-client-protocol.h
356@@ -0,0 +1,235 @@ 471@@ -0,0 +1,235 @@
@@ -1208,7 +1323,7 @@ index 0000000..90f582a
1208+} 1323+}
1209diff --git a/tools/legacy/sample_misc/wayland/src/wayland-drm-protocol.c b/tools/legacy/sample_misc/wayland/src/wayland-drm-protocol.c 1324diff --git a/tools/legacy/sample_misc/wayland/src/wayland-drm-protocol.c b/tools/legacy/sample_misc/wayland/src/wayland-drm-protocol.c
1210new file mode 100644 1325new file mode 100644
1211index 0000000..8e1fd50 1326index 0000000..7640883
1212--- /dev/null 1327--- /dev/null
1213+++ b/tools/legacy/sample_misc/wayland/src/wayland-drm-protocol.c 1328+++ b/tools/legacy/sample_misc/wayland/src/wayland-drm-protocol.c
1214@@ -0,0 +1,84 @@ 1329@@ -0,0 +1,84 @@
@@ -1297,5 +1412,5 @@ index 0000000..8e1fd50
1297+}; 1412+};
1298+ 1413+
1299-- 1414--
13002.7.4 14152.32.0
1301 1416
diff --git a/recipes-multimedia/onevpl/onevpl/0001-Fix-NV12-input-format-in-legacy-samples.patch b/recipes-multimedia/onevpl/onevpl/0001-Fix-NV12-input-format-in-legacy-samples.patch
deleted file mode 100644
index d1f87f30..00000000
--- a/recipes-multimedia/onevpl/onevpl/0001-Fix-NV12-input-format-in-legacy-samples.patch
+++ /dev/null
@@ -1,36 +0,0 @@
1From 4fcf0bf6e745d929cc28ae5d0a37ba730a8ed6fa Mon Sep 17 00:00:00 2001
2From: Natalia Domnina <natalia.domnina@intel.com>
3Date: Wed, 19 May 2021 12:01:43 +0300
4Subject: [PATCH] Fix NV12 input format in legacy samples
5
6Upstream-Status: Backport
7inner-source #4fcf0bf
8
9Signed-off-by: Yew, Chang Ching <chang.ching.yew@intel.com>
10---
11 tools/legacy/sample_common/src/sample_utils.cpp | 2 +-
12 1 file changed, 1 insertion(+), 1 deletion(-)
13
14diff --git a/tools/legacy/sample_common/src/sample_utils.cpp b/tools/legacy/sample_common/src/sample_utils.cpp
15index 2457a74..8c821ca 100644
16--- a/tools/legacy/sample_common/src/sample_utils.cpp
17+++ b/tools/legacy/sample_common/src/sample_utils.cpp
18@@ -401,7 +401,6 @@ mfxStatus CSmplYUVReader::LoadNextFrame(mfxFrameSurface1* pSurface) {
19 {
20 case MFX_FOURCC_I420:
21 case MFX_FOURCC_YV12:
22- case MFX_FOURCC_NV12:
23 switch (pInfo.FourCC) {
24 case MFX_FOURCC_NV12:
25
26@@ -503,6 +502,7 @@ mfxStatus CSmplYUVReader::LoadNextFrame(mfxFrameSurface1* pSurface) {
27 }
28 }
29 break;
30+ case MFX_FOURCC_NV12:
31 case MFX_FOURCC_P010:
32 case MFX_FOURCC_P210:
33 #if (MFX_VERSION >= 1031)
34--
352.32.0
36
diff --git a/recipes-multimedia/onevpl/onevpl/0001-Fix-sample_encode-i010-input.patch b/recipes-multimedia/onevpl/onevpl/0001-Fix-sample_encode-i010-input.patch
deleted file mode 100644
index 47890846..00000000
--- a/recipes-multimedia/onevpl/onevpl/0001-Fix-sample_encode-i010-input.patch
+++ /dev/null
@@ -1,62 +0,0 @@
1From ffd917e7b4dc37ff3863b43cf4821f3454944344 Mon Sep 17 00:00:00 2001
2From: Seunghyuk Park <seunghyuk.h.park@intel.com>
3Date: Mon, 31 May 2021 10:47:41 -0700
4Subject: [PATCH] Fix sample_encode i010 input
5
6Upstream-Status: Backport
7inner-source #ffd917e
8
9Signed-off-by: Yew, Chang Ching <chang.ching.yew@intel.com>
10---
11 .../legacy/sample_encode/src/pipeline_encode.cpp | 16 ++++++++++------
12 tools/legacy/sample_encode/src/sample_encode.cpp | 4 ++--
13 2 files changed, 12 insertions(+), 8 deletions(-)
14
15diff --git a/tools/legacy/sample_encode/src/pipeline_encode.cpp b/tools/legacy/sample_encode/src/pipeline_encode.cpp
16index 4aa5aef..9af4901 100644
17--- a/tools/legacy/sample_encode/src/pipeline_encode.cpp
18+++ b/tools/legacy/sample_encode/src/pipeline_encode.cpp
19@@ -1716,15 +1716,19 @@ mfxStatus CEncodingPipeline::Init(sInputParams *pParams) {
20
21 m_MVCflags = pParams->MVC_flags;
22
23- // FileReader can convert yv12->nv12 without vpp
24- m_InputFourCC =
25- (pParams->FileInputFourCC == MFX_FOURCC_I420) ? MFX_FOURCC_NV12 : pParams->FileInputFourCC;
26+ // FileReader can convert yv12->nv12 without vpp, when hw impl
27 #if (MFX_VERSION >= 2000)
28- if (pParams->bUseHWLib == true)
29- pParams->EncodeFourCC = MFX_FOURCC_NV12;
30+ if (pParams->bUseHWLib == false)
31+ m_InputFourCC = pParams->FileInputFourCC;
32 else
33- pParams->EncodeFourCC = MFX_FOURCC_I420;
34 #endif
35+ {
36+ m_InputFourCC = (pParams->FileInputFourCC == MFX_FOURCC_I420) ? MFX_FOURCC_NV12
37+ : pParams->FileInputFourCC;
38+ pParams->EncodeFourCC =
39+ (pParams->EncodeFourCC == MFX_FOURCC_I420) ? MFX_FOURCC_NV12 : pParams->EncodeFourCC;
40+ }
41+
42 m_nTimeout = pParams->nTimeout;
43
44 m_strDevicePath = pParams->strDevicePath;
45diff --git a/tools/legacy/sample_encode/src/sample_encode.cpp b/tools/legacy/sample_encode/src/sample_encode.cpp
46index 0a22eb2..74607a8 100644
47--- a/tools/legacy/sample_encode/src/sample_encode.cpp
48+++ b/tools/legacy/sample_encode/src/sample_encode.cpp
49@@ -592,8 +592,8 @@ mfxStatus ParseInputString(msdk_char* strInput[], mfxU8 nArgNum, sInputParams* p
50 }
51 #if (MFX_VERSION >= 2000)
52 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-i420"))) {
53- pParams->FileInputFourCC = MFX_FOURCC_IYUV;
54- pParams->EncodeFourCC = MFX_FOURCC_IYUV;
55+ pParams->FileInputFourCC = MFX_FOURCC_I420;
56+ pParams->EncodeFourCC = MFX_FOURCC_I420;
57 }
58 else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-i010"))) {
59 pParams->FileInputFourCC = MFX_FOURCC_I010;
60--
612.32.0
62
diff --git a/recipes-multimedia/onevpl/onevpl/0001-Fix-sample_vpp-sample_encode-alignment-issue.patch b/recipes-multimedia/onevpl/onevpl/0001-Fix-sample_vpp-sample_encode-alignment-issue.patch
deleted file mode 100644
index 05e707ec..00000000
--- a/recipes-multimedia/onevpl/onevpl/0001-Fix-sample_vpp-sample_encode-alignment-issue.patch
+++ /dev/null
@@ -1,96 +0,0 @@
1From 1b754c4bf20c33ae0e9a82197be58975da828516 Mon Sep 17 00:00:00 2001
2From: Seunghyuk Park <seunghyuk.h.park@intel.com>
3Date: Tue, 25 May 2021 13:46:00 -0700
4Subject: [PATCH] Fix sample_vpp, sample_encode alignment issue
5
6Upstream-Status: Backport
7inner-source #1b754c4b
8
9Signed-off-by: Yew, Chang Ching <chang.ching.yew@intel.com>
10---
11 .../sample_encode/src/pipeline_encode.cpp | 21 +++++++++++++++++++
12 .../sample_vpp/src/sample_vpp_utils.cpp | 9 ++++++++
13 2 files changed, 30 insertions(+)
14
15diff --git a/tools/legacy/sample_encode/src/pipeline_encode.cpp b/tools/legacy/sample_encode/src/pipeline_encode.cpp
16index 6e5c6fc..f68ed02 100644
17--- a/tools/legacy/sample_encode/src/pipeline_encode.cpp
18+++ b/tools/legacy/sample_encode/src/pipeline_encode.cpp
19@@ -594,6 +594,13 @@ mfxStatus CEncodingPipeline::InitMfxEncParams(sInputParams *pInParams) {
20 ? MSDK_ALIGN16(pInParams->nDstHeight)
21 : MSDK_ALIGN32(pInParams->nDstHeight);
22
23+#if (MFX_VERSION >= 2000)
24+ if (!pInParams->bUseHWLib) {
25+ m_mfxEncParams.mfx.FrameInfo.Width = pInParams->nDstWidth;
26+ m_mfxEncParams.mfx.FrameInfo.Height = pInParams->nDstHeight;
27+ }
28+#endif
29+
30 m_mfxEncParams.mfx.FrameInfo.CropX = 0;
31 m_mfxEncParams.mfx.FrameInfo.CropY = 0;
32 m_mfxEncParams.mfx.FrameInfo.CropW = pInParams->nDstWidth;
33@@ -855,6 +862,13 @@ mfxStatus CEncodingPipeline::InitMfxVppParams(sInputParams *pInParams) {
34 ? MSDK_ALIGN16(pInParams->nHeight)
35 : MSDK_ALIGN32(pInParams->nHeight);
36
37+#if (MFX_VERSION >= 2000)
38+ if (!pInParams->bUseHWLib) {
39+ m_mfxVppParams.vpp.In.Width = pInParams->nWidth;
40+ m_mfxVppParams.vpp.In.Height = pInParams->nHeight;
41+ }
42+#endif
43+
44 // set crops in input mfxFrameInfo for correct work of file reader
45 // VPP itself ignores crops at initialization
46 m_mfxVppParams.vpp.In.CropW = pInParams->nWidth;
47@@ -893,6 +907,13 @@ mfxStatus CEncodingPipeline::InitMfxVppParams(sInputParams *pInParams) {
48 ? MSDK_ALIGN16(pInParams->nDstHeight)
49 : MSDK_ALIGN32(pInParams->nDstHeight);
50
51+#if (MFX_VERSION >= 2000)
52+ if (!pInParams->bUseHWLib) {
53+ m_mfxVppParams.vpp.Out.Width = pInParams->nDstWidth;
54+ m_mfxVppParams.vpp.Out.Height = pInParams->nDstHeight;
55+ }
56+#endif
57+
58 // configure and attach external parameters
59 InitVppFilters();
60
61diff --git a/tools/legacy/sample_vpp/src/sample_vpp_utils.cpp b/tools/legacy/sample_vpp/src/sample_vpp_utils.cpp
62index 60b7720..ccb6cff 100644
63--- a/tools/legacy/sample_vpp/src/sample_vpp_utils.cpp
64+++ b/tools/legacy/sample_vpp/src/sample_vpp_utils.cpp
65@@ -385,12 +385,20 @@ mfxStatus InitParamsVPP(MfxVideoParamsWrapper* pParams, sInputParams* pInParams,
66 pParams->vpp.In.CropY = pInParams->frameInfoIn[paramID].CropY;
67 pParams->vpp.In.CropW = pInParams->frameInfoIn[paramID].CropW;
68 pParams->vpp.In.CropH = pInParams->frameInfoIn[paramID].CropH;
69+
70 pParams->vpp.In.Width = MSDK_ALIGN16(pInParams->frameInfoIn[paramID].nWidth);
71 pParams->vpp.In.Height =
72 (MFX_PICSTRUCT_PROGRESSIVE == pInParams->frameInfoIn[paramID].PicStruct)
73 ? MSDK_ALIGN16(pInParams->frameInfoIn[paramID].nHeight)
74 : MSDK_ALIGN32(pInParams->frameInfoIn[paramID].nHeight);
75
76+#if (MFX_VERSION >= 2000)
77+ if (MFX_IMPL_SOFTWARE == pInParams->ImpLib) {
78+ pParams->vpp.In.Width = pInParams->frameInfoIn[paramID].nWidth;
79+ pParams->vpp.In.Height = pInParams->frameInfoIn[paramID].nHeight;
80+ }
81+#endif
82+
83 // width must be a multiple of 16
84 // height must be a multiple of 16 in case of frame picture and
85 // a multiple of 32 in case of field picture
86@@ -441,6 +449,7 @@ mfxStatus InitParamsVPP(MfxVideoParamsWrapper* pParams, sInputParams* pInParams,
87 (MFX_PICSTRUCT_PROGRESSIVE == pInParams->frameInfoOut[paramID].PicStruct)
88 ? MSDK_ALIGN16(pInParams->frameInfoOut[paramID].nHeight)
89 : MSDK_ALIGN32(pInParams->frameInfoOut[paramID].nHeight);
90+
91 #if (MFX_VERSION >= 2000)
92 if (MFX_IMPL_SOFTWARE == pInParams->ImpLib) {
93 pParams->vpp.Out.Width = pInParams->frameInfoOut[paramID].nWidth;
94--
952.32.0
96
diff --git a/recipes-multimedia/onevpl/onevpl/0001-Remove-duplicate-MFXVideoDECODE_VPP-from-samples.patch b/recipes-multimedia/onevpl/onevpl/0001-Remove-duplicate-MFXVideoDECODE_VPP-from-samples.patch
deleted file mode 100644
index 8470e418..00000000
--- a/recipes-multimedia/onevpl/onevpl/0001-Remove-duplicate-MFXVideoDECODE_VPP-from-samples.patch
+++ /dev/null
@@ -1,62 +0,0 @@
1From 0b74a78b99822bce5ea197513dd5683f41badd7b Mon Sep 17 00:00:00 2001
2From: Jon Recker <jon.recker@intel.com>
3Date: Mon, 29 Mar 2021 09:59:03 -0700
4Subject: [PATCH] Remove duplicate MFXVideoDECODE_VPP from samples
5
6Upstream-Status: Submitted
7---
8 .../sample_common/include/sample_vpl_common.h | 38 -------------------
9 1 file changed, 38 deletions(-)
10
11diff --git a/tools/legacy/sample_common/include/sample_vpl_common.h b/tools/legacy/sample_common/include/sample_vpl_common.h
12index 4450b7f..016955a 100644
13--- a/tools/legacy/sample_common/include/sample_vpl_common.h
14+++ b/tools/legacy/sample_common/include/sample_vpl_common.h
15@@ -49,44 +49,6 @@ public:
16 }
17 };
18
19-class MFXVideoDECODE_VPP {
20-public:
21- explicit MFXVideoDECODE_VPP(mfxSession session) {
22- m_session = session;
23- }
24- virtual ~MFXVideoDECODE_VPP(void) {}
25-
26- virtual mfxStatus Init(mfxVideoParam *decode_par,
27- mfxVideoChannelParam **vpp_par_array,
28- mfxU32 num_vpp_par) {
29- return MFXVideoDECODE_VPP_Init(m_session, decode_par, vpp_par_array, num_vpp_par);
30- }
31-
32- virtual mfxStatus DecodeFrameAsync(mfxBitstream *bs,
33- mfxU32 *skip_channels,
34- mfxU32 num_skip_channels,
35- mfxSurfaceArray **surf_array_out) {
36- return MFXVideoDECODE_VPP_DecodeFrameAsync(m_session,
37- bs,
38- skip_channels,
39- num_skip_channels,
40- surf_array_out);
41- }
42-
43- virtual mfxStatus Reset(mfxVideoParam *decode_par,
44- mfxVideoChannelParam **vpp_par_array,
45- mfxU32 num_vpp_par) {
46- return MFXVideoDECODE_VPP_Reset(m_session, decode_par, vpp_par_array, num_vpp_par);
47- }
48-
49- virtual mfxStatus GetChannelParam(mfxVideoChannelParam *par, mfxU32 channel_id) {
50- return MFXVideoDECODE_VPP_GetChannelParam(m_session, par, channel_id);
51- }
52-
53-protected:
54- mfxSession m_session; // (mfxSession) handle to the owning session
55-};
56-
57 #endif
58
59 #endif //__SAMPLE_VPL_COMMON_H__
60--
612.31.1
62
diff --git a/recipes-multimedia/onevpl/onevpl/0001-Update-headers-to-oneAPI-spec-v2.3-e170992.patch b/recipes-multimedia/onevpl/onevpl/0001-Update-headers-to-oneAPI-spec-v2.3-e170992.patch
deleted file mode 100644
index 030b395c..00000000
--- a/recipes-multimedia/onevpl/onevpl/0001-Update-headers-to-oneAPI-spec-v2.3-e170992.patch
+++ /dev/null
@@ -1,741 +0,0 @@
1From bb2f6199088879568e31f91f6d9b7aa737c5aa04 Mon Sep 17 00:00:00 2001
2From: Jon Recker <jon.recker@intel.com>
3Date: Wed, 9 Jun 2021 10:39:10 +0800
4Subject: [PATCH] Update headers to oneAPI-spec v2.3 (e170992)
5
6Upstream-Status: Submitted
7---
8 api/vpl/mfx.h | 25 ++++++++
9 api/vpl/mfxcommon.h | 9 ++-
10 api/vpl/mfxdefs.h | 86 ++++++++++++-------------
11 api/vpl/mfxdispatcher.h | 4 +-
12 api/vpl/mfximplcaps.h | 4 +-
13 api/vpl/mfxsession.h | 11 +++-
14 api/vpl/mfxstructures.h | 137 ++++++++++++++++++++++------------------
15 api/vpl/mfxvideo++.h | 76 ++++++++++++++++++++++
16 8 files changed, 238 insertions(+), 114 deletions(-)
17 create mode 100644 api/vpl/mfx.h
18
19diff --git a/api/vpl/mfx.h b/api/vpl/mfx.h
20new file mode 100644
21index 0000000..32fc50b
22--- /dev/null
23+++ b/api/vpl/mfx.h
24@@ -0,0 +1,25 @@
25+/*############################################################################
26+ # Copyright (C) 2021 Intel Corporation
27+ #
28+ # SPDX-License-Identifier: MIT
29+ ############################################################################*/
30+
31+#ifndef __MFX_H__
32+#define __MFX_H__
33+
34+#include "mfxdefs.h"
35+#include "mfxcommon.h"
36+#include "mfxstructures.h"
37+#include "mfxdispatcher.h"
38+#include "mfximplcaps.h"
39+#include "mfxsession.h"
40+#include "mfxvideo.h"
41+#include "mfxadapter.h"
42+
43+#include "mfxbrc.h"
44+#include "mfxmvc.h"
45+#include "mfxpcp.h"
46+#include "mfxvp8.h"
47+#include "mfxjpeg.h"
48+
49+#endif /* __MFXDEFS_H__ */
50diff --git a/api/vpl/mfxcommon.h b/api/vpl/mfxcommon.h
51index 90a2f3d..9884aa4 100644
52--- a/api/vpl/mfxcommon.h
53+++ b/api/vpl/mfxcommon.h
54@@ -172,7 +172,7 @@ typedef struct {
55 } mfxExtThreadsParam;
56 MFX_PACK_END()
57
58-/*! The PlatformCodeName enumerator itemizes microarchitecture code names for the Legacy mode.
59+/*! The PlatformCodeName enumerator itemizes product code names for platforms.
60 For details about Intel code names, see ark.intel.com. */
61 enum {
62 MFX_PLATFORM_UNKNOWN = 0, /*!< Unknown platform. */
63@@ -192,6 +192,10 @@ enum {
64 MFX_PLATFORM_JASPERLAKE = 32, /*!< Code name Jasper Lake. */
65 MFX_PLATFORM_ELKHARTLAKE = 33, /*!< Code name Elkhart Lake. */
66 MFX_PLATFORM_TIGERLAKE = 40, /*!< Code name Tiger Lake. */
67+ MFX_PLATFORM_ROCKETLAKE = 42, /*!< Code name Rocket Lake. */
68+ MFX_PLATFORM_ALDERLAKE_S = 43, /*!< Code name Alder Lake S. */
69+ MFX_PLATFORM_ALDERLAKE_P = 44, /*!< Code name Alder Lake P. */
70+ MFX_PLATFORM_ARCTICSOUND_P = 45, /*!< Code name Arctic Sound P. */
71 MFX_PLATFORM_KEEMBAY = 50, /*!< Code name Keem Bay. */
72 };
73
74@@ -370,7 +374,6 @@ typedef enum {
75 MFX_ACCEL_MODE_VIA_HDDLUNITE = 0x0500, /*!< Hardware acceleration goes through the HDDL* Unite*. */
76 } mfxAccelerationMode;
77
78-
79 #define MFX_ACCELERATIONMODESCRIPTION_VERSION MFX_STRUCT_VERSION(1, 0)
80
81 MFX_PACK_BEGIN_STRUCT_W_PTR()
82@@ -438,7 +441,7 @@ typedef struct {
83 mfxU16 reserved[3]; /*!< Reserved for future use. */
84 mfxU16 NumExtParam; /*!< The number of extra configuration structures attached to this structure. */
85 mfxExtBuffer **ExtParam; /*!< Points to an array of pointers to the extra configuration structures; see the ExtendedBufferID enumerator for a list of extended configurations. */
86- mfxU32 VendorImplID; /*!< Vendor specific number with given implementation ID. Represents the same filed from mfxImplDescription. */
87+ mfxU32 VendorImplID; /*!< Vendor specific number with given implementation ID. Represents the same field from mfxImplDescription. */
88 mfxU32 reserved2[3]; /*!< Reserved for future use. */
89 } mfxInitializationParam;
90 MFX_PACK_END()
91diff --git a/api/vpl/mfxdefs.h b/api/vpl/mfxdefs.h
92index 14cece0..dfd9f98 100644
93--- a/api/vpl/mfxdefs.h
94+++ b/api/vpl/mfxdefs.h
95@@ -8,7 +8,7 @@
96 #define __MFXDEFS_H__
97
98 #define MFX_VERSION_MAJOR 2
99-#define MFX_VERSION_MINOR 2
100+#define MFX_VERSION_MINOR 3
101
102 // MFX_VERSION - version of API that 'assumed' by build may be provided externally
103 // if it omitted then latest stable API derived from Major.Minor is assumed
104@@ -27,7 +27,7 @@
105 /*! The corresponding version of the Intel(r) Media SDK legacy API that is used as a basis
106 for the current API. */
107
108-#define MFX_LEGACY_VERSION 1034
109+#define MFX_LEGACY_VERSION 1035
110
111
112 #ifdef __cplusplus
113@@ -90,47 +90,47 @@ extern "C"
114 #endif
115
116 #ifndef MFX_DEPRECATED_OFF
117- #if defined(__cplusplus) && __cplusplus >= 201402L
118- #define MFX_DEPRECATED [[deprecated]]
119- #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg [[deprecated]]
120- #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
121- #elif defined(__clang__)
122- #define MFX_DEPRECATED __attribute__((deprecated))
123- #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg __attribute__((deprecated))
124- #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
125- #elif defined(__INTEL_COMPILER)
126- #if (defined(_WIN32) || defined(_WIN64))
127- #define MFX_DEPRECATED __declspec(deprecated)
128- #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
129- #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg) __pragma(deprecated(arg))
130- #elif defined(__linux__)
131- #define MFX_DEPRECATED __attribute__((deprecated))
132- #if defined(__cplusplus)
133- #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg __attribute__((deprecated))
134- #else
135- #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
136- #endif
137- #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
138- #endif
139- #elif defined(_MSC_VER) && _MSC_VER > 1200 // VS 6 doesn't support deprecation
140- #define MFX_DEPRECATED __declspec(deprecated)
141- #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
142- #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg) __pragma(deprecated(arg))
143- #elif defined(__GNUC__)
144- #define MFX_DEPRECATED __attribute__((deprecated))
145- #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg __attribute__((deprecated))
146- #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
147- #else
148- #define MFX_DEPRECATED
149- #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
150- #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
151- #endif
152-#else
153- #define MFX_DEPRECATED
154- #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
155- #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
156-#endif
157-
158+ #if defined(__cplusplus) && __cplusplus >= 201402L
159+ #define MFX_DEPRECATED [[deprecated]]
160+ #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg [[deprecated]]
161+ #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
162+ #elif defined(__clang__)
163+ #define MFX_DEPRECATED __attribute__((deprecated))
164+ #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg __attribute__((deprecated))
165+ #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
166+ #elif defined(__INTEL_COMPILER)
167+ #if (defined(_WIN32) || defined(_WIN64))
168+ #define MFX_DEPRECATED __declspec(deprecated)
169+ #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
170+ #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg) __pragma(deprecated(arg))
171+ #elif defined(__linux__)
172+ #define MFX_DEPRECATED __attribute__((deprecated))
173+ #if defined(__cplusplus)
174+ #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg __attribute__((deprecated))
175+ #else
176+ #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
177+ #endif
178+ #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
179+ #endif
180+ #elif defined(_MSC_VER) && _MSC_VER > 1200 // VS 6 doesn't support deprecation
181+ #define MFX_DEPRECATED __declspec(deprecated)
182+ #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
183+ #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg) __pragma(deprecated(arg))
184+ #elif defined(__GNUC__)
185+ #define MFX_DEPRECATED __attribute__((deprecated))
186+ #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg __attribute__((deprecated))
187+ #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
188+ #else
189+ #define MFX_DEPRECATED
190+ #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
191+ #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
192+ #endif
193+ #else
194+ #define MFX_DEPRECATED
195+ #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
196+ #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg)
197+ #endif
198+
199 typedef unsigned char mfxU8; /*!< Unsigned integer, 8 bit type. */
200 typedef char mfxI8; /*!< Signed integer, 8 bit type. */
201 typedef short mfxI16; /*!< Signed integer, 16 bit type. */
202diff --git a/api/vpl/mfxdispatcher.h b/api/vpl/mfxdispatcher.h
203index 8db716b..86ecea3 100644
204--- a/api/vpl/mfxdispatcher.h
205+++ b/api/vpl/mfxdispatcher.h
206@@ -1,5 +1,5 @@
207 /*############################################################################
208- # Copyright (C) Intel Corporation
209+ # Copyright (C) 2020 Intel Corporation
210 #
211 # SPDX-License-Identifier: MIT
212 ############################################################################*/
213@@ -193,7 +193,7 @@ mfxStatus MFX_CDECL MFXCreateSession(mfxLoader loader, mfxU32 i, mfxSession* ses
214
215 /*!
216 @brief
217- Destroys handle allocated by the MFXQueryImplsCapabilities function.
218+ Destroys handle allocated by the MFXEnumImplementations function.
219
220 @param[in] loader Loader handle.
221 @param[in] hdl Handle to destroy. Can be equal to NULL.
222diff --git a/api/vpl/mfximplcaps.h b/api/vpl/mfximplcaps.h
223index 16851d0..514a1c4 100644
224--- a/api/vpl/mfximplcaps.h
225+++ b/api/vpl/mfximplcaps.h
226@@ -1,5 +1,5 @@
227 /*############################################################################
228- # Copyright (C) Intel Corporation
229+ # Copyright (C) 2020 Intel Corporation
230 #
231 # SPDX-License-Identifier: MIT
232 ############################################################################*/
233@@ -33,7 +33,7 @@ mfxHDL* MFX_CDECL MFXQueryImplsDescription(mfxImplCapsDeliveryFormat format, mfx
234
235 /*!
236 @brief
237- Destroys the handle allocated by the MFXQueryImplsCapabilities function.
238+ Destroys the handle allocated by the MFXQueryImplsDescription function.
239 Implementation must remember which handles are released. Once the last handle is released, this function must release memory
240 allocated for the array of handles.
241
242diff --git a/api/vpl/mfxsession.h b/api/vpl/mfxsession.h
243index e9c7127..7e2493a 100644
244--- a/api/vpl/mfxsession.h
245+++ b/api/vpl/mfxsession.h
246@@ -49,6 +49,9 @@ typedef struct _mfxSession *mfxSession;
247 MFX_ERR_UNSUPPORTED The function cannot find the desired legacy Intel(r) Media SDK implementation or version.
248
249 @since This function is available since API version 1.0.
250+
251+ @deprecated Deprecated in API version 2.3. Use MFXLoad and MFXCreateSession to initialize the session.
252+ Use MFX_DEPRECATED_OFF macro to turn off the deprecation message visualization.
253 */
254 MFX_DEPRECATED mfxStatus MFX_CDECL MFXInit(mfxIMPL impl, mfxVersion *ver, mfxSession *session);
255
256@@ -56,8 +59,7 @@ MFX_DEPRECATED mfxStatus MFX_CDECL MFXInit(mfxIMPL impl, mfxVersion *ver, mfxSes
257 @brief
258 Creates and initializes a session in the legacy mode for compatibility with Intel(r) Media SDK applications.
259 This function is deprecated starting from API version 2.0, applications must use MFXLoad with mfxCreateSession
260- to select the implementation and initialize the session.
261-
262+ to select the implementation and initialize the session.
263
264 Call this function before calling any other API functions.
265 If the desired implementation specified by ``par`` is MFX_IMPL_AUTO, the function will search for
266@@ -72,7 +74,7 @@ MFX_DEPRECATED mfxStatus MFX_CDECL MFXInit(mfxIMPL impl, mfxVersion *ver, mfxSes
267 For example, if an application uses only H.264 decoding as described in API v1.0, the application should initialize the library with API v1.0. This ensures backward compatibility.
268
269 The argument ``par.ExternalThreads`` specifies threading mode. Value 0 means that the implementation should create and
270- handle work threads internally (this is essentially the equivalent of the regular MFXInit). I
271+ handle work threads internally (this is essentially the equivalent of the regular MFXInit).
272
273 @param[in] par mfxInitParam structure that indicates the desired implementation, minimum library version and desired threading mode.
274 @param[out] session Pointer to the session handle.
275@@ -82,6 +84,9 @@ MFX_DEPRECATED mfxStatus MFX_CDECL MFXInit(mfxIMPL impl, mfxVersion *ver, mfxSes
276 MFX_ERR_UNSUPPORTED The function cannot find the desired implementation or version.
277
278 @since This function is available since API version 1.14.
279+
280+ @deprecated Deprecated in API version 2.3. Use MFXLoad and MFXCreateSession to initialize the session.
281+ Use MFX_DEPRECATED_OFF macro to turn off the deprecation message visualization.
282 */
283 MFX_DEPRECATED mfxStatus MFX_CDECL MFXInitEx(mfxInitParam par, mfxSession *session);
284
285diff --git a/api/vpl/mfxstructures.h b/api/vpl/mfxstructures.h
286index f285979..94d8d25 100644
287--- a/api/vpl/mfxstructures.h
288+++ b/api/vpl/mfxstructures.h
289@@ -40,13 +40,13 @@ MFX_PACK_BEGIN_USUAL_STRUCT()
290 /*! Specifies properties of video frames. See also "Configuration Parameter Constraints" chapter. */
291 typedef struct {
292 mfxU32 reserved[4]; /*!< Reserved for future use. */
293- /*! The unique ID of each VPP channel set by application. It's required that during Init/Reset application fills ChannelId for
294- each mfxVideoChannelParam provided by the application and the SDK sets it back to the correspondent
295- mfxSurfaceArray::mfxFrameSurface1 to distinguish different channels. It's expected that surfaces for some channels might be
296- returned with some delay so application has to use mfxFrameInfo::ChannelId to distinguish what returned surface belongs to
297- what VPP channel. Decoder's initialization parameters are always sent through channel with mfxFrameInfo::ChannelId equals to
298+ /*! The unique ID of each VPP channel set by application. It's required that during Init/Reset application fills ChannelId for
299+ each mfxVideoChannelParam provided by the application and the SDK sets it back to the correspondent
300+ mfxSurfaceArray::mfxFrameSurface1 to distinguish different channels. It's expected that surfaces for some channels might be
301+ returned with some delay so application has to use mfxFrameInfo::ChannelId to distinguish what returned surface belongs to
302+ what VPP channel. Decoder's initialization parameters are always sent through channel with mfxFrameInfo::ChannelId equals to
303 zero. It's allowed to skip setting of decoder's parameters for simplified decoding procedure */
304- mfxU16 ChannelId;
305+ mfxU16 ChannelId;
306 /*! Number of bits used to represent luma samples.
307 @note Not all codecs and implementations support this value. Use the Query API function to check if this feature is supported. */
308 mfxU16 BitDepthLuma;
309@@ -552,22 +552,22 @@ typedef struct mfxFrameSurfaceInterface {
310 MFX_ERR_UNKNOWN Any internal error.
311 */
312 mfxStatus (MFX_CDECL *Synchronize)(mfxFrameSurface1* surface, mfxU32 wait);
313-
314+
315 /*! @brief
316- The library calls the function after complete of associated video operation
317- notifying the application that frame surface is ready.
318-
319- @attention This is callback function and intended to be called by
320- the library only.
321-
322- It is expected that the function is low-intrusive designed otherwise it may
323- impact performance.
324+ The library calls the function after complete of associated video operation
325+ notifying the application that frame surface is ready.
326+
327+ @attention This is callback function and intended to be called by
328+ the library only.
329+
330+ It is expected that the function is low-intrusive designed otherwise it may
331+ impact performance.
332
333 @param[in] sts The status of completed operation.
334
335 */
336 void (MFX_CDECL *OnComplete)(mfxStatus sts);
337-
338+
339 mfxHDL reserved2[3];
340 } mfxFrameSurfaceInterface;
341 MFX_PACK_END()
342@@ -719,22 +719,22 @@ typedef struct {
343 return MFX_ERR_REALLOC_SURFACE. See the CodingOptionValue enumerator for values of this option. Use the Query API
344 function to check if this feature is supported. */
345 mfxU16 EnableReallocRequest;
346- /*! Special parameter for AV1 decoder. Indicates presence/absence of film grain parameters in bitstream.
347- Also controls decoding behavior for streams with film grain parameters. MFXVideoDECODE_DecodeHeader returns nonzero FilmGrain
348+ /*! Special parameter for AV1 decoder. Indicates presence/absence of film grain parameters in bitstream.
349+ Also controls decoding behavior for streams with film grain parameters. MFXVideoDECODE_DecodeHeader returns nonzero FilmGrain
350 for streams with film grain parameters and zero for streams w/o them. Decoding with film grain requires additional output surfaces.
351 If FilmGrain` is non-zero then MFXVideoDECODE_QueryIOSurf will request more surfaces in case of external allocated video memory at decoder output.
352 FilmGrain is passed to MFXVideoDECODE_Init function to control decoding operation for AV1 streams with film grain parameters.
353- If FilmGrain is nonzero decoding of each frame require two output surfaces (one for reconstructed frame and one for output frame with film grain applied).
354+ If FilmGrain is nonzero decoding of each frame require two output surfaces (one for reconstructed frame and one for output frame with film grain applied).
355 The decoder returns MFX_ERR_MORE_SURFACE from MFXVideoDECODE_DecodeFrameAsync if it has insufficient output surfaces to decode frame.
356- Application can forcibly disable the feature passing zero value of `FilmGrain` to `MFXVideoDECODE_Init`.
357- In this case the decoder will output reconstructed frames w/o film grain applied.
358+ Application can forcibly disable the feature passing zero value of `FilmGrain` to `MFXVideoDECODE_Init`.
359+ In this case the decoder will output reconstructed frames w/o film grain applied.
360 Application can retrieve film grain parameters for a frame by attaching extended buffer mfxExtAV1FilmGrainParam to mfxFrameSurface1.
361 If stream has no film grain parameters `FilmGrain` passed to `MFXVideoDECODE_Init` is ignored by the decoder. */
362 mfxU16 FilmGrain;
363 /*! If not zero, it forces SDK to attempt to decode bitstream even if a decoder may not support all features associated with given CodecLevel. Decoder may produce visual artifacts. Only AVC decoder supports this field. */
364 mfxU16 IgnoreLevelConstrain;
365 /*! This flag is used to disable output of main decoding channel. When it's ON SkipOutput = MFX_CODINGOPTION_ON decoder outputs only video processed channels. For pure decode this flag should be always disabled. */
366- mfxU16 SkipOutput;
367+ mfxU16 SkipOutput;
368 mfxU16 reserved2[4];
369 };
370 struct { /* JPEG Decoding Options */
371@@ -898,7 +898,7 @@ enum {
372 MFX_LEVEL_AVC_6 =60,
373 MFX_LEVEL_AVC_61 =61,
374 MFX_LEVEL_AVC_62 =62,
375- /*! @} */
376+ /*! @} */
377
378 /*! @{ */
379 /* MPEG2 Profiles. */
380@@ -1484,8 +1484,7 @@ typedef struct {
381 mfxU16 WinBRCSize;
382
383 /*! When rate control method is MFX_RATECONTROL_QVBR, this parameter specifies quality factor.
384-Values are in the 1 to 51 range,
385- where 1 corresponds to the best quality.
386+ Values are in the 1 to 51 range, where 1 corresponds to the best quality.
387 */
388 mfxU16 QVBRQuality;
389 /*!
390@@ -1678,6 +1677,7 @@ Values are in the 1 to 51 range,
391 This parameter is valid only during initialization.
392 */
393 mfxU16 AdaptiveCQM;
394+
395 mfxU16 reserved[162];
396 } mfxExtCodingOption3;
397 MFX_PACK_END()
398@@ -2024,13 +2024,16 @@ enum {
399 See the mfxExtInCrops structure for details.
400 */
401 MFX_EXTBUFF_CROPS = MFX_MAKEFOURCC('C', 'R', 'O', 'P'),
402-
403+
404 /*!
405 See the mfxExtAV1FilmGrainParam structure for more details.
406 */
407- MFX_EXTBUFF_AV1_FILM_GRAIN_PARAM = MFX_MAKEFOURCC('A','1','F','G')
408+ MFX_EXTBUFF_AV1_FILM_GRAIN_PARAM = MFX_MAKEFOURCC('A','1','F','G'),
409
410-
411+ /*!
412+ See the mfxExtHyperModeParam structure for more details.
413+ */
414+ MFX_EXTBUFF_HYPER_MODE_PARAM = MFX_MAKEFOURCC('H', 'Y', 'P', 'M')
415 };
416
417 /* VPP Conf: Do not use certain algorithms */
418@@ -2488,10 +2491,10 @@ MFX_PACK_BEGIN_STRUCT_W_PTR()
419 Each filter may be included in the pipeline in one of two different ways:
420
421 @li Adding a filter ID to this structure. In this method,
422- the default filter parameters are used.
423-
424+ the default filter parameters are used.
425+
426 @li Attaching a filter configuration structure directly to the mfxVideoParam structure.
427- In this method, adding filter ID to the mfxExtVPPDoUse structure is optional.
428+ In this method, adding filter ID to the mfxExtVPPDoUse structure is optional.
429
430 See Table “Configurable VPP filters” for complete list of
431 configurable filters, their IDs, and configuration structures.
432@@ -2590,7 +2593,7 @@ MFX_PACK_BEGIN_USUAL_STRUCT()
433
434 On some platforms this filter is not supported. To query its support, the application should use the same approach that it uses
435 to configure VPP filters: adding the filter ID to the mfxExtVPPDoUse structure or by attaching the mfxExtVPPImageStab structure
436- directly to the mfxVideoParam structure and calling the MFXVideoVPP_Query function.
437+ directly to the mfxVideoParam structure and calling the MFXVideoVPP_Query function.
438
439 If this filter is supported, the function returns a MFX_ERR_NONE
440 status and copies the content of the input structure to the output structure. If the filter is not supported, the function returns MFX_WRN_FILTER_SKIPPED, removes the
441@@ -2617,14 +2620,14 @@ enum {
442
443 MFX_PACK_BEGIN_USUAL_STRUCT()
444 /*!
445- Configures the HDR SEI message.
446+ Configures the HDR SEI message.
447
448 If the application attaches this structure to the mfxEncodeCtrl structure
449- at runtime, the encoder inserts the HDR SEI message for the current frame and ignores InsertPayloadToggle.
450+ at runtime, the encoder inserts the HDR SEI message for the current frame and ignores InsertPayloadToggle.
451
452 If the application attaches this
453 structure to the mfxVideoParam structure during initialization or reset, the encoder inserts the HDR SEI message based on InsertPayloadToggle.
454-
455+
456 Field semantics are defined in ITU-T* H.265 Annex D.
457 */
458 typedef struct {
459@@ -2633,10 +2636,10 @@ typedef struct {
460
461 mfxU16 InsertPayloadToggle; /*!< InsertHDRPayload enumerator value. */
462 mfxU16 DisplayPrimariesX[3]; /*!< Color primaries for a video source in increments of 0.00002. Consist of RGB x coordinates and
463- define how to convert colors from RGB color space to CIE XYZ color space. Fields range is
464+ define how to convert colors from RGB color space to CIE XYZ color space. Fields range is
465 0 to 50000. */
466 mfxU16 DisplayPrimariesY[3]; /*!< Color primaries for a video source in increments of 0.00002. Consists of RGB y coordinates and
467- defines how to convert colors from RGB color space to CIE XYZ color space. Field range is
468+ defines how to convert colors from RGB color space to CIE XYZ color space. Field range is
469 0 to 50000. */
470 mfxU16 WhitePointX; /*!< White point X coordinate. */
471 mfxU16 WhitePointY; /*!< White point Y coordinate. */
472@@ -2649,14 +2652,14 @@ MFX_PACK_END()
473
474 MFX_PACK_BEGIN_USUAL_STRUCT()
475 /*!
476- Configures the HDR SEI message.
477+ Configures the HDR SEI message.
478
479 If the application attaches this structure to the mfxEncodeCtrl
480- structure at runtime, the encoder inserts the HDR SEI message for the current frame and ignores InsertPayloadToggle.
481+ structure at runtime, the encoder inserts the HDR SEI message for the current frame and ignores InsertPayloadToggle.
482
483 If the application
484 attaches this structure to the mfxVideoParam structure during initialization or reset, the encoder inserts the HDR SEI message based on
485- InsertPayloadToggle.
486+ InsertPayloadToggle.
487
488 Field semantics are defined in ITU-T* H.265 Annex D.
489 */
490@@ -3659,12 +3662,8 @@ enum {
491 MFX_SCALING_MODE_DEFAULT = 0, /*!< Default scaling mode. The library selects the most appropriate scaling method. */
492 MFX_SCALING_MODE_LOWPOWER = 1, /*!< Low power scaling mode which is applicable for library implementations.
493 The exact scaling algorithm is defined by the library. */
494- MFX_SCALING_MODE_QUALITY = 2, /*!< The best quality scaling mode. */
495-
496-
497+ MFX_SCALING_MODE_QUALITY = 2, /*!< The best quality scaling mode. */
498 MFX_SCALING_MODE_VENDOR = 1000, /*!< The enumeration to separate common scaling controls above and vendor specific. */
499-
500-
501 MFX_SCALING_MODE_INTEL_GEN_COMPUTE = MFX_SCALING_MODE_VENDOR + 1, /*! The mode to run scaling operation on Execution Units (EUs). */
502 MFX_SCALING_MODE_INTEL_GEN_VDBOX = MFX_SCALING_MODE_VENDOR + 2, /*! The special optimization mode where scaling operation running on SFC (Scaler & Format Converter) is coupled with VDBOX (also known as Multi-Format Codec fixed-function engine). This mode is applicable for DECODE_VPP domain functions. */
503 MFX_SCALING_MODE_INTEL_GEN_VEBOX = MFX_SCALING_MODE_VENDOR + 3 /*! The special optimization mode where scaling operation running on SFC is coupled with VEBOX (HW video processing pipe). */
504@@ -4040,14 +4039,14 @@ MFX_PACK_BEGIN_USUAL_STRUCT()
505 */
506 typedef struct {
507 mfxExtBuffer Header; /*!< Extension buffer header. Header.BufferId must be equal to MFX_EXTBUFF_VPP_MCTF. */
508- mfxU16 FilterStrength; /*!< Value in range of 0 to 20 (inclusive) to indicate the filter strength of MCTF.
509+ mfxU16 FilterStrength; /*!< Value in range of 0 to 20 (inclusive) to indicate the filter strength of MCTF.
510
511 The strength of the MCTF process controls the degree of possible change of pixel values eligible for MCTF - the greater the strength value, the larger the change. It is a dimensionless quantity - values in the range of 1 to 20 inclusively imply strength; value 0 stands for AUTO mode and is
512 valid during initialization or reset only
513
514 If an invalid value is given, it is fixed to the default value of 0.
515 If the field value is in the range of 1 to 20 inclusive, MCTF operates in fixed-strength mode with the given strength of MCTF process.
516-
517+
518 At runtime, values of 0 and greater than 20 are ignored. */
519 mfxU16 reserved[27];
520 } mfxExtVppMctf;
521@@ -4160,7 +4159,7 @@ typedef struct {
522 } mfxExtDeviceAffinityMask;
523 MFX_PACK_END()
524
525-/*! The FilmGrainFlags enumerator itemizes flags in AV1 film grain parameters.
526+/*! The FilmGrainFlags enumerator itemizes flags in AV1 film grain parameters.
527 The flags are equivalent to respective syntax elements from film_grain_params() section of uncompressed header. */
528 enum {
529 MFX_FILM_GRAIN_NO = 0, /*!< Film grain isn't added to this frame. */
530@@ -4196,7 +4195,7 @@ typedef struct {
531 mfxAV1FilmGrainPoint PointCb[10]; /*!< The array of points for Cb component. */
532 mfxAV1FilmGrainPoint PointCr[10]; /*!< The array of points for Cr component. */
533
534- mfxU8 GrainScalingMinus8; /*!< The shift – 8 applied to the values of the chroma component. The grain_scaling_minus_8 can take values of 0..3 and
535+ mfxU8 GrainScalingMinus8; /*!< The shift – 8 applied to the values of the chroma component. The grain_scaling_minus_8 can take values of 0..3 and
536 determines the range and quantization step of the standard deviation of film grain.*/
537 mfxU8 ArCoeffLag; /*!< The number of auto-regressive coefficients for luma and chroma.*/
538
539@@ -4204,8 +4203,8 @@ typedef struct {
540 mfxU8 ArCoeffsCbPlus128[25]; /*!< Auto-regressive coefficients used for the Cb plane. */
541 mfxU8 ArCoeffsCrPlus128[25]; /*!< The number of points for the piece-wise linear scaling function of the Cr component.*/
542
543- mfxU8 ArCoeffShiftMinus6; /*!< The range of the auto-regressive coefficients.
544- Values of 0, 1, 2, and 3 correspond to the ranges for auto-regressive coefficients of
545+ mfxU8 ArCoeffShiftMinus6; /*!< The range of the auto-regressive coefficients.
546+ Values of 0, 1, 2, and 3 correspond to the ranges for auto-regressive coefficients of
547 [-2, 2), [-1, 1), [-0.5, 0.5) and [-0.25, 0.25) respectively.*/
548 mfxU8 GrainScaleShift; /*!< Downscaling factor of the grain synthesis process for the Gaussian random numbers .*/
549
550@@ -4229,8 +4228,8 @@ MFX_PACK_BEGIN_STRUCT_W_PTR()
551 typedef struct mfxSurfaceArray
552 {
553 mfxHDL Context; /*!< The context of the memory interface. User should not touch (change, set, null) this pointer. */
554- mfxStructVersion Version; /*!< The version of the structure. */
555- mfxU16 reserved[3];
556+ mfxStructVersion Version; /*!< The version of the structure. */
557+ mfxU16 reserved[3];
558 /*! @brief
559 Increments the internal reference counter of the surface. The surface is not destroyed until the surface is released using the (*Release) function. (*AddRef) should be used each time a new link to the surface is created (for example, copy structure) for proper surface management.
560
561@@ -4242,11 +4241,11 @@ typedef struct mfxSurfaceArray
562 MFX_ERR_INVALID_HANDLE If mfxSurfaceArray->Context is invalid (for example NULL). \n
563 MFX_ERR_UNKNOWN Any internal error.
564
565- */
566- mfxStatus (*AddRef)(struct mfxSurfaceArray* surface_array);
567+ */
568+ mfxStatus (*AddRef)(struct mfxSurfaceArray* surface_array);
569 /*! @brief
570- Decrements the internal reference counter of the surface. (*Release) should be called after using the (*AddRef) function to add a
571- surface or when allocation logic requires it.
572+ Decrements the internal reference counter of the surface. (*Release) should be called after using the (*AddRef) function to add a
573+ surface or when allocation logic requires it.
574
575 @param[in] surface_array Valid mfxSurfaceArray.
576
577@@ -4257,7 +4256,7 @@ typedef struct mfxSurfaceArray
578 MFX_ERR_UNDEFINED_BEHAVIOR If Reference Counter of surface is zero before call. \n
579 MFX_ERR_UNKNOWN Any internal error.
580 */
581- mfxStatus (*Release)(struct mfxSurfaceArray* surface_array);
582+ mfxStatus (*Release)(struct mfxSurfaceArray* surface_array);
583
584 /*! @brief
585 Returns current reference counter of mfxSurfaceArray structure.
586@@ -4270,10 +4269,10 @@ typedef struct mfxSurfaceArray
587 MFX_ERR_NULL_PTR If surface or counter is NULL. \n
588 MFX_ERR_INVALID_HANDLE If mfxSurfaceArray->Context is invalid (for example NULL). \n
589 MFX_ERR_UNKNOWN Any internal error.
590- */
591+ */
592 mfxStatus (*GetRefCounter)(struct mfxSurfaceArray* surface_array, mfxU32* counter);
593
594- mfxFrameSurface1** Surfaces; /*!< The array of pointers to mfxFrameSurface1. mfxFrameSurface1 surfaces are allocated by the same
595+ mfxFrameSurface1** Surfaces; /*!< The array of pointers to mfxFrameSurface1. mfxFrameSurface1 surfaces are allocated by the same
596 agent who allocates mfxSurfaceArray. */
597 mfxU32 NumSurfaces; /*!<The size of array of pointers to mfxFrameSurface1. */
598 mfxU32 reserved1;
599@@ -4299,7 +4298,7 @@ MFX_PACK_BEGIN_USUAL_STRUCT()
600 mfxU16 Top; /*!< Y coordinate of region of top-left corner of rectangle. */
601 mfxU16 Right; /*!< X coordinate of region of bottom-right corner of rectangle. */
602 mfxU16 Bottom; /*!< Y coordinate of region of bottom-right corner of rectangle. */
603- } mfxRect;
604+ } mfxRect;
605 MFX_PACK_END()
606
607 MFX_PACK_BEGIN_USUAL_STRUCT()
608@@ -4313,6 +4312,22 @@ typedef struct {
609 }mfxExtInCrops;
610 MFX_PACK_END()
611
612+/*! The mfxHyperMode enumerator describes HyperMode implementation behavior. */
613+typedef enum {
614+ MFX_HYPERMODE_OFF = 0x0, /*!< Don't use HyperMode implementation. */
615+ MFX_HYPERMODE_ON = 0x1, /*!< Enable HyperMode implementation and return error if some issue on initialization. */
616+ MFX_HYPERMODE_ADAPTIVE = 0x2, /*!< Enable HyperMode implementation and switch to single fallback if some issue on initialization. */
617+} mfxHyperMode;
618+
619+MFX_PACK_BEGIN_USUAL_STRUCT()
620+/*! The structure is used for HyperMode initialization. */
621+typedef struct {
622+ mfxExtBuffer Header; /*!< Extension buffer header. BufferId must be equal to MFX_EXTBUFF_HYPER_MODE_PARAM. */
623+ mfxHyperMode Mode; /*!< HyperMode implementation behavior. */
624+ mfxU16 reserved[19];
625+} mfxExtHyperModeParam;
626+MFX_PACK_END()
627+
628 #ifdef __cplusplus
629 } // extern "C"
630 #endif
631diff --git a/api/vpl/mfxvideo++.h b/api/vpl/mfxvideo++.h
632index 1b10390..c05cd50 100644
633--- a/api/vpl/mfxvideo++.h
634+++ b/api/vpl/mfxvideo++.h
635@@ -71,6 +71,19 @@ public:
636 return MFXVideoCORE_SyncOperation(m_session, syncp, wait);
637 }
638
639+ virtual mfxStatus GetSurfaceForEncode(mfxFrameSurface1** output_surf) {
640+ return MFXMemory_GetSurfaceForEncode(m_session, output_surf);
641+ }
642+ virtual mfxStatus GetSurfaceForDecode(mfxFrameSurface1** output_surf) {
643+ return MFXMemory_GetSurfaceForDecode(m_session, output_surf);
644+ }
645+ virtual mfxStatus GetSurfaceForVPP (mfxFrameSurface1** output_surf) {
646+ return MFXMemory_GetSurfaceForVPP (m_session, output_surf);
647+ }
648+ virtual mfxStatus GetSurfaceForVPPOut(mfxFrameSurface1** output_surf) {
649+ return MFXMemory_GetSurfaceForVPPOut(m_session, output_surf);
650+ }
651+
652 virtual operator mfxSession(void) {
653 return m_session;
654 }
655@@ -121,6 +134,10 @@ public:
656 return MFXVideoENCODE_EncodeFrameAsync(m_session, ctrl, surface, bs, syncp);
657 }
658
659+ virtual mfxStatus GetSurface(mfxFrameSurface1** output_surf) {
660+ return MFXMemory_GetSurfaceForEncode(m_session, output_surf);
661+ }
662+
663 protected:
664 mfxSession m_session; // (mfxSession) handle to the owning session
665 };
666@@ -173,6 +190,10 @@ public:
667 return MFXVideoDECODE_DecodeFrameAsync(m_session, bs, surface_work, surface_out, syncp);
668 }
669
670+ virtual mfxStatus GetSurface(mfxFrameSurface1** output_surf) {
671+ return MFXMemory_GetSurfaceForDecode(m_session, output_surf);
672+ }
673+
674 protected:
675 mfxSession m_session; // (mfxSession) handle to the owning session
676 };
677@@ -215,6 +236,61 @@ public:
678 return MFXVideoVPP_RunFrameVPPAsync(m_session, in, out, aux, syncp);
679 }
680
681+ virtual mfxStatus GetSurfaceIn(mfxFrameSurface1** output_surf) {
682+ return MFXMemory_GetSurfaceForVPP(m_session, output_surf);
683+ }
684+ virtual mfxStatus GetSurfaceOut(mfxFrameSurface1** output_surf) {
685+ return MFXMemory_GetSurfaceForVPPOut(m_session, output_surf);
686+ }
687+
688+ virtual mfxStatus ProcessFrameAsync(mfxFrameSurface1 *in, mfxFrameSurface1 **out) {
689+ return MFXVideoVPP_ProcessFrameAsync(m_session, in, out);
690+ }
691+
692+protected:
693+ mfxSession m_session; // (mfxSession) handle to the owning session
694+};
695+
696+class MFXVideoDECODE_VPP
697+{
698+public:
699+ explicit MFXVideoDECODE_VPP(mfxSession session) { m_session = session; }
700+ virtual ~MFXVideoDECODE_VPP(void) {
701+ Close();
702+ }
703+
704+ virtual mfxStatus Init(mfxVideoParam* decode_par, mfxVideoChannelParam** vpp_par_array, mfxU32 num_channel_par) {
705+ return MFXVideoDECODE_VPP_Init(m_session, decode_par, vpp_par_array, num_channel_par);
706+ }
707+ virtual mfxStatus Reset(mfxVideoParam* decode_par, mfxVideoChannelParam** vpp_par_array, mfxU32 num_channel_par) {
708+ return MFXVideoDECODE_VPP_Reset(m_session, decode_par, vpp_par_array, num_channel_par);
709+ }
710+ virtual mfxStatus GetChannelParam(mfxVideoChannelParam *par, mfxU32 channel_id) {
711+ return MFXVideoDECODE_VPP_GetChannelParam(m_session, par, channel_id);
712+ }
713+ virtual mfxStatus DecodeFrameAsync(mfxBitstream *bs, mfxU32* skip_channels, mfxU32 num_skip_channels, mfxSurfaceArray **surf_array_out) {
714+ return MFXVideoDECODE_VPP_DecodeFrameAsync(m_session, bs, skip_channels, num_skip_channels, surf_array_out);
715+ }
716+
717+ virtual mfxStatus DecodeHeader(mfxBitstream *bs, mfxVideoParam *par) {
718+ return MFXVideoDECODE_VPP_DecodeHeader(m_session, bs, par);
719+ }
720+ virtual mfxStatus Close(void) {
721+ return MFXVideoDECODE_VPP_Close(m_session);
722+ }
723+ virtual mfxStatus GetVideoParam(mfxVideoParam *par) {
724+ return MFXVideoDECODE_VPP_GetVideoParam(m_session, par);
725+ }
726+ virtual mfxStatus GetDecodeStat(mfxDecodeStat *stat) {
727+ return MFXVideoDECODE_VPP_GetDecodeStat(m_session, stat);
728+ }
729+ virtual mfxStatus GetPayload(mfxU64 *ts, mfxPayload *payload) {
730+ return MFXVideoDECODE_VPP_GetPayload(m_session, ts, payload);
731+ }
732+ virtual mfxStatus SetSkipMode(mfxSkipMode mode) {
733+ return MFXVideoDECODE_VPP_SetSkipMode(m_session, mode);
734+ }
735+
736 protected:
737 mfxSession m_session; // (mfxSession) handle to the owning session
738 };
739--
7402.31.1
741
diff --git a/recipes-multimedia/onevpl/onevpl/0001-cmake-Allow-build-env-to-set-variables.patch b/recipes-multimedia/onevpl/onevpl/0001-cmake-Allow-build-env-to-set-variables.patch
deleted file mode 100644
index bb867a83..00000000
--- a/recipes-multimedia/onevpl/onevpl/0001-cmake-Allow-build-env-to-set-variables.patch
+++ /dev/null
@@ -1,65 +0,0 @@
1From 79eea3016649aa9e33e564b6971473ac15fa601a Mon Sep 17 00:00:00 2001
2From: Naveen Saini <naveen.kumar.saini@intel.com>
3Date: Tue, 27 Apr 2021 17:09:01 +0800
4Subject: [PATCH] cmake: Allow build env to set variables
5
6Upstream-Status: Inappropriate
7
8Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
9---
10 cmake/oneAPIInstallDirs.cmake | 32 ++++++++++++++++++++++----------
11 1 file changed, 22 insertions(+), 10 deletions(-)
12
13diff --git a/cmake/oneAPIInstallDirs.cmake b/cmake/oneAPIInstallDirs.cmake
14index 184e19b..0773500 100644
15--- a/cmake/oneAPIInstallDirs.cmake
16+++ b/cmake/oneAPIInstallDirs.cmake
17@@ -8,23 +8,35 @@
18 # Set installation directories
19 #
20
21-if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
22- set(CMAKE_INSTALL_BINDIR bin32)
23- set(CMAKE_INSTALL_LIBDIR lib32)
24-else()
25- set(CMAKE_INSTALL_BINDIR bin)
26- set(CMAKE_INSTALL_LIBDIR lib)
27+if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
28+ set(CMAKE_INSTALL_LIBDIR lib)
29+endif()
30+
31+if(NOT DEFINED CMAKE_INSTALL_BINDIR)
32+ set(CMAKE_INSTALL_BINDIR bin)
33+endif()
34+
35+if(NOT DEFINED CMAKE_INSTALL_ENVDIR)
36+ set(CMAKE_INSTALL_ENVDIR env)
37+endif()
38+
39+if(NOT DEFINED CMAKE_INSTALL_MODDIR)
40+ set(CMAKE_INSTALL_MODDIR modulefiles)
41+endif()
42+
43+if(NOT CMAKE_INSTALL_EXAMPLEDIR)
44+ set(CMAKE_INSTALL_EXAMPLEDIR examples)
45+endif()
46+
47+if(NOT CMAKE_INSTALL_LICENSEDIR)
48+ set(CMAKE_INSTALL_LICENSEDIR licensing)
49 endif()
50
51 set(CMAKE_INSTALL_INCLUDEDIR include)
52 set(CMAKE_INSTALL_DOCDIR documentation)
53-set(CMAKE_INSTALL_ENVDIR env)
54-set(CMAKE_INSTALL_MODDIR modulefiles)
55 set(CMAKE_INSTALL_SYSCHECKDIR sys_check)
56 set(CMAKE_INSTALL_MODFILEDIR modulefiles)
57 set(CMAKE_INSTALL_REDISTDIR redist)
58-set(CMAKE_INSTALL_EXAMPLEDIR examples)
59-set(CMAKE_INSTALL_LICENSEDIR licensing)
60 set(CMAKE_INSTALL_TOOLSDIR tools)
61 set(CMAKE_INSTALL_SYSCONFDIR config)
62 set(CMAKE_INSTALL_SRCDIR src)
63--
642.17.1
65
diff --git a/recipes-multimedia/onevpl/onevpl_2021.2.2.bb b/recipes-multimedia/onevpl/onevpl_2021.2.2.bb
deleted file mode 100644
index 6e08b42b..00000000
--- a/recipes-multimedia/onevpl/onevpl_2021.2.2.bb
+++ /dev/null
@@ -1,55 +0,0 @@
1SUMMARY = "oneAPI Video Processing Library"
2DESCRIPTION = "The oneAPI Video Processing Library (oneVPL) provides \
3a single video processing API for encode, decode, and video processing \
4that works across a wide range of accelerators."
5
6HOMEPAGE = "https://github.com/oneapi-src/oneVPL"
7LICENSE = "MIT"
8LIC_FILES_CHKSUM = "file://LICENSE;md5=c18ea6bb4786a26bf4eee88a7424a408 \
9 file://third-party-programs.txt;md5=0a071a05786c453d52f8b3e511ed39c4"
10
11SRC_URI = "git://github.com/oneapi-src/oneVPL.git;protocol=https \
12 file://0001-cmake-Allow-build-env-to-set-variables.patch \
13 file://0001-Add-X11-support-to-legacy-tools.patch \
14 file://0001-Adding-Wayland-support-to-legacy-tools.patch \
15 file://0001-Update-headers-to-oneAPI-spec-v2.3-e170992.patch \
16 file://0001-Remove-duplicate-MFXVideoDECODE_VPP-from-samples.patch \
17 file://0001-Add-SMT-and-media_sdk_compatibility_headers.patch \
18 file://0001-Fix-NV12-input-format-in-legacy-samples.patch \
19 file://0001-Fix-sample_vpp-sample_encode-alignment-issue.patch \
20 file://0001-Fix-sample_encode-i010-input.patch \
21 file://0001-Corrected-the-install-path.patch \
22 "
23SRCREV = "17968d8d2299352f5a9e09388d24e81064c81c87"
24S = "${WORKDIR}/git"
25
26inherit cmake
27DEPENDS = "libva"
28
29COMPATIBLE_HOST = '(x86_64).*-linux'
30
31PACKAGES =+ "${PN}-examples"
32
33EXTRA_OECMAKE += " \
34 -DVPL_UTIL_PATH=${S}/examples/util \
35 -DCMAKE_INSTALL_ENVDIR=${datadir}/vpl/env \
36 -DCMAKE_INSTALL_MODDIR=${datadir}/vpl/modulefiles \
37 -DCMAKE_INSTALL_EXAMPLEDIR=${datadir}/vpl/examples \
38 -DCMAKE_INSTALL_LICENSEDIR=${datadir}/vpl/licensing \
39"
40do_install_append () {
41 # delete examples source files
42 find "${D}${datadir}/vpl/examples/" -type d \! -name 'examples' \! -name 'content' -exec rm -rf {} +
43}
44
45FILES_${PN}-examples = "${bindir}/dpcpp-blur \
46 ${bindir}/hello-* \
47 ${datadir}/vpl/examples \
48 "
49
50FILES_SOLIBSDEV = ""
51FILES_${PN}-dev += "${libdir}/libvpl.so"
52
53FILES_${PN} += "${datadir} \
54 ${libdir}/libvpl_wayland.so \
55 "
diff --git a/recipes-multimedia/onevpl/onevpl_2021.4.0.bb b/recipes-multimedia/onevpl/onevpl_2021.4.0.bb
new file mode 100644
index 00000000..4d9591fa
--- /dev/null
+++ b/recipes-multimedia/onevpl/onevpl_2021.4.0.bb
@@ -0,0 +1,33 @@
1SUMMARY = "oneAPI Video Processing Library"
2DESCRIPTION = "The oneAPI Video Processing Library (oneVPL) provides \
3a single video processing API for encode, decode, and video processing \
4that works across a wide range of accelerators."
5
6HOMEPAGE = "https://github.com/oneapi-src/oneVPL"
7LICENSE = "MIT"
8LIC_FILES_CHKSUM = "file://LICENSE;md5=c18ea6bb4786a26bf4eee88a7424a408 \
9 file://third-party-programs.txt;md5=52d2c0c51bb5c0d9d9c16ae91d66c8fb"
10
11SRC_URI = "git://github.com/oneapi-src/oneVPL.git;protocol=https \
12 file://0001-Adding-Wayland-support-to-legacy-tools.patch \
13 file://0001-Corrected-the-install-path.patch \
14 "
15SRCREV = "d5c072584ee6f81305ed85de8759658ab7854606"
16S = "${WORKDIR}/git"
17
18inherit cmake
19DEPENDS = "libva"
20
21COMPATIBLE_HOST = '(x86_64).*-linux'
22
23PACKAGES =+ "${PN}-examples"
24
25FILES_${PN}-examples = "${datadir}/oneVPL/examples \
26 "
27
28FILES_SOLIBSDEV = ""
29FILES_${PN}-dev += "${libdir}/libvpl.so"
30
31FILES_${PN} += "${datadir} \
32 ${libdir}/libvpl_wayland.so \
33 "