1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/*
* (C) 2007-2013 see Authors.txt
*
* This file is part of MPC-HC.
*
* MPC-HC is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* MPC-HC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "stdafx.h"
#include "VideoDecOutputPin.h"
#include "VideoDecDXVAAllocator.h"
#include "MPCVideoDecFilter.h"
#include "../../../DSUtil/DSUtil.h"
CVideoDecOutputPin::CVideoDecOutputPin(TCHAR* pObjectName, CBaseVideoFilter* pFilter, HRESULT* phr, LPCWSTR pName)
: CBaseVideoOutputPin(pObjectName, pFilter, phr, pName)
{
m_pVideoDecFilter = static_cast<CMPCVideoDecFilter*>(pFilter);
m_pDXVA2Allocator = nullptr;
m_dwDXVA1SurfaceCount = 0;
m_GuidDecoderDXVA1 = GUID_NULL;
memset(&m_ddUncompPixelFormat, 0, sizeof(m_ddUncompPixelFormat));
}
CVideoDecOutputPin::~CVideoDecOutputPin()
{
}
HRESULT CVideoDecOutputPin::InitAllocator(IMemAllocator** ppAlloc)
{
TRACE(_T("CVideoDecOutputPin::InitAllocator\n"));
if (m_pVideoDecFilter->UseDXVA2()) {
HRESULT hr = S_FALSE;
m_pDXVA2Allocator = DEBUG_NEW CVideoDecDXVAAllocator(m_pVideoDecFilter, &hr);
if (!m_pDXVA2Allocator) {
return E_OUTOFMEMORY;
}
if (FAILED(hr)) {
delete m_pDXVA2Allocator;
return hr;
}
// Return the IMemAllocator interface.
return m_pDXVA2Allocator->QueryInterface(__uuidof(IMemAllocator), (void**)ppAlloc);
} else {
return __super::InitAllocator(ppAlloc);
}
}
STDMETHODIMP CVideoDecOutputPin::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
return
QI(IAMVideoAcceleratorNotify)
__super::NonDelegatingQueryInterface(riid, ppv);
}
// === IAMVideoAcceleratorNotify
STDMETHODIMP CVideoDecOutputPin::GetUncompSurfacesInfo(const GUID* pGuid, LPAMVAUncompBufferInfo pUncompBufferInfo)
{
HRESULT hr = E_INVALIDARG;
if (SUCCEEDED(m_pVideoDecFilter->CheckDXVA1Decoder(pGuid))) {
CComQIPtr<IAMVideoAccelerator> pAMVideoAccelerator = GetConnected();
if (pAMVideoAccelerator) {
pUncompBufferInfo->dwMaxNumSurfaces = m_pVideoDecFilter->GetPicEntryNumber();
pUncompBufferInfo->dwMinNumSurfaces = m_pVideoDecFilter->GetPicEntryNumber();
hr = m_pVideoDecFilter->FindDXVA1DecoderConfiguration(pAMVideoAccelerator, pGuid, &pUncompBufferInfo->ddUncompPixelFormat);
if (SUCCEEDED(hr)) {
memcpy(&m_ddUncompPixelFormat, &pUncompBufferInfo->ddUncompPixelFormat, sizeof(DDPIXELFORMAT));
m_GuidDecoderDXVA1 = *pGuid;
}
}
}
return hr;
}
STDMETHODIMP CVideoDecOutputPin::SetUncompSurfacesInfo(DWORD dwActualUncompSurfacesAllocated)
{
m_dwDXVA1SurfaceCount = dwActualUncompSurfacesAllocated;
return S_OK;
}
STDMETHODIMP CVideoDecOutputPin::GetCreateVideoAcceleratorData(const GUID* pGuid, LPDWORD pdwSizeMiscData, LPVOID* ppMiscData)
{
HRESULT hr = E_UNEXPECTED;
AMVAUncompDataInfo UncompInfo;
AMVACompBufferInfo CompInfo[30];
DWORD dwNumTypesCompBuffers = _countof(CompInfo);
CComQIPtr<IAMVideoAccelerator> pAMVideoAccelerator = GetConnected();
DXVA_ConnectMode* pConnectMode;
if (pAMVideoAccelerator) {
memcpy(&UncompInfo.ddUncompPixelFormat, &m_ddUncompPixelFormat, sizeof(DDPIXELFORMAT));
UncompInfo.dwUncompWidth = m_pVideoDecFilter->PictWidthRounded();
UncompInfo.dwUncompHeight = m_pVideoDecFilter->PictHeightRounded();
hr = pAMVideoAccelerator->GetCompBufferInfo(&m_GuidDecoderDXVA1, &UncompInfo, &dwNumTypesCompBuffers, CompInfo);
if (SUCCEEDED(hr)) {
hr = m_pVideoDecFilter->CreateDXVA1Decoder(pAMVideoAccelerator, pGuid, m_dwDXVA1SurfaceCount);
if (SUCCEEDED(hr)) {
m_pVideoDecFilter->SetDXVA1Params(&m_GuidDecoderDXVA1, &m_ddUncompPixelFormat);
pConnectMode = (DXVA_ConnectMode*)CoTaskMemAlloc(sizeof(DXVA_ConnectMode));
if (pConnectMode != nullptr) {
pConnectMode->guidMode = m_GuidDecoderDXVA1;
pConnectMode->wRestrictedMode = m_pVideoDecFilter->GetDXVA1RestrictedMode();
*pdwSizeMiscData = sizeof(DXVA_ConnectMode);
*ppMiscData = pConnectMode;
} else {
hr = E_OUTOFMEMORY;
}
}
}
}
return hr;
}
|