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

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