main.c 10.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*              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
20
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 22 23
 */

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

26
#include "quartz_private.h"
27
#include "wine/unicode.h"
28 29 30

WINE_DEFAULT_DEBUG_CHANNEL(quartz);

31 32 33 34
extern HRESULT WINAPI QUARTZ_DllGetClassObject(REFCLSID, REFIID, LPVOID *) DECLSPEC_HIDDEN;
extern HRESULT WINAPI QUARTZ_DllCanUnloadNow(void) DECLSPEC_HIDDEN;
extern BOOL WINAPI QUARTZ_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;

35
static DWORD dll_ref = 0;
36

37 38 39
/* For the moment, do nothing here. */
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
{
40 41
    if (fdwReason == DLL_PROCESS_DETACH)
        video_unregister_windowclass();
42
    return QUARTZ_DllMain( hInstDLL, fdwReason, lpv );
43 44 45 46
}

/******************************************************************************
 * 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
    { &CLSID_SeekingPassThru, SeekingPassThru_create },
64 65
    { &CLSID_FilterGraph, FilterGraph_create },
    { &CLSID_FilterGraphNoThread, FilterGraphNoThread_create },
66
    { &CLSID_FilterMapper, FilterMapper_create },
67
    { &CLSID_FilterMapper2, FilterMapper2_create },
68
    { &CLSID_AsyncReader, AsyncReader_create },
69
    { &CLSID_MemoryAllocator, StdMemAllocator_create },
70
    { &CLSID_AviSplitter, AVISplitter_create },
71
    { &CLSID_MPEG1Splitter, MPEGSplitter_create },
72
    { &CLSID_VideoRenderer, VideoRenderer_create },
73
    { &CLSID_NullRenderer, NullRenderer_create },
74
    { &CLSID_VideoRendererDefault, VideoRendererDefault_create },
75
    { &CLSID_DSoundRender, DSoundRender_create },
76
    { &CLSID_AudioRender, DSoundRender_create },
77
    { &CLSID_AVIDec, AVIDec_create },
78 79 80
    { &CLSID_SystemClock, QUARTZ_CreateSystemClock },
    { &CLSID_ACMWrapper, ACMWrapper_create },
    { &CLSID_WAVEParser, WAVEParser_create }
81 82 83 84
};

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

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

96
    *ppobj = NULL;
97 98 99 100
    WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
    return E_NOINTERFACE;
}

101 102
static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
{
103
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
104
    return InterlockedIncrement(&This->ref);
105 106
}

107 108
static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
{
109
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
110

111
    ULONG ref = InterlockedDecrement(&This->ref);
112 113

    if (ref == 0)
114
	CoTaskMemFree(This);
115 116 117 118 119 120

    return ref;
}


static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
121 122
					  REFIID riid, LPVOID *ppobj)
{
123
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
124 125 126 127 128
    HRESULT hres;
    LPUNKNOWN punk;
    
    TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);

129
    *ppobj = NULL;
130
    hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
131 132 133
    if (SUCCEEDED(hres)) {
        hres = IUnknown_QueryInterface(punk, riid, ppobj);
        IUnknown_Release(punk);
134 135 136 137
    }
    return hres;
}

138 139
static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
{
140
    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
141 142 143 144
    FIXME("(%p)->(%d),stub!\n",This,dolock);
    return S_OK;
}

145
static const IClassFactoryVtbl DSCF_Vtbl =
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
{
    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
 */
171
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
172
{
173
    unsigned int i;
174

175
    TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
176

177
    if (IsEqualGUID( &IID_IClassFactory, riid ) || IsEqualGUID( &IID_IUnknown, riid))
178
    {
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
        {
            if (IsEqualGUID(object_creation[i].clsid, rclsid))
            {
                IClassFactoryImpl *factory = CoTaskMemAlloc(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;
            }
        }
195
    }
196
    return QUARTZ_DllGetClassObject( rclsid, riid, ppv );
197 198 199
}

/***********************************************************************
200
 *              DllCanUnloadNow (QUARTZ.@)
201
 */
202
HRESULT WINAPI DllCanUnloadNow(void)
203
{
204 205
    if (dll_ref) return S_FALSE;
    return QUARTZ_DllCanUnloadNow();
206
}
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
static const struct {
213
	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 256 257 258 259 260 261 262 263
/***********************************************************************
 *              proxies
 */
HRESULT CALLBACK ICaptureGraphBuilder_FindInterface_Proxy( ICaptureGraphBuilder *This,
                                                           const GUID *pCategory,
                                                           IBaseFilter *pf,
                                                           REFIID riid,
                                                           void **ppint )
{
    return ICaptureGraphBuilder_RemoteFindInterface_Proxy( This, pCategory, pf,
                                                           riid, (IUnknown **)ppint );
}

HRESULT __RPC_STUB ICaptureGraphBuilder_FindInterface_Stub( ICaptureGraphBuilder *This,
                                                            const GUID *pCategory,
                                                            IBaseFilter *pf,
                                                            REFIID riid,
                                                            IUnknown **ppint )
{
    return ICaptureGraphBuilder_FindInterface( This, pCategory, pf, riid, (void **)ppint );
}

HRESULT CALLBACK ICaptureGraphBuilder2_FindInterface_Proxy( ICaptureGraphBuilder2 *This,
                                                            const GUID *pCategory,
                                                            const GUID *pType,
                                                            IBaseFilter *pf,
                                                            REFIID riid,
                                                            void **ppint )
{
    return ICaptureGraphBuilder2_RemoteFindInterface_Proxy( This, pCategory, pType,
                                                            pf, riid, (IUnknown **)ppint );
}

HRESULT __RPC_STUB ICaptureGraphBuilder2_FindInterface_Stub( ICaptureGraphBuilder2 *This,
                                                             const GUID *pCategory,
                                                             const GUID *pType,
                                                             IBaseFilter *pf,
                                                             REFIID riid,
                                                             IUnknown **ppint )
{
    return ICaptureGraphBuilder2_FindInterface( This, pCategory, pType, pf, riid, (void **)ppint );
}

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
/***********************************************************************
 *              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);
}

280
LONG WINAPI AmpFactorToDB(LONG ampfactor)
281
{
282
    FIXME("(%d) Stub!\n", ampfactor);
283 284 285
    return 0;
}

286
LONG WINAPI DBToAmpFactor(LONG db)
287
{
288
    FIXME("(%d) Stub!\n", db);
289 290 291 292 293
    /* Avoid divide by zero (probably during range computation) in Windows Media Player 6.4 */
    if (db < -1000)
	return 0;
    return 100;
}
294

295 296 297
/***********************************************************************
 *              AMGetErrorTextA (QUARTZ.@)
 */
298
DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR buffer, DWORD maxlen)
299
{
300 301
    DWORD res;
    WCHAR errorW[MAX_ERROR_TEXT_LEN];
302

303 304 305
    TRACE("(%x,%p,%d)\n", hr, buffer, maxlen);
    if (!buffer)
        return 0;
306

307 308
    res = AMGetErrorTextW(hr, errorW, sizeof(errorW)/sizeof(*errorW));
    return WideCharToMultiByte(CP_ACP, 0, errorW, res, buffer, maxlen, 0, 0);
309 310
}

311 312 313
/***********************************************************************
 *              AMGetErrorTextW (QUARTZ.@)
 */
314
DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR buffer, DWORD maxlen)
315
{
316
    unsigned int len;
317 318 319
    static const WCHAR format[] = {'E','r','r','o','r',':',' ','0','x','%','l','x',0};
    WCHAR error[MAX_ERROR_TEXT_LEN];

320
    FIXME("(%x,%p,%d) stub\n", hr, buffer, maxlen);
321 322 323

    if (!buffer) return 0;
    wsprintfW(error, format, hr);
324
    if ((len = strlenW(error)) >= maxlen) return 0;
325 326 327
    lstrcpyW(buffer, error);
    return len;
}