msvcrt: _difftime64() takes 64-bit args.
[wine.git] / dlls / qcap / avico.c
blob0287271fbc81ed00d8d820847831b030ce146d3b
1 /*
2 * Copyright 2013 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "dshow.h"
26 #include "vfw.h"
27 #include "aviriff.h"
29 #include "qcap_main.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(qcap);
35 typedef struct {
36 BaseFilter filter;
37 IPersistPropertyBag IPersistPropertyBag_iface;
39 BaseInputPin *in;
40 BaseOutputPin *out;
42 DWORD fcc_handler;
43 HIC hic;
45 VIDEOINFOHEADER *videoinfo;
46 size_t videoinfo_size;
47 DWORD driver_flags;
48 DWORD max_frame_size;
50 DWORD frame_cnt;
51 } AVICompressor;
53 static inline AVICompressor *impl_from_BaseFilter(BaseFilter *filter)
55 return CONTAINING_RECORD(filter, AVICompressor, filter);
58 static inline AVICompressor *impl_from_IBaseFilter(IBaseFilter *iface)
60 BaseFilter *filter = CONTAINING_RECORD(iface, BaseFilter, IBaseFilter_iface);
61 return impl_from_BaseFilter(filter);
64 static inline AVICompressor *impl_from_BasePin(BasePin *pin)
66 return impl_from_IBaseFilter(pin->pinInfo.pFilter);
69 static HRESULT ensure_driver(AVICompressor *This)
71 if(This->hic)
72 return S_OK;
74 This->hic = ICOpen(FCC('v','i','d','c'), This->fcc_handler, ICMODE_COMPRESS);
75 if(!This->hic) {
76 FIXME("ICOpen failed\n");
77 return E_FAIL;
80 return S_OK;
83 static HRESULT fill_format_info(AVICompressor *This, VIDEOINFOHEADER *src_videoinfo)
85 DWORD size;
86 ICINFO icinfo;
87 HRESULT hres;
89 hres = ensure_driver(This);
90 if(hres != S_OK)
91 return hres;
93 size = ICGetInfo(This->hic, &icinfo, sizeof(icinfo));
94 if(size != sizeof(icinfo))
95 return E_FAIL;
97 size = ICCompressGetFormatSize(This->hic, &src_videoinfo->bmiHeader);
98 if(!size) {
99 FIXME("ICCompressGetFormatSize failed\n");
100 return E_FAIL;
103 size += FIELD_OFFSET(VIDEOINFOHEADER, bmiHeader);
104 This->videoinfo = heap_alloc(size);
105 if(!This->videoinfo)
106 return E_OUTOFMEMORY;
108 This->videoinfo_size = size;
109 This->driver_flags = icinfo.dwFlags;
110 memset(This->videoinfo, 0, sizeof(*This->videoinfo));
111 ICCompressGetFormat(This->hic, &src_videoinfo->bmiHeader, &This->videoinfo->bmiHeader);
113 This->videoinfo->dwBitRate = 10000000/src_videoinfo->AvgTimePerFrame * This->videoinfo->bmiHeader.biSizeImage * 8;
114 This->videoinfo->AvgTimePerFrame = src_videoinfo->AvgTimePerFrame;
115 This->max_frame_size = This->videoinfo->bmiHeader.biSizeImage;
116 return S_OK;
119 static HRESULT WINAPI AVICompressor_QueryInterface(IBaseFilter *iface, REFIID riid, void **ppv)
121 AVICompressor *This = impl_from_IBaseFilter(iface);
123 if(IsEqualIID(riid, &IID_IUnknown)) {
124 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
125 *ppv = &This->filter.IBaseFilter_iface;
126 }else if(IsEqualIID(riid, &IID_IPersist)) {
127 TRACE("(%p)->(IID_IPersist %p)\n", This, ppv);
128 *ppv = &This->filter.IBaseFilter_iface;
129 }else if(IsEqualIID(riid, &IID_IMediaFilter)) {
130 TRACE("(%p)->(IID_IMediaFilter %p)\n", This, ppv);
131 *ppv = &This->filter.IBaseFilter_iface;
132 }else if(IsEqualIID(riid, &IID_IBaseFilter)) {
133 TRACE("(%p)->(IID_IBaseFilter %p)\n", This, ppv);
134 *ppv = &This->filter.IBaseFilter_iface;
135 }else if(IsEqualIID(riid, &IID_IPersistPropertyBag)) {
136 TRACE("(%p)->(IID_IPersistPropertyBag %p)\n", This, ppv);
137 *ppv = &This->IPersistPropertyBag_iface;
138 }else {
139 FIXME("no interface for %s\n", debugstr_guid(riid));
140 *ppv = NULL;
141 return E_NOINTERFACE;
144 IUnknown_AddRef((IUnknown*)*ppv);
145 return S_OK;
149 static ULONG WINAPI AVICompressor_Release(IBaseFilter *iface)
151 AVICompressor *This = impl_from_IBaseFilter(iface);
152 ULONG ref = BaseFilterImpl_Release(&This->filter.IBaseFilter_iface);
154 TRACE("(%p) ref=%d\n", This, ref);
156 if(!ref) {
157 if(This->hic)
158 ICClose(This->hic);
159 heap_free(This->videoinfo);
160 if(This->in)
161 BaseInputPinImpl_Release(&This->in->pin.IPin_iface);
162 if(This->out)
163 BaseOutputPinImpl_Release(&This->out->pin.IPin_iface);
164 heap_free(This);
167 return ref;
170 static HRESULT WINAPI AVICompressor_Stop(IBaseFilter *iface)
172 AVICompressor *This = impl_from_IBaseFilter(iface);
174 TRACE("(%p)\n", This);
176 if(This->filter.state == State_Stopped)
177 return S_OK;
179 ICCompressEnd(This->hic);
180 This->filter.state = State_Stopped;
181 return S_OK;
184 static HRESULT WINAPI AVICompressor_Pause(IBaseFilter *iface)
186 AVICompressor *This = impl_from_IBaseFilter(iface);
187 FIXME("(%p)\n", This);
188 return E_NOTIMPL;
191 static HRESULT WINAPI AVICompressor_Run(IBaseFilter *iface, REFERENCE_TIME tStart)
193 AVICompressor *This = impl_from_IBaseFilter(iface);
194 HRESULT hres;
196 TRACE("(%p)->(%s)\n", This, wine_dbgstr_longlong(tStart));
198 if(This->filter.state == State_Running)
199 return S_OK;
201 hres = IMemAllocator_Commit(This->out->pAllocator);
202 if(FAILED(hres)) {
203 FIXME("Commit failed: %08x\n", hres);
204 return hres;
207 This->frame_cnt = 0;
209 This->filter.state = State_Running;
210 return S_OK;
213 static HRESULT WINAPI AVICompressor_FindPin(IBaseFilter *iface, LPCWSTR Id, IPin **ppPin)
215 AVICompressor *This = impl_from_IBaseFilter(iface);
216 FIXME("(%p)->(%s %p)\n", This, debugstr_w(Id), ppPin);
217 return VFW_E_NOT_FOUND;
220 static HRESULT WINAPI AVICompressor_QueryFilterInfo(IBaseFilter *iface, FILTER_INFO *pInfo)
222 AVICompressor *This = impl_from_IBaseFilter(iface);
223 FIXME("(%p)->(%p)\n", This, pInfo);
224 return E_NOTIMPL;
227 static HRESULT WINAPI AVICompressor_QueryVendorInfo(IBaseFilter *iface, LPWSTR *pVendorInfo)
229 AVICompressor *This = impl_from_IBaseFilter(iface);
230 FIXME("(%p)->(%p)\n", This, pVendorInfo);
231 return E_NOTIMPL;
234 static const IBaseFilterVtbl AVICompressorVtbl = {
235 AVICompressor_QueryInterface,
236 BaseFilterImpl_AddRef,
237 AVICompressor_Release,
238 BaseFilterImpl_GetClassID,
239 AVICompressor_Stop,
240 AVICompressor_Pause,
241 AVICompressor_Run,
242 BaseFilterImpl_GetState,
243 BaseFilterImpl_SetSyncSource,
244 BaseFilterImpl_GetSyncSource,
245 BaseFilterImpl_EnumPins,
246 AVICompressor_FindPin,
247 AVICompressor_QueryFilterInfo,
248 BaseFilterImpl_JoinFilterGraph,
249 AVICompressor_QueryVendorInfo
252 static IPin* WINAPI AVICompressor_GetPin(BaseFilter *iface, int pos)
254 AVICompressor *This = impl_from_BaseFilter(iface);
255 IPin *ret;
257 TRACE("(%p)->(%d)\n", This, pos);
259 switch(pos) {
260 case 0:
261 ret = &This->in->pin.IPin_iface;
262 break;
263 case 1:
264 ret = &This->out->pin.IPin_iface;
265 break;
266 default:
267 TRACE("No pin %d\n", pos);
268 return NULL;
271 IPin_AddRef(ret);
272 return ret;
275 static LONG WINAPI AVICompressor_GetPinCount(BaseFilter *iface)
277 return 2;
280 static const BaseFilterFuncTable filter_func_table = {
281 AVICompressor_GetPin,
282 AVICompressor_GetPinCount
285 static AVICompressor *impl_from_IPersistPropertyBag(IPersistPropertyBag *iface)
287 return CONTAINING_RECORD(iface, AVICompressor, IPersistPropertyBag_iface);
290 static HRESULT WINAPI AVICompressorPropertyBag_QueryInterface(IPersistPropertyBag *iface, REFIID riid, void **ppv)
292 AVICompressor *This = impl_from_IPersistPropertyBag(iface);
293 return IBaseFilter_QueryInterface(&This->filter.IBaseFilter_iface, riid, ppv);
296 static ULONG WINAPI AVICompressorPropertyBag_AddRef(IPersistPropertyBag *iface)
298 AVICompressor *This = impl_from_IPersistPropertyBag(iface);
299 return IBaseFilter_AddRef(&This->filter.IBaseFilter_iface);
302 static ULONG WINAPI AVICompressorPropertyBag_Release(IPersistPropertyBag *iface)
304 AVICompressor *This = impl_from_IPersistPropertyBag(iface);
305 return IBaseFilter_Release(&This->filter.IBaseFilter_iface);
308 static HRESULT WINAPI AVICompressorPropertyBag_GetClassID(IPersistPropertyBag *iface, CLSID *pClassID)
310 AVICompressor *This = impl_from_IPersistPropertyBag(iface);
311 return IBaseFilter_GetClassID(&This->filter.IBaseFilter_iface, pClassID);
314 static HRESULT WINAPI AVICompressorPropertyBag_InitNew(IPersistPropertyBag *iface)
316 AVICompressor *This = impl_from_IPersistPropertyBag(iface);
317 FIXME("(%p)->()\n", This);
318 return E_NOTIMPL;
321 static HRESULT WINAPI AVICompressorPropertyBag_Load(IPersistPropertyBag *iface, IPropertyBag *pPropBag, IErrorLog *pErrorLog)
323 AVICompressor *This = impl_from_IPersistPropertyBag(iface);
324 BSTR str;
325 VARIANT v;
326 HRESULT hres;
328 static const WCHAR fcc_handlerW[] = {'F','c','c','H','a','n','d','l','e','r',0};
330 TRACE("(%p)->(%p %p)\n", This, pPropBag, pErrorLog);
332 V_VT(&v) = VT_EMPTY;
333 hres = IPropertyBag_Read(pPropBag, fcc_handlerW, &v, NULL);
334 if(FAILED(hres)) {
335 WARN("Could not read FccHandler: %08x\n", hres);
336 return hres;
339 if(V_VT(&v) != VT_BSTR) {
340 FIXME("Got vt %d\n", V_VT(&v));
341 VariantClear(&v);
342 return E_FAIL;
345 str = V_BSTR(&v);
346 TRACE("FccHandler = %s\n", debugstr_w(str));
347 if(SysStringLen(str) != 4) {
348 FIXME("Invalid FccHandler len\n");
349 SysFreeString(str);
350 return E_FAIL;
353 This->fcc_handler = FCC(str[0], str[1], str[2], str[3]);
354 SysFreeString(str);
355 return S_OK;
358 static HRESULT WINAPI AVICompressorPropertyBag_Save(IPersistPropertyBag *iface, IPropertyBag *pPropBag,
359 BOOL fClearDirty, BOOL fSaveAllProperties)
361 AVICompressor *This = impl_from_IPersistPropertyBag(iface);
362 FIXME("(%p)->(%p %x %x)\n", This, pPropBag, fClearDirty, fSaveAllProperties);
363 return E_NOTIMPL;
366 static const IPersistPropertyBagVtbl PersistPropertyBagVtbl = {
367 AVICompressorPropertyBag_QueryInterface,
368 AVICompressorPropertyBag_AddRef,
369 AVICompressorPropertyBag_Release,
370 AVICompressorPropertyBag_GetClassID,
371 AVICompressorPropertyBag_InitNew,
372 AVICompressorPropertyBag_Load,
373 AVICompressorPropertyBag_Save
376 static inline AVICompressor *impl_from_IPin(IPin *iface)
378 BasePin *bp = CONTAINING_RECORD(iface, BasePin, IPin_iface);
379 return impl_from_IBaseFilter(bp->pinInfo.pFilter);
382 static HRESULT WINAPI AVICompressorIn_QueryInterface(IPin *iface, REFIID riid, void **ppv)
384 return BaseInputPinImpl_QueryInterface(iface, riid, ppv);
387 static ULONG WINAPI AVICompressorIn_AddRef(IPin *iface)
389 AVICompressor *This = impl_from_IPin(iface);
390 return IBaseFilter_AddRef(&This->filter.IBaseFilter_iface);
393 static ULONG WINAPI AVICompressorIn_Release(IPin *iface)
395 AVICompressor *This = impl_from_IPin(iface);
396 return IBaseFilter_Release(&This->filter.IBaseFilter_iface);
399 static HRESULT WINAPI AVICompressorIn_ReceiveConnection(IPin *iface,
400 IPin *pConnector, const AM_MEDIA_TYPE *pmt)
402 AVICompressor *This = impl_from_IPin(iface);
403 HRESULT hres;
405 TRACE("(%p)->(%p AM_MEDIA_TYPE(%p))\n", This, pConnector, pmt);
406 dump_AM_MEDIA_TYPE(pmt);
408 hres = BaseInputPinImpl_ReceiveConnection(iface, pConnector, pmt);
409 if(FAILED(hres))
410 return hres;
412 hres = fill_format_info(This, (VIDEOINFOHEADER*)pmt->pbFormat);
413 if(FAILED(hres))
414 BasePinImpl_Disconnect(iface);
415 return hres;
418 static HRESULT WINAPI AVICompressorIn_Disconnect(IPin *iface)
420 AVICompressor *This = impl_from_IPin(iface);
421 HRESULT hres;
423 TRACE("(%p)\n", This);
425 hres = BasePinImpl_Disconnect(iface);
426 if(FAILED(hres))
427 return hres;
429 heap_free(This->videoinfo);
430 This->videoinfo = NULL;
431 return S_OK;
434 static const IPinVtbl AVICompressorInputPinVtbl = {
435 AVICompressorIn_QueryInterface,
436 AVICompressorIn_AddRef,
437 AVICompressorIn_Release,
438 BaseInputPinImpl_Connect,
439 AVICompressorIn_ReceiveConnection,
440 AVICompressorIn_Disconnect,
441 BasePinImpl_ConnectedTo,
442 BasePinImpl_ConnectionMediaType,
443 BasePinImpl_QueryPinInfo,
444 BasePinImpl_QueryDirection,
445 BasePinImpl_QueryId,
446 BasePinImpl_QueryAccept,
447 BasePinImpl_EnumMediaTypes,
448 BasePinImpl_QueryInternalConnections,
449 BaseInputPinImpl_EndOfStream,
450 BaseInputPinImpl_BeginFlush,
451 BaseInputPinImpl_EndFlush,
452 BaseInputPinImpl_NewSegment
455 static HRESULT WINAPI AVICompressorIn_CheckMediaType(BasePin *base, const AM_MEDIA_TYPE *pmt)
457 AVICompressor *This = impl_from_BasePin(base);
458 VIDEOINFOHEADER *videoinfo;
459 HRESULT hres;
460 DWORD res;
462 TRACE("(%p)->(AM_MEDIA_TYPE(%p))\n", base, pmt);
463 dump_AM_MEDIA_TYPE(pmt);
465 if(!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
466 return S_FALSE;
468 if(!IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)) {
469 FIXME("formattype %s unsupported\n", debugstr_guid(&pmt->formattype));
470 return S_FALSE;
473 hres = ensure_driver(This);
474 if(hres != S_OK)
475 return hres;
477 videoinfo = (VIDEOINFOHEADER*)pmt->pbFormat;
478 res = ICCompressQuery(This->hic, &videoinfo->bmiHeader, NULL);
479 return res == ICERR_OK ? S_OK : S_FALSE;
482 static LONG WINAPI AVICompressorIn_GetMediaTypeVersion(BasePin *base)
484 return 0;
487 static HRESULT WINAPI AVICompressorIn_GetMediaType(BasePin *base, int iPosition, AM_MEDIA_TYPE *amt)
489 TRACE("(%p)->(%d %p)\n", base, iPosition, amt);
490 return S_FALSE;
493 static HRESULT WINAPI AVICompressorIn_Receive(BaseInputPin *base, IMediaSample *pSample)
495 AVICompressor *This = impl_from_BasePin(&base->pin);
496 VIDEOINFOHEADER *src_videoinfo;
497 REFERENCE_TIME start, stop;
498 IMediaSample *out_sample;
499 AM_MEDIA_TYPE *mt;
500 IMediaSample2 *sample2;
501 DWORD comp_flags = 0;
502 BOOL is_preroll;
503 BOOL sync_point;
504 BYTE *ptr, *buf;
505 DWORD res;
506 HRESULT hres;
508 TRACE("(%p)->(%p)\n", base, pSample);
510 if(!This->hic) {
511 FIXME("Driver not loaded\n");
512 return E_UNEXPECTED;
515 hres = IMediaSample_QueryInterface(pSample, &IID_IMediaSample2, (void**)&sample2);
516 if(SUCCEEDED(hres)) {
517 FIXME("Use IMediaSample2\n");
518 IMediaSample2_Release(sample2);
521 is_preroll = IMediaSample_IsPreroll(pSample) == S_OK;
522 sync_point = IMediaSample_IsSyncPoint(pSample) == S_OK;
524 hres = IMediaSample_GetTime(pSample, &start, &stop);
525 if(FAILED(hres)) {
526 WARN("GetTime failed: %08x\n", hres);
527 return hres;
530 hres = IMediaSample_GetMediaType(pSample, &mt);
531 if(FAILED(hres))
532 return hres;
534 hres = IMediaSample_GetPointer(pSample, &ptr);
535 if(FAILED(hres)) {
536 WARN("GetPointer failed: %08x\n", hres);
537 return hres;
540 hres = BaseOutputPinImpl_GetDeliveryBuffer(This->out, &out_sample, &start, &stop, 0);
541 if(FAILED(hres))
542 return hres;
544 hres = IMediaSample_GetPointer(out_sample, &buf);
545 if(FAILED(hres))
546 return hres;
548 if((This->driver_flags & VIDCF_TEMPORAL) && !(This->driver_flags & VIDCF_FASTTEMPORALC))
549 FIXME("Unsupported temporal compression\n");
551 src_videoinfo = (VIDEOINFOHEADER*)This->in->pin.mtCurrent.pbFormat;
552 This->videoinfo->bmiHeader.biSizeImage = This->max_frame_size;
553 res = ICCompress(This->hic, sync_point ? ICCOMPRESS_KEYFRAME : 0, &This->videoinfo->bmiHeader, buf,
554 &src_videoinfo->bmiHeader, ptr, 0, &comp_flags, This->frame_cnt, 0, 0, NULL, NULL);
555 if(res != ICERR_OK) {
556 WARN("ICCompress failed: %d\n", res);
557 IMediaSample_Release(out_sample);
558 return E_FAIL;
561 IMediaSample_SetActualDataLength(out_sample, This->videoinfo->bmiHeader.biSizeImage);
562 IMediaSample_SetPreroll(out_sample, is_preroll);
563 IMediaSample_SetSyncPoint(out_sample, (comp_flags&AVIIF_KEYFRAME) != 0);
564 IMediaSample_SetDiscontinuity(out_sample, (IMediaSample_IsDiscontinuity(pSample) == S_OK));
566 if (IMediaSample_GetMediaTime(pSample, &start, &stop) == S_OK)
567 IMediaSample_SetMediaTime(out_sample, &start, &stop);
568 else
569 IMediaSample_SetMediaTime(out_sample, NULL, NULL);
571 hres = BaseOutputPinImpl_Deliver(This->out, out_sample);
572 if(FAILED(hres))
573 WARN("Deliver failed: %08x\n", hres);
575 IMediaSample_Release(out_sample);
576 This->frame_cnt++;
577 return hres;
580 static const BaseInputPinFuncTable AVICompressorBaseInputPinVtbl = {
582 AVICompressorIn_CheckMediaType,
583 NULL,
584 AVICompressorIn_GetMediaTypeVersion,
585 AVICompressorIn_GetMediaType
587 AVICompressorIn_Receive
590 static HRESULT WINAPI AVICompressorOut_QueryInterface(IPin *iface, REFIID riid, void **ppv)
592 return BaseInputPinImpl_QueryInterface(iface, riid, ppv);
595 static ULONG WINAPI AVICompressorOut_AddRef(IPin *iface)
597 AVICompressor *This = impl_from_IPin(iface);
598 return IBaseFilter_AddRef(&This->filter.IBaseFilter_iface);
601 static ULONG WINAPI AVICompressorOut_Release(IPin *iface)
603 AVICompressor *This = impl_from_IPin(iface);
604 return IBaseFilter_Release(&This->filter.IBaseFilter_iface);
607 static const IPinVtbl AVICompressorOutputPinVtbl = {
608 AVICompressorOut_QueryInterface,
609 AVICompressorOut_AddRef,
610 AVICompressorOut_Release,
611 BaseOutputPinImpl_Connect,
612 BaseOutputPinImpl_ReceiveConnection,
613 BaseOutputPinImpl_Disconnect,
614 BasePinImpl_ConnectedTo,
615 BasePinImpl_ConnectionMediaType,
616 BasePinImpl_QueryPinInfo,
617 BasePinImpl_QueryDirection,
618 BasePinImpl_QueryId,
619 BasePinImpl_QueryAccept,
620 BasePinImpl_EnumMediaTypes,
621 BasePinImpl_QueryInternalConnections,
622 BaseOutputPinImpl_EndOfStream,
623 BaseOutputPinImpl_BeginFlush,
624 BaseOutputPinImpl_EndFlush,
625 BasePinImpl_NewSegment
628 static LONG WINAPI AVICompressorOut_GetMediaTypeVersion(BasePin *base)
630 FIXME("(%p)\n", base);
631 return 0;
634 static HRESULT WINAPI AVICompressorOut_GetMediaType(BasePin *base, int iPosition, AM_MEDIA_TYPE *amt)
636 AVICompressor *This = impl_from_IBaseFilter(base->pinInfo.pFilter);
638 TRACE("(%p)->(%d %p)\n", base, iPosition, amt);
640 if(iPosition || !This->videoinfo)
641 return S_FALSE;
643 amt->majortype = MEDIATYPE_Video;
644 amt->subtype = MEDIASUBTYPE_PCM;
645 amt->bFixedSizeSamples = FALSE;
646 amt->bTemporalCompression = (This->driver_flags & VIDCF_TEMPORAL) != 0;
647 amt->lSampleSize = This->in->pin.mtCurrent.lSampleSize;
648 amt->formattype = FORMAT_VideoInfo;
649 amt->pUnk = NULL;
650 amt->cbFormat = This->videoinfo_size;
651 amt->pbFormat = (BYTE*)This->videoinfo;
652 return S_OK;
655 static HRESULT WINAPI AVICompressorOut_DecideBufferSize(BaseOutputPin *base, IMemAllocator *alloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
657 AVICompressor *This = impl_from_BasePin(&base->pin);
658 ALLOCATOR_PROPERTIES actual;
660 TRACE("(%p)\n", This);
662 if (!ppropInputRequest->cBuffers)
663 ppropInputRequest->cBuffers = 1;
664 if (ppropInputRequest->cbBuffer < This->max_frame_size)
665 ppropInputRequest->cbBuffer = This->max_frame_size;
666 if (!ppropInputRequest->cbAlign)
667 ppropInputRequest->cbAlign = 1;
669 return IMemAllocator_SetProperties(alloc, ppropInputRequest, &actual);
672 static HRESULT WINAPI AVICompressorOut_DecideAllocator(BaseOutputPin *base,
673 IMemInputPin *pPin, IMemAllocator **pAlloc)
675 TRACE("(%p)->(%p %p)\n", base, pPin, pAlloc);
676 return BaseOutputPinImpl_DecideAllocator(base, pPin, pAlloc);
679 static HRESULT WINAPI AVICompressorOut_BreakConnect(BaseOutputPin *base)
681 FIXME("(%p)\n", base);
682 return E_NOTIMPL;
685 static const BaseOutputPinFuncTable AVICompressorBaseOutputPinVtbl = {
687 NULL,
688 BaseOutputPinImpl_AttemptConnection,
689 AVICompressorOut_GetMediaTypeVersion,
690 AVICompressorOut_GetMediaType
692 AVICompressorOut_DecideBufferSize,
693 AVICompressorOut_DecideAllocator,
694 AVICompressorOut_BreakConnect
697 IUnknown* WINAPI QCAP_createAVICompressor(IUnknown *outer, HRESULT *phr)
699 PIN_INFO in_pin_info = {NULL, PINDIR_INPUT, {'I','n','p','u','t',0}};
700 PIN_INFO out_pin_info = {NULL, PINDIR_OUTPUT, {'O','u','t','p','u','t',0}};
701 AVICompressor *compressor;
702 HRESULT hres;
704 TRACE("\n");
706 compressor = heap_alloc_zero(sizeof(*compressor));
707 if(!compressor) {
708 *phr = E_NOINTERFACE;
709 return NULL;
712 BaseFilter_Init(&compressor->filter, &AVICompressorVtbl, &CLSID_AVICo,
713 (DWORD_PTR)(__FILE__ ": AVICompressor.csFilter"), &filter_func_table);
715 compressor->IPersistPropertyBag_iface.lpVtbl = &PersistPropertyBagVtbl;
717 in_pin_info.pFilter = &compressor->filter.IBaseFilter_iface;
718 hres = BaseInputPin_Construct(&AVICompressorInputPinVtbl, sizeof(BaseInputPin), &in_pin_info,
719 &AVICompressorBaseInputPinVtbl, &compressor->filter.csFilter, NULL, (IPin**)&compressor->in);
720 if(FAILED(hres)) {
721 IBaseFilter_Release(&compressor->filter.IBaseFilter_iface);
722 *phr = hres;
723 return NULL;
726 out_pin_info.pFilter = &compressor->filter.IBaseFilter_iface;
727 hres = BaseOutputPin_Construct(&AVICompressorOutputPinVtbl, sizeof(BaseOutputPin), &out_pin_info,
728 &AVICompressorBaseOutputPinVtbl, &compressor->filter.csFilter, (IPin**)&compressor->out);
729 if(FAILED(hres)) {
730 IBaseFilter_Release(&compressor->filter.IBaseFilter_iface);
731 *phr = hres;
732 return NULL;
735 *phr = S_OK;
736 return (IUnknown*)&compressor->filter.IBaseFilter_iface;