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
26 #include "wine/debug.h"
33 #include "amstream_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(amstream
);
39 IAMMultiMediaStream lpVtbl
;
41 IGraphBuilder
* pFilterGraph
;
43 IGraphBuilder
* GraphBuilder
;
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
);
58 return CLASS_E_NOAGGREGATION
;
60 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IAMMultiMediaStreamImpl
));
62 object
->lpVtbl
.lpVtbl
= &AM_Vtbl
;
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
);
85 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppvObject
);
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
);
107 HeapFree(GetProcessHeap(), 0, This
);
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
);
122 static HRESULT WINAPI
IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream
* iface
, REFMSPID idPurpose
, IMediaStream
** ppMediaStream
)
124 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
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
);
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
);
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
);
162 static HRESULT WINAPI
IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream
* iface
, STREAM_STATE NewState
)
164 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
166 FIXME("(%p/%p)->() stub!\n", This
, iface
);
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
);
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
);
189 static HRESULT WINAPI
IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream
* iface
, STREAM_TIME SeekTime
)
191 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
193 FIXME("(%p/%p)->() stub!\n", This
, iface
);
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
);
207 /*** IAMMultiMediaStream methods ***/
208 static HRESULT WINAPI
IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream
* iface
, STREAM_TYPE StreamType
, DWORD dwFlags
, IGraphBuilder
* pFilterGraph
)
210 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
213 FIXME("(%p/%p)->(%x,%x,%p) partial stub!\n", This
, iface
, (DWORD
)StreamType
, dwFlags
, pFilterGraph
);
217 This
->pFilterGraph
= pFilterGraph
;
218 IGraphBuilder_AddRef(This
->pFilterGraph
);
222 hr
= CoCreateInstance(&CLSID_FilterGraph
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IGraphBuilder
, (LPVOID
*)&This
->pFilterGraph
);
227 This
->StreamType
= StreamType
;
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
);
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
);
251 static HRESULT WINAPI
IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream
* iface
, IUnknown
* pStreamObject
, const MSPID
* PurposeId
,
252 DWORD dwFlags
, IMediaStream
** ppNewStream
)
254 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
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
);
264 pNewStreams
= (IMediaStream
**)CoTaskMemAlloc((This
->nbStreams
+1)*sizeof(IMediaStream
*));
267 IMediaStream_Release(pStream
);
268 return E_OUTOFMEMORY
;
271 CopyMemory(pNewStreams
, This
->pStreams
, This
->nbStreams
*sizeof(IMediaStream
*));
272 CoTaskMemFree(This
->pStreams
);
273 This
->pStreams
= pNewStreams
;
274 This
->pStreams
[This
->nbStreams
] = pStream
;
278 *ppNewStream
= pStream
;
284 static HRESULT WINAPI
IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream
* iface
, LPCWSTR pszFileName
, DWORD dwFlags
)
287 IAMMultiMediaStreamImpl
*This
= (IAMMultiMediaStreamImpl
*)iface
;
288 IFileSourceFilter
*SourceFilter
;
289 IBaseFilter
*BaseFilter
;
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
);
300 ret
= IFileSourceFilter_Load(SourceFilter
, pszFileName
, NULL
);
303 IFileSourceFilter_Release(SourceFilter
);
307 ret
= IFileSourceFilter_QueryInterface(SourceFilter
, &IID_IBaseFilter
, (void**)&BaseFilter
);
310 IFileSourceFilter_Release(SourceFilter
);
314 ret
= IBaseFilter_EnumPins(BaseFilter
, &EnumPins
);
320 ret
= IEnumPins_Next(EnumPins
, 1, &ipin
, NULL
);
323 ret
= IPin_QueryDirection(ipin
, &pin_direction
);
324 IEnumPins_Release(EnumPins
);
325 if(ret
== S_OK
&& pin_direction
== PINDIR_OUTPUT
)
332 IEnumPins_Release(EnumPins
);
336 ret
= IFilterGraph_QueryInterface(This
->pFilterGraph
, &IID_IGraphBuilder
, (void**)&This
->GraphBuilder
);
342 ret
= IGraphBuilder_AddSourceFilter(This
->GraphBuilder
, pszFileName
, pszFileName
, &BaseFilter
);
344 IBaseFilter_Release(BaseFilter
);
345 IFileSourceFilter_Release(SourceFilter
);
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
);
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
)
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