[svn] / trunk / xvidcore / dshow / src / CXvidDecoder.cpp Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/dshow/src/CXvidDecoder.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1529 - (view) (download)

1 : edgomez 1384 /*****************************************************************************
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 : syskin 1529 * $Id: CXvidDecoder.cpp,v 1.12 2004-08-01 08:45:15 syskin Exp $
23 : edgomez 1384 *
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 : suxen_drol 1521 C:\DX90SDK\Include
40 :     C:\DX90SDK\Samples\C++\DirectShow\BaseClasses
41 : edgomez 1384
42 : suxen_drol 1521 C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Release
43 :     C:\DX90SDK\Samples\C++\DirectShow\BaseClasses\Debug
44 : edgomez 1384 */
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 :     m_hdll = LoadLibrary(XVID_DLL_NAME);
216 :     if (m_hdll == NULL) {
217 :     DPRINTF("dll load failed");
218 : syskin 1498 MessageBox(0, XVID_DLL_NAME " not found","Error", MB_TOPMOST);
219 : edgomez 1384 return;
220 :     }
221 :    
222 :     xvid_global_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global");
223 :     if (xvid_global_func == NULL) {
224 : syskin 1498 MessageBox(0, "xvid_global() not found", "Error", MB_TOPMOST);
225 : edgomez 1384 return;
226 :     }
227 :    
228 :     xvid_decore_func = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_decore");
229 :     if (xvid_decore_func == NULL) {
230 : syskin 1498 MessageBox(0, "xvid_decore() not found", "Error", MB_TOPMOST);
231 : edgomez 1384 return;
232 :     }
233 :    
234 :     if (xvid_global_func(0, XVID_GBL_INIT, &init, NULL) < 0)
235 :     {
236 : syskin 1498 MessageBox(0, "xvid_global() failed", "Error", MB_TOPMOST);
237 : edgomez 1384 return;
238 :     }
239 :    
240 :     memset(&m_create, 0, sizeof(m_create));
241 :     m_create.version = XVID_VERSION;
242 :     m_create.handle = NULL;
243 :    
244 :     memset(&m_frame, 0, sizeof(m_frame));
245 :     m_frame.version = XVID_VERSION;
246 :    
247 :     LoadRegistryInfo();
248 :    
249 :     USE_IYUV = false;
250 :     USE_YV12 = false;
251 :     USE_YUY2 = false;
252 :     USE_YVYU = false;
253 :     USE_UYVY = false;
254 :     USE_RGB32 = false;
255 :     USE_RGB24 = false;
256 :     USE_RG555 = false;
257 :     USE_RG565 = false;
258 :    
259 :     switch ( g_config.nForceColorspace )
260 :     {
261 :     case FORCE_NONE:
262 :     USE_IYUV = true;
263 :     USE_YV12 = true;
264 :     USE_YUY2 = true;
265 :     USE_YVYU = true;
266 :     USE_UYVY = true;
267 :     USE_RGB32 = true;
268 :     USE_RGB24 = true;
269 :     USE_RG555 = true;
270 :     USE_RG565 = true;
271 :     break;
272 :     case FORCE_YV12:
273 :     USE_IYUV = true;
274 :     USE_YV12 = true;
275 :     break;
276 :     case FORCE_YUY2:
277 :     USE_YUY2 = true;
278 :     break;
279 :     case FORCE_RGB24:
280 :     USE_RGB24 = true;
281 :     break;
282 :     case FORCE_RGB32:
283 :     USE_RGB32 = true;
284 :     break;
285 :     }
286 : syskin 1488
287 :     switch (g_config.aspect_ratio)
288 :     {
289 : syskin 1498 case 0:
290 :     case 1:
291 : syskin 1488 break;
292 : syskin 1498 case 2:
293 : syskin 1488 ar_x = 4;
294 :     ar_y = 3;
295 :     break;
296 : syskin 1498 case 3:
297 : syskin 1488 ar_x = 16;
298 :     ar_y = 9;
299 :     break;
300 : syskin 1498 case 4:
301 : syskin 1488 ar_x = 47;
302 :     ar_y = 20;
303 :     break;
304 :     }
305 : edgomez 1384 }
306 :    
307 : syskin 1428 void CXvidDecoder::CloseLib()
308 : edgomez 1384 {
309 :     DPRINTF("Destructor");
310 :    
311 : syskin 1428 if (m_create.handle != NULL) {
312 : edgomez 1384 xvid_decore_func(m_create.handle, XVID_DEC_DESTROY, 0, 0);
313 :     m_create.handle = NULL;
314 :     }
315 :    
316 : syskin 1428 if (m_hdll != NULL) {
317 : edgomez 1384 FreeLibrary(m_hdll);
318 :     m_hdll = NULL;
319 :     }
320 :     }
321 :    
322 : syskin 1428 /* destructor */
323 : edgomez 1384
324 : syskin 1428 CXvidDecoder::~CXvidDecoder()
325 :     {
326 :     CloseLib();
327 :     }
328 : edgomez 1384
329 : syskin 1428
330 :    
331 : edgomez 1384 /* check input type */
332 :    
333 :     HRESULT CXvidDecoder::CheckInputType(const CMediaType * mtIn)
334 :     {
335 :     DPRINTF("CheckInputType");
336 :     BITMAPINFOHEADER * hdr;
337 : syskin 1498
338 :     ar_x = ar_y = 0;
339 : edgomez 1384
340 :     if (*mtIn->Type() != MEDIATYPE_Video)
341 :     {
342 :     DPRINTF("Error: Unknown Type");
343 : syskin 1428 CloseLib();
344 : edgomez 1384 return VFW_E_TYPE_NOT_ACCEPTED;
345 :     }
346 :    
347 :     if (*mtIn->FormatType() == FORMAT_VideoInfo)
348 :     {
349 :     VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format();
350 :     hdr = &vih->bmiHeader;
351 :     }
352 :     else if (*mtIn->FormatType() == FORMAT_VideoInfo2)
353 :     {
354 :     VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format();
355 :     hdr = &vih2->bmiHeader;
356 : syskin 1498 if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) {
357 : syskin 1488 ar_x = vih2->dwPictAspectRatioX;
358 :     ar_y = vih2->dwPictAspectRatioY;
359 :     }
360 : edgomez 1384 DPRINTF("VIDEOINFOHEADER2 AR: %d:%d", ar_x, ar_y);
361 :     }
362 :     else
363 :     {
364 :     DPRINTF("Error: Unknown FormatType");
365 : syskin 1428 CloseLib();
366 : edgomez 1384 return VFW_E_TYPE_NOT_ACCEPTED;
367 :     }
368 :    
369 :     if (hdr->biHeight < 0)
370 :     {
371 :     DPRINTF("colorspace: inverted input format not supported");
372 :     }
373 :    
374 :     m_create.width = hdr->biWidth;
375 :     m_create.height = hdr->biHeight;
376 :    
377 :     switch(hdr->biCompression)
378 :     {
379 :    
380 :     case FOURCC_MP4V:
381 : syskin 1428 if (!(g_config.supported_4cc & SUPPORT_MP4V)) {
382 :     CloseLib();
383 :     return VFW_E_TYPE_NOT_ACCEPTED;
384 :     }
385 : edgomez 1384 break;
386 :     case FOURCC_DIVX :
387 : syskin 1428 if (!(g_config.supported_4cc & SUPPORT_DIVX)) {
388 :     CloseLib();
389 :     return VFW_E_TYPE_NOT_ACCEPTED;
390 :     }
391 : edgomez 1384 break;
392 :     case FOURCC_DX50 :
393 : syskin 1428 if (!(g_config.supported_4cc & SUPPORT_DX50)) {
394 :     CloseLib();
395 :     return VFW_E_TYPE_NOT_ACCEPTED;
396 :     }
397 : edgomez 1384 case FOURCC_XVID :
398 :     break;
399 :    
400 :    
401 :     default :
402 :     DPRINTF("Unknown fourcc: 0x%08x (%c%c%c%c)",
403 :     hdr->biCompression,
404 :     (hdr->biCompression)&0xff,
405 :     (hdr->biCompression>>8)&0xff,
406 :     (hdr->biCompression>>16)&0xff,
407 :     (hdr->biCompression>>24)&0xff);
408 : syskin 1428 CloseLib();
409 : edgomez 1384 return VFW_E_TYPE_NOT_ACCEPTED;
410 :     }
411 :     return S_OK;
412 :     }
413 :    
414 :    
415 :     /* get list of supported output colorspaces */
416 :    
417 :    
418 :     HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut)
419 :     {
420 :     BITMAPINFOHEADER * bmih;
421 :     DPRINTF("GetMediaType");
422 :    
423 :     if (m_pInput->IsConnected() == FALSE)
424 :     {
425 :     return E_UNEXPECTED;
426 :     }
427 :    
428 :     if (!g_config.videoinfo_compat) {
429 :     VIDEOINFOHEADER2 * vih = (VIDEOINFOHEADER2 *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER2));
430 :     if (vih == NULL) return E_OUTOFMEMORY;
431 :    
432 :     ZeroMemory(vih, sizeof (VIDEOINFOHEADER2));
433 :     bmih = &(vih->bmiHeader);
434 :     mtOut->SetFormatType(&FORMAT_VideoInfo2);
435 :    
436 :     if (ar_x != 0 && ar_y != 0) {
437 :     vih->dwPictAspectRatioX = ar_x;
438 :     vih->dwPictAspectRatioY = ar_y;
439 : syskin 1498 forced_ar = true;
440 : edgomez 1384 } else { // just to be safe
441 :     vih->dwPictAspectRatioX = m_create.width;
442 :     vih->dwPictAspectRatioY = abs(m_create.height);
443 : syskin 1498 forced_ar = false;
444 :     }
445 : edgomez 1384 } else {
446 :    
447 :     VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER));
448 :     if (vih == NULL) return E_OUTOFMEMORY;
449 :    
450 :     ZeroMemory(vih, sizeof (VIDEOINFOHEADER));
451 :     bmih = &(vih->bmiHeader);
452 :     mtOut->SetFormatType(&FORMAT_VideoInfo);
453 :     }
454 :    
455 :     bmih->biSize = sizeof(BITMAPINFOHEADER);
456 :     bmih->biWidth = m_create.width;
457 :     bmih->biHeight = m_create.height;
458 :     bmih->biPlanes = 1;
459 :    
460 :     if (iPosition < 0) return E_INVALIDARG;
461 :    
462 :     switch(iPosition)
463 :     {
464 :    
465 :     case 0:
466 :     if ( USE_YUY2 )
467 :     {
468 :     bmih->biCompression = MEDIASUBTYPE_YUY2.Data1;
469 :     bmih->biBitCount = 16;
470 :     mtOut->SetSubtype(&MEDIASUBTYPE_YUY2);
471 :     break;
472 :     }
473 :     case 1 :
474 :     if ( USE_YVYU )
475 :     {
476 :     bmih->biCompression = MEDIASUBTYPE_YVYU.Data1;
477 :     bmih->biBitCount = 16;
478 :     mtOut->SetSubtype(&MEDIASUBTYPE_YVYU);
479 :     break;
480 :     }
481 :     case 2 :
482 :     if ( USE_UYVY )
483 :     {
484 :     bmih->biCompression = MEDIASUBTYPE_UYVY.Data1;
485 :     bmih->biBitCount = 16;
486 :     mtOut->SetSubtype(&MEDIASUBTYPE_UYVY);
487 :     break;
488 :     }
489 :     case 3 :
490 :     if ( USE_IYUV )
491 :     {
492 :     bmih->biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1;
493 :     bmih->biBitCount = 12;
494 :     mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV);
495 :     break;
496 :     }
497 :     case 4 :
498 :     if ( USE_YV12 )
499 :     {
500 :     bmih->biCompression = MEDIASUBTYPE_YV12.Data1;
501 :     bmih->biBitCount = 12;
502 :     mtOut->SetSubtype(&MEDIASUBTYPE_YV12);
503 :     break;
504 :     }
505 :     case 5 :
506 :     if ( USE_RGB32 )
507 :     {
508 :     bmih->biCompression = BI_RGB;
509 :     bmih->biBitCount = 32;
510 :     mtOut->SetSubtype(&MEDIASUBTYPE_RGB32);
511 :     break;
512 :     }
513 :     case 6 :
514 :     if ( USE_RGB24 )
515 :     {
516 :     bmih->biCompression = BI_RGB;
517 :     bmih->biBitCount = 24;
518 :     mtOut->SetSubtype(&MEDIASUBTYPE_RGB24);
519 :     break;
520 :     }
521 :     case 7 :
522 :     if ( USE_RG555 )
523 :     {
524 :     bmih->biCompression = BI_RGB;
525 :     bmih->biBitCount = 16;
526 :     mtOut->SetSubtype(&MEDIASUBTYPE_RGB555);
527 :     break;
528 :     }
529 :     case 8 :
530 :     if ( USE_RG565 )
531 :     {
532 :     bmih->biCompression = BI_RGB;
533 :     bmih->biBitCount = 16;
534 :     mtOut->SetSubtype(&MEDIASUBTYPE_RGB565);
535 :     break;
536 :     }
537 :     default :
538 :     return VFW_S_NO_MORE_ITEMS;
539 :     }
540 :    
541 :     bmih->biSizeImage = GetBitmapSize(bmih);
542 :    
543 :     mtOut->SetType(&MEDIATYPE_Video);
544 :     mtOut->SetTemporalCompression(FALSE);
545 :     mtOut->SetSampleSize(bmih->biSizeImage);
546 :    
547 :     return S_OK;
548 :     }
549 :    
550 :    
551 :     /* (internal function) change colorspace */
552 :    
553 :     HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format)
554 :     {
555 :     if (formattype == FORMAT_VideoInfo)
556 :     {
557 :     VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format;
558 :     m_frame.output.stride[0] = (((vih->bmiHeader.biWidth * vih->bmiHeader.biBitCount) + 31) & ~31) >> 3;
559 :     rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP);
560 :     }
561 :     else if (formattype == FORMAT_VideoInfo2)
562 :     {
563 :     VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format;
564 :     m_frame.output.stride[0] = (((vih2->bmiHeader.biWidth * vih2->bmiHeader.biBitCount) + 31) & ~31) >> 3;
565 :     rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP);
566 :     }
567 :     else
568 :     {
569 :     return S_FALSE;
570 :     }
571 :    
572 :     if (subtype == CLSID_MEDIASUBTYPE_IYUV)
573 :     {
574 :     DPRINTF("IYUV");
575 :     rgb_flip = 0;
576 :     m_frame.output.csp = XVID_CSP_I420;
577 :     m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3; /* planar format fix */
578 :     }
579 :     else if (subtype == MEDIASUBTYPE_YV12)
580 :     {
581 :     DPRINTF("YV12");
582 :     rgb_flip = 0;
583 :     m_frame.output.csp = XVID_CSP_YV12;
584 :     m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3; /* planar format fix */
585 :     }
586 :     else if (subtype == MEDIASUBTYPE_YUY2)
587 :     {
588 :     DPRINTF("YUY2");
589 :     rgb_flip = 0;
590 :     m_frame.output.csp = XVID_CSP_YUY2;
591 :     }
592 :     else if (subtype == MEDIASUBTYPE_YVYU)
593 :     {
594 :     DPRINTF("YVYU");
595 :     rgb_flip = 0;
596 :     m_frame.output.csp = XVID_CSP_YVYU;
597 :     }
598 :     else if (subtype == MEDIASUBTYPE_UYVY)
599 :     {
600 :     DPRINTF("UYVY");
601 :     rgb_flip = 0;
602 :     m_frame.output.csp = XVID_CSP_UYVY;
603 :     }
604 :     else if (subtype == MEDIASUBTYPE_RGB32)
605 :     {
606 :     DPRINTF("RGB32");
607 :     m_frame.output.csp = rgb_flip | XVID_CSP_BGRA;
608 :     }
609 :     else if (subtype == MEDIASUBTYPE_RGB24)
610 :     {
611 :     DPRINTF("RGB24");
612 :     m_frame.output.csp = rgb_flip | XVID_CSP_BGR;
613 :     }
614 :     else if (subtype == MEDIASUBTYPE_RGB555)
615 :     {
616 :     DPRINTF("RGB555");
617 :     m_frame.output.csp = rgb_flip | XVID_CSP_RGB555;
618 :     }
619 :     else if (subtype == MEDIASUBTYPE_RGB565)
620 :     {
621 :     DPRINTF("RGB565");
622 :     m_frame.output.csp = rgb_flip | XVID_CSP_RGB565;
623 :     }
624 :     else if (subtype == GUID_NULL)
625 :     {
626 :     m_frame.output.csp = XVID_CSP_NULL;
627 :     }
628 :     else
629 :     {
630 :     return S_FALSE;
631 :     }
632 :    
633 :     return S_OK;
634 :     }
635 :    
636 :    
637 :     /* set output colorspace */
638 :    
639 :     HRESULT CXvidDecoder::SetMediaType(PIN_DIRECTION direction, const CMediaType *pmt)
640 :     {
641 :     DPRINTF("SetMediaType");
642 :    
643 :     if (direction == PINDIR_OUTPUT)
644 :     {
645 :     return ChangeColorspace(*pmt->Subtype(), *pmt->FormatType(), pmt->Format());
646 :     }
647 :    
648 :     return S_OK;
649 :     }
650 :    
651 :    
652 :     /* check input<->output compatiblity */
653 :    
654 :     HRESULT CXvidDecoder::CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut)
655 :     {
656 :     DPRINTF("CheckTransform");
657 :     return S_OK;
658 :     }
659 :    
660 :    
661 :     /* alloc output buffer */
662 :    
663 :     HRESULT CXvidDecoder::DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
664 :     {
665 :     DPRINTF("DecideBufferSize");
666 :     HRESULT result;
667 :     ALLOCATOR_PROPERTIES ppropActual;
668 :    
669 :     if (m_pInput->IsConnected() == FALSE)
670 :     {
671 :     return E_UNEXPECTED;
672 :     }
673 :    
674 :     ppropInputRequest->cBuffers = 1;
675 :     ppropInputRequest->cbBuffer = m_create.width * m_create.height * 4;
676 :     // cbAlign causes problems with the resize filter */
677 :     // ppropInputRequest->cbAlign = 16;
678 :     ppropInputRequest->cbPrefix = 0;
679 :    
680 :     result = pAlloc->SetProperties(ppropInputRequest, &ppropActual);
681 :     if (result != S_OK)
682 :     {
683 :     return result;
684 :     }
685 :    
686 :     if (ppropActual.cbBuffer < ppropInputRequest->cbBuffer)
687 :     {
688 :     return E_FAIL;
689 :     }
690 :    
691 :     return S_OK;
692 :     }
693 :    
694 :    
695 :     /* decode frame */
696 :    
697 :     HRESULT CXvidDecoder::Transform(IMediaSample *pIn, IMediaSample *pOut)
698 :     {
699 :     DPRINTF("Transform");
700 :     xvid_dec_stats_t stats;
701 :     int length;
702 :    
703 :     memset(&stats, 0, sizeof(stats));
704 :     stats.version = XVID_VERSION;
705 :    
706 :     if (m_create.handle == NULL)
707 :     {
708 :     if (xvid_decore_func(0, XVID_DEC_CREATE, &m_create, 0) < 0)
709 :     {
710 :     DPRINTF("*** XVID_DEC_CREATE error");
711 :     return S_FALSE;
712 :     }
713 :     }
714 :    
715 :     AM_MEDIA_TYPE * mtOut;
716 :     pOut->GetMediaType(&mtOut);
717 :     if (mtOut != NULL)
718 :     {
719 :     HRESULT result;
720 :    
721 :     result = ChangeColorspace(mtOut->subtype, mtOut->formattype, mtOut->pbFormat);
722 :     DeleteMediaType(mtOut);
723 :    
724 :     if (result != S_OK)
725 :     {
726 :     DPRINTF("*** ChangeColorspace error");
727 :     return result;
728 :     }
729 :     }
730 :    
731 :     m_frame.length = pIn->GetActualDataLength();
732 :     if (pIn->GetPointer((BYTE**)&m_frame.bitstream) != S_OK)
733 :     {
734 :     return S_FALSE;
735 :     }
736 :    
737 :     if (pOut->GetPointer((BYTE**)&m_frame.output.plane[0]) != S_OK)
738 :     {
739 :     return S_FALSE;
740 :     }
741 :    
742 :     m_frame.general = XVID_LOWDELAY;
743 :    
744 :     if (pIn->IsDiscontinuity() == S_OK)
745 : syskin 1427 m_frame.general |= XVID_DISCONTINUITY;
746 : edgomez 1384
747 :     if (g_config.nDeblock_Y)
748 :     m_frame.general |= XVID_DEBLOCKY;
749 :    
750 :     if (g_config.nDeblock_UV)
751 :     m_frame.general |= XVID_DEBLOCKUV;
752 : syskin 1437
753 :     if (g_config.nDering_Y)
754 :     m_frame.general |= XVID_DERINGY;
755 :    
756 :     if (g_config.nDering_UV)
757 :     m_frame.general |= XVID_DERINGUV;
758 :    
759 : edgomez 1384 if (g_config.nFilmEffect)
760 :     m_frame.general |= XVID_FILMEFFECT;
761 :    
762 : suxen_drol 1397 m_frame.brightness = g_config.nBrightness;
763 :    
764 : edgomez 1384 m_frame.output.csp &= ~XVID_CSP_VFLIP;
765 :     m_frame.output.csp |= rgb_flip^(g_config.nFlipVideo ? XVID_CSP_VFLIP : 0);
766 :    
767 : syskin 1498
768 :    
769 :    
770 : edgomez 1384 repeat :
771 :    
772 :     if (pIn->IsPreroll() != S_OK)
773 :     {
774 :     length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);
775 :    
776 :     if (length < 0)
777 :     {
778 :     DPRINTF("*** XVID_DEC_DECODE");
779 :     return S_FALSE;
780 : syskin 1498 } else
781 :     if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1 && forced_ar == false) {
782 :     // inspired by minolta! works for VMR 7 + 9
783 :    
784 :     IMediaSample2 *pOut2 = NULL;
785 :     AM_SAMPLE2_PROPERTIES outProp2;
786 :     if (SUCCEEDED(pOut->QueryInterface(IID_IMediaSample2, (void **)&pOut2)) &&
787 :     SUCCEEDED(pOut2->GetProperties(FIELD_OFFSET(AM_SAMPLE2_PROPERTIES, tStart), (PBYTE)&outProp2)))
788 :     {
789 :     CMediaType mtOut2 = m_pOutput->CurrentMediaType();
790 :     VIDEOINFOHEADER2* vihOut2 = (VIDEOINFOHEADER2*)mtOut2.Format();
791 : suxen_drol 1502
792 :     if (*mtOut2.FormatType() == FORMAT_VideoInfo2 &&
793 :     vihOut2->dwPictAspectRatioX != ar_x && vihOut2->dwPictAspectRatioY != ar_y)
794 : syskin 1498 {
795 :     vihOut2->dwPictAspectRatioX = ar_x;
796 :     vihOut2->dwPictAspectRatioY = ar_y;
797 :     pOut2->SetMediaType(&mtOut2);
798 :     m_pOutput->SetMediaType(&mtOut2);
799 :     }
800 :     pOut2->Release();
801 :     }
802 : edgomez 1384 }
803 :     }
804 :     else
805 :     { /* Preroll frame - won't be displayed */
806 :     int tmp = m_frame.output.csp;
807 :     int tmp_gen = m_frame.general;
808 :    
809 :     m_frame.output.csp = XVID_CSP_NULL;
810 :    
811 :     /* Disable postprocessing to speed-up seeking */
812 :     m_frame.general &= ~XVID_DEBLOCKY;
813 :     m_frame.general &= ~XVID_DEBLOCKUV;
814 :     /* m_frame.general &= ~XVID_DERING; */
815 :     m_frame.general &= ~XVID_FILMEFFECT;
816 :    
817 :     length = xvid_decore_func(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats);
818 :     if (length < 0)
819 :     {
820 :     DPRINTF("*** XVID_DEC_DECODE");
821 :     return S_FALSE;
822 :     }
823 :    
824 :     m_frame.output.csp = tmp;
825 :     m_frame.general = tmp_gen;
826 :     }
827 :    
828 :     if (stats.type == XVID_TYPE_NOTHING && length > 0) {
829 : edgomez 1432 DPRINTF(" B-Frame decoder lag");
830 : edgomez 1384 return S_FALSE;
831 :     }
832 :    
833 :    
834 :     if (stats.type == XVID_TYPE_VOL)
835 :     {
836 :     if (stats.data.vol.width != m_create.width ||
837 :     stats.data.vol.height != m_create.height)
838 :     {
839 :     DPRINTF("TODO: auto-resize");
840 :     return S_FALSE;
841 :     }
842 : syskin 1498
843 : edgomez 1384 pOut->SetSyncPoint(TRUE);
844 :    
845 : syskin 1498 if (g_config.aspect_ratio == 0 || g_config.aspect_ratio == 1) { /* auto */
846 :     int par_x, par_y;
847 :     if (stats.data.vol.par == XVID_PAR_EXT) {
848 :     par_x = stats.data.vol.par_width;
849 :     par_y = stats.data.vol.par_height;
850 :     } else {
851 : syskin 1529 par_x = PARS[stats.data.vol.par-1][0];
852 :     par_y = PARS[stats.data.vol.par-1][1];
853 : syskin 1498 }
854 :    
855 :     ar_x = par_x * stats.data.vol.width;
856 :     ar_y = par_y * stats.data.vol.height;
857 :     }
858 :    
859 : edgomez 1384 m_frame.bitstream = (BYTE*)m_frame.bitstream + length;
860 :     m_frame.length -= length;
861 :     goto repeat;
862 :     }
863 :    
864 :     if (pIn->IsPreroll() == S_OK) {
865 :     return S_FALSE;
866 :     }
867 :    
868 :     return S_OK;
869 :     }
870 :    
871 :    
872 :     /* get property page list */
873 :    
874 :     STDMETHODIMP CXvidDecoder::GetPages(CAUUID * pPages)
875 :     {
876 :     DPRINTF("GetPages");
877 :    
878 :     pPages->cElems = 1;
879 :     pPages->pElems = (GUID *)CoTaskMemAlloc(pPages->cElems * sizeof(GUID));
880 :     if (pPages->pElems == NULL)
881 :     {
882 :     return E_OUTOFMEMORY;
883 :     }
884 :     pPages->pElems[0] = CLSID_CABOUT;
885 :    
886 :     return S_OK;
887 :     }
888 :    
889 :    
890 :     /* cleanup pages */
891 :    
892 :     STDMETHODIMP CXvidDecoder::FreePages(CAUUID * pPages)
893 :     {
894 :     DPRINTF("FreePages");
895 :     CoTaskMemFree(pPages->pElems);
896 :     return S_OK;
897 :     }

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