]> git.sesse.net Git - ffmpeg/blob - libavdevice/dshow_filter.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavdevice / dshow_filter.c
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 #define NO_DSHOW_STRSAFE
23 #include "dshow_capture.h"
24
25 DECLARE_QUERYINTERFACE(libAVFilter,
26     { {&IID_IUnknown,0}, {&IID_IBaseFilter,0} })
27 DECLARE_ADDREF(libAVFilter)
28 DECLARE_RELEASE(libAVFilter)
29
30 long WINAPI
31 libAVFilter_GetClassID(libAVFilter *this, CLSID *id)
32 {
33     dshowdebug("libAVFilter_GetClassID(%p)\n", this);
34     /* I'm not creating a ClassID just for this. */
35     return E_FAIL;
36 }
37 long WINAPI
38 libAVFilter_Stop(libAVFilter *this)
39 {
40     dshowdebug("libAVFilter_Stop(%p)\n", this);
41     this->state = State_Stopped;
42     return S_OK;
43 }
44 long WINAPI
45 libAVFilter_Pause(libAVFilter *this)
46 {
47     dshowdebug("libAVFilter_Pause(%p)\n", this);
48     this->state = State_Paused;
49     return S_OK;
50 }
51 long WINAPI
52 libAVFilter_Run(libAVFilter *this, REFERENCE_TIME start)
53 {
54     dshowdebug("libAVFilter_Run(%p) %"PRId64"\n", this, start);
55     this->state = State_Running;
56     this->start_time = start;
57     return S_OK;
58 }
59 long WINAPI
60 libAVFilter_GetState(libAVFilter *this, DWORD ms, FILTER_STATE *state)
61 {
62     dshowdebug("libAVFilter_GetState(%p)\n", this);
63     if (!state)
64         return E_POINTER;
65     *state = this->state;
66     return S_OK;
67 }
68 long WINAPI
69 libAVFilter_SetSyncSource(libAVFilter *this, IReferenceClock *clock)
70 {
71     dshowdebug("libAVFilter_SetSyncSource(%p)\n", this);
72
73     if (this->clock != clock) {
74         if (this->clock)
75             IReferenceClock_Release(this->clock);
76         this->clock = clock;
77         if (clock)
78             IReferenceClock_AddRef(clock);
79     }
80
81     return S_OK;
82 }
83 long WINAPI
84 libAVFilter_GetSyncSource(libAVFilter *this, IReferenceClock **clock)
85 {
86     dshowdebug("libAVFilter_GetSyncSource(%p)\n", this);
87
88     if (!clock)
89         return E_POINTER;
90     if (this->clock)
91         IReferenceClock_AddRef(this->clock);
92     *clock = this->clock;
93
94     return S_OK;
95 }
96 long WINAPI
97 libAVFilter_EnumPins(libAVFilter *this, IEnumPins **enumpin)
98 {
99     libAVEnumPins *new;
100     dshowdebug("libAVFilter_EnumPins(%p)\n", this);
101
102     if (!enumpin)
103         return E_POINTER;
104     new = libAVEnumPins_Create(this->pin, this);
105     if (!new)
106         return E_OUTOFMEMORY;
107
108     *enumpin = (IEnumPins *) new;
109     return S_OK;
110 }
111 long WINAPI
112 libAVFilter_FindPin(libAVFilter *this, const wchar_t *id, IPin **pin)
113 {
114     libAVPin *found = NULL;
115     dshowdebug("libAVFilter_FindPin(%p)\n", this);
116
117     if (!id || !pin)
118         return E_POINTER;
119     if (!wcscmp(id, L"In")) {
120         found = this->pin;
121         libAVPin_AddRef(found);
122     }
123     *pin = (IPin *) found;
124     if (!found)
125         return VFW_E_NOT_FOUND;
126
127     return S_OK;
128 }
129 long WINAPI
130 libAVFilter_QueryFilterInfo(libAVFilter *this, FILTER_INFO *info)
131 {
132     dshowdebug("libAVFilter_QueryFilterInfo(%p)\n", this);
133
134     if (!info)
135         return E_POINTER;
136     if (this->info.pGraph)
137         IFilterGraph_AddRef(this->info.pGraph);
138     *info = this->info;
139
140     return S_OK;
141 }
142 long WINAPI
143 libAVFilter_JoinFilterGraph(libAVFilter *this, IFilterGraph *graph,
144                             const wchar_t *name)
145 {
146     dshowdebug("libAVFilter_JoinFilterGraph(%p)\n", this);
147
148     this->info.pGraph = graph;
149     if (name)
150         wcscpy(this->info.achName, name);
151
152     return S_OK;
153 }
154 long WINAPI
155 libAVFilter_QueryVendorInfo(libAVFilter *this, wchar_t **info)
156 {
157     dshowdebug("libAVFilter_QueryVendorInfo(%p)\n", this);
158
159     if (!info)
160         return E_POINTER;
161     *info = wcsdup(L"libAV");
162
163     return S_OK;
164 }
165
166 static int
167 libAVFilter_Setup(libAVFilter *this, void *priv_data, void *callback,
168                   enum dshowDeviceType type)
169 {
170     IBaseFilterVtbl *vtbl = this->vtbl;
171     SETVTBL(vtbl, libAVFilter, QueryInterface);
172     SETVTBL(vtbl, libAVFilter, AddRef);
173     SETVTBL(vtbl, libAVFilter, Release);
174     SETVTBL(vtbl, libAVFilter, GetClassID);
175     SETVTBL(vtbl, libAVFilter, Stop);
176     SETVTBL(vtbl, libAVFilter, Pause);
177     SETVTBL(vtbl, libAVFilter, Run);
178     SETVTBL(vtbl, libAVFilter, GetState);
179     SETVTBL(vtbl, libAVFilter, SetSyncSource);
180     SETVTBL(vtbl, libAVFilter, GetSyncSource);
181     SETVTBL(vtbl, libAVFilter, EnumPins);
182     SETVTBL(vtbl, libAVFilter, FindPin);
183     SETVTBL(vtbl, libAVFilter, QueryFilterInfo);
184     SETVTBL(vtbl, libAVFilter, JoinFilterGraph);
185     SETVTBL(vtbl, libAVFilter, QueryVendorInfo);
186
187     this->pin = libAVPin_Create(this);
188
189     this->priv_data = priv_data;
190     this->callback  = callback;
191     this->type      = type;
192
193     return 1;
194 }
195 static int
196 libAVFilter_Cleanup(libAVFilter *this)
197 {
198     libAVPin_Release(this->pin);
199     return 1;
200 }
201 DECLARE_CREATE(libAVFilter, libAVFilter_Setup(this, priv_data, callback, type),
202                void *priv_data, void *callback, enum dshowDeviceType type)
203 DECLARE_DESTROY(libAVFilter, libAVFilter_Cleanup)