[svn] / branches / dev-api-4 / xvidcore / dshow / src / CXvidDecoder.cpp Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/dshow/src/CXvidDecoder.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1341 - (view) (download)

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

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4