Imported Debian version 2.5.0~trusty1.1
[deb_ffmpeg.git] / ffmpeg / libavdevice / dshow_capture.h
CommitLineData
2ba45a60
DM
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_H
23#define AVDEVICE_DSHOW_H
24
25#define DSHOWDEBUG 0
26
27#include "avdevice.h"
28
29#define COBJMACROS
f6fa7814 30#define WIN32_LEAN_AND_MEAN
2ba45a60
DM
31#include <windows.h>
32#define NO_DSHOW_STRSAFE
33#include <dshow.h>
34#include <dvdmedia.h>
35
36/* EC_DEVICE_LOST is not defined in MinGW dshow headers. */
37#ifndef EC_DEVICE_LOST
38#define EC_DEVICE_LOST 0x1f
39#endif
40
41long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src);
42void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps);
43void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps);
44void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type);
45void ff_printGUID(const GUID *g);
46
47#if DSHOWDEBUG
48extern const AVClass *ff_dshow_context_class_ptr;
49#define dshowdebug(...) av_log(&ff_dshow_context_class_ptr, AV_LOG_DEBUG, __VA_ARGS__)
50#else
51#define dshowdebug(...)
52#endif
53
54static inline void nothing(void *foo)
55{
56}
57
58struct GUIDoffset {
59 const GUID *iid;
60 int offset;
61};
62
63enum dshowDeviceType {
64 VideoDevice = 0,
65 AudioDevice = 1,
66};
67
68#define DECLARE_QUERYINTERFACE(class, ...) \
69long WINAPI \
70class##_QueryInterface(class *this, const GUID *riid, void **ppvObject) \
71{ \
72 struct GUIDoffset ifaces[] = __VA_ARGS__; \
73 int i; \
74 dshowdebug(AV_STRINGIFY(class)"_QueryInterface(%p, %p, %p)\n", this, riid, ppvObject); \
75 ff_printGUID(riid); \
76 if (!ppvObject) \
77 return E_POINTER; \
78 for (i = 0; i < sizeof(ifaces)/sizeof(ifaces[0]); i++) { \
79 if (IsEqualGUID(riid, ifaces[i].iid)) { \
80 void *obj = (void *) ((uint8_t *) this + ifaces[i].offset); \
81 class##_AddRef(this); \
82 dshowdebug("\tfound %d with offset %d\n", i, ifaces[i].offset); \
83 *ppvObject = (void *) obj; \
84 return S_OK; \
85 } \
86 } \
87 dshowdebug("\tE_NOINTERFACE\n"); \
88 *ppvObject = NULL; \
89 return E_NOINTERFACE; \
90}
91#define DECLARE_ADDREF(class) \
92unsigned long WINAPI \
93class##_AddRef(class *this) \
94{ \
95 dshowdebug(AV_STRINGIFY(class)"_AddRef(%p)\t%ld\n", this, this->ref+1); \
96 return InterlockedIncrement(&this->ref); \
97}
98#define DECLARE_RELEASE(class) \
99unsigned long WINAPI \
100class##_Release(class *this) \
101{ \
102 long ref = InterlockedDecrement(&this->ref); \
103 dshowdebug(AV_STRINGIFY(class)"_Release(%p)\t%ld\n", this, ref); \
104 if (!ref) \
105 class##_Destroy(this); \
106 return ref; \
107}
108
109#define DECLARE_DESTROY(class, func) \
110void class##_Destroy(class *this) \
111{ \
112 dshowdebug(AV_STRINGIFY(class)"_Destroy(%p)\n", this); \
113 func(this); \
114 if (this) { \
115 if (this->vtbl) \
116 CoTaskMemFree(this->vtbl); \
117 CoTaskMemFree(this); \
118 } \
119}
120#define DECLARE_CREATE(class, setup, ...) \
121class *class##_Create(__VA_ARGS__) \
122{ \
123 class *this = CoTaskMemAlloc(sizeof(class)); \
124 void *vtbl = CoTaskMemAlloc(sizeof(*this->vtbl)); \
125 dshowdebug(AV_STRINGIFY(class)"_Create(%p)\n", this); \
126 if (!this || !vtbl) \
127 goto fail; \
128 ZeroMemory(this, sizeof(class)); \
129 ZeroMemory(vtbl, sizeof(*this->vtbl)); \
130 this->ref = 1; \
131 this->vtbl = vtbl; \
132 if (!setup) \
133 goto fail; \
134 dshowdebug("created "AV_STRINGIFY(class)" %p\n", this); \
135 return this; \
136fail: \
137 class##_Destroy(this); \
138 dshowdebug("could not create "AV_STRINGIFY(class)"\n"); \
139 return NULL; \
140}
141
142#define SETVTBL(vtbl, class, fn) \
143 do { (vtbl)->fn = (void *) class##_##fn; } while(0)
144
145/*****************************************************************************
146 * Forward Declarations
147 ****************************************************************************/
148typedef struct libAVPin libAVPin;
149typedef struct libAVMemInputPin libAVMemInputPin;
150typedef struct libAVEnumPins libAVEnumPins;
151typedef struct libAVEnumMediaTypes libAVEnumMediaTypes;
152typedef struct libAVFilter libAVFilter;
153
154/*****************************************************************************
155 * libAVPin
156 ****************************************************************************/
157struct libAVPin {
158 IPinVtbl *vtbl;
159 long ref;
160 libAVFilter *filter;
161 IPin *connectedto;
162 AM_MEDIA_TYPE type;
163 IMemInputPinVtbl *imemvtbl;
164};
165
166long WINAPI libAVPin_QueryInterface (libAVPin *, const GUID *, void **);
167unsigned long WINAPI libAVPin_AddRef (libAVPin *);
168unsigned long WINAPI libAVPin_Release (libAVPin *);
169long WINAPI libAVPin_Connect (libAVPin *, IPin *, const AM_MEDIA_TYPE *);
170long WINAPI libAVPin_ReceiveConnection (libAVPin *, IPin *, const AM_MEDIA_TYPE *);
171long WINAPI libAVPin_Disconnect (libAVPin *);
172long WINAPI libAVPin_ConnectedTo (libAVPin *, IPin **);
173long WINAPI libAVPin_ConnectionMediaType (libAVPin *, AM_MEDIA_TYPE *);
174long WINAPI libAVPin_QueryPinInfo (libAVPin *, PIN_INFO *);
175long WINAPI libAVPin_QueryDirection (libAVPin *, PIN_DIRECTION *);
176long WINAPI libAVPin_QueryId (libAVPin *, wchar_t **);
177long WINAPI libAVPin_QueryAccept (libAVPin *, const AM_MEDIA_TYPE *);
178long WINAPI libAVPin_EnumMediaTypes (libAVPin *, IEnumMediaTypes **);
179long WINAPI libAVPin_QueryInternalConnections(libAVPin *, IPin **, unsigned long *);
180long WINAPI libAVPin_EndOfStream (libAVPin *);
181long WINAPI libAVPin_BeginFlush (libAVPin *);
182long WINAPI libAVPin_EndFlush (libAVPin *);
183long WINAPI libAVPin_NewSegment (libAVPin *, REFERENCE_TIME, REFERENCE_TIME, double);
184
185long WINAPI libAVMemInputPin_QueryInterface (libAVMemInputPin *, const GUID *, void **);
186unsigned long WINAPI libAVMemInputPin_AddRef (libAVMemInputPin *);
187unsigned long WINAPI libAVMemInputPin_Release (libAVMemInputPin *);
188long WINAPI libAVMemInputPin_GetAllocator (libAVMemInputPin *, IMemAllocator **);
189long WINAPI libAVMemInputPin_NotifyAllocator (libAVMemInputPin *, IMemAllocator *, BOOL);
190long WINAPI libAVMemInputPin_GetAllocatorRequirements(libAVMemInputPin *, ALLOCATOR_PROPERTIES *);
191long WINAPI libAVMemInputPin_Receive (libAVMemInputPin *, IMediaSample *);
192long WINAPI libAVMemInputPin_ReceiveMultiple (libAVMemInputPin *, IMediaSample **, long, long *);
193long WINAPI libAVMemInputPin_ReceiveCanBlock (libAVMemInputPin *);
194
195void libAVPin_Destroy(libAVPin *);
196libAVPin *libAVPin_Create (libAVFilter *filter);
197
198void libAVMemInputPin_Destroy(libAVMemInputPin *);
199
200/*****************************************************************************
201 * libAVEnumPins
202 ****************************************************************************/
203struct libAVEnumPins {
204 IEnumPinsVtbl *vtbl;
205 long ref;
206 int pos;
207 libAVPin *pin;
208 libAVFilter *filter;
209};
210
211long WINAPI libAVEnumPins_QueryInterface(libAVEnumPins *, const GUID *, void **);
212unsigned long WINAPI libAVEnumPins_AddRef (libAVEnumPins *);
213unsigned long WINAPI libAVEnumPins_Release (libAVEnumPins *);
214long WINAPI libAVEnumPins_Next (libAVEnumPins *, unsigned long, IPin **, unsigned long *);
215long WINAPI libAVEnumPins_Skip (libAVEnumPins *, unsigned long);
216long WINAPI libAVEnumPins_Reset (libAVEnumPins *);
217long WINAPI libAVEnumPins_Clone (libAVEnumPins *, libAVEnumPins **);
218
219void libAVEnumPins_Destroy(libAVEnumPins *);
220libAVEnumPins *libAVEnumPins_Create (libAVPin *pin, libAVFilter *filter);
221
222/*****************************************************************************
223 * libAVEnumMediaTypes
224 ****************************************************************************/
225struct libAVEnumMediaTypes {
226 IEnumPinsVtbl *vtbl;
227 long ref;
228 int pos;
229 AM_MEDIA_TYPE type;
230};
231
232long WINAPI libAVEnumMediaTypes_QueryInterface(libAVEnumMediaTypes *, const GUID *, void **);
233unsigned long WINAPI libAVEnumMediaTypes_AddRef (libAVEnumMediaTypes *);
234unsigned long WINAPI libAVEnumMediaTypes_Release (libAVEnumMediaTypes *);
235long WINAPI libAVEnumMediaTypes_Next (libAVEnumMediaTypes *, unsigned long, AM_MEDIA_TYPE **, unsigned long *);
236long WINAPI libAVEnumMediaTypes_Skip (libAVEnumMediaTypes *, unsigned long);
237long WINAPI libAVEnumMediaTypes_Reset (libAVEnumMediaTypes *);
238long WINAPI libAVEnumMediaTypes_Clone (libAVEnumMediaTypes *, libAVEnumMediaTypes **);
239
240void libAVEnumMediaTypes_Destroy(libAVEnumMediaTypes *);
241libAVEnumMediaTypes *libAVEnumMediaTypes_Create(const AM_MEDIA_TYPE *type);
242
243/*****************************************************************************
244 * libAVFilter
245 ****************************************************************************/
246struct libAVFilter {
247 IBaseFilterVtbl *vtbl;
248 long ref;
249 const wchar_t *name;
250 libAVPin *pin;
251 FILTER_INFO info;
252 FILTER_STATE state;
253 IReferenceClock *clock;
254 enum dshowDeviceType type;
255 void *priv_data;
256 int stream_index;
257 int64_t start_time;
258 void (*callback)(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType type);
259};
260
261long WINAPI libAVFilter_QueryInterface (libAVFilter *, const GUID *, void **);
262unsigned long WINAPI libAVFilter_AddRef (libAVFilter *);
263unsigned long WINAPI libAVFilter_Release (libAVFilter *);
264long WINAPI libAVFilter_GetClassID (libAVFilter *, CLSID *);
265long WINAPI libAVFilter_Stop (libAVFilter *);
266long WINAPI libAVFilter_Pause (libAVFilter *);
267long WINAPI libAVFilter_Run (libAVFilter *, REFERENCE_TIME);
268long WINAPI libAVFilter_GetState (libAVFilter *, DWORD, FILTER_STATE *);
269long WINAPI libAVFilter_SetSyncSource (libAVFilter *, IReferenceClock *);
270long WINAPI libAVFilter_GetSyncSource (libAVFilter *, IReferenceClock **);
271long WINAPI libAVFilter_EnumPins (libAVFilter *, IEnumPins **);
272long WINAPI libAVFilter_FindPin (libAVFilter *, const wchar_t *, IPin **);
273long WINAPI libAVFilter_QueryFilterInfo(libAVFilter *, FILTER_INFO *);
274long WINAPI libAVFilter_JoinFilterGraph(libAVFilter *, IFilterGraph *, const wchar_t *);
275long WINAPI libAVFilter_QueryVendorInfo(libAVFilter *, wchar_t **);
276
277void libAVFilter_Destroy(libAVFilter *);
278libAVFilter *libAVFilter_Create (void *, void *, enum dshowDeviceType);
279
280#endif /* AVDEVICE_DSHOW_H */