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 "wine/debug.h"
32 #include "amstream_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
38 IAMMultiMediaStream IAMMultiMediaStream_iface;
40 IGraphBuilder* pFilterGraph;
42 IGraphBuilder* GraphBuilder;
44 IMediaStream** pStreams;
45 STREAM_TYPE StreamType;
46 } IAMMultiMediaStreamImpl;
48 static inline IAMMultiMediaStreamImpl *impl_from_IAMMultiMediaStream(IAMMultiMediaStream *iface)
50 return CONTAINING_RECORD(iface, IAMMultiMediaStreamImpl, IAMMultiMediaStream_iface);
53 static const struct IAMMultiMediaStreamVtbl AM_Vtbl;
55 HRESULT AM_create(IUnknown *pUnkOuter, LPVOID *ppObj)
57 IAMMultiMediaStreamImpl* object;
59 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
62 return CLASS_E_NOAGGREGATION;
64 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAMMultiMediaStreamImpl));
67 ERR("Out of memory\n");
71 object->IAMMultiMediaStream_iface.lpVtbl = &AM_Vtbl;
79 /*** IUnknown methods ***/
80 static HRESULT WINAPI IAMMultiMediaStreamImpl_QueryInterface(IAMMultiMediaStream* iface, REFIID riid, void** ppvObject)
82 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
84 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
86 if (IsEqualGUID(riid, &IID_IUnknown) ||
87 IsEqualGUID(riid, &IID_IMultiMediaStream) ||
88 IsEqualGUID(riid, &IID_IAMMultiMediaStream))
90 IUnknown_AddRef(iface);
95 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
100 static ULONG WINAPI IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream* iface)
102 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
104 TRACE("(%p/%p)\n", iface, This);
106 return InterlockedIncrement(&This->ref);
109 static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface)
111 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
112 ULONG ref = InterlockedDecrement(&This->ref);
114 TRACE("(%p/%p)\n", iface, This);
117 HeapFree(GetProcessHeap(), 0, This);
122 /*** IMultiMediaStream methods ***/
123 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetInformation(IAMMultiMediaStream* iface, DWORD* pdwFlags, STREAM_TYPE* pStreamType)
125 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
127 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pdwFlags, pStreamType);
132 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream* iface, REFMSPID idPurpose, IMediaStream** ppMediaStream)
134 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
138 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(idPurpose), ppMediaStream);
140 for (i = 0; i < This->nbStreams; i++)
142 IMediaStream_GetInformation(This->pStreams[i], &PurposeId, NULL);
143 if (IsEqualIID(&PurposeId, idPurpose))
145 *ppMediaStream = This->pStreams[i];
146 IMediaStream_AddRef(*ppMediaStream);
151 return MS_E_NOSTREAM;
154 static HRESULT WINAPI IAMMultiMediaStreamImpl_EnumMediaStreams(IAMMultiMediaStream* iface, LONG Index, IMediaStream** ppMediaStream)
156 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
158 FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, Index, ppMediaStream);
163 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetState(IAMMultiMediaStream* iface, STREAM_STATE* pCurrentState)
165 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
167 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentState);
172 static HRESULT WINAPI IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream* iface, STREAM_STATE NewState)
174 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
176 FIXME("(%p/%p)->() stub!\n", This, iface);
181 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetTime(IAMMultiMediaStream* iface, STREAM_TIME* pCurrentTime)
183 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
185 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentTime);
190 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetDuration(IAMMultiMediaStream* iface, STREAM_TIME* pDuration)
192 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
194 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDuration);
199 static HRESULT WINAPI IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream* iface, STREAM_TIME SeekTime)
201 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
203 FIXME("(%p/%p)->() stub!\n", This, iface);
208 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetEndOfStream(IAMMultiMediaStream* iface, HANDLE* phEOS)
210 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
212 FIXME("(%p/%p)->(%p) stub!\n", This, iface, phEOS);
217 /*** IAMMultiMediaStream methods ***/
218 static HRESULT WINAPI IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream* iface, STREAM_TYPE StreamType, DWORD dwFlags, IGraphBuilder* pFilterGraph)
220 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
223 TRACE("(%p/%p)->(%x,%x,%p)\n", This, iface, (DWORD)StreamType, dwFlags, pFilterGraph);
227 This->pFilterGraph = pFilterGraph;
228 IGraphBuilder_AddRef(This->pFilterGraph);
232 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&This->pFilterGraph);
237 This->StreamType = StreamType;
243 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilterGraph(IAMMultiMediaStream* iface, IGraphBuilder** ppGraphBuilder)
245 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
247 TRACE("(%p/%p)->(%p)\n", This, iface, ppGraphBuilder);
252 if (This->pFilterGraph)
253 return IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)ppGraphBuilder);
255 *ppGraphBuilder = NULL;
260 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilter(IAMMultiMediaStream* iface, IMediaStreamFilter** ppFilter)
262 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
264 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppFilter);
269 static HRESULT WINAPI IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream* iface, IUnknown* pStreamObject, const MSPID* PurposeId,
270 DWORD dwFlags, IMediaStream** ppNewStream)
272 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
274 IMediaStream* pStream;
275 IMediaStream** pNewStreams;
277 FIXME("(%p/%p)->(%p,%s,%x,%p) partial stub!\n", This, iface, pStreamObject, debugstr_guid(PurposeId), dwFlags, ppNewStream);
279 if (IsEqualGUID(PurposeId, &MSPID_PrimaryVideo))
280 hr = DirectDrawMediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
282 hr = MediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
286 pNewStreams = CoTaskMemAlloc((This->nbStreams+1)*sizeof(IMediaStream*));
289 IMediaStream_Release(pStream);
290 return E_OUTOFMEMORY;
293 CopyMemory(pNewStreams, This->pStreams, This->nbStreams*sizeof(IMediaStream*));
294 CoTaskMemFree(This->pStreams);
295 This->pStreams = pNewStreams;
296 This->pStreams[This->nbStreams] = pStream;
300 *ppNewStream = pStream;
306 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream* iface, LPCWSTR pszFileName, DWORD dwFlags)
309 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
310 IFileSourceFilter *SourceFilter;
311 IBaseFilter *BaseFilter;
314 PIN_DIRECTION pin_direction;
316 TRACE("(%p/%p)->(%s,%x)\n", This, iface, debugstr_w(pszFileName), dwFlags);
318 ret = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSourceFilter, (void**)&SourceFilter);
322 ret = IFileSourceFilter_Load(SourceFilter, pszFileName, NULL);
325 IFileSourceFilter_Release(SourceFilter);
329 ret = IFileSourceFilter_QueryInterface(SourceFilter, &IID_IBaseFilter, (void**)&BaseFilter);
332 IFileSourceFilter_Release(SourceFilter);
336 ret = IBaseFilter_EnumPins(BaseFilter, &EnumPins);
342 ret = IEnumPins_Next(EnumPins, 1, &ipin, NULL);
345 ret = IPin_QueryDirection(ipin, &pin_direction);
346 IEnumPins_Release(EnumPins);
347 if(ret == S_OK && pin_direction == PINDIR_OUTPUT)
354 IEnumPins_Release(EnumPins);
358 /* If Initialize was not called before, we do it here */
359 if (!This->pFilterGraph)
361 ret = IAMMultiMediaStream_Initialize(iface, STREAMTYPE_READ, 0, NULL);
366 ret = IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)&This->GraphBuilder);
372 ret = IGraphBuilder_AddSourceFilter(This->GraphBuilder, pszFileName, pszFileName, &BaseFilter);
375 IBaseFilter_Release(BaseFilter);
376 IFileSourceFilter_Release(SourceFilter);
380 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenMoniker(IAMMultiMediaStream* iface, IBindCtx* pCtx, IMoniker* pMoniker, DWORD dwFlags)
382 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
384 FIXME("(%p/%p)->(%p,%p,%x) stub!\n", This, iface, pCtx, pMoniker, dwFlags);
389 static HRESULT WINAPI IAMMultiMediaStreamImpl_Render(IAMMultiMediaStream* iface, DWORD dwFlags)
391 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
393 FIXME("(%p/%p)->(%x) partial stub!\n", This, iface, dwFlags);
395 if(dwFlags != AMMSF_NOCLOCK)
398 return IGraphBuilder_Render(This->GraphBuilder, This->ipin);
401 static const IAMMultiMediaStreamVtbl AM_Vtbl =
403 IAMMultiMediaStreamImpl_QueryInterface,
404 IAMMultiMediaStreamImpl_AddRef,
405 IAMMultiMediaStreamImpl_Release,
406 IAMMultiMediaStreamImpl_GetInformation,
407 IAMMultiMediaStreamImpl_GetMediaStream,
408 IAMMultiMediaStreamImpl_EnumMediaStreams,
409 IAMMultiMediaStreamImpl_GetState,
410 IAMMultiMediaStreamImpl_SetState,
411 IAMMultiMediaStreamImpl_GetTime,
412 IAMMultiMediaStreamImpl_GetDuration,
413 IAMMultiMediaStreamImpl_Seek,
414 IAMMultiMediaStreamImpl_GetEndOfStream,
415 IAMMultiMediaStreamImpl_Initialize,
416 IAMMultiMediaStreamImpl_GetFilterGraph,
417 IAMMultiMediaStreamImpl_GetFilter,
418 IAMMultiMediaStreamImpl_AddMediaStream,
419 IAMMultiMediaStreamImpl_OpenFile,
420 IAMMultiMediaStreamImpl_OpenMoniker,
421 IAMMultiMediaStreamImpl_Render