1 |
|
/***************************************************************************** |
2 |
|
* |
3 |
|
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - XviD Decoder part of the DShow Filter - |
5 |
|
* |
6 |
|
* Copyright(C) 2002-2004 Peter Ross <pross@xvid.org> |
7 |
|
* |
8 |
|
* This program is free software ; you can redistribute it and/or modify |
9 |
|
* it under the terms of the GNU General Public License as published by |
10 |
|
* the Free Software Foundation ; either version 2 of the License, or |
11 |
|
* (at your option) any later version. |
12 |
|
* |
13 |
|
* This program is distributed in the hope that it will be useful, |
14 |
|
* but WITHOUT ANY WARRANTY ; without even the implied warranty of |
15 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
* GNU General Public License for more details. |
17 |
|
* |
18 |
|
* You should have received a copy of the GNU General Public License |
19 |
|
* along with this program ; if not, write to the Free Software |
20 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
|
* |
22 |
|
* $Id$ |
23 |
|
* |
24 |
|
****************************************************************************/ |
25 |
|
|
26 |
|
/**************************************************************************** |
27 |
|
* |
28 |
|
* 2003/12/11 - added some additional options, mainly to make the deblocking |
29 |
|
* code from xvidcore available. Most of the new code is taken |
30 |
|
* from Nic's dshow filter, (C) Nic, http://nic.dnsalias.com |
31 |
|
* |
32 |
|
****************************************************************************/ |
33 |
|
|
34 |
|
/* |
35 |
|
this requires the directx sdk |
36 |
|
place these paths at the top of the Tools|Options|Directories list |
37 |
|
|
38 |
|
headers: |
39 |
|
C:\DXVCSDK\include |
40 |
|
C:\DXVCSDK\samples\Multimedia\DirectShow\BaseClasses |
41 |
|
|
42 |
|
libraries (optional): |
43 |
|
C:\DXVCSDK\samples\Multimedia\DirectShow\BaseClasses\Release |
44 |
|
*/ |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
#include <windows.h> |
49 |
|
|
50 |
|
#include <streams.h> |
51 |
|
#include <initguid.h> |
52 |
|
#include <olectl.h> |
53 |
|
#if (1100 > _MSC_VER) |
54 |
|
#include <olectlid.h> |
55 |
|
#endif |
56 |
|
#include <dvdmedia.h> // VIDEOINFOHEADER2 |
57 |
|
|
58 |
|
#include <xvid.h> // XviD API |
59 |
|
|
60 |
|
#include "IXvidDecoder.h" |
61 |
|
#include "CXvidDecoder.h" |
62 |
|
#include "CAbout.h" |
63 |
|
#include "config.h" |
64 |
|
#include "debug.h" |
65 |
|
|
66 |
|
static bool USE_IYUV; |
67 |
|
static bool USE_YV12; |
68 |
|
static bool USE_YUY2; |
69 |
|
static bool USE_YVYU; |
70 |
|
static bool USE_UYVY; |
71 |
|
static bool USE_RGB32; |
72 |
|
static bool USE_RGB24; |
73 |
|
static bool USE_RG555; |
74 |
|
static bool USE_RG565; |
75 |
|
|
76 |
|
const AMOVIESETUP_MEDIATYPE sudInputPinTypes[] = |
77 |
|
{ |
78 |
|
{ &MEDIATYPE_Video, &CLSID_XVID }, |
79 |
|
{ &MEDIATYPE_Video, &CLSID_XVID_UC }, |
80 |
|
{ &MEDIATYPE_Video, &CLSID_DIVX }, |
81 |
|
{ &MEDIATYPE_Video, &CLSID_DIVX_UC }, |
82 |
|
{ &MEDIATYPE_Video, &CLSID_DX50 }, |
83 |
|
{ &MEDIATYPE_Video, &CLSID_DX50_UC }, |
84 |
|
{ &MEDIATYPE_Video, &CLSID_MP4V }, |
85 |
|
}; |
86 |
|
|
87 |
|
const AMOVIESETUP_MEDIATYPE sudOutputPinTypes[] = |
88 |
|
{ |
89 |
|
{ &MEDIATYPE_Video, &MEDIASUBTYPE_NULL } |
90 |
|
}; |
91 |
|
|
92 |
|
|
93 |
|
const AMOVIESETUP_PIN psudPins[] = |
94 |
|
{ |
95 |
|
{ |
96 |
|
L"Input", // String pin name |
97 |
|
FALSE, // Is it rendered |
98 |
|
FALSE, // Is it an output |
99 |
|
FALSE, // Allowed none |
100 |
|
FALSE, // Allowed many |
101 |
|
&CLSID_NULL, // Connects to filter |
102 |
|
L"Output", // Connects to pin |
103 |
|
sizeof(sudInputPinTypes) / sizeof(AMOVIESETUP_MEDIATYPE), // Number of types |
104 |
|
&sudInputPinTypes[0] // The pin details |
105 |
|
}, |
106 |
|
{ |
107 |
|
L"Output", // String pin name |
108 |
|
FALSE, // Is it rendered |
109 |
|
TRUE, // Is it an output |
110 |
|
FALSE, // Allowed none |
111 |
|
FALSE, // Allowed many |
112 |
|
&CLSID_NULL, // Connects to filter |
113 |
|
L"Input", // Connects to pin |
114 |
|
sizeof(sudOutputPinTypes) / sizeof(AMOVIESETUP_MEDIATYPE), // Number of types |
115 |
|
sudOutputPinTypes // The pin details |
116 |
|
} |
117 |
|
}; |
118 |
|
|
119 |
|
|
120 |
|
const AMOVIESETUP_FILTER sudXvidDecoder = |
121 |
|
{ |
122 |
|
&CLSID_XVID, // Filter CLSID |
123 |
|
XVID_NAME_L, // Filter name |
124 |
|
MERIT_PREFERRED, // Its merit |
125 |
|
sizeof(psudPins) / sizeof(AMOVIESETUP_PIN), // Number of pins |
126 |
|
psudPins // Pin details |
127 |
|
}; |
128 |
|
|
129 |
|
|
130 |
|
// List of class IDs and creator functions for the class factory. This |
131 |
|
// provides the link between the OLE entry point in the DLL and an object |
132 |
|
// being created. The class factory will call the static CreateInstance |
133 |
|
|
134 |
|
CFactoryTemplate g_Templates[] = |
135 |
|
{ |
136 |
|
{ |
137 |
|
XVID_NAME_L, |
138 |
|
&CLSID_XVID, |
139 |
|
CXvidDecoder::CreateInstance, |
140 |
|
NULL, |
141 |
|
&sudXvidDecoder |
142 |
|
}, |
143 |
|
{ |
144 |
|
XVID_NAME_L L"About", |
145 |
|
&CLSID_CABOUT, |
146 |
|
CAbout::CreateInstance |
147 |
|
} |
148 |
|
|
149 |
|
}; |
150 |
|
|
151 |
|
|
152 |
|
/* note: g_cTemplates must be global; used by strmbase.lib(dllentry.cpp,dllsetup.cpp) */ |
153 |
|
int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate); |
154 |
|
|
155 |
|
|
156 |
|
STDAPI DllRegisterServer() |
157 |
|
{ |
158 |
|
return AMovieDllRegisterServer2( TRUE ); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
STDAPI DllUnregisterServer() |
163 |
|
{ |
164 |
|
return AMovieDllRegisterServer2( FALSE ); |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
/* create instance */ |
169 |
|
|
170 |
|
CUnknown * WINAPI CXvidDecoder::CreateInstance(LPUNKNOWN punk, HRESULT *phr) |
171 |
|
{ |
172 |
|
CXvidDecoder * pNewObject = new CXvidDecoder(punk, phr); |
173 |
|
if (pNewObject == NULL) |
174 |
|
{ |
175 |
|
*phr = E_OUTOFMEMORY; |
176 |
|
} |
177 |
|
return pNewObject; |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
/* query interfaces */ |
182 |
|
|
183 |
|
STDMETHODIMP CXvidDecoder::NonDelegatingQueryInterface(REFIID riid, void **ppv) |
184 |
|
{ |
185 |
|
CheckPointer(ppv, E_POINTER); |
186 |
|
|
187 |
|
if (riid == IID_IXvidDecoder) |
188 |
|
{ |
189 |
|
return GetInterface((IXvidDecoder *) this, ppv); |
190 |
|
} |
191 |
|
|
192 |
|
if (riid == IID_ISpecifyPropertyPages) |
193 |
|
{ |
194 |
|
return GetInterface((ISpecifyPropertyPages *) this, ppv); |
195 |
|
} |
196 |
|
|
197 |
|
return CVideoTransformFilter::NonDelegatingQueryInterface(riid, ppv); |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
/* constructor */ |
203 |
|
|
204 |
|
#define XVID_DLL_NAME "xvidcore.dll" |
205 |
|
|
206 |
|
CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) : |
207 |
|
CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID) |
208 |
|
{ |
209 |
|
DPRINTF("Constructor"); |
210 |
|
|
211 |
|
xvid_gbl_init_t init; |
212 |
|
memset(&init, 0, sizeof(init)); |
213 |
|
init.version = XVID_VERSION; |
214 |
|
|
215 |
|
ar_x = ar_y = 0; |
216 |
|
|
217 |
|
m_hdll = LoadLibrary(XVID_DLL_NAME); |
218 |
|
if (m_hdll == NULL) { |
219 |
|
DPRINTF("dll load failed"); |
220 |
|
MessageBox(0, XVID_DLL_NAME " not found","Error", 0); |
221 |
|
return; |
222 |
|
} |
223 |
|
|
224 |
|
xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"); |
225 |
|
if (xvid_global_func == NULL) { |
226 |
|
MessageBox(0, "xvid_global() not found", "Error", 0); |
227 |
|
return; |
228 |
|
} |
229 |
|
|
230 |
|
xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore"); |
231 |
|
if (xvid_decore_func == NULL) { |
232 |
|
MessageBox(0, "xvid_decore() not found", "Error", 0); |
233 |
|
return; |
234 |
|
} |
235 |
|
|
236 |
|
if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0) |
237 |
|
{ |
238 |
|
MessageBox(0, "xvid_global() failed", "Error", 0); |
239 |
|
return; |
240 |
|
} |
241 |
|
|
242 |
|
memset(&m_create, 0, sizeof(m_create)); |
243 |
|
m_create.version = XVID_VERSION; |
244 |
|
m_create.handle = NULL; |
245 |
|
|
246 |
|
memset(&m_frame, 0, sizeof(m_frame)); |
247 |
|
m_frame.version = XVID_VERSION; |
248 |
|
|
249 |
|
LoadRegistryInfo(); |
250 |
|
|
251 |
|
USE_IYUV = false; |
252 |
|
USE_YV12 = false; |
253 |
|
USE_YUY2 = false; |
254 |
|
USE_YVYU = false; |
255 |
|
USE_UYVY = false; |
256 |
|
USE_RGB32 = false; |
257 |
|
USE_RGB24 = false; |
258 |
|
USE_RG555 = false; |
259 |
|
USE_RG565 = false; |
260 |
|
|
261 |
|
switch ( g_config.nForceColorspace ) |
262 |
|
{ |
263 |
|
case FORCE_NONE: |
264 |
|
USE_IYUV = true; |
265 |
|
USE_YV12 = true; |
266 |
|
USE_YUY2 = true; |
267 |
|
USE_YVYU = true; |
268 |
|
USE_UYVY = true; |
269 |
|
USE_RGB32 = true; |
270 |
|
USE_RGB24 = true; |
271 |
|
USE_RG555 = true; |
272 |
|
USE_RG565 = true; |
273 |
|
break; |
274 |
|
case FORCE_YV12: |
275 |
|
USE_IYUV = true; |
276 |
|
USE_YV12 = true; |
277 |
|
break; |
278 |
|
case FORCE_YUY2: |
279 |
|
USE_YUY2 = true; |
280 |
|
break; |
281 |
|
case FORCE_RGB24: |
282 |
|
USE_RGB24 = true; |
283 |
|
break; |
284 |
|
case FORCE_RGB32: |
285 |
|
USE_RGB32 = true; |
286 |
|
break; |
287 |
|
} |
288 |
|
} |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
/* destructor */ |
293 |
|
|
294 |
|
CXvidDecoder::~CXvidDecoder() |
295 |
|
{ |
296 |
|
DPRINTF("Destructor"); |
297 |
|
|
298 |
|
if (m_create.handle != NULL) |
299 |
|
{ |
300 |
|
xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0); |
301 |
|
m_create.handle = NULL; |
302 |
|
} |
303 |
|
|
304 |
|
if (m_hdll != NULL) |
305 |
|
{ |
306 |
|
FreeLibrary(m_hdll); |
307 |
|
m_hdll = NULL; |
308 |
|
} |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
/* check input type */ |
314 |
|
|
315 |
|
HRESULT CXvidDecoder::CheckInputType(const CMediaType * mtIn) |
316 |
|
{ |
317 |
|
DPRINTF("CheckInputType"); |
318 |
|
BITMAPINFOHEADER * hdr; |
319 |
|
|
320 |
|
if (*mtIn->Type() != MEDIATYPE_Video) |
321 |
|
{ |
322 |
|
DPRINTF("Error: Unknown Type"); |
323 |
|
return VFW_E_TYPE_NOT_ACCEPTED; |
324 |
|
} |
325 |
|
|
326 |
|
if (*mtIn->FormatType() == FORMAT_VideoInfo) |
327 |
|
{ |
328 |
|
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format(); |
329 |
|
hdr = &vih->bmiHeader; |
330 |
|
/* PAR (x:y) is (1/ppm_X):(1/ppm_Y) where ppm is pixels-per-meter |
331 |
|
which is equal to ppm_Y:ppm_X */ |
332 |
|
ar_x = vih->bmiHeader.biYPelsPerMeter * abs(hdr->biWidth); |
333 |
|
ar_y = vih->bmiHeader.biXPelsPerMeter * abs(hdr->biHeight); |
334 |
|
} |
335 |
|
else if (*mtIn->FormatType() == FORMAT_VideoInfo2) |
336 |
|
{ |
337 |
|
VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format(); |
338 |
|
hdr = &vih2->bmiHeader; |
339 |
|
ar_x = vih2->dwPictAspectRatioX; |
340 |
|
ar_y = vih2->dwPictAspectRatioY; |
341 |
|
} |
342 |
|
else |
343 |
|
{ |
344 |
|
DPRINTF("Error: Unknown FormatType"); |
345 |
|
return VFW_E_TYPE_NOT_ACCEPTED; |
346 |
|
} |
347 |
|
|
348 |
|
if (hdr->biHeight < 0) |
349 |
|
{ |
350 |
|
DPRINTF("colorspace: inverted input format not supported"); |
351 |
|
} |
352 |
|
|
353 |
|
m_create.width = hdr->biWidth; |
354 |
|
m_create.height = hdr->biHeight; |
355 |
|
|
356 |
|
switch(hdr->biCompression) |
357 |
|
{ |
358 |
|
|
359 |
|
case FOURCC_MP4V: |
360 |
|
if (!(g_config.supported_4cc & SUPPORT_MP4V)) return VFW_E_TYPE_NOT_ACCEPTED; |
361 |
|
break; |
362 |
|
case FOURCC_DIVX : |
363 |
|
if (!(g_config.supported_4cc & SUPPORT_DIVX)) return VFW_E_TYPE_NOT_ACCEPTED; |
364 |
|
break; |
365 |
|
case FOURCC_DX50 : |
366 |
|
if (!(g_config.supported_4cc & SUPPORT_DX50)) return VFW_E_TYPE_NOT_ACCEPTED; |
367 |
|
case FOURCC_XVID : |
368 |
|
break; |
369 |
|
|
370 |
|
|
371 |
|
default : |
372 |
|
DPRINTF("Unknown fourcc: 0x%08x (%c%c%c%c)", |
373 |
|
hdr->biCompression, |
374 |
|
(hdr->biCompression)&0xff, |
375 |
|
(hdr->biCompression>>8)&0xff, |
376 |
|
(hdr->biCompression>>16)&0xff, |
377 |
|
(hdr->biCompression>>24)&0xff); |
378 |
|
return VFW_E_TYPE_NOT_ACCEPTED; |
379 |
|
} |
380 |
|
return S_OK; |
381 |
|
} |
382 |
|
|
383 |
|
|
384 |
|
/* get list of supported output colorspaces */ |
385 |
|
|
386 |
|
|
387 |
|
HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut) |
388 |
|
{ |
389 |
|
DPRINTF("GetMediaType"); |
390 |
|
|
391 |
|
if (m_pInput->IsConnected() == FALSE) |
392 |
|
{ |
393 |
|
return E_UNEXPECTED; |
394 |
|
} |
395 |
|
|
396 |
|
VIDEOINFOHEADER2 * vih = (VIDEOINFOHEADER2 *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER2)); |
397 |
|
if (vih == NULL) |
398 |
|
{ |
399 |
|
return E_OUTOFMEMORY; |
400 |
|
} |
401 |
|
|
402 |
|
ZeroMemory(vih, sizeof (VIDEOINFOHEADER2)); |
403 |
|
vih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
404 |
|
vih->bmiHeader.biWidth = m_create.width; |
405 |
|
vih->bmiHeader.biHeight = m_create.height; |
406 |
|
vih->bmiHeader.biPlanes = 1; |
407 |
|
|
408 |
|
if (iPosition < 0) |
409 |
|
{ |
410 |
|
return E_INVALIDARG; |
411 |
|
} |
412 |
|
|
413 |
|
switch(iPosition) |
414 |
|
{ |
415 |
|
|
416 |
|
case 0: |
417 |
|
if ( USE_YUY2 ) |
418 |
|
{ |
419 |
|
vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1; |
420 |
|
vih->bmiHeader.biBitCount = 16; |
421 |
|
mtOut->SetSubtype(&MEDIASUBTYPE_YUY2); |
422 |
|
break; |
423 |
|
} |
424 |
|
case 1 : |
425 |
|
if ( USE_YVYU ) |
426 |
|
{ |
427 |
|
vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1; |
428 |
|
vih->bmiHeader.biBitCount = 16; |
429 |
|
mtOut->SetSubtype(&MEDIASUBTYPE_YVYU); |
430 |
|
break; |
431 |
|
} |
432 |
|
case 2 : |
433 |
|
if ( USE_UYVY ) |
434 |
|
{ |
435 |
|
vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1; |
436 |
|
vih->bmiHeader.biBitCount = 16; |
437 |
|
mtOut->SetSubtype(&MEDIASUBTYPE_UYVY); |
438 |
|
break; |
439 |
|
} |
440 |
|
case 3 : |
441 |
|
if ( USE_IYUV ) |
442 |
|
{ |
443 |
|
vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1; |
444 |
|
vih->bmiHeader.biBitCount = 12; |
445 |
|
mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV); |
446 |
|
break; |
447 |
|
} |
448 |
|
case 4 : |
449 |
|
if ( USE_YV12 ) |
450 |
|
{ |
451 |
|
vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1; |
452 |
|
vih->bmiHeader.biBitCount = 12; |
453 |
|
mtOut->SetSubtype(&MEDIASUBTYPE_YV12); |
454 |
|
break; |
455 |
|
} |
456 |
|
case 5 : |
457 |
|
if ( USE_RGB32 ) |
458 |
|
{ |
459 |
|
vih->bmiHeader.biCompression = BI_RGB; |
460 |
|
vih->bmiHeader.biBitCount = 32; |
461 |
|
mtOut->SetSubtype(&MEDIASUBTYPE_RGB32); |
462 |
|
break; |
463 |
|
} |
464 |
|
case 6 : |
465 |
|
if ( USE_RGB24 ) |
466 |
|
{ |
467 |
|
vih->bmiHeader.biCompression = BI_RGB; |
468 |
|
vih->bmiHeader.biBitCount = 24; |
469 |
|
mtOut->SetSubtype(&MEDIASUBTYPE_RGB24); |
470 |
|
break; |
471 |
|
} |
472 |
|
case 7 : |
473 |
|
if ( USE_RG555 ) |
474 |
|
{ |
475 |
|
vih->bmiHeader.biCompression = BI_RGB; |
476 |
|
vih->bmiHeader.biBitCount = 16; |
477 |
|
mtOut->SetSubtype(&MEDIASUBTYPE_RGB555); |
478 |
|
break; |
479 |
|
} |
480 |
|
case 8 : |
481 |
|
if ( USE_RG565 ) |
482 |
|
{ |
483 |
|
vih->bmiHeader.biCompression = BI_RGB; |
484 |
|
vih->bmiHeader.biBitCount = 16; |
485 |
|
mtOut->SetSubtype(&MEDIASUBTYPE_RGB565); |
486 |
|
break; |
487 |
|
} |
488 |
|
default : |
489 |
|
return VFW_S_NO_MORE_ITEMS; |
490 |
|
} |
491 |
|
|
492 |
|
vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader); |
493 |
|
|
494 |
|
if (ar_x != 0 && ar_y != 0) { |
495 |
|
vih->dwPictAspectRatioX = ar_x; |
496 |
|
vih->dwPictAspectRatioY = ar_y; |
497 |
|
} else { // just to be safe |
498 |
|
vih->dwPictAspectRatioX = m_create.width; |
499 |
|
vih->dwPictAspectRatioY = abs(m_create.height); |
500 |
|
} |
501 |
|
|
502 |
|
mtOut->SetType(&MEDIATYPE_Video); |
503 |
|
mtOut->SetFormatType(&FORMAT_VideoInfo2); |
504 |
|
mtOut->SetTemporalCompression(FALSE); |
505 |
|
mtOut->SetSampleSize(vih->bmiHeader.biSizeImage); |
506 |
|
|
507 |
|
return S_OK; |
508 |
|
} |
509 |
|
|
510 |
|
|
511 |
|
/* (internal function) change colorspace */ |
512 |
|
|
513 |
|
HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format) |
514 |
|
{ |
515 |
|
if (formattype == FORMAT_VideoInfo) |
516 |
|
{ |
517 |
|
VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format; |
518 |
|
m_frame.output.stride[0] = (((vih->bmiHeader.biWidth * vih->bmiHeader.biBitCount) + 31) & ~31) >> 3; |
519 |
|
rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); |
520 |
|
} |
521 |
|
else if (formattype == FORMAT_VideoInfo2) |
522 |
|
{ |
523 |
|
VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format; |
524 |
|
m_frame.output.stride[0] = (((vih2->bmiHeader.biWidth * vih2->bmiHeader.biBitCount) + 31) & ~31) >> 3; |
525 |
|
rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); |
526 |
|
} |
527 |
|
else |
528 |
|
{ |
529 |
|
return S_FALSE; |
530 |
|
} |
531 |
|
|
532 |
|
if (subtype == CLSID_MEDIASUBTYPE_IYUV) |
533 |
|
{ |
534 |
|
DPRINTF("IYUV"); |
535 |
|
rgb_flip = 0; |
536 |
|
m_frame.output.csp = XVID_CSP_I420; |
537 |
|
m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3; /* planar format fix */ |
538 |
|
} |
539 |
|
else if (subtype == MEDIASUBTYPE_YV12) |
540 |
|
{ |
541 |
|
DPRINTF("YV12"); |
542 |
|
rgb_flip = 0; |
543 |
|
m_frame.output.csp = XVID_CSP_YV12; |
544 |
|
m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3; /* planar format fix */ |
545 |
|
} |
546 |
|
else if (subtype == MEDIASUBTYPE_YUY2) |
547 |
|
{ |
548 |
|
DPRINTF("YUY2"); |
549 |
|
rgb_flip = 0; |
550 |
|
m_frame.output.csp = XVID_CSP_YUY2; |
551 |
|
} |
552 |
|
else if (subtype == MEDIASUBTYPE_YVYU) |
553 |
|
{ |
554 |
|
DPRINTF("YVYU"); |
555 |
|
rgb_flip = 0; |
556 |
|
m_frame.output.csp = XVID_CSP_YVYU; |
557 |
|
} |
558 |
|
else if (subtype == MEDIASUBTYPE_UYVY) |
559 |
|
{ |
560 |
|
DPRINTF("UYVY"); |
561 |
|
rgb_flip = 0; |
562 |
|
m_frame.output.csp = XVID_CSP_UYVY; |
563 |
|
} |
564 |
|
else if (subtype == MEDIASUBTYPE_RGB32) |
565 |
|
{ |
566 |
|
DPRINTF("RGB32"); |
567 |
|
m_frame.output.csp = rgb_flip | XVID_CSP_BGRA; |
568 |
|
} |
569 |
|
else if (subtype == MEDIASUBTYPE_RGB24) |
570 |
|
{ |
571 |
|
DPRINTF("RGB24"); |
572 |
|
m_frame.output.csp = rgb_flip | XVID_CSP_BGR; |
573 |
|
} |
574 |
|
else if (subtype == MEDIASUBTYPE_RGB555) |
575 |
|
{ |
576 |
|
DPRINTF("RGB555"); |
577 |
|
m_frame.output.csp = rgb_flip | XVID_CSP_RGB555; |
578 |
|
} |
579 |
|
else if (subtype == MEDIASUBTYPE_RGB565) |
580 |
|
{ |
581 |
|
DPRINTF("RGB565"); |
582 |
|
m_frame.output.csp = rgb_flip | XVID_CSP_RGB565; |
583 |
|
} |
584 |
|
else if (subtype == GUID_NULL) |
585 |
|
{ |
586 |
|
m_frame.output.csp = XVID_CSP_NULL; |
587 |
|
} |
588 |
|
else |
589 |
|
{ |
590 |
|
return S_FALSE; |
591 |
|
} |
592 |
|
|
593 |
|
return S_OK; |
594 |
|
} |
595 |
|
|
596 |
|
|
597 |
|
/* set output colorspace */ |
598 |
|
|
599 |
|
HRESULT CXvidDecoder::SetMediaType(PIN_DIRECTION direction, const CMediaType *pmt) |
600 |
|
{ |
601 |
|
DPRINTF("SetMediaType"); |
602 |
|
|
603 |
|
if (direction == PINDIR_OUTPUT) |
604 |
|
{ |
605 |
|
return ChangeColorspace(*pmt->Subtype(), *pmt->FormatType(), pmt->Format()); |
606 |
|
} |
607 |
|
|
608 |
|
return S_OK; |
609 |
|
} |
610 |
|
|
611 |
|
|
612 |
|
/* check input<->output compatiblity */ |
613 |
|
|
614 |
|
HRESULT CXvidDecoder::CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut) |
615 |
|
{ |
616 |
|
DPRINTF("CheckTransform"); |
617 |
|
return S_OK; |
618 |
|
} |
619 |
|
|
620 |
|
|
621 |
|
/* alloc output buffer */ |
622 |
|
|
623 |
|
HRESULT CXvidDecoder::DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest) |
624 |
|
{ |
625 |
|
DPRINTF("DecideBufferSize"); |
626 |
|
HRESULT result; |
627 |
|
ALLOCATOR_PROPERTIES ppropActual; |
628 |
|
|
629 |
|
if (m_pInput->IsConnected() == FALSE) |
630 |
|
{ |
631 |
|
return E_UNEXPECTED; |
632 |
|
} |
633 |
|
|
634 |
|
ppropInputRequest->cBuffers = 1; |
635 |
|
ppropInputRequest->cbBuffer = m_create.width * m_create.height * 4; |
636 |
|
// cbAlign causes problems with the resize filter */ |
637 |
|
// ppropInputRequest->cbAlign = 16; |
638 |
|
ppropInputRequest->cbPrefix = 0; |
639 |
|
|
640 |
|
result = pAlloc->SetProperties(ppropInputRequest, &ppropActual); |
641 |
|
if (result != S_OK) |
642 |
|
{ |
643 |
|
return result; |
644 |
|
} |
645 |
|
|
646 |
|
if (ppropActual.cbBuffer < ppropInputRequest->cbBuffer) |
647 |
|
{ |
648 |
|
return E_FAIL; |
649 |
|
} |
650 |
|
|
651 |
|
return S_OK; |
652 |
|
} |
653 |
|
|
654 |
|
|
655 |
|
/* decode frame */ |
656 |
|
|
657 |
|
HRESULT CXvidDecoder::Transform(IMediaSample *pIn, IMediaSample *pOut) |
658 |
|
{ |
659 |
|
DPRINTF("Transform"); |
660 |
|
xvid_dec_stats_t stats; |
661 |
|
int length; |
662 |
|
|
663 |
|
memset(&stats, 0, sizeof(stats)); |
664 |
|
stats.version = XVID_VERSION; |
665 |
|
|
666 |
|
if (m_create.handle == NULL) |
667 |
|
{ |
668 |
|
if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0) |
669 |
|
{ |
670 |
|
DPRINTF("*** XVID_DEC_CREATE error"); |
671 |
|
return S_FALSE; |
672 |
|
} |
673 |
|
} |
674 |
|
|
675 |
|
AM_MEDIA_TYPE * mtOut; |
676 |
|
pOut->GetMediaType(&mtOut); |
677 |
|
if (mtOut != NULL) |
678 |
|
{ |
679 |
|
HRESULT result; |
680 |
|
|
681 |
|
result = ChangeColorspace(mtOut->subtype, mtOut->formattype, mtOut->pbFormat); |
682 |
|
DeleteMediaType(mtOut); |
683 |
|
|
684 |
|
if (result != S_OK) |
685 |
|
{ |
686 |
|
DPRINTF("*** ChangeColorspace error"); |
687 |
|
return result; |
688 |
|
} |
689 |
|
} |
690 |
|
|
691 |
|
m_frame.length = pIn->GetActualDataLength(); |
692 |
|
if (pIn->GetPointer((BYTE**)&m_frame.bitstream) != S_OK) |
693 |
|
{ |
694 |
|
return S_FALSE; |
695 |
|
} |
696 |
|
|
697 |
|
if (pOut->GetPointer((BYTE**)&m_frame.output.plane[0]) != S_OK) |
698 |
|
{ |
699 |
|
return S_FALSE; |
700 |
|
} |
701 |
|
|
702 |
|
m_frame.general = XVID_LOWDELAY; |
703 |
|
|
704 |
|
if (pIn->IsDiscontinuity() == S_OK) |
705 |
|
m_frame.general = XVID_DISCONTINUITY; |
706 |
|
|
707 |
|
if (g_config.nDeblock_Y) |
708 |
|
m_frame.general |= XVID_DEBLOCKY; |
709 |
|
|
710 |
|
if (g_config.nDeblock_UV) |
711 |
|
m_frame.general |= XVID_DEBLOCKUV; |
712 |
|
/* |
713 |
|
if (g_config.nDering) |
714 |
|
m_frame.general |= XVID_DERING; |
715 |
|
*/ |
716 |
|
if (g_config.nFilmEffect) |
717 |
|
m_frame.general |= XVID_FILMEFFECT; |
718 |
|
|
719 |
|
m_frame.output.csp &= ~XVID_CSP_VFLIP; |
720 |
|
m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0); |
721 |
|
|
722 |
|
repeat : |
723 |
|
|
724 |
|
if (pIn->IsPreroll() != S_OK) |
725 |
|
{ |
726 |
|
length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); |
727 |
|
|
728 |
|
if (length < 0) |
729 |
|
{ |
730 |
|
DPRINTF("*** XVID_DEC_DECODE"); |
731 |
|
return S_FALSE; |
732 |
|
} |
733 |
|
} |
734 |
|
else |
735 |
|
{ /* Preroll frame - won't be displayed */ |
736 |
|
int tmp = m_frame.output.csp; |
737 |
|
int tmp_gen = m_frame.general; |
738 |
|
|
739 |
|
m_frame.output.csp = XVID_CSP_NULL; |
740 |
|
|
741 |
|
/* Disable postprocessing to speed-up seeking */ |
742 |
|
m_frame.general &= ~XVID_DEBLOCKY; |
743 |
|
m_frame.general &= ~XVID_DEBLOCKUV; |
744 |
|
/* m_frame.general &= ~XVID_DERING; */ |
745 |
|
m_frame.general &= ~XVID_FILMEFFECT; |
746 |
|
|
747 |
|
length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); |
748 |
|
if (length < 0) |
749 |
|
{ |
750 |
|
DPRINTF("*** XVID_DEC_DECODE"); |
751 |
|
return S_FALSE; |
752 |
|
} |
753 |
|
|
754 |
|
m_frame.output.csp = tmp; |
755 |
|
m_frame.general = tmp_gen; |
756 |
|
} |
757 |
|
|
758 |
|
if (stats.type == XVID_TYPE_NOTHING && length > 0) { |
759 |
|
DPRINTF("B-Frame decoder lag"); |
760 |
|
return S_FALSE; |
761 |
|
} |
762 |
|
|
763 |
|
|
764 |
|
if (stats.type == XVID_TYPE_VOL) |
765 |
|
{ |
766 |
|
if (stats.data.vol.width != m_create.width || |
767 |
|
stats.data.vol.height != m_create.height) |
768 |
|
{ |
769 |
|
DPRINTF("TODO: auto-resize"); |
770 |
|
return S_FALSE; |
771 |
|
} |
772 |
|
|
773 |
|
pOut->SetDiscontinuity(TRUE); |
774 |
|
pOut->SetSyncPoint(TRUE); |
775 |
|
|
776 |
|
m_frame.bitstream = (BYTE*)m_frame.bitstream + length; |
777 |
|
m_frame.length -= length; |
778 |
|
goto repeat; |
779 |
|
} |
780 |
|
|
781 |
|
if (pIn->IsPreroll() == S_OK) { |
782 |
|
return S_FALSE; |
783 |
|
} |
784 |
|
|
785 |
|
return S_OK; |
786 |
|
} |
787 |
|
|
788 |
|
|
789 |
|
/* get property page list */ |
790 |
|
|
791 |
|
STDMETHODIMP CXvidDecoder::GetPages(CAUUID * pPages) |
792 |
|
{ |
793 |
|
DPRINTF("GetPages"); |
794 |
|
|
795 |
|
pPages->cElems = 1; |
796 |
|
pPages->pElems = (GUID *)CoTaskMemAlloc(pPages->cElems * sizeof(GUID)); |
797 |
|
if (pPages->pElems == NULL) |
798 |
|
{ |
799 |
|
return E_OUTOFMEMORY; |
800 |
|
} |
801 |
|
pPages->pElems[0] = CLSID_CABOUT; |
802 |
|
|
803 |
|
return S_OK; |
804 |
|
} |
805 |
|
|
806 |
|
|
807 |
|
/* cleanup pages */ |
808 |
|
|
809 |
|
STDMETHODIMP CXvidDecoder::FreePages(CAUUID * pPages) |
810 |
|
{ |
811 |
|
DPRINTF("FreePages"); |
812 |
|
CoTaskMemFree(pPages->pElems); |
813 |
|
return S_OK; |
814 |
|
} |