4 * hidenori@a2.ctktv.ne.jp
22 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(quartz);
27 #include "quartz_private.h"
41 typedef struct QUARTZ_CLASSENTRY
44 QUARTZ_pCreateIUnknown pCreateIUnk;
49 IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
50 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
51 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
52 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
53 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
55 static ICOM_VTABLE(IClassFactory) iclassfact =
57 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
58 IClassFactory_fnQueryInterface,
59 IClassFactory_fnAddRef,
60 IClassFactory_fnRelease,
61 IClassFactory_fnCreateInstance,
62 IClassFactory_fnLockServer
68 ICOM_VFIELD(IClassFactory);
70 /* IClassFactory fields */
71 const QUARTZ_CLASSENTRY* pEntry;
74 static const QUARTZ_CLASSENTRY QUARTZ_ClassList[] =
76 { &CLSID_FilterGraph, &QUARTZ_CreateFilterGraph },
77 { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
78 { &CLSID_MemoryAllocator, &QUARTZ_CreateMemoryAllocator },
79 { &CLSID_SystemDeviceEnum, &QUARTZ_CreateSystemDeviceEnum },
80 { &CLSID_FilterMapper, &QUARTZ_CreateFilterMapper },
81 { &CLSID_FilterMapper2, &QUARTZ_CreateFilterMapper2 },
82 { &CLSID_SeekingPassThru, &QUARTZ_CreateSeekingPassThru },
83 { &CLSID_AudioRender, &QUARTZ_CreateAudioRenderer },
84 { &CLSID_VideoRenderer, &QUARTZ_CreateVideoRenderer },
85 { &CLSID_quartzWaveParser, &QUARTZ_CreateWaveParser },
86 { &CLSID_AviSplitter, &QUARTZ_CreateAVISplitter },
87 { &CLSID_AsyncReader, &QUARTZ_CreateAsyncReader },
88 { &CLSID_URLReader, &QUARTZ_CreateURLReader },
89 { &CLSID_AVIDec, &QUARTZ_CreateAVIDec },
90 { &CLSID_Colour, &QUARTZ_CreateColour },
94 /* per-process variables */
95 static CRITICAL_SECTION csHeap;
96 static DWORD dwClassObjRef;
97 static HANDLE hDLLHeap;
99 void* QUARTZ_AllocObj( DWORD dwSize )
103 EnterCriticalSection( &csHeap );
105 pv = HeapAlloc( hDLLHeap, 0, dwSize );
108 LeaveCriticalSection( &csHeap );
113 void QUARTZ_FreeObj( void* pobj )
115 EnterCriticalSection( &csHeap );
116 HeapFree( hDLLHeap, 0, pobj );
118 LeaveCriticalSection( &csHeap );
121 void* QUARTZ_AllocMem( DWORD dwSize )
123 return HeapAlloc( hDLLHeap, 0, dwSize );
126 void QUARTZ_FreeMem( void* pMem )
128 HeapFree( hDLLHeap, 0, pMem );
131 void* QUARTZ_ReallocMem( void* pMem, DWORD dwSize )
134 return QUARTZ_AllocMem( dwSize );
136 return HeapReAlloc( hDLLHeap, 0, pMem, dwSize );
140 LPWSTR QUARTZ_strncpyAtoW( LPWSTR lpwstr, LPCSTR lpstr, INT wbuflen )
144 len = MultiByteToWideChar( CP_ACP, 0, lpstr, -1, lpwstr, wbuflen );
151 /************************************************************************/
153 static HRESULT WINAPI
154 IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
156 ICOM_THIS(IClassFactoryImpl,iface);
158 TRACE("(%p)->(%p,%p)\n",This,riid,ppobj);
159 if ( ( IsEqualGUID( &IID_IUnknown, riid ) ) ||
160 ( IsEqualGUID( &IID_IClassFactory, riid ) ) )
163 IClassFactory_AddRef(iface);
167 return E_NOINTERFACE;
170 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
172 ICOM_THIS(IClassFactoryImpl,iface);
174 TRACE("(%p)->()\n",This);
176 return InterlockedExchangeAdd(&(This->ref),1) + 1;
179 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
181 ICOM_THIS(IClassFactoryImpl,iface);
184 TRACE("(%p)->()\n",This);
185 ref = InterlockedExchangeAdd(&(This->ref),-1) - 1;
189 QUARTZ_FreeObj(This);
193 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj)
195 ICOM_THIS(IClassFactoryImpl,iface);
199 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
203 if ( pOuter != NULL && !IsEqualGUID( riid, &IID_IUnknown ) )
204 return CLASS_E_NOAGGREGATION;
208 hr = (*This->pEntry->pCreateIUnk)(pOuter,(void**)&punk);
212 hr = IUnknown_QueryInterface(punk,riid,ppobj);
213 IUnknown_Release(punk);
218 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
220 ICOM_THIS(IClassFactoryImpl,iface);
223 TRACE("(%p)->(%d)\n",This,dolock);
225 hr = IClassFactory_AddRef(iface);
227 hr = IClassFactory_Release(iface);
234 static HRESULT IClassFactory_Alloc( const CLSID* pclsid, void** ppobj )
236 const QUARTZ_CLASSENTRY* pEntry;
237 IClassFactoryImpl* pImpl;
239 TRACE( "(%s,%p)\n", debugstr_guid(pclsid), ppobj );
241 pEntry = QUARTZ_ClassList;
242 while ( pEntry->pclsid != NULL )
244 if ( IsEqualGUID( pclsid, pEntry->pclsid ) )
249 return CLASS_E_CLASSNOTAVAILABLE;
251 pImpl = (IClassFactoryImpl*)QUARTZ_AllocObj( sizeof(IClassFactoryImpl) );
253 return E_OUTOFMEMORY;
255 TRACE( "allocated successfully.\n" );
257 ICOM_VTBL(pImpl) = &iclassfact;
259 pImpl->pEntry = pEntry;
261 *ppobj = (void*)pImpl;
266 /***********************************************************************
267 * QUARTZ_InitProcess (internal)
269 static BOOL QUARTZ_InitProcess( void )
274 hDLLHeap = (HANDLE)NULL;
275 InitializeCriticalSection( &csHeap );
277 hDLLHeap = HeapCreate( 0, 0x10000, 0 );
278 if ( hDLLHeap == (HANDLE)NULL )
284 /***********************************************************************
285 * QUARTZ_UninitProcess (internal)
287 static void QUARTZ_UninitProcess( void )
291 if ( dwClassObjRef != 0 )
292 ERR( "you must release some objects allocated from quartz.\n" );
293 if ( hDLLHeap != (HANDLE)NULL )
295 HeapDestroy( hDLLHeap );
296 hDLLHeap = (HANDLE)NULL;
298 DeleteCriticalSection( &csHeap );
301 /***********************************************************************
304 BOOL WINAPI QUARTZ_DllMain(
309 TRACE("(%08x,%08lx,%p)\n",hInstDLL,fdwReason,lpvReserved);
313 case DLL_PROCESS_ATTACH:
314 if ( !QUARTZ_InitProcess() )
317 case DLL_PROCESS_DETACH:
318 QUARTZ_UninitProcess();
320 case DLL_THREAD_ATTACH:
322 case DLL_THREAD_DETACH:
330 /***********************************************************************
331 * DllCanUnloadNow (QUARTZ.@)
337 HRESULT WINAPI QUARTZ_DllCanUnloadNow(void)
341 EnterCriticalSection( &csHeap );
342 hr = ( dwClassObjRef == 0 ) ? S_OK : S_FALSE;
343 LeaveCriticalSection( &csHeap );
348 /***********************************************************************
349 * DllGetClassObject (QUARTZ.@)
351 HRESULT WINAPI QUARTZ_DllGetClassObject(
352 const CLSID* pclsid,const IID* piid,void** ppv)
355 if ( IsEqualCLSID( &IID_IUnknown, piid ) ||
356 IsEqualCLSID( &IID_IClassFactory, piid ) )
358 return IClassFactory_Alloc( pclsid, ppv );
361 return CLASS_E_CLASSNOTAVAILABLE;
364 /***********************************************************************
365 * DllRegisterServer (QUARTZ.@)
368 HRESULT WINAPI QUARTZ_DllRegisterServer( void )
370 FIXME( "(): stub\n" );
374 /***********************************************************************
375 * DllUnregisterServer (QUARTZ.@)
378 HRESULT WINAPI QUARTZ_DllUnregisterServer( void )
380 FIXME( "(): stub\n" );
384 /**************************************************************************/
385 /**************************************************************************/
387 /* FIXME - all string should be defined in the resource of quartz. */
389 static LPCSTR hresult_to_string( HRESULT hr )
393 #define ENTRY(x) case x: return (const char*)#x
394 /* some known codes */
400 ENTRY(E_NOINTERFACE);
401 ENTRY(E_OUTOFMEMORY);
402 ENTRY(CLASS_E_CLASSNOTAVAILABLE);
403 ENTRY(CLASS_E_NOAGGREGATION);
406 ENTRY(VFW_S_NO_MORE_ITEMS);
407 ENTRY(VFW_E_BAD_KEY);
408 ENTRY(VFW_E_INVALIDMEDIATYPE);
409 ENTRY(VFW_E_INVALIDSUBTYPE);
410 ENTRY(VFW_E_NEED_OWNER);
411 ENTRY(VFW_E_ENUM_OUT_OF_SYNC);
412 ENTRY(VFW_E_ALREADY_CONNECTED);
413 ENTRY(VFW_E_FILTER_ACTIVE);
414 ENTRY(VFW_E_NO_TYPES);
415 ENTRY(VFW_E_NO_ACCEPTABLE_TYPES);
416 ENTRY(VFW_E_INVALID_DIRECTION);
417 ENTRY(VFW_E_NOT_CONNECTED);
418 ENTRY(VFW_E_NO_ALLOCATOR);
419 ENTRY(VFW_E_RUNTIME_ERROR);
420 ENTRY(VFW_E_BUFFER_NOTSET);
421 ENTRY(VFW_E_BUFFER_OVERFLOW);
422 ENTRY(VFW_E_BADALIGN);
423 ENTRY(VFW_E_ALREADY_COMMITTED);
424 ENTRY(VFW_E_BUFFERS_OUTSTANDING);
425 ENTRY(VFW_E_NOT_COMMITTED);
426 ENTRY(VFW_E_SIZENOTSET);
427 ENTRY(VFW_E_NO_CLOCK);
428 ENTRY(VFW_E_NO_SINK);
429 ENTRY(VFW_E_NO_INTERFACE);
430 ENTRY(VFW_E_NOT_FOUND);
431 ENTRY(VFW_E_CANNOT_CONNECT);
432 ENTRY(VFW_E_CANNOT_RENDER);
433 ENTRY(VFW_E_CHANGING_FORMAT);
434 ENTRY(VFW_E_NO_COLOR_KEY_SET);
435 ENTRY(VFW_E_NOT_OVERLAY_CONNECTION);
436 ENTRY(VFW_E_NOT_SAMPLE_CONNECTION);
437 ENTRY(VFW_E_PALETTE_SET);
438 ENTRY(VFW_E_COLOR_KEY_SET);
439 ENTRY(VFW_E_NO_COLOR_KEY_FOUND);
440 ENTRY(VFW_E_NO_PALETTE_AVAILABLE);
441 ENTRY(VFW_E_NO_DISPLAY_PALETTE);
442 ENTRY(VFW_E_TOO_MANY_COLORS);
443 ENTRY(VFW_E_STATE_CHANGED);
444 ENTRY(VFW_E_NOT_STOPPED);
445 ENTRY(VFW_E_NOT_PAUSED);
446 ENTRY(VFW_E_NOT_RUNNING);
447 ENTRY(VFW_E_WRONG_STATE);
448 ENTRY(VFW_E_START_TIME_AFTER_END);
449 ENTRY(VFW_E_INVALID_RECT);
450 ENTRY(VFW_E_TYPE_NOT_ACCEPTED);
451 ENTRY(VFW_E_SAMPLE_REJECTED);
452 ENTRY(VFW_E_SAMPLE_REJECTED_EOS);
453 ENTRY(VFW_S_DUPLICATE_NAME);
454 ENTRY(VFW_E_DUPLICATE_NAME);
455 ENTRY(VFW_E_TIMEOUT);
456 ENTRY(VFW_E_INVALID_FILE_FORMAT);
457 ENTRY(VFW_E_ENUM_OUT_OF_RANGE);
458 ENTRY(VFW_E_CIRCULAR_GRAPH);
459 ENTRY(VFW_E_NOT_ALLOWED_TO_SAVE);
460 ENTRY(VFW_E_TIME_ALREADY_PASSED);
461 ENTRY(VFW_E_ALREADY_CANCELLED);
462 ENTRY(VFW_E_CORRUPT_GRAPH_FILE);
463 ENTRY(VFW_E_ADVISE_ALREADY_SET);
464 ENTRY(VFW_S_STATE_INTERMEDIATE);
465 ENTRY(VFW_E_NO_MODEX_AVAILABLE);
466 ENTRY(VFW_E_NO_ADVISE_SET);
467 ENTRY(VFW_E_NO_FULLSCREEN);
468 ENTRY(VFW_E_IN_FULLSCREEN_MODE);
469 ENTRY(VFW_E_UNKNOWN_FILE_TYPE);
470 ENTRY(VFW_E_CANNOT_LOAD_SOURCE_FILTER);
471 ENTRY(VFW_S_PARTIAL_RENDER);
472 ENTRY(VFW_E_FILE_TOO_SHORT);
473 ENTRY(VFW_E_INVALID_FILE_VERSION);
474 ENTRY(VFW_S_SOME_DATA_IGNORED);
475 ENTRY(VFW_S_CONNECTIONS_DEFERRED);
476 ENTRY(VFW_E_INVALID_CLSID);
477 ENTRY(VFW_E_INVALID_MEDIA_TYPE);
478 ENTRY(VFW_E_SAMPLE_TIME_NOT_SET);
479 ENTRY(VFW_S_RESOURCE_NOT_NEEDED);
480 ENTRY(VFW_E_MEDIA_TIME_NOT_SET);
481 ENTRY(VFW_E_NO_TIME_FORMAT_SET);
482 ENTRY(VFW_E_MONO_AUDIO_HW);
483 ENTRY(VFW_S_MEDIA_TYPE_IGNORED);
484 ENTRY(VFW_E_NO_DECOMPRESSOR);
485 ENTRY(VFW_E_NO_AUDIO_HARDWARE);
486 ENTRY(VFW_S_VIDEO_NOT_RENDERED);
487 ENTRY(VFW_S_AUDIO_NOT_RENDERED);
490 ENTRY(VFW_E_PROCESSOR_NOT_SUITABLE);
491 ENTRY(VFW_E_UNSUPPORTED_AUDIO);
492 ENTRY(VFW_E_UNSUPPORTED_VIDEO);
493 ENTRY(VFW_E_MPEG_NOT_CONSTRAINED);
494 ENTRY(VFW_E_NOT_IN_GRAPH);
495 ENTRY(VFW_S_ESTIMATED);
496 ENTRY(VFW_E_NO_TIME_FORMAT);
497 ENTRY(VFW_E_READ_ONLY);
498 ENTRY(VFW_S_RESERVED);
499 ENTRY(VFW_E_BUFFER_UNDERFLOW);
500 ENTRY(VFW_E_UNSUPPORTED_STREAM);
501 ENTRY(VFW_E_NO_TRANSPORT);
502 ENTRY(VFW_S_STREAM_OFF);
503 ENTRY(VFW_S_CANT_CUE);
504 ENTRY(VFW_E_BAD_VIDEOCD);
505 ENTRY(VFW_S_NO_STOP_TIME);
506 ENTRY(VFW_E_OUT_OF_VIDEO_MEMORY);
507 ENTRY(VFW_E_VP_NEGOTIATION_FAILED);
508 ENTRY(VFW_E_DDRAW_CAPS_NOT_SUITABLE);
509 ENTRY(VFW_E_NO_VP_HARDWARE);
510 ENTRY(VFW_E_NO_CAPTURE_HARDWARE);
511 ENTRY(VFW_E_DVD_OPERATION_INHIBITED);
512 ENTRY(VFW_E_DVD_INVALIDDOMAIN);
513 ENTRY(VFW_E_DVD_NO_BUTTON);
514 ENTRY(VFW_E_DVD_GRAPHNOTREADY);
515 ENTRY(VFW_E_DVD_RENDERFAIL);
516 ENTRY(VFW_E_DVD_DECNOTENOUGH);
517 ENTRY(VFW_E_DDRAW_VERSION_NOT_SUITABLE);
518 ENTRY(VFW_E_COPYPROT_FAILED);
519 ENTRY(VFW_S_NOPREVIEWPIN);
520 ENTRY(VFW_E_TIME_EXPIRED);
521 ENTRY(VFW_S_DVD_NON_ONE_SEQUENTIAL);
522 ENTRY(VFW_E_DVD_WRONG_SPEED);
523 ENTRY(VFW_E_DVD_MENU_DOES_NOT_EXIST);
524 ENTRY(VFW_E_DVD_CMD_CANCELLED);
525 ENTRY(VFW_E_DVD_STATE_WRONG_VERSION);
526 ENTRY(VFW_E_DVD_STATE_CORRUPT);
527 ENTRY(VFW_E_DVD_STATE_WRONG_DISC);
528 ENTRY(VFW_E_DVD_INCOMPATIBLE_REGION);
529 ENTRY(VFW_E_DVD_NO_ATTRIBUTES);
530 ENTRY(VFW_E_DVD_NO_GOUP_PGC);
531 ENTRY(VFW_E_DVD_LOW_PARENTAL_LEVEL);
532 ENTRY(VFW_E_DVD_NOT_IN_KARAOKE_MODE);
533 ENTRY(VFW_S_DVD_CHANNEL_CONTENTS_NOT_AVAILABLE);
534 ENTRY(VFW_S_DVD_NOT_ACCURATE);
535 ENTRY(VFW_E_FRAME_STEP_UNSUPPORTED);
536 ENTRY(VFW_E_DVD_STREAM_DISABLED);
537 ENTRY(VFW_E_DVD_TITLE_UNKNOWN);
538 ENTRY(VFW_E_DVD_INVALID_DISC);
539 ENTRY(VFW_E_DVD_NO_RESUME_INFORMATION);
540 ENTRY(VFW_E_PIN_ALREADY_BLOCKED_ON_THIS_THREAD);
541 ENTRY(VFW_E_PIN_ALREADY_BLOCKED);
542 ENTRY(VFW_E_CERTIFICATION_FAILURE);
549 /***********************************************************************
550 * AMGetErrorTextA (quartz.@)
552 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR pszbuf, DWORD dwBufLen)
557 lpszRes = hresult_to_string( hr );
558 if ( lpszRes == NULL )
560 len = (DWORD)(strlen(lpszRes)+1);
561 if ( len > dwBufLen )
564 memcpy( pszbuf, lpszRes, len );
568 /***********************************************************************
569 * AMGetErrorTextW (quartz.@)
571 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR pwszbuf, DWORD dwBufLen)
573 CHAR szBuf[MAX_ERROR_TEXT_LEN+1];
576 dwLen = AMGetErrorTextA(hr,szBuf,MAX_ERROR_TEXT_LEN);
581 QUARTZ_strncpyAtoW( pwszbuf, szBuf, dwBufLen );
583 return lstrlenW( pwszbuf );