00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef AVDEVICE_DSHOW_H
00023 #define AVDEVICE_DSHOW_H
00024
00025 #define DSHOWDEBUG 0
00026
00027 #include "avdevice.h"
00028
00029 #define COBJMACROS
00030 #include <windows.h>
00031 #include <dshow.h>
00032 #include <dvdmedia.h>
00033
00034 long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src);
00035 void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps);
00036 void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps);
00037 void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type);
00038 void ff_printGUID(const GUID *g);
00039
00040 #if DSHOWDEBUG
00041 extern const AVClass *ff_dshow_context_class_ptr;
00042 #define dshowdebug(...) av_log(&ff_dshow_context_class_ptr, AV_LOG_DEBUG, __VA_ARGS__)
00043 #else
00044 #define dshowdebug(...)
00045 #endif
00046
00047 static inline void nothing(void *foo)
00048 {
00049 }
00050
00051 struct GUIDoffset {
00052 const GUID *iid;
00053 int offset;
00054 };
00055
00056 enum dshowDeviceType {
00057 VideoDevice = 0,
00058 AudioDevice = 1,
00059 };
00060
00061 #define DECLARE_QUERYINTERFACE(class, ...) \
00062 long WINAPI \
00063 class##_QueryInterface(class *this, const GUID *riid, void **ppvObject) \
00064 { \
00065 struct GUIDoffset ifaces[] = __VA_ARGS__; \
00066 int i; \
00067 dshowdebug(AV_STRINGIFY(class)"_QueryInterface(%p, %p, %p)\n", this, riid, ppvObject); \
00068 ff_printGUID(riid); \
00069 if (!ppvObject) \
00070 return E_POINTER; \
00071 for (i = 0; i < sizeof(ifaces)/sizeof(ifaces[0]); i++) { \
00072 if (IsEqualGUID(riid, ifaces[i].iid)) { \
00073 void *obj = (void *) ((uint8_t *) this + ifaces[i].offset); \
00074 class##_AddRef(this); \
00075 dshowdebug("\tfound %d with offset %d\n", i, ifaces[i].offset); \
00076 *ppvObject = (void *) obj; \
00077 return S_OK; \
00078 } \
00079 } \
00080 dshowdebug("\tE_NOINTERFACE\n"); \
00081 *ppvObject = NULL; \
00082 return E_NOINTERFACE; \
00083 }
00084 #define DECLARE_ADDREF(class) \
00085 unsigned long WINAPI \
00086 class##_AddRef(class *this) \
00087 { \
00088 dshowdebug(AV_STRINGIFY(class)"_AddRef(%p)\t%ld\n", this, this->ref+1); \
00089 return InterlockedIncrement(&this->ref); \
00090 }
00091 #define DECLARE_RELEASE(class) \
00092 unsigned long WINAPI \
00093 class##_Release(class *this) \
00094 { \
00095 long ref = InterlockedDecrement(&this->ref); \
00096 dshowdebug(AV_STRINGIFY(class)"_Release(%p)\t%ld\n", this, ref); \
00097 if (!ref) \
00098 class##_Destroy(this); \
00099 return ref; \
00100 }
00101
00102 #define DECLARE_DESTROY(class, func) \
00103 void class##_Destroy(class *this) \
00104 { \
00105 dshowdebug(AV_STRINGIFY(class)"_Destroy(%p)\n", this); \
00106 func(this); \
00107 if (this) { \
00108 if (this->vtbl) \
00109 CoTaskMemFree(this->vtbl); \
00110 CoTaskMemFree(this); \
00111 } \
00112 }
00113 #define DECLARE_CREATE(class, setup, ...) \
00114 class *class##_Create(__VA_ARGS__) \
00115 { \
00116 class *this = CoTaskMemAlloc(sizeof(class)); \
00117 void *vtbl = CoTaskMemAlloc(sizeof(*this->vtbl)); \
00118 dshowdebug(AV_STRINGIFY(class)"_Create(%p)\n", this); \
00119 if (!this || !vtbl) \
00120 goto fail; \
00121 ZeroMemory(this, sizeof(class)); \
00122 ZeroMemory(vtbl, sizeof(*this->vtbl)); \
00123 this->ref = 1; \
00124 this->vtbl = vtbl; \
00125 if (!setup) \
00126 goto fail; \
00127 dshowdebug("created "AV_STRINGIFY(class)" %p\n", this); \
00128 return this; \
00129 fail: \
00130 class##_Destroy(this); \
00131 dshowdebug("could not create "AV_STRINGIFY(class)"\n"); \
00132 return NULL; \
00133 }
00134
00135 #define SETVTBL(vtbl, class, fn) \
00136 do { (vtbl)->fn = (void *) class##_##fn; } while(0)
00137
00138
00139
00140
00141 typedef struct libAVPin libAVPin;
00142 typedef struct libAVMemInputPin libAVMemInputPin;
00143 typedef struct libAVEnumPins libAVEnumPins;
00144 typedef struct libAVEnumMediaTypes libAVEnumMediaTypes;
00145 typedef struct libAVFilter libAVFilter;
00146
00147
00148
00149
00150 struct libAVPin {
00151 IPinVtbl *vtbl;
00152 long ref;
00153 libAVFilter *filter;
00154 IPin *connectedto;
00155 AM_MEDIA_TYPE type;
00156 IMemInputPinVtbl *imemvtbl;
00157 };
00158
00159 long WINAPI libAVPin_QueryInterface (libAVPin *, const GUID *, void **);
00160 unsigned long WINAPI libAVPin_AddRef (libAVPin *);
00161 unsigned long WINAPI libAVPin_Release (libAVPin *);
00162 long WINAPI libAVPin_Connect (libAVPin *, IPin *, const AM_MEDIA_TYPE *);
00163 long WINAPI libAVPin_ReceiveConnection (libAVPin *, IPin *, const AM_MEDIA_TYPE *);
00164 long WINAPI libAVPin_Disconnect (libAVPin *);
00165 long WINAPI libAVPin_ConnectedTo (libAVPin *, IPin **);
00166 long WINAPI libAVPin_ConnectionMediaType (libAVPin *, AM_MEDIA_TYPE *);
00167 long WINAPI libAVPin_QueryPinInfo (libAVPin *, PIN_INFO *);
00168 long WINAPI libAVPin_QueryDirection (libAVPin *, PIN_DIRECTION *);
00169 long WINAPI libAVPin_QueryId (libAVPin *, wchar_t **);
00170 long WINAPI libAVPin_QueryAccept (libAVPin *, const AM_MEDIA_TYPE *);
00171 long WINAPI libAVPin_EnumMediaTypes (libAVPin *, IEnumMediaTypes **);
00172 long WINAPI libAVPin_QueryInternalConnections(libAVPin *, IPin **, unsigned long *);
00173 long WINAPI libAVPin_EndOfStream (libAVPin *);
00174 long WINAPI libAVPin_BeginFlush (libAVPin *);
00175 long WINAPI libAVPin_EndFlush (libAVPin *);
00176 long WINAPI libAVPin_NewSegment (libAVPin *, REFERENCE_TIME, REFERENCE_TIME, double);
00177
00178 long WINAPI libAVMemInputPin_QueryInterface (libAVMemInputPin *, const GUID *, void **);
00179 unsigned long WINAPI libAVMemInputPin_AddRef (libAVMemInputPin *);
00180 unsigned long WINAPI libAVMemInputPin_Release (libAVMemInputPin *);
00181 long WINAPI libAVMemInputPin_GetAllocator (libAVMemInputPin *, IMemAllocator **);
00182 long WINAPI libAVMemInputPin_NotifyAllocator (libAVMemInputPin *, IMemAllocator *, WINBOOL);
00183 long WINAPI libAVMemInputPin_GetAllocatorRequirements(libAVMemInputPin *, ALLOCATOR_PROPERTIES *);
00184 long WINAPI libAVMemInputPin_Receive (libAVMemInputPin *, IMediaSample *);
00185 long WINAPI libAVMemInputPin_ReceiveMultiple (libAVMemInputPin *, IMediaSample **, long, long *);
00186 long WINAPI libAVMemInputPin_ReceiveCanBlock (libAVMemInputPin *);
00187
00188 void libAVPin_Destroy(libAVPin *);
00189 libAVPin *libAVPin_Create (libAVFilter *filter);
00190
00191 void libAVMemInputPin_Destroy(libAVMemInputPin *);
00192
00193
00194
00195
00196 struct libAVEnumPins {
00197 IEnumPinsVtbl *vtbl;
00198 long ref;
00199 int pos;
00200 libAVPin *pin;
00201 libAVFilter *filter;
00202 };
00203
00204 long WINAPI libAVEnumPins_QueryInterface(libAVEnumPins *, const GUID *, void **);
00205 unsigned long WINAPI libAVEnumPins_AddRef (libAVEnumPins *);
00206 unsigned long WINAPI libAVEnumPins_Release (libAVEnumPins *);
00207 long WINAPI libAVEnumPins_Next (libAVEnumPins *, unsigned long, IPin **, unsigned long *);
00208 long WINAPI libAVEnumPins_Skip (libAVEnumPins *, unsigned long);
00209 long WINAPI libAVEnumPins_Reset (libAVEnumPins *);
00210 long WINAPI libAVEnumPins_Clone (libAVEnumPins *, libAVEnumPins **);
00211
00212 void libAVEnumPins_Destroy(libAVEnumPins *);
00213 libAVEnumPins *libAVEnumPins_Create (libAVPin *pin, libAVFilter *filter);
00214
00215
00216
00217
00218 struct libAVEnumMediaTypes {
00219 IEnumPinsVtbl *vtbl;
00220 long ref;
00221 int pos;
00222 AM_MEDIA_TYPE type;
00223 };
00224
00225 long WINAPI libAVEnumMediaTypes_QueryInterface(libAVEnumMediaTypes *, const GUID *, void **);
00226 unsigned long WINAPI libAVEnumMediaTypes_AddRef (libAVEnumMediaTypes *);
00227 unsigned long WINAPI libAVEnumMediaTypes_Release (libAVEnumMediaTypes *);
00228 long WINAPI libAVEnumMediaTypes_Next (libAVEnumMediaTypes *, unsigned long, AM_MEDIA_TYPE **, unsigned long *);
00229 long WINAPI libAVEnumMediaTypes_Skip (libAVEnumMediaTypes *, unsigned long);
00230 long WINAPI libAVEnumMediaTypes_Reset (libAVEnumMediaTypes *);
00231 long WINAPI libAVEnumMediaTypes_Clone (libAVEnumMediaTypes *, libAVEnumMediaTypes **);
00232
00233 void libAVEnumMediaTypes_Destroy(libAVEnumMediaTypes *);
00234 libAVEnumMediaTypes *libAVEnumMediaTypes_Create(const AM_MEDIA_TYPE *type);
00235
00236
00237
00238
00239 struct libAVFilter {
00240 IBaseFilterVtbl *vtbl;
00241 long ref;
00242 const wchar_t *name;
00243 libAVPin *pin;
00244 FILTER_INFO info;
00245 FILTER_STATE state;
00246 IReferenceClock *clock;
00247 enum dshowDeviceType type;
00248 void *priv_data;
00249 int stream_index;
00250 int64_t start_time;
00251 void (*callback)(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time);
00252 };
00253
00254 long WINAPI libAVFilter_QueryInterface (libAVFilter *, const GUID *, void **);
00255 unsigned long WINAPI libAVFilter_AddRef (libAVFilter *);
00256 unsigned long WINAPI libAVFilter_Release (libAVFilter *);
00257 long WINAPI libAVFilter_GetClassID (libAVFilter *, CLSID *);
00258 long WINAPI libAVFilter_Stop (libAVFilter *);
00259 long WINAPI libAVFilter_Pause (libAVFilter *);
00260 long WINAPI libAVFilter_Run (libAVFilter *, REFERENCE_TIME);
00261 long WINAPI libAVFilter_GetState (libAVFilter *, DWORD, FILTER_STATE *);
00262 long WINAPI libAVFilter_SetSyncSource (libAVFilter *, IReferenceClock *);
00263 long WINAPI libAVFilter_GetSyncSource (libAVFilter *, IReferenceClock **);
00264 long WINAPI libAVFilter_EnumPins (libAVFilter *, IEnumPins **);
00265 long WINAPI libAVFilter_FindPin (libAVFilter *, const wchar_t *, IPin **);
00266 long WINAPI libAVFilter_QueryFilterInfo(libAVFilter *, FILTER_INFO *);
00267 long WINAPI libAVFilter_JoinFilterGraph(libAVFilter *, IFilterGraph *, const wchar_t *);
00268 long WINAPI libAVFilter_QueryVendorInfo(libAVFilter *, wchar_t **);
00269
00270 void libAVFilter_Destroy(libAVFilter *);
00271 libAVFilter *libAVFilter_Create (void *, void *, enum dshowDeviceType);
00272
00273 #endif