forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuickFilter.cpp
217 lines (186 loc) · 5.61 KB
/
QuickFilter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
* This file is part of QtAV (from 2016)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include "QmlAV/QuickFilter.h"
#include "QtAV/private/Filter_p.h"
#include "QtAV/LibAVFilter.h"
#include "QtAV/GLSLFilter.h"
#include "QtAV/VideoShaderObject.h"
#include "QtAV/OpenGLVideo.h"
//namespace QtAV {
class QuickVideoFilterPrivate : public VideoFilterPrivate
{
public:
QuickVideoFilterPrivate() : type(QuickVideoFilter::AVFilter)
, user_filter(NULL)
, avfilter(new LibAVFilterVideo())
, glslfilter(new GLSLFilter())
{
filter = avfilter.data();
}
QuickVideoFilter::FilterType type;
VideoFilter *filter;
VideoFilter *user_filter; // life time is managed by qml
QScopedPointer<LibAVFilterVideo> avfilter;
QScopedPointer<GLSLFilter> glslfilter;
};
QuickVideoFilter::QuickVideoFilter(QObject *parent)
: VideoFilter(*new QuickVideoFilterPrivate(), parent)
{
DPTR_D(QuickVideoFilter);
connect(d.avfilter.data(), SIGNAL(optionsChanged()), this, SIGNAL(avfilterChanged()));
}
bool QuickVideoFilter::isSupported(VideoFilterContext::Type ct) const
{
DPTR_D(const QuickVideoFilter);
if (d.filter)
return d.filter->isSupported(ct);
return false;
}
QuickVideoFilter::FilterType QuickVideoFilter::type() const
{
return d_func().type;
}
void QuickVideoFilter::setType(FilterType value)
{
DPTR_D(QuickVideoFilter);
if (d.type == value)
return;
d.type = value;
if (value == GLSLFilter)
d.filter = d.glslfilter.data();
else if (value == AVFilter)
d.filter = d.avfilter.data();
else
d.filter = d.user_filter;
Q_EMIT typeChanged();
}
QStringList QuickVideoFilter::supportedAVFilters() const
{
return d_func().avfilter->filters();
}
QString QuickVideoFilter::avfilter() const
{
return d_func().avfilter->options();
}
void QuickVideoFilter::setAVFilter(const QString &options)
{
d_func().avfilter->setOptions(options);
}
VideoFilter* QuickVideoFilter::userFilter() const
{
return d_func().user_filter;
}
void QuickVideoFilter::setUserFilter(VideoFilter *f)
{
DPTR_D(QuickVideoFilter);
if (d.user_filter == f)
return;
d.user_filter = f;
if (d.type == UserFilter)
d.filter = d.user_filter;
Q_EMIT userFilterChanged();
}
DynamicShaderObject* QuickVideoFilter::shader() const
{
return static_cast<DynamicShaderObject*>(d_func().glslfilter->opengl()->userShader());
}
void QuickVideoFilter::setShader(DynamicShaderObject *value)
{
DPTR_D(QuickVideoFilter);
if (shader() == value)
return;
d.glslfilter->opengl()->setUserShader(value);
Q_EMIT shaderChanged();
}
void QuickVideoFilter::process(Statistics *statistics, VideoFrame *frame)
{
DPTR_D(QuickVideoFilter);
if (!d.filter)
return;
d.filter->apply(statistics, frame);
}
class QuickAudioFilterPrivate : public AudioFilterPrivate
{
public:
QuickAudioFilterPrivate() : AudioFilterPrivate()
, type(QuickAudioFilter::AVFilter)
, user_filter(NULL)
, avfilter(new LibAVFilterAudio())
{
filter = avfilter.data();
}
QuickAudioFilter::FilterType type;
AudioFilter *filter;
AudioFilter* user_filter; // life time is managed by qml
QScopedPointer<LibAVFilterAudio> avfilter;
};
QuickAudioFilter::QuickAudioFilter(QObject *parent)
: AudioFilter(*new QuickAudioFilterPrivate(), parent)
{
DPTR_D(QuickAudioFilter);
connect(d.avfilter.data(), SIGNAL(optionsChanged()), this, SIGNAL(avfilterChanged()));
}
QuickAudioFilter::FilterType QuickAudioFilter::type() const
{
return d_func().type;
}
void QuickAudioFilter::setType(FilterType value)
{
DPTR_D(QuickAudioFilter);
if (d.type == value)
return;
d.type = value;
if (value == AVFilter)
d.filter = d.avfilter.data();
else
d.filter = d.user_filter;
Q_EMIT typeChanged();
}
QStringList QuickAudioFilter::supportedAVFilters() const
{
return d_func().avfilter->filters();
}
QString QuickAudioFilter::avfilter() const
{
return d_func().avfilter->options();
}
void QuickAudioFilter::setAVFilter(const QString &options)
{
d_func().avfilter->setOptions(options);
}
AudioFilter *QuickAudioFilter::userFilter() const
{
return d_func().user_filter;
}
void QuickAudioFilter::setUserFilter(AudioFilter *f)
{
DPTR_D(QuickAudioFilter);
if (d.user_filter == f)
return;
d.user_filter = f;
if (d.type == UserFilter)
d.filter = d.user_filter;
Q_EMIT userFilterChanged();
}
void QuickAudioFilter::process(Statistics *statistics, AudioFrame *frame)
{
DPTR_D(QuickAudioFilter);
if (!d.filter)
return;
d.filter->apply(statistics, frame);
}
//} //namespace QtAV