Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
evrhelpers.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "evrhelpers_p.h"
5
6#include <cguid.h>
7
8#ifndef D3DFMT_YV12
9#define D3DFMT_YV12 (D3DFORMAT)MAKEFOURCC ('Y', 'V', '1', '2')
10#endif
11#ifndef D3DFMT_NV12
12#define D3DFMT_NV12 (D3DFORMAT)MAKEFOURCC ('N', 'V', '1', '2')
13#endif
14
16
17HRESULT qt_evr_getFourCC(IMFMediaType *type, DWORD *fourCC)
18{
19 if (!fourCC)
20 return E_POINTER;
21
22 HRESULT hr = S_OK;
23 GUID guidSubType = GUID_NULL;
24
25 if (SUCCEEDED(hr))
26 hr = type->GetGUID(MF_MT_SUBTYPE, &guidSubType);
27
28 if (SUCCEEDED(hr))
29 *fourCC = guidSubType.Data1;
30
31 return hr;
32}
33
34bool qt_evr_areMediaTypesEqual(IMFMediaType *type1, IMFMediaType *type2)
35{
36 if (!type1 && !type2)
37 return true;
38 if (!type1 || !type2)
39 return false;
40
41 DWORD dwFlags = 0;
42 HRESULT hr = type1->IsEqual(type2, &dwFlags);
43
44 return (hr == S_OK);
45}
46
47HRESULT qt_evr_validateVideoArea(const MFVideoArea& area, UINT32 width, UINT32 height)
48{
49 float fOffsetX = qt_evr_MFOffsetToFloat(area.OffsetX);
50 float fOffsetY = qt_evr_MFOffsetToFloat(area.OffsetY);
51
52 if ( ((LONG)fOffsetX + area.Area.cx > (LONG)width) ||
53 ((LONG)fOffsetY + area.Area.cy > (LONG)height) ) {
54 return MF_E_INVALIDMEDIATYPE;
55 }
56 return S_OK;
57}
58
59bool qt_evr_isSampleTimePassed(IMFClock *clock, IMFSample *sample)
60{
61 if (!sample || !clock)
62 return false;
63
64 HRESULT hr = S_OK;
65 MFTIME hnsTimeNow = 0;
66 MFTIME hnsSystemTime = 0;
67 MFTIME hnsSampleStart = 0;
68 MFTIME hnsSampleDuration = 0;
69
70 hr = clock->GetCorrelatedTime(0, &hnsTimeNow, &hnsSystemTime);
71
72 if (SUCCEEDED(hr))
73 hr = sample->GetSampleTime(&hnsSampleStart);
74
75 if (SUCCEEDED(hr))
76 hr = sample->GetSampleDuration(&hnsSampleDuration);
77
78 if (SUCCEEDED(hr)) {
79 if (hnsSampleStart + hnsSampleDuration < hnsTimeNow)
80 return true;
81 }
82
83 return false;
84}
85
87{
88 switch (format) {
89 case D3DFMT_A8R8G8B8:
90 return QVideoFrameFormat::Format_BGRA8888;
91 case D3DFMT_X8R8G8B8:
92 return QVideoFrameFormat::Format_BGRX8888;
93 case D3DFMT_A8:
94 return QVideoFrameFormat::Format_Y8;
95 case D3DFMT_A8B8G8R8:
96 return QVideoFrameFormat::Format_RGBA8888;
97 case D3DFMT_X8B8G8R8:
98 return QVideoFrameFormat::Format_RGBX8888;
99 case D3DFMT_UYVY:
100 return QVideoFrameFormat::Format_UYVY;
101 case D3DFMT_YUY2:
102 return QVideoFrameFormat::Format_YUYV;
103 case D3DFMT_NV12:
104 return QVideoFrameFormat::Format_NV12;
105 case D3DFMT_YV12:
106 return QVideoFrameFormat::Format_YV12;
107 case D3DFMT_UNKNOWN:
108 default:
109 return QVideoFrameFormat::Format_Invalid;
110 }
111}
112
113D3DFORMAT qt_evr_D3DFormatFromPixelFormat(QVideoFrameFormat::PixelFormat format)
114{
115 switch (format) {
116 case QVideoFrameFormat::Format_ARGB8888:
117 return D3DFMT_A8B8G8R8;
118 case QVideoFrameFormat::Format_BGRA8888:
119 return D3DFMT_A8R8G8B8;
120 case QVideoFrameFormat::Format_BGRX8888:
121 return D3DFMT_X8R8G8B8;
122 case QVideoFrameFormat::Format_Y8:
123 return D3DFMT_A8;
124 case QVideoFrameFormat::Format_RGBA8888:
125 return D3DFMT_A8B8G8R8;
126 case QVideoFrameFormat::Format_RGBX8888:
127 return D3DFMT_X8B8G8R8;
128 case QVideoFrameFormat::Format_UYVY:
129 return D3DFMT_UYVY;
130 case QVideoFrameFormat::Format_YUYV:
131 return D3DFMT_YUY2;
132 case QVideoFrameFormat::Format_NV12:
133 return D3DFMT_NV12;
134 case QVideoFrameFormat::Format_YV12:
135 return D3DFMT_YV12;
136 case QVideoFrameFormat::Format_Invalid:
137 default:
138 return D3DFMT_UNKNOWN;
139 }
140}
141
142QT_END_NAMESPACE
#define D3DFMT_YV12
Definition evrhelpers.cpp:9
D3DFORMAT qt_evr_D3DFormatFromPixelFormat(QVideoFrameFormat::PixelFormat format)
bool qt_evr_areMediaTypesEqual(IMFMediaType *type1, IMFMediaType *type2)
#define D3DFMT_NV12
QVideoFrameFormat::PixelFormat qt_evr_pixelFormatFromD3DFormat(DWORD format)
bool qt_evr_isSampleTimePassed(IMFClock *clock, IMFSample *sample)
HRESULT qt_evr_validateVideoArea(const MFVideoArea &area, UINT32 width, UINT32 height)