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