mshtml: Wine Gecko 1.5 release.
[wine/multimedia.git] / dlls / amstream / amstream.c
blobc771f774ac3556dd4425b9d9cba736c212fe2279
1 /*
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"
24 #define COBJMACROS
26 #include "winbase.h"
27 #include "wingdi.h"
29 #include "amstream_private.h"
30 #include "amstream.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
34 typedef struct {
35 IAMMultiMediaStream IAMMultiMediaStream_iface;
36 LONG ref;
37 IGraphBuilder* pFilterGraph;
38 IPin* ipin;
39 ULONG nbStreams;
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);
57 if( pUnkOuter )
58 return CLASS_E_NOAGGREGATION;
60 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAMMultiMediaStreamImpl));
61 if (!object)
63 ERR("Out of memory\n");
64 return E_OUTOFMEMORY;
67 object->IAMMultiMediaStream_iface.lpVtbl = &AM_Vtbl;
68 object->ref = 1;
70 *ppObj = object;
72 return S_OK;
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);
87 *ppvObject = This;
88 return S_OK;
91 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
93 return E_NOINTERFACE;
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);
109 ULONG i;
111 TRACE("(%p/%p)\n", iface, This);
113 if (!ref)
115 for(i = 0; i < This->nbStreams; i++)
116 IMediaStream_Release(This->pStreams[i]);
117 if (This->ipin)
118 IPin_Release(This->ipin);
119 if (This->pFilterGraph)
120 IGraphBuilder_Release(This->pFilterGraph);
121 HeapFree(GetProcessHeap(), 0, This);
124 return ref;
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);
134 return E_NOTIMPL;
137 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream* iface, REFMSPID idPurpose, IMediaStream** ppMediaStream)
139 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
140 MSPID PurposeId;
141 unsigned int i;
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);
152 return S_OK;
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);
165 return E_NOTIMPL;
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);
174 return E_NOTIMPL;
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);
183 return E_NOTIMPL;
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);
192 return E_NOTIMPL;
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);
201 return E_NOTIMPL;
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);
210 return E_NOTIMPL;
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);
219 return E_NOTIMPL;
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);
226 HRESULT hr = S_OK;
228 TRACE("(%p/%p)->(%x,%x,%p)\n", This, iface, (DWORD)StreamType, dwFlags, pFilterGraph);
230 if (pFilterGraph)
232 This->pFilterGraph = pFilterGraph;
233 IGraphBuilder_AddRef(This->pFilterGraph);
235 else
237 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&This->pFilterGraph);
240 if (SUCCEEDED(hr))
242 This->StreamType = StreamType;
245 return hr;
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);
254 if (!ppGraphBuilder)
255 return E_POINTER;
257 if (This->pFilterGraph)
258 return IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)ppGraphBuilder);
259 else
260 *ppGraphBuilder = NULL;
262 return S_OK;
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);
271 return E_NOTIMPL;
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);
278 HRESULT hr;
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);
285 if (SUCCEEDED(hr))
287 pNewStreams = CoTaskMemRealloc(This->pStreams, (This->nbStreams+1) * sizeof(IMediaStream*));
288 if (!pNewStreams)
290 IMediaStream_Release(pStream);
291 return E_OUTOFMEMORY;
293 This->pStreams = pNewStreams;
294 This->pStreams[This->nbStreams] = pStream;
295 This->nbStreams++;
297 if (ppNewStream)
298 *ppNewStream = pStream;
301 return hr;
304 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream* iface, LPCWSTR pszFileName, DWORD dwFlags)
306 HRESULT ret;
307 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
308 IFileSourceFilter *SourceFilter;
309 IBaseFilter *BaseFilter;
310 IEnumPins *EnumPins;
311 IPin *ipin;
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);
320 if (FAILED(ret))
321 return ret;
324 ret = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSourceFilter, (void**)&SourceFilter);
325 if(ret != S_OK)
326 return ret;
328 ret = IGraphBuilder_AddSourceFilter(This->pFilterGraph, pszFileName, pszFileName, &BaseFilter);
329 if (FAILED(ret))
330 goto end;
332 ret = IFileSourceFilter_Load(SourceFilter, pszFileName, NULL);
333 if(ret != S_OK)
335 IFileSourceFilter_Release(SourceFilter);
336 return ret;
339 ret = IFileSourceFilter_QueryInterface(SourceFilter, &IID_IBaseFilter, (void**)&BaseFilter);
340 if(ret != S_OK)
342 IFileSourceFilter_Release(SourceFilter);
343 return ret;
346 ret = IBaseFilter_EnumPins(BaseFilter, &EnumPins);
347 if(ret != S_OK)
349 goto end;
352 ret = IEnumPins_Next(EnumPins, 1, &ipin, NULL);
353 if (ret == S_OK)
355 ret = IPin_QueryDirection(ipin, &pin_direction);
356 IEnumPins_Release(EnumPins);
357 if (ret == S_OK && pin_direction == PINDIR_OUTPUT)
358 This->ipin = ipin;
360 else
362 IEnumPins_Release(EnumPins);
365 end:
366 IBaseFilter_Release(BaseFilter);
367 IFileSourceFilter_Release(SourceFilter);
368 return ret;
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);
377 return E_NOTIMPL;
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)
387 return E_INVALIDARG;
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