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 #include <windows.h>
31 #define NO_DSHOW_STRSAFE
32 #include <dshow.h>
33 #include <dvdmedia.h>
34
37
38 /* EC_DEVICE_LOST is not defined in MinGW dshow headers. */
39 #ifndef EC_DEVICE_LOST
40 #define EC_DEVICE_LOST 0x1f
41 #endif
42
48
50 #define dshowdebug(...) ff_dlog(&ff_dshow_context_class_ptr, __VA_ARGS__)
51
53 {
54 }
55
59 };
60
64 };
65
69 };
70
71 #define DECLARE_QUERYINTERFACE(prefix, class, ...) \
72 long WINAPI \
73 ff_dshow_##prefix##_QueryInterface(class *this, const GUID *riid, void **ppvObject) \
74 { \
75 struct GUIDoffset ifaces[] = __VA_ARGS__; \
76 int i; \
77 dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_QueryInterface(%p, %p, %p)\n", this, riid, ppvObject); \
78 ff_printGUID(riid); \
79 if (!ppvObject) \
80 return E_POINTER; \
81 for (i = 0; i < sizeof(ifaces)/sizeof(ifaces[0]); i++) { \
82 if (IsEqualGUID(riid, ifaces[i].iid)) { \
83 void *obj = (void *) ((uint8_t *) this + ifaces[i].offset); \
84 ff_dshow_##prefix##_AddRef(this); \
85 dshowdebug("\tfound %d with offset %d\n", i, ifaces[i].offset); \
86 *ppvObject = (void *) obj; \
87 return S_OK; \
88 } \
89 } \
90 dshowdebug("\tE_NOINTERFACE\n"); \
91 *ppvObject = NULL; \
92 return E_NOINTERFACE; \
93 }
94 #define DECLARE_ADDREF(prefix, class) \
95 unsigned long WINAPI \
96 ff_dshow_##prefix##_AddRef(class *this) \
97 { \
98 dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_AddRef(%p)\t%ld\n", this, this->ref+1); \
99 return InterlockedIncrement(&this->ref); \
100 }
101 #define DECLARE_RELEASE(prefix, class) \
102 unsigned long WINAPI \
103 ff_dshow_##prefix##_Release(class *this) \
104 { \
105 long ref = InterlockedDecrement(&this->ref); \
106 dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_Release(%p)\t%ld\n", this, ref); \
107 if (!ref) \
108 ff_dshow_##prefix##_Destroy(this); \
109 return ref; \
110 }
111
112 #define DECLARE_DESTROY(prefix, class, func) \
113 void ff_dshow_##prefix##_Destroy(class *this) \
114 { \
115 dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_Destroy(%p)\n", this); \
116 func(this); \
117 if (this) { \
118 if (this->vtbl) \
119 CoTaskMemFree(this->vtbl); \
120 CoTaskMemFree(this); \
121 } \
122 }
123 #define DECLARE_CREATE(prefix, class, setup, ...) \
124 class *ff_dshow_##prefix##_Create(__VA_ARGS__) \
125 { \
126 class *this = CoTaskMemAlloc(sizeof(class)); \
127 dshowdebug("ff_dshow_"AV_STRINGIFY(prefix)"_Create(%p)\n", this); \
128 if (!this) \
129 goto fail; \
130 ZeroMemory(this, sizeof(class)); \
131 this->vtbl = CoTaskMemAlloc(sizeof(*this->vtbl)); \
132 if (!this->vtbl) \
133 goto fail; \
134 ZeroMemory(this->vtbl, sizeof(*this->vtbl)); \
135 this->ref = 1; \
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 */