forked from moschopsuk/VT-Playback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtcontrolwindow.cpp
247 lines (196 loc) · 6.28 KB
/
vtcontrolwindow.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include "vtcontrolwindow.h"
#include "ui_vtcontrolwindow.h"
#include "mediaitemwidget.h"
#include "playlistmodel.h"
#include "playlistitem.h"
#include <mlt++/Mlt.h>
#include <QDebug>
#include <QtGui>
VTControlWindow::VTControlWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::VTControlWindow) {
ui->setupUi(this);
//Create
profile = new Mlt::Profile("hdv_720_50p");
consumer = new Mlt::Consumer(*profile, "multi");
//Bug fix black screen on decklink pause
consumer->set("terminate_on_pause", 0);
consumer->set("rescale", "bilinear");
createConsumers();
createPlaylistTable();
//Create internal timmer for
//tracking video progress
timer = new QTimer();
timer->start(200);
connect(timer, SIGNAL(timeout()), this, SLOT(updateSeekBar()));
setupPlaylist();
reset();
}
VTControlWindow::~VTControlWindow() {
delete ui;
reset();
Mlt::Factory::close();
}
Mlt::Profile* VTControlWindow::activeProfile() {
return profile;
}
void VTControlWindow::PlayItem(Mlt::Producer &p) {
producer->seek(0);
this->producer = &p;
reset();
if(producer->is_valid()) {
ui->totaltimeLabel->setText(QString(producer->get_length_time()));
consumer->connect(*producer);
consumer->start();
isPaused = false;
}
if(producer->get_speed() == 0) {
play();
}
}
void VTControlWindow::createConsumers() {
//create the decklink consumer
consumer->set("0", "decklink:0");
//create the sdl_preview window
consumer->set("1", "sdl_preview");
consumer->set("1.real_time", "0");
consumer->set("1.resize", "1");
consumer->set("1.window_id", (int) ui->videoWidget->winId());
ui->videoWidget->setStyleSheet("background-color:black;");
//Create a dummy producer and connect the two
//to avoid any errors
producer = new Mlt::Producer(*profile, "color:red");
consumer->connect(*producer);
producer->set_speed(0.0);
}
void VTControlWindow::setupPlaylist() {
//Use palettes to change background to white
//Using stylesheets will reset everything
QPalette Pal(palette());
Pal.setColor(QPalette::Background, Qt::white);
ui->playlistScrollArea->setAutoFillBackground(true);
ui->playlistScrollArea->setPalette(Pal);
//create a child widget to hold the
//items in the scroll area
techArea = new QWidget(this);
techArea->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
//create an layout with the aligmnet at the top.
QVBoxLayout *layout = new QVBoxLayout(techArea);
layout->setAlignment(Qt::AlignTop);
techArea->setLayout(layout);
ui->playlistScrollArea->setWidget(techArea);
}
void VTControlWindow::on_actionAddMedia_triggered() {
QString fileName = QFileDialog::getOpenFileName(this);
if(fileName.isNull()) {
return;
}
QLayout *lay = techArea->layout();
MediaItemWidget *widget = new MediaItemWidget(this, fileName, techArea);
lay->addWidget(widget);
}
void VTControlWindow::createPlaylistTable() {
model = new PlayListModel(this);
ui->playlistTable->setModel(model);
ui->playlistTable->verticalHeader()->setVisible(false);
ui->playlistTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
ui->playlistTable->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->playlistTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
}
void VTControlWindow::QueueItem(PlaylistItem item) {
model->addItem(item);
}
void VTControlWindow::updateSeekBar() {
if(!consumer->is_stopped()){
int sliderValue = 1.0 * ((int)producer->position()) / producer->get_length() * ui->seekbar->maximum();
ui->seekbar->setValue(sliderValue);
ui->currentTimeLabel->setText(QString(producer->frames_to_time(producer->position())));
int remaining = producer->get_length() - producer->position();
ui->remaingTimeLabel->setText(QString(producer->frames_to_time(remaining)));
//qDebug() << producer->position() << "#" << producer->get_length();
if(producer->position() >= (producer->get_length() - 1)) {
reset();
emit vtComplete();
}
}
}
void VTControlWindow::on_stopButton_clicked() {
reset();
}
void VTControlWindow::reset() {
QString nullTimeStamp = QString("00:00:00:00");
ui->currentTimeLabel->setText(nullTimeStamp);
ui->remaingTimeLabel->setText(nullTimeStamp);
ui->totaltimeLabel->setText(nullTimeStamp);
ui->seekbar->setValue(0);
if(!consumer->is_stopped()) {
consumer->stop();
}
isPaused = true;
}
void VTControlWindow::on_playButton_clicked() {
if(producer->get_speed() == 0) {
play();
} else {
pause();
}
}
void VTControlWindow::play() {
isPaused = false;
ui->playButton->setText("Pause");
producer->set_speed(1.0);
producer->set("1.refresh", 1);
}
void VTControlWindow::pause() {
if (producer && producer->get_speed() != 0) {
producer->set_speed(0);
if (consumer->is_valid()) {
consumer->purge();
producer->seek(consumer->position() + 1);
}
}
isPaused = true;
ui->playButton->setText("Play");
}
void VTControlWindow::on_clearButton_clicked() {
model->reset();
listIndex = 0;
}
/*
* Begin Playlist Methods
*/
void VTControlWindow::on_StartPlaylistButton_clicked() {
//clear onstage
reset();
//Connect the two.
connect(this, SIGNAL(vtComplete()), this, SLOT(playlistNext()));
startPlaylist();
}
void VTControlWindow::startPlaylist() {
listIndex = 0;
playoutVT(0);
}
void VTControlWindow::playlistNext() {
listIndex++;
playoutVT(listIndex);
}
void VTControlWindow::playoutVT(int index) {
QList<PlaylistItem> playlist = model->getModelList();
qDebug() << listIndex << playlist.count();
//We are now past the playlist
if(playlist.count() <= listIndex) {
if(ui->loopPlaylist->isChecked()) {
startPlaylist();
return;
}
//unlink the reciver;
disconnect(this, SLOT(playlistNext()));
ui->playlistTable->selectRow(0);
reset();
return;
}
ui->playlistTable->selectRow(index);
PlaylistItem item = playlist.at(index);
item.getProducer()->seek(0);
PlayItem(*item.getProducer());
}