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
);
111 TRACE("(%p/%p)\n", iface
, This
);
115 for(i
= 0; i
< This
->nbStreams
; i
++)
116 IMediaStream_Release(This
->pStreams
[i
]);
118 IPin_Release(This
->ipin
);
119 if (This
->pFilterGraph
)
120 IGraphBuilder_Release(This
->pFilterGraph
);
121 HeapFree(GetProcessHeap(), 0, This
);
127 /*** IMultiMediaStream methods ***/
128 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetInformation(IAMMultiMediaStream
* iface
, DWORD
* pdwFlags
, STREAM_TYPE
* pStreamType
)
130 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
132 FIXME("(%p/%p)->(%p,%p) stub!\n", This
, iface
, pdwFlags
, pStreamType
);
137 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream
* iface
, REFMSPID idPurpose
, IMediaStream
** ppMediaStream
)
139 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
143 TRACE("(%p/%p)->(%s,%p)\n", This
, iface
, debugstr_guid(idPurpose
), ppMediaStream
);
145 for (i
= 0; i
< This
->nbStreams
; i
++)
147 IMediaStream_GetInformation(This
->pStreams
[i
], &PurposeId
, NULL
);
148 if (IsEqualIID(&PurposeId
, idPurpose
))
150 *ppMediaStream
= This
->pStreams
[i
];
151 IMediaStream_AddRef(*ppMediaStream
);
156 return MS_E_NOSTREAM
;
159 static HRESULT WINAPI
IAMMultiMediaStreamImpl_EnumMediaStreams(IAMMultiMediaStream
* iface
, LONG Index
, IMediaStream
** ppMediaStream
)
161 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
163 FIXME("(%p/%p)->(%d,%p) stub!\n", This
, iface
, Index
, ppMediaStream
);
168 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetState(IAMMultiMediaStream
* iface
, STREAM_STATE
* pCurrentState
)
170 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
172 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pCurrentState
);
177 static HRESULT WINAPI
IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream
* iface
, STREAM_STATE NewState
)
179 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
181 FIXME("(%p/%p)->() stub!\n", This
, iface
);
186 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetTime(IAMMultiMediaStream
* iface
, STREAM_TIME
* pCurrentTime
)
188 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
190 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pCurrentTime
);
195 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetDuration(IAMMultiMediaStream
* iface
, STREAM_TIME
* pDuration
)
197 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
199 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pDuration
);
204 static HRESULT WINAPI
IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream
* iface
, STREAM_TIME SeekTime
)
206 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
208 FIXME("(%p/%p)->() stub!\n", This
, iface
);
213 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetEndOfStream(IAMMultiMediaStream
* iface
, HANDLE
* phEOS
)
215 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
217 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, phEOS
);
222 /*** IAMMultiMediaStream methods ***/
223 static HRESULT WINAPI
IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream
* iface
, STREAM_TYPE StreamType
, DWORD dwFlags
, IGraphBuilder
* pFilterGraph
)
225 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
228 TRACE("(%p/%p)->(%x,%x,%p)\n", This
, iface
, (DWORD
)StreamType
, dwFlags
, pFilterGraph
);
232 This
->pFilterGraph
= pFilterGraph
;
233 IGraphBuilder_AddRef(This
->pFilterGraph
);
237 hr
= CoCreateInstance(&CLSID_FilterGraph
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IGraphBuilder
, (LPVOID
*)&This
->pFilterGraph
);
242 This
->StreamType
= StreamType
;
248 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetFilterGraph(IAMMultiMediaStream
* iface
, IGraphBuilder
** ppGraphBuilder
)
250 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
252 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppGraphBuilder
);
257 if (This
->pFilterGraph
)
258 return IFilterGraph_QueryInterface(This
->pFilterGraph
, &IID_IGraphBuilder
, (void**)ppGraphBuilder
);
260 *ppGraphBuilder
= NULL
;
265 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetFilter(IAMMultiMediaStream
* iface
, IMediaStreamFilter
** ppFilter
)
267 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
269 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, ppFilter
);
274 static HRESULT WINAPI
IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream
* iface
, IUnknown
* pStreamObject
, const MSPID
* PurposeId
,
275 DWORD dwFlags
, IMediaStream
** ppNewStream
)
277 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
279 IMediaStream
* pStream
;
280 IMediaStream
** pNewStreams
;
282 FIXME("(%p/%p)->(%p,%s,%x,%p) partial stub!\n", This
, iface
, pStreamObject
, debugstr_guid(PurposeId
), dwFlags
, ppNewStream
);
284 hr
= mediastream_create((IMultiMediaStream
*)iface
, PurposeId
, This
->StreamType
, &pStream
);
287 pNewStreams
= CoTaskMemRealloc(This
->pStreams
, (This
->nbStreams
+1) * sizeof(IMediaStream
*));
290 IMediaStream_Release(pStream
);
291 return E_OUTOFMEMORY
;
293 This
->pStreams
= pNewStreams
;
294 This
->pStreams
[This
->nbStreams
] = pStream
;
298 *ppNewStream
= pStream
;
304 static HRESULT WINAPI
IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream
* iface
, LPCWSTR pszFileName
, DWORD dwFlags
)
307 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
308 IFileSourceFilter
*SourceFilter
;
309 IBaseFilter
*BaseFilter
;
312 PIN_DIRECTION pin_direction
;
314 TRACE("(%p/%p)->(%s,%x)\n", This
, iface
, debugstr_w(pszFileName
), dwFlags
);
316 /* If Initialize was not called before, we do it here */
317 if (!This
->pFilterGraph
)
319 ret
= IAMMultiMediaStream_Initialize(iface
, STREAMTYPE_READ
, 0, NULL
);
324 ret
= CoCreateInstance(&CLSID_AsyncReader
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IFileSourceFilter
, (void**)&SourceFilter
);
328 ret
= IGraphBuilder_AddSourceFilter(This
->pFilterGraph
, pszFileName
, pszFileName
, &BaseFilter
);
332 ret
= IFileSourceFilter_Load(SourceFilter
, pszFileName
, NULL
);
335 IFileSourceFilter_Release(SourceFilter
);
339 ret
= IFileSourceFilter_QueryInterface(SourceFilter
, &IID_IBaseFilter
, (void**)&BaseFilter
);
342 IFileSourceFilter_Release(SourceFilter
);
346 ret
= IBaseFilter_EnumPins(BaseFilter
, &EnumPins
);
352 ret
= IEnumPins_Next(EnumPins
, 1, &ipin
, NULL
);
355 ret
= IPin_QueryDirection(ipin
, &pin_direction
);
356 IEnumPins_Release(EnumPins
);
357 if (ret
== S_OK
&& pin_direction
== PINDIR_OUTPUT
)
362 IEnumPins_Release(EnumPins
);
366 IBaseFilter_Release(BaseFilter
);
367 IFileSourceFilter_Release(SourceFilter
);
371 static HRESULT WINAPI
IAMMultiMediaStreamImpl_OpenMoniker(IAMMultiMediaStream
* iface
, IBindCtx
* pCtx
, IMoniker
* pMoniker
, DWORD dwFlags
)
373 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
375 FIXME("(%p/%p)->(%p,%p,%x) stub!\n", This
, iface
, pCtx
, pMoniker
, dwFlags
);
380 static HRESULT WINAPI
IAMMultiMediaStreamImpl_Render(IAMMultiMediaStream
* iface
, DWORD dwFlags
)
382 IAMMultiMediaStreamImpl
*This
= impl_from_IAMMultiMediaStream(iface
);
384 FIXME("(%p/%p)->(%x) partial stub!\n", This
, iface
, dwFlags
);
386 if(dwFlags
!= AMMSF_NOCLOCK
)
389 return IGraphBuilder_Render(This
->pFilterGraph
, This
->ipin
);
392 static const IAMMultiMediaStreamVtbl AM_Vtbl
=
394 IAMMultiMediaStreamImpl_QueryInterface
,
395 IAMMultiMediaStreamImpl_AddRef
,
396 IAMMultiMediaStreamImpl_Release
,
397 IAMMultiMediaStreamImpl_GetInformation
,
398 IAMMultiMediaStreamImpl_GetMediaStream
,
399 IAMMultiMediaStreamImpl_EnumMediaStreams
,
400 IAMMultiMediaStreamImpl_GetState
,
401 IAMMultiMediaStreamImpl_SetState
,
402 IAMMultiMediaStreamImpl_GetTime
,
403 IAMMultiMediaStreamImpl_GetDuration
,
404 IAMMultiMediaStreamImpl_Seek
,
405 IAMMultiMediaStreamImpl_GetEndOfStream
,
406 IAMMultiMediaStreamImpl_Initialize
,
407 IAMMultiMediaStreamImpl_GetFilterGraph
,
408 IAMMultiMediaStreamImpl_GetFilter
,
409 IAMMultiMediaStreamImpl_AddMediaStream
,
410 IAMMultiMediaStreamImpl_OpenFile
,
411 IAMMultiMediaStreamImpl_OpenMoniker
,
412 IAMMultiMediaStreamImpl_Render