FFmpeg
Loading...
Searching...
No Matches
dshow_capture.h
Go to the documentation of this file.
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
25#define DSHOWDEBUG 0
26
27#include "avdevice.h"
28
29#define COBJMACROS
30#include <windows.h>
31#define NO_DSHOW_STRSAFE
32#include <dshow.h>
33#include <dvdmedia.h>
34
35#include "libavcodec/internal.h"
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
43long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src);
44void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps);
45void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps);
46void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type);
47void ff_printGUID(const GUID *g);
48
50#define dshowdebug(...) ff_dlog(&ff_dshow_context_class_ptr, __VA_ARGS__)
51
52static inline void nothing(void *foo)
53{
54}
55
56struct GUIDoffset {
57 const GUID *iid;
58 int offset;
59};
60
65
70
71#define DECLARE_QUERYINTERFACE(prefix, class, ...) \
72long WINAPI \
73ff_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) \
95unsigned long WINAPI \
96ff_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) \
102unsigned long WINAPI \
103ff_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) \
113void 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, ...) \
124class *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; \
140fail: \
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 ****************************************************************************/
152typedef struct DShowPin DShowPin;
154typedef struct DShowEnumPins DShowEnumPins;
156typedef struct DShowFilter DShowFilter;
157
158/*****************************************************************************
159 * DShowPin
160 ****************************************************************************/
161struct DShowPin {
162 IPinVtbl *vtbl;
163 long ref;
166 AM_MEDIA_TYPE type;
167 IMemInputPinVtbl *imemvtbl;
168};
169
170long WINAPI ff_dshow_pin_QueryInterface (DShowPin *, const GUID *, void **);
171unsigned long WINAPI ff_dshow_pin_AddRef (DShowPin *);
172unsigned long WINAPI ff_dshow_pin_Release (DShowPin *);
173long WINAPI ff_dshow_pin_Connect (DShowPin *, IPin *, const AM_MEDIA_TYPE *);
174long WINAPI ff_dshow_pin_ReceiveConnection (DShowPin *, IPin *, const AM_MEDIA_TYPE *);
175long WINAPI ff_dshow_pin_Disconnect (DShowPin *);
176long WINAPI ff_dshow_pin_ConnectedTo (DShowPin *, IPin **);
177long WINAPI ff_dshow_pin_ConnectionMediaType (DShowPin *, AM_MEDIA_TYPE *);
178long WINAPI ff_dshow_pin_QueryPinInfo (DShowPin *, PIN_INFO *);
179long WINAPI ff_dshow_pin_QueryDirection (DShowPin *, PIN_DIRECTION *);
180long WINAPI ff_dshow_pin_QueryId (DShowPin *, wchar_t **);
181long WINAPI ff_dshow_pin_QueryAccept (DShowPin *, const AM_MEDIA_TYPE *);
182long WINAPI ff_dshow_pin_EnumMediaTypes (DShowPin *, IEnumMediaTypes **);
183long WINAPI ff_dshow_pin_QueryInternalConnections(DShowPin *, IPin **, unsigned long *);
184long WINAPI ff_dshow_pin_EndOfStream (DShowPin *);
185long WINAPI ff_dshow_pin_BeginFlush (DShowPin *);
186long WINAPI ff_dshow_pin_EndFlush (DShowPin *);
187long WINAPI ff_dshow_pin_NewSegment (DShowPin *, REFERENCE_TIME, REFERENCE_TIME, double);
188
189long WINAPI ff_dshow_meminputpin_QueryInterface (DShowMemInputPin *, const GUID *, void **);
190unsigned long WINAPI ff_dshow_meminputpin_AddRef (DShowMemInputPin *);
191unsigned long WINAPI ff_dshow_meminputpin_Release (DShowMemInputPin *);
192long WINAPI ff_dshow_meminputpin_GetAllocator (DShowMemInputPin *, IMemAllocator **);
193long WINAPI ff_dshow_meminputpin_NotifyAllocator (DShowMemInputPin *, IMemAllocator *, BOOL);
194long WINAPI ff_dshow_meminputpin_GetAllocatorRequirements(DShowMemInputPin *, ALLOCATOR_PROPERTIES *);
195long WINAPI ff_dshow_meminputpin_Receive (DShowMemInputPin *, IMediaSample *);
196long WINAPI ff_dshow_meminputpin_ReceiveMultiple (DShowMemInputPin *, IMediaSample **, long, long *);
198
201
203
204/*****************************************************************************
205 * DShowEnumPins
206 ****************************************************************************/
208 IEnumPinsVtbl *vtbl;
209 long ref;
210 int pos;
213};
214
215long WINAPI ff_dshow_enumpins_QueryInterface(DShowEnumPins *, const GUID *, void **);
218long WINAPI ff_dshow_enumpins_Next (DShowEnumPins *, unsigned long, IPin **, unsigned long *);
219long WINAPI ff_dshow_enumpins_Skip (DShowEnumPins *, unsigned long);
222
225
226/*****************************************************************************
227 * DShowEnumMediaTypes
228 ****************************************************************************/
230 IEnumMediaTypesVtbl *vtbl;
231 long ref;
232 int pos;
233 AM_MEDIA_TYPE type;
234};
235
239long WINAPI ff_dshow_enummediatypes_Next (DShowEnumMediaTypes *, unsigned long, AM_MEDIA_TYPE **, unsigned long *);
240long WINAPI ff_dshow_enummediatypes_Skip (DShowEnumMediaTypes *, unsigned long);
243
246
247/*****************************************************************************
248 * DShowFilter
249 ****************************************************************************/
251 IBaseFilterVtbl *vtbl;
252 long ref;
253 const wchar_t *name;
255 FILTER_INFO info;
256 FILTER_STATE state;
257 IReferenceClock *clock;
262 void (*callback)(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType type);
263};
264
265long WINAPI ff_dshow_filter_QueryInterface (DShowFilter *, const GUID *, void **);
266unsigned long WINAPI ff_dshow_filter_AddRef (DShowFilter *);
267unsigned long WINAPI ff_dshow_filter_Release (DShowFilter *);
269long WINAPI ff_dshow_filter_Stop (DShowFilter *);
270long WINAPI ff_dshow_filter_Pause (DShowFilter *);
271long WINAPI ff_dshow_filter_Run (DShowFilter *, REFERENCE_TIME);
272long WINAPI ff_dshow_filter_GetState (DShowFilter *, DWORD, FILTER_STATE *);
273long WINAPI ff_dshow_filter_SetSyncSource (DShowFilter *, IReferenceClock *);
274long WINAPI ff_dshow_filter_GetSyncSource (DShowFilter *, IReferenceClock **);
275long WINAPI ff_dshow_filter_EnumPins (DShowFilter *, IEnumPins **);
276long WINAPI ff_dshow_filter_FindPin (DShowFilter *, const wchar_t *, IPin **);
277long WINAPI ff_dshow_filter_QueryFilterInfo(DShowFilter *, FILTER_INFO *);
278long WINAPI ff_dshow_filter_JoinFilterGraph(DShowFilter *, IFilterGraph *, const wchar_t *);
279long WINAPI ff_dshow_filter_QueryVendorInfo(DShowFilter *, wchar_t **);
280
283
284/*****************************************************************************
285 * dshow_ctx
286 ****************************************************************************/
287struct dshow_ctx {
288 const AVClass *class;
289
290 IGraphBuilder *graph;
291
292 char *device_name[2];
294
297
316
317 IBaseFilter *device_filter[2];
318 IPin *device_pin[2];
321
322 HANDLE mutex;
323 HANDLE event[2]; /* event[0] is set by DirectShow
324 * event[1] is set by callback() */
326
327 int eof;
328
330 unsigned int video_frame_num;
331
332 IMediaControl *control;
333 IMediaEvent *media_event;
334
338
342
346};
347
348/*****************************************************************************
349 * CrossBar
350 ****************************************************************************/
351HRESULT ff_dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2,
352 IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx);
353
354void ff_dshow_show_filter_properties(IBaseFilter *pFilter, AVFormatContext *avctx);
355
356#endif /* AVDEVICE_DSHOW_CAPTURE_H */
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
Main libavdevice API header.
long long int64_t
Definition coverity.c:34
long WINAPI ff_dshow_filter_GetState(DShowFilter *, DWORD, FILTER_STATE *)
void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps)
long WINAPI ff_dshow_pin_EnumMediaTypes(DShowPin *, IEnumMediaTypes **)
Definition dshow_pin.c:143
dshowDeviceType
@ AudioDevice
@ VideoDevice
unsigned long WINAPI ff_dshow_pin_Release(DShowPin *)
DShowPin * ff_dshow_pin_Create(DShowFilter *filter)
long WINAPI ff_dshow_pin_QueryAccept(DShowPin *, const AM_MEDIA_TYPE *)
Definition dshow_pin.c:138
long WINAPI ff_dshow_filter_GetClassID(DShowFilter *, CLSID *)
const AVClass * ff_dshow_context_class_ptr
long WINAPI ff_dshow_meminputpin_ReceiveMultiple(DShowMemInputPin *, IMediaSample **, long, long *)
Definition dshow_pin.c:358
void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type)
void ff_dshow_show_filter_properties(IBaseFilter *pFilter, AVFormatContext *avctx)
Pops up a user dialog allowing them to adjust properties for the given filter, if possible.
Definition dshow.c:1123
long WINAPI ff_dshow_pin_QueryDirection(DShowPin *, PIN_DIRECTION *)
Definition dshow_pin.c:119
DShowFilter * ff_dshow_filter_Create(void *, void *, enum dshowDeviceType)
void ff_dshow_enummediatypes_Destroy(DShowEnumMediaTypes *)
long WINAPI ff_dshow_filter_FindPin(DShowFilter *, const wchar_t *, IPin **)
long WINAPI ff_dshow_enumpins_Clone(DShowEnumPins *, DShowEnumPins **)
void ff_dshow_pin_Destroy(DShowPin *)
long WINAPI ff_dshow_pin_QueryInterface(DShowPin *, const GUID *, void **)
long WINAPI ff_dshow_meminputpin_GetAllocator(DShowMemInputPin *, IMemAllocator **)
Definition dshow_pin.c:273
long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src)
long WINAPI ff_dshow_meminputpin_Receive(DShowMemInputPin *, IMediaSample *)
Definition dshow_pin.c:290
long WINAPI ff_dshow_meminputpin_QueryInterface(DShowMemInputPin *, const GUID *, void **)
Definition dshow_pin.c:254
unsigned long WINAPI ff_dshow_enumpins_AddRef(DShowEnumPins *)
void ff_dshow_enumpins_Destroy(DShowEnumPins *)
unsigned long WINAPI ff_dshow_filter_AddRef(DShowFilter *)
long WINAPI ff_dshow_filter_Run(DShowFilter *, REFERENCE_TIME)
long WINAPI ff_dshow_filter_QueryVendorInfo(DShowFilter *, wchar_t **)
long WINAPI ff_dshow_meminputpin_ReceiveCanBlock(DShowMemInputPin *)
Definition dshow_pin.c:370
unsigned long WINAPI ff_dshow_meminputpin_Release(DShowMemInputPin *)
Definition dshow_pin.c:267
long WINAPI ff_dshow_enummediatypes_Next(DShowEnumMediaTypes *, unsigned long, AM_MEDIA_TYPE **, unsigned long *)
long WINAPI ff_dshow_enummediatypes_Clone(DShowEnumMediaTypes *, DShowEnumMediaTypes **)
DShowEnumMediaTypes * ff_dshow_enummediatypes_Create(const AM_MEDIA_TYPE *type)
long WINAPI ff_dshow_enummediatypes_Reset(DShowEnumMediaTypes *)
long WINAPI ff_dshow_enummediatypes_Skip(DShowEnumMediaTypes *, unsigned long)
long WINAPI ff_dshow_filter_Pause(DShowFilter *)
long WINAPI ff_dshow_filter_SetSyncSource(DShowFilter *, IReferenceClock *)
long WINAPI ff_dshow_pin_Disconnect(DShowPin *)
Definition dshow_pin.c:66
unsigned long WINAPI ff_dshow_enumpins_Release(DShowEnumPins *)
HRESULT ff_dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 *graph_builder2, IBaseFilter *device_filter, enum dshowDeviceType devtype, AVFormatContext *avctx)
Given a fully constructed graph, check if there is a cross bar filter, and configure its pins if so.
long WINAPI ff_dshow_enumpins_Skip(DShowEnumPins *, unsigned long)
long WINAPI ff_dshow_enummediatypes_QueryInterface(DShowEnumMediaTypes *, const GUID *, void **)
long WINAPI ff_dshow_pin_EndFlush(DShowPin *)
Definition dshow_pin.c:176
DShowEnumPins * ff_dshow_enumpins_Create(DShowPin *pin, DShowFilter *filter)
long WINAPI ff_dshow_filter_EnumPins(DShowFilter *, IEnumPins **)
long WINAPI ff_dshow_enumpins_Reset(DShowEnumPins *)
long WINAPI ff_dshow_enumpins_Next(DShowEnumPins *, unsigned long, IPin **, unsigned long *)
long WINAPI ff_dshow_meminputpin_GetAllocatorRequirements(DShowMemInputPin *, ALLOCATOR_PROPERTIES *)
Definition dshow_pin.c:284
long WINAPI ff_dshow_filter_GetSyncSource(DShowFilter *, IReferenceClock **)
long WINAPI ff_dshow_filter_Stop(DShowFilter *)
struct DShowMemInputPin DShowMemInputPin
long WINAPI ff_dshow_pin_ConnectedTo(DShowPin *, IPin **)
Definition dshow_pin.c:79
unsigned long WINAPI ff_dshow_meminputpin_AddRef(DShowMemInputPin *)
Definition dshow_pin.c:261
dshowSourceFilterType
@ AudioSourceDevice
@ VideoSourceDevice
long WINAPI ff_dshow_pin_QueryPinInfo(DShowPin *, PIN_INFO *)
Definition dshow_pin.c:103
long WINAPI ff_dshow_pin_ReceiveConnection(DShowPin *, IPin *, const AM_MEDIA_TYPE *)
Definition dshow_pin.c:39
long WINAPI ff_dshow_filter_QueryFilterInfo(DShowFilter *, FILTER_INFO *)
static void nothing(void *foo)
unsigned long WINAPI ff_dshow_enummediatypes_Release(DShowEnumMediaTypes *)
long WINAPI ff_dshow_enumpins_QueryInterface(DShowEnumPins *, const GUID *, void **)
long WINAPI ff_dshow_pin_QueryInternalConnections(DShowPin *, IPin **, unsigned long *)
Definition dshow_pin.c:158
long WINAPI ff_dshow_pin_NewSegment(DShowPin *, REFERENCE_TIME, REFERENCE_TIME, double)
Definition dshow_pin.c:182
long WINAPI ff_dshow_pin_BeginFlush(DShowPin *)
Definition dshow_pin.c:170
long WINAPI ff_dshow_pin_Connect(DShowPin *, IPin *, const AM_MEDIA_TYPE *)
void ff_dshow_filter_Destroy(DShowFilter *)
long WINAPI ff_dshow_filter_QueryInterface(DShowFilter *, const GUID *, void **)
long WINAPI ff_dshow_meminputpin_NotifyAllocator(DShowMemInputPin *, IMemAllocator *, BOOL)
Definition dshow_pin.c:278
long WINAPI ff_dshow_filter_JoinFilterGraph(DShowFilter *, IFilterGraph *, const wchar_t *)
long WINAPI ff_dshow_pin_QueryId(DShowPin *, wchar_t **)
Definition dshow_pin.c:127
void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps)
void ff_dshow_meminputpin_Destroy(DShowMemInputPin *)
Definition dshow_pin.c:377
unsigned long WINAPI ff_dshow_enummediatypes_AddRef(DShowEnumMediaTypes *)
void ff_printGUID(const GUID *g)
long WINAPI ff_dshow_pin_EndOfStream(DShowPin *)
Definition dshow_pin.c:164
long WINAPI ff_dshow_pin_ConnectionMediaType(DShowPin *, AM_MEDIA_TYPE *)
Definition dshow_pin.c:92
unsigned long WINAPI ff_dshow_pin_AddRef(DShowPin *)
unsigned long WINAPI ff_dshow_filter_Release(DShowFilter *)
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
int index
Definition gxfenc.c:90
cl_device_type type
common internal api header.
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
Describe the class of an AVClass context structure.
Definition log.h:76
Format I/O context.
Definition avformat.h:1333
Rational number (pair of numerator and denominator).
Definition rational.h:58
IEnumMediaTypesVtbl * vtbl
DShowPin * pin
DShowFilter * filter
IEnumPinsVtbl * vtbl
IBaseFilterVtbl * vtbl
void(* callback)(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType type)
const wchar_t * name
int64_t start_time
FILTER_STATE state
enum dshowDeviceType type
IReferenceClock * clock
DShowPin * pin
FILTER_INFO info
DShowFilter * filter
IPin * connectedto
IPinVtbl * vtbl
AM_MEDIA_TYPE type
IMemInputPinVtbl * imemvtbl
const GUID * iid
IMediaEvent * media_event
int show_video_device_dialog
IMediaControl * control
char * audio_filter_save_file
char * device_name[2]
int crossbar_audio_input_pin_number
int show_analog_tv_tuner_audio_dialog
int requested_width
int audio_device_number
int64_t curbufsize[2]
int show_analog_tv_tuner_dialog
char * audio_filter_load_file
IGraphBuilder * graph
int show_video_crossbar_connection_dialog
AVRational requested_framerate
int show_audio_device_dialog
int show_audio_crossbar_connection_dialog
char * video_pin_name
char * video_filter_load_file
char * video_filter_save_file
int crossbar_video_input_pin_number
int audio_buffer_size
DShowPin * capture_pin[2]
enum AVCodecID video_codec_id
char * framerate
char * device_unique_name[2]
PacketListEntry * pktl
enum AVPixelFormat pixel_format
int video_device_number
int use_video_device_timestamps
IPin * device_pin[2]
unsigned int video_frame_num
char * audio_pin_name
int requested_height
IBaseFilter * device_filter[2]
DShowFilter * capture_filter[2]
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
#define src
Definition vp8dsp.c:248
const char * g
Definition vf_curves.c:128