mfplat/sample: Optimize copying to 2d buffer.
[wine.git] / dlls / amstream / main.c
bloba78377d0b7eca83cd68986d8dfb38c754e17fbc0
1 /*
2 * MultiMedia Streams Base Functions (AMSTREAM.DLL)
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winerror.h"
31 #include "ole2.h"
32 #include "rpcproxy.h"
34 #include "amstream_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
40 /******************************************************************************
41 * Multimedia Streams ClassFactory
43 typedef struct {
44 IClassFactory IClassFactory_iface;
45 LONG ref;
46 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
47 } IClassFactoryImpl;
49 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
51 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
54 struct object_creation_info
56 const CLSID *clsid;
57 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
60 static const struct object_creation_info object_creation[] =
62 { &CLSID_AMMultiMediaStream, multimedia_stream_create },
63 { &CLSID_AMDirectDrawStream, ddraw_stream_create },
64 { &CLSID_AMAudioStream, audio_stream_create },
65 { &CLSID_AMAudioData, AMAudioData_create },
66 { &CLSID_MediaStreamFilter, filter_create }
69 static HRESULT WINAPI AMCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
71 if (IsEqualGUID(riid, &IID_IUnknown)
72 || IsEqualGUID(riid, &IID_IClassFactory))
74 IClassFactory_AddRef(iface);
75 *ppobj = iface;
76 return S_OK;
79 *ppobj = NULL;
80 WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
81 return E_NOINTERFACE;
84 static ULONG WINAPI AMCF_AddRef(IClassFactory *iface)
86 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
87 return InterlockedIncrement(&This->ref);
90 static ULONG WINAPI AMCF_Release(IClassFactory *iface)
92 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
93 ULONG ref = InterlockedDecrement(&This->ref);
95 if (ref == 0)
96 free(This);
98 return ref;
102 static HRESULT WINAPI AMCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
103 REFIID riid, void **ppobj)
105 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
106 HRESULT hres;
107 IUnknown *punk;
109 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
111 *ppobj = NULL;
112 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
113 if (SUCCEEDED(hres)) {
114 hres = IUnknown_QueryInterface(punk, riid, ppobj);
115 IUnknown_Release(punk);
117 return hres;
120 static HRESULT WINAPI AMCF_LockServer(IClassFactory *iface, BOOL dolock)
122 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
123 FIXME("(%p)->(%d),stub!\n",This,dolock);
124 return S_OK;
127 static const IClassFactoryVtbl DSCF_Vtbl =
129 AMCF_QueryInterface,
130 AMCF_AddRef,
131 AMCF_Release,
132 AMCF_CreateInstance,
133 AMCF_LockServer
136 /*******************************************************************************
137 * DllGetClassObject [AMSTREAM.@]
138 * Retrieves class object from a DLL object
140 * NOTES
141 * Docs say returns STDAPI
143 * PARAMS
144 * rclsid [I] CLSID for the class object
145 * riid [I] Reference to identifier of interface for class object
146 * ppv [O] Address of variable to receive interface pointer for riid
148 * RETURNS
149 * Success: S_OK
150 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
151 * E_UNEXPECTED
153 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
155 unsigned int i;
156 IClassFactoryImpl *factory;
158 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
160 if ( !IsEqualGUID( &IID_IClassFactory, riid )
161 && ! IsEqualGUID( &IID_IUnknown, riid) )
162 return E_NOINTERFACE;
164 for (i = 0; i < ARRAY_SIZE(object_creation); i++)
166 if (IsEqualGUID(object_creation[i].clsid, rclsid))
167 break;
170 if (i == ARRAY_SIZE(object_creation))
172 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
173 return CLASS_E_CLASSNOTAVAILABLE;
176 if (!(factory = calloc(1, sizeof(*factory))))
177 return E_OUTOFMEMORY;
179 factory->IClassFactory_iface.lpVtbl = &DSCF_Vtbl;
180 factory->ref = 1;
182 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
184 *ppv = &factory->IClassFactory_iface;
185 return S_OK;