Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / runtime / phonon / xine / videoeffect.cpp
blob7ee592d620d17d8b7938cc7b81813cb7c5a67b73
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"
23 #include <QVariant>
24 #include "xineengine.h"
25 #include <QMutexLocker>
27 namespace Phonon
29 namespace Xine
31 VideoEffect::VideoEffect(int effectId, QObject *parent)
32 : QObject(parent),
33 m_pluginName(0),
34 m_pluginParams(0),
35 m_path(0)
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) {
41 if (i == effectId) {
42 // found it
43 m_pluginName = postPlugins[i];
44 break;
50 VideoEffect::VideoEffect(const char *name, QObject *parent)
51 : QObject(parent),
52 m_pluginName(name),
53 m_pluginParams(0),
54 m_path(0)
58 VideoEffect::~VideoEffect()
60 foreach (xine_post_t *post, m_plugins) {
61 xine_post_dispose(XineEngine::xine(), post);
63 free(m_pluginParams);
66 void VideoEffect::setPath(VideoPath *path)
68 m_path = 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());
98 m_plugins.clear();
103 xine_post_t *VideoEffect::newInstance(xine_video_port_t *videoPort)
105 QMutexLocker lock(&m_mutex);
106 if (m_pluginName) {
107 xine_post_t *x = xine_post_init(XineEngine::xine(), m_pluginName, 1, 0, &videoPort);
108 m_plugins << x;
109 xine_post_in_t *paraInput = xine_post_input(x, "parameters");
110 if (paraInput) {
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);
114 m_pluginApis << api;
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];
122 switch (p.type) {
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));
127 break;
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));
132 break;
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.";
137 break;
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));
142 break;
143 case POST_PARAM_TYPE_LAST: /* terminator of parameter list */
144 default:
145 abort();
149 } else {
150 m_pluginApis << 0;
152 return x;
154 return 0;
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();
166 if (!post || !api) {
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);
173 int i = 0;
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];
177 switch (p.type) {
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.";
186 return QVariant();
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 */
190 break;
191 default:
192 abort();
195 kError(610) << "invalid parameterIndex passed to VideoEffect::value";
196 return QVariant();
199 void VideoEffect::setParameterValue(int parameterIndex, const QVariant &newValue)
201 QMutexLocker lock(&m_mutex);
202 if (m_plugins.isEmpty() || m_pluginApis.isEmpty()) {
203 return;
206 xine_post_t *post = m_plugins.first();
207 xine_post_api_t *api = m_pluginApis.first();
208 if (!post || !api) {
209 return;
212 xine_post_api_descr_t *desc = api->get_param_descr();
213 Q_ASSERT(m_pluginParams);
214 int i = 0;
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];
218 switch (p.type) {
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();
224 break;
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();
230 break;
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.";
235 return;
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;
241 break;
242 case POST_PARAM_TYPE_LAST: /* terminator of parameter list */
243 kError(610) << "invalid parameterIndex passed to VideoEffect::setValue";
244 break;
245 default:
246 abort();
248 api->set_parameters(post, m_pluginParams);
249 } else {
250 kError(610) << "invalid parameterIndex passed to VideoEffect::setValue";
254 }} //namespace Phonon::Xine
256 #include "videoeffect.moc"
257 // vim: sw=4 ts=4