• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavdevice/dshow_pin.c

Go to the documentation of this file.
00001 /*
00002  * DirectShow capture interface
00003  * Copyright (c) 2010 Ramiro Polla
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "dshow.h"
00023 
00024 #include <stddef.h>
00025 #define imemoffset offsetof(libAVPin, imemvtbl)
00026 
00027 DECLARE_QUERYINTERFACE(libAVPin,
00028     { {&IID_IUnknown,0}, {&IID_IPin,0}, {&IID_IMemInputPin,imemoffset} })
00029 DECLARE_ADDREF(libAVPin)
00030 DECLARE_RELEASE(libAVPin)
00031 
00032 long WINAPI
00033 libAVPin_Connect(libAVPin *this, IPin *pin, const AM_MEDIA_TYPE *type)
00034 {
00035     dshowdebug("libAVPin_Connect(%p, %p, %p)\n", this, pin, type);
00036     /* Input pins receive connections. */
00037     return S_FALSE;
00038 }
00039 long WINAPI
00040 libAVPin_ReceiveConnection(libAVPin *this, IPin *pin,
00041                            const AM_MEDIA_TYPE *type)
00042 {
00043     enum dshowDeviceType devtype = this->filter->type;
00044     dshowdebug("libAVPin_ReceiveConnection(%p)\n", this);
00045 
00046     if (!pin)
00047         return E_POINTER;
00048     if (this->connectedto)
00049         return VFW_E_ALREADY_CONNECTED;
00050 
00051     ff_print_AM_MEDIA_TYPE(type);
00052     if (devtype == VideoDevice) {
00053         if (!IsEqualGUID(&type->majortype, &MEDIATYPE_Video))
00054             return VFW_E_TYPE_NOT_ACCEPTED;
00055     } else {
00056         if (!IsEqualGUID(&type->majortype, &MEDIATYPE_Audio))
00057             return VFW_E_TYPE_NOT_ACCEPTED;
00058     }
00059 
00060     IPin_AddRef(pin);
00061     this->connectedto = pin;
00062 
00063     ff_copy_dshow_media_type(&this->type, type);
00064 
00065     return S_OK;
00066 }
00067 long WINAPI
00068 libAVPin_Disconnect(libAVPin *this)
00069 {
00070     dshowdebug("libAVPin_Disconnect(%p)\n", this);
00071 
00072     if (this->filter->state != State_Stopped)
00073         return VFW_E_NOT_STOPPED;
00074     if (!this->connectedto)
00075         return S_FALSE;
00076     this->connectedto = NULL;
00077 
00078     return S_OK;
00079 }
00080 long WINAPI
00081 libAVPin_ConnectedTo(libAVPin *this, IPin **pin)
00082 {
00083     dshowdebug("libAVPin_ConnectedTo(%p)\n", this);
00084 
00085     if (!pin)
00086         return E_POINTER;
00087     if (!this->connectedto)
00088         return VFW_E_NOT_CONNECTED;
00089     IPin_AddRef(this->connectedto);
00090     *pin = this->connectedto;
00091 
00092     return S_OK;
00093 }
00094 long WINAPI
00095 libAVPin_ConnectionMediaType(libAVPin *this, AM_MEDIA_TYPE *type)
00096 {
00097     dshowdebug("libAVPin_ConnectionMediaType(%p)\n", this);
00098 
00099     if (!type)
00100         return E_POINTER;
00101     if (!this->connectedto)
00102         return VFW_E_NOT_CONNECTED;
00103 
00104     return ff_copy_dshow_media_type(type, &this->type);
00105 }
00106 long WINAPI
00107 libAVPin_QueryPinInfo(libAVPin *this, PIN_INFO *info)
00108 {
00109     dshowdebug("libAVPin_QueryPinInfo(%p)\n", this);
00110 
00111     if (!info)
00112         return E_POINTER;
00113 
00114     if (this->filter)
00115         libAVFilter_AddRef(this->filter);
00116 
00117     info->pFilter = (IBaseFilter *) this->filter;
00118     info->dir     = PINDIR_INPUT;
00119     wcscpy(info->achName, L"Capture");
00120 
00121     return S_OK;
00122 }
00123 long WINAPI
00124 libAVPin_QueryDirection(libAVPin *this, PIN_DIRECTION *dir)
00125 {
00126     dshowdebug("libAVPin_QueryDirection(%p)\n", this);
00127     if (!dir)
00128         return E_POINTER;
00129     *dir = PINDIR_INPUT;
00130     return S_OK;
00131 }
00132 long WINAPI
00133 libAVPin_QueryId(libAVPin *this, wchar_t **id)
00134 {
00135     dshowdebug("libAVPin_QueryId(%p)\n", this);
00136 
00137     if (!id)
00138         return E_POINTER;
00139 
00140     *id = wcsdup(L"libAV Pin");
00141 
00142     return S_OK;
00143 }
00144 long WINAPI
00145 libAVPin_QueryAccept(libAVPin *this, const AM_MEDIA_TYPE *type)
00146 {
00147     dshowdebug("libAVPin_QueryAccept(%p)\n", this);
00148     return S_FALSE;
00149 }
00150 long WINAPI
00151 libAVPin_EnumMediaTypes(libAVPin *this, IEnumMediaTypes **enumtypes)
00152 {
00153     const AM_MEDIA_TYPE *type = NULL;
00154     libAVEnumMediaTypes *new;
00155     dshowdebug("libAVPin_EnumMediaTypes(%p)\n", this);
00156 
00157     if (!enumtypes)
00158         return E_POINTER;
00159     new = libAVEnumMediaTypes_Create(type);
00160     if (!new)
00161         return E_OUTOFMEMORY;
00162 
00163     *enumtypes = (IEnumMediaTypes *) new;
00164     return S_OK;
00165 }
00166 long WINAPI
00167 libAVPin_QueryInternalConnections(libAVPin *this, IPin **pin,
00168                                   unsigned long *npin)
00169 {
00170     dshowdebug("libAVPin_QueryInternalConnections(%p)\n", this);
00171     return E_NOTIMPL;
00172 }
00173 long WINAPI
00174 libAVPin_EndOfStream(libAVPin *this)
00175 {
00176     dshowdebug("libAVPin_EndOfStream(%p)\n", this);
00177     /* I don't care. */
00178     return S_OK;
00179 }
00180 long WINAPI
00181 libAVPin_BeginFlush(libAVPin *this)
00182 {
00183     dshowdebug("libAVPin_BeginFlush(%p)\n", this);
00184     /* I don't care. */
00185     return S_OK;
00186 }
00187 long WINAPI
00188 libAVPin_EndFlush(libAVPin *this)
00189 {
00190     dshowdebug("libAVPin_EndFlush(%p)\n", this);
00191     /* I don't care. */
00192     return S_OK;
00193 }
00194 long WINAPI
00195 libAVPin_NewSegment(libAVPin *this, REFERENCE_TIME start, REFERENCE_TIME stop,
00196                     double rate)
00197 {
00198     dshowdebug("libAVPin_NewSegment(%p)\n", this);
00199     /* I don't care. */
00200     return S_OK;
00201 }
00202 
00203 static int
00204 libAVPin_Setup(libAVPin *this, libAVFilter *filter)
00205 {
00206     IPinVtbl *vtbl = this->vtbl;
00207     IMemInputPinVtbl *imemvtbl;
00208 
00209     if (!filter)
00210         return 0;
00211 
00212     imemvtbl = av_malloc(sizeof(IMemInputPinVtbl));
00213     if (!imemvtbl)
00214         return 0;
00215 
00216     SETVTBL(imemvtbl, libAVMemInputPin, QueryInterface);
00217     SETVTBL(imemvtbl, libAVMemInputPin, AddRef);
00218     SETVTBL(imemvtbl, libAVMemInputPin, Release);
00219     SETVTBL(imemvtbl, libAVMemInputPin, GetAllocator);
00220     SETVTBL(imemvtbl, libAVMemInputPin, NotifyAllocator);
00221     SETVTBL(imemvtbl, libAVMemInputPin, GetAllocatorRequirements);
00222     SETVTBL(imemvtbl, libAVMemInputPin, Receive);
00223     SETVTBL(imemvtbl, libAVMemInputPin, ReceiveMultiple);
00224     SETVTBL(imemvtbl, libAVMemInputPin, ReceiveCanBlock);
00225 
00226     this->imemvtbl = imemvtbl;
00227 
00228     SETVTBL(vtbl, libAVPin, QueryInterface);
00229     SETVTBL(vtbl, libAVPin, AddRef);
00230     SETVTBL(vtbl, libAVPin, Release);
00231     SETVTBL(vtbl, libAVPin, Connect);
00232     SETVTBL(vtbl, libAVPin, ReceiveConnection);
00233     SETVTBL(vtbl, libAVPin, Disconnect);
00234     SETVTBL(vtbl, libAVPin, ConnectedTo);
00235     SETVTBL(vtbl, libAVPin, ConnectionMediaType);
00236     SETVTBL(vtbl, libAVPin, QueryPinInfo);
00237     SETVTBL(vtbl, libAVPin, QueryDirection);
00238     SETVTBL(vtbl, libAVPin, QueryId);
00239     SETVTBL(vtbl, libAVPin, QueryAccept);
00240     SETVTBL(vtbl, libAVPin, EnumMediaTypes);
00241     SETVTBL(vtbl, libAVPin, QueryInternalConnections);
00242     SETVTBL(vtbl, libAVPin, EndOfStream);
00243     SETVTBL(vtbl, libAVPin, BeginFlush);
00244     SETVTBL(vtbl, libAVPin, EndFlush);
00245     SETVTBL(vtbl, libAVPin, NewSegment);
00246 
00247     this->filter = filter;
00248 
00249     return 1;
00250 }
00251 DECLARE_CREATE(libAVPin, libAVPin_Setup(this, filter), libAVFilter *filter)
00252 DECLARE_DESTROY(libAVPin, nothing)
00253 
00254 /*****************************************************************************
00255  * libAVMemInputPin
00256  ****************************************************************************/
00257 long WINAPI
00258 libAVMemInputPin_QueryInterface(libAVMemInputPin *this, const GUID *riid,
00259                                 void **ppvObject)
00260 {
00261     libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
00262     dshowdebug("libAVMemInputPin_QueryInterface(%p)\n", this);
00263     return libAVPin_QueryInterface(pin, riid, ppvObject);
00264 }
00265 unsigned long WINAPI
00266 libAVMemInputPin_AddRef(libAVMemInputPin *this)
00267 {
00268     libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
00269     dshowdebug("libAVMemInputPin_AddRef(%p)\n", this);
00270     return libAVPin_AddRef(pin);
00271 }
00272 unsigned long WINAPI
00273 libAVMemInputPin_Release(libAVMemInputPin *this)
00274 {
00275     libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
00276     dshowdebug("libAVMemInputPin_Release(%p)\n", this);
00277     return libAVPin_Release(pin);
00278 }
00279 long WINAPI
00280 libAVMemInputPin_GetAllocator(libAVMemInputPin *this, IMemAllocator **alloc)
00281 {
00282     dshowdebug("libAVMemInputPin_GetAllocator(%p)\n", this);
00283     return VFW_E_NO_ALLOCATOR;
00284 }
00285 long WINAPI
00286 libAVMemInputPin_NotifyAllocator(libAVMemInputPin *this, IMemAllocator *alloc,
00287                                  WINBOOL rdwr)
00288 {
00289     dshowdebug("libAVMemInputPin_NotifyAllocator(%p)\n", this);
00290     return S_OK;
00291 }
00292 long WINAPI
00293 libAVMemInputPin_GetAllocatorRequirements(libAVMemInputPin *this,
00294                                           ALLOCATOR_PROPERTIES *props)
00295 {
00296     dshowdebug("libAVMemInputPin_GetAllocatorRequirements(%p)\n", this);
00297     return E_NOTIMPL;
00298 }
00299 long WINAPI
00300 libAVMemInputPin_Receive(libAVMemInputPin *this, IMediaSample *sample)
00301 {
00302     libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
00303     enum dshowDeviceType devtype = pin->filter->type;
00304     void *priv_data;
00305     uint8_t *buf;
00306     int buf_size;
00307     int index;
00308     int64_t curtime;
00309 
00310     dshowdebug("libAVMemInputPin_Receive(%p)\n", this);
00311 
00312     if (!sample)
00313         return E_POINTER;
00314 
00315     if (devtype == VideoDevice) {
00316         /* PTS from video devices is unreliable. */
00317         IReferenceClock *clock = pin->filter->clock;
00318         IReferenceClock_GetTime(clock, &curtime);
00319     } else {
00320         int64_t dummy;
00321         IMediaSample_GetTime(sample, &curtime, &dummy);
00322         curtime += pin->filter->start_time;
00323     }
00324 
00325     buf_size = IMediaSample_GetActualDataLength(sample);
00326     IMediaSample_GetPointer(sample, &buf);
00327     priv_data = pin->filter->priv_data;
00328     index = pin->filter->stream_index;
00329 
00330     pin->filter->callback(priv_data, index, buf, buf_size, curtime);
00331 
00332     return S_OK;
00333 }
00334 long WINAPI
00335 libAVMemInputPin_ReceiveMultiple(libAVMemInputPin *this,
00336                                  IMediaSample **samples, long n, long *nproc)
00337 {
00338     int i;
00339     dshowdebug("libAVMemInputPin_ReceiveMultiple(%p)\n", this);
00340 
00341     for (i = 0; i < n; i++)
00342         libAVMemInputPin_Receive(this, samples[i]);
00343 
00344     *nproc = n;
00345     return S_OK;
00346 }
00347 long WINAPI
00348 libAVMemInputPin_ReceiveCanBlock(libAVMemInputPin *this)
00349 {
00350     dshowdebug("libAVMemInputPin_ReceiveCanBlock(%p)\n", this);
00351     /* I swear I will not block. */
00352     return S_FALSE;
00353 }
00354 
00355 void
00356 libAVMemInputPin_Destroy(libAVMemInputPin *this)
00357 {
00358     libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset);
00359     dshowdebug("libAVMemInputPin_Destroy(%p)\n", this);
00360     return libAVPin_Destroy(pin);
00361 }

Generated on Wed Apr 11 2012 07:31:35 for FFmpeg by  doxygen 1.7.1