Parent Directory
|
Revision Log
Revision 1271 - (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 : | Isibaar | 1271 | * $Id: CXvidDecoder.cpp,v 1.1.2.6 2003-12-17 17:08:29 Isibaar 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 : | CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) : | ||
205 : | CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID) | ||
206 : | { | ||
207 : | DPRINTF("Constructor"); | ||
208 : | |||
209 : | xvid_gbl_init_t init; | ||
210 : | memset(&init, 0, sizeof(init)); | ||
211 : | init.version = XVID_VERSION; | ||
212 : | suxen_drol | 1208 | if (xvid_global(0, XVID_GBL_INIT, &init, NULL) < 0) |
213 : | suxen_drol | 888 | { |
214 : | suxen_drol | 1208 | MessageBox(0, "xvid_global() failed", "Error", 0); |
215 : | suxen_drol | 888 | return; |
216 : | } | ||
217 : | |||
218 : | memset(&m_create, 0, sizeof(m_create)); | ||
219 : | m_create.version = XVID_VERSION; | ||
220 : | m_create.handle = NULL; | ||
221 : | |||
222 : | memset(&m_frame, 0, sizeof(m_frame)); | ||
223 : | m_frame.version = XVID_VERSION; | ||
224 : | Isibaar | 1260 | |
225 : | HKEY hKey; | ||
226 : | DWORD size; | ||
227 : | RegOpenKeyEx(XVID_REG_KEY, XVID_REG_SUBKEY, 0, KEY_READ, &hKey); | ||
228 : | |||
229 : | // Set the default post-processing settings | ||
230 : | REG_GET_N("Brightness", PPSettings.nBrightness, 25) | ||
231 : | REG_GET_N("Deblock_Y", PPSettings.bDeblock_Y, 0) | ||
232 : | REG_GET_N("Deblock_UV", PPSettings.bDeblock_UV, 0) | ||
233 : | Isibaar | 1271 | REG_GET_N("Dering", PPSettings.bDering, 0) |
234 : | REG_GET_N("FilmEffect", PPSettings.bFilmEffect, 0) | ||
235 : | Isibaar | 1260 | REG_GET_N("ForceColorspace", PPSettings.nForceColorspace, 0) |
236 : | |||
237 : | RegCloseKey(hKey); | ||
238 : | |||
239 : | USE_IYUV = false; | ||
240 : | USE_YV12 = false; | ||
241 : | USE_YUY2 = false; | ||
242 : | USE_YVYU = false; | ||
243 : | USE_UYVY = false; | ||
244 : | USE_RGB32 = false; | ||
245 : | USE_RGB24 = false; | ||
246 : | USE_RG555 = false; | ||
247 : | USE_RG565 = false; | ||
248 : | |||
249 : | switch ( PPSettings.nForceColorspace ) | ||
250 : | { | ||
251 : | case FORCE_NONE: | ||
252 : | USE_IYUV = true; | ||
253 : | USE_YV12 = true; | ||
254 : | USE_YUY2 = true; | ||
255 : | USE_YVYU = true; | ||
256 : | USE_UYVY = true; | ||
257 : | USE_RGB32 = true; | ||
258 : | USE_RGB24 = true; | ||
259 : | USE_RG555 = true; | ||
260 : | USE_RG565 = true; | ||
261 : | break; | ||
262 : | case FORCE_YV12: | ||
263 : | USE_IYUV = true; | ||
264 : | USE_YV12 = true; | ||
265 : | break; | ||
266 : | case FORCE_YUY2: | ||
267 : | USE_YUY2 = true; | ||
268 : | break; | ||
269 : | case FORCE_RGB24: | ||
270 : | USE_RGB24 = true; | ||
271 : | break; | ||
272 : | case FORCE_RGB32: | ||
273 : | USE_RGB32 = true; | ||
274 : | break; | ||
275 : | } | ||
276 : | suxen_drol | 888 | } |
277 : | |||
278 : | |||
279 : | |||
280 : | /* destructor */ | ||
281 : | |||
282 : | CXvidDecoder::~CXvidDecoder() | ||
283 : | { | ||
284 : | DPRINTF("Destructor"); | ||
285 : | |||
286 : | if (m_create.handle != NULL) | ||
287 : | { | ||
288 : | suxen_drol | 1208 | xvid_decore(m_create.handle, XVID_DEC_DESTROY, 0, 0); |
289 : | suxen_drol | 888 | m_create.handle = NULL; |
290 : | } | ||
291 : | } | ||
292 : | |||
293 : | |||
294 : | |||
295 : | /* check input type */ | ||
296 : | |||
297 : | HRESULT CXvidDecoder::CheckInputType(const CMediaType * mtIn) | ||
298 : | { | ||
299 : | DPRINTF("CheckInputType"); | ||
300 : | BITMAPINFOHEADER * hdr; | ||
301 : | |||
302 : | if (*mtIn->Type() != MEDIATYPE_Video) | ||
303 : | { | ||
304 : | DPRINTF("Error: Unknown Type"); | ||
305 : | return VFW_E_TYPE_NOT_ACCEPTED; | ||
306 : | } | ||
307 : | |||
308 : | if (*mtIn->FormatType() == FORMAT_VideoInfo) | ||
309 : | { | ||
310 : | VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format(); | ||
311 : | hdr = &vih->bmiHeader; | ||
312 : | } | ||
313 : | else if (*mtIn->FormatType() == FORMAT_VideoInfo2) | ||
314 : | { | ||
315 : | VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format(); | ||
316 : | hdr = &vih2->bmiHeader; | ||
317 : | } | ||
318 : | else | ||
319 : | { | ||
320 : | DPRINTF("Error: Unknown FormatType"); | ||
321 : | return VFW_E_TYPE_NOT_ACCEPTED; | ||
322 : | } | ||
323 : | |||
324 : | if (hdr->biHeight < 0) | ||
325 : | { | ||
326 : | DPRINTF("colorspace: inverted input format not supported"); | ||
327 : | } | ||
328 : | |||
329 : | m_create.width = hdr->biWidth; | ||
330 : | m_create.height = hdr->biHeight; | ||
331 : | |||
332 : | switch(hdr->biCompression) | ||
333 : | { | ||
334 : | case FOURCC_XVID : | ||
335 : | // case FOURCC_DIVX : | ||
336 : | // case FOURCC_DX50 : | ||
337 : | break; | ||
338 : | |||
339 : | default : | ||
340 : | DPRINTF("Unknown fourcc: 0x%08x (%c%c%c%c)", | ||
341 : | hdr->biCompression, | ||
342 : | (hdr->biCompression)&0xff, | ||
343 : | (hdr->biCompression>>8)&0xff, | ||
344 : | (hdr->biCompression>>16)&0xff, | ||
345 : | (hdr->biCompression>>24)&0xff); | ||
346 : | return VFW_E_TYPE_NOT_ACCEPTED; | ||
347 : | } | ||
348 : | |||
349 : | return S_OK; | ||
350 : | } | ||
351 : | |||
352 : | |||
353 : | /* get list of supported output colorspaces */ | ||
354 : | |||
355 : | suxen_drol | 1208 | |
356 : | suxen_drol | 888 | HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut) |
357 : | { | ||
358 : | DPRINTF("GetMediaType"); | ||
359 : | |||
360 : | if (m_pInput->IsConnected() == FALSE) | ||
361 : | { | ||
362 : | return E_UNEXPECTED; | ||
363 : | } | ||
364 : | |||
365 : | VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER)); | ||
366 : | if (vih == NULL) | ||
367 : | { | ||
368 : | return E_OUTOFMEMORY; | ||
369 : | } | ||
370 : | |||
371 : | ZeroMemory(vih, sizeof (VIDEOINFOHEADER)); | ||
372 : | vih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | ||
373 : | vih->bmiHeader.biWidth = m_create.width; | ||
374 : | vih->bmiHeader.biHeight = m_create.height; | ||
375 : | vih->bmiHeader.biPlanes = 1; | ||
376 : | |||
377 : | if (iPosition < 0) | ||
378 : | { | ||
379 : | return E_INVALIDARG; | ||
380 : | } | ||
381 : | |||
382 : | switch(iPosition) | ||
383 : | { | ||
384 : | case 0 : | ||
385 : | Isibaar | 1260 | if ( USE_IYUV ) |
386 : | { | ||
387 : | suxen_drol | 1208 | vih->bmiHeader.biCompression = CLSID_MEDIASUBTYPE_IYUV.Data1; |
388 : | suxen_drol | 888 | vih->bmiHeader.biBitCount = 12; |
389 : | suxen_drol | 1208 | mtOut->SetSubtype(&CLSID_MEDIASUBTYPE_IYUV); |
390 : | suxen_drol | 888 | break; |
391 : | Isibaar | 1260 | } |
392 : | suxen_drol | 888 | case 1 : |
393 : | Isibaar | 1260 | if ( USE_YV12 ) |
394 : | { | ||
395 : | suxen_drol | 888 | vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1; |
396 : | vih->bmiHeader.biBitCount = 12; | ||
397 : | mtOut->SetSubtype(&MEDIASUBTYPE_YV12); | ||
398 : | break; | ||
399 : | Isibaar | 1260 | } |
400 : | suxen_drol | 888 | case 2: |
401 : | Isibaar | 1260 | if ( USE_YUY2 ) |
402 : | { | ||
403 : | suxen_drol | 888 | vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1; |
404 : | vih->bmiHeader.biBitCount = 16; | ||
405 : | mtOut->SetSubtype(&MEDIASUBTYPE_YUY2); | ||
406 : | break; | ||
407 : | Isibaar | 1260 | } |
408 : | suxen_drol | 888 | case 3 : |
409 : | Isibaar | 1260 | if ( USE_YVYU ) |
410 : | { | ||
411 : | suxen_drol | 888 | vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1; |
412 : | vih->bmiHeader.biBitCount = 16; | ||
413 : | mtOut->SetSubtype(&MEDIASUBTYPE_YVYU); | ||
414 : | break; | ||
415 : | Isibaar | 1260 | } |
416 : | suxen_drol | 888 | case 4 : |
417 : | Isibaar | 1260 | if ( USE_UYVY ) |
418 : | { | ||
419 : | suxen_drol | 888 | vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1; |
420 : | vih->bmiHeader.biBitCount = 16; | ||
421 : | mtOut->SetSubtype(&MEDIASUBTYPE_UYVY); | ||
422 : | break; | ||
423 : | Isibaar | 1260 | } |
424 : | suxen_drol | 888 | case 5 : |
425 : | Isibaar | 1260 | if ( USE_RGB32 ) |
426 : | { | ||
427 : | suxen_drol | 888 | vih->bmiHeader.biCompression = BI_RGB; |
428 : | vih->bmiHeader.biBitCount = 32; | ||
429 : | mtOut->SetSubtype(&MEDIASUBTYPE_RGB32); | ||
430 : | break; | ||
431 : | Isibaar | 1260 | } |
432 : | suxen_drol | 888 | case 6 : |
433 : | Isibaar | 1260 | if ( USE_RGB24 ) |
434 : | { | ||
435 : | suxen_drol | 888 | vih->bmiHeader.biCompression = BI_RGB; |
436 : | vih->bmiHeader.biBitCount = 24; | ||
437 : | mtOut->SetSubtype(&MEDIASUBTYPE_RGB24); | ||
438 : | break; | ||
439 : | Isibaar | 1260 | } |
440 : | suxen_drol | 888 | case 7 : |
441 : | Isibaar | 1260 | if ( USE_RG555 ) |
442 : | { | ||
443 : | suxen_drol | 888 | vih->bmiHeader.biCompression = BI_RGB; |
444 : | vih->bmiHeader.biBitCount = 16; | ||
445 : | mtOut->SetSubtype(&MEDIASUBTYPE_RGB555); | ||
446 : | break; | ||
447 : | Isibaar | 1260 | } |
448 : | suxen_drol | 888 | case 8 : |
449 : | Isibaar | 1260 | if ( USE_RG565 ) |
450 : | { | ||
451 : | suxen_drol | 888 | vih->bmiHeader.biCompression = BI_RGB; |
452 : | vih->bmiHeader.biBitCount = 16; | ||
453 : | mtOut->SetSubtype(&MEDIASUBTYPE_RGB565); | ||
454 : | break; | ||
455 : | Isibaar | 1260 | } |
456 : | suxen_drol | 888 | default : |
457 : | return VFW_S_NO_MORE_ITEMS; | ||
458 : | } | ||
459 : | |||
460 : | vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader); | ||
461 : | |||
462 : | mtOut->SetType(&MEDIATYPE_Video); | ||
463 : | mtOut->SetFormatType(&FORMAT_VideoInfo); | ||
464 : | mtOut->SetTemporalCompression(FALSE); | ||
465 : | mtOut->SetSampleSize(vih->bmiHeader.biSizeImage); | ||
466 : | |||
467 : | return S_OK; | ||
468 : | } | ||
469 : | |||
470 : | |||
471 : | /* (internal function) change colorspace */ | ||
472 : | |||
473 : | HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format) | ||
474 : | { | ||
475 : | if (formattype == FORMAT_VideoInfo) | ||
476 : | { | ||
477 : | VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format; | ||
478 : | m_frame.output.stride[0] = (((vih->bmiHeader.biWidth * vih->bmiHeader.biBitCount) + 31) & ~31) >> 3; | ||
479 : | rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); | ||
480 : | } | ||
481 : | else if (formattype == FORMAT_VideoInfo2) | ||
482 : | { | ||
483 : | VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format; | ||
484 : | m_frame.output.stride[0] = (((vih2->bmiHeader.biWidth * vih2->bmiHeader.biBitCount) + 31) & ~31) >> 3; | ||
485 : | rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); | ||
486 : | } | ||
487 : | else | ||
488 : | { | ||
489 : | return S_FALSE; | ||
490 : | } | ||
491 : | |||
492 : | suxen_drol | 1208 | if (subtype == CLSID_MEDIASUBTYPE_IYUV) |
493 : | suxen_drol | 888 | { |
494 : | DPRINTF("IYUV"); | ||
495 : | m_frame.output.csp = XVID_CSP_I420; | ||
496 : | m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3; /* planar format fix */ | ||
497 : | } | ||
498 : | else if (subtype == MEDIASUBTYPE_YV12) | ||
499 : | { | ||
500 : | DPRINTF("YV12"); | ||
501 : | m_frame.output.csp = XVID_CSP_YV12; | ||
502 : | m_frame.output.stride[0] = (m_frame.output.stride[0] * 2) / 3; /* planar format fix */ | ||
503 : | } | ||
504 : | else if (subtype == MEDIASUBTYPE_YUY2) | ||
505 : | { | ||
506 : | DPRINTF("YUY2"); | ||
507 : | m_frame.output.csp = XVID_CSP_YUY2; | ||
508 : | } | ||
509 : | else if (subtype == MEDIASUBTYPE_YVYU) | ||
510 : | { | ||
511 : | DPRINTF("YVYU"); | ||
512 : | m_frame.output.csp = XVID_CSP_YVYU; | ||
513 : | } | ||
514 : | else if (subtype == MEDIASUBTYPE_UYVY) | ||
515 : | { | ||
516 : | DPRINTF("UYVY"); | ||
517 : | m_frame.output.csp = XVID_CSP_UYVY; | ||
518 : | } | ||
519 : | else if (subtype == MEDIASUBTYPE_RGB32) | ||
520 : | { | ||
521 : | DPRINTF("RGB32"); | ||
522 : | m_frame.output.csp = rgb_flip | XVID_CSP_BGRA; | ||
523 : | } | ||
524 : | else if (subtype == MEDIASUBTYPE_RGB24) | ||
525 : | { | ||
526 : | DPRINTF("RGB24"); | ||
527 : | m_frame.output.csp = rgb_flip | XVID_CSP_BGR; | ||
528 : | } | ||
529 : | else if (subtype == MEDIASUBTYPE_RGB555) | ||
530 : | { | ||
531 : | DPRINTF("RGB555"); | ||
532 : | m_frame.output.csp = rgb_flip | XVID_CSP_RGB555; | ||
533 : | } | ||
534 : | else if (subtype == MEDIASUBTYPE_RGB565) | ||
535 : | { | ||
536 : | DPRINTF("RGB565"); | ||
537 : | m_frame.output.csp = rgb_flip | XVID_CSP_RGB565; | ||
538 : | } | ||
539 : | else if (subtype == GUID_NULL) | ||
540 : | { | ||
541 : | m_frame.output.csp = XVID_CSP_NULL; | ||
542 : | } | ||
543 : | else | ||
544 : | { | ||
545 : | return S_FALSE; | ||
546 : | } | ||
547 : | |||
548 : | return S_OK; | ||
549 : | } | ||
550 : | |||
551 : | |||
552 : | /* set output colorspace */ | ||
553 : | |||
554 : | HRESULT CXvidDecoder::SetMediaType(PIN_DIRECTION direction, const CMediaType *pmt) | ||
555 : | { | ||
556 : | DPRINTF("SetMediaType"); | ||
557 : | |||
558 : | if (direction == PINDIR_OUTPUT) | ||
559 : | { | ||
560 : | return ChangeColorspace(*pmt->Subtype(), *pmt->FormatType(), pmt->Format()); | ||
561 : | } | ||
562 : | |||
563 : | return S_OK; | ||
564 : | } | ||
565 : | |||
566 : | |||
567 : | /* check input<->output compatiblity */ | ||
568 : | |||
569 : | HRESULT CXvidDecoder::CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut) | ||
570 : | { | ||
571 : | DPRINTF("CheckTransform"); | ||
572 : | return S_OK; | ||
573 : | } | ||
574 : | |||
575 : | |||
576 : | /* alloc output buffer */ | ||
577 : | |||
578 : | HRESULT CXvidDecoder::DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest) | ||
579 : | { | ||
580 : | DPRINTF("DecideBufferSize"); | ||
581 : | HRESULT result; | ||
582 : | ALLOCATOR_PROPERTIES ppropActual; | ||
583 : | |||
584 : | if (m_pInput->IsConnected() == FALSE) | ||
585 : | { | ||
586 : | return E_UNEXPECTED; | ||
587 : | } | ||
588 : | |||
589 : | ppropInputRequest->cBuffers = 1; | ||
590 : | ppropInputRequest->cbBuffer = m_create.width * m_create.height * 4; | ||
591 : | // cbAlign causes problems with the resize filter */ | ||
592 : | // ppropInputRequest->cbAlign = 16; | ||
593 : | ppropInputRequest->cbPrefix = 0; | ||
594 : | |||
595 : | result = pAlloc->SetProperties(ppropInputRequest, &ppropActual); | ||
596 : | if (result != S_OK) | ||
597 : | { | ||
598 : | return result; | ||
599 : | } | ||
600 : | |||
601 : | if (ppropActual.cbBuffer < ppropInputRequest->cbBuffer) | ||
602 : | { | ||
603 : | return E_FAIL; | ||
604 : | } | ||
605 : | |||
606 : | return S_OK; | ||
607 : | } | ||
608 : | |||
609 : | |||
610 : | /* decode frame */ | ||
611 : | |||
612 : | HRESULT CXvidDecoder::Transform(IMediaSample *pIn, IMediaSample *pOut) | ||
613 : | { | ||
614 : | DPRINTF("Transform"); | ||
615 : | xvid_dec_stats_t stats; | ||
616 : | int length; | ||
617 : | |||
618 : | memset(&stats, 0, sizeof(stats)); | ||
619 : | stats.version = XVID_VERSION; | ||
620 : | |||
621 : | if (m_create.handle == NULL) | ||
622 : | { | ||
623 : | suxen_drol | 1208 | if (xvid_decore(0, XVID_DEC_CREATE, &m_create, 0) < 0) |
624 : | suxen_drol | 888 | { |
625 : | DPRINTF("*** XVID_DEC_CREATE error"); | ||
626 : | return S_FALSE; | ||
627 : | } | ||
628 : | } | ||
629 : | |||
630 : | AM_MEDIA_TYPE * mtOut; | ||
631 : | pOut->GetMediaType(&mtOut); | ||
632 : | if (mtOut != NULL) | ||
633 : | { | ||
634 : | HRESULT result; | ||
635 : | |||
636 : | result = ChangeColorspace(mtOut->subtype, mtOut->formattype, mtOut->pbFormat); | ||
637 : | DeleteMediaType(mtOut); | ||
638 : | |||
639 : | if (result != S_OK) | ||
640 : | { | ||
641 : | DPRINTF("*** ChangeColorspace error"); | ||
642 : | return result; | ||
643 : | } | ||
644 : | } | ||
645 : | |||
646 : | m_frame.length = pIn->GetActualDataLength(); | ||
647 : | if (pIn->GetPointer((BYTE**)&m_frame.bitstream) != S_OK) | ||
648 : | { | ||
649 : | return S_FALSE; | ||
650 : | } | ||
651 : | |||
652 : | if (pOut->GetPointer((BYTE**)&m_frame.output.plane[0]) != S_OK) | ||
653 : | { | ||
654 : | return S_FALSE; | ||
655 : | } | ||
656 : | |||
657 : | m_frame.general = XVID_LOWDELAY; | ||
658 : | Isibaar | 1260 | |
659 : | suxen_drol | 888 | if (pIn->IsDiscontinuity() == S_OK) |
660 : | m_frame.general = XVID_DISCONTINUITY; | ||
661 : | |||
662 : | Isibaar | 1260 | if (PPSettings.bDeblock_Y) |
663 : | m_frame.general |= XVID_DEBLOCKY; | ||
664 : | |||
665 : | if (PPSettings.bDeblock_UV) | ||
666 : | m_frame.general |= XVID_DEBLOCKUV; | ||
667 : | Isibaar | 1271 | /* |
668 : | if (PPSettings.bDering) | ||
669 : | m_frame.general |= XVID_DERING; | ||
670 : | */ | ||
671 : | if (PPSettings.bFilmEffect) | ||
672 : | m_frame.general |= XVID_FILMEFFECT; | ||
673 : | |||
674 : | Isibaar | 1260 | if (PPSettings.bFlipVideo) { |
675 : | if (rgb_flip) | ||
676 : | m_frame.output.csp &= ~XVID_CSP_VFLIP; | ||
677 : | else | ||
678 : | m_frame.output.csp |= XVID_CSP_VFLIP; | ||
679 : | } | ||
680 : | else { | ||
681 : | if (rgb_flip) | ||
682 : | m_frame.output.csp |= XVID_CSP_VFLIP; | ||
683 : | else | ||
684 : | m_frame.output.csp &= ~XVID_CSP_VFLIP; | ||
685 : | } | ||
686 : | |||
687 : | suxen_drol | 888 | repeat : |
688 : | |||
689 : | if (pIn->IsPreroll() != S_OK) | ||
690 : | { | ||
691 : | suxen_drol | 1208 | length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); |
692 : | syskin | 1250 | |
693 : | suxen_drol | 888 | if (length < 0) |
694 : | { | ||
695 : | DPRINTF("*** XVID_DEC_DECODE"); | ||
696 : | return S_FALSE; | ||
697 : | } | ||
698 : | } | ||
699 : | else | ||
700 : | { | ||
701 : | int tmp = m_frame.output.csp; | ||
702 : | m_frame.output.csp = XVID_CSP_NULL; | ||
703 : | |||
704 : | suxen_drol | 1208 | length = xvid_decore(m_create.handle, XVID_DEC_DECODE, &m_frame, &stats); |
705 : | suxen_drol | 888 | if (length < 0) |
706 : | { | ||
707 : | DPRINTF("*** XVID_DEC_DECODE"); | ||
708 : | return S_FALSE; | ||
709 : | } | ||
710 : | |||
711 : | m_frame.output.csp = tmp; | ||
712 : | } | ||
713 : | |||
714 : | syskin | 1250 | if (stats.type == XVID_TYPE_NOTHING) { |
715 : | DPRINTF("B-Frame decoder lag"); | ||
716 : | return S_FALSE; | ||
717 : | } | ||
718 : | |||
719 : | |||
720 : | suxen_drol | 888 | if (stats.type == XVID_TYPE_VOL) |
721 : | { | ||
722 : | if (stats.data.vol.width != m_create.width || | ||
723 : | stats.data.vol.height != m_create.height) | ||
724 : | { | ||
725 : | DPRINTF("TODO: auto-resize"); | ||
726 : | return S_FALSE; | ||
727 : | } | ||
728 : | |||
729 : | m_frame.bitstream = (BYTE*)m_frame.bitstream + length; | ||
730 : | m_frame.length -= length; | ||
731 : | goto repeat; | ||
732 : | } | ||
733 : | |||
734 : | return S_OK; | ||
735 : | } | ||
736 : | |||
737 : | |||
738 : | /* get property page list */ | ||
739 : | |||
740 : | STDMETHODIMP CXvidDecoder::GetPages(CAUUID * pPages) | ||
741 : | { | ||
742 : | DPRINTF("GetPages"); | ||
743 : | |||
744 : | pPages->cElems = 1; | ||
745 : | pPages->pElems = (GUID *)CoTaskMemAlloc(pPages->cElems * sizeof(GUID)); | ||
746 : | if (pPages->pElems == NULL) | ||
747 : | { | ||
748 : | return E_OUTOFMEMORY; | ||
749 : | } | ||
750 : | pPages->pElems[0] = CLSID_CABOUT; | ||
751 : | |||
752 : | return S_OK; | ||
753 : | } | ||
754 : | |||
755 : | |||
756 : | /* cleanup pages */ | ||
757 : | |||
758 : | STDMETHODIMP CXvidDecoder::FreePages(CAUUID * pPages) | ||
759 : | { | ||
760 : | DPRINTF("FreePages"); | ||
761 : | CoTaskMemFree(pPages->pElems); | ||
762 : | return S_OK; | ||
763 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |