amstream: sign-compare fixes.
[wine/multimedia.git] / dlls / amstream / amstream.c
blobf25147524aee7d5ad2db8f20c21b0ae595026de6
1 /*
2 * Implementation of IAMMultiMediaStream Interface
4 * Copyright 2004 Christian Costa
5 * Copyright 2006 Ivan Leo Puoti
7 * This file contains the (internal) driver registration functions,
8 * driver enumeration APIs and DirectDraw creation functions.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "config.h"
26 #include "wine/debug.h"
28 #define COBJMACROS
30 #include "winbase.h"
31 #include "wingdi.h"
33 #include "amstream_private.h"
34 #include "amstream.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
38 typedef struct {
39 IAMMultiMediaStream lpVtbl;
40 LONG ref;
41 IGraphBuilder* pFilterGraph;
42 IPin* ipin;
43 IGraphBuilder* GraphBuilder;
44 ULONG nbStreams;
45 IMediaStream** pStreams;
46 STREAM_TYPE StreamType;
47 } IAMMultiMediaStreamImpl;
49 static const struct IAMMultiMediaStreamVtbl AM_Vtbl;
51 HRESULT AM_create(IUnknown *pUnkOuter, LPVOID *ppObj)
53 IAMMultiMediaStreamImpl* object;
55 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
57 if( pUnkOuter )
58 return CLASS_E_NOAGGREGATION;
60 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAMMultiMediaStreamImpl));
62 object->lpVtbl.lpVtbl = &AM_Vtbl;
63 object->ref = 1;
65 *ppObj = object;
67 return S_OK;
70 /*** IUnknown methods ***/
71 static HRESULT WINAPI IAMMultiMediaStreamImpl_QueryInterface(IAMMultiMediaStream* iface, REFIID riid, void** ppvObject)
73 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
75 FIXME("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
77 if (IsEqualGUID(riid, &IID_IUnknown) ||
78 IsEqualGUID(riid, &IID_IAMMultiMediaStream))
80 IClassFactory_AddRef(iface);
81 *ppvObject = This;
82 return S_OK;
85 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
87 return E_NOINTERFACE;
90 static ULONG WINAPI IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream* iface)
92 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
94 TRACE("(%p/%p)\n", iface, This);
96 return InterlockedIncrement(&This->ref);
99 static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface)
101 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
102 ULONG ref = InterlockedDecrement(&This->ref);
104 TRACE("(%p/%p)\n", iface, This);
106 if (!ref)
107 HeapFree(GetProcessHeap(), 0, This);
109 return ref;
112 /*** IMultiMediaStream methods ***/
113 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetInformation(IAMMultiMediaStream* iface, DWORD* pdwFlags, STREAM_TYPE* pStreamType)
115 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
117 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pdwFlags, pStreamType);
119 return E_NOTIMPL;
122 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream* iface, REFMSPID idPurpose, IMediaStream** ppMediaStream)
124 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
125 MSPID PurposeId;
126 unsigned int i;
128 TRACE("(%p/%p)->(%p,%p)\n", This, iface, idPurpose, ppMediaStream);
130 for (i = 0; i < This->nbStreams; i++)
132 IMediaStream_GetInformation(This->pStreams[i], &PurposeId, NULL);
133 if (IsEqualIID(&PurposeId, idPurpose))
135 *ppMediaStream = This->pStreams[i];
136 IMediaStream_AddRef(*ppMediaStream);
137 return S_OK;
141 return MS_E_NOSTREAM;
144 static HRESULT WINAPI IAMMultiMediaStreamImpl_EnumMediaStreams(IAMMultiMediaStream* iface, long Index, IMediaStream** ppMediaStream)
146 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
148 FIXME("(%p/%p)->(%ld,%p) stub!\n", This, iface, Index, ppMediaStream);
150 return E_NOTIMPL;
153 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetState(IAMMultiMediaStream* iface, STREAM_STATE* pCurrentState)
155 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
157 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentState);
159 return E_NOTIMPL;
162 static HRESULT WINAPI IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream* iface, STREAM_STATE NewState)
164 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
166 FIXME("(%p/%p)->() stub!\n", This, iface);
168 return E_NOTIMPL;
171 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetTime(IAMMultiMediaStream* iface, STREAM_TIME* pCurrentTime)
173 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
175 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentTime);
177 return E_NOTIMPL;
180 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetDuration(IAMMultiMediaStream* iface, STREAM_TIME* pDuration)
182 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
184 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDuration);
186 return E_NOTIMPL;
189 static HRESULT WINAPI IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream* iface, STREAM_TIME SeekTime)
191 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
193 FIXME("(%p/%p)->() stub!\n", This, iface);
195 return E_NOTIMPL;
198 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetEndOfStream(IAMMultiMediaStream* iface, HANDLE* phEOS)
200 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
202 FIXME("(%p/%p)->(%p) stub!\n", This, iface, phEOS);
204 return E_NOTIMPL;
207 /*** IAMMultiMediaStream methods ***/
208 static HRESULT WINAPI IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream* iface, STREAM_TYPE StreamType, DWORD dwFlags, IGraphBuilder* pFilterGraph)
210 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
211 HRESULT hr = S_OK;
213 FIXME("(%p/%p)->(%x,%x,%p) partial stub!\n", This, iface, (DWORD)StreamType, dwFlags, pFilterGraph);
215 if (pFilterGraph)
217 This->pFilterGraph = pFilterGraph;
218 IGraphBuilder_AddRef(This->pFilterGraph);
220 else
222 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&This->pFilterGraph);
225 if (SUCCEEDED(hr))
227 This->StreamType = StreamType;
230 return hr;
233 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilterGraph(IAMMultiMediaStream* iface, IGraphBuilder** ppGraphBuilder)
235 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
237 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppGraphBuilder);
239 return E_NOTIMPL;
242 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilter(IAMMultiMediaStream* iface, IMediaStreamFilter** ppFilter)
244 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
246 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppFilter);
248 return E_NOTIMPL;
251 static HRESULT WINAPI IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream* iface, IUnknown* pStreamObject, const MSPID* PurposeId,
252 DWORD dwFlags, IMediaStream** ppNewStream)
254 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
255 HRESULT hr;
256 IMediaStream* pStream;
257 IMediaStream** pNewStreams;
259 FIXME("(%p/%p)->(%p,%p,%x,%p) partial stub!\n", This, iface, pStreamObject, PurposeId, dwFlags, ppNewStream);
261 hr = MediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
262 if (SUCCEEDED(hr))
264 pNewStreams = (IMediaStream**)CoTaskMemAlloc((This->nbStreams+1)*sizeof(IMediaStream*));
265 if (!pNewStreams)
267 IMediaStream_Release(pStream);
268 return E_OUTOFMEMORY;
270 if (This->nbStreams)
271 CopyMemory(pNewStreams, This->pStreams, This->nbStreams*sizeof(IMediaStream*));
272 CoTaskMemFree(This->pStreams);
273 This->pStreams = pNewStreams;
274 This->pStreams[This->nbStreams] = pStream;
275 This->nbStreams++;
277 if (ppNewStream)
278 *ppNewStream = pStream;
281 return hr;
284 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream* iface, LPCWSTR pszFileName, DWORD dwFlags)
286 HRESULT ret;
287 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
288 IFileSourceFilter *SourceFilter;
289 IBaseFilter *BaseFilter;
290 IEnumPins *EnumPins;
291 IPin *ipin;
292 PIN_DIRECTION pin_direction;
294 TRACE("(%p/%p)->(%s,%x)\n", This, iface, debugstr_w(pszFileName), dwFlags);
296 ret = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSourceFilter, (void**)&SourceFilter);
297 if(ret != S_OK)
298 return ret;
300 ret = IFileSourceFilter_Load(SourceFilter, pszFileName, NULL);
301 if(ret != S_OK)
303 IFileSourceFilter_Release(SourceFilter);
304 return ret;
307 ret = IFileSourceFilter_QueryInterface(SourceFilter, &IID_IBaseFilter, (void**)&BaseFilter);
308 if(ret != S_OK)
310 IFileSourceFilter_Release(SourceFilter);
311 return ret;
314 ret = IBaseFilter_EnumPins(BaseFilter, &EnumPins);
315 if(ret != S_OK)
317 goto end;
320 ret = IEnumPins_Next(EnumPins, 1, &ipin, NULL);
321 if(ret == S_OK)
323 ret = IPin_QueryDirection(ipin, &pin_direction);
324 IEnumPins_Release(EnumPins);
325 if(ret == S_OK && pin_direction == PINDIR_OUTPUT)
326 This->ipin = ipin;
327 else
328 goto end;
330 else
332 IEnumPins_Release(EnumPins);
333 goto end;
336 ret = IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)&This->GraphBuilder);
337 if(ret != S_OK)
339 goto end;
342 ret = IGraphBuilder_AddSourceFilter(This->GraphBuilder, pszFileName, pszFileName, &BaseFilter);
343 end:
344 IBaseFilter_Release(BaseFilter);
345 IFileSourceFilter_Release(SourceFilter);
346 return ret;
349 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenMoniker(IAMMultiMediaStream* iface, IBindCtx* pCtx, IMoniker* pMoniker, DWORD dwFlags)
351 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
353 FIXME("(%p/%p)->(%p,%p,%x) stub!\n", This, iface, pCtx, pMoniker, dwFlags);
355 return E_NOTIMPL;
358 static HRESULT WINAPI IAMMultiMediaStreamImpl_Render(IAMMultiMediaStream* iface, DWORD dwFlags)
360 IAMMultiMediaStreamImpl *This = (IAMMultiMediaStreamImpl *)iface;
362 FIXME("(%p/%p)->(%x)\n", This, iface, dwFlags);
364 if(dwFlags != AMMSF_NOCLOCK)
365 return E_INVALIDARG;
367 return IGraphBuilder_Render(This->GraphBuilder, This->ipin);
370 static const IAMMultiMediaStreamVtbl AM_Vtbl =
372 IAMMultiMediaStreamImpl_QueryInterface,
373 IAMMultiMediaStreamImpl_AddRef,
374 IAMMultiMediaStreamImpl_Release,
375 IAMMultiMediaStreamImpl_GetInformation,
376 IAMMultiMediaStreamImpl_GetMediaStream,
377 IAMMultiMediaStreamImpl_EnumMediaStreams,
378 IAMMultiMediaStreamImpl_GetState,
379 IAMMultiMediaStreamImpl_SetState,
380 IAMMultiMediaStreamImpl_GetTime,
381 IAMMultiMediaStreamImpl_GetDuration,
382 IAMMultiMediaStreamImpl_Seek,
383 IAMMultiMediaStreamImpl_GetEndOfStream,
384 IAMMultiMediaStreamImpl_Initialize,
385 IAMMultiMediaStreamImpl_GetFilterGraph,
386 IAMMultiMediaStreamImpl_GetFilter,
387 IAMMultiMediaStreamImpl_AddMediaStream,
388 IAMMultiMediaStreamImpl_OpenFile,
389 IAMMultiMediaStreamImpl_OpenMoniker,
390 IAMMultiMediaStreamImpl_Render