Parent Directory | Revision Log
Revision 1902 - (view) (download)
1 : | edgomez | 1384 | /***************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | Isibaar | 1896 | * - Xvid Decoder part of the DShow Filter - |
5 : | edgomez | 1384 | * |
6 : | Isibaar | 1896 | * Copyright(C) 2002-2010 Peter Ross <pross@xvid.org> |
7 : | * 2003-2010 Michael Militzer <michael@xvid.org> | ||
8 : | edgomez | 1384 | * |
9 : | * This program is free software ; you can redistribute it and/or modify | ||
10 : | * it under the terms of the GNU General Public License as published by | ||
11 : | * the Free Software Foundation ; either version 2 of the License, or | ||
12 : | * (at your option) any later version. | ||
13 : | * | ||
14 : | * This program is distributed in the hope that it will be useful, | ||
15 : | * but WITHOUT ANY WARRANTY ; without even the implied warranty of | ||
16 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 : | * GNU General Public License for more details. | ||
18 : | * | ||
19 : | * You should have received a copy of the GNU General Public License | ||
20 : | * along with this program ; if not, write to the Free Software | ||
21 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 : | * | ||
23 : | Isibaar | 1902 | * $Id: CXvidDecoder.cpp,v 1.23 2010-10-29 16:39:07 Isibaar Exp $ |
24 : | edgomez | 1384 | * |
25 : | ****************************************************************************/ | ||
26 : | |||
27 : | /**************************************************************************** | ||
28 : | * | ||
29 : | * 2003/12/11 - added some additional options, mainly to make the deblocking | ||
30 : | * code from xvidcore available. Most of the new code is taken | ||
31 : | * from Nic's dshow filter, (C) Nic, http://nic.dnsalias.com | ||
32 : | * | ||
33 : | ****************************************************************************/ | ||
34 : | |||
35 : | /* | ||
36 : | this requires the directx sdk | ||
37 : | place these paths at the top of the Tools|Options|Directories list | ||
38 : | |||
39 : | headers: | ||
40 : | suxen_drol | 1521 | C:\DX90SDK\Include |
41 : | C:\DX90SDK\Samples\C++\DirectShow\BaseClasses | ||
42 : | edgomez | 1384 | |
43 : | suxen_drol | 1521 | C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Release |
44 : | C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Debug | ||
45 : | edgomez | 1384 | */ |
46 : | |||
47 : | Isibaar | 1902 | // #define XVID_USE_MFT |
48 : | // #define XVID_USE_TRAYICON | ||
49 : | edgomez | 1384 | |
50 : | #include <windows.h> | ||
51 : | |||
52 : | #include <streams.h> | ||
53 : | #include <initguid.h> | ||
54 : | #include <olectl.h> | ||
55 : | #if (1100 > _MSC_VER) | ||
56 : | #include <olectlid.h> | ||
57 : | #endif | ||
58 : | #include <dvdmedia.h> // VIDEOINFOHEADER2 | ||
59 : | |||
60 : | Isibaar | 1898 | #if defined(XVID_USE_MFT) |
61 : | #define MFT_UNIQUE_METHOD_NAMES | ||
62 : | #include <mftransform.h> | ||
63 : | #include <mfapi.h> | ||
64 : | #include <mferror.h> | ||
65 : | #include <shlwapi.h> | ||
66 : | #endif | ||
67 : | |||
68 : | Isibaar | 1896 | #include <shellapi.h> |
69 : | edgomez | 1384 | |
70 : | Isibaar | 1896 | #include <xvid.h> // Xvid API |
71 : | |||
72 : | #include "resource.h" | ||
73 : | |||
74 : | edgomez | 1384 | #include "IXvidDecoder.h" |
75 : | #include "CXvidDecoder.h" | ||
76 : | #include "CAbout.h" | ||
77 : | #include "config.h" | ||
78 : | #include "debug.h" | ||
79 : | |||
80 : | static bool USE_IYUV; | ||
81 : | static bool USE_YV12; | ||
82 : | static bool USE_YUY2; | ||
83 : | static bool USE_YVYU; | ||
84 : | static bool USE_UYVY; | ||
85 : | static bool USE_RGB32; | ||
86 : | static bool USE_RGB24; | ||
87 : | static bool USE_RG555; | ||
88 : | static bool USE_RG565; | ||
89 : | |||
90 : | const AMOVIESETUP_MEDIATYPE sudInputPinTypes[] = | ||
91 : | { | ||
92 : | { &MEDIATYPE_Video, &CLSID_XVID }, | ||
93 : | { &MEDIATYPE_Video, &CLSID_XVID_UC }, | ||
94 : | { &MEDIATYPE_Video, &CLSID_DIVX }, | ||
95 : | { &MEDIATYPE_Video, &CLSID_DIVX_UC }, | ||
96 : | { &MEDIATYPE_Video, &CLSID_DX50 }, | ||
97 : | { &MEDIATYPE_Video, &CLSID_DX50_UC }, | ||
98 : | { &MEDIATYPE_Video, &CLSID_MP4V }, | ||
99 : | suxen_drol | 1647 | { &MEDIATYPE_Video, &CLSID_MP4V_UC }, |
100 : | edgomez | 1384 | }; |
101 : | |||
102 : | const AMOVIESETUP_MEDIATYPE sudOutputPinTypes[] = | ||
103 : | { | ||
104 : | { &MEDIATYPE_Video, &MEDIASUBTYPE_NULL } | ||
105 : | }; | ||
106 : | |||
107 : | |||
108 : | const AMOVIESETUP_PIN psudPins[] = | ||
109 : | { | ||
110 : | { | ||
111 : | L"Input", // String pin name | ||
112 : | FALSE, // Is it rendered | ||
113 : | FALSE, // Is it an output | ||
114 : | FALSE, // Allowed none | ||
115 : | FALSE, // Allowed many | ||
116 : | &CLSID_NULL, // Connects to filter | ||
117 : | L"Output", // Connects to pin | ||
118 : | sizeof(sudInputPinTypes) / sizeof(AMOVIESETUP_MEDIATYPE), // Number of types | ||
119 : | &sudInputPinTypes[0] // The pin details | ||
120 : | }, | ||
121 : | { | ||
122 : | L"Output", // String pin name | ||
123 : | FALSE, // Is it rendered | ||
124 : | TRUE, // Is it an output | ||
125 : | FALSE, // Allowed none | ||
126 : | FALSE, // Allowed many | ||
127 : | &CLSID_NULL, // Connects to filter | ||
128 : | L"Input", // Connects to pin | ||
129 : | sizeof(sudOutputPinTypes) / sizeof(AMOVIESETUP_MEDIATYPE), // Number of types | ||
130 : | sudOutputPinTypes // The pin details | ||
131 : | } | ||
132 : | }; | ||
133 : | |||
134 : | |||
135 : | const AMOVIESETUP_FILTER sudXvidDecoder = | ||
136 : | { | ||
137 : | &CLSID_XVID, // Filter CLSID | ||
138 : | XVID_NAME_L, // Filter name | ||
139 : | MERIT_PREFERRED, // Its merit | ||
140 : | sizeof(psudPins) / sizeof(AMOVIESETUP_PIN), // Number of pins | ||
141 : | psudPins // Pin details | ||
142 : | }; | ||
143 : | |||
144 : | |||
145 : | // List of class IDs and creator functions for the class factory. This | ||
146 : | // provides the link between the OLE entry point in the DLL and an object | ||
147 : | // being created. The class factory will call the static CreateInstance | ||
148 : | |||
149 : | CFactoryTemplate g_Templates[] = | ||
150 : | { | ||
151 : | { | ||
152 : | XVID_NAME_L, | ||
153 : | &CLSID_XVID, | ||
154 : | CXvidDecoder::CreateInstance, | ||
155 : | NULL, | ||
156 : | &sudXvidDecoder | ||
157 : | }, | ||
158 : | { | ||
159 : | XVID_NAME_L L"About", | ||
160 : | &CLSID_CABOUT, | ||
161 : | CAbout::CreateInstance | ||
162 : | } | ||
163 : | |||
164 : | }; | ||
165 : | |||
166 : | /* note: g_cTemplates must be global; used by strmbase.lib(dllentry.cpp,dllsetup.cpp) */ | ||
167 : | int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate); | ||
168 : | |||
169 : | Isibaar | 1896 | #ifdef XVID_USE_TRAYICON |
170 : | extern HINSTANCE g_xvid_hInst; | ||
171 : | edgomez | 1384 | |
172 : | Isibaar | 1896 | static int GUI_Page = 0; |
173 : | Isibaar | 1901 | static int Tray_Icon = 0; |
174 : | Isibaar | 1896 | extern "C" void CALLBACK Configure(HWND hWndParent, HINSTANCE hInstParent, LPSTR lpCmdLine, int nCmdShow ); |
175 : | |||
176 : | LRESULT CALLBACK msg_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | ||
177 : | { | ||
178 : | switch ( uMsg ) | ||
179 : | { | ||
180 : | case WM_ICONMESSAGE: | ||
181 : | switch(lParam) | ||
182 : | { | ||
183 : | case WM_LBUTTONDBLCLK: | ||
184 : | if (!GUI_Page) { | ||
185 : | GUI_Page = 1; | ||
186 : | Configure(hwnd, g_xvid_hInst, "", 1); | ||
187 : | GUI_Page = 0; | ||
188 : | } | ||
189 : | break; | ||
190 : | default: | ||
191 : | return DefWindowProc(hwnd, uMsg, wParam, lParam); | ||
192 : | }; | ||
193 : | break; | ||
194 : | Isibaar | 1901 | |
195 : | case WM_DESTROY: | ||
196 : | NOTIFYICONDATA nid; | ||
197 : | ZeroMemory(&nid,sizeof(NOTIFYICONDATA)); | ||
198 : | |||
199 : | nid.cbSize = NOTIFYICONDATA_V1_SIZE; | ||
200 : | nid.hWnd = hwnd; | ||
201 : | nid.uID = 1456; | ||
202 : | Isibaar | 1896 | |
203 : | Isibaar | 1901 | Shell_NotifyIcon(NIM_DELETE, &nid); |
204 : | Tray_Icon = 0; | ||
205 : | Isibaar | 1896 | default: |
206 : | return DefWindowProc(hwnd, uMsg, wParam, lParam); | ||
207 : | } | ||
208 : | |||
209 : | return TRUE; /* ok */ | ||
210 : | } | ||
211 : | #endif | ||
212 : | |||
213 : | edgomez | 1384 | STDAPI DllRegisterServer() |
214 : | { | ||
215 : | Isibaar | 1898 | #if defined(XVID_USE_MFT) |
216 : | int inputs_num = sizeof(sudInputPinTypes) / sizeof(AMOVIESETUP_MEDIATYPE); | ||
217 : | int outputs_num = sizeof(sudOutputPinTypes) / sizeof(AMOVIESETUP_MEDIATYPE); | ||
218 : | MFT_REGISTER_TYPE_INFO * mft_bs = new MFT_REGISTER_TYPE_INFO[inputs_num]; | ||
219 : | MFT_REGISTER_TYPE_INFO * mft_csp = new MFT_REGISTER_TYPE_INFO[outputs_num]; | ||
220 : | |||
221 : | { | ||
222 : | int i; | ||
223 : | for(i=0;i<inputs_num;i++) { | ||
224 : | mft_bs[i].guidMajorType = *sudInputPinTypes[i].clsMajorType; | ||
225 : | mft_bs[i].guidSubtype = *sudInputPinTypes[i].clsMinorType; | ||
226 : | } | ||
227 : | for(i=0;i<outputs_num;i++) { | ||
228 : | mft_csp[i].guidMajorType = *sudOutputPinTypes[i].clsMajorType; | ||
229 : | mft_csp[i].guidSubtype = *sudOutputPinTypes[i].clsMinorType; // MFT and AM GUIDs really the same? | ||
230 : | } | ||
231 : | } | ||
232 : | |||
233 : | /* Register the MFT decoder */ | ||
234 : | MFTRegister(CLSID_XVID, // CLSID | ||
235 : | MFT_CATEGORY_VIDEO_DECODER, // Category | ||
236 : | const_cast<LPWSTR>(XVID_NAME_L), // Friendly name | ||
237 : | 0, // Flags | ||
238 : | inputs_num, // Number of input types | ||
239 : | mft_bs, // Input types | ||
240 : | outputs_num, // Number of output types | ||
241 : | mft_csp, // Output types | ||
242 : | NULL // Attributes (optional) | ||
243 : | ); | ||
244 : | |||
245 : | delete[] mft_bs; | ||
246 : | delete[] mft_csp; | ||
247 : | #endif /* XVID_USE_MFT */ | ||
248 : | |||
249 : | edgomez | 1384 | return AMovieDllRegisterServer2( TRUE ); |
250 : | } | ||
251 : | |||
252 : | |||
253 : | STDAPI DllUnregisterServer() | ||
254 : | { | ||
255 : | Isibaar | 1898 | #if defined(XVID_USE_MFT) |
256 : | MFTUnregister(CLSID_XVID); | ||
257 : | #endif | ||
258 : | edgomez | 1384 | return AMovieDllRegisterServer2( FALSE ); |
259 : | } | ||
260 : | |||
261 : | |||
262 : | /* create instance */ | ||
263 : | |||
264 : | CUnknown * WINAPI CXvidDecoder::CreateInstance(LPUNKNOWN punk, HRESULT *phr) | ||
265 : | { | ||
266 : | CXvidDecoder * pNewObject = new CXvidDecoder(punk, phr); | ||
267 : | if (pNewObject == NULL) | ||
268 : | { | ||
269 : | *phr = E_OUTOFMEMORY; | ||
270 : | } | ||
271 : | return pNewObject; | ||
272 : | } | ||
273 : | |||
274 : | |||
275 : | /* query interfaces */ | ||
276 : | |||
277 : | STDMETHODIMP CXvidDecoder::NonDelegatingQueryInterface(REFIID riid, void **ppv) | ||
278 : | { | ||
279 : | CheckPointer(ppv, E_POINTER); | ||
280 : | |||
281 : | if (riid == IID_IXvidDecoder) | ||
282 : | { | ||
283 : | return GetInterface((IXvidDecoder *) this, ppv); | ||
284 : | } | ||
285 : | |||
286 : | if (riid == IID_ISpecifyPropertyPages) | ||
287 : | { | ||
288 : | return GetInterface((ISpecifyPropertyPages *) this, ppv); | ||
289 : | } | ||
290 : | |||
291 : | Isibaar | 1898 | #if defined(XVID_USE_MFT) |
292 : | if (riid == IID_IMFTransform) | ||
293 : | { | ||
294 : | return GetInterface((IMFTransform *) this, ppv); | ||
295 : | } | ||
296 : | #endif | ||
297 : | |||
298 : | edgomez | 1384 | return CVideoTransformFilter::NonDelegatingQueryInterface(riid, ppv); |
299 : | } | ||
300 : | |||
301 : | |||
302 : | |||
303 : | /* constructor */ | ||
304 : | |||
305 : | #define XVID_DLL_NAME "xvidcore.dll" | ||
306 : | |||
307 : | CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) : | ||
308 : | Isibaar | 1605 | CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID), m_hdll (NULL) |
309 : | edgomez | 1384 | { |
310 : | DPRINTF("Constructor"); | ||
311 : | |||
312 : | Isibaar | 1605 | xvid_decore_func = NULL; // Hmm, some strange errors appearing if I try to initialize... |
313 : | xvid_global_func = NULL; // ...this in constructor's init-list. So, they assigned here. | ||
314 : | |||
315 : | Isibaar | 1898 | #if defined(XVID_USE_MFT) |
316 : | InitializeCriticalSection(&m_mft_lock); | ||
317 : | m_pInputType = NULL; | ||
318 : | m_pOutputType = NULL; | ||
319 : | m_rtFrame = 0; | ||
320 : | m_duration = 0; | ||
321 : | m_discont = 0; | ||
322 : | m_frameRate.Denominator = 1; | ||
323 : | m_frameRate.Numerator = 1; | ||
324 : | #endif | ||
325 : | |||
326 : | Isibaar | 1605 | LoadRegistryInfo(); |
327 : | |||
328 : | *phr = OpenLib(); | ||
329 : | } | ||
330 : | |||
331 : | HRESULT CXvidDecoder::OpenLib() | ||
332 : | { | ||
333 : | DPRINTF("OpenLib"); | ||
334 : | |||
335 : | if (m_hdll != NULL) | ||
336 : | return E_UNEXPECTED; // Seems, that library already opened. | ||
337 : | |||
338 : | edgomez | 1384 | xvid_gbl_init_t init; |
339 : | memset(&init, 0, sizeof(init)); | ||
340 : | init.version = XVID_VERSION; | ||
341 : | |||
342 : | m_hdll = LoadLibrary(XVID_DLL_NAME); | ||
343 : | if (m_hdll == NULL) { | ||
344 : | DPRINTF("dll load failed"); | ||
345 : | syskin | 1498 | MessageBox(0, XVID_DLL_NAME " not found","Error", MB_TOPMOST); |
346 : | Isibaar | 1605 | return E_FAIL; |
347 : | edgomez | 1384 | } |
348 : | |||
349 : | xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"); | ||
350 : | if (xvid_global_func == NULL) { | ||
351 : | Isibaar | 1605 | FreeLibrary(m_hdll); |
352 : | m_hdll = NULL; | ||
353 : | syskin | 1498 | MessageBox(0, "xvid_global() not found", "Error", MB_TOPMOST); |
354 : | Isibaar | 1605 | return E_FAIL; |
355 : | edgomez | 1384 | } |
356 : | |||
357 : | xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore"); | ||
358 : | if (xvid_decore_func == NULL) { | ||
359 : | Isibaar | 1605 | xvid_global_func = NULL; |
360 : | FreeLibrary(m_hdll); | ||
361 : | m_hdll = NULL; | ||
362 : | syskin | 1498 | MessageBox(0, "xvid_decore() not found", "Error", MB_TOPMOST); |
363 : | Isibaar | 1605 | return E_FAIL; |
364 : | edgomez | 1384 | } |
365 : | |||
366 : | if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0) | ||
367 : | { | ||
368 : | Isibaar | 1605 | xvid_global_func = NULL; |
369 : | xvid_decore_func = NULL; | ||
370 : | FreeLibrary(m_hdll); | ||
371 : | m_hdll = NULL; | ||
372 : | syskin | 1498 | MessageBox(0, "xvid_global() failed", "Error", MB_TOPMOST); |
373 : | Isibaar | 1605 | return E_FAIL; |
374 : | edgomez | 1384 | } |
375 : | |||
376 : | memset(&m_create, 0, sizeof(m_create)); | ||
377 : | m_create.version = XVID_VERSION; | ||
378 : | m_create.handle = NULL; | ||
379 : | |||
380 : | memset(&m_frame, 0, sizeof(m_frame)); | ||
381 : | m_frame.version = XVID_VERSION; | ||
382 : | |||
383 : | USE_IYUV = false; | ||
384 : | USE_YV12 = false; | ||
385 : | USE_YUY2 = false; | ||
386 : | USE_YVYU = false; | ||
387 : | USE_UYVY = false; | ||
388 : | USE_RGB32 = false; | ||
389 : | USE_RGB24 = false; | ||
390 : | USE_RG555 = false; | ||
391 : | USE_RG565 = false; | ||
392 : | |||
393 : | switch ( g_config.nForceColorspace ) | ||
394 : | { | ||
395 : | case FORCE_NONE: | ||
396 : | USE_IYUV = true; | ||
397 : | USE_YV12 = true; | ||
398 : | USE_YUY2 = true; | ||
399 : | USE_YVYU = true; | ||
400 : | USE_UYVY = true; | ||
401 : | USE_RGB32 = true; | ||
402 : | USE_RGB24 = true; | ||
403 : | USE_RG555 = true; | ||
404 : | USE_RG565 = true; | ||
405 : | break; | ||
406 : | case FORCE_YV12: | ||
407 : | USE_IYUV = true; | ||
408 : | USE_YV12 = true; | ||
409 : | break; | ||
410 : | case FORCE_YUY2: | ||
411 : | USE_YUY2 = true; | ||
412 : | break; | ||
413 : | case FORCE_RGB24: | ||
414 : | USE_RGB24 = true; | ||
415 : | break; | ||
416 : | case FORCE_RGB32: | ||
417 : | USE_RGB32 = true; | ||
418 : | break; | ||
419 : | } | ||
420 : | syskin | 1488 | |
421 : | switch (g_config.aspect_ratio) | ||
422 : | { | ||
423 : | syskin | 1498 | case 0: |
424 : | case 1: | ||
425 : | syskin | 1488 | break; |
426 : | syskin | 1498 | case 2: |
427 : | syskin | 1488 | ar_x = 4; |
428 : | ar_y = 3; | ||
429 : | break; | ||
430 : | syskin | 1498 | case 3: |
431 : | syskin | 1488 | ar_x = 16; |
432 : | ar_y = 9; | ||
433 : | break; | ||
434 : | syskin | 1498 | case 4: |
435 : | syskin | 1488 | ar_x = 47; |
436 : | ar_y = 20; | ||
437 : | break; | ||
438 : | } | ||
439 : | Isibaar | 1605 | |
440 : | return S_OK; | ||
441 : | edgomez | 1384 | } |
442 : | |||
443 : | syskin | 1428 | void CXvidDecoder::CloseLib() |
444 : | edgomez | 1384 | { |
445 : | Isibaar | 1605 | DPRINTF("CloseLib"); |
446 : | edgomez | 1384 | |
447 : | Isibaar | 1605 | if ((m_create.handle != NULL) && (xvid_decore_func != NULL)) |
448 : | { | ||
449 : | edgomez | 1384 | xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0); |
450 : | m_create.handle = NULL; | ||
451 : | } | ||
452 : | |||
453 : | syskin | 1428 | if (m_hdll != NULL) { |
454 : | edgomez | 1384 | FreeLibrary(m_hdll); |
455 : | m_hdll = NULL; | ||
456 : | } | ||
457 : | Isibaar | 1605 | xvid_decore_func = NULL; |
458 : | xvid_global_func = NULL; | ||
459 : | edgomez | 1384 | } |
460 : | |||
461 : | syskin | 1428 | /* destructor */ |
462 : | edgomez | 1384 | |
463 : | syskin | 1428 | CXvidDecoder::~CXvidDecoder() |
464 : | { | ||
465 : | Isibaar | 1605 | DPRINTF("Destructor"); |
466 : | Isibaar | 1896 | |
467 : | #ifdef XVID_USE_TRAYICON | ||
468 : | Isibaar | 1901 | if (Tray_Icon) { /* Destroy tray icon */ |
469 : | Isibaar | 1896 | NOTIFYICONDATA nid; |
470 : | Isibaar | 1901 | ZeroMemory(&nid,sizeof(NOTIFYICONDATA)); |
471 : | |||
472 : | nid.cbSize = NOTIFYICONDATA_V1_SIZE; | ||
473 : | Isibaar | 1896 | nid.hWnd = MSG_hwnd; |
474 : | Isibaar | 1901 | nid.uID = 1456; |
475 : | Isibaar | 1896 | |
476 : | Isibaar | 1901 | Shell_NotifyIcon(NIM_DELETE, &nid); |
477 : | Tray_Icon = 0; | ||
478 : | Isibaar | 1896 | } |
479 : | #endif | ||
480 : | Isibaar | 1898 | |
481 : | Isibaar | 1901 | /* Close xvidcore library */ |
482 : | CloseLib(); | ||
483 : | |||
484 : | Isibaar | 1898 | #if defined(XVID_USE_MFT) |
485 : | DeleteCriticalSection(&m_mft_lock); | ||
486 : | #endif | ||
487 : | syskin | 1428 | } |
488 : | edgomez | 1384 | |
489 : | syskin | 1428 | |
490 : | |||
491 : | edgomez | 1384 | /* check input type */ |
492 : | |||
493 : | HRESULT CXvidDecoder::CheckInputType(const CMediaType * mtIn) | ||
494 : | { | ||
495 : | DPRINTF("CheckInputType"); | ||
496 : | BITMAPINFOHEADER * hdr; | ||
497 : | syskin | 1498 | |
498 : | ar_x = ar_y = 0; | ||
499 : | edgomez | 1384 | |
500 : | if (*mtIn->Type() != MEDIATYPE_Video) | ||
501 : | { | ||
502 : | DPRINTF("Error: Unknown Type"); | ||
503 : | syskin | 1428 | CloseLib(); |
504 : | edgomez | 1384 | return VFW_E_TYPE_NOT_ACCEPTED; |
505 : | } | ||
506 : | |||
507 : | Isibaar | 1605 | if (m_hdll == NULL) |
508 : | { | ||
509 : | HRESULT hr = OpenLib(); | ||
510 : | |||
511 : | if (FAILED(hr) || (m_hdll == NULL)) // Paranoid checks. | ||
512 : | return VFW_E_TYPE_NOT_ACCEPTED; | ||
513 : | } | ||
514 : | |||
515 : | edgomez | 1384 | if (*mtIn->FormatType() == FORMAT_VideoInfo) |
516 : | { | ||
517 : | VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format(); | ||
518 : | hdr = &vih->bmiHeader; | ||
519 : | } | ||
520 : | else if (*mtIn->FormatType() == FORMAT_VideoInfo2) | ||
521 : | { | ||
522 : | VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format(); | ||
523 : | hdr = &vih2->bmiHeader; | ||
524 : | syskin | 1498 | if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { |
525 : | syskin | 1488 | ar_x = vih2->dwPictAspectRatioX; |
526 : | ar_y = vih2->dwPictAspectRatioY; | ||
527 : | } | ||
528 : | edgomez | 1384 | DPRINTF("VIDEOINFOHEADER2 AR: %d:%d", ar_x, ar_y); |
529 : | } | ||
530 : | suxen_drol | 1647 | else if (*mtIn->FormatType() == FORMAT_MPEG2Video) { |
531 : | MPEG2VIDEOINFO * mpgvi = (MPEG2VIDEOINFO*)mtIn->Format(); | ||
532 : | VIDEOINFOHEADER2 * vih2 = &mpgvi->hdr; | ||
533 : | hdr = &vih2->bmiHeader; | ||
534 : | if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { | ||
535 : | ar_x = vih2->dwPictAspectRatioX; | ||
536 : | ar_y = vih2->dwPictAspectRatioY; | ||
537 : | } | ||
538 : | DPRINTF("VIDEOINFOHEADER2 AR: %d:%d", ar_x, ar_y); | ||
539 : | |||
540 : | /* haali media splitter reports VOL information in the format header */ | ||
541 : | |||
542 : | if (mpgvi->cbSequenceHeader>0) { | ||
543 : | |||
544 : | xvid_dec_stats_t stats; | ||
545 : | memset(&stats, 0, sizeof(stats)); | ||
546 : | stats.version = XVID_VERSION; | ||
547 : | |||
548 : | if (m_create.handle == NULL) { | ||
549 : | if (xvid_decore_func == NULL) | ||
550 : | return E_FAIL; | ||
551 : | if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0) { | ||
552 : | DPRINTF("*** XVID_DEC_CREATE error"); | ||
553 : | Isibaar | 1868 | return E_FAIL; |
554 : | suxen_drol | 1647 | } |
555 : | } | ||
556 : | |||
557 : | m_frame.general = 0; | ||
558 : | m_frame.bitstream = (void*)mpgvi->dwSequenceHeader; | ||
559 : | m_frame.length = mpgvi->cbSequenceHeader; | ||
560 : | m_frame.output.csp = XVID_CSP_NULL; | ||
561 : | |||
562 : | Isibaar | 1868 | int ret = 0; |
563 : | if ((ret=xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats)) >= 0) { | ||
564 : | suxen_drol | 1647 | /* honour video dimensions reported in VOL header */ |
565 : | if (stats.type == XVID_TYPE_VOL) { | ||
566 : | hdr->biWidth = stats.data.vol.width; | ||
567 : | hdr->biHeight = stats.data.vol.height; | ||
568 : | Isibaar | 1898 | } |
569 : | } | ||
570 : | Isibaar | 1868 | if (ret == XVID_ERR_MEMORY) return E_FAIL; |
571 : | Isibaar | 1898 | } |
572 : | suxen_drol | 1647 | } |
573 : | Isibaar | 1898 | else |
574 : | { | ||
575 : | edgomez | 1384 | DPRINTF("Error: Unknown FormatType"); |
576 : | syskin | 1428 | CloseLib(); |
577 : | edgomez | 1384 | return VFW_E_TYPE_NOT_ACCEPTED; |
578 : | Isibaar | 1898 | } |
579 : | if (hdr->biHeight < 0) | ||
580 : | { | ||
581 : | DPRINTF("colorspace: inverted input format not supported"); | ||
582 : | } | ||
583 : | |||
584 : | m_create.width = hdr->biWidth; | ||
585 : | m_create.height = hdr->biHeight; | ||
586 : | |||
587 : | switch(hdr->biCompression) | ||
588 : | { | ||
589 : | suxen_drol | 1647 | case FOURCC_mp4v: |
590 : | edgomez | 1384 | case FOURCC_MP4V: |
591 : | syskin | 1428 | if (!(g_config.supported_4cc & SUPPORT_MP4V)) { |
592 : | CloseLib(); | ||
593 : | return VFW_E_TYPE_NOT_ACCEPTED; | ||
594 : | } | ||
595 : | edgomez | 1384 | break; |
596 : | case FOURCC_DIVX : | ||
597 : | syskin | 1428 | if (!(g_config.supported_4cc & SUPPORT_DIVX)) { |
598 : | CloseLib(); | ||
599 : | return VFW_E_TYPE_NOT_ACCEPTED; | ||
600 : | } | ||
601 : | edgomez | 1384 | break; |
602 : | case FOURCC_DX50 : | ||
603 : | syskin | 1428 | if (!(g_config.supported_4cc & SUPPORT_DX50)) { |
604 : | CloseLib(); | ||
605 : | return VFW_E_TYPE_NOT_ACCEPTED; | ||
606 : | } | ||
607 : | edgomez | 1384 | case FOURCC_XVID : |
608 : | break; | ||
609 : | |||
610 : | |||
611 : | default : | ||
612 : | DPRINTF("Unknown fourcc: 0x%08x (%c%c%c%c)", | ||
613 : | hdr->biCompression, | ||
614 : | (hdr->biCompression)&0xff, | ||
615 : | (hdr->biCompression>>8)&0xff, | ||
616 : | (hdr->biCompression>>16)&0xff, | ||
617 : | (hdr->biCompression>>24)&0xff); | ||
618 : | syskin | 1428 | CloseLib(); |
619 : | edgomez | 1384 | return VFW_E_TYPE_NOT_ACCEPTED; |
620 : | } | ||
621 : | Isibaar | 1890 | |
622 : | m_create.fourcc = hdr->biCompression; | ||
623 : | |||
624 : | edgomez | 1384 | return S_OK; |
625 : | } | ||
626 : | |||
627 : | |||
628 : | /* get list of supported output colorspaces */ | ||
629 : | |||
630 : | |||
631 : | HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut) | ||
632 : | { | ||
633 : | BITMAPINFOHEADER * bmih; | ||
634 : | DPRINTF("GetMediaType"); | ||
635 : | |||
636 : | if (m_pInput->IsConnected() == FALSE) | ||
637 : | { | ||
638 : | return E_UNEXPECTED; | ||
639 : | } | ||
640 : | |||
641 : | if (!g_config.videoinfo_compat) { | ||
642 : | VIDEOINFOHEADER2 * vih = (VIDEOINFOHEADER2 *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER2)); | ||
643 : | if (vih == NULL) return E_OUTOFMEMORY; | ||
644 : | |||
645 : | ZeroMemory(vih, sizeof (VIDEOINFOHEADER2)); | ||
646 : | bmih = &(vih->bmiHeader); | ||
647 : | mtOut->SetFormatType(&FORMAT_VideoInfo2); | ||
648 : | |||
649 : | if (ar_x != 0 && ar_y != 0) { | ||
650 : | vih->dwPictAspectRatioX = ar_x; | ||
651 : | vih->dwPictAspectRatioY = ar_y; | ||
652 : | syskin | 1498 | forced_ar = true; |
653 : | edgomez | 1384 | } else { // just to be safe |
654 : | vih->dwPictAspectRatioX = m_create.width; | ||
655 : | vih->dwPictAspectRatioY = abs(m_create.height); | ||
656 : | syskin | 1498 | forced_ar = false; |
657 : | } | ||
658 : | edgomez | 1384 | } else { |
659 : | |||
660 : | VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER)); | ||
661 : | if (vih == NULL) return E_OUTOFMEMORY; | ||
662 : | |||
663 : | ZeroMemory(vih, sizeof (VIDEOINFOHEADER)); | ||
664 : | bmih = &(vih->bmiHeader); | ||
665 : | mtOut->SetFormatType(&FORMAT_VideoInfo); | ||
666 : | } | ||
667 : | |||
668 : | bmih->biSize = sizeof(BITMAPINFOHEADER); | ||
669 : | bmih->biWidth = m_create.width; | ||
670 : | bmih->biHeight = m_create.height; | ||
671 : | bmih->biPlanes = 1; | ||
672 : | |||
673 : | if (iPosition < 0) return E_INVALIDARG; | ||
674 : | |||
675 : | switch(iPosition) | ||
676 : | { | ||
677 : | |||
678 : | case 0: | ||
679 : | if ( USE_YUY2 ) | ||
680 : | { | ||
681 : | bmih->biCompression = MEDIASUBTYPE_YUY2.Data1; | ||
682 : | bmih->biBitCount = 16; | ||
683 : | mtOut->SetSubtype(&MEDIASUBTYPE_YUY2); | ||
684 : | break; | ||
685 : | } | ||
686 : | case 1 : | ||
687 : | if ( USE_YVYU ) | ||
688 : | { | ||
689 : | bmih->biCompression = MEDIASUBTYPE_YVYU.Data1; | ||
690 : | bmih->biBitCount = 16; | ||
691 : | mtOut->SetSubtype(&MEDIASUBTYPE_YVYU); | ||
692 : | break; | ||
693 : | } | ||
694 : | case 2 : | ||
695 : | if ( USE_UYVY ) | ||
696 : | { | ||
697 : | bmih->biCompression = MEDIASUBTYPE_UYVY.Data1; | ||
698 : | bmih->biBitCount = 16; | ||
699 : | mtOut->SetSubtype(&MEDIASUBTYPE_UYVY); | ||
700 : | break; | ||
701 : | } | ||
702 : | case 3 : | ||
703 : | if ( USE_IYUV ) | ||
704 : | { | ||
705 : | bmih->biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1; | ||
706 : | bmih->biBitCount = 12; | ||
707 : | mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV); | ||
708 : | break; | ||
709 : | } | ||
710 : | case 4 : | ||
711 : | if ( USE_YV12 ) | ||
712 : | { | ||
713 : | bmih->biCompression = MEDIASUBTYPE_YV12.Data1; | ||
714 : | bmih->biBitCount = 12; | ||
715 : | mtOut->SetSubtype(&MEDIASUBTYPE_YV12); | ||
716 : | break; | ||
717 : | } | ||
718 : | case 5 : | ||
719 : | if ( USE_RGB32 ) | ||
720 : | { | ||
721 : | bmih->biCompression = BI_RGB; | ||
722 : | bmih->biBitCount = 32; | ||
723 : | mtOut->SetSubtype(&MEDIASUBTYPE_RGB32); | ||
724 : | break; | ||
725 : | } | ||
726 : | case 6 : | ||
727 : | if ( USE_RGB24 ) | ||
728 : | { | ||
729 : | bmih->biCompression = BI_RGB; | ||
730 : | bmih->biBitCount = 24; | ||
731 : | mtOut->SetSubtype(&MEDIASUBTYPE_RGB24); | ||
732 : | break; | ||
733 : | } | ||
734 : | case 7 : | ||
735 : | if ( USE_RG555 ) | ||
736 : | { | ||
737 : | bmih->biCompression = BI_RGB; | ||
738 : | bmih->biBitCount = 16; | ||
739 : | mtOut->SetSubtype(&MEDIASUBTYPE_RGB555); | ||
740 : | break; | ||
741 : | } | ||
742 : | case 8 : | ||
743 : | if ( USE_RG565 ) | ||
744 : | { | ||
745 : | bmih->biCompression = BI_RGB; | ||
746 : | bmih->biBitCount = 16; | ||
747 : | mtOut->SetSubtype(&MEDIASUBTYPE_RGB565); | ||
748 : | break; | ||
749 : | } | ||
750 : | default : | ||
751 : | return VFW_S_NO_MORE_ITEMS; | ||
752 : | } | ||
753 : | |||
754 : | bmih->biSizeImage = GetBitmapSize(bmih); | ||
755 : | |||
756 : | mtOut->SetType(&MEDIATYPE_Video); | ||
757 : | mtOut->SetTemporalCompression(FALSE); | ||
758 : | mtOut->SetSampleSize(bmih->biSizeImage); | ||
759 : | |||
760 : | return S_OK; | ||
761 : | } | ||
762 : | |||
763 : | |||
764 : | /* (internal function) change colorspace */ | ||
765 : | suxen_drol | 1558 | #define CALC_BI_STRIDE(width,bitcount) ((((width * bitcount) + 31) & ~31) >> 3) |
766 : | edgomez | 1384 | |
767 : | HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format) | ||
768 : | { | ||
769 : | suxen_drol | 1558 | DWORD biWidth; |
770 : | |||
771 : | edgomez | 1384 | if (formattype == FORMAT_VideoInfo) |
772 : | { | ||
773 : | VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format; | ||
774 : | suxen_drol | 1558 | biWidth = vih->bmiHeader.biWidth; |
775 : | Isibaar | 1898 | out_stride = CALC_BI_STRIDE(vih->bmiHeader.biWidth, vih->bmiHeader.biBitCount); |
776 : | edgomez | 1384 | rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); |
777 : | } | ||
778 : | else if (formattype == FORMAT_VideoInfo2) | ||
779 : | { | ||
780 : | VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format; | ||
781 : | suxen_drol | 1558 | biWidth = vih2->bmiHeader.biWidth; |
782 : | Isibaar | 1898 | out_stride = CALC_BI_STRIDE(vih2->bmiHeader.biWidth, vih2->bmiHeader.biBitCount); |
783 : | edgomez | 1384 | rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); |
784 : | } | ||
785 : | else | ||
786 : | { | ||
787 : | return S_FALSE; | ||
788 : | } | ||
789 : | |||
790 : | if (subtype == CLSID_MEDIASUBTYPE_IYUV) | ||
791 : | { | ||
792 : | DPRINTF("IYUV"); | ||
793 : | rgb_flip = 0; | ||
794 : | m_frame.output.csp = XVID_CSP_I420; | ||
795 : | Isibaar | 1898 | out_stride = CALC_BI_STRIDE(biWidth, 8); /* planar format fix */ |
796 : | edgomez | 1384 | } |
797 : | else if (subtype == MEDIASUBTYPE_YV12) | ||
798 : | { | ||
799 : | DPRINTF("YV12"); | ||
800 : | rgb_flip = 0; | ||
801 : | m_frame.output.csp = XVID_CSP_YV12; | ||
802 : | Isibaar | 1898 | out_stride = CALC_BI_STRIDE(biWidth, 8); /* planar format fix */ |
803 : | edgomez | 1384 | } |
804 : | else if (subtype == MEDIASUBTYPE_YUY2) | ||
805 : | { | ||
806 : | DPRINTF("YUY2"); | ||
807 : | rgb_flip = 0; | ||
808 : | m_frame.output.csp = XVID_CSP_YUY2; | ||
809 : | } | ||
810 : | else if (subtype == MEDIASUBTYPE_YVYU) | ||
811 : | { | ||
812 : | DPRINTF("YVYU"); | ||
813 : | rgb_flip = 0; | ||
814 : | m_frame.output.csp = XVID_CSP_YVYU; | ||
815 : | } | ||
816 : | else if (subtype == MEDIASUBTYPE_UYVY) | ||
817 : | { | ||
818 : | DPRINTF("UYVY"); | ||
819 : | rgb_flip = 0; | ||
820 : | m_frame.output.csp = XVID_CSP_UYVY; | ||
821 : | } | ||
822 : | else if (subtype == MEDIASUBTYPE_RGB32) | ||
823 : | { | ||
824 : | DPRINTF("RGB32"); | ||
825 : | m_frame.output.csp = rgb_flip | XVID_CSP_BGRA; | ||
826 : | } | ||
827 : | else if (subtype == MEDIASUBTYPE_RGB24) | ||
828 : | { | ||
829 : | DPRINTF("RGB24"); | ||
830 : | m_frame.output.csp = rgb_flip | XVID_CSP_BGR; | ||
831 : | } | ||
832 : | else if (subtype == MEDIASUBTYPE_RGB555) | ||
833 : | { | ||
834 : | DPRINTF("RGB555"); | ||
835 : | m_frame.output.csp = rgb_flip | XVID_CSP_RGB555; | ||
836 : | } | ||
837 : | else if (subtype == MEDIASUBTYPE_RGB565) | ||
838 : | { | ||
839 : | DPRINTF("RGB565"); | ||
840 : | m_frame.output.csp = rgb_flip | XVID_CSP_RGB565; | ||
841 : | } | ||
842 : | else if (subtype == GUID_NULL) | ||
843 : | { | ||
844 : | m_frame.output.csp = XVID_CSP_NULL; | ||
845 : | } | ||
846 : | else | ||
847 : | { | ||
848 : | return S_FALSE; | ||
849 : | } | ||
850 : | |||
851 : | return S_OK; | ||
852 : | } | ||
853 : | |||
854 : | |||
855 : | /* set output colorspace */ | ||
856 : | |||
857 : | HRESULT CXvidDecoder::SetMediaType(PIN_DIRECTION direction, const CMediaType *pmt) | ||
858 : | { | ||
859 : | DPRINTF("SetMediaType"); | ||
860 : | |||
861 : | if (direction == PINDIR_OUTPUT) | ||
862 : | { | ||
863 : | return ChangeColorspace(*pmt->Subtype(), *pmt->FormatType(), pmt->Format()); | ||
864 : | } | ||
865 : | |||
866 : | return S_OK; | ||
867 : | } | ||
868 : | |||
869 : | |||
870 : | /* check input<->output compatiblity */ | ||
871 : | |||
872 : | HRESULT CXvidDecoder::CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut) | ||
873 : | { | ||
874 : | DPRINTF("CheckTransform"); | ||
875 : | Isibaar | 1896 | |
876 : | edgomez | 1384 | return S_OK; |
877 : | } | ||
878 : | |||
879 : | Isibaar | 1896 | /* input/output pin connection complete */ |
880 : | edgomez | 1384 | |
881 : | Isibaar | 1896 | HRESULT CXvidDecoder::CompleteConnect(PIN_DIRECTION direction, IPin *pReceivePin) |
882 : | { | ||
883 : | DPRINTF("CompleteConnect"); | ||
884 : | |||
885 : | #ifdef XVID_USE_TRAYICON | ||
886 : | Isibaar | 1901 | if ((direction == PINDIR_OUTPUT) && (Tray_Icon == 0)) |
887 : | Isibaar | 1896 | { |
888 : | WNDCLASSEX wc; | ||
889 : | |||
890 : | wc.cbSize = sizeof(WNDCLASSEX); | ||
891 : | wc.lpfnWndProc = msg_proc; | ||
892 : | wc.style = CS_HREDRAW | CS_VREDRAW; | ||
893 : | wc.cbWndExtra = 0; | ||
894 : | wc.cbClsExtra = 0; | ||
895 : | wc.hInstance = (HINSTANCE) g_xvid_hInst; | ||
896 : | wc.hbrBackground = (HBRUSH) GetStockObject(NULL_BRUSH); | ||
897 : | wc.lpszMenuName = NULL; | ||
898 : | wc.lpszClassName = "XVID_MSG_WINDOW"; | ||
899 : | wc.hIcon = NULL; | ||
900 : | wc.hIconSm = NULL; | ||
901 : | wc.hCursor = NULL; | ||
902 : | RegisterClassEx(&wc); | ||
903 : | |||
904 : | MSG_hwnd = CreateWindowEx(0, "XVID_MSG_WINDOW", NULL, 0, CW_USEDEFAULT, | ||
905 : | CW_USEDEFAULT, 0, 0, HWND_MESSAGE, NULL, (HINSTANCE) g_xvid_hInst, NULL); | ||
906 : | |||
907 : | /* display the tray icon */ | ||
908 : | NOTIFYICONDATA nid; | ||
909 : | Isibaar | 1901 | ZeroMemory(&nid,sizeof(NOTIFYICONDATA)); |
910 : | |||
911 : | nid.cbSize = NOTIFYICONDATA_V1_SIZE; | ||
912 : | Isibaar | 1896 | nid.hWnd = MSG_hwnd; |
913 : | Isibaar | 1901 | nid.uID = 1456; |
914 : | Isibaar | 1896 | nid.uCallbackMessage = WM_ICONMESSAGE; |
915 : | nid.hIcon = LoadIcon(g_xvid_hInst, MAKEINTRESOURCE(IDI_ICON)); | ||
916 : | strcpy_s(nid.szTip, 19, "Xvid Video Decoder"); | ||
917 : | nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; | ||
918 : | |||
919 : | Shell_NotifyIcon(NIM_ADD, &nid); | ||
920 : | Isibaar | 1901 | |
921 : | DestroyIcon(nid.hIcon); | ||
922 : | Tray_Icon = 1; | ||
923 : | Isibaar | 1896 | } |
924 : | #endif | ||
925 : | |||
926 : | return S_OK; | ||
927 : | } | ||
928 : | |||
929 : | /* input/output pin disconnected */ | ||
930 : | HRESULT CXvidDecoder::BreakConnect(PIN_DIRECTION direction) | ||
931 : | { | ||
932 : | DPRINTF("BreakConnect"); | ||
933 : | |||
934 : | return S_OK; | ||
935 : | } | ||
936 : | |||
937 : | edgomez | 1384 | /* alloc output buffer */ |
938 : | |||
939 : | HRESULT CXvidDecoder::DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest) | ||
940 : | { | ||
941 : | DPRINTF("DecideBufferSize"); | ||
942 : | HRESULT result; | ||
943 : | ALLOCATOR_PROPERTIES ppropActual; | ||
944 : | |||
945 : | if (m_pInput->IsConnected() == FALSE) | ||
946 : | { | ||
947 : | return E_UNEXPECTED; | ||
948 : | } | ||
949 : | |||
950 : | ppropInputRequest->cBuffers = 1; | ||
951 : | ppropInputRequest->cbBuffer = m_create.width * m_create.height * 4; | ||
952 : | // cbAlign causes problems with the resize filter */ | ||
953 : | // ppropInputRequest->cbAlign = 16; | ||
954 : | ppropInputRequest->cbPrefix = 0; | ||
955 : | |||
956 : | result = pAlloc->SetProperties(ppropInputRequest, &ppropActual); | ||
957 : | if (result != S_OK) | ||
958 : | { | ||
959 : | return result; | ||
960 : | } | ||
961 : | |||
962 : | if (ppropActual.cbBuffer < ppropInputRequest->cbBuffer) | ||
963 : | { | ||
964 : | return E_FAIL; | ||
965 : | } | ||
966 : | |||
967 : | return S_OK; | ||
968 : | } | ||
969 : | |||
970 : | |||
971 : | /* decode frame */ | ||
972 : | |||
973 : | HRESULT CXvidDecoder::Transform(IMediaSample *pIn, IMediaSample *pOut) | ||
974 : | { | ||
975 : | DPRINTF("Transform"); | ||
976 : | xvid_dec_stats_t stats; | ||
977 : | int length; | ||
978 : | |||
979 : | memset(&stats, 0, sizeof(stats)); | ||
980 : | stats.version = XVID_VERSION; | ||
981 : | |||
982 : | if (m_create.handle == NULL) | ||
983 : | { | ||
984 : | Isibaar | 1605 | if (xvid_decore_func == NULL) |
985 : | return E_FAIL; | ||
986 : | |||
987 : | edgomez | 1384 | if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0) |
988 : | { | ||
989 : | DPRINTF("*** XVID_DEC_CREATE error"); | ||
990 : | Isibaar | 1868 | return E_FAIL; |
991 : | edgomez | 1384 | } |
992 : | } | ||
993 : | |||
994 : | AM_MEDIA_TYPE * mtOut; | ||
995 : | pOut->GetMediaType(&mtOut); | ||
996 : | if (mtOut != NULL) | ||
997 : | { | ||
998 : | HRESULT result; | ||
999 : | |||
1000 : | result = ChangeColorspace(mtOut->subtype, mtOut->formattype, mtOut->pbFormat); | ||
1001 : | DeleteMediaType(mtOut); | ||
1002 : | |||
1003 : | if (result != S_OK) | ||
1004 : | { | ||
1005 : | DPRINTF("*** ChangeColorspace error"); | ||
1006 : | return result; | ||
1007 : | } | ||
1008 : | } | ||
1009 : | |||
1010 : | m_frame.length = pIn->GetActualDataLength(); | ||
1011 : | if (pIn->GetPointer((BYTE**)&m_frame.bitstream) != S_OK) | ||
1012 : | { | ||
1013 : | return S_FALSE; | ||
1014 : | } | ||
1015 : | |||
1016 : | if (pOut->GetPointer((BYTE**)&m_frame.output.plane[0]) != S_OK) | ||
1017 : | { | ||
1018 : | return S_FALSE; | ||
1019 : | } | ||
1020 : | |||
1021 : | m_frame.general = XVID_LOWDELAY; | ||
1022 : | |||
1023 : | if (pIn->IsDiscontinuity() == S_OK) | ||
1024 : | syskin | 1427 | m_frame.general |= XVID_DISCONTINUITY; |
1025 : | edgomez | 1384 | |
1026 : | if (g_config.nDeblock_Y) | ||
1027 : | m_frame.general |= XVID_DEBLOCKY; | ||
1028 : | |||
1029 : | if (g_config.nDeblock_UV) | ||
1030 : | m_frame.general |= XVID_DEBLOCKUV; | ||
1031 : | syskin | 1437 | |
1032 : | if (g_config.nDering_Y) | ||
1033 : | m_frame.general |= XVID_DERINGY; | ||
1034 : | |||
1035 : | if (g_config.nDering_UV) | ||
1036 : | m_frame.general |= XVID_DERINGUV; | ||
1037 : | |||
1038 : | edgomez | 1384 | if (g_config.nFilmEffect) |
1039 : | m_frame.general |= XVID_FILMEFFECT; | ||
1040 : | |||
1041 : | suxen_drol | 1397 | m_frame.brightness = g_config.nBrightness; |
1042 : | |||
1043 : | edgomez | 1384 | m_frame.output.csp &= ~XVID_CSP_VFLIP; |
1044 : | m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0); | ||
1045 : | Isibaar | 1898 | m_frame.output.stride[0] = out_stride; |
1046 : | edgomez | 1384 | |
1047 : | Isibaar | 1605 | // Paranoid check. |
1048 : | if (xvid_decore_func == NULL) | ||
1049 : | return E_FAIL; | ||
1050 : | syskin | 1498 | |
1051 : | |||
1052 : | edgomez | 1384 | repeat : |
1053 : | |||
1054 : | if (pIn->IsPreroll() != S_OK) | ||
1055 : | { | ||
1056 : | length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); | ||
1057 : | Isibaar | 1868 | |
1058 : | if (length == XVID_ERR_MEMORY) | ||
1059 : | return E_FAIL; | ||
1060 : | else if (length < 0) | ||
1061 : | edgomez | 1384 | { |
1062 : | DPRINTF("*** XVID_DEC_DECODE"); | ||
1063 : | return S_FALSE; | ||
1064 : | syskin | 1498 | } else |
1065 : | if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1 && forced_ar == false) { | ||
1066 : | suxen_drol | 1633 | |
1067 : | if (stats.type != XVID_TYPE_NOTHING) { /* dont attempt to set vmr aspect ratio if no frame was returned by decoder */ | ||
1068 : | syskin | 1498 | // inspired by minolta! works for VMR 7 + 9 |
1069 : | IMediaSample2 *pOut2 = NULL; | ||
1070 : | AM_SAMPLE2_PROPERTIES outProp2; | ||
1071 : | if (SUCCEEDED(pOut->QueryInterface(IID_IMediaSample2, (void **)&pOut2)) && | ||
1072 : | SUCCEEDED(pOut2->GetProperties(FIELD_OFFSET(AM_SAMPLE2_PROPERTIES, tStart), (PBYTE)&outProp2))) | ||
1073 : | { | ||
1074 : | CMediaType mtOut2 = m_pOutput->CurrentMediaType(); | ||
1075 : | VIDEOINFOHEADER2* vihOut2 = (VIDEOINFOHEADER2*)mtOut2.Format(); | ||
1076 : | suxen_drol | 1502 | |
1077 : | if (*mtOut2.FormatType() == FORMAT_VideoInfo2 && | ||
1078 : | vihOut2->dwPictAspectRatioX != ar_x && vihOut2->dwPictAspectRatioY != ar_y) | ||
1079 : | syskin | 1498 | { |
1080 : | vihOut2->dwPictAspectRatioX = ar_x; | ||
1081 : | vihOut2->dwPictAspectRatioY = ar_y; | ||
1082 : | pOut2->SetMediaType(&mtOut2); | ||
1083 : | m_pOutput->SetMediaType(&mtOut2); | ||
1084 : | } | ||
1085 : | pOut2->Release(); | ||
1086 : | } | ||
1087 : | suxen_drol | 1633 | } |
1088 : | edgomez | 1384 | } |
1089 : | } | ||
1090 : | else | ||
1091 : | { /* Preroll frame - won't be displayed */ | ||
1092 : | int tmp = m_frame.output.csp; | ||
1093 : | int tmp_gen = m_frame.general; | ||
1094 : | |||
1095 : | m_frame.output.csp = XVID_CSP_NULL; | ||
1096 : | |||
1097 : | /* Disable postprocessing to speed-up seeking */ | ||
1098 : | m_frame.general &= ~XVID_DEBLOCKY; | ||
1099 : | m_frame.general &= ~XVID_DEBLOCKUV; | ||
1100 : | Isibaar | 1605 | /*m_frame.general &= ~XVID_DERING;*/ |
1101 : | edgomez | 1384 | m_frame.general &= ~XVID_FILMEFFECT; |
1102 : | |||
1103 : | length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); | ||
1104 : | Isibaar | 1868 | if (length == XVID_ERR_MEMORY) |
1105 : | return E_FAIL; | ||
1106 : | else if (length < 0) | ||
1107 : | edgomez | 1384 | { |
1108 : | DPRINTF("*** XVID_DEC_DECODE"); | ||
1109 : | return S_FALSE; | ||
1110 : | } | ||
1111 : | |||
1112 : | m_frame.output.csp = tmp; | ||
1113 : | m_frame.general = tmp_gen; | ||
1114 : | } | ||
1115 : | |||
1116 : | if (stats.type == XVID_TYPE_NOTHING && length > 0) { | ||
1117 : | edgomez | 1432 | DPRINTF(" B-Frame decoder lag"); |
1118 : | edgomez | 1384 | return S_FALSE; |
1119 : | } | ||
1120 : | |||
1121 : | |||
1122 : | if (stats.type == XVID_TYPE_VOL) | ||
1123 : | { | ||
1124 : | if (stats.data.vol.width != m_create.width || | ||
1125 : | stats.data.vol.height != m_create.height) | ||
1126 : | { | ||
1127 : | DPRINTF("TODO: auto-resize"); | ||
1128 : | return S_FALSE; | ||
1129 : | } | ||
1130 : | syskin | 1498 | |
1131 : | edgomez | 1384 | pOut->SetSyncPoint(TRUE); |
1132 : | |||
1133 : | syskin | 1498 | if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { /* auto */ |
1134 : | int par_x, par_y; | ||
1135 : | if (stats.data.vol.par == XVID_PAR_EXT) { | ||
1136 : | par_x = stats.data.vol.par_width; | ||
1137 : | par_y = stats.data.vol.par_height; | ||
1138 : | } else { | ||
1139 : | syskin | 1529 | par_x = PARS[stats.data.vol.par-1][0]; |
1140 : | par_y = PARS[stats.data.vol.par-1][1]; | ||
1141 : | syskin | 1498 | } |
1142 : | |||
1143 : | ar_x = par_x * stats.data.vol.width; | ||
1144 : | ar_y = par_y * stats.data.vol.height; | ||
1145 : | } | ||
1146 : | |||
1147 : | edgomez | 1384 | m_frame.bitstream = (BYTE*)m_frame.bitstream + length; |
1148 : | m_frame.length -= length; | ||
1149 : | goto repeat; | ||
1150 : | } | ||
1151 : | |||
1152 : | if (pIn->IsPreroll() == S_OK) { | ||
1153 : | return S_FALSE; | ||
1154 : | } | ||
1155 : | |||
1156 : | return S_OK; | ||
1157 : | } | ||
1158 : | |||
1159 : | |||
1160 : | /* get property page list */ | ||
1161 : | |||
1162 : | STDMETHODIMP CXvidDecoder::GetPages(CAUUID * pPages) | ||
1163 : | { | ||
1164 : | DPRINTF("GetPages"); | ||
1165 : | |||
1166 : | pPages->cElems = 1; | ||
1167 : | pPages->pElems = (GUID *)CoTaskMemAlloc(pPages->cElems * sizeof(GUID)); | ||
1168 : | if (pPages->pElems == NULL) | ||
1169 : | { | ||
1170 : | return E_OUTOFMEMORY; | ||
1171 : | } | ||
1172 : | pPages->pElems[0] = CLSID_CABOUT; | ||
1173 : | |||
1174 : | return S_OK; | ||
1175 : | } | ||
1176 : | |||
1177 : | |||
1178 : | /* cleanup pages */ | ||
1179 : | |||
1180 : | STDMETHODIMP CXvidDecoder::FreePages(CAUUID * pPages) | ||
1181 : | { | ||
1182 : | DPRINTF("FreePages"); | ||
1183 : | CoTaskMemFree(pPages->pElems); | ||
1184 : | return S_OK; | ||
1185 : | } | ||
1186 : | Isibaar | 1898 | |
1187 : | /*=============================================================================== | ||
1188 : | // MFT Interface | ||
1189 : | //=============================================================================*/ | ||
1190 : | #if defined(XVID_USE_MFT) | ||
1191 : | #include <limits.h> // _I64_MAX | ||
1192 : | #define INVALID_TIME _I64_MAX | ||
1193 : | |||
1194 : | HRESULT CXvidDecoder::MFTGetStreamLimits(DWORD *pdwInputMinimum, DWORD *pdwInputMaximum, DWORD *pdwOutputMinimum, DWORD *pdwOutputMaximum) | ||
1195 : | { | ||
1196 : | DPRINTF("(MFT)GetStreamLimits"); | ||
1197 : | |||
1198 : | if ((pdwInputMinimum == NULL) || (pdwInputMaximum == NULL) || (pdwOutputMinimum == NULL) || (pdwOutputMaximum == NULL)) | ||
1199 : | return E_POINTER; | ||
1200 : | |||
1201 : | /* Just a fixed number of streams allowed */ | ||
1202 : | *pdwInputMinimum = *pdwInputMaximum = 1; | ||
1203 : | *pdwOutputMinimum = *pdwOutputMaximum = 1; | ||
1204 : | |||
1205 : | return S_OK; | ||
1206 : | } | ||
1207 : | |||
1208 : | HRESULT CXvidDecoder::MFTGetStreamCount(DWORD *pcInputStreams, DWORD *pcOutputStreams) | ||
1209 : | { | ||
1210 : | DPRINTF("(MFT)GetStreamCount"); | ||
1211 : | |||
1212 : | if ((pcInputStreams == NULL) || (pcOutputStreams == NULL)) | ||
1213 : | return E_POINTER; | ||
1214 : | |||
1215 : | /* We have a fixed number of streams */ | ||
1216 : | *pcInputStreams = 1; | ||
1217 : | *pcOutputStreams = 1; | ||
1218 : | |||
1219 : | return S_OK; | ||
1220 : | } | ||
1221 : | |||
1222 : | HRESULT CXvidDecoder::MFTGetStreamIDs(DWORD dwInputIDArraySize, DWORD *pdwInputIDs, DWORD dwOutputIDArraySize, DWORD *pdwOutputIDs) | ||
1223 : | { | ||
1224 : | DPRINTF("(MFT)GetStreamIDs"); | ||
1225 : | return E_NOTIMPL; /* We have fixed number of streams, so stream ID match stream index */ | ||
1226 : | } | ||
1227 : | |||
1228 : | HRESULT CXvidDecoder::MFTGetInputStreamInfo(DWORD dwInputStreamID, MFT_INPUT_STREAM_INFO *pStreamInfo) | ||
1229 : | { | ||
1230 : | DPRINTF("(MFT)GetInputStreamInfo"); | ||
1231 : | |||
1232 : | if (pStreamInfo == NULL) | ||
1233 : | return E_POINTER; | ||
1234 : | |||
1235 : | if (dwInputStreamID != 0) | ||
1236 : | return MF_E_INVALIDSTREAMNUMBER; | ||
1237 : | |||
1238 : | EnterCriticalSection(&m_mft_lock); | ||
1239 : | |||
1240 : | pStreamInfo->dwFlags = MFT_INPUT_STREAM_WHOLE_SAMPLES | MFT_INPUT_STREAM_SINGLE_SAMPLE_PER_BUFFER; | ||
1241 : | pStreamInfo->hnsMaxLatency = 0; | ||
1242 : | |||
1243 : | pStreamInfo->cbSize = 1; /* Need atleast 1 byte input */ | ||
1244 : | pStreamInfo->cbMaxLookahead = 0; | ||
1245 : | pStreamInfo->cbAlignment = 1; | ||
1246 : | |||
1247 : | LeaveCriticalSection(&m_mft_lock); | ||
1248 : | return S_OK; | ||
1249 : | } | ||
1250 : | |||
1251 : | HRESULT CXvidDecoder::MFTGetOutputStreamInfo(DWORD dwOutputStreamID, MFT_OUTPUT_STREAM_INFO *pStreamInfo) | ||
1252 : | { | ||
1253 : | DPRINTF("(MFT)GetOutputStreamInfo"); | ||
1254 : | |||
1255 : | if (pStreamInfo == NULL) | ||
1256 : | return E_POINTER; | ||
1257 : | |||
1258 : | if (dwOutputStreamID != 0) | ||
1259 : | return MF_E_INVALIDSTREAMNUMBER; | ||
1260 : | |||
1261 : | EnterCriticalSection(&m_mft_lock); | ||
1262 : | |||
1263 : | pStreamInfo->dwFlags = MFT_OUTPUT_STREAM_WHOLE_SAMPLES | MFT_OUTPUT_STREAM_SINGLE_SAMPLE_PER_BUFFER | MFT_OUTPUT_STREAM_FIXED_SAMPLE_SIZE | MFT_OUTPUT_STREAM_DISCARDABLE; | ||
1264 : | |||
1265 : | if (m_pOutputType == NULL) { | ||
1266 : | pStreamInfo->cbSize = 0; | ||
1267 : | pStreamInfo->cbAlignment = 0; | ||
1268 : | } | ||
1269 : | else { | ||
1270 : | pStreamInfo->cbSize = m_create.width * abs(m_create.height) * 4; // XXX | ||
1271 : | pStreamInfo->cbAlignment = 1; | ||
1272 : | } | ||
1273 : | |||
1274 : | LeaveCriticalSection(&m_mft_lock); | ||
1275 : | return S_OK; | ||
1276 : | } | ||
1277 : | |||
1278 : | HRESULT CXvidDecoder::GetAttributes(IMFAttributes** pAttributes) | ||
1279 : | { | ||
1280 : | DPRINTF("(MFT)GetAttributes"); | ||
1281 : | return E_NOTIMPL; /* We don't support any attributes */ | ||
1282 : | } | ||
1283 : | |||
1284 : | HRESULT CXvidDecoder::GetInputStreamAttributes(DWORD dwInputStreamID, IMFAttributes **ppAttributes) | ||
1285 : | { | ||
1286 : | DPRINTF("(MFT)GetInputStreamAttributes"); | ||
1287 : | return E_NOTIMPL; /* We don't support any attributes */ | ||
1288 : | } | ||
1289 : | |||
1290 : | HRESULT CXvidDecoder::GetOutputStreamAttributes(DWORD dwOutputStreamID, IMFAttributes **ppAttributes) | ||
1291 : | { | ||
1292 : | DPRINTF("(MFT)GetOutputStreamAttributes"); | ||
1293 : | return E_NOTIMPL; /* We don't support any attributes */ | ||
1294 : | } | ||
1295 : | |||
1296 : | HRESULT CXvidDecoder::MFTDeleteInputStream(DWORD dwStreamID) | ||
1297 : | { | ||
1298 : | DPRINTF("(MFT)DeleteInputStream"); | ||
1299 : | return E_NOTIMPL; /* We have a fixed number of streams */ | ||
1300 : | } | ||
1301 : | |||
1302 : | HRESULT CXvidDecoder::MFTAddInputStreams(DWORD cStreams, DWORD *adwStreamIDs) | ||
1303 : | { | ||
1304 : | DPRINTF("(MFT)AddInputStreams"); | ||
1305 : | return E_NOTIMPL; /* We have a fixed number of streams */ | ||
1306 : | } | ||
1307 : | |||
1308 : | HRESULT CXvidDecoder::MFTGetInputAvailableType(DWORD dwInputStreamID, DWORD dwTypeIndex, IMFMediaType **ppType) | ||
1309 : | { | ||
1310 : | DPRINTF("(MFT)GetInputAvailableType"); | ||
1311 : | |||
1312 : | if (dwInputStreamID != 0) | ||
1313 : | return MF_E_INVALIDSTREAMNUMBER; | ||
1314 : | |||
1315 : | DWORD i = 0; | ||
1316 : | GUID *bs_guid_table[8]; | ||
1317 : | |||
1318 : | bs_guid_table[i++] = (GUID *)&CLSID_XVID; | ||
1319 : | bs_guid_table[i++] = (GUID *)&CLSID_XVID_UC; | ||
1320 : | |||
1321 : | if (g_config.supported_4cc & SUPPORT_DX50) { | ||
1322 : | bs_guid_table[i++] = (GUID *)&CLSID_DX50; | ||
1323 : | bs_guid_table[i++] = (GUID *)&CLSID_DX50_UC; | ||
1324 : | } | ||
1325 : | if (g_config.supported_4cc & SUPPORT_DIVX) { | ||
1326 : | bs_guid_table[i++] = (GUID *)&CLSID_DIVX; | ||
1327 : | bs_guid_table[i++] = (GUID *)&CLSID_DIVX_UC; | ||
1328 : | } | ||
1329 : | if (g_config.supported_4cc & SUPPORT_MP4V) { | ||
1330 : | bs_guid_table[i++] = (GUID *)&CLSID_MP4V; | ||
1331 : | bs_guid_table[i++] = (GUID *)&CLSID_MP4V_UC; | ||
1332 : | } | ||
1333 : | |||
1334 : | const GUID *subtype; | ||
1335 : | if (dwTypeIndex < i) { | ||
1336 : | subtype = bs_guid_table[dwTypeIndex]; | ||
1337 : | } | ||
1338 : | else { | ||
1339 : | return MF_E_NO_MORE_TYPES; | ||
1340 : | } | ||
1341 : | |||
1342 : | EnterCriticalSection(&m_mft_lock); | ||
1343 : | |||
1344 : | HRESULT hr = S_OK; | ||
1345 : | |||
1346 : | if (ppType) { | ||
1347 : | IMFMediaType *pInputType = NULL; | ||
1348 : | hr = MFCreateMediaType(&pInputType); | ||
1349 : | |||
1350 : | if (SUCCEEDED(hr)) | ||
1351 : | hr = pInputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); | ||
1352 : | |||
1353 : | if (SUCCEEDED(hr)) | ||
1354 : | hr = pInputType->SetGUID(MF_MT_SUBTYPE, *subtype); | ||
1355 : | |||
1356 : | if (SUCCEEDED(hr)) { | ||
1357 : | *ppType = pInputType; | ||
1358 : | (*ppType)->AddRef(); | ||
1359 : | } | ||
1360 : | if (pInputType) pInputType->Release(); | ||
1361 : | } | ||
1362 : | |||
1363 : | LeaveCriticalSection(&m_mft_lock); | ||
1364 : | |||
1365 : | return hr; | ||
1366 : | } | ||
1367 : | |||
1368 : | HRESULT CXvidDecoder::MFTGetOutputAvailableType(DWORD dwOutputStreamID, DWORD dwTypeIndex, IMFMediaType **ppType) | ||
1369 : | { | ||
1370 : | DPRINTF("(MFT)GetOutputAvailableType"); | ||
1371 : | |||
1372 : | if (ppType == NULL) | ||
1373 : | return E_INVALIDARG; | ||
1374 : | |||
1375 : | if (dwOutputStreamID != 0) | ||
1376 : | return MF_E_INVALIDSTREAMNUMBER; | ||
1377 : | |||
1378 : | if (dwTypeIndex < 0) return E_INVALIDARG; | ||
1379 : | |||
1380 : | GUID csp; | ||
1381 : | int bitdepth = 8; | ||
1382 : | switch(dwTypeIndex) | ||
1383 : | { | ||
1384 : | case 0: | ||
1385 : | if ( USE_YUY2 ) | ||
1386 : | { | ||
1387 : | csp = MFVideoFormat_YUY2; | ||
1388 : | bitdepth = 4; | ||
1389 : | break; | ||
1390 : | } | ||
1391 : | case 1 : | ||
1392 : | if ( USE_UYVY ) | ||
1393 : | { | ||
1394 : | csp = MFVideoFormat_UYVY; | ||
1395 : | bitdepth = 4; | ||
1396 : | break; | ||
1397 : | } | ||
1398 : | case 2 : | ||
1399 : | if ( USE_IYUV ) | ||
1400 : | { | ||
1401 : | csp = MFVideoFormat_IYUV; | ||
1402 : | bitdepth = 3; | ||
1403 : | break; | ||
1404 : | } | ||
1405 : | case 3 : | ||
1406 : | if ( USE_YV12 ) | ||
1407 : | { | ||
1408 : | csp = MFVideoFormat_YV12; | ||
1409 : | bitdepth = 3; | ||
1410 : | break; | ||
1411 : | } | ||
1412 : | case 4 : | ||
1413 : | if ( USE_RGB32 ) | ||
1414 : | { | ||
1415 : | csp = MFVideoFormat_RGB32; | ||
1416 : | bitdepth = 8; | ||
1417 : | break; | ||
1418 : | } | ||
1419 : | case 5 : | ||
1420 : | if ( USE_RGB24 ) | ||
1421 : | { | ||
1422 : | csp = MFVideoFormat_RGB24; | ||
1423 : | bitdepth = 6; | ||
1424 : | break; | ||
1425 : | } | ||
1426 : | case 6 : | ||
1427 : | if ( USE_RG555 ) | ||
1428 : | { | ||
1429 : | csp = MFVideoFormat_RGB555; | ||
1430 : | bitdepth = 4; | ||
1431 : | break; | ||
1432 : | } | ||
1433 : | case 7 : | ||
1434 : | if ( USE_RG565 ) | ||
1435 : | { | ||
1436 : | csp = MFVideoFormat_RGB565; | ||
1437 : | bitdepth = 4; | ||
1438 : | break; | ||
1439 : | } | ||
1440 : | default : | ||
1441 : | return MF_E_NO_MORE_TYPES; | ||
1442 : | } | ||
1443 : | |||
1444 : | if (m_pInputType == NULL) | ||
1445 : | return MF_E_TRANSFORM_TYPE_NOT_SET; | ||
1446 : | |||
1447 : | EnterCriticalSection(&m_mft_lock); | ||
1448 : | |||
1449 : | HRESULT hr = S_OK; | ||
1450 : | |||
1451 : | IMFMediaType *pOutputType = NULL; | ||
1452 : | hr = MFCreateMediaType(&pOutputType); | ||
1453 : | |||
1454 : | if (SUCCEEDED(hr)) { | ||
1455 : | hr = pOutputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); | ||
1456 : | } | ||
1457 : | |||
1458 : | if (SUCCEEDED(hr)) { | ||
1459 : | hr = pOutputType->SetGUID(MF_MT_SUBTYPE, csp); | ||
1460 : | } | ||
1461 : | |||
1462 : | if (SUCCEEDED(hr)) { | ||
1463 : | hr = pOutputType->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE); | ||
1464 : | } | ||
1465 : | |||
1466 : | if (SUCCEEDED(hr)) { | ||
1467 : | hr = pOutputType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE); | ||
1468 : | } | ||
1469 : | |||
1470 : | if (SUCCEEDED(hr)) { | ||
1471 : | hr = pOutputType->SetUINT32(MF_MT_SAMPLE_SIZE, (m_create.height * m_create.width * bitdepth)>>1); | ||
1472 : | } | ||
1473 : | |||
1474 : | if (SUCCEEDED(hr)) { | ||
1475 : | hr = MFSetAttributeSize(pOutputType, MF_MT_FRAME_SIZE, m_create.width, m_create.height); | ||
1476 : | } | ||
1477 : | |||
1478 : | if (SUCCEEDED(hr)) { | ||
1479 : | hr = MFSetAttributeRatio(pOutputType, MF_MT_FRAME_RATE, m_frameRate.Numerator, m_frameRate.Denominator); | ||
1480 : | } | ||
1481 : | |||
1482 : | if (SUCCEEDED(hr)) { | ||
1483 : | hr = pOutputType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive); | ||
1484 : | } | ||
1485 : | |||
1486 : | if (SUCCEEDED(hr)) { | ||
1487 : | hr = MFSetAttributeRatio(pOutputType, MF_MT_PIXEL_ASPECT_RATIO, ar_x, ar_y); | ||
1488 : | } | ||
1489 : | |||
1490 : | if (SUCCEEDED(hr)) { | ||
1491 : | *ppType = pOutputType; | ||
1492 : | (*ppType)->AddRef(); | ||
1493 : | } | ||
1494 : | |||
1495 : | if (pOutputType) pOutputType->Release(); | ||
1496 : | |||
1497 : | LeaveCriticalSection(&m_mft_lock); | ||
1498 : | return hr; | ||
1499 : | } | ||
1500 : | |||
1501 : | HRESULT CXvidDecoder::MFTSetInputType(DWORD dwInputStreamID, IMFMediaType *pType, DWORD dwFlags) | ||
1502 : | { | ||
1503 : | DPRINTF("(MFT)SetInputType"); | ||
1504 : | |||
1505 : | if (dwInputStreamID != 0) | ||
1506 : | return MF_E_INVALIDSTREAMNUMBER; | ||
1507 : | |||
1508 : | if (dwFlags & ~MFT_SET_TYPE_TEST_ONLY) | ||
1509 : | return E_INVALIDARG; | ||
1510 : | |||
1511 : | EnterCriticalSection(&m_mft_lock); | ||
1512 : | |||
1513 : | HRESULT hr = S_OK; | ||
1514 : | |||
1515 : | /* Actually set the type or just test it? */ | ||
1516 : | BOOL bReallySet = ((dwFlags & MFT_SET_TYPE_TEST_ONLY) == 0); | ||
1517 : | |||
1518 : | /* If we have samples pending the type can't be changed right now */ | ||
1519 : | if (HasPendingOutput()) | ||
1520 : | hr = MF_E_TRANSFORM_CANNOT_CHANGE_MEDIATYPE_WHILE_PROCESSING; | ||
1521 : | |||
1522 : | if (SUCCEEDED(hr)) { | ||
1523 : | if (pType) { // /* Check the type */ | ||
1524 : | hr = OnCheckInputType(pType); | ||
1525 : | } | ||
1526 : | } | ||
1527 : | |||
1528 : | if (SUCCEEDED(hr)) { | ||
1529 : | if (bReallySet) { /* Set the type if needed */ | ||
1530 : | hr = OnSetInputType(pType); | ||
1531 : | } | ||
1532 : | } | ||
1533 : | |||
1534 : | LeaveCriticalSection(&m_mft_lock); | ||
1535 : | return hr; | ||
1536 : | } | ||
1537 : | |||
1538 : | HRESULT CXvidDecoder::MFTSetOutputType(DWORD dwOutputStreamID, IMFMediaType *pType, DWORD dwFlags) | ||
1539 : | { | ||
1540 : | DPRINTF("(MFT)SetOutputType"); | ||
1541 : | |||
1542 : | if (dwOutputStreamID != 0) | ||
1543 : | return MF_E_INVALIDSTREAMNUMBER; | ||
1544 : | |||
1545 : | if (dwFlags & ~MFT_SET_TYPE_TEST_ONLY) | ||
1546 : | return E_INVALIDARG; | ||
1547 : | |||
1548 : | HRESULT hr = S_OK; | ||
1549 : | |||
1550 : | EnterCriticalSection(&m_mft_lock); | ||
1551 : | |||
1552 : | Isibaar | 1899 | /* Actually set the type or just test it? */ |
1553 : | Isibaar | 1898 | BOOL bReallySet = ((dwFlags & MFT_SET_TYPE_TEST_ONLY) == 0); |
1554 : | |||
1555 : | /* If we have samples pending the type can't be changed right now */ | ||
1556 : | if (HasPendingOutput()) | ||
1557 : | hr = MF_E_TRANSFORM_CANNOT_CHANGE_MEDIATYPE_WHILE_PROCESSING; | ||
1558 : | |||
1559 : | if (SUCCEEDED(hr)) { | ||
1560 : | if (pType) { /* Check the type */ | ||
1561 : | AM_MEDIA_TYPE *am; | ||
1562 : | hr = MFCreateAMMediaTypeFromMFMediaType(pType, GUID_NULL, &am); | ||
1563 : | |||
1564 : | if (SUCCEEDED(hr)) { | ||
1565 : | if (FAILED(ChangeColorspace(am->subtype, am->formattype, am->pbFormat))) { | ||
1566 : | DPRINTF("(MFT)InternalCheckOutputType (MF_E_INVALIDTYPE)"); | ||
1567 : | return MF_E_INVALIDTYPE; | ||
1568 : | } | ||
1569 : | |||
1570 : | CoTaskMemFree(am->pbFormat); | ||
1571 : | CoTaskMemFree(am); | ||
1572 : | } | ||
1573 : | } | ||
1574 : | } | ||
1575 : | |||
1576 : | if (SUCCEEDED(hr)) { | ||
1577 : | if (bReallySet) { /* Set the type if needed */ | ||
1578 : | hr = OnSetOutputType(pType); | ||
1579 : | } | ||
1580 : | } | ||
1581 : | |||
1582 : | #ifdef XVID_USE_TRAYICON | ||
1583 : | Isibaar | 1901 | if (SUCCEEDED(hr) && Tray_Icon == 0) /* Create message passing window */ |
1584 : | Isibaar | 1898 | { |
1585 : | WNDCLASSEX wc; | ||
1586 : | |||
1587 : | wc.cbSize = sizeof(WNDCLASSEX); | ||
1588 : | wc.lpfnWndProc = msg_proc; | ||
1589 : | wc.style = CS_HREDRAW | CS_VREDRAW; | ||
1590 : | wc.cbWndExtra = 0; | ||
1591 : | wc.cbClsExtra = 0; | ||
1592 : | wc.hInstance = (HINSTANCE) g_xvid_hInst; | ||
1593 : | wc.hbrBackground = (HBRUSH) GetStockObject(NULL_BRUSH); | ||
1594 : | wc.lpszMenuName = NULL; | ||
1595 : | wc.lpszClassName = "XVID_MSG_WINDOW"; | ||
1596 : | wc.hIcon = NULL; | ||
1597 : | wc.hIconSm = NULL; | ||
1598 : | wc.hCursor = NULL; | ||
1599 : | RegisterClassEx(&wc); | ||
1600 : | |||
1601 : | MSG_hwnd = CreateWindowEx(0, "XVID_MSG_WINDOW", NULL, 0, CW_USEDEFAULT, | ||
1602 : | CW_USEDEFAULT, 0, 0, HWND_MESSAGE, NULL, (HINSTANCE) g_xvid_hInst, NULL); | ||
1603 : | |||
1604 : | /* display the tray icon */ | ||
1605 : | NOTIFYICONDATA nid; | ||
1606 : | Isibaar | 1901 | ZeroMemory(&nid,sizeof(NOTIFYICONDATA)); |
1607 : | |||
1608 : | nid.cbSize = NOTIFYICONDATA_V1_SIZE; | ||
1609 : | Isibaar | 1898 | nid.hWnd = MSG_hwnd; |
1610 : | Isibaar | 1901 | nid.uID = 1456; |
1611 : | Isibaar | 1898 | nid.uCallbackMessage = WM_ICONMESSAGE; |
1612 : | nid.hIcon = LoadIcon(g_xvid_hInst, MAKEINTRESOURCE(IDI_ICON)); | ||
1613 : | strcpy_s(nid.szTip, 19, "Xvid Video Decoder"); | ||
1614 : | nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; | ||
1615 : | |||
1616 : | Shell_NotifyIcon(NIM_ADD, &nid); | ||
1617 : | Isibaar | 1901 | |
1618 : | DestroyIcon(nid.hIcon); | ||
1619 : | Tray_Icon = 1; | ||
1620 : | Isibaar | 1898 | } |
1621 : | #endif | ||
1622 : | |||
1623 : | LeaveCriticalSection(&m_mft_lock); | ||
1624 : | return hr; | ||
1625 : | } | ||
1626 : | |||
1627 : | HRESULT CXvidDecoder::MFTGetInputCurrentType(DWORD dwInputStreamID, IMFMediaType **ppType) | ||
1628 : | { | ||
1629 : | DPRINTF("(MFT)GetInputCurrentType"); | ||
1630 : | |||
1631 : | if (ppType == NULL) | ||
1632 : | return E_POINTER; | ||
1633 : | |||
1634 : | if (dwInputStreamID != 0) | ||
1635 : | return MF_E_INVALIDSTREAMNUMBER; | ||
1636 : | |||
1637 : | EnterCriticalSection(&m_mft_lock); | ||
1638 : | |||
1639 : | HRESULT hr = S_OK; | ||
1640 : | |||
1641 : | if (!m_pInputType) | ||
1642 : | hr = MF_E_TRANSFORM_TYPE_NOT_SET; | ||
1643 : | |||
1644 : | if (SUCCEEDED(hr)) { | ||
1645 : | *ppType = m_pInputType; | ||
1646 : | (*ppType)->AddRef(); | ||
1647 : | } | ||
1648 : | |||
1649 : | LeaveCriticalSection(&m_mft_lock); | ||
1650 : | return hr; | ||
1651 : | } | ||
1652 : | |||
1653 : | HRESULT CXvidDecoder::MFTGetOutputCurrentType(DWORD dwOutputStreamID, IMFMediaType **ppType) | ||
1654 : | { | ||
1655 : | DPRINTF("(MFT)GetOutputCurrentType"); | ||
1656 : | |||
1657 : | if (ppType == NULL) | ||
1658 : | return E_POINTER; | ||
1659 : | |||
1660 : | if (dwOutputStreamID != 0) | ||
1661 : | return MF_E_INVALIDSTREAMNUMBER; | ||
1662 : | |||
1663 : | EnterCriticalSection(&m_mft_lock); | ||
1664 : | |||
1665 : | HRESULT hr = S_OK; | ||
1666 : | |||
1667 : | if (!m_pOutputType) | ||
1668 : | hr = MF_E_TRANSFORM_TYPE_NOT_SET; | ||
1669 : | |||
1670 : | if (SUCCEEDED(hr)) { | ||
1671 : | *ppType = m_pOutputType; | ||
1672 : | (*ppType)->AddRef(); | ||
1673 : | } | ||
1674 : | |||
1675 : | LeaveCriticalSection(&m_mft_lock); | ||
1676 : | return hr; | ||
1677 : | } | ||
1678 : | |||
1679 : | HRESULT CXvidDecoder::MFTGetInputStatus(DWORD dwInputStreamID, DWORD *pdwFlags) | ||
1680 : | { | ||
1681 : | DPRINTF("(MFT)GetInputStatus"); | ||
1682 : | |||
1683 : | if (pdwFlags == NULL) | ||
1684 : | return E_POINTER; | ||
1685 : | |||
1686 : | if (dwInputStreamID != 0) | ||
1687 : | return MF_E_INVALIDSTREAMNUMBER; | ||
1688 : | |||
1689 : | EnterCriticalSection(&m_mft_lock); | ||
1690 : | |||
1691 : | /* If there's pending output sampels we don't accept new | ||
1692 : | input data until ProcessOutput() or Flush() was called */ | ||
1693 : | if (!HasPendingOutput()) { | ||
1694 : | *pdwFlags = MFT_INPUT_STATUS_ACCEPT_DATA; | ||
1695 : | } | ||
1696 : | else { | ||
1697 : | *pdwFlags = 0; | ||
1698 : | } | ||
1699 : | |||
1700 : | LeaveCriticalSection(&m_mft_lock); | ||
1701 : | |||
1702 : | return S_OK; | ||
1703 : | } | ||
1704 : | |||
1705 : | HRESULT CXvidDecoder::MFTGetOutputStatus(DWORD *pdwFlags) | ||
1706 : | { | ||
1707 : | DPRINTF("(MFT)GetOutputStatus"); | ||
1708 : | |||
1709 : | if (pdwFlags == NULL) | ||
1710 : | return E_POINTER; | ||
1711 : | |||
1712 : | EnterCriticalSection(&m_mft_lock); | ||
1713 : | |||
1714 : | /* We can render an output sample only after we | ||
1715 : | have decoded one */ | ||
1716 : | if (HasPendingOutput()) { | ||
1717 : | *pdwFlags = MFT_OUTPUT_STATUS_SAMPLE_READY; | ||
1718 : | } | ||
1719 : | else { | ||
1720 : | *pdwFlags = 0; | ||
1721 : | } | ||
1722 : | |||
1723 : | LeaveCriticalSection(&m_mft_lock); | ||
1724 : | |||
1725 : | return S_OK; | ||
1726 : | } | ||
1727 : | |||
1728 : | HRESULT CXvidDecoder::MFTSetOutputBounds(LONGLONG hnsLowerBound, LONGLONG hnsUpperBound) | ||
1729 : | { | ||
1730 : | DPRINTF("(MFT)SetOutputBounds"); | ||
1731 : | return E_NOTIMPL; | ||
1732 : | } | ||
1733 : | |||
1734 : | HRESULT CXvidDecoder::MFTProcessEvent(DWORD dwInputStreamID, IMFMediaEvent *pEvent) | ||
1735 : | { | ||
1736 : | DPRINTF("(MFT)ProcessEvent"); | ||
1737 : | return E_NOTIMPL; /* We don't handle any stream events */ | ||
1738 : | } | ||
1739 : | |||
1740 : | HRESULT CXvidDecoder::MFTProcessMessage(MFT_MESSAGE_TYPE eMessage, ULONG_PTR ulParam) | ||
1741 : | { | ||
1742 : | DPRINTF("(MFT)ProcessMessage"); | ||
1743 : | HRESULT hr = S_OK; | ||
1744 : | |||
1745 : | EnterCriticalSection(&m_mft_lock); | ||
1746 : | |||
1747 : | switch (eMessage) | ||
1748 : | { | ||
1749 : | case MFT_MESSAGE_COMMAND_FLUSH: | ||
1750 : | if (m_create.handle != NULL) { | ||
1751 : | DPRINTF("(MFT)CommandFlush"); | ||
1752 : | |||
1753 : | xvid_dec_stats_t stats; | ||
1754 : | int used_bytes; | ||
1755 : | |||
1756 : | memset(&stats, 0, sizeof(stats)); | ||
1757 : | stats.version = XVID_VERSION; | ||
1758 : | |||
1759 : | int csp = m_frame.output.csp; | ||
1760 : | |||
1761 : | m_frame.output.csp = XVID_CSP_INTERNAL; | ||
1762 : | m_frame.bitstream = NULL; | ||
1763 : | m_frame.length = -1; | ||
1764 : | m_frame.general = XVID_LOWDELAY; | ||
1765 : | |||
1766 : | do { | ||
1767 : | used_bytes = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); | ||
1768 : | } while(used_bytes>=0 && stats.type <= 0); | ||
1769 : | |||
1770 : | m_frame.output.csp = csp; | ||
1771 : | m_frame.output.plane[1] = NULL; /* Don't display flushed samples */ | ||
1772 : | |||
1773 : | //m_timestamp = INVALID_TIME; | ||
1774 : | //m_timelength = INVALID_TIME; | ||
1775 : | //m_rtFrame = 0; | ||
1776 : | } | ||
1777 : | break; | ||
1778 : | |||
1779 : | case MFT_MESSAGE_COMMAND_DRAIN: | ||
1780 : | m_discont = 1; /* Set discontinuity flag */ | ||
1781 : | m_rtFrame = 0; | ||
1782 : | break; | ||
1783 : | |||
1784 : | case MFT_MESSAGE_SET_D3D_MANAGER: | ||
1785 : | hr = E_NOTIMPL; | ||
1786 : | break; | ||
1787 : | |||
1788 : | case MFT_MESSAGE_NOTIFY_BEGIN_STREAMING: | ||
1789 : | case MFT_MESSAGE_NOTIFY_END_STREAMING: | ||
1790 : | break; | ||
1791 : | |||
1792 : | case MFT_MESSAGE_NOTIFY_START_OF_STREAM: | ||
1793 : | case MFT_MESSAGE_NOTIFY_END_OF_STREAM: | ||
1794 : | break; | ||
1795 : | } | ||
1796 : | |||
1797 : | LeaveCriticalSection(&m_mft_lock); | ||
1798 : | |||
1799 : | return hr; | ||
1800 : | } | ||
1801 : | |||
1802 : | HRESULT CXvidDecoder::MFTProcessInput(DWORD dwInputStreamID, IMFSample *pSample, DWORD dwFlags) | ||
1803 : | { | ||
1804 : | DPRINTF("(MFT)ProcessInput"); | ||
1805 : | |||
1806 : | if (pSample == NULL) | ||
1807 : | return E_POINTER; | ||
1808 : | |||
1809 : | if (dwInputStreamID != 0) | ||
1810 : | return MF_E_INVALIDSTREAMNUMBER; | ||
1811 : | |||
1812 : | if (dwFlags != 0) | ||
1813 : | return E_INVALIDARG; | ||
1814 : | |||
1815 : | if (!m_pInputType || !m_pOutputType) { | ||
1816 : | return MF_E_NOTACCEPTING; /* Must have set input and output types */ | ||
1817 : | } | ||
1818 : | else if (HasPendingOutput()) { | ||
1819 : | return MF_E_NOTACCEPTING; /* We still have output samples to render */ | ||
1820 : | } | ||
1821 : | |||
1822 : | xvid_dec_stats_t stats; | ||
1823 : | int length; | ||
1824 : | |||
1825 : | memset(&stats, 0, sizeof(stats)); | ||
1826 : | stats.version = XVID_VERSION; | ||
1827 : | |||
1828 : | if (m_create.handle == NULL) | ||
1829 : | { | ||
1830 : | if (xvid_decore_func == NULL) | ||
1831 : | return E_FAIL; | ||
1832 : | if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0) | ||
1833 : | { | ||
1834 : | DPRINTF("*** XVID_DEC_CREATE error"); | ||
1835 : | return E_FAIL; | ||
1836 : | } | ||
1837 : | } | ||
1838 : | |||
1839 : | EnterCriticalSection(&m_mft_lock); | ||
1840 : | |||
1841 : | HRESULT hr = S_OK; | ||
1842 : | IMFMediaBuffer *pBuffer; | ||
1843 : | |||
1844 : | if (SUCCEEDED(hr)) { | ||
1845 : | hr = pSample->ConvertToContiguousBuffer(&pBuffer); | ||
1846 : | } | ||
1847 : | |||
1848 : | if (SUCCEEDED(hr)) { | ||
1849 : | hr = pBuffer->Lock((BYTE**)&m_frame.bitstream, NULL, (DWORD *)&m_frame.length); | ||
1850 : | } | ||
1851 : | |||
1852 : | m_frame.general = XVID_LOWDELAY; | ||
1853 : | |||
1854 : | if (m_discont == 1) { | ||
1855 : | m_frame.general |= XVID_DISCONTINUITY; | ||
1856 : | m_discont = 0; | ||
1857 : | } | ||
1858 : | |||
1859 : | if (g_config.nDeblock_Y) | ||
1860 : | m_frame.general |= XVID_DEBLOCKY; | ||
1861 : | |||
1862 : | if (g_config.nDeblock_UV) | ||
1863 : | m_frame.general |= XVID_DEBLOCKUV; | ||
1864 : | |||
1865 : | if (g_config.nDering_Y) | ||
1866 : | m_frame.general |= XVID_DERINGY; | ||
1867 : | |||
1868 : | if (g_config.nDering_UV) | ||
1869 : | m_frame.general |= XVID_DERINGUV; | ||
1870 : | |||
1871 : | if (g_config.nFilmEffect) | ||
1872 : | m_frame.general |= XVID_FILMEFFECT; | ||
1873 : | |||
1874 : | m_frame.brightness = g_config.nBrightness; | ||
1875 : | |||
1876 : | m_frame.output.csp &= ~XVID_CSP_VFLIP; | ||
1877 : | m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0); | ||
1878 : | |||
1879 : | int csp = m_frame.output.csp; | ||
1880 : | m_frame.output.csp = XVID_CSP_INTERNAL; | ||
1881 : | |||
1882 : | // Paranoid check. | ||
1883 : | if (xvid_decore_func == NULL) { | ||
1884 : | hr = E_FAIL; | ||
1885 : | goto END_LOOP; | ||
1886 : | } | ||
1887 : | |||
1888 : | repeat : | ||
1889 : | length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); | ||
1890 : | |||
1891 : | if (length == XVID_ERR_MEMORY) { | ||
1892 : | hr = E_FAIL; | ||
1893 : | goto END_LOOP; | ||
1894 : | } | ||
1895 : | else if (length < 0) | ||
1896 : | { | ||
1897 : | DPRINTF("*** XVID_DEC_DECODE"); | ||
1898 : | goto END_LOOP; | ||
1899 : | } | ||
1900 : | |||
1901 : | if (stats.type == XVID_TYPE_NOTHING && length > 0) { | ||
1902 : | DPRINTF(" B-Frame decoder lag"); | ||
1903 : | m_frame.output.plane[1] = NULL; | ||
1904 : | goto END_LOOP; | ||
1905 : | } | ||
1906 : | |||
1907 : | if (stats.type == XVID_TYPE_VOL) | ||
1908 : | { | ||
1909 : | if (stats.data.vol.width != m_create.width || | ||
1910 : | stats.data.vol.height != m_create.height) | ||
1911 : | { | ||
1912 : | DPRINTF("TODO: auto-resize"); | ||
1913 : | m_frame.output.plane[1] = NULL; | ||
1914 : | hr = E_FAIL; | ||
1915 : | } | ||
1916 : | |||
1917 : | if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { /* auto */ | ||
1918 : | int par_x, par_y; | ||
1919 : | if (stats.data.vol.par == XVID_PAR_EXT) { | ||
1920 : | par_x = stats.data.vol.par_width; | ||
1921 : | par_y = stats.data.vol.par_height; | ||
1922 : | } else { | ||
1923 : | par_x = PARS[stats.data.vol.par-1][0]; | ||
1924 : | par_y = PARS[stats.data.vol.par-1][1]; | ||
1925 : | } | ||
1926 : | |||
1927 : | ar_x = par_x * stats.data.vol.width; | ||
1928 : | ar_y = par_y * stats.data.vol.height; | ||
1929 : | } | ||
1930 : | |||
1931 : | m_frame.bitstream = (BYTE*)m_frame.bitstream + length; | ||
1932 : | m_frame.length -= length; | ||
1933 : | goto repeat; | ||
1934 : | } | ||
1935 : | |||
1936 : | END_LOOP: | ||
1937 : | m_frame.output.csp = csp; | ||
1938 : | |||
1939 : | if (pBuffer) { | ||
1940 : | pBuffer->Unlock(); | ||
1941 : | pBuffer->Release(); | ||
1942 : | } | ||
1943 : | |||
1944 : | if (SUCCEEDED(hr)) { | ||
1945 : | /* Try to get a timestamp */ | ||
1946 : | if (FAILED(pSample->GetSampleTime(&m_timestamp))) | ||
1947 : | m_timestamp = INVALID_TIME; | ||
1948 : | |||
1949 : | if (FAILED(pSample->GetSampleDuration(&m_timelength))) { | ||
1950 : | m_timelength = INVALID_TIME; | ||
1951 : | } | ||
1952 : | } | ||
1953 : | |||
1954 : | LeaveCriticalSection(&m_mft_lock); | ||
1955 : | |||
1956 : | return hr; | ||
1957 : | } | ||
1958 : | |||
1959 : | HRESULT CXvidDecoder::MFTProcessOutput(DWORD dwFlags, DWORD cOutputBufferCount, MFT_OUTPUT_DATA_BUFFER *pOutputSamples, DWORD *pdwStatus) | ||
1960 : | { | ||
1961 : | DPRINTF("(MFT)ProcessOutput"); | ||
1962 : | |||
1963 : | /* Preroll in MFT ?? | ||
1964 : | Flags ?? -> TODO... */ | ||
1965 : | if (dwFlags != 0) | ||
1966 : | return E_INVALIDARG; | ||
1967 : | |||
1968 : | if (pOutputSamples == NULL || pdwStatus == NULL) | ||
1969 : | return E_POINTER; | ||
1970 : | |||
1971 : | if (cOutputBufferCount != 1) /* Must be exactly one output buffer */ | ||
1972 : | return E_INVALIDARG; | ||
1973 : | |||
1974 : | if (pOutputSamples[0].pSample == NULL) /* Must have a sample */ | ||
1975 : | return E_INVALIDARG; | ||
1976 : | |||
1977 : | if (!HasPendingOutput()) { /* If there's no sample we need to decode one first */ | ||
1978 : | return MF_E_TRANSFORM_NEED_MORE_INPUT; | ||
1979 : | } | ||
1980 : | |||
1981 : | EnterCriticalSection(&m_mft_lock); | ||
1982 : | |||
1983 : | HRESULT hr = S_OK; | ||
1984 : | |||
1985 : | BYTE *Dst = NULL; | ||
1986 : | DWORD buffer_size; | ||
1987 : | |||
1988 : | IMFMediaBuffer *pOutput = NULL; | ||
1989 : | |||
1990 : | if (SUCCEEDED(hr)) { | ||
1991 : | hr = pOutputSamples[0].pSample->GetBufferByIndex(0, &pOutput); /* Get output buffer */ | ||
1992 : | } | ||
1993 : | |||
1994 : | if (SUCCEEDED(hr)) { | ||
1995 : | hr = pOutput->GetMaxLength(&buffer_size); | ||
1996 : | } | ||
1997 : | |||
1998 : | if (SUCCEEDED(hr)) | ||
1999 : | hr = pOutput->Lock(&Dst, NULL, NULL); | ||
2000 : | |||
2001 : | if (SUCCEEDED(hr)) { | ||
2002 : | xvid_gbl_convert_t convert; | ||
2003 : | |||
2004 : | memset(&convert, 0, sizeof(convert)); | ||
2005 : | convert.version = XVID_VERSION; | ||
2006 : | |||
2007 : | convert.input.csp = XVID_CSP_INTERNAL; | ||
2008 : | convert.input.plane[0] = m_frame.output.plane[0]; | ||
2009 : | convert.input.plane[1] = m_frame.output.plane[1]; | ||
2010 : | convert.input.plane[2] = m_frame.output.plane[2]; | ||
2011 : | convert.input.stride[0] = m_frame.output.stride[0]; | ||
2012 : | convert.input.stride[1] = m_frame.output.stride[1]; | ||
2013 : | convert.input.stride[2] = m_frame.output.stride[2]; | ||
2014 : | |||
2015 : | convert.output.csp = m_frame.output.csp; | ||
2016 : | convert.output.plane[0] = Dst; | ||
2017 : | convert.output.stride[0] = out_stride; | ||
2018 : | |||
2019 : | convert.width = m_create.width; | ||
2020 : | convert.height = m_create.height; | ||
2021 : | convert.interlacing = 0; | ||
2022 : | |||
2023 : | if (m_frame.output.plane[1] != NULL && Dst != NULL && xvid_global_func != NULL) | ||
2024 : | if (xvid_global_func(0, XVID_GBL_CONVERT, &convert, NULL) < 0) /* CSP convert into output buffer */ | ||
2025 : | hr = E_FAIL; | ||
2026 : | |||
2027 : | m_frame.output.plane[1] = NULL; | ||
2028 : | } | ||
2029 : | |||
2030 : | *pdwStatus = 0; | ||
2031 : | |||
2032 : | if (SUCCEEDED(hr)) { | ||
2033 : | if (SUCCEEDED(hr)) | ||
2034 : | hr = pOutputSamples[0].pSample->SetUINT32(MFSampleExtension_CleanPoint, TRUE); // key frame | ||
2035 : | |||
2036 : | if (SUCCEEDED(hr)) { /* Set timestamp of output sample */ | ||
2037 : | if (m_timestamp != INVALID_TIME) | ||
2038 : | hr = pOutputSamples[0].pSample->SetSampleTime(m_timestamp); | ||
2039 : | else | ||
2040 : | hr = pOutputSamples[0].pSample->SetSampleTime(m_rtFrame); | ||
2041 : | |||
2042 : | if (m_timelength != INVALID_TIME) | ||
2043 : | hr = pOutputSamples[0].pSample->SetSampleDuration(m_timelength); | ||
2044 : | else | ||
2045 : | hr = pOutputSamples[0].pSample->SetSampleDuration(m_duration); | ||
2046 : | |||
2047 : | m_rtFrame += m_duration; | ||
2048 : | } | ||
2049 : | |||
2050 : | if (SUCCEEDED(hr)) | ||
2051 : | hr = pOutput->SetCurrentLength(m_create.width * abs(m_create.height) * 4); // XXX | ||
2052 : | } | ||
2053 : | |||
2054 : | if (pOutput) { | ||
2055 : | pOutput->Unlock(); | ||
2056 : | pOutput->Release(); | ||
2057 : | } | ||
2058 : | |||
2059 : | LeaveCriticalSection(&m_mft_lock); | ||
2060 : | |||
2061 : | return hr; | ||
2062 : | } | ||
2063 : | |||
2064 : | HRESULT CXvidDecoder::OnCheckInputType(IMFMediaType *pmt) | ||
2065 : | { | ||
2066 : | DPRINTF("(MFT)CheckInputType"); | ||
2067 : | |||
2068 : | HRESULT hr = S_OK; | ||
2069 : | |||
2070 : | /* Check if input type is already set. Reject any type that is not identical */ | ||
2071 : | if (m_pInputType) { | ||
2072 : | DWORD dwFlags = 0; | ||
2073 : | if (S_OK == m_pInputType->IsEqual(pmt, &dwFlags)) { | ||
2074 : | return S_OK; | ||
2075 : | } | ||
2076 : | else { | ||
2077 : | return MF_E_INVALIDTYPE; | ||
2078 : | } | ||
2079 : | } | ||
2080 : | |||
2081 : | GUID majortype = {0}, subtype = {0}; | ||
2082 : | UINT32 width = 0, height = 0; | ||
2083 : | |||
2084 : | hr = pmt->GetMajorType(&majortype); | ||
2085 : | |||
2086 : | if (SUCCEEDED(hr)) { | ||
2087 : | if (majortype != MFMediaType_Video) { /* Must be Video */ | ||
2088 : | hr = MF_E_INVALIDTYPE; | ||
2089 : | } | ||
2090 : | } | ||
2091 : | |||
2092 : | if (m_hdll == NULL) { | ||
2093 : | HRESULT hr = OpenLib(); | ||
2094 : | |||
2095 : | if (FAILED(hr) || (m_hdll == NULL)) // Paranoid checks. | ||
2096 : | hr = MF_E_INVALIDTYPE; | ||
2097 : | } | ||
2098 : | |||
2099 : | if (SUCCEEDED(hr)) { | ||
2100 : | hr = MFGetAttributeSize(pmt, MF_MT_FRAME_SIZE, &width, &height); | ||
2101 : | } | ||
2102 : | |||
2103 : | /* Check the frame size */ | ||
2104 : | if (SUCCEEDED(hr)) { | ||
2105 : | if (width > 4096 || height > 4096) { | ||
2106 : | hr = MF_E_INVALIDTYPE; | ||
2107 : | } | ||
2108 : | } | ||
2109 : | m_create.width = width; | ||
2110 : | m_create.height = height; | ||
2111 : | |||
2112 : | if (SUCCEEDED(hr)) { | ||
2113 : | if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { | ||
2114 : | hr = MFGetAttributeRatio(pmt, MF_MT_PIXEL_ASPECT_RATIO, (UINT32*)&ar_x, (UINT32*)&ar_y); | ||
2115 : | } | ||
2116 : | } | ||
2117 : | |||
2118 : | /* TODO1: Make sure there really is a frame rate after all! | ||
2119 : | TODO2: Use the framerate for something! */ | ||
2120 : | MFRatio fps = {0}; | ||
2121 : | if (SUCCEEDED(hr)) { | ||
2122 : | hr = MFGetAttributeRatio(pmt, MF_MT_FRAME_RATE, (UINT32*)&fps.Numerator, (UINT32*)&fps.Denominator); | ||
2123 : | } | ||
2124 : | |||
2125 : | if (SUCCEEDED(hr)) { | ||
2126 : | hr = pmt->GetGUID(MF_MT_SUBTYPE, &subtype); | ||
2127 : | } | ||
2128 : | |||
2129 : | if (subtype == CLSID_MP4V || subtype == CLSID_MP4V_UC) { | ||
2130 : | if (!(g_config.supported_4cc & SUPPORT_MP4V)) { | ||
2131 : | CloseLib(); | ||
2132 : | hr = MF_E_INVALIDTYPE; | ||
2133 : | } | ||
2134 : | else m_create.fourcc = FOURCC_MP4V; | ||
2135 : | } | ||
2136 : | else if (subtype == CLSID_DIVX || subtype == CLSID_DIVX_UC) { | ||
2137 : | if (!(g_config.supported_4cc & SUPPORT_DIVX)) { | ||
2138 : | CloseLib(); | ||
2139 : | hr = MF_E_INVALIDTYPE; | ||
2140 : | } | ||
2141 : | else m_create.fourcc = FOURCC_DIVX; | ||
2142 : | } | ||
2143 : | else if (subtype == CLSID_DX50 || subtype == CLSID_DX50_UC) { | ||
2144 : | if (!(g_config.supported_4cc & SUPPORT_DX50)) { | ||
2145 : | CloseLib(); | ||
2146 : | hr = MF_E_INVALIDTYPE; | ||
2147 : | } | ||
2148 : | else m_create.fourcc = FOURCC_DX50; | ||
2149 : | } | ||
2150 : | else if (subtype == CLSID_XVID || subtype == CLSID_XVID_UC) { | ||
2151 : | m_create.fourcc = FOURCC_XVID; | ||
2152 : | } | ||
2153 : | else { | ||
2154 : | DPRINTF("Unknown subtype!"); | ||
2155 : | CloseLib(); | ||
2156 : | hr = MF_E_INVALIDTYPE; | ||
2157 : | } | ||
2158 : | |||
2159 : | /* haali media splitter reports VOL information in the format header */ | ||
2160 : | if (SUCCEEDED(hr)) | ||
2161 : | { | ||
2162 : | UINT32 cbSeqHeader = 0; | ||
2163 : | |||
2164 : | (void)pmt->GetBlobSize(MF_MT_MPEG_SEQUENCE_HEADER, &cbSeqHeader); | ||
2165 : | |||
2166 : | if (cbSeqHeader>0) { | ||
2167 : | xvid_dec_stats_t stats; | ||
2168 : | memset(&stats, 0, sizeof(stats)); | ||
2169 : | stats.version = XVID_VERSION; | ||
2170 : | |||
2171 : | if (m_create.handle == NULL) { | ||
2172 : | if (xvid_decore_func == NULL) | ||
2173 : | hr = E_FAIL; | ||
2174 : | if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0) { | ||
2175 : | DPRINTF("*** XVID_DEC_CREATE error"); | ||
2176 : | hr = E_FAIL; | ||
2177 : | } | ||
2178 : | } | ||
2179 : | |||
2180 : | if (SUCCEEDED(hr)) { | ||
2181 : | (void)pmt->GetAllocatedBlob(MF_MT_MPEG_SEQUENCE_HEADER, (UINT8 **)&m_frame.bitstream, (UINT32 *)&m_frame.length); | ||
2182 : | m_frame.general = 0; | ||
2183 : | m_frame.output.csp = XVID_CSP_NULL; | ||
2184 : | |||
2185 : | int ret = 0; | ||
2186 : | if ((ret=xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats)) >= 0) { | ||
2187 : | /* honour video dimensions reported in VOL header */ | ||
2188 : | if (stats.type == XVID_TYPE_VOL) { | ||
2189 : | m_create.width = stats.data.vol.width; | ||
2190 : | m_create.height = stats.data.vol.height; | ||
2191 : | } | ||
2192 : | } | ||
2193 : | |||
2194 : | if (ret == XVID_ERR_MEMORY) hr = E_FAIL; | ||
2195 : | CoTaskMemFree(m_frame.bitstream); | ||
2196 : | } | ||
2197 : | } | ||
2198 : | } | ||
2199 : | |||
2200 : | return hr; | ||
2201 : | } | ||
2202 : | |||
2203 : | HRESULT CXvidDecoder::OnSetInputType(IMFMediaType *pmt) | ||
2204 : | { | ||
2205 : | HRESULT hr = S_OK; | ||
2206 : | UINT32 w, h; | ||
2207 : | |||
2208 : | if (m_pInputType) m_pInputType->Release(); | ||
2209 : | |||
2210 : | hr = MFGetAttributeSize(pmt, MF_MT_FRAME_SIZE, &w, &h); | ||
2211 : | m_create.width = w; m_create.height = h; | ||
2212 : | |||
2213 : | if (SUCCEEDED(hr)) | ||
2214 : | hr = MFGetAttributeRatio(pmt, MF_MT_FRAME_RATE, (UINT32*)&m_frameRate.Numerator, (UINT32*)&m_frameRate.Denominator); | ||
2215 : | |||
2216 : | if (SUCCEEDED(hr)) { /* Store frame duration, derived from the frame rate */ | ||
2217 : | hr = MFFrameRateToAverageTimePerFrame(m_frameRate.Numerator, m_frameRate.Denominator, &m_duration); | ||
2218 : | } | ||
2219 : | |||
2220 : | if (SUCCEEDED(hr)) { | ||
2221 : | m_pInputType = pmt; | ||
2222 : | m_pInputType->AddRef(); | ||
2223 : | } | ||
2224 : | |||
2225 : | return hr; | ||
2226 : | } | ||
2227 : | |||
2228 : | HRESULT CXvidDecoder::OnSetOutputType(IMFMediaType *pmt) | ||
2229 : | { | ||
2230 : | if (m_pOutputType) m_pOutputType->Release(); | ||
2231 : | |||
2232 : | m_pOutputType = pmt; | ||
2233 : | m_pOutputType->AddRef(); | ||
2234 : | |||
2235 : | return S_OK; | ||
2236 : | } | ||
2237 : | |||
2238 : | #endif /* XVID_USE_MFT */ |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |