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