2 * Implementation of MediaStream Filter
4 * Copyright 2008, 2012 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/debug.h"
29 #include "wine/strmbase.h"
31 #include "amstream_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(amstream
);
40 IAMMediaStream
** streams
;
41 } IMediaStreamFilterImpl
;
43 static inline IMediaStreamFilterImpl
*impl_from_IMediaStreamFilter(IMediaStreamFilter
*iface
)
45 return CONTAINING_RECORD(iface
, IMediaStreamFilterImpl
, filter
);
48 /*** IUnknown methods ***/
50 static HRESULT WINAPI
MediaStreamFilterImpl_QueryInterface(IMediaStreamFilter
*iface
, REFIID riid
, void **ret_iface
)
52 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ret_iface
);
56 if (IsEqualIID(riid
, &IID_IUnknown
) ||
57 IsEqualIID(riid
, &IID_IPersist
) ||
58 IsEqualIID(riid
, &IID_IMediaFilter
) ||
59 IsEqualIID(riid
, &IID_IBaseFilter
) ||
60 IsEqualIID(riid
, &IID_IMediaStreamFilter
))
65 IMediaStreamFilter_AddRef(*ret_iface
);
72 static ULONG WINAPI
MediaStreamFilterImpl_AddRef(IMediaStreamFilter
*iface
)
74 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
75 ULONG ref
= BaseFilterImpl_AddRef(&This
->filter
.IBaseFilter_iface
);
77 TRACE("(%p)->(): new ref = %u\n", iface
, ref
);
82 static ULONG WINAPI
MediaStreamFilterImpl_Release(IMediaStreamFilter
*iface
)
84 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
85 ULONG ref
= InterlockedDecrement(&This
->filter
.refCount
);
87 TRACE("(%p)->(): new ref = %u\n", iface
, ref
);
92 for (i
= 0; i
< This
->nb_streams
; i
++)
94 IAMMediaStream_JoinFilter(This
->streams
[i
], NULL
);
95 IAMMediaStream_Release(This
->streams
[i
]);
97 CoTaskMemFree(This
->streams
);
98 BaseFilter_Destroy(&This
->filter
);
99 HeapFree(GetProcessHeap(), 0, This
);
105 /*** IPersist methods ***/
107 static HRESULT WINAPI
MediaStreamFilterImpl_GetClassID(IMediaStreamFilter
*iface
, CLSID
*clsid
)
109 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
110 return BaseFilterImpl_GetClassID(&This
->filter
.IBaseFilter_iface
, clsid
);
113 /*** IBaseFilter methods ***/
115 static HRESULT WINAPI
MediaStreamFilterImpl_Stop(IMediaStreamFilter
*iface
)
117 FIXME("(%p)->(): Stub!\n", iface
);
122 static HRESULT WINAPI
MediaStreamFilterImpl_Pause(IMediaStreamFilter
*iface
)
124 FIXME("(%p)->(): Stub!\n", iface
);
129 static HRESULT WINAPI
MediaStreamFilterImpl_Run(IMediaStreamFilter
*iface
, REFERENCE_TIME start
)
131 FIXME("(%p)->(%s): Stub!\n", iface
, wine_dbgstr_longlong(start
));
136 static HRESULT WINAPI
MediaStreamFilterImpl_GetState(IMediaStreamFilter
*iface
, DWORD ms_timeout
, FILTER_STATE
*state
)
138 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
139 return BaseFilterImpl_GetState(&This
->filter
.IBaseFilter_iface
, ms_timeout
, state
);
142 static HRESULT WINAPI
MediaStreamFilterImpl_SetSyncSource(IMediaStreamFilter
*iface
, IReferenceClock
*clock
)
144 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
145 return BaseFilterImpl_SetSyncSource(&This
->filter
.IBaseFilter_iface
, clock
);
148 static HRESULT WINAPI
MediaStreamFilterImpl_GetSyncSource(IMediaStreamFilter
*iface
, IReferenceClock
**clock
)
150 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
151 return BaseFilterImpl_GetSyncSource(&This
->filter
.IBaseFilter_iface
, clock
);
154 static HRESULT WINAPI
MediaStreamFilterImpl_EnumPins(IMediaStreamFilter
*iface
, IEnumPins
**enum_pins
)
156 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
157 return BaseFilterImpl_EnumPins(&This
->filter
.IBaseFilter_iface
, enum_pins
);
160 static HRESULT WINAPI
MediaStreamFilterImpl_FindPin(IMediaStreamFilter
*iface
, LPCWSTR id
, IPin
**pin
)
162 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
163 return BaseFilterImpl_FindPin(&This
->filter
.IBaseFilter_iface
, id
, pin
);
166 static HRESULT WINAPI
MediaStreamFilterImpl_QueryFilterInfo(IMediaStreamFilter
*iface
, FILTER_INFO
*info
)
168 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
169 return BaseFilterImpl_QueryFilterInfo(&This
->filter
.IBaseFilter_iface
, info
);
172 static HRESULT WINAPI
MediaStreamFilterImpl_JoinFilterGraph(IMediaStreamFilter
*iface
, IFilterGraph
*graph
, LPCWSTR name
)
174 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
175 return BaseFilterImpl_JoinFilterGraph(&This
->filter
.IBaseFilter_iface
, graph
, name
);
178 static HRESULT WINAPI
MediaStreamFilterImpl_QueryVendorInfo(IMediaStreamFilter
*iface
, LPWSTR
*vendor_info
)
180 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
181 return BaseFilterImpl_QueryVendorInfo(&This
->filter
.IBaseFilter_iface
, vendor_info
);
184 /*** IMediaStreamFilter methods ***/
186 static HRESULT WINAPI
MediaStreamFilterImpl_AddMediaStream(IMediaStreamFilter
* iface
, IAMMediaStream
*pAMMediaStream
)
188 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
189 IAMMediaStream
** streams
;
192 TRACE("(%p)->(%p)\n", iface
, pAMMediaStream
);
194 streams
= CoTaskMemRealloc(This
->streams
, (This
->nb_streams
+ 1) * sizeof(IAMMediaStream
*));
196 return E_OUTOFMEMORY
;
197 This
->streams
= streams
;
199 hr
= IAMMediaStream_JoinFilter(pAMMediaStream
, iface
);
203 This
->streams
[This
->nb_streams
] = pAMMediaStream
;
206 IAMMediaStream_AddRef(pAMMediaStream
);
211 static HRESULT WINAPI
MediaStreamFilterImpl_GetMediaStream(IMediaStreamFilter
* iface
, REFMSPID idPurpose
, IMediaStream
**ppMediaStream
)
213 IMediaStreamFilterImpl
*This
= impl_from_IMediaStreamFilter(iface
);
217 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(idPurpose
), ppMediaStream
);
219 for (i
= 0; i
< This
->nb_streams
; i
++)
221 IAMMediaStream_GetInformation(This
->streams
[i
], &purpose_id
, NULL
);
222 if (IsEqualIID(&purpose_id
, idPurpose
))
224 *ppMediaStream
= (IMediaStream
*)This
->streams
[i
];
225 IMediaStream_AddRef(*ppMediaStream
);
230 return MS_E_NOSTREAM
;
233 static HRESULT WINAPI
MediaStreamFilterImpl_EnumMediaStreams(IMediaStreamFilter
* iface
, LONG Index
, IMediaStream
**ppMediaStream
)
235 FIXME("(%p)->(%d,%p): Stub!\n", iface
, Index
, ppMediaStream
);
240 static HRESULT WINAPI
MediaStreamFilterImpl_SupportSeeking(IMediaStreamFilter
* iface
, BOOL bRenderer
)
242 FIXME("(%p)->(%d): Stub!\n", iface
, bRenderer
);
247 static HRESULT WINAPI
MediaStreamFilterImpl_ReferenceTimeToStreamTime(IMediaStreamFilter
* iface
, REFERENCE_TIME
*pTime
)
249 FIXME("(%p)->(%p): Stub!\n", iface
, pTime
);
254 static HRESULT WINAPI
MediaStreamFilterImpl_GetCurrentStreamTime(IMediaStreamFilter
* iface
, REFERENCE_TIME
*pCurrentStreamTime
)
256 FIXME("(%p)->(%p): Stub!\n", iface
, pCurrentStreamTime
);
261 static HRESULT WINAPI
MediaStreamFilterImpl_WaitUntil(IMediaStreamFilter
* iface
, REFERENCE_TIME WaitStreamTime
)
263 FIXME("(%p)->(%s): Stub!\n", iface
, wine_dbgstr_longlong(WaitStreamTime
));
268 static HRESULT WINAPI
MediaStreamFilterImpl_Flush(IMediaStreamFilter
* iface
, BOOL bCancelEOS
)
270 FIXME("(%p)->(%d): Stub!\n", iface
, bCancelEOS
);
275 static HRESULT WINAPI
MediaStreamFilterImpl_EndOfStream(IMediaStreamFilter
* iface
)
277 FIXME("(%p)->(): Stub!\n", iface
);
282 static const IMediaStreamFilterVtbl MediaStreamFilter_Vtbl
=
284 MediaStreamFilterImpl_QueryInterface
,
285 MediaStreamFilterImpl_AddRef
,
286 MediaStreamFilterImpl_Release
,
287 MediaStreamFilterImpl_GetClassID
,
288 MediaStreamFilterImpl_Stop
,
289 MediaStreamFilterImpl_Pause
,
290 MediaStreamFilterImpl_Run
,
291 MediaStreamFilterImpl_GetState
,
292 MediaStreamFilterImpl_SetSyncSource
,
293 MediaStreamFilterImpl_GetSyncSource
,
294 MediaStreamFilterImpl_EnumPins
,
295 MediaStreamFilterImpl_FindPin
,
296 MediaStreamFilterImpl_QueryFilterInfo
,
297 MediaStreamFilterImpl_JoinFilterGraph
,
298 MediaStreamFilterImpl_QueryVendorInfo
,
299 MediaStreamFilterImpl_AddMediaStream
,
300 MediaStreamFilterImpl_GetMediaStream
,
301 MediaStreamFilterImpl_EnumMediaStreams
,
302 MediaStreamFilterImpl_SupportSeeking
,
303 MediaStreamFilterImpl_ReferenceTimeToStreamTime
,
304 MediaStreamFilterImpl_GetCurrentStreamTime
,
305 MediaStreamFilterImpl_WaitUntil
,
306 MediaStreamFilterImpl_Flush
,
307 MediaStreamFilterImpl_EndOfStream
310 static IPin
* WINAPI
MediaStreamFilterImpl_GetPin(BaseFilter
*iface
, int pos
)
312 IMediaStreamFilterImpl
* This
= (IMediaStreamFilterImpl
*)iface
;
314 if (pos
< This
->nb_streams
)
317 IAMMediaStream_QueryInterface(This
->streams
[pos
], &IID_IPin
, (void **)&pin
);
324 static LONG WINAPI
MediaStreamFilterImpl_GetPinCount(BaseFilter
*iface
)
326 IMediaStreamFilterImpl
* This
= (IMediaStreamFilterImpl
*)iface
;
328 return This
->nb_streams
;
331 static const BaseFilterFuncTable BaseFuncTable
= {
332 MediaStreamFilterImpl_GetPin
,
333 MediaStreamFilterImpl_GetPinCount
336 HRESULT
MediaStreamFilter_create(IUnknown
*pUnkOuter
, void **ppObj
)
338 IMediaStreamFilterImpl
* object
;
340 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
343 return CLASS_E_NOAGGREGATION
;
345 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IMediaStreamFilterImpl
));
347 return E_OUTOFMEMORY
;
349 BaseFilter_Init(&object
->filter
, (IBaseFilterVtbl
*)&MediaStreamFilter_Vtbl
, &CLSID_MediaStreamFilter
, (DWORD_PTR
)(__FILE__
": MediaStreamFilterImpl.csFilter"), &BaseFuncTable
);
351 *ppObj
= &object
->filter
.IBaseFilter_iface
;