2 * DirectShow capture interface
3 * Copyright (c) 2010 Ramiro Polla
5 * This file is part of FFmpeg.
7 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #define imemoffset offsetof(libAVPin, imemvtbl)
27 DECLARE_QUERYINTERFACE(libAVPin,
28 { {&IID_IUnknown,0}, {&IID_IPin,0}, {&IID_IMemInputPin,imemoffset} })
29 DECLARE_ADDREF(libAVPin)
30 DECLARE_RELEASE(libAVPin)
33 libAVPin_Connect(libAVPin *this, IPin *pin, const AM_MEDIA_TYPE *type)
35 dshowdebug("libAVPin_Connect(%p, %p, %p)\n", this, pin, type);
36 /* Input pins receive connections. */
40 libAVPin_ReceiveConnection(libAVPin *this, IPin *pin,
41 const AM_MEDIA_TYPE *type)
43 enum dshowDeviceType devtype = this->filter->type;
44 dshowdebug("libAVPin_ReceiveConnection(%p)\n", this);
48 if (this->connectedto)
49 return VFW_E_ALREADY_CONNECTED;
51 ff_print_AM_MEDIA_TYPE(type);
52 if (devtype == VideoDevice) {
53 if (!IsEqualGUID(&type->majortype, &MEDIATYPE_Video))
54 return VFW_E_TYPE_NOT_ACCEPTED;
56 if (!IsEqualGUID(&type->majortype, &MEDIATYPE_Audio))
57 return VFW_E_TYPE_NOT_ACCEPTED;
61 this->connectedto = pin;
63 ff_copy_dshow_media_type(&this->type, type);
68 libAVPin_Disconnect(libAVPin *this)
70 dshowdebug("libAVPin_Disconnect(%p)\n", this);
72 if (this->filter->state != State_Stopped)
73 return VFW_E_NOT_STOPPED;
74 if (!this->connectedto)
76 this->connectedto = NULL;
81 libAVPin_ConnectedTo(libAVPin *this, IPin **pin)
83 dshowdebug("libAVPin_ConnectedTo(%p)\n", this);
87 if (!this->connectedto)
88 return VFW_E_NOT_CONNECTED;
89 IPin_AddRef(this->connectedto);
90 *pin = this->connectedto;
95 libAVPin_ConnectionMediaType(libAVPin *this, AM_MEDIA_TYPE *type)
97 dshowdebug("libAVPin_ConnectionMediaType(%p)\n", this);
101 if (!this->connectedto)
102 return VFW_E_NOT_CONNECTED;
104 return ff_copy_dshow_media_type(type, &this->type);
107 libAVPin_QueryPinInfo(libAVPin *this, PIN_INFO *info)
109 dshowdebug("libAVPin_QueryPinInfo(%p)\n", this);
115 libAVFilter_AddRef(this->filter);
117 info->pFilter = (IBaseFilter *) this->filter;
118 info->dir = PINDIR_INPUT;
119 wcscpy(info->achName, L"Capture");
124 libAVPin_QueryDirection(libAVPin *this, PIN_DIRECTION *dir)
126 dshowdebug("libAVPin_QueryDirection(%p)\n", this);
133 libAVPin_QueryId(libAVPin *this, wchar_t **id)
135 dshowdebug("libAVPin_QueryId(%p)\n", this);
140 *id = wcsdup(L"libAV Pin");
145 libAVPin_QueryAccept(libAVPin *this, const AM_MEDIA_TYPE *type)
147 dshowdebug("libAVPin_QueryAccept(%p)\n", this);
151 libAVPin_EnumMediaTypes(libAVPin *this, IEnumMediaTypes **enumtypes)
153 const AM_MEDIA_TYPE *type = NULL;
154 libAVEnumMediaTypes *new;
155 dshowdebug("libAVPin_EnumMediaTypes(%p)\n", this);
159 new = libAVEnumMediaTypes_Create(type);
161 return E_OUTOFMEMORY;
163 *enumtypes = (IEnumMediaTypes *) new;
167 libAVPin_QueryInternalConnections(libAVPin *this, IPin **pin,
170 dshowdebug("libAVPin_QueryInternalConnections(%p)\n", this);
174 libAVPin_EndOfStream(libAVPin *this)
176 dshowdebug("libAVPin_EndOfStream(%p)\n", this);
181 libAVPin_BeginFlush(libAVPin *this)
183 dshowdebug("libAVPin_BeginFlush(%p)\n", this);
188 libAVPin_EndFlush(libAVPin *this)
190 dshowdebug("libAVPin_EndFlush(%p)\n", this);
195 libAVPin_NewSegment(libAVPin *this, REFERENCE_TIME start, REFERENCE_TIME stop,
198 dshowdebug("libAVPin_NewSegment(%p)\n", this);
204 libAVPin_Setup(libAVPin *this, libAVFilter *filter)
206 IPinVtbl *vtbl = this->vtbl;
207 IMemInputPinVtbl *imemvtbl;
212 imemvtbl = av_malloc(sizeof(IMemInputPinVtbl));
216 SETVTBL(imemvtbl, libAVMemInputPin, QueryInterface);
217 SETVTBL(imemvtbl, libAVMemInputPin, AddRef);
218 SETVTBL(imemvtbl, libAVMemInputPin, Release);
219 SETVTBL(imemvtbl, libAVMemInputPin, GetAllocator);
220 SETVTBL(imemvtbl, libAVMemInputPin, NotifyAllocator);
221 SETVTBL(imemvtbl, libAVMemInputPin, GetAllocatorRequirements);
222 SETVTBL(imemvtbl, libAVMemInputPin, Receive);
223 SETVTBL(imemvtbl, libAVMemInputPin, ReceiveMultiple);
224 SETVTBL(imemvtbl, libAVMemInputPin, ReceiveCanBlock);
226 this->imemvtbl = imemvtbl;
228 SETVTBL(vtbl, libAVPin, QueryInterface);
229 SETVTBL(vtbl, libAVPin, AddRef);
230 SETVTBL(vtbl, libAVPin, Release);
231 SETVTBL(vtbl, libAVPin, Connect);
232 SETVTBL(vtbl, libAVPin, ReceiveConnection);
233 SETVTBL(vtbl, libAVPin, Disconnect);
234 SETVTBL(vtbl, libAVPin, ConnectedTo);
235 SETVTBL(vtbl, libAVPin, ConnectionMediaType);
236 SETVTBL(vtbl, libAVPin, QueryPinInfo);
237 SETVTBL(vtbl, libAVPin, QueryDirection);
238 SETVTBL(vtbl, libAVPin, QueryId);
239 SETVTBL(vtbl, libAVPin, QueryAccept);
240 SETVTBL(vtbl, libAVPin, EnumMediaTypes);
241 SETVTBL(vtbl, libAVPin, QueryInternalConnections);
242 SETVTBL(vtbl, libAVPin, EndOfStream);
243 SETVTBL(vtbl, libAVPin, BeginFlush);
244 SETVTBL(vtbl, libAVPin, EndFlush);
245 SETVTBL(vtbl, libAVPin, NewSegment);
247 this->filter = filter;
251 DECLARE_CREATE(libAVPin, libAVPin_Setup(this, filter), libAVFilter *filter)
252 DECLARE_DESTROY(libAVPin, nothing)
254 /*****************************************************************************
256 ****************************************************************************/
258 libAVMemInputPin_QueryInterface(libAVMemInputPin *this, const GUID *riid,
261 libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
262 dshowdebug("libAVMemInputPin_QueryInterface(%p)\n", this);
263 return libAVPin_QueryInterface(pin, riid, ppvObject);
266 libAVMemInputPin_AddRef(libAVMemInputPin *this)
268 libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
269 dshowdebug("libAVMemInputPin_AddRef(%p)\n", this);
270 return libAVPin_AddRef(pin);
273 libAVMemInputPin_Release(libAVMemInputPin *this)
275 libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
276 dshowdebug("libAVMemInputPin_Release(%p)\n", this);
277 return libAVPin_Release(pin);
280 libAVMemInputPin_GetAllocator(libAVMemInputPin *this, IMemAllocator **alloc)
282 dshowdebug("libAVMemInputPin_GetAllocator(%p)\n", this);
283 return VFW_E_NO_ALLOCATOR;
286 libAVMemInputPin_NotifyAllocator(libAVMemInputPin *this, IMemAllocator *alloc,
289 dshowdebug("libAVMemInputPin_NotifyAllocator(%p)\n", this);
293 libAVMemInputPin_GetAllocatorRequirements(libAVMemInputPin *this,
294 ALLOCATOR_PROPERTIES *props)
296 dshowdebug("libAVMemInputPin_GetAllocatorRequirements(%p)\n", this);
300 libAVMemInputPin_Receive(libAVMemInputPin *this, IMediaSample *sample)
302 libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
303 enum dshowDeviceType devtype = pin->filter->type;
310 dshowdebug("libAVMemInputPin_Receive(%p)\n", this);
315 if (devtype == VideoDevice) {
316 /* PTS from video devices is unreliable. */
317 IReferenceClock *clock = pin->filter->clock;
318 IReferenceClock_GetTime(clock, &curtime);
321 IMediaSample_GetTime(sample, &curtime, &dummy);
322 curtime += pin->filter->start_time;
325 buf_size = IMediaSample_GetActualDataLength(sample);
326 IMediaSample_GetPointer(sample, &buf);
327 priv_data = pin->filter->priv_data;
328 index = pin->filter->stream_index;
330 pin->filter->callback(priv_data, index, buf, buf_size, curtime);
335 libAVMemInputPin_ReceiveMultiple(libAVMemInputPin *this,
336 IMediaSample **samples, long n, long *nproc)
339 dshowdebug("libAVMemInputPin_ReceiveMultiple(%p)\n", this);
341 for (i = 0; i < n; i++)
342 libAVMemInputPin_Receive(this, samples[i]);
348 libAVMemInputPin_ReceiveCanBlock(libAVMemInputPin *this)
350 dshowdebug("libAVMemInputPin_ReceiveCanBlock(%p)\n", this);
351 /* I swear I will not block. */
356 libAVMemInputPin_Destroy(libAVMemInputPin *this)
358 libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
359 dshowdebug("libAVMemInputPin_Destroy(%p)\n", this);
360 return libAVPin_Destroy(pin);