1 /*****************************************************************************
2 * VLC backend for the Phonon library *
3 * Copyright (C) 2007-2008 Tanguy Krotoff <tkrotoff@gmail.com> *
4 * Copyright (C) 2008 Lukas Durfina <lukas.durfina@gmail.com> *
5 * Copyright (C) 2009 Fathi Boudra <fabo@kde.org> *
7 * This program 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 3 of the License, or (at your option) any later version. *
12 * This program 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. *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with this package; if not, write to the Free Software *
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 *****************************************************************************/
22 #include "videowidget.h"
24 #include "mediaobject.h"
25 #include "vlcmediaobject.h"
27 #include "vlcloader.h"
29 #include <QtGui/QWidget>
30 #include <QtGui/QApplication>
31 #include <QtGui/QDesktopWidget>
32 #include <QtCore/QtDebug>
38 VideoWidget::VideoWidget(QWidget *p_parent)
41 p_video_widget = new Widget(p_parent);
43 aspect_ratio = Phonon::VideoWidget::AspectRatioAuto;
44 scale_mode = Phonon::VideoWidget::FitInView;
46 b_filter_adjust_activated = false;
53 VideoWidget::~VideoWidget()
57 void VideoWidget::connectToMediaObject(PrivateMediaObject *mediaObject)
59 SinkNode::connectToMediaObject(mediaObject);
61 connect(mediaObject, SIGNAL(videoWidgetSizeChanged(int, int)),
62 SLOT(videoWidgetSizeChanged(int, int)));
64 mediaObject->setVideoWidgetId((int) p_video_widget->winId());
67 Phonon::VideoWidget::AspectRatio VideoWidget::aspectRatio() const
72 // VLC accepted formats are x:y (4:3, 16:9, etc...) expressing the global image aspect
73 void VideoWidget::setAspectRatio(Phonon::VideoWidget::AspectRatio aspect)
75 // finish if no player
76 if (!vlc_current_media_player)
79 aspect_ratio = aspect;
81 switch (aspect_ratio) {
82 case Phonon::VideoWidget::AspectRatioAuto: // Let the decoder find the aspect ratio automatically from the media file (this is the default)
83 // p_libvlc_video_set_aspect_ratio(p_vlc_current_media_player, "", vlc_exception);
86 case Phonon::VideoWidget::AspectRatioWidget: // Fit the video into the widget making the aspect ratio depend solely on the size of the widget
87 // This way the aspect ratio is freely resizeable by the user
88 // p_libvlc_video_set_aspect_ratio(p_vlc_current_media_player, "", vlc_exception);
91 case Phonon::VideoWidget::AspectRatio4_3:
92 // p_libvlc_video_set_aspect_ratio(p_vlc_current_media_player, "4:3", vlc_exception);
95 case Phonon::VideoWidget::AspectRatio16_9:
96 // p_libvlc_video_set_aspect_ratio(p_vlc_current_media_player, "16:9", vlc_exception);
100 qCritical() << __FUNCTION__ << "error: unsupported AspectRatio:" << (int) aspect_ratio;
104 Phonon::VideoWidget::ScaleMode VideoWidget::scaleMode() const
109 // The ScaleMode enumeration describes how to treat aspect ratio during resizing of video
110 void VideoWidget::setScaleMode(Phonon::VideoWidget::ScaleMode scale)
113 switch (scale_mode) {
114 case Phonon::VideoWidget::FitInView: // The video will be fitted to fill the view keeping aspect ratio
116 case Phonon::VideoWidget::ScaleAndCrop: // The video is scaled
119 qWarning() << __FUNCTION__ << "unknow Phonon::VideoWidget::ScaleMode:" << scale_mode;
123 qreal VideoWidget::brightness() const
128 void VideoWidget::setBrightness(qreal brightness)
130 f_brightness = brightness;
132 // vlc takes brightness in range 0.0 - 2.0
133 if (vlc_current_media_player) {
134 if (!b_filter_adjust_activated) {
135 // p_libvlc_video_filter_add(p_vlc_current_media_player, ADJUST, vlc_exception);
136 // vlcExceptionRaised();
137 b_filter_adjust_activated = true;
139 // p_libvlc_video_set_brightness(p_vlc_current_media_player, f_brightness + 1.0, vlc_exception);
140 // vlcExceptionRaised();
144 qreal VideoWidget::contrast() const
149 void VideoWidget::setContrast(qreal contrast)
151 f_contrast = contrast;
153 // vlc takes contrast in range 0.0 - 2.0
154 float f_contrast = contrast;
155 if (vlc_current_media_player) {
156 if (!b_filter_adjust_activated) {
157 // p_libvlc_video_filter_add(p_vlc_current_media_player, ADJUST, vlc_exception);
158 // vlcExceptionRaised();
159 b_filter_adjust_activated = true;
161 // p_libvlc_video_set_contrast(p_vlc_current_media_player, f_contrast + 1.0, vlc_exception);
162 // vlcExceptionRaised();
166 qreal VideoWidget::hue() const
171 void VideoWidget::setHue(qreal hue)
175 // vlc takes hue in range 0 - 360 in integer
176 int i_hue = (f_hue + 1.0) * 180;
177 if (vlc_current_media_player) {
178 if (!b_filter_adjust_activated) {
179 // p_libvlc_video_filter_add(p_vlc_current_media_player, ADJUST, vlc_exception);
180 // vlcExceptionRaised();
181 b_filter_adjust_activated = true;
183 // p_libvlc_video_set_hue(p_vlc_current_media_player, i_hue, vlc_exception);
184 // vlcExceptionRaised();
189 qreal VideoWidget::saturation() const
194 void VideoWidget::setSaturation(qreal saturation)
196 f_saturation = saturation;
198 // vlc takes brightness in range 0.0 - 3.0
199 if (vlc_current_media_player) {
200 if (!b_filter_adjust_activated) {
201 // p_libvlc_video_filter_add(p_vlc_current_media_player, ADJUST, vlc_exception);
202 // vlcExceptionRaised();
203 b_filter_adjust_activated = true;
205 // p_libvlc_video_set_saturation(p_vlc_current_media_player, (f_saturation + 1.0) * 1.5, vlc_exception);
206 // vlcExceptionRaised();
210 Widget * VideoWidget::widget()
212 return p_video_widget;
215 void VideoWidget::videoWidgetSizeChanged(int i_width, int i_height)
217 qDebug() << __FUNCTION__ << "video width" << i_width << "height:" << i_height;
219 // It resizes dynamically the widget and the main window
220 // Note: I didn't find another way
222 QSize videoSize(i_width, i_height);
223 videoSize.boundedTo(QApplication::desktop()->availableGeometry().size());
225 p_video_widget->hide();
226 p_video_widget->setVideoSize(videoSize);
228 QWidget *p_parent = qobject_cast<QWidget *>(this->parent());
229 QSize previousSize = p_parent->minimumSize();
230 p_parent->setMinimumSize(videoSize);
232 p_video_widget->show();
234 p_parent->setMinimumSize(previousSize);
239 } // Namespace Phonon::VLC