2 * Generic Implementation of strmbase video classes
4 * Copyright 2012 Aric Stewart, CodeWeavers
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
27 #include "wine/debug.h"
28 #include "wine/unicode.h"
29 #include "wine/strmbase.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(strmbase
);
33 static inline BaseControlVideo
*impl_from_IBasicVideo(IBasicVideo
*iface
)
35 return CONTAINING_RECORD(iface
, BaseControlVideo
, IBasicVideo_iface
);
38 HRESULT WINAPI
BaseControlVideo_Init(BaseControlVideo
*pControlVideo
, const IBasicVideoVtbl
*lpVtbl
, BaseFilter
*owner
, CRITICAL_SECTION
*lock
, BasePin
* pPin
, const BaseControlVideoFuncTable
* pFuncsTable
)
40 pControlVideo
->IBasicVideo_iface
.lpVtbl
= lpVtbl
;
41 pControlVideo
->pFilter
= owner
;
42 pControlVideo
->pInterfaceLock
= lock
;
43 pControlVideo
->pPin
= pPin
;
44 pControlVideo
->pFuncsTable
= pFuncsTable
;
46 BaseDispatch_Init(&pControlVideo
->baseDispatch
, &IID_IBasicVideo
);
51 HRESULT WINAPI
BaseControlVideo_Destroy(BaseControlVideo
*pControlVideo
)
53 return BaseDispatch_Destroy(&pControlVideo
->baseDispatch
);
56 static HRESULT
BaseControlVideoImpl_CheckSourceRect(BaseControlVideo
*This
, RECT
*pSourceRect
)
58 LONG VideoWidth
, VideoHeight
;
61 if (IsRectEmpty(pSourceRect
))
64 hr
= BaseControlVideoImpl_GetVideoSize((IBasicVideo
*)This
, &VideoWidth
, &VideoHeight
);
68 if (pSourceRect
->top
< 0 || pSourceRect
->left
< 0 ||
69 pSourceRect
->bottom
> VideoHeight
|| pSourceRect
->right
> VideoWidth
)
75 static HRESULT
BaseControlVideoImpl_CheckTargetRect(BaseControlVideo
*This
, RECT
*pTargetRect
)
77 if (IsRectEmpty(pTargetRect
))
83 HRESULT WINAPI
BaseControlVideoImpl_GetTypeInfoCount(IBasicVideo
*iface
, UINT
*pctinfo
)
85 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
87 return BaseDispatchImpl_GetTypeInfoCount(&This
->baseDispatch
, pctinfo
);
90 HRESULT WINAPI
BaseControlVideoImpl_GetTypeInfo(IBasicVideo
*iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
92 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
94 return BaseDispatchImpl_GetTypeInfo(&This
->baseDispatch
, &IID_NULL
, iTInfo
, lcid
, ppTInfo
);
97 HRESULT WINAPI
BaseControlVideoImpl_GetIDsOfNames(IBasicVideo
*iface
, REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
99 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
101 return BaseDispatchImpl_GetIDsOfNames(&This
->baseDispatch
, riid
, rgszNames
, cNames
, lcid
, rgDispId
);
104 HRESULT WINAPI
BaseControlVideoImpl_Invoke(IBasicVideo
*iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExepInfo
, UINT
*puArgErr
)
106 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
107 ITypeInfo
*pTypeInfo
;
110 hr
= BaseDispatchImpl_GetTypeInfo(&This
->baseDispatch
, riid
, 1, lcid
, &pTypeInfo
);
113 hr
= ITypeInfo_Invoke(pTypeInfo
, &This
->IBasicVideo_iface
, dispIdMember
, wFlags
, pDispParams
, pVarResult
, pExepInfo
, puArgErr
);
114 ITypeInfo_Release(pTypeInfo
);
120 HRESULT WINAPI
BaseControlVideoImpl_get_AvgTimePerFrame(IBasicVideo
*iface
, REFTIME
*pAvgTimePerFrame
)
122 VIDEOINFOHEADER
*vih
;
123 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
125 if (!pAvgTimePerFrame
)
127 if (!This
->pPin
->pConnectedTo
)
128 return VFW_E_NOT_CONNECTED
;
130 TRACE("(%p/%p)->(%p)\n", This
, iface
, pAvgTimePerFrame
);
132 vih
= This
->pFuncsTable
->pfnGetVideoFormat(This
);
133 *pAvgTimePerFrame
= vih
->AvgTimePerFrame
;
137 HRESULT WINAPI
BaseControlVideoImpl_get_BitRate(IBasicVideo
*iface
, LONG
*pBitRate
)
139 VIDEOINFOHEADER
*vih
;
140 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
142 TRACE("(%p/%p)->(%p)\n", This
, iface
, pBitRate
);
146 if (!This
->pPin
->pConnectedTo
)
147 return VFW_E_NOT_CONNECTED
;
149 vih
= This
->pFuncsTable
->pfnGetVideoFormat(This
);
150 *pBitRate
= vih
->dwBitRate
;
154 HRESULT WINAPI
BaseControlVideoImpl_get_BitErrorRate(IBasicVideo
*iface
, LONG
*pBitErrorRate
)
156 VIDEOINFOHEADER
*vih
;
157 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
159 TRACE("(%p/%p)->(%p)\n", This
, iface
, pBitErrorRate
);
163 if (!This
->pPin
->pConnectedTo
)
164 return VFW_E_NOT_CONNECTED
;
166 vih
= This
->pFuncsTable
->pfnGetVideoFormat(This
);
167 *pBitErrorRate
= vih
->dwBitErrorRate
;
171 HRESULT WINAPI
BaseControlVideoImpl_get_VideoWidth(IBasicVideo
*iface
, LONG
*pVideoWidth
)
173 VIDEOINFOHEADER
*vih
;
174 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
176 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVideoWidth
);
180 vih
= This
->pFuncsTable
->pfnGetVideoFormat(This
);
181 *pVideoWidth
= vih
->bmiHeader
.biWidth
;
186 HRESULT WINAPI
BaseControlVideoImpl_get_VideoHeight(IBasicVideo
*iface
, LONG
*pVideoHeight
)
188 VIDEOINFOHEADER
*vih
;
189 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
191 TRACE("(%p/%p)->(%p)\n", This
, iface
, pVideoHeight
);
195 vih
= This
->pFuncsTable
->pfnGetVideoFormat(This
);
196 *pVideoHeight
= abs(vih
->bmiHeader
.biHeight
);
201 HRESULT WINAPI
BaseControlVideoImpl_put_SourceLeft(IBasicVideo
*iface
, LONG SourceLeft
)
204 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
207 TRACE("(%p/%p)->(%d)\n", This
, iface
, SourceLeft
);
208 hr
= This
->pFuncsTable
->pfnGetSourceRect(This
, &SourceRect
);
211 SourceRect
.right
= (SourceRect
.right
- SourceRect
.left
) + SourceLeft
;
212 SourceRect
.left
= SourceLeft
;
213 hr
= BaseControlVideoImpl_CheckSourceRect(This
, &SourceRect
);
216 hr
= This
->pFuncsTable
->pfnSetSourceRect(This
, &SourceRect
);
221 HRESULT WINAPI
BaseControlVideoImpl_get_SourceLeft(IBasicVideo
*iface
, LONG
*pSourceLeft
)
224 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
226 TRACE("(%p/%p)->(%p)\n", This
, iface
, pSourceLeft
);
229 This
->pFuncsTable
->pfnGetSourceRect(This
, &SourceRect
);
230 *pSourceLeft
= SourceRect
.left
;
235 HRESULT WINAPI
BaseControlVideoImpl_put_SourceWidth(IBasicVideo
*iface
, LONG SourceWidth
)
238 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
241 TRACE("(%p/%p)->(%d)\n", This
, iface
, SourceWidth
);
242 hr
= This
->pFuncsTable
->pfnGetSourceRect(This
, &SourceRect
);
245 SourceRect
.right
= SourceRect
.left
+ SourceWidth
;
246 hr
= BaseControlVideoImpl_CheckSourceRect(This
, &SourceRect
);
249 hr
= This
->pFuncsTable
->pfnSetSourceRect(This
, &SourceRect
);
254 HRESULT WINAPI
BaseControlVideoImpl_get_SourceWidth(IBasicVideo
*iface
, LONG
*pSourceWidth
)
257 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
259 TRACE("(%p/%p)->(%p)\n", This
, iface
, pSourceWidth
);
262 This
->pFuncsTable
->pfnGetSourceRect(This
, &SourceRect
);
263 *pSourceWidth
= SourceRect
.right
- SourceRect
.left
;
268 HRESULT WINAPI
BaseControlVideoImpl_put_SourceTop(IBasicVideo
*iface
, LONG SourceTop
)
271 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
274 TRACE("(%p/%p)->(%d)\n", This
, iface
, SourceTop
);
275 hr
= This
->pFuncsTable
->pfnGetSourceRect(This
, &SourceRect
);
278 SourceRect
.bottom
= (SourceRect
.bottom
- SourceRect
.top
) + SourceTop
;
279 SourceRect
.top
= SourceTop
;
280 hr
= BaseControlVideoImpl_CheckSourceRect(This
, &SourceRect
);
283 hr
= This
->pFuncsTable
->pfnSetSourceRect(This
, &SourceRect
);
288 HRESULT WINAPI
BaseControlVideoImpl_get_SourceTop(IBasicVideo
*iface
, LONG
*pSourceTop
)
291 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
293 TRACE("(%p/%p)->(%p)\n", This
, iface
, pSourceTop
);
296 This
->pFuncsTable
->pfnGetSourceRect(This
, &SourceRect
);
297 *pSourceTop
= SourceRect
.top
;
302 HRESULT WINAPI
BaseControlVideoImpl_put_SourceHeight(IBasicVideo
*iface
, LONG SourceHeight
)
305 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
308 TRACE("(%p/%p)->(%d)\n", This
, iface
, SourceHeight
);
309 hr
= This
->pFuncsTable
->pfnGetSourceRect(This
, &SourceRect
);
312 SourceRect
.bottom
= SourceRect
.top
+ SourceHeight
;
313 hr
= BaseControlVideoImpl_CheckSourceRect(This
, &SourceRect
);
316 hr
= This
->pFuncsTable
->pfnSetSourceRect(This
, &SourceRect
);
321 HRESULT WINAPI
BaseControlVideoImpl_get_SourceHeight(IBasicVideo
*iface
, LONG
*pSourceHeight
)
324 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
326 TRACE("(%p/%p)->(%p)\n", This
, iface
, pSourceHeight
);
329 This
->pFuncsTable
->pfnGetSourceRect(This
, &SourceRect
);
331 *pSourceHeight
= SourceRect
.bottom
- SourceRect
.top
;
336 HRESULT WINAPI
BaseControlVideoImpl_put_DestinationLeft(IBasicVideo
*iface
, LONG DestinationLeft
)
339 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
342 TRACE("(%p/%p)->(%d)\n", This
, iface
, DestinationLeft
);
343 hr
= This
->pFuncsTable
->pfnGetTargetRect(This
, &DestRect
);
346 DestRect
.right
= (DestRect
.right
- DestRect
.left
) + DestinationLeft
;
347 DestRect
.left
= DestinationLeft
;
348 hr
= BaseControlVideoImpl_CheckTargetRect(This
, &DestRect
);
351 hr
= This
->pFuncsTable
->pfnSetTargetRect(This
, &DestRect
);
356 HRESULT WINAPI
BaseControlVideoImpl_get_DestinationLeft(IBasicVideo
*iface
, LONG
*pDestinationLeft
)
359 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
361 TRACE("(%p/%p)->(%p)\n", This
, iface
, pDestinationLeft
);
362 if (!pDestinationLeft
)
364 This
->pFuncsTable
->pfnGetTargetRect(This
, &DestRect
);
365 *pDestinationLeft
= DestRect
.left
;
370 HRESULT WINAPI
BaseControlVideoImpl_put_DestinationWidth(IBasicVideo
*iface
, LONG DestinationWidth
)
373 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
376 TRACE("(%p/%p)->(%d)\n", This
, iface
, DestinationWidth
);
377 hr
= This
->pFuncsTable
->pfnGetTargetRect(This
, &DestRect
);
380 DestRect
.right
= DestRect
.left
+ DestinationWidth
;
381 hr
= BaseControlVideoImpl_CheckTargetRect(This
, &DestRect
);
384 hr
= This
->pFuncsTable
->pfnSetTargetRect(This
, &DestRect
);
389 HRESULT WINAPI
BaseControlVideoImpl_get_DestinationWidth(IBasicVideo
*iface
, LONG
*pDestinationWidth
)
392 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
394 TRACE("(%p/%p)->(%p)\n", This
, iface
, pDestinationWidth
);
395 if (!pDestinationWidth
)
397 This
->pFuncsTable
->pfnGetTargetRect(This
, &DestRect
);
398 *pDestinationWidth
= DestRect
.right
- DestRect
.left
;
403 HRESULT WINAPI
BaseControlVideoImpl_put_DestinationTop(IBasicVideo
*iface
, LONG DestinationTop
)
406 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
409 TRACE("(%p/%p)->(%d)\n", This
, iface
, DestinationTop
);
410 hr
= This
->pFuncsTable
->pfnGetTargetRect(This
, &DestRect
);
413 DestRect
.bottom
= (DestRect
.bottom
- DestRect
.top
) + DestinationTop
;
414 DestRect
.top
= DestinationTop
;
415 hr
= BaseControlVideoImpl_CheckTargetRect(This
, &DestRect
);
418 hr
= This
->pFuncsTable
->pfnSetTargetRect(This
, &DestRect
);
423 HRESULT WINAPI
BaseControlVideoImpl_get_DestinationTop(IBasicVideo
*iface
, LONG
*pDestinationTop
)
426 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
428 TRACE("(%p/%p)->(%p)\n", This
, iface
, pDestinationTop
);
429 if (!pDestinationTop
)
431 This
->pFuncsTable
->pfnGetTargetRect(This
, &DestRect
);
432 *pDestinationTop
= DestRect
.top
;
437 HRESULT WINAPI
BaseControlVideoImpl_put_DestinationHeight(IBasicVideo
*iface
, LONG DestinationHeight
)
440 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
443 TRACE("(%p/%p)->(%d)\n", This
, iface
, DestinationHeight
);
444 hr
= This
->pFuncsTable
->pfnGetTargetRect(This
, &DestRect
);
447 DestRect
.bottom
= DestRect
.top
+ DestinationHeight
;
448 hr
= BaseControlVideoImpl_CheckTargetRect(This
, &DestRect
);
451 hr
= This
->pFuncsTable
->pfnSetTargetRect(This
, &DestRect
);
456 HRESULT WINAPI
BaseControlVideoImpl_get_DestinationHeight(IBasicVideo
*iface
, LONG
*pDestinationHeight
)
459 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
461 TRACE("(%p/%p)->(%p)\n", This
, iface
, pDestinationHeight
);
462 if (!pDestinationHeight
)
464 This
->pFuncsTable
->pfnGetTargetRect(This
, &DestRect
);
465 *pDestinationHeight
= DestRect
.bottom
- DestRect
.top
;
470 HRESULT WINAPI
BaseControlVideoImpl_SetSourcePosition(IBasicVideo
*iface
, LONG Left
, LONG Top
, LONG Width
, LONG Height
)
473 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
475 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This
, iface
, Left
, Top
, Width
, Height
);
477 SetRect(&SourceRect
, Left
, Top
, Left
+ Width
, Top
+ Height
);
478 if (FAILED(BaseControlVideoImpl_CheckSourceRect(This
, &SourceRect
)))
480 return This
->pFuncsTable
->pfnSetSourceRect(This
, &SourceRect
);
483 HRESULT WINAPI
BaseControlVideoImpl_GetSourcePosition(IBasicVideo
*iface
, LONG
*pLeft
, LONG
*pTop
, LONG
*pWidth
, LONG
*pHeight
)
486 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
488 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This
, iface
, pLeft
, pTop
, pWidth
, pHeight
);
489 if (!pLeft
|| !pTop
|| !pWidth
|| !pHeight
)
491 This
->pFuncsTable
->pfnGetSourceRect(This
, &SourceRect
);
493 *pLeft
= SourceRect
.left
;
494 *pTop
= SourceRect
.top
;
495 *pWidth
= SourceRect
.right
- SourceRect
.left
;
496 *pHeight
= SourceRect
.bottom
- SourceRect
.top
;
501 HRESULT WINAPI
BaseControlVideoImpl_SetDefaultSourcePosition(IBasicVideo
*iface
)
503 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
505 TRACE("(%p/%p)->()\n", This
, iface
);
506 return This
->pFuncsTable
->pfnSetDefaultSourceRect(This
);
509 HRESULT WINAPI
BaseControlVideoImpl_SetDestinationPosition(IBasicVideo
*iface
, LONG Left
, LONG Top
, LONG Width
, LONG Height
)
512 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
514 TRACE("(%p/%p)->(%d, %d, %d, %d)\n", This
, iface
, Left
, Top
, Width
, Height
);
516 SetRect(&DestRect
, Left
, Top
, Left
+ Width
, Top
+ Height
);
517 if (FAILED(BaseControlVideoImpl_CheckTargetRect(This
, &DestRect
)))
519 return This
->pFuncsTable
->pfnSetTargetRect(This
, &DestRect
);
522 HRESULT WINAPI
BaseControlVideoImpl_GetDestinationPosition(IBasicVideo
*iface
, LONG
*pLeft
, LONG
*pTop
, LONG
*pWidth
, LONG
*pHeight
)
525 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
527 TRACE("(%p/%p)->(%p, %p, %p, %p)\n", This
, iface
, pLeft
, pTop
, pWidth
, pHeight
);
528 if (!pLeft
|| !pTop
|| !pWidth
|| !pHeight
)
530 This
->pFuncsTable
->pfnGetTargetRect(This
, &DestRect
);
532 *pLeft
= DestRect
.left
;
533 *pTop
= DestRect
.top
;
534 *pWidth
= DestRect
.right
- DestRect
.left
;
535 *pHeight
= DestRect
.bottom
- DestRect
.top
;
540 HRESULT WINAPI
BaseControlVideoImpl_SetDefaultDestinationPosition(IBasicVideo
*iface
)
542 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
544 TRACE("(%p/%p)->()\n", This
, iface
);
545 return This
->pFuncsTable
->pfnSetDefaultTargetRect(This
);
548 HRESULT WINAPI
BaseControlVideoImpl_GetVideoSize(IBasicVideo
*iface
, LONG
*pWidth
, LONG
*pHeight
)
550 VIDEOINFOHEADER
*vih
;
551 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
553 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, pWidth
, pHeight
);
554 if (!pWidth
|| !pHeight
)
557 vih
= This
->pFuncsTable
->pfnGetVideoFormat(This
);
558 *pHeight
= vih
->bmiHeader
.biHeight
;
559 *pWidth
= vih
->bmiHeader
.biWidth
;
564 HRESULT WINAPI
BaseControlVideoImpl_GetVideoPaletteEntries(IBasicVideo
*iface
, LONG StartIndex
, LONG Entries
, LONG
*pRetrieved
, LONG
*pPalette
)
566 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
568 TRACE("(%p/%p)->(%d, %d, %p, %p)\n", This
, iface
, StartIndex
, Entries
, pRetrieved
, pPalette
);
569 if (!pRetrieved
|| !pPalette
)
573 return VFW_E_NO_PALETTE_AVAILABLE
;
576 HRESULT WINAPI
BaseControlVideoImpl_GetCurrentImage(IBasicVideo
*iface
, LONG
*pBufferSize
, LONG
*pDIBImage
)
578 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
579 if (!pBufferSize
|| !pDIBImage
)
582 return This
->pFuncsTable
->pfnGetStaticImage(This
, pBufferSize
, pDIBImage
);
585 HRESULT WINAPI
BaseControlVideoImpl_IsUsingDefaultSource(IBasicVideo
*iface
)
587 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
589 return This
->pFuncsTable
->pfnIsDefaultSourceRect(This
);
592 HRESULT WINAPI
BaseControlVideoImpl_IsUsingDefaultDestination(IBasicVideo
*iface
)
594 BaseControlVideo
*This
= impl_from_IBasicVideo(iface
);
596 return This
->pFuncsTable
->pfnIsDefaultTargetRect(This
);