main.c 7.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*              DirectShow Base Functions (QUARTZ.DLL)
 *
 * Copyright 2002 Lionel Ulmer
 *
 * This file contains the (internal) driver registration functions,
 * driver enumeration APIs and DirectDraw creation functions.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"
24 25
#include "wine/debug.h"

26
#include "quartz_private.h"
27 28 29

WINE_DEFAULT_DEBUG_CHANNEL(quartz);

30
static DWORD dll_ref = 0;
31

32 33 34 35 36
/* For the moment, do nothing here. */
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
{
    switch(fdwReason) {
        case DLL_PROCESS_ATTACH:
37
            DisableThreadLibraryCalls(hInstDLL);
38 39 40 41 42 43 44 45 46
	    break;
	case DLL_PROCESS_DETACH:
	    break;
    }
    return TRUE;
}

/******************************************************************************
 * DirectShow ClassFactory
47
 */
48 49 50
typedef struct {
    IClassFactory ITF_IClassFactory;

51
    LONG ref;
52 53 54 55 56 57 58 59 60 61 62
    HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
} IClassFactoryImpl;

struct object_creation_info
{
    const CLSID *clsid;
    HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
};

static const struct object_creation_info object_creation[] =
{
63 64
    { &CLSID_FilterGraph, FilterGraph_create },
    { &CLSID_FilterGraphNoThread, FilterGraphNoThread_create },
65 66
    { &CLSID_FilterMapper, FilterMapper2_create },
    { &CLSID_FilterMapper2, FilterMapper2_create },
67
    { &CLSID_AsyncReader, AsyncReader_create },
68
    { &CLSID_MemoryAllocator, StdMemAllocator_create },
69
    { &CLSID_AviSplitter, AVISplitter_create },
70 71 72
    { &CLSID_VideoRenderer, VideoRenderer_create },
    { &CLSID_DSoundRender, DSoundRender_create },
    { &CLSID_AVIDec, AVIDec_create },
73
    { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
Christian Costa's avatar
Christian Costa committed
74 75
    { &CLSID_ACMWrapper, &ACMWrapper_create },
    { &CLSID_WAVEParser, &WAVEParser_create }
76 77 78 79
};

static HRESULT WINAPI
DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
80
{
81
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
82 83 84 85 86 87 88 89 90 91 92 93 94

    if (IsEqualGUID(riid, &IID_IUnknown)
	|| IsEqualGUID(riid, &IID_IClassFactory))
    {
	IClassFactory_AddRef(iface);
	*ppobj = This;
	return S_OK;
    }

    WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
    return E_NOINTERFACE;
}

95 96
static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
{
97
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
98
    return InterlockedIncrement(&This->ref);
99 100
}

101 102
static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
{
103
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
104

105
    ULONG ref = InterlockedDecrement(&This->ref);
106 107 108 109 110 111 112 113 114

    if (ref == 0)
	HeapFree(GetProcessHeap(), 0, This);

    return ref;
}


static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
115 116
					  REFIID riid, LPVOID *ppobj)
{
117
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
118 119 120 121 122
    HRESULT hres;
    LPUNKNOWN punk;
    
    TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);

123
    *ppobj = NULL;
124
    hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
125 126 127
    if (SUCCEEDED(hres)) {
        hres = IUnknown_QueryInterface(punk, riid, ppobj);
        IUnknown_Release(punk);
128 129 130 131
    }
    return hres;
}

132 133
static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
{
134
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
135 136 137 138
    FIXME("(%p)->(%d),stub!\n",This,dolock);
    return S_OK;
}

139
static const IClassFactoryVtbl DSCF_Vtbl =
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
{
    DSCF_QueryInterface,
    DSCF_AddRef,
    DSCF_Release,
    DSCF_CreateInstance,
    DSCF_LockServer
};

/*******************************************************************************
 * DllGetClassObject [QUARTZ.@]
 * Retrieves class object from a DLL object
 *
 * NOTES
 *    Docs say returns STDAPI
 *
 * PARAMS
 *    rclsid [I] CLSID for the class object
 *    riid   [I] Reference to identifier of interface for class object
 *    ppv    [O] Address of variable to receive interface pointer for riid
 *
 * RETURNS
 *    Success: S_OK
 *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
 *             E_UNEXPECTED
 */
165
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
166
{
167
    unsigned int i;
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    IClassFactoryImpl *factory;
    
    TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
    
    if ( !IsEqualGUID( &IID_IClassFactory, riid )
	 && ! IsEqualGUID( &IID_IUnknown, riid) )
	return E_NOINTERFACE;

    for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
    {
	if (IsEqualGUID(object_creation[i].clsid, rclsid))
	    break;
    }

    if (i == sizeof(object_creation)/sizeof(object_creation[0]))
    {
	FIXME("%s: no class found.\n", debugstr_guid(rclsid));
	return CLASS_E_CLASSNOTAVAILABLE;
    }

    factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
    if (factory == NULL) return E_OUTOFMEMORY;

    factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
    factory->ref = 1;

    factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;

    *ppv = &(factory->ITF_IClassFactory);
    return S_OK;
198 199 200
}

/***********************************************************************
201
 *              DllCanUnloadNow (QUARTZ.@)
202
 */
203
HRESULT WINAPI DllCanUnloadNow()
204 205 206
{
    return dll_ref != 0 ? S_FALSE : S_OK;
}
207 208


209 210 211
#define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
    { { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } } , #name },

212 213
static struct {
	const GUID	riid;
214
	const char 	*name;
215 216
} InterfaceDesc[] =
{
217 218
#include "uuids.h"
    { { 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0} }, NULL }
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
};

/***********************************************************************
 *              qzdebugstr_guid (internal)
 *
 * Gives a text version of DirectShow GUIDs
 */
const char * qzdebugstr_guid( const GUID * id )
{
    int i;
    char * name = NULL;

    for (i=0;InterfaceDesc[i].name && !name;i++) {
        if (IsEqualGUID(&InterfaceDesc[i].riid, id)) return InterfaceDesc[i].name;
    }
    return debugstr_guid(id);
}

/***********************************************************************
 *              qzdebugstr_State (internal)
 *
 * Gives a text version of the FILTER_STATE enumeration
 */
const char * qzdebugstr_State(FILTER_STATE state)
{
    switch (state)
    {
    case State_Stopped:
        return "State_Stopped";
    case State_Running:
        return "State_Running";
    case State_Paused:
        return "State_Paused";
    default:
        return "State_Unknown";
    }
}
256

257
LONG WINAPI AmpFactorToDB(LONG ampfactor)
258 259 260 261 262
{
    FIXME("(%ld) Stub!\n", ampfactor);
    return 0;
}

263
LONG WINAPI DBToAmpFactor(LONG db)
264 265 266 267 268 269 270
{
    FIXME("(%ld) Stub!\n", db);
    /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
    if (db < -1000)
	return 0;
    return 100;
}