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 lpVtbl
;
40 IGraphBuilder
* pFilterGraph
;
42 IGraphBuilder
* GraphBuilder
;
44 IMediaStream
** pStreams
;
45 STREAM_TYPE StreamType
;
46 } IAMMultiMediaStreamImpl
;
48 static const struct IAMMultiMediaStreamVtbl AM_Vtbl
;
50 HRESULT
AM_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
52 IAMMultiMediaStreamImpl
* object
;
54 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
57 return CLASS_E_NOAGGREGATION
;
59 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IAMMultiMediaStreamImpl
));
61 object
->lpVtbl
.lpVtbl
= &AM_Vtbl
;
69 /*** IUnknown methods ***/
70 static HRESULT WINAPI
IAMMultiMediaStreamImpl_QueryInterface(IAMMultiMediaStream
* iface
, REFIID riid
, void** ppvObject
)
72 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
74 FIXME("(%p/%p)->(%s,%p)\n", iface
, This
, debugstr_guid(riid
), ppvObject
);
76 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
77 IsEqualGUID(riid
, &IID_IAMMultiMediaStream
))
79 IClassFactory_AddRef(iface
);
84 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
89 static ULONG WINAPI
IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream
* iface
)
91 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
93 TRACE("(%p/%p)\n", iface
, This
);
95 return InterlockedIncrement(&This
->ref
);
98 static ULONG WINAPI
IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream
* iface
)
100 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
101 ULONG ref
= InterlockedDecrement(&This
->ref
);
103 TRACE("(%p/%p)\n", iface
, This
);
106 HeapFree(GetProcessHeap(), 0, This
);
111 /*** IMultiMediaStream methods ***/
112 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetInformation(IAMMultiMediaStream
* iface
, DWORD
* pdwFlags
, STREAM_TYPE
* pStreamType
)
114 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
116 FIXME("(%p/%p)->(%p,%p) stub!\n", This
, iface
, pdwFlags
, pStreamType
);
121 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream
* iface
, REFMSPID idPurpose
, IMediaStream
** ppMediaStream
)
123 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
127 TRACE("(%p/%p)->(%p,%p)\n", This
, iface
, idPurpose
, ppMediaStream
);
129 for (i
= 0; i
< This
->nbStreams
; i
++)
131 IMediaStream_GetInformation(This
->pStreams
[i
], &PurposeId
, NULL
);
132 if (IsEqualIID(&PurposeId
, idPurpose
))
134 *ppMediaStream
= This
->pStreams
[i
];
135 IMediaStream_AddRef(*ppMediaStream
);
140 return MS_E_NOSTREAM
;
143 static HRESULT WINAPI
IAMMultiMediaStreamImpl_EnumMediaStreams(IAMMultiMediaStream
* iface
, long Index
, IMediaStream
** ppMediaStream
)
145 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
147 FIXME("(%p/%p)->(%ld,%p) stub!\n", This
, iface
, Index
, ppMediaStream
);
152 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetState(IAMMultiMediaStream
* iface
, STREAM_STATE
* pCurrentState
)
154 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
156 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pCurrentState
);
161 static HRESULT WINAPI
IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream
* iface
, STREAM_STATE NewState
)
163 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
165 FIXME("(%p/%p)->() stub!\n", This
, iface
);
170 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetTime(IAMMultiMediaStream
* iface
, STREAM_TIME
* pCurrentTime
)
172 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
174 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pCurrentTime
);
179 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetDuration(IAMMultiMediaStream
* iface
, STREAM_TIME
* pDuration
)
181 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
183 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, pDuration
);
188 static HRESULT WINAPI
IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream
* iface
, STREAM_TIME SeekTime
)
190 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
192 FIXME("(%p/%p)->() stub!\n", This
, iface
);
197 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetEndOfStream(IAMMultiMediaStream
* iface
, HANDLE
* phEOS
)
199 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
201 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, phEOS
);
206 /*** IAMMultiMediaStream methods ***/
207 static HRESULT WINAPI
IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream
* iface
, STREAM_TYPE StreamType
, DWORD dwFlags
, IGraphBuilder
* pFilterGraph
)
209 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
212 FIXME("(%p/%p)->(%x,%x,%p) partial stub!\n", This
, iface
, (DWORD
)StreamType
, dwFlags
, pFilterGraph
);
216 This
->pFilterGraph
= pFilterGraph
;
217 IGraphBuilder_AddRef(This
->pFilterGraph
);
221 hr
= CoCreateInstance(&CLSID_FilterGraph
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IGraphBuilder
, (LPVOID
*)&This
->pFilterGraph
);
226 This
->StreamType
= StreamType
;
232 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetFilterGraph(IAMMultiMediaStream
* iface
, IGraphBuilder
** ppGraphBuilder
)
234 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
236 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, ppGraphBuilder
);
241 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetFilter(IAMMultiMediaStream
* iface
, IMediaStreamFilter
** ppFilter
)
243 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
245 FIXME("(%p/%p)->(%p) stub!\n", This
, iface
, ppFilter
);
250 static HRESULT WINAPI
IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream
* iface
, IUnknown
* pStreamObject
, const MSPID
* PurposeId
,
251 DWORD dwFlags
, IMediaStream
** ppNewStream
)
253 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
255 IMediaStream
* pStream
;
256 IMediaStream
** pNewStreams
;
258 FIXME("(%p/%p)->(%p,%p,%x,%p) partial stub!\n", This
, iface
, pStreamObject
, PurposeId
, dwFlags
, ppNewStream
);
260 hr
= MediaStream_create((IMultiMediaStream
*)iface
, PurposeId
, This
->StreamType
, &pStream
);
263 pNewStreams
= CoTaskMemAlloc((This
->nbStreams
+1)*sizeof(IMediaStream
*));
266 IMediaStream_Release(pStream
);
267 return E_OUTOFMEMORY
;
270 CopyMemory(pNewStreams
, This
->pStreams
, This
->nbStreams
*sizeof(IMediaStream
*));
271 CoTaskMemFree(This
->pStreams
);
272 This
->pStreams
= pNewStreams
;
273 This
->pStreams
[This
->nbStreams
] = pStream
;
277 *ppNewStream
= pStream
;
283 static HRESULT WINAPI
IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream
* iface
, LPCWSTR pszFileName
, DWORD dwFlags
)
286 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
287 IFileSourceFilter
*SourceFilter
;
288 IBaseFilter
*BaseFilter
;
291 PIN_DIRECTION pin_direction
;
293 TRACE("(%p/%p)->(%s,%x)\n", This
, iface
, debugstr_w(pszFileName
), dwFlags
);
295 ret
= CoCreateInstance(&CLSID_AsyncReader
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IFileSourceFilter
, (void**)&SourceFilter
);
299 ret
= IFileSourceFilter_Load(SourceFilter
, pszFileName
, NULL
);
302 IFileSourceFilter_Release(SourceFilter
);
306 ret
= IFileSourceFilter_QueryInterface(SourceFilter
, &IID_IBaseFilter
, (void**)&BaseFilter
);
309 IFileSourceFilter_Release(SourceFilter
);
313 ret
= IBaseFilter_EnumPins(BaseFilter
, &EnumPins
);
319 ret
= IEnumPins_Next(EnumPins
, 1, &ipin
, NULL
);
322 ret
= IPin_QueryDirection(ipin
, &pin_direction
);
323 IEnumPins_Release(EnumPins
);
324 if(ret
== S_OK
&& pin_direction
== PINDIR_OUTPUT
)
331 IEnumPins_Release(EnumPins
);
335 ret
= IFilterGraph_QueryInterface(This
->pFilterGraph
, &IID_IGraphBuilder
, (void**)&This
->GraphBuilder
);
341 ret
= IGraphBuilder_AddSourceFilter(This
->GraphBuilder
, pszFileName
, pszFileName
, &BaseFilter
);
343 IBaseFilter_Release(BaseFilter
);
344 IFileSourceFilter_Release(SourceFilter
);
348 static HRESULT WINAPI
IAMMultiMediaStreamImpl_OpenMoniker(IAMMultiMediaStream
* iface
, IBindCtx
* pCtx
, IMoniker
* pMoniker
, DWORD dwFlags
)
350 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
352 FIXME("(%p/%p)->(%p,%p,%x) stub!\n", This
, iface
, pCtx
, pMoniker
, dwFlags
);
357 static HRESULT WINAPI
IAMMultiMediaStreamImpl_Render(IAMMultiMediaStream
* iface
, DWORD dwFlags
)
359 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
361 FIXME("(%p/%p)->(%x)\n", This
, iface
, dwFlags
);
363 if(dwFlags
!= AMMSF_NOCLOCK
)
366 return IGraphBuilder_Render(This
->GraphBuilder
, This
->ipin
);
369 static const IAMMultiMediaStreamVtbl AM_Vtbl
=
371 IAMMultiMediaStreamImpl_QueryInterface
,
372 IAMMultiMediaStreamImpl_AddRef
,
373 IAMMultiMediaStreamImpl_Release
,
374 IAMMultiMediaStreamImpl_GetInformation
,
375 IAMMultiMediaStreamImpl_GetMediaStream
,
376 IAMMultiMediaStreamImpl_EnumMediaStreams
,
377 IAMMultiMediaStreamImpl_GetState
,
378 IAMMultiMediaStreamImpl_SetState
,
379 IAMMultiMediaStreamImpl_GetTime
,
380 IAMMultiMediaStreamImpl_GetDuration
,
381 IAMMultiMediaStreamImpl_Seek
,
382 IAMMultiMediaStreamImpl_GetEndOfStream
,
383 IAMMultiMediaStreamImpl_Initialize
,
384 IAMMultiMediaStreamImpl_GetFilterGraph
,
385 IAMMultiMediaStreamImpl_GetFilter
,
386 IAMMultiMediaStreamImpl_AddMediaStream
,
387 IAMMultiMediaStreamImpl_OpenFile
,
388 IAMMultiMediaStreamImpl_OpenMoniker
,
389 IAMMultiMediaStreamImpl_Render