| 1 |
/*############################################################################ |
| 2 |
# Copyright (C) Intel Corporation |
| 3 |
# |
| 4 |
# SPDX-License-Identifier: MIT |
| 5 |
############################################################################*/ |
| 6 |
|
| 7 |
#include "vpl/mfx_dispatcher_vpl.h" |
| 8 |
|
| 9 |
// exported functions for API >= 2.0 |
| 10 |
|
| 11 |
// create unique loader context |
| 12 |
mfxLoader MFXLoad() { |
| 13 |
LoaderCtxVPL *loaderCtx; |
| 14 |
|
| 15 |
try { |
| 16 |
std::unique_ptr<LoaderCtxVPL> pLoaderCtx; |
| 17 |
pLoaderCtx.reset(new LoaderCtxVPL{}); |
| 18 |
loaderCtx = (LoaderCtxVPL *)pLoaderCtx.release(); |
| 19 |
} |
| 20 |
catch (...) { |
| 21 |
return nullptr; |
| 22 |
} |
| 23 |
|
| 24 |
// initialize logging if appropriate environment variables are set |
| 25 |
loaderCtx->InitDispatcherLog(); |
| 26 |
|
| 27 |
return (mfxLoader)loaderCtx; |
| 28 |
} |
| 29 |
|
| 30 |
// unload libraries, destroy all created mfxConfig objects, free other memory |
| 31 |
void MFXUnload(mfxLoader loader) { |
| 32 |
if (loader) { |
| 33 |
LoaderCtxVPL *loaderCtx = (LoaderCtxVPL *)loader; |
| 34 |
|
| 35 |
loaderCtx->UnloadAllLibraries(); |
| 36 |
|
| 37 |
loaderCtx->FreeConfigFilters(); |
| 38 |
|
| 39 |
delete loaderCtx; |
| 40 |
} |
| 41 |
|
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
// create config context |
| 46 |
// each loader may have more than one config context |
| 47 |
mfxConfig MFXCreateConfig(mfxLoader loader) { |
| 48 |
if (!loader) |
| 49 |
return nullptr; |
| 50 |
|
| 51 |
LoaderCtxVPL *loaderCtx = (LoaderCtxVPL *)loader; |
| 52 |
ConfigCtxVPL *configCtx; |
| 53 |
|
| 54 |
DispatcherLogVPL *dispLog = loaderCtx->GetLogger(); |
| 55 |
DISP_LOG_FUNCTION(dispLog); |
| 56 |
|
| 57 |
try { |
| 58 |
configCtx = loaderCtx->AddConfigFilter(); |
| 59 |
} |
| 60 |
catch (...) { |
| 61 |
return nullptr; |
| 62 |
} |
| 63 |
|
| 64 |
return (mfxConfig)(configCtx); |
| 65 |
} |
| 66 |
|
| 67 |
// set a config proprerty to use in enumerating implementations |
| 68 |
mfxStatus MFXSetConfigFilterProperty(mfxConfig config, const mfxU8 *name, mfxVariant value) { |
| 69 |
if (!config) |
| 70 |
return MFX_ERR_NULL_PTR; |
| 71 |
|
| 72 |
ConfigCtxVPL *configCtx = (ConfigCtxVPL *)config; |
| 73 |
LoaderCtxVPL *loaderCtx = configCtx->m_parentLoader; |
| 74 |
|
| 75 |
DispatcherLogVPL *dispLog = loaderCtx->GetLogger(); |
| 76 |
DISP_LOG_FUNCTION(dispLog); |
| 77 |
|
| 78 |
mfxStatus sts = configCtx->SetFilterProperty(name, value); |
| 79 |
if (sts) |
| 80 |
return sts; |
| 81 |
|
| 82 |
loaderCtx->m_bNeedUpdateValidImpls = true; |
| 83 |
|
| 84 |
sts = loaderCtx->UpdateLowLatency(); |
| 85 |
|
| 86 |
return sts; |
| 87 |
} |
| 88 |
|
| 89 |
// iterate over available implementations |
| 90 |
// capabilities are returned in idesc |
| 91 |
mfxStatus MFXEnumImplementations(mfxLoader loader, |
| 92 |
mfxU32 i, |
| 93 |
mfxImplCapsDeliveryFormat format, |
| 94 |
mfxHDL *idesc) { |
| 95 |
if (!loader || !idesc) |
| 96 |
return MFX_ERR_NULL_PTR; |
| 97 |
|
| 98 |
LoaderCtxVPL *loaderCtx = (LoaderCtxVPL *)loader; |
| 99 |
|
| 100 |
DispatcherLogVPL *dispLog = loaderCtx->GetLogger(); |
| 101 |
DISP_LOG_FUNCTION(dispLog); |
| 102 |
|
| 103 |
mfxStatus sts = MFX_ERR_NONE; |
| 104 |
|
| 105 |
// load and query all libraries |
| 106 |
if (loaderCtx->m_bNeedFullQuery) { |
| 107 |
// if a session was already created in low-latency mode, unload all implementations |
| 108 |
// before running full load and query |
| 109 |
if (loaderCtx->m_bLowLatency && !loaderCtx->m_bNeedLowLatencyQuery) { |
| 110 |
loaderCtx->UnloadAllLibraries(); |
| 111 |
} |
| 112 |
|
| 113 |
sts = loaderCtx->FullLoadAndQuery(); |
| 114 |
if (sts) |
| 115 |
return MFX_ERR_NOT_FOUND; |
| 116 |
} |
| 117 |
|
| 118 |
// update list of valid libraries based on updated set of |
| 119 |
// mfxConfig properties |
| 120 |
if (loaderCtx->m_bNeedUpdateValidImpls) { |
| 121 |
sts = loaderCtx->UpdateValidImplList(); |
| 122 |
if (sts) |
| 123 |
return MFX_ERR_NOT_FOUND; |
| 124 |
} |
| 125 |
|
| 126 |
sts = loaderCtx->QueryImpl(i, format, idesc); |
| 127 |
|
| 128 |
return sts; |
| 129 |
} |
| 130 |
|
| 131 |
// create a new session with implementation i |
| 132 |
mfxStatus MFXCreateSession(mfxLoader loader, mfxU32 i, mfxSession *session) { |
| 133 |
if (!loader || !session) |
| 134 |
return MFX_ERR_NULL_PTR; |
| 135 |
|
| 136 |
LoaderCtxVPL *loaderCtx = (LoaderCtxVPL *)loader; |
| 137 |
|
| 138 |
DispatcherLogVPL *dispLog = loaderCtx->GetLogger(); |
| 139 |
DISP_LOG_FUNCTION(dispLog); |
| 140 |
|
| 141 |
mfxStatus sts = MFX_ERR_NONE; |
| 142 |
|
| 143 |
if (loaderCtx->m_bLowLatency) { |
| 144 |
DISP_LOG_MESSAGE(dispLog, "message: low latency mode enabled"); |
| 145 |
|
| 146 |
if (loaderCtx->m_bNeedLowLatencyQuery) { |
| 147 |
// load low latency libraries |
| 148 |
sts = loaderCtx->LoadLibsLowLatency(); |
| 149 |
if (sts != MFX_ERR_NONE) |
| 150 |
return MFX_ERR_NOT_FOUND; |
| 151 |
|
| 152 |
// run limited query operations for low latency init |
| 153 |
sts = loaderCtx->QueryLibraryCaps(); |
| 154 |
if (sts != MFX_ERR_NONE) |
| 155 |
return MFX_ERR_NOT_FOUND; |
| 156 |
} |
| 157 |
} |
| 158 |
else { |
| 159 |
DISP_LOG_MESSAGE(dispLog, "message: low latency mode disabled"); |
| 160 |
|
| 161 |
// load and query all libraries |
| 162 |
if (loaderCtx->m_bNeedFullQuery) { |
| 163 |
sts = loaderCtx->FullLoadAndQuery(); |
| 164 |
if (sts) |
| 165 |
return MFX_ERR_NOT_FOUND; |
| 166 |
} |
| 167 |
|
| 168 |
// update list of valid libraries based on updated set of |
| 169 |
// mfxConfig properties |
| 170 |
if (loaderCtx->m_bNeedUpdateValidImpls) { |
| 171 |
sts = loaderCtx->UpdateValidImplList(); |
| 172 |
if (sts) |
| 173 |
return MFX_ERR_NOT_FOUND; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
sts = loaderCtx->CreateSession(i, session); |
| 178 |
|
| 179 |
return sts; |
| 180 |
} |
| 181 |
|
| 182 |
// release memory associated with implementation description hdl |
| 183 |
mfxStatus MFXDispReleaseImplDescription(mfxLoader loader, mfxHDL hdl) { |
| 184 |
if (!loader) |
| 185 |
return MFX_ERR_NULL_PTR; |
| 186 |
|
| 187 |
LoaderCtxVPL *loaderCtx = (LoaderCtxVPL *)loader; |
| 188 |
|
| 189 |
DispatcherLogVPL *dispLog = loaderCtx->GetLogger(); |
| 190 |
DISP_LOG_FUNCTION(dispLog); |
| 191 |
|
| 192 |
mfxStatus sts = loaderCtx->ReleaseImpl(hdl); |
| 193 |
|
| 194 |
return sts; |
| 195 |
} |