Parent Directory
|
Revision Log
Revision 632 - (view) (download)
1 : | Isibaar | 6 | /* |
2 : | this requires the directx sdk | ||
3 : | place these paths at the top of the Tools|Options|Directories list | ||
4 : | |||
5 : | headers: | ||
6 : | C:\DXVCSDK\include | ||
7 : | C:\DXVCSDK\samples\Multimedia\DirectShow\BaseClasses | ||
8 : | |||
9 : | libraries (optional): | ||
10 : | C:\DXVCSDK\samples\Multimedia\DirectShow\BaseClasses\Release | ||
11 : | */ | ||
12 : | |||
13 : | #include <windows.h> | ||
14 : | |||
15 : | #include <streams.h> | ||
16 : | #include <initguid.h> | ||
17 : | #include <olectl.h> | ||
18 : | #if (1100 > _MSC_VER) | ||
19 : | #include <olectlid.h> | ||
20 : | #endif | ||
21 : | #include <dvdmedia.h> // VIDEOINFOHEADER2 | ||
22 : | |||
23 : | Isibaar | 380 | #include <xvid.h> // XviD API |
24 : | |||
25 : | Isibaar | 6 | #include "IXvidDecoder.h" |
26 : | #include "CXvidDecoder.h" | ||
27 : | #include "CAbout.h" | ||
28 : | |||
29 : | |||
30 : | |||
31 : | const AMOVIESETUP_MEDIATYPE sudInputPinTypes[] = | ||
32 : | { | ||
33 : | { &MEDIATYPE_Video, &CLSID_XVID }, | ||
34 : | { &MEDIATYPE_Video, &CLSID_XVID_UC }, | ||
35 : | { &MEDIATYPE_Video, &CLSID_DIVX }, | ||
36 : | { &MEDIATYPE_Video, &CLSID_DIVX_UC } | ||
37 : | }; | ||
38 : | |||
39 : | const AMOVIESETUP_MEDIATYPE sudOutputPinTypes[] = | ||
40 : | { | ||
41 : | { &MEDIATYPE_Video, &MEDIASUBTYPE_NULL } | ||
42 : | }; | ||
43 : | |||
44 : | |||
45 : | const AMOVIESETUP_PIN psudPins[] = | ||
46 : | { | ||
47 : | { | ||
48 : | L"Input", // String pin name | ||
49 : | FALSE, // Is it rendered | ||
50 : | FALSE, // Is it an output | ||
51 : | FALSE, // Allowed none | ||
52 : | FALSE, // Allowed many | ||
53 : | &CLSID_NULL, // Connects to filter | ||
54 : | L"Output", // Connects to pin | ||
55 : | sizeof(sudInputPinTypes) / sizeof(AMOVIESETUP_MEDIATYPE), // Number of types | ||
56 : | &sudInputPinTypes[0] // The pin details | ||
57 : | }, | ||
58 : | { | ||
59 : | L"Output", // String pin name | ||
60 : | FALSE, // Is it rendered | ||
61 : | TRUE, // Is it an output | ||
62 : | FALSE, // Allowed none | ||
63 : | FALSE, // Allowed many | ||
64 : | &CLSID_NULL, // Connects to filter | ||
65 : | L"Input", // Connects to pin | ||
66 : | sizeof(sudOutputPinTypes) / sizeof(AMOVIESETUP_MEDIATYPE), // Number of types | ||
67 : | sudOutputPinTypes // The pin details | ||
68 : | } | ||
69 : | }; | ||
70 : | |||
71 : | |||
72 : | const AMOVIESETUP_FILTER sudXvidDecoder = | ||
73 : | { | ||
74 : | &CLSID_XVID, // Filter CLSID | ||
75 : | XVID_NAME_L, // Filter name | ||
76 : | MERIT_PREFERRED, // Its merit | ||
77 : | sizeof(psudPins) / sizeof(AMOVIESETUP_PIN), // Number of pins | ||
78 : | psudPins // Pin details | ||
79 : | }; | ||
80 : | |||
81 : | |||
82 : | // List of class IDs and creator functions for the class factory. This | ||
83 : | // provides the link between the OLE entry point in the DLL and an object | ||
84 : | // being created. The class factory will call the static CreateInstance | ||
85 : | |||
86 : | CFactoryTemplate g_Templates[] = | ||
87 : | { | ||
88 : | { | ||
89 : | XVID_NAME_L, | ||
90 : | &CLSID_XVID, | ||
91 : | CXvidDecoder::CreateInstance, | ||
92 : | NULL, | ||
93 : | &sudXvidDecoder | ||
94 : | }, | ||
95 : | { | ||
96 : | XVID_NAME_L L"About", | ||
97 : | &CLSID_CABOUT, | ||
98 : | CAbout::CreateInstance | ||
99 : | } | ||
100 : | |||
101 : | }; | ||
102 : | |||
103 : | int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate); | ||
104 : | |||
105 : | |||
106 : | |||
107 : | |||
108 : | STDAPI DllRegisterServer() | ||
109 : | { | ||
110 : | return AMovieDllRegisterServer2( TRUE ); | ||
111 : | } | ||
112 : | |||
113 : | |||
114 : | STDAPI DllUnregisterServer() | ||
115 : | { | ||
116 : | return AMovieDllRegisterServer2( FALSE ); | ||
117 : | } | ||
118 : | |||
119 : | |||
120 : | /* create instance */ | ||
121 : | |||
122 : | CUnknown * WINAPI CXvidDecoder::CreateInstance(LPUNKNOWN punk, HRESULT *phr) | ||
123 : | { | ||
124 : | CXvidDecoder * pNewObject = new CXvidDecoder(punk, phr); | ||
125 : | if (pNewObject == NULL) | ||
126 : | { | ||
127 : | *phr = E_OUTOFMEMORY; | ||
128 : | } | ||
129 : | return pNewObject; | ||
130 : | } | ||
131 : | |||
132 : | |||
133 : | /* query interfaces */ | ||
134 : | |||
135 : | STDMETHODIMP CXvidDecoder::NonDelegatingQueryInterface(REFIID riid, void **ppv) | ||
136 : | { | ||
137 : | CheckPointer(ppv, E_POINTER); | ||
138 : | |||
139 : | if (riid == IID_IXvidDecoder) | ||
140 : | { | ||
141 : | return GetInterface((IXvidDecoder *) this, ppv); | ||
142 : | } | ||
143 : | |||
144 : | if (riid == IID_ISpecifyPropertyPages) | ||
145 : | { | ||
146 : | return GetInterface((ISpecifyPropertyPages *) this, ppv); | ||
147 : | } | ||
148 : | |||
149 : | return CVideoTransformFilter::NonDelegatingQueryInterface(riid, ppv); | ||
150 : | } | ||
151 : | |||
152 : | |||
153 : | |||
154 : | /* dummy decore() */ | ||
155 : | |||
156 : | static int dummy_xvid_decore(void * handle, int opt, void * param1, void * param2) | ||
157 : | { | ||
158 : | return XVID_ERR_FAIL; | ||
159 : | } | ||
160 : | |||
161 : | |||
162 : | |||
163 : | /* constructor */ | ||
164 : | |||
165 : | #define XVID_DLL_NAME "xvid.dll" | ||
166 : | #define XVID_INIT_NAME "xvid_init" | ||
167 : | #define XVID_DECORE_NAME "xvid_decore" | ||
168 : | |||
169 : | CXvidDecoder::CXvidDecoder(LPUNKNOWN punk, HRESULT *phr) : | ||
170 : | CVideoTransformFilter(NAME("CXvidDecoder"), punk, CLSID_XVID) | ||
171 : | { | ||
172 : | DEBUG("Constructor"); | ||
173 : | |||
174 : | ASSERT(phr); | ||
175 : | |||
176 : | m_xvid_decore = dummy_xvid_decore; | ||
177 : | |||
178 : | m_hdll = LoadLibrary(XVID_DLL_NAME); | ||
179 : | if (m_hdll == NULL) { | ||
180 : | DEBUG("dll load failed"); | ||
181 : | MessageBox(0, XVID_DLL_NAME " not found","Error", 0); | ||
182 : | return; | ||
183 : | } | ||
184 : | |||
185 : | m_xvid_init = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, XVID_INIT_NAME); | ||
186 : | if (m_xvid_init == NULL) { | ||
187 : | MessageBox(0, XVID_INIT_NAME "() not found", "Error", 0); | ||
188 : | return; | ||
189 : | } | ||
190 : | |||
191 : | m_xvid_decore = (int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, XVID_DECORE_NAME); | ||
192 : | if (m_xvid_decore == NULL) { | ||
193 : | MessageBox(0, XVID_DECORE_NAME "() not found", "Error", 0); | ||
194 : | return; | ||
195 : | } | ||
196 : | |||
197 : | XVID_INIT_PARAM init; | ||
198 : | |||
199 : | init.cpu_flags = 0; | ||
200 : | if (m_xvid_init(0, 0, &init, 0) != XVID_ERR_OK) | ||
201 : | { | ||
202 : | MessageBox(0, XVID_INIT_NAME "() failed", "Error", 0); | ||
203 : | return; | ||
204 : | } | ||
205 : | |||
206 : | if (init.api_version < API_VERSION) | ||
207 : | { | ||
208 : | MessageBox(0, XVID_DLL_NAME " implements an older api version; update your " XVID_DLL_NAME, "Warning", 0); | ||
209 : | } | ||
210 : | else if (init.api_version > API_VERSION) | ||
211 : | { | ||
212 : | MessageBox(0, XVID_DLL_NAME " implements a newer api version; update your directshow filter", "Error", 0); | ||
213 : | return; | ||
214 : | } | ||
215 : | |||
216 : | m_param.handle = NULL; | ||
217 : | } | ||
218 : | |||
219 : | |||
220 : | |||
221 : | /* destructor */ | ||
222 : | |||
223 : | CXvidDecoder::~CXvidDecoder() | ||
224 : | { | ||
225 : | DEBUG("Destructor"); | ||
226 : | |||
227 : | if (m_param.handle != NULL) | ||
228 : | { | ||
229 : | m_xvid_decore(m_param.handle, XVID_DEC_DESTROY, 0, 0); | ||
230 : | m_param.handle = NULL; | ||
231 : | } | ||
232 : | |||
233 : | if (m_hdll != NULL) | ||
234 : | { | ||
235 : | FreeLibrary(m_hdll); | ||
236 : | m_hdll = NULL; | ||
237 : | } | ||
238 : | } | ||
239 : | |||
240 : | |||
241 : | |||
242 : | /* check input type */ | ||
243 : | |||
244 : | HRESULT CXvidDecoder::CheckInputType(const CMediaType * mtIn) | ||
245 : | { | ||
246 : | DEBUG("CheckInputType"); | ||
247 : | BITMAPINFOHEADER * hdr; | ||
248 : | |||
249 : | if (*mtIn->Type() != MEDIATYPE_Video) | ||
250 : | { | ||
251 : | return VFW_E_TYPE_NOT_ACCEPTED; | ||
252 : | } | ||
253 : | |||
254 : | if (*mtIn->FormatType() == FORMAT_VideoInfo) | ||
255 : | { | ||
256 : | VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtIn->Format(); | ||
257 : | hdr = &vih->bmiHeader; | ||
258 : | } | ||
259 : | else if (*mtIn->FormatType() == FORMAT_VideoInfo2) | ||
260 : | { | ||
261 : | VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 *) mtIn->Format(); | ||
262 : | hdr = &vih2->bmiHeader; | ||
263 : | } | ||
264 : | else | ||
265 : | { | ||
266 : | return VFW_E_TYPE_NOT_ACCEPTED; | ||
267 : | } | ||
268 : | |||
269 : | if (hdr->biHeight < 0) | ||
270 : | { | ||
271 : | DEBUG("colorspace: inverted input format not supported"); | ||
272 : | } | ||
273 : | |||
274 : | m_param.width = hdr->biWidth; | ||
275 : | m_param.height = hdr->biHeight; | ||
276 : | |||
277 : | switch(hdr->biCompression) | ||
278 : | { | ||
279 : | case FOURCC_XVID : | ||
280 : | // case FOURCC_DIVX : | ||
281 : | break; | ||
282 : | |||
283 : | default : | ||
284 : | return VFW_E_TYPE_NOT_ACCEPTED; | ||
285 : | } | ||
286 : | |||
287 : | return S_OK; | ||
288 : | } | ||
289 : | |||
290 : | |||
291 : | /* get list of supported output colorspaces */ | ||
292 : | |||
293 : | suxen_drol | 613 | #define ENABLE_IYUV |
294 : | #define ENABLE_YV12 | ||
295 : | #define ENABLE_YUY2 | ||
296 : | #define ENABLE_UYVY | ||
297 : | #define ENABLE_YVYU | ||
298 : | #define ENABLE_RGB32 | ||
299 : | #define ENABLE_RGB24 | ||
300 : | #define ENABLE_RGB565 | ||
301 : | #define ENABLE_RGB555 | ||
302 : | |||
303 : | Isibaar | 6 | HRESULT CXvidDecoder::GetMediaType(int iPosition, CMediaType *mtOut) |
304 : | { | ||
305 : | DEBUG("GetMediaType"); | ||
306 : | |||
307 : | if (m_pInput->IsConnected() == FALSE) | ||
308 : | { | ||
309 : | return E_UNEXPECTED; | ||
310 : | } | ||
311 : | |||
312 : | VIDEOINFOHEADER * vih = (VIDEOINFOHEADER *) mtOut->ReallocFormatBuffer(sizeof(VIDEOINFOHEADER)); | ||
313 : | if (vih == NULL) | ||
314 : | { | ||
315 : | return E_OUTOFMEMORY; | ||
316 : | } | ||
317 : | |||
318 : | ZeroMemory(vih, sizeof (VIDEOINFOHEADER)); | ||
319 : | vih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | ||
320 : | vih->bmiHeader.biWidth = m_param.width; | ||
321 : | vih->bmiHeader.biHeight = m_param.height; | ||
322 : | vih->bmiHeader.biPlanes = 1; | ||
323 : | |||
324 : | if (iPosition < 0) | ||
325 : | { | ||
326 : | return E_INVALIDARG; | ||
327 : | } | ||
328 : | |||
329 : | switch(iPosition) | ||
330 : | { | ||
331 : | suxen_drol | 613 | case 0 : |
332 : | #ifdef ENABLE_IYUV | ||
333 : | vih->bmiHeader.biCompression = MEDIASUBTYPE_IYUV.Data1; | ||
334 : | vih->bmiHeader.biBitCount = 12; | ||
335 : | mtOut->SetSubtype(&MEDIASUBTYPE_IYUV); | ||
336 : | break; | ||
337 : | #endif | ||
338 : | |||
339 : | case 1: | ||
340 : | #ifdef ENABLE_YV12 | ||
341 : | Isibaar | 6 | vih->bmiHeader.biCompression = MEDIASUBTYPE_YV12.Data1; |
342 : | vih->bmiHeader.biBitCount = 12; | ||
343 : | mtOut->SetSubtype(&MEDIASUBTYPE_YV12); | ||
344 : | break; | ||
345 : | suxen_drol | 613 | #endif |
346 : | Isibaar | 6 | |
347 : | suxen_drol | 613 | case 2: |
348 : | #ifdef ENABLE_YUY2 | ||
349 : | Isibaar | 6 | vih->bmiHeader.biCompression = MEDIASUBTYPE_YUY2.Data1; |
350 : | vih->bmiHeader.biBitCount = 16; | ||
351 : | mtOut->SetSubtype(&MEDIASUBTYPE_YUY2); | ||
352 : | break; | ||
353 : | suxen_drol | 613 | #endif |
354 : | Isibaar | 6 | |
355 : | suxen_drol | 613 | case 3: |
356 : | #ifdef ENABLE_YVYU | ||
357 : | Isibaar | 6 | vih->bmiHeader.biCompression = MEDIASUBTYPE_YVYU.Data1; |
358 : | vih->bmiHeader.biBitCount = 16; | ||
359 : | mtOut->SetSubtype(&MEDIASUBTYPE_YVYU); | ||
360 : | break; | ||
361 : | suxen_drol | 613 | #endif |
362 : | Isibaar | 6 | |
363 : | suxen_drol | 613 | case 4: |
364 : | #ifdef ENABLE_UYVY | ||
365 : | Isibaar | 6 | vih->bmiHeader.biCompression = MEDIASUBTYPE_UYVY.Data1; |
366 : | vih->bmiHeader.biBitCount = 16; | ||
367 : | mtOut->SetSubtype(&MEDIASUBTYPE_UYVY); | ||
368 : | break; | ||
369 : | suxen_drol | 613 | #endif |
370 : | Isibaar | 6 | |
371 : | suxen_drol | 613 | case 5: |
372 : | #ifdef ENABLE_RGB32 | ||
373 : | Isibaar | 6 | vih->bmiHeader.biCompression = BI_RGB; |
374 : | vih->bmiHeader.biBitCount = 32; | ||
375 : | mtOut->SetSubtype(&MEDIASUBTYPE_RGB32); | ||
376 : | break; | ||
377 : | suxen_drol | 613 | #endif |
378 : | Isibaar | 6 | |
379 : | suxen_drol | 613 | case 6: |
380 : | #ifdef ENABLE_RGB24 | ||
381 : | Isibaar | 6 | vih->bmiHeader.biCompression = BI_RGB; |
382 : | vih->bmiHeader.biBitCount = 24; | ||
383 : | mtOut->SetSubtype(&MEDIASUBTYPE_RGB24); | ||
384 : | break; | ||
385 : | suxen_drol | 613 | #endif |
386 : | Isibaar | 6 | |
387 : | suxen_drol | 613 | case 7: |
388 : | suxen_drol | 632 | #ifdef ENABLE_RGB565 |
389 : | Isibaar | 6 | vih->bmiHeader.biCompression = BI_RGB; |
390 : | vih->bmiHeader.biBitCount = 16; | ||
391 : | suxen_drol | 632 | mtOut->SetSubtype(&MEDIASUBTYPE_RGB565); |
392 : | Isibaar | 6 | break; |
393 : | suxen_drol | 613 | #endif |
394 : | Isibaar | 6 | |
395 : | suxen_drol | 613 | case 8: |
396 : | suxen_drol | 632 | #ifdef ENABLE_RGB555 |
397 : | Isibaar | 6 | vih->bmiHeader.biCompression = BI_RGB; |
398 : | vih->bmiHeader.biBitCount = 16; | ||
399 : | suxen_drol | 632 | mtOut->SetSubtype(&MEDIASUBTYPE_RGB555); |
400 : | Isibaar | 6 | break; |
401 : | suxen_drol | 613 | #endif |
402 : | |||
403 : | Isibaar | 6 | default : |
404 : | return VFW_S_NO_MORE_ITEMS; | ||
405 : | } | ||
406 : | |||
407 : | vih->bmiHeader.biSizeImage = GetBitmapSize(&vih->bmiHeader); | ||
408 : | |||
409 : | mtOut->SetType(&MEDIATYPE_Video); | ||
410 : | mtOut->SetFormatType(&FORMAT_VideoInfo); | ||
411 : | mtOut->SetTemporalCompression(FALSE); | ||
412 : | mtOut->SetSampleSize(vih->bmiHeader.biSizeImage); | ||
413 : | |||
414 : | return S_OK; | ||
415 : | } | ||
416 : | |||
417 : | |||
418 : | /* (internal function) change colorspace */ | ||
419 : | |||
420 : | HRESULT CXvidDecoder::ChangeColorspace(GUID subtype, GUID formattype, void * format) | ||
421 : | { | ||
422 : | suxen_drol | 632 | int rgb_flip; |
423 : | |||
424 : | if (formattype == FORMAT_VideoInfo) | ||
425 : | { | ||
426 : | VIDEOINFOHEADER * vih = (VIDEOINFOHEADER * )format; | ||
427 : | //m_frame.stride = vih->bmiHeader.biWidth; | ||
428 : | // dev-api-3: | ||
429 : | m_frame.stride = (((vih->bmiHeader.biWidth * vih->bmiHeader.biBitCount) + 31) & ~31) >> 3; | ||
430 : | rgb_flip = (vih->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); | ||
431 : | } | ||
432 : | else if (formattype == FORMAT_VideoInfo2) | ||
433 : | { | ||
434 : | VIDEOINFOHEADER2 * vih2 = (VIDEOINFOHEADER2 * )format; | ||
435 : | //m_frame.stride = vih2->bmiHeader.biWidth; | ||
436 : | // dev-api-3: | ||
437 : | m_frame.stride = (((vih2->bmiHeader.biWidth * vih2->bmiHeader.biBitCount) + 31) & ~31) >> 3; | ||
438 : | rgb_flip = (vih2->bmiHeader.biHeight < 0 ? 0 : XVID_CSP_VFLIP); | ||
439 : | } | ||
440 : | else | ||
441 : | { | ||
442 : | return S_FALSE; | ||
443 : | } | ||
444 : | |||
445 : | suxen_drol | 613 | if (subtype == MEDIASUBTYPE_IYUV) |
446 : | Isibaar | 6 | { |
447 : | suxen_drol | 613 | DEBUG("IYUV"); |
448 : | m_frame.colorspace = XVID_CSP_I420; | ||
449 : | } | ||
450 : | else if (subtype == MEDIASUBTYPE_YV12) | ||
451 : | { | ||
452 : | Isibaar | 6 | DEBUG("YV12"); |
453 : | m_frame.colorspace = XVID_CSP_YV12; | ||
454 : | } | ||
455 : | else if (subtype == MEDIASUBTYPE_YUY2) | ||
456 : | { | ||
457 : | DEBUG("YUY2"); | ||
458 : | m_frame.colorspace = XVID_CSP_YUY2; | ||
459 : | } | ||
460 : | else if (subtype == MEDIASUBTYPE_YVYU) | ||
461 : | { | ||
462 : | DEBUG("YVYU"); | ||
463 : | m_frame.colorspace = XVID_CSP_YVYU; | ||
464 : | } | ||
465 : | else if (subtype == MEDIASUBTYPE_UYVY) | ||
466 : | { | ||
467 : | DEBUG("UYVY"); | ||
468 : | m_frame.colorspace = XVID_CSP_UYVY; | ||
469 : | } | ||
470 : | else if (subtype == MEDIASUBTYPE_RGB32) | ||
471 : | { | ||
472 : | DEBUG("RGB32"); | ||
473 : | suxen_drol | 632 | m_frame.colorspace = rgb_flip | XVID_CSP_RGB32; |
474 : | Isibaar | 6 | } |
475 : | else if (subtype == MEDIASUBTYPE_RGB24) | ||
476 : | { | ||
477 : | DEBUG("RGB24"); | ||
478 : | suxen_drol | 632 | m_frame.colorspace = rgb_flip | XVID_CSP_RGB24; |
479 : | Isibaar | 6 | } |
480 : | else if (subtype == MEDIASUBTYPE_RGB555) | ||
481 : | { | ||
482 : | DEBUG("RGB555"); | ||
483 : | suxen_drol | 632 | m_frame.colorspace = rgb_flip | XVID_CSP_RGB555; |
484 : | Isibaar | 6 | } |
485 : | else if (subtype == MEDIASUBTYPE_RGB565) | ||
486 : | { | ||
487 : | DEBUG("RGB565"); | ||
488 : | suxen_drol | 632 | m_frame.colorspace = rgb_flip | XVID_CSP_RGB565; |
489 : | Isibaar | 6 | } |
490 : | else if (subtype == GUID_NULL) | ||
491 : | { | ||
492 : | m_frame.colorspace = XVID_CSP_NULL; | ||
493 : | } | ||
494 : | else | ||
495 : | { | ||
496 : | return S_FALSE; | ||
497 : | } | ||
498 : | |||
499 : | return S_OK; | ||
500 : | |||
501 : | } | ||
502 : | |||
503 : | |||
504 : | /* set output colorspace */ | ||
505 : | |||
506 : | HRESULT CXvidDecoder::SetMediaType(PIN_DIRECTION direction, const CMediaType *pmt) | ||
507 : | { | ||
508 : | DEBUG("SetMediaType"); | ||
509 : | |||
510 : | if (direction == PINDIR_OUTPUT) | ||
511 : | { | ||
512 : | return ChangeColorspace(*pmt->Subtype(), *pmt->FormatType(), pmt->Format()); | ||
513 : | } | ||
514 : | |||
515 : | return S_OK; | ||
516 : | } | ||
517 : | |||
518 : | |||
519 : | /* check input<->output compatiblity */ | ||
520 : | |||
521 : | HRESULT CXvidDecoder::CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut) | ||
522 : | { | ||
523 : | DEBUG("CheckTransform"); | ||
524 : | return S_OK; | ||
525 : | } | ||
526 : | |||
527 : | |||
528 : | /* alloc output buffer */ | ||
529 : | |||
530 : | HRESULT CXvidDecoder::DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest) | ||
531 : | { | ||
532 : | DEBUG("DecideBufferSize"); | ||
533 : | HRESULT result; | ||
534 : | ALLOCATOR_PROPERTIES ppropActual; | ||
535 : | |||
536 : | if (m_pInput->IsConnected() == FALSE) | ||
537 : | { | ||
538 : | return E_UNEXPECTED; | ||
539 : | } | ||
540 : | |||
541 : | ppropInputRequest->cBuffers = 1; | ||
542 : | ppropInputRequest->cbBuffer = m_param.width * m_param.height * 4; | ||
543 : | // cbAlign causes problems with the resize filter */ | ||
544 : | // ppropInputRequest->cbAlign = 16; | ||
545 : | ppropInputRequest->cbPrefix = 0; | ||
546 : | |||
547 : | result = pAlloc->SetProperties(ppropInputRequest, &ppropActual); | ||
548 : | if (result != S_OK) | ||
549 : | { | ||
550 : | return result; | ||
551 : | } | ||
552 : | |||
553 : | if (ppropActual.cbBuffer < ppropInputRequest->cbBuffer) | ||
554 : | { | ||
555 : | return E_FAIL; | ||
556 : | } | ||
557 : | |||
558 : | return S_OK; | ||
559 : | } | ||
560 : | |||
561 : | |||
562 : | |||
563 : | /* decode frame */ | ||
564 : | |||
565 : | HRESULT CXvidDecoder::Transform(IMediaSample *pIn, IMediaSample *pOut) | ||
566 : | { | ||
567 : | DEBUG("Transform"); | ||
568 : | |||
569 : | if (m_param.handle == NULL) | ||
570 : | { | ||
571 : | if (m_xvid_decore(0, XVID_DEC_CREATE, &m_param, 0) != XVID_ERR_OK) | ||
572 : | { | ||
573 : | return S_FALSE; | ||
574 : | } | ||
575 : | } | ||
576 : | |||
577 : | AM_MEDIA_TYPE * mtOut; | ||
578 : | pOut->GetMediaType(&mtOut); | ||
579 : | if (mtOut != NULL) | ||
580 : | { | ||
581 : | HRESULT result; | ||
582 : | |||
583 : | result = ChangeColorspace(mtOut->subtype, mtOut->formattype, mtOut->pbFormat); | ||
584 : | DeleteMediaType(mtOut); | ||
585 : | |||
586 : | if (result != S_OK) | ||
587 : | { | ||
588 : | return result; | ||
589 : | } | ||
590 : | } | ||
591 : | |||
592 : | if (pIn->GetPointer((BYTE**)&m_frame.bitstream) != S_OK) | ||
593 : | { | ||
594 : | return S_FALSE; | ||
595 : | } | ||
596 : | |||
597 : | if (pOut->GetPointer((BYTE**)&m_frame.image) != S_OK) | ||
598 : | { | ||
599 : | return S_FALSE; | ||
600 : | } | ||
601 : | |||
602 : | m_frame.length = pIn->GetSize(); | ||
603 : | |||
604 : | if (pIn->IsPreroll() != S_OK) | ||
605 : | { | ||
606 : | if (m_xvid_decore(m_param.handle, XVID_DEC_DECODE, &m_frame, 0) != XVID_ERR_OK) | ||
607 : | { | ||
608 : | return S_FALSE; | ||
609 : | } | ||
610 : | } | ||
611 : | else | ||
612 : | { | ||
613 : | int tmp = m_frame.colorspace; | ||
614 : | m_frame.colorspace = XVID_CSP_NULL; | ||
615 : | |||
616 : | if (m_xvid_decore(m_param.handle, XVID_DEC_DECODE, &m_frame, 0) != XVID_ERR_OK) | ||
617 : | { | ||
618 : | return S_FALSE; | ||
619 : | } | ||
620 : | |||
621 : | m_frame.colorspace = tmp; | ||
622 : | |||
623 : | } | ||
624 : | |||
625 : | return S_OK; | ||
626 : | } | ||
627 : | |||
628 : | |||
629 : | /* get property page list */ | ||
630 : | |||
631 : | STDMETHODIMP CXvidDecoder::GetPages(CAUUID * pPages) | ||
632 : | { | ||
633 : | DEBUG("GetPages"); | ||
634 : | |||
635 : | pPages->cElems = 1; | ||
636 : | pPages->pElems = (GUID *)CoTaskMemAlloc(pPages->cElems * sizeof(GUID)); | ||
637 : | if (pPages->pElems == NULL) | ||
638 : | { | ||
639 : | return E_OUTOFMEMORY; | ||
640 : | } | ||
641 : | pPages->pElems[0] = CLSID_CABOUT; | ||
642 : | |||
643 : | return S_OK; | ||
644 : | } | ||
645 : | |||
646 : | |||
647 : | /* cleanup pages */ | ||
648 : | |||
649 : | STDMETHODIMP CXvidDecoder::FreePages(CAUUID * pPages) | ||
650 : | { | ||
651 : | DEBUG("FreePages"); | ||
652 : | CoTaskMemFree(pPages->pElems); | ||
653 : | return S_OK; | ||
654 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |