1 /* This file is part of the KDE project
2 Copyright (C) 2006 Tim Beaulen <tbscope@gmail.com>
3 Copyright (C) 2006-2007 Matthias Kretz <kretz@kde.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 #include "videoeffect.h"
24 #include "xineengine.h"
25 #include <QMutexLocker>
31 VideoEffect::VideoEffect(int effectId
, QObject
*parent
)
37 const char *const *postPlugins
= xine_list_post_plugins_typed(XineEngine::xine(), XINE_POST_TYPE_VIDEO_FILTER
);
38 if (effectId
>= 0x7F000000) {
39 effectId
-= 0x7F000000;
40 for(int i
= 0; postPlugins
[i
]; ++i
) {
43 m_pluginName
= postPlugins
[i
];
50 VideoEffect::VideoEffect(const char *name
, QObject
*parent
)
58 VideoEffect::~VideoEffect()
60 foreach (xine_post_t
*post
, m_plugins
) {
61 xine_post_dispose(XineEngine::xine(), post
);
66 void VideoEffect::setPath(VideoPath
*path
)
71 QList
<EffectParameter
> VideoEffect::allDescriptions()
73 ensureParametersReady();
74 return m_parameterList
;
77 EffectParameter
VideoEffect::description(int parameterIndex
)
79 ensureParametersReady();
80 if (parameterIndex
>= m_parameterList
.size()) {
81 return EffectParameter();
83 return m_parameterList
[parameterIndex
];
86 int VideoEffect::parameterCount()
88 ensureParametersReady();
89 return m_parameterList
.size();
92 void VideoEffect::ensureParametersReady()
94 if (m_parameterList
.isEmpty() && m_plugins
.isEmpty()) {
95 newInstance(XineEngine::nullVideoPort());
96 if (!m_plugins
.isEmpty()) {
97 xine_post_dispose(XineEngine::xine(), m_plugins
.first());
103 xine_post_t
*VideoEffect::newInstance(xine_video_port_t
*videoPort
)
105 QMutexLocker
lock(&m_mutex
);
107 xine_post_t
*x
= xine_post_init(XineEngine::xine(), m_pluginName
, 1, 0, &videoPort
);
109 xine_post_in_t
*paraInput
= xine_post_input(x
, "parameters");
111 Q_ASSERT(paraInput
->type
== XINE_POST_DATA_PARAMETERS
);
112 Q_ASSERT(paraInput
->data
);
113 xine_post_api_t
*api
= reinterpret_cast<xine_post_api_t
*>(paraInput
->data
);
115 if (m_parameterList
.isEmpty()) {
116 xine_post_api_descr_t
*desc
= api
->get_param_descr();
117 Q_ASSERT(0 == m_pluginParams
);
118 m_pluginParams
= static_cast<char *>(malloc(desc
->struct_size
));
119 api
->get_parameters(x
, m_pluginParams
);
120 for (int i
= 0; desc
->parameter
[i
].type
!= POST_PARAM_TYPE_LAST
; ++i
) {
121 xine_post_api_parameter_t
&p
= desc
->parameter
[i
];
123 case POST_PARAM_TYPE_INT
: /* integer (or vector of integers) */
124 addParameter(EffectParameter(i
, p
.name
, EffectParameter::IntegerHint
,
125 *reinterpret_cast<int *>(m_pluginParams
+ p
.offset
),
126 static_cast<int>(p
.range_min
), static_cast<int>(p
.range_max
), p
.description
));
128 case POST_PARAM_TYPE_DOUBLE
: /* double (or vector of doubles) */
129 addParameter(EffectParameter(i
, p
.name
, 0,
130 *reinterpret_cast<double *>(m_pluginParams
+ p
.offset
),
131 p
.range_min
, p
.range_max
, p
.description
));
133 case POST_PARAM_TYPE_CHAR
: /* char (or vector of chars = string) */
134 case POST_PARAM_TYPE_STRING
: /* (char *), ASCIIZ */
135 case POST_PARAM_TYPE_STRINGLIST
: /* (char **) list, NULL terminated */
136 kWarning(610) << "char/string/stringlist parameter '" << p
.name
<< "' not supported.";
138 case POST_PARAM_TYPE_BOOL
: /* integer (0 or 1) */
139 addParameter(EffectParameter(i
, p
.name
, EffectParameter::ToggledHint
,
140 static_cast<bool>(*reinterpret_cast<int *>(m_pluginParams
+ p
.offset
)),
141 QVariant(), QVariant(), p
.description
));
143 case POST_PARAM_TYPE_LAST
: /* terminator of parameter list */
157 QVariant
VideoEffect::parameterValue(int parameterIndex
) const
159 QMutexLocker
lock(&m_mutex
);
160 if (m_plugins
.isEmpty() || m_pluginApis
.isEmpty()) {
161 return QVariant(); // invalid
164 xine_post_t
*post
= m_plugins
.first();
165 xine_post_api_t
*api
= m_pluginApis
.first();
167 return QVariant(); // invalid
170 xine_post_api_descr_t
*desc
= api
->get_param_descr();
171 Q_ASSERT(m_pluginParams
);
172 api
->get_parameters(post
, m_pluginParams
);
174 for (; i
< parameterIndex
&& desc
->parameter
[i
].type
!= POST_PARAM_TYPE_LAST
; ++i
);
175 if (i
== parameterIndex
) {
176 xine_post_api_parameter_t
&p
= desc
->parameter
[i
];
178 case POST_PARAM_TYPE_INT
: /* integer (or vector of integers) */
179 return *reinterpret_cast<int *>(m_pluginParams
+ p
.offset
);
180 case POST_PARAM_TYPE_DOUBLE
: /* double (or vector of doubles) */
181 return *reinterpret_cast<double *>(m_pluginParams
+ p
.offset
);
182 case POST_PARAM_TYPE_CHAR
: /* char (or vector of chars = string) */
183 case POST_PARAM_TYPE_STRING
: /* (char *), ASCIIZ */
184 case POST_PARAM_TYPE_STRINGLIST
: /* (char **) list, NULL terminated */
185 kWarning(610) << "char/string/stringlist parameter '" << p
.name
<< "' not supported.";
187 case POST_PARAM_TYPE_BOOL
: /* integer (0 or 1) */
188 return static_cast<bool>(*reinterpret_cast<int *>(m_pluginParams
+ p
.offset
));
189 case POST_PARAM_TYPE_LAST
: /* terminator of parameter list */
195 kError(610) << "invalid parameterIndex passed to VideoEffect::value";
199 void VideoEffect::setParameterValue(int parameterIndex
, const QVariant
&newValue
)
201 QMutexLocker
lock(&m_mutex
);
202 if (m_plugins
.isEmpty() || m_pluginApis
.isEmpty()) {
206 xine_post_t
*post
= m_plugins
.first();
207 xine_post_api_t
*api
= m_pluginApis
.first();
212 xine_post_api_descr_t
*desc
= api
->get_param_descr();
213 Q_ASSERT(m_pluginParams
);
215 for (; i
< parameterIndex
&& desc
->parameter
[i
].type
!= POST_PARAM_TYPE_LAST
; ++i
);
216 if (i
== parameterIndex
) {
217 xine_post_api_parameter_t
&p
= desc
->parameter
[i
];
219 case POST_PARAM_TYPE_INT
: /* integer (or vector of integers) */
221 int *value
= reinterpret_cast<int *>(m_pluginParams
+ p
.offset
);
222 *value
= newValue
.toInt();
225 case POST_PARAM_TYPE_DOUBLE
: /* double (or vector of doubles) */
227 double *value
= reinterpret_cast<double *>(m_pluginParams
+ p
.offset
);
228 *value
= newValue
.toDouble();
231 case POST_PARAM_TYPE_CHAR
: /* char (or vector of chars = string) */
232 case POST_PARAM_TYPE_STRING
: /* (char *), ASCIIZ */
233 case POST_PARAM_TYPE_STRINGLIST
: /* (char **) list, NULL terminated */
234 kWarning(610) << "char/string/stringlist parameter '" << p
.name
<< "' not supported.";
236 case POST_PARAM_TYPE_BOOL
: /* integer (0 or 1) */
238 int *value
= reinterpret_cast<int *>(m_pluginParams
+ p
.offset
);
239 *value
= newValue
.toBool() ? 1 : 0;
242 case POST_PARAM_TYPE_LAST
: /* terminator of parameter list */
243 kError(610) << "invalid parameterIndex passed to VideoEffect::setValue";
248 api
->set_parameters(post
, m_pluginParams
);
250 kError(610) << "invalid parameterIndex passed to VideoEffect::setValue";
254 }} //namespace Phonon::Xine
256 #include "videoeffect.moc"