po: Update Korean translation.
[wine/multimedia.git] / dlls / amstream / amstream.c
blobfe214690805602cd7e1899c7c9d69106509d187a
1 /*
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"
27 #define COBJMACROS
29 #include "winbase.h"
30 #include "wingdi.h"
32 #include "amstream_private.h"
33 #include "amstream.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(amstream);
37 typedef struct {
38 IAMMultiMediaStream IAMMultiMediaStream_iface;
39 LONG ref;
40 IGraphBuilder* pFilterGraph;
41 IPin* ipin;
42 IGraphBuilder* GraphBuilder;
43 ULONG nbStreams;
44 IMediaStream** pStreams;
45 STREAM_TYPE StreamType;
46 } IAMMultiMediaStreamImpl;
48 static inline IAMMultiMediaStreamImpl *impl_from_IAMMultiMediaStream(IAMMultiMediaStream *iface)
50 return CONTAINING_RECORD(iface, IAMMultiMediaStreamImpl, IAMMultiMediaStream_iface);
53 static const struct IAMMultiMediaStreamVtbl AM_Vtbl;
55 HRESULT AM_create(IUnknown *pUnkOuter, LPVOID *ppObj)
57 IAMMultiMediaStreamImpl* object;
59 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
61 if( pUnkOuter )
62 return CLASS_E_NOAGGREGATION;
64 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAMMultiMediaStreamImpl));
65 if (!object)
67 ERR("Out of memory\n");
68 return E_OUTOFMEMORY;
71 object->IAMMultiMediaStream_iface.lpVtbl = &AM_Vtbl;
72 object->ref = 1;
74 *ppObj = object;
76 return S_OK;
79 /*** IUnknown methods ***/
80 static HRESULT WINAPI IAMMultiMediaStreamImpl_QueryInterface(IAMMultiMediaStream* iface, REFIID riid, void** ppvObject)
82 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
84 TRACE("(%p/%p)->(%s,%p)\n", iface, This, debugstr_guid(riid), ppvObject);
86 if (IsEqualGUID(riid, &IID_IUnknown) ||
87 IsEqualGUID(riid, &IID_IMultiMediaStream) ||
88 IsEqualGUID(riid, &IID_IAMMultiMediaStream))
90 IUnknown_AddRef(iface);
91 *ppvObject = This;
92 return S_OK;
95 ERR("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
97 return E_NOINTERFACE;
100 static ULONG WINAPI IAMMultiMediaStreamImpl_AddRef(IAMMultiMediaStream* iface)
102 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
104 TRACE("(%p/%p)\n", iface, This);
106 return InterlockedIncrement(&This->ref);
109 static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface)
111 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
112 ULONG ref = InterlockedDecrement(&This->ref);
114 TRACE("(%p/%p)\n", iface, This);
116 if (!ref)
117 HeapFree(GetProcessHeap(), 0, This);
119 return ref;
122 /*** IMultiMediaStream methods ***/
123 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetInformation(IAMMultiMediaStream* iface, DWORD* pdwFlags, STREAM_TYPE* pStreamType)
125 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
127 FIXME("(%p/%p)->(%p,%p) stub!\n", This, iface, pdwFlags, pStreamType);
129 return E_NOTIMPL;
132 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetMediaStream(IAMMultiMediaStream* iface, REFMSPID idPurpose, IMediaStream** ppMediaStream)
134 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
135 MSPID PurposeId;
136 unsigned int i;
138 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(idPurpose), ppMediaStream);
140 for (i = 0; i < This->nbStreams; i++)
142 IMediaStream_GetInformation(This->pStreams[i], &PurposeId, NULL);
143 if (IsEqualIID(&PurposeId, idPurpose))
145 *ppMediaStream = This->pStreams[i];
146 IMediaStream_AddRef(*ppMediaStream);
147 return S_OK;
151 return MS_E_NOSTREAM;
154 static HRESULT WINAPI IAMMultiMediaStreamImpl_EnumMediaStreams(IAMMultiMediaStream* iface, LONG Index, IMediaStream** ppMediaStream)
156 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
158 FIXME("(%p/%p)->(%d,%p) stub!\n", This, iface, Index, ppMediaStream);
160 return E_NOTIMPL;
163 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetState(IAMMultiMediaStream* iface, STREAM_STATE* pCurrentState)
165 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
167 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentState);
169 return E_NOTIMPL;
172 static HRESULT WINAPI IAMMultiMediaStreamImpl_SetState(IAMMultiMediaStream* iface, STREAM_STATE NewState)
174 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
176 FIXME("(%p/%p)->() stub!\n", This, iface);
178 return E_NOTIMPL;
181 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetTime(IAMMultiMediaStream* iface, STREAM_TIME* pCurrentTime)
183 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
185 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pCurrentTime);
187 return E_NOTIMPL;
190 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetDuration(IAMMultiMediaStream* iface, STREAM_TIME* pDuration)
192 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
194 FIXME("(%p/%p)->(%p) stub!\n", This, iface, pDuration);
196 return E_NOTIMPL;
199 static HRESULT WINAPI IAMMultiMediaStreamImpl_Seek(IAMMultiMediaStream* iface, STREAM_TIME SeekTime)
201 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
203 FIXME("(%p/%p)->() stub!\n", This, iface);
205 return E_NOTIMPL;
208 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetEndOfStream(IAMMultiMediaStream* iface, HANDLE* phEOS)
210 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
212 FIXME("(%p/%p)->(%p) stub!\n", This, iface, phEOS);
214 return E_NOTIMPL;
217 /*** IAMMultiMediaStream methods ***/
218 static HRESULT WINAPI IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream* iface, STREAM_TYPE StreamType, DWORD dwFlags, IGraphBuilder* pFilterGraph)
220 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
221 HRESULT hr = S_OK;
223 TRACE("(%p/%p)->(%x,%x,%p)\n", This, iface, (DWORD)StreamType, dwFlags, pFilterGraph);
225 if (pFilterGraph)
227 This->pFilterGraph = pFilterGraph;
228 IGraphBuilder_AddRef(This->pFilterGraph);
230 else
232 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&This->pFilterGraph);
235 if (SUCCEEDED(hr))
237 This->StreamType = StreamType;
240 return hr;
243 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilterGraph(IAMMultiMediaStream* iface, IGraphBuilder** ppGraphBuilder)
245 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
247 TRACE("(%p/%p)->(%p)\n", This, iface, ppGraphBuilder);
249 if (!ppGraphBuilder)
250 return E_POINTER;
252 if (This->pFilterGraph)
253 return IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)ppGraphBuilder);
254 else
255 *ppGraphBuilder = NULL;
257 return S_OK;
260 static HRESULT WINAPI IAMMultiMediaStreamImpl_GetFilter(IAMMultiMediaStream* iface, IMediaStreamFilter** ppFilter)
262 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
264 FIXME("(%p/%p)->(%p) stub!\n", This, iface, ppFilter);
266 return E_NOTIMPL;
269 static HRESULT WINAPI IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream* iface, IUnknown* pStreamObject, const MSPID* PurposeId,
270 DWORD dwFlags, IMediaStream** ppNewStream)
272 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
273 HRESULT hr;
274 IMediaStream* pStream;
275 IMediaStream** pNewStreams;
277 FIXME("(%p/%p)->(%p,%s,%x,%p) partial stub!\n", This, iface, pStreamObject, debugstr_guid(PurposeId), dwFlags, ppNewStream);
279 if (IsEqualGUID(PurposeId, &MSPID_PrimaryVideo))
280 hr = DirectDrawMediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
281 else
282 hr = MediaStream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
284 if (SUCCEEDED(hr))
286 pNewStreams = CoTaskMemAlloc((This->nbStreams+1)*sizeof(IMediaStream*));
287 if (!pNewStreams)
289 IMediaStream_Release(pStream);
290 return E_OUTOFMEMORY;
292 if (This->nbStreams)
293 CopyMemory(pNewStreams, This->pStreams, This->nbStreams*sizeof(IMediaStream*));
294 CoTaskMemFree(This->pStreams);
295 This->pStreams = pNewStreams;
296 This->pStreams[This->nbStreams] = pStream;
297 This->nbStreams++;
299 if (ppNewStream)
300 *ppNewStream = pStream;
303 return hr;
306 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenFile(IAMMultiMediaStream* iface, LPCWSTR pszFileName, DWORD dwFlags)
308 HRESULT ret;
309 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
310 IFileSourceFilter *SourceFilter;
311 IBaseFilter *BaseFilter;
312 IEnumPins *EnumPins;
313 IPin *ipin;
314 PIN_DIRECTION pin_direction;
316 TRACE("(%p/%p)->(%s,%x)\n", This, iface, debugstr_w(pszFileName), dwFlags);
318 ret = CoCreateInstance(&CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSourceFilter, (void**)&SourceFilter);
319 if(ret != S_OK)
320 return ret;
322 ret = IFileSourceFilter_Load(SourceFilter, pszFileName, NULL);
323 if(ret != S_OK)
325 IFileSourceFilter_Release(SourceFilter);
326 return ret;
329 ret = IFileSourceFilter_QueryInterface(SourceFilter, &IID_IBaseFilter, (void**)&BaseFilter);
330 if(ret != S_OK)
332 IFileSourceFilter_Release(SourceFilter);
333 return ret;
336 ret = IBaseFilter_EnumPins(BaseFilter, &EnumPins);
337 if(ret != S_OK)
339 goto end;
342 ret = IEnumPins_Next(EnumPins, 1, &ipin, NULL);
343 if(ret == S_OK)
345 ret = IPin_QueryDirection(ipin, &pin_direction);
346 IEnumPins_Release(EnumPins);
347 if(ret == S_OK && pin_direction == PINDIR_OUTPUT)
348 This->ipin = ipin;
349 else
350 goto end;
352 else
354 IEnumPins_Release(EnumPins);
355 goto end;
358 /* If Initialize was not called before, we do it here */
359 if (!This->pFilterGraph)
361 ret = IAMMultiMediaStream_Initialize(iface, STREAMTYPE_READ, 0, NULL);
362 if (FAILED(ret))
363 goto end;
366 ret = IFilterGraph_QueryInterface(This->pFilterGraph, &IID_IGraphBuilder, (void**)&This->GraphBuilder);
367 if(ret != S_OK)
369 goto end;
372 ret = IGraphBuilder_AddSourceFilter(This->GraphBuilder, pszFileName, pszFileName, &BaseFilter);
374 end:
375 IBaseFilter_Release(BaseFilter);
376 IFileSourceFilter_Release(SourceFilter);
377 return ret;
380 static HRESULT WINAPI IAMMultiMediaStreamImpl_OpenMoniker(IAMMultiMediaStream* iface, IBindCtx* pCtx, IMoniker* pMoniker, DWORD dwFlags)
382 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
384 FIXME("(%p/%p)->(%p,%p,%x) stub!\n", This, iface, pCtx, pMoniker, dwFlags);
386 return E_NOTIMPL;
389 static HRESULT WINAPI IAMMultiMediaStreamImpl_Render(IAMMultiMediaStream* iface, DWORD dwFlags)
391 IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
393 FIXME("(%p/%p)->(%x) partial stub!\n", This, iface, dwFlags);
395 if(dwFlags != AMMSF_NOCLOCK)
396 return E_INVALIDARG;
398 return IGraphBuilder_Render(This->GraphBuilder, This->ipin);
401 static const IAMMultiMediaStreamVtbl AM_Vtbl =
403 IAMMultiMediaStreamImpl_QueryInterface,
404 IAMMultiMediaStreamImpl_AddRef,
405 IAMMultiMediaStreamImpl_Release,
406 IAMMultiMediaStreamImpl_GetInformation,
407 IAMMultiMediaStreamImpl_GetMediaStream,
408 IAMMultiMediaStreamImpl_EnumMediaStreams,
409 IAMMultiMediaStreamImpl_GetState,
410 IAMMultiMediaStreamImpl_SetState,
411 IAMMultiMediaStreamImpl_GetTime,
412 IAMMultiMediaStreamImpl_GetDuration,
413 IAMMultiMediaStreamImpl_Seek,
414 IAMMultiMediaStreamImpl_GetEndOfStream,
415 IAMMultiMediaStreamImpl_Initialize,
416 IAMMultiMediaStreamImpl_GetFilterGraph,
417 IAMMultiMediaStreamImpl_GetFilter,
418 IAMMultiMediaStreamImpl_AddMediaStream,
419 IAMMultiMediaStreamImpl_OpenFile,
420 IAMMultiMediaStreamImpl_OpenMoniker,
421 IAMMultiMediaStreamImpl_Render