1 /*
2 * DirectShow capture interface
3 * Copyright (c) 2010 Ramiro Polla
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef AVDEVICE_DSHOW_CAPTURE_H
23 #define AVDEVICE_DSHOW_CAPTURE_H
24
26
28
30 #define WIN32_LEAN_AND_MEAN
31 #include <windows.h>
32 #define NO_DSHOW_STRSAFE
33 #include <dshow.h>
34 #include <dvdmedia.h>
35
38
39 /* EC_DEVICE_LOST is not defined in MinGW dshow headers. */
40 #ifndef EC_DEVICE_LOST
41 #define EC_DEVICE_LOST 0x1f
42 #endif
43
49
51 #define dshowdebug(...) ff_dlog(&ff_dshow_context_class_ptr, __VA_ARGS__)
52
54 {
55 }
56
60 };
61
65 };
66
70 };
71
72 #define DECLARE_QUERYINTERFACE(prefix, class, ...) \
73 long WINAPI \
74 ff_dshow_##prefix##_QueryInterface(class *this, const GUID *riid, void **ppvObject) \
75 { \
76 struct GUIDoffset ifaces[] = __VA_ARGS__; \
77 int i; \
78 dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_QueryInterface(%p, %p, %p)\n", this, riid, ppvObject); \
79 ff_printGUID(riid); \
80 if (!ppvObject) \
81 return E_POINTER; \
82 for (i = 0; i < sizeof(ifaces)/sizeof(ifaces[0]); i++) { \
83 if (IsEqualGUID(riid, ifaces[i].iid)) { \
84 void *obj = (void *) ((uint8_t *) this + ifaces[i].offset); \
85 ff_dshow_##prefix##_AddRef(this); \
86 dshowdebug("\tfound %d with offset %d\n", i, ifaces[i].offset); \
87 *ppvObject = (void *) obj; \
88 return S_OK; \
89 } \
90 } \
91 dshowdebug("\tE_NOINTERFACE\n"); \
92 *ppvObject = NULL; \
93 return E_NOINTERFACE; \
94 }
95 #define DECLARE_ADDREF(prefix, class) \
96 unsigned long WINAPI \
97 ff_dshow_##prefix##_AddRef(class *this) \
98 { \
99 dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_AddRef(%p)\t%ld\n", this, this->ref+1); \
100 return InterlockedIncrement(&this->ref); \
101 }
102 #define DECLARE_RELEASE(prefix, class) \
103 unsigned long WINAPI \
104 ff_dshow_##prefix##_Release(class *this) \
105 { \
106 long ref = InterlockedDecrement(&this->ref); \
107 dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_Release(%p)\t%ld\n", this, ref); \
108 if (!ref) \
109 ff_dshow_##prefix##_Destroy(this); \
110 return ref; \
111 }
112
113 #define DECLARE_DESTROY(prefix, class, func) \
114 void ff_dshow_##prefix##_Destroy(class *this) \
115 { \
116 dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_Destroy(%p)\n", this); \
117 func(this); \
118 if (this) { \
119 if (this->vtbl) \
120 CoTaskMemFree(this->vtbl); \
121 CoTaskMemFree(this); \
122 } \
123 }
124 #define DECLARE_CREATE(prefix, class, setup, ...) \
125 class *ff_dshow_##prefix##_Create(__VA_ARGS__) \
126 { \
127 class *this = CoTaskMemAlloc(sizeof(class)); \
128 void *vtbl = CoTaskMemAlloc(sizeof(*this->vtbl)); \
129 dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_Create(%p)\n", this); \
130 if (!this || !vtbl) \
131 goto fail; \
132 ZeroMemory(this, sizeof(class)); \
133 ZeroMemory(vtbl, sizeof(*this->vtbl)); \
134 this->ref = 1; \
135 this->vtbl = vtbl; \
136 if (!setup) \
137 goto fail; \
138 dshowdebug("created ff_dshow_"AV_STRINGIFY(prefix)" %p\n", this); \
139 return this; \
140 fail: \
141 ff_dshow_##prefix##_Destroy(this); \
142 dshowdebug("could not create ff_dshow_"AV_STRINGIFY(prefix)"\n"); \
143 return NULL; \
144 }
145
146 #define SETVTBL(vtbl, prefix, fn) \
147 do { (vtbl)->fn = (void *) ff_dshow_##prefix##_##fn; } while(0)
148
149 /*****************************************************************************
150 * Forward Declarations
151 ****************************************************************************/
157
158 /*****************************************************************************
159 * DShowPin
160 ****************************************************************************/
188
198
201
203
204 /*****************************************************************************
205 * DShowEnumPins
206 ****************************************************************************/
222
225
226 /*****************************************************************************
227 * DShowEnumMediaTypes
228 ****************************************************************************/
230 IEnumMediaTypesVtbl *
vtbl;
243
246
247 /*****************************************************************************
248 * DShowFilter
249 ****************************************************************************/
251 IBaseFilterVtbl *
vtbl;
280
283
284 /*****************************************************************************
285 * dshow_ctx
286 ****************************************************************************/
289
291
323 HANDLE event[2]; /* event[0] is set by DirectShow
324 * event[1] is set by callback() */
326
328
348 /*****************************************************************************
349 * CrossBar
350 ****************************************************************************/
353
355
356 #endif /* AVDEVICE_DSHOW_CAPTURE_H */