forked from AlexiaChen/RtspMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vlcplayer.cpp
206 lines (160 loc) · 3.82 KB
/
vlcplayer.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
#include <iostream>
#include <cstdlib>
#include <QFileDialog>
#include <QMenu>
#include <QString>
#include <QStringList>
#include <QIcon>
#include <QDebug>
#include <QSize>
#include "vlcplayer.h"
#include "rtspdialog.h"
#include "global.h"
#include "configuredlg.h"
#include "monitorwindowmanager.h"
#include "monitorwindow.h"
VLCPlayer::VLCPlayer(QWidget *parent)
: QMainWindow(parent), m_row(2), m_column(3)
{
ui = new Ui::VLCPlayerClass;
m_rtsp = new RtspDialog(this);
m_configDlg = new ConfigureDlg(this);
ui->setupUi(this);
QMenu *file = menuBar()->addMenu("File");
QAction *openUrl = file->addAction("Open SDP File");
QAction *exit = file->addAction("Exit");
QMenu *config = menuBar()->addMenu("Configure");
QAction *layout = config->addAction("Row X Column");
//创建一个Manager类,以便管理监视窗口的行列配置
m_manager = new MonitorWindowManager(m_row, m_column, ui->container);
ui->container->setLayout(m_manager);
for (int i = 0; i < m_row; ++i)
{
for (int j = 0; j < m_column;++j)
{
m_playerSet.append(m_manager->getItemAtPosition(i, j));
}
}
for (auto& player : m_playerSet)
{
connect(player->ffmpeg(), SIGNAL(GetImage(const QImage &)), player, SLOT(setImage(const QImage&)));
}
connect(ui->play, SIGNAL(clicked()), this, SLOT(Play()));
connect(ui->replay, SIGNAL(clicked()), this, SLOT(Replay()));
connect(ui->record, SIGNAL(clicked()), this, SLOT(Record()));
connect(ui->stop, SIGNAL(clicked()), this, SLOT(Stop()));
connect(exit, SIGNAL(triggered()), this, SLOT(Exit()));
connect(openUrl, SIGNAL(triggered()), this, SLOT(OpenURL()));
connect(layout, SIGNAL(triggered()), this, SLOT(showRowColumnDlg()));
connect(m_rtsp, SIGNAL(fileComplete(QString&, QString&,QString&)), this,SLOT(recvFile(QString&, QString&,QString&)));
connect(m_configDlg, SIGNAL(configComplete(int, int)), this, SLOT(recvConfig(int, int)));
}
VLCPlayer::~VLCPlayer()
{
delete ui;
delete m_rtsp;
delete m_configDlg;
delete m_manager;
}
//播放和暂停
void VLCPlayer::Play()
{
for (auto &player : m_playerSet)
{
if (player->isActive())
{
if (player->isPlaying())
{
player->pausePlaying();
ui->play->setIcon(QIcon(":/Resources/play.png"));
}
else
{
player->resumePlaying();
ui->play->setIcon(QIcon(":/Resources/pause.png"));
}
}
}
}
void VLCPlayer::Replay()
{
}
void VLCPlayer::Record()
{
for (auto& player : m_playerSet)
{
if (player->isActive())
{
if (player->isRecording())
{
player->stopRecording();
ui->record->setIcon(QIcon(":/Resources/record.png"));
}
else
{
player->startRecording();
ui->record->setIcon(QIcon(":/Resources/offrecord.png"));
}
}
}
}
void VLCPlayer::Exit()
{
this->close();
}
void VLCPlayer::OpenURL()
{
m_rtsp->show();
}
void VLCPlayer::recvFile(QString& file, QString &path,QString& format)
{
for (auto& player : m_playerSet)
{
if (!player->isActive())
{
ui->play->setIcon(QIcon(":/Resources/pause.png"));
player->setUrl(file);
player->setOutFile(path);
player->startPlaying();
}
}
}
void VLCPlayer::recvConfig(int row, int column)
{
m_row = row;
m_column = column;
m_manager->setMonitorLayout(m_row, m_column);
m_playerSet.clear();
for (int i = 0; i < m_row; ++i)
{
for (int j = 0; j < m_column; ++j)
{
m_playerSet.append(m_manager->getItemAtPosition(i, j));
}
}
for (auto &player : m_playerSet)
{
connect(player->ffmpeg(), SIGNAL(GetImage(const QImage &)), player, SLOT(setImage(const QImage&)));
}
}
//停止,关闭监视
void VLCPlayer::Stop()
{
for (auto &player : m_playerSet)
{
if (player->isActive())
{
player->stop();
}
}
ui->play->setIcon(QIcon(":/Resources/play.png"));
ui->record->setIcon(QIcon(":/Resources/record.png"));
for(auto &player : m_playerSet)
{
player->setPixmap(QPixmap());
}
}
void VLCPlayer::showRowColumnDlg()
{
m_configDlg->show();
}