forked from mltframework/shotcut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdlwidget.cpp
136 lines (124 loc) · 4.68 KB
/
sdlwidget.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
/*
* Copyright (c) 2011 Meltytech, LLC
* Author: Dan Dennedy <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sdlwidget.h"
#include <Mlt.h>
#include <QtGui>
using namespace Mlt;
SDLWidget::SDLWidget(QWidget *parent)
: QWidget(parent)
, Controller()
{
// Required for SDL embeddding
parent->setAttribute(Qt::WA_NativeWindow);
setMouseTracking(true);
}
int SDLWidget::open(Mlt::Producer* producer, bool isMulti)
{
int error = Controller::open(producer, isMulti);
if (!error)
error = reconfigure(isMulti);
return error;
}
int SDLWidget::reconfigure(bool isMulti)
{
int error = 0;
QString serviceName = property("mlt_service").toString();
if (!m_consumer || !m_consumer->is_valid()) {
if (serviceName.isEmpty())
#if defined(Q_WS_WIN)
// sdl_preview does not work good on Windows
serviceName = "sdl";
#else
serviceName = "sdl_preview";
#endif
if (isMulti)
m_consumer = new Mlt::FilteredConsumer(profile(), "multi");
else
m_consumer = new Mlt::FilteredConsumer(profile(), serviceName.toAscii().constData());
}
if (m_consumer->is_valid()) {
// Connect the producer to the consumer - tell it to "run" later
m_consumer->connect(*m_producer);
// Make an event handler for when a frame's image should be displayed
m_consumer->listen("consumer-frame-show", this, (mlt_listener) on_frame_show);
m_consumer->set("real_time", property("realtime").toBool()? 1 : -1);
if (isMulti) {
m_consumer->set("terminate_on_pause", 0);
// Embed the SDL window in our GUI.
m_consumer->set("0.window_id", (int) this->winId());
// Set the background color
m_consumer->set("0.window_background", palette().color(QPalette::Window).name().toAscii().constData());
if (!profile().progressive())
m_consumer->set("progressive", property("progressive").toBool());
m_consumer->set("0.rescale", property("rescale").toString().toAscii().constData());
m_consumer->set("0.deinterlace_method", property("deinterlace_method").toString().toAscii().constData());
#ifndef Q_WS_WIN
m_consumer->set("0.scrub_audio", 1);
#endif
}
else {
// Embed the SDL window in our GUI.
m_consumer->set("window_id", (int) this->winId());
// Set the background color
m_consumer->set("window_background", palette().color(QPalette::Window).name().toAscii().constData());
if (!profile().progressive())
m_consumer->set("progressive", property("progressive").toBool());
m_consumer->set("rescale", property("rescale").toString().toAscii().constData());
m_consumer->set("deinterlace_method", property("deinterlace_method").toString().toAscii().constData());
#ifndef Q_WS_WIN
m_consumer->set("scrub_audio", 1);
#endif
}
}
else {
// Cleanup on error
error = 2;
Controller::closeConsumer();
Controller::close();
}
return error;
}
void SDLWidget::mousePressEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton)
m_dragStart = event->pos();
emit dragStarted();
}
void SDLWidget::mouseMoveEvent(QMouseEvent* event)
{
if (event->modifiers() == Qt::ShiftModifier && m_producer) {
emit seekTo(m_producer->get_length() * event->x() / width());
return;
}
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event->pos() - m_dragStart).manhattanLength() < QApplication::startDragDistance())
return;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setData("application/mlt+xml", "");
drag->setMimeData(mimeData);
drag->exec(Qt::LinkAction);
}
// MLT consumer-frame-show event handler
void SDLWidget::on_frame_show(mlt_consumer, void* self, mlt_frame frame_ptr)
{
SDLWidget* widget = static_cast<SDLWidget*>(self);
Frame frame(frame_ptr);
emit widget->frameReceived(Mlt::QFrame(frame));
}