3
3
// SPDX-License-Identifier: Apache-2.0
4
4
5
5
#include " msdkvideobase.h"
6
+ #include " mfxadapter.h"
6
7
#include " talk/owt/sdk/base/nativehandlebuffer.h"
7
8
#include " talk/owt/sdk/base/win/d3d11_allocator.h"
8
9
#include " talk/owt/sdk/base/win/d3dnativeframe.h"
@@ -67,15 +68,53 @@ void MSDKVideoDecoder::CheckOnCodecThread() {
67
68
68
69
bool MSDKVideoDecoder::CreateD3D11Device () {
69
70
HRESULT hr = S_OK;
70
- UINT create_flag = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
71
71
72
72
static D3D_FEATURE_LEVEL feature_levels[] = {
73
73
D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1,
74
74
D3D_FEATURE_LEVEL_10_1};
75
75
D3D_FEATURE_LEVEL feature_levels_out;
76
76
77
+ mfxU8 headers[] = {0x00 , 0x00 , 0x00 , 0x01 , 0x67 , 0x42 , 0xE0 , 0x0A , 0x96 ,
78
+ 0x52 , 0x85 , 0x89 , 0xC8 , 0x00 , 0x00 , 0x00 , 0x01 , 0x68 ,
79
+ 0xC9 , 0x23 , 0xC8 , 0x00 , 0x00 , 0x00 , 0x01 , 0x09 , 0x10 };
80
+ mfxBitstream bs = {};
81
+ bs.Data = headers;
82
+ bs.DataLength = bs.MaxLength = sizeof (headers);
83
+
84
+ mfxStatus sts = MFX_ERR_NONE;
85
+ mfxU32 num_adapters;
86
+ sts = MFXQueryAdaptersNumber (&num_adapters);
87
+
88
+ if (sts != MFX_ERR_NONE)
89
+ return false ;
90
+
91
+ std::vector<mfxAdapterInfo> display_data (num_adapters);
92
+ mfxAdaptersInfo adapters = {display_data.data (), mfxU32 (display_data.size ()),
93
+ 0u };
94
+ sts = MFXQueryAdaptersDecode (&bs, MFX_CODEC_AVC, &adapters);
95
+ if (sts != MFX_ERR_NONE) {
96
+ RTC_LOG (LS_ERROR) << " Failed to query adapter with hardware acceleration" ;
97
+ return false ;
98
+ }
99
+ mfxU32 adapter_idx = adapters.Adapters [0 ].Number ;
100
+
101
+ hr = CreateDXGIFactory (__uuidof (IDXGIFactory2), (void **)(&m_pDXGIFactory));
102
+ if (FAILED (hr)) {
103
+ RTC_LOG (LS_ERROR)
104
+ << " Failed to create dxgi factory for adatper enumeration." ;
105
+ return false ;
106
+ }
107
+
108
+ hr = m_pDXGIFactory->EnumAdapters (adapter_idx, &m_pAdapter);
109
+ if (FAILED (hr)) {
110
+ RTC_LOG (LS_ERROR) << " Failed to enum adapter for specified adapter index." ;
111
+ return false ;
112
+ }
113
+
114
+ // On DG1 this setting driver type to hardware will result-in device
115
+ // creation failure.
77
116
hr = D3D11CreateDevice (
78
- nullptr , D3D_DRIVER_TYPE_HARDWARE , nullptr , create_flag , feature_levels,
117
+ m_pAdapter, D3D_DRIVER_TYPE_UNKNOWN , nullptr , 0 , feature_levels,
79
118
sizeof (feature_levels) / sizeof (feature_levels[0 ]), D3D11_SDK_VERSION,
80
119
&d3d11_device, &feature_levels_out, &d3d11_device_context);
81
120
if (FAILED (hr)) {
@@ -173,9 +212,9 @@ int32_t MSDKVideoDecoder::InitDecodeOnCodecThread() {
173
212
codec_id = MFX_CODEC_AV1;
174
213
}
175
214
176
- if (!factory->LoadDecoderPlugin (codec_id, m_mfxSession, &m_pluginID)) {
177
- return WEBRTC_VIDEO_CODEC_ERROR;
178
- }
215
+ // if (!factory->LoadDecoderPlugin(codec_id, m_mfxSession, &m_pluginID)) {
216
+ // return WEBRTC_VIDEO_CODEC_ERROR;
217
+ // }
179
218
180
219
if (!CreateD3D11Device ()) {
181
220
return WEBRTC_VIDEO_CODEC_ERROR;
@@ -256,6 +295,8 @@ int32_t MSDKVideoDecoder::Decode(
256
295
return WEBRTC_VIDEO_CODEC_ERROR;
257
296
}
258
297
nSurfNum = MSDK_MAX (request.NumFrameSuggested , 1 );
298
+
299
+ request.Type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
259
300
sts = m_pMFXAllocator->Alloc (m_pMFXAllocator->pthis , &request,
260
301
&m_mfxResponse);
261
302
if (MFX_ERR_NONE != sts) {
@@ -275,6 +316,19 @@ int32_t MSDKVideoDecoder::Decode(
275
316
MSDK_MEMCPY_VAR (m_pInputSurfaces[i].Info , &(request.Info ),
276
317
sizeof (mfxFrameInfo));
277
318
m_pInputSurfaces[i].Data .MemId = m_mfxResponse.mids [i];
319
+ m_pInputSurfaces[i].Data .MemType = request.Type ;
320
+ }
321
+
322
+ if (!m_mfxVideoParams.mfx .FrameInfo .FrameRateExtN ||
323
+ m_mfxVideoParams.mfx .FrameInfo .FrameRateExtD ) {
324
+ m_mfxVideoParams.mfx .FrameInfo .FrameRateExtN = 30 ;
325
+ m_mfxVideoParams.mfx .FrameInfo .FrameRateExtD = 1 ;
326
+ }
327
+
328
+ if (!m_mfxVideoParams.mfx .FrameInfo .AspectRatioH ||
329
+ !m_mfxVideoParams.mfx .FrameInfo .AspectRatioW ) {
330
+ m_mfxVideoParams.mfx .FrameInfo .AspectRatioH = 1 ;
331
+ m_mfxVideoParams.mfx .FrameInfo .AspectRatioW = 1 ;
278
332
}
279
333
// Finally we're done with all configurations and we're OK to init the
280
334
// decoder.
@@ -316,12 +370,15 @@ int32_t MSDKVideoDecoder::Decode(
316
370
if (sts == MFX_ERR_NONE && syncp != nullptr ) {
317
371
sts = m_mfxSession->SyncOperation (syncp, MSDK_DEC_WAIT_INTERVAL);
318
372
if (sts >= MFX_ERR_NONE) {
319
- mfxHDLPair* dxMemId = (mfxHDLPair*)pOutputSurface->Data .MemId ;
320
-
373
+ mfxMemId dxMemId = pOutputSurface->Data .MemId ;
374
+ mfxHDLPair pair = {nullptr };
375
+ // Maybe we should also send the allocator as part of the frame
376
+ // handle for locking/unlocking purpose.
377
+ m_pMFXAllocator->GetFrameHDL (dxMemId, (mfxHDL*)&pair);
321
378
if (callback_) {
322
379
surface_handle->d3d11_device = d3d11_device.p ;
323
380
surface_handle->texture =
324
- reinterpret_cast <ID3D11Texture2D*>(dxMemId-> first );
381
+ reinterpret_cast <ID3D11Texture2D*>(pair. first );
325
382
// Texture_array_index not used when decoding with MSDK.
326
383
surface_handle->texture_array_index = 0 ;
327
384
D3D11_TEXTURE2D_DESC texture_desc;
0 commit comments