2 * Implementation of IAMMultiMediaStream Interface
4 * Copyright 2004 Christian Costa
5 * Copyright 2006 Ivan Leo Puoti
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/debug.h"
29 #include "amstream_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
35 IAMMultiMediaStream IAMMultiMediaStream_iface;
37 IGraphBuilder* pFilterGraph;
40 IMediaStream** pStreams;
41 STREAM_TYPE StreamType;
42 } IAMMultiMediaStreamImpl;
44 static inline IAMMultiMediaStreamImpl *impl_from_IAMMultiMediaStream(IAMMultiMediaStream *iface)
46 return CONTAINING_RECORD(iface, IAMMultiMediaStreamImpl, IAMMultiMediaStream_iface);
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);
58 return CLASS_E_NOAGGREGATION;
60 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAMMultiMediaStreamImpl));
63 ERR("Out of memory\n");
67 object->IAMMultiMediaStream_iface.lpVtbl = &AM_Vtbl;
75 /*** IUnknown methods ***/
76 static HRESULT WINAPI IAMMultiMediaStreamImpl_QueryInterface(IAMMultiMediaStream* iface, REFIID riid, void** ppvObject)
78 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
80 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
82 if (IsEqualGUID(riid, &IID_IUnknown) ||
83 IsEqualGUID(riid, &IID_IMultiMediaStream) ||
84 IsEqualGUID(riid, &IID_IAMMultiMediaStream))
86 IUnknown_AddRef(iface);
91 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
96 static ULONG WINAPI IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream* iface)
98 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
100 TRACE("(%p/%p)\n", iface, This);
102 return InterlockedIncrement(&This->ref);
105 static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface)
107 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
108 ULONG ref = InterlockedDecrement(&This->ref);
110 TRACE("(%p/%p)\n", iface, This);
113 HeapFree(GetProcessHeap(), 0, This);
118 /*** IMultiMediaStream methods ***/
119 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetInformation(IAMMultiMediaStream* iface, DWORD* pdwFlags, STREAM_TYPE* pStreamType)
121 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
123 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pdwFlags, pStreamType);
128 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream* iface, REFMSPID idPurpose, IMediaStream** ppMediaStream)
130 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
134 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(idPurpose), ppMediaStream);
136 for (i = 0; i < This->nbStreams; i++)
138 IMediaStream_GetInformation(This->pStreams[i], &PurposeId, NULL);
139 if (IsEqualIID(&PurposeId, idPurpose))
141 *ppMediaStream = This->pStreams[i];
142 IMediaStream_AddRef(*ppMediaStream);
147 return MS_E_NOSTREAM;
150 static HRESULT WINAPI IAMMultiMediaStreamImpl_EnumMediaStreams(IAMMultiMediaStream* iface, LONG Index, IMediaStream** ppMediaStream)
152 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
154 FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, Index, ppMediaStream);
159 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetState(IAMMultiMediaStream* iface, STREAM_STATE* pCurrentState)
161 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
163 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentState);
168 static HRESULT WINAPI IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream* iface, STREAM_STATE NewState)
170 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
172 FIXME("(%p/%p)->() stub!\n", This, iface);
177 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetTime(IAMMultiMediaStream* iface, STREAM_TIME* pCurrentTime)
179 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
181 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentTime);
186 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetDuration(IAMMultiMediaStream* iface, STREAM_TIME* pDuration)
188 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
190 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDuration);
195 static HRESULT WINAPI IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream* iface, STREAM_TIME SeekTime)
197 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
199 FIXME("(%p/%p)->() stub!\n", This, iface);
204 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetEndOfStream(IAMMultiMediaStream* iface, HANDLE* phEOS)
206 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
208 FIXME("(%p/%p)->(%p) stub!\n", This, iface, phEOS);
213 /*** IAMMultiMediaStream methods ***/
214 static HRESULT WINAPI IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream* iface, STREAM_TYPE StreamType, DWORD dwFlags, IGraphBuilder* pFilterGraph)
216 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
219 TRACE("(%p/%p)->(%x,%x,%p)\n", This, iface, (DWORD)StreamType, dwFlags, pFilterGraph);
223 This->pFilterGraph = pFilterGraph;
224 IGraphBuilder_AddRef(This->pFilterGraph);
228 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&This->pFilterGraph);
233 This->StreamType = StreamType;
239 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilterGraph(IAMMultiMediaStream* iface, IGraphBuilder** ppGraphBuilder)
241 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
243 TRACE("(%p/%p)->(%p)\n", This, iface, ppGraphBuilder);
248 if (This->pFilterGraph)
249 return IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)ppGraphBuilder);
251 *ppGraphBuilder = NULL;
256 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilter(IAMMultiMediaStream* iface, IMediaStreamFilter** ppFilter)
258 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
260 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppFilter);
265 static HRESULT WINAPI IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream* iface, IUnknown* pStreamObject, const MSPID* PurposeId,
266 DWORD dwFlags, IMediaStream** ppNewStream)
268 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
270 IMediaStream* pStream;
271 IMediaStream** pNewStreams;
273 FIXME("(%p/%p)->(%p,%s,%x,%p) partial stub!\n", This, iface, pStreamObject, debugstr_guid(PurposeId), dwFlags, ppNewStream);
275 hr = mediastream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
278 pNewStreams = CoTaskMemRealloc(This->pStreams, (This->nbStreams+1) * sizeof(IMediaStream*));
281 IMediaStream_Release(pStream);
282 return E_OUTOFMEMORY;
284 This->pStreams = pNewStreams;
285 This->pStreams[This->nbStreams] = pStream;
289 *ppNewStream = pStream;
295 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream* iface, LPCWSTR pszFileName, DWORD dwFlags)
298 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
299 IFileSourceFilter *SourceFilter;
300 IBaseFilter *BaseFilter;
303 PIN_DIRECTION pin_direction;
305 TRACE("(%p/%p)->(%s,%x)\n", This, iface, debugstr_w(pszFileName), dwFlags);
307 /* If Initialize was not called before, we do it here */
308 if (!This->pFilterGraph)
310 ret = IAMMultiMediaStream_Initialize(iface, STREAMTYPE_READ, 0, NULL);
315 ret = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSourceFilter, (void**)&SourceFilter);
319 ret = IFileSourceFilter_Load(SourceFilter, pszFileName, NULL);
322 IFileSourceFilter_Release(SourceFilter);
326 ret = IFileSourceFilter_QueryInterface(SourceFilter, &IID_IBaseFilter, (void**)&BaseFilter);
329 IFileSourceFilter_Release(SourceFilter);
333 ret = IBaseFilter_EnumPins(BaseFilter, &EnumPins);
339 ret = IEnumPins_Next(EnumPins, 1, &ipin, NULL);
342 ret = IPin_QueryDirection(ipin, &pin_direction);
343 IEnumPins_Release(EnumPins);
344 if(ret == S_OK && pin_direction == PINDIR_OUTPUT)
351 IEnumPins_Release(EnumPins);
355 ret = IGraphBuilder_AddSourceFilter(This->pFilterGraph, pszFileName, pszFileName, &BaseFilter);
358 IBaseFilter_Release(BaseFilter);
359 IFileSourceFilter_Release(SourceFilter);
363 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenMoniker(IAMMultiMediaStream* iface, IBindCtx* pCtx, IMoniker* pMoniker, DWORD dwFlags)
365 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
367 FIXME("(%p/%p)->(%p,%p,%x) stub!\n", This, iface, pCtx, pMoniker, dwFlags);
372 static HRESULT WINAPI IAMMultiMediaStreamImpl_Render(IAMMultiMediaStream* iface, DWORD dwFlags)
374 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
376 FIXME("(%p/%p)->(%x) partial stub!\n", This, iface, dwFlags);
378 if(dwFlags != AMMSF_NOCLOCK)
381 return IGraphBuilder_Render(This->pFilterGraph, This->ipin);
384 static const IAMMultiMediaStreamVtbl AM_Vtbl =
386 IAMMultiMediaStreamImpl_QueryInterface,
387 IAMMultiMediaStreamImpl_AddRef,
388 IAMMultiMediaStreamImpl_Release,
389 IAMMultiMediaStreamImpl_GetInformation,
390 IAMMultiMediaStreamImpl_GetMediaStream,
391 IAMMultiMediaStreamImpl_EnumMediaStreams,
392 IAMMultiMediaStreamImpl_GetState,
393 IAMMultiMediaStreamImpl_SetState,
394 IAMMultiMediaStreamImpl_GetTime,
395 IAMMultiMediaStreamImpl_GetDuration,
396 IAMMultiMediaStreamImpl_Seek,
397 IAMMultiMediaStreamImpl_GetEndOfStream,
398 IAMMultiMediaStreamImpl_Initialize,
399 IAMMultiMediaStreamImpl_GetFilterGraph,
400 IAMMultiMediaStreamImpl_GetFilter,
401 IAMMultiMediaStreamImpl_AddMediaStream,
402 IAMMultiMediaStreamImpl_OpenFile,
403 IAMMultiMediaStreamImpl_OpenMoniker,
404 IAMMultiMediaStreamImpl_Render