annotate ffmpeg/libavdevice/dshow_capture.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * DirectShow capture interface
yading@10 3 * Copyright (c) 2010 Ramiro Polla
yading@10 4 *
yading@10 5 * This file is part of FFmpeg.
yading@10 6 *
yading@10 7 * FFmpeg is free software; you can redistribute it and/or
yading@10 8 * modify it under the terms of the GNU Lesser General Public
yading@10 9 * License as published by the Free Software Foundation; either
yading@10 10 * version 2.1 of the License, or (at your option) any later version.
yading@10 11 *
yading@10 12 * FFmpeg is distributed in the hope that it will be useful,
yading@10 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 15 * Lesser General Public License for more details.
yading@10 16 *
yading@10 17 * You should have received a copy of the GNU Lesser General Public
yading@10 18 * License along with FFmpeg; if not, write to the Free Software
yading@10 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 20 */
yading@10 21
yading@10 22 #ifndef AVDEVICE_DSHOW_H
yading@10 23 #define AVDEVICE_DSHOW_H
yading@10 24
yading@10 25 #define DSHOWDEBUG 0
yading@10 26
yading@10 27 #include "avdevice.h"
yading@10 28
yading@10 29 #define COBJMACROS
yading@10 30 #include <windows.h>
yading@10 31 #define NO_DSHOW_STRSAFE
yading@10 32 #include <dshow.h>
yading@10 33 #include <dvdmedia.h>
yading@10 34
yading@10 35 /* EC_DEVICE_LOST is not defined in MinGW dshow headers. */
yading@10 36 #ifndef EC_DEVICE_LOST
yading@10 37 #define EC_DEVICE_LOST 0x1f
yading@10 38 #endif
yading@10 39
yading@10 40 long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src);
yading@10 41 void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps);
yading@10 42 void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps);
yading@10 43 void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type);
yading@10 44 void ff_printGUID(const GUID *g);
yading@10 45
yading@10 46 #if DSHOWDEBUG
yading@10 47 extern const AVClass *ff_dshow_context_class_ptr;
yading@10 48 #define dshowdebug(...) av_log(&ff_dshow_context_class_ptr, AV_LOG_DEBUG, __VA_ARGS__)
yading@10 49 #else
yading@10 50 #define dshowdebug(...)
yading@10 51 #endif
yading@10 52
yading@10 53 static inline void nothing(void *foo)
yading@10 54 {
yading@10 55 }
yading@10 56
yading@10 57 struct GUIDoffset {
yading@10 58 const GUID *iid;
yading@10 59 int offset;
yading@10 60 };
yading@10 61
yading@10 62 enum dshowDeviceType {
yading@10 63 VideoDevice = 0,
yading@10 64 AudioDevice = 1,
yading@10 65 };
yading@10 66
yading@10 67 #define DECLARE_QUERYINTERFACE(class, ...) \
yading@10 68 long WINAPI \
yading@10 69 class##_QueryInterface(class *this, const GUID *riid, void **ppvObject) \
yading@10 70 { \
yading@10 71 struct GUIDoffset ifaces[] = __VA_ARGS__; \
yading@10 72 int i; \
yading@10 73 dshowdebug(AV_STRINGIFY(class)"_QueryInterface(%p, %p, %p)\n", this, riid, ppvObject); \
yading@10 74 ff_printGUID(riid); \
yading@10 75 if (!ppvObject) \
yading@10 76 return E_POINTER; \
yading@10 77 for (i = 0; i < sizeof(ifaces)/sizeof(ifaces[0]); i++) { \
yading@10 78 if (IsEqualGUID(riid, ifaces[i].iid)) { \
yading@10 79 void *obj = (void *) ((uint8_t *) this + ifaces[i].offset); \
yading@10 80 class##_AddRef(this); \
yading@10 81 dshowdebug("\tfound %d with offset %d\n", i, ifaces[i].offset); \
yading@10 82 *ppvObject = (void *) obj; \
yading@10 83 return S_OK; \
yading@10 84 } \
yading@10 85 } \
yading@10 86 dshowdebug("\tE_NOINTERFACE\n"); \
yading@10 87 *ppvObject = NULL; \
yading@10 88 return E_NOINTERFACE; \
yading@10 89 }
yading@10 90 #define DECLARE_ADDREF(class) \
yading@10 91 unsigned long WINAPI \
yading@10 92 class##_AddRef(class *this) \
yading@10 93 { \
yading@10 94 dshowdebug(AV_STRINGIFY(class)"_AddRef(%p)\t%ld\n", this, this->ref+1); \
yading@10 95 return InterlockedIncrement(&this->ref); \
yading@10 96 }
yading@10 97 #define DECLARE_RELEASE(class) \
yading@10 98 unsigned long WINAPI \
yading@10 99 class##_Release(class *this) \
yading@10 100 { \
yading@10 101 long ref = InterlockedDecrement(&this->ref); \
yading@10 102 dshowdebug(AV_STRINGIFY(class)"_Release(%p)\t%ld\n", this, ref); \
yading@10 103 if (!ref) \
yading@10 104 class##_Destroy(this); \
yading@10 105 return ref; \
yading@10 106 }
yading@10 107
yading@10 108 #define DECLARE_DESTROY(class, func) \
yading@10 109 void class##_Destroy(class *this) \
yading@10 110 { \
yading@10 111 dshowdebug(AV_STRINGIFY(class)"_Destroy(%p)\n", this); \
yading@10 112 func(this); \
yading@10 113 if (this) { \
yading@10 114 if (this->vtbl) \
yading@10 115 CoTaskMemFree(this->vtbl); \
yading@10 116 CoTaskMemFree(this); \
yading@10 117 } \
yading@10 118 }
yading@10 119 #define DECLARE_CREATE(class, setup, ...) \
yading@10 120 class *class##_Create(__VA_ARGS__) \
yading@10 121 { \
yading@10 122 class *this = CoTaskMemAlloc(sizeof(class)); \
yading@10 123 void *vtbl = CoTaskMemAlloc(sizeof(*this->vtbl)); \
yading@10 124 dshowdebug(AV_STRINGIFY(class)"_Create(%p)\n", this); \
yading@10 125 if (!this || !vtbl) \
yading@10 126 goto fail; \
yading@10 127 ZeroMemory(this, sizeof(class)); \
yading@10 128 ZeroMemory(vtbl, sizeof(*this->vtbl)); \
yading@10 129 this->ref = 1; \
yading@10 130 this->vtbl = vtbl; \
yading@10 131 if (!setup) \
yading@10 132 goto fail; \
yading@10 133 dshowdebug("created "AV_STRINGIFY(class)" %p\n", this); \
yading@10 134 return this; \
yading@10 135 fail: \
yading@10 136 class##_Destroy(this); \
yading@10 137 dshowdebug("could not create "AV_STRINGIFY(class)"\n"); \
yading@10 138 return NULL; \
yading@10 139 }
yading@10 140
yading@10 141 #define SETVTBL(vtbl, class, fn) \
yading@10 142 do { (vtbl)->fn = (void *) class##_##fn; } while(0)
yading@10 143
yading@10 144 /*****************************************************************************
yading@10 145 * Forward Declarations
yading@10 146 ****************************************************************************/
yading@10 147 typedef struct libAVPin libAVPin;
yading@10 148 typedef struct libAVMemInputPin libAVMemInputPin;
yading@10 149 typedef struct libAVEnumPins libAVEnumPins;
yading@10 150 typedef struct libAVEnumMediaTypes libAVEnumMediaTypes;
yading@10 151 typedef struct libAVFilter libAVFilter;
yading@10 152
yading@10 153 /*****************************************************************************
yading@10 154 * libAVPin
yading@10 155 ****************************************************************************/
yading@10 156 struct libAVPin {
yading@10 157 IPinVtbl *vtbl;
yading@10 158 long ref;
yading@10 159 libAVFilter *filter;
yading@10 160 IPin *connectedto;
yading@10 161 AM_MEDIA_TYPE type;
yading@10 162 IMemInputPinVtbl *imemvtbl;
yading@10 163 };
yading@10 164
yading@10 165 long WINAPI libAVPin_QueryInterface (libAVPin *, const GUID *, void **);
yading@10 166 unsigned long WINAPI libAVPin_AddRef (libAVPin *);
yading@10 167 unsigned long WINAPI libAVPin_Release (libAVPin *);
yading@10 168 long WINAPI libAVPin_Connect (libAVPin *, IPin *, const AM_MEDIA_TYPE *);
yading@10 169 long WINAPI libAVPin_ReceiveConnection (libAVPin *, IPin *, const AM_MEDIA_TYPE *);
yading@10 170 long WINAPI libAVPin_Disconnect (libAVPin *);
yading@10 171 long WINAPI libAVPin_ConnectedTo (libAVPin *, IPin **);
yading@10 172 long WINAPI libAVPin_ConnectionMediaType (libAVPin *, AM_MEDIA_TYPE *);
yading@10 173 long WINAPI libAVPin_QueryPinInfo (libAVPin *, PIN_INFO *);
yading@10 174 long WINAPI libAVPin_QueryDirection (libAVPin *, PIN_DIRECTION *);
yading@10 175 long WINAPI libAVPin_QueryId (libAVPin *, wchar_t **);
yading@10 176 long WINAPI libAVPin_QueryAccept (libAVPin *, const AM_MEDIA_TYPE *);
yading@10 177 long WINAPI libAVPin_EnumMediaTypes (libAVPin *, IEnumMediaTypes **);
yading@10 178 long WINAPI libAVPin_QueryInternalConnections(libAVPin *, IPin **, unsigned long *);
yading@10 179 long WINAPI libAVPin_EndOfStream (libAVPin *);
yading@10 180 long WINAPI libAVPin_BeginFlush (libAVPin *);
yading@10 181 long WINAPI libAVPin_EndFlush (libAVPin *);
yading@10 182 long WINAPI libAVPin_NewSegment (libAVPin *, REFERENCE_TIME, REFERENCE_TIME, double);
yading@10 183
yading@10 184 long WINAPI libAVMemInputPin_QueryInterface (libAVMemInputPin *, const GUID *, void **);
yading@10 185 unsigned long WINAPI libAVMemInputPin_AddRef (libAVMemInputPin *);
yading@10 186 unsigned long WINAPI libAVMemInputPin_Release (libAVMemInputPin *);
yading@10 187 long WINAPI libAVMemInputPin_GetAllocator (libAVMemInputPin *, IMemAllocator **);
yading@10 188 long WINAPI libAVMemInputPin_NotifyAllocator (libAVMemInputPin *, IMemAllocator *, BOOL);
yading@10 189 long WINAPI libAVMemInputPin_GetAllocatorRequirements(libAVMemInputPin *, ALLOCATOR_PROPERTIES *);
yading@10 190 long WINAPI libAVMemInputPin_Receive (libAVMemInputPin *, IMediaSample *);
yading@10 191 long WINAPI libAVMemInputPin_ReceiveMultiple (libAVMemInputPin *, IMediaSample **, long, long *);
yading@10 192 long WINAPI libAVMemInputPin_ReceiveCanBlock (libAVMemInputPin *);
yading@10 193
yading@10 194 void libAVPin_Destroy(libAVPin *);
yading@10 195 libAVPin *libAVPin_Create (libAVFilter *filter);
yading@10 196
yading@10 197 void libAVMemInputPin_Destroy(libAVMemInputPin *);
yading@10 198
yading@10 199 /*****************************************************************************
yading@10 200 * libAVEnumPins
yading@10 201 ****************************************************************************/
yading@10 202 struct libAVEnumPins {
yading@10 203 IEnumPinsVtbl *vtbl;
yading@10 204 long ref;
yading@10 205 int pos;
yading@10 206 libAVPin *pin;
yading@10 207 libAVFilter *filter;
yading@10 208 };
yading@10 209
yading@10 210 long WINAPI libAVEnumPins_QueryInterface(libAVEnumPins *, const GUID *, void **);
yading@10 211 unsigned long WINAPI libAVEnumPins_AddRef (libAVEnumPins *);
yading@10 212 unsigned long WINAPI libAVEnumPins_Release (libAVEnumPins *);
yading@10 213 long WINAPI libAVEnumPins_Next (libAVEnumPins *, unsigned long, IPin **, unsigned long *);
yading@10 214 long WINAPI libAVEnumPins_Skip (libAVEnumPins *, unsigned long);
yading@10 215 long WINAPI libAVEnumPins_Reset (libAVEnumPins *);
yading@10 216 long WINAPI libAVEnumPins_Clone (libAVEnumPins *, libAVEnumPins **);
yading@10 217
yading@10 218 void libAVEnumPins_Destroy(libAVEnumPins *);
yading@10 219 libAVEnumPins *libAVEnumPins_Create (libAVPin *pin, libAVFilter *filter);
yading@10 220
yading@10 221 /*****************************************************************************
yading@10 222 * libAVEnumMediaTypes
yading@10 223 ****************************************************************************/
yading@10 224 struct libAVEnumMediaTypes {
yading@10 225 IEnumPinsVtbl *vtbl;
yading@10 226 long ref;
yading@10 227 int pos;
yading@10 228 AM_MEDIA_TYPE type;
yading@10 229 };
yading@10 230
yading@10 231 long WINAPI libAVEnumMediaTypes_QueryInterface(libAVEnumMediaTypes *, const GUID *, void **);
yading@10 232 unsigned long WINAPI libAVEnumMediaTypes_AddRef (libAVEnumMediaTypes *);
yading@10 233 unsigned long WINAPI libAVEnumMediaTypes_Release (libAVEnumMediaTypes *);
yading@10 234 long WINAPI libAVEnumMediaTypes_Next (libAVEnumMediaTypes *, unsigned long, AM_MEDIA_TYPE **, unsigned long *);
yading@10 235 long WINAPI libAVEnumMediaTypes_Skip (libAVEnumMediaTypes *, unsigned long);
yading@10 236 long WINAPI libAVEnumMediaTypes_Reset (libAVEnumMediaTypes *);
yading@10 237 long WINAPI libAVEnumMediaTypes_Clone (libAVEnumMediaTypes *, libAVEnumMediaTypes **);
yading@10 238
yading@10 239 void libAVEnumMediaTypes_Destroy(libAVEnumMediaTypes *);
yading@10 240 libAVEnumMediaTypes *libAVEnumMediaTypes_Create(const AM_MEDIA_TYPE *type);
yading@10 241
yading@10 242 /*****************************************************************************
yading@10 243 * libAVFilter
yading@10 244 ****************************************************************************/
yading@10 245 struct libAVFilter {
yading@10 246 IBaseFilterVtbl *vtbl;
yading@10 247 long ref;
yading@10 248 const wchar_t *name;
yading@10 249 libAVPin *pin;
yading@10 250 FILTER_INFO info;
yading@10 251 FILTER_STATE state;
yading@10 252 IReferenceClock *clock;
yading@10 253 enum dshowDeviceType type;
yading@10 254 void *priv_data;
yading@10 255 int stream_index;
yading@10 256 int64_t start_time;
yading@10 257 void (*callback)(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time);
yading@10 258 };
yading@10 259
yading@10 260 long WINAPI libAVFilter_QueryInterface (libAVFilter *, const GUID *, void **);
yading@10 261 unsigned long WINAPI libAVFilter_AddRef (libAVFilter *);
yading@10 262 unsigned long WINAPI libAVFilter_Release (libAVFilter *);
yading@10 263 long WINAPI libAVFilter_GetClassID (libAVFilter *, CLSID *);
yading@10 264 long WINAPI libAVFilter_Stop (libAVFilter *);
yading@10 265 long WINAPI libAVFilter_Pause (libAVFilter *);
yading@10 266 long WINAPI libAVFilter_Run (libAVFilter *, REFERENCE_TIME);
yading@10 267 long WINAPI libAVFilter_GetState (libAVFilter *, DWORD, FILTER_STATE *);
yading@10 268 long WINAPI libAVFilter_SetSyncSource (libAVFilter *, IReferenceClock *);
yading@10 269 long WINAPI libAVFilter_GetSyncSource (libAVFilter *, IReferenceClock **);
yading@10 270 long WINAPI libAVFilter_EnumPins (libAVFilter *, IEnumPins **);
yading@10 271 long WINAPI libAVFilter_FindPin (libAVFilter *, const wchar_t *, IPin **);
yading@10 272 long WINAPI libAVFilter_QueryFilterInfo(libAVFilter *, FILTER_INFO *);
yading@10 273 long WINAPI libAVFilter_JoinFilterGraph(libAVFilter *, IFilterGraph *, const wchar_t *);
yading@10 274 long WINAPI libAVFilter_QueryVendorInfo(libAVFilter *, wchar_t **);
yading@10 275
yading@10 276 void libAVFilter_Destroy(libAVFilter *);
yading@10 277 libAVFilter *libAVFilter_Create (void *, void *, enum dshowDeviceType);
yading@10 278
yading@10 279 #endif /* AVDEVICE_DSHOW_H */