-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathqmpwidget.cpp
1411 lines (1253 loc) · 33.7 KB
/
qmpwidget.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* CloudClient - A Qt cloud client for lixian.vip.xunlei.com
* Copyright (C) 2012 by Aaron Lewis <[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/>.
*/
/*
* qmpwidget - A Qt widget for embedding MPlayer
* Copyright (C) 2010 by Jonas Gehring
*
* 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 <QAbstractSlider>
#include <QKeyEvent>
#include <QLocalSocket>
#include <QPainter>
#include <QProcess>
#include <QStringList>
#include <QTemporaryFile>
#include <QThread>
#include <QtDebug>
#ifdef QT_OPENGL_LIB
#include <QGLWidget>
#endif
#include "qmpwidget.h"
//#define QMP_DEBUG_OUTPUT
#ifdef QMP_USE_YUVPIPE
#include "qmpyuvreader.h"
#endif // QMP_USE_YUVPIPE
// A plain video widget
class QMPPlainVideoWidget : public QWidget
{
Q_OBJECT
public:
QMPPlainVideoWidget(QWidget *parent = 0)
: QWidget(parent)
{
setAttribute(Qt::WA_NoSystemBackground);
setMouseTracking(true);
}
void showUserImage(const QImage &image)
{
m_userImage = image;
update();
}
public slots:
void displayImage(const QImage &image)
{
m_pixmap = QPixmap::fromImage(image);
update();
}
protected:
void paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter p(this);
p.setCompositionMode(QPainter::CompositionMode_Source);
if (!m_userImage.isNull()) {
p.fillRect(rect(), Qt::black);
p.drawImage(rect().center() - m_userImage.rect().center(), m_userImage);
} else if (!m_pixmap.isNull()) {
p.drawPixmap(rect(), m_pixmap);
} else {
p.fillRect(rect(), Qt::black);
}
p.end();
}
private:
QPixmap m_pixmap;
QImage m_userImage;
};
#ifdef QT_OPENGL_LIB
// A OpenGL video widget
class QMPOpenGLVideoWidget : public QGLWidget
{
Q_OBJECT
public:
QMPOpenGLVideoWidget(QWidget *parent = 0)
: QGLWidget(parent), m_tex(-1)
{
setMouseTracking(true);
}
void showUserImage(const QImage &image)
{
m_userImage = image;
makeCurrent();
if (m_tex >= 0) {
deleteTexture(m_tex);
}
if (!m_userImage.isNull()) {
m_tex = bindTexture(image);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else {
glViewport(0, 0, width(), qMax(height(), 1));
}
updateGL();
}
public slots:
void displayImage(const QImage &image)
{
if (!m_userImage.isNull()) {
return;
}
makeCurrent();
if (m_tex >= 0) {
deleteTexture(m_tex);
}
m_tex = bindTexture(image);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
updateGL();
}
protected:
void initializeGL()
{
glEnable(GL_TEXTURE_2D);
glClearColor(0, 0, 0, 0);
glClearDepth(1);
}
void resizeGL(int w, int h)
{
glViewport(0, 0, w, qMax(h, 1));
}
void paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
if (m_tex >= 0) {
glBindTexture(GL_TEXTURE_2D, m_tex);
if (!m_userImage.isNull()) {
QRect r = m_userImage.rect();
r.moveTopLeft(rect().center() - m_userImage.rect().center());
glViewport(r.x(), r.y(), r.width(), r.height());
}
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(-1, -1);
glTexCoord2f(1, 0); glVertex2f( 1, -1);
glTexCoord2f(1, 1); glVertex2f( 1, 1);
glTexCoord2f(0, 1); glVertex2f(-1, 1);
glEnd();
}
}
private:
QImage m_userImage;
int m_tex;
};
#endif // QT_OPENGL_LIB
// A custom QProcess designed for the MPlayer slave interface
class QMPProcess : public QProcess
{
Q_OBJECT
public:
QMPProcess(QObject *parent = 0)
: QProcess(parent), m_state(QMPwidget::NotStartedState), m_mplayerPath("mplayer"),
m_fakeInputconf(NULL)
#ifdef QMP_USE_YUVPIPE
, m_yuvReader(NULL)
#endif
{
resetValues();
#ifdef Q_WS_WIN
m_mode = QMPwidget::EmbeddedMode;
m_videoOutput = "directx,directx:noaccel";
#elif defined(Q_WS_X11)
m_mode = QMPwidget::EmbeddedMode;
#ifdef QT_OPENGL_LIB
m_videoOutput = "gl2,gl,xv";
#else
m_videoOutput = "xv";
#endif
#elif defined(Q_WS_MAC)
m_mode = QMPwidget::PipeMode;
#ifdef QT_OPENGL_LIB
m_videoOutput = "gl,quartz";
#else
m_videoOutput = "quartz";
#endif
#endif
m_movieFinishedTimer.setSingleShot(true);
m_movieFinishedTimer.setInterval(100);
connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdout()));
connect(this, SIGNAL(readyReadStandardError()), this, SLOT(readStderr()));
connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished()));
connect(&m_movieFinishedTimer, SIGNAL(timeout()), this, SLOT(movieFinished()));
}
~QMPProcess()
{
#ifdef QMP_USE_YUVPIPE
if (m_yuvReader != NULL) {
m_yuvReader->stop();
}
#endif
if (m_fakeInputconf != NULL) {
delete m_fakeInputconf;
}
}
// Starts the MPlayer process in idle mode
void start(QWidget *widget, const QStringList &args)
{
if (m_mode == QMPwidget::PipeMode) {
#ifdef QMP_USE_YUVPIPE
m_yuvReader = new QMPYuvReader(this);
#else
m_mode = QMPwidget::EmbeddedMode;
#endif
}
// Figure out the mplayer version in order to check if
// "-input nodefault-bindings" is available
bool useFakeInputconf = true;
QString version = mplayerVersion();
if (version.contains("SVN")) { // Check revision
QRegExp re("SVN-r([0-9]*)");
if (re.indexIn(version) > -1) {
int revision = re.cap(1).toInt();
if (revision >= 28878) {
useFakeInputconf = false;
}
}
}
QStringList myargs;
myargs += "-slave";
myargs += "-idle";
myargs += "-noquiet";
myargs += "-identify";
myargs += "-nomouseinput";
myargs += "-nokeepaspect";
myargs += "-monitorpixelaspect";
myargs += "1";
if (!useFakeInputconf) {
myargs += "-input";
myargs += "nodefault-bindings:conf=/dev/null";
} else {
#ifndef Q_WS_WIN
// Ugly hack for older versions of mplayer (used in kmplayer and other)
if (m_fakeInputconf == NULL) {
m_fakeInputconf = new QTemporaryFile();
if (m_fakeInputconf->open()) {
writeFakeInputconf(m_fakeInputconf);
} else {
delete m_fakeInputconf;
m_fakeInputconf = NULL;
}
}
if (m_fakeInputconf != NULL) {
myargs += "-input";
myargs += QString("conf=%1").arg(m_fakeInputconf->fileName());
}
#endif
}
if (m_mode == QMPwidget::EmbeddedMode) {
myargs += "-wid";
myargs += QString::number((int)widget->winId());
if (!m_videoOutput.isEmpty()) {
myargs += "-vo";
myargs += m_videoOutput;
}
} else {
#ifdef QMP_USE_YUVPIPE
myargs += "-vo";
myargs += QString("yuv4mpeg:file=%1").arg(m_yuvReader->m_pipe);
#endif
}
myargs += args;
#ifdef QMP_DEBUG_OUTPUT
qDebug() << myargs;
#endif
QProcess::start(m_mplayerPath, myargs);
changeState(QMPwidget::IdleState);
if (m_mode == QMPwidget::PipeMode) {
#ifdef QMP_USE_YUVPIPE
connect(m_yuvReader, SIGNAL(imageReady(const QImage &)), widget, SLOT(displayImage(const QImage &)));
m_yuvReader->start();
#endif
}
}
QString mplayerVersion()
{
QProcess p;
p.start(m_mplayerPath, QStringList("-version"));
if (!p.waitForStarted()) {
return QString();
}
if (!p.waitForFinished()) {
return QString();
}
QString output = QString(p.readAll());
QRegExp re("MPlayer ([^ ]*)");
if (re.indexIn(output) > -1) {
return re.cap(1);
}
return output;
}
QProcess::ProcessState processState() const
{
return QProcess::state();
}
void writeCommand(const QString &command)
{
#ifdef QMP_DEBUG_OUTPUT
qDebug("in: \"%s\"", qPrintable(command));
#endif
QProcess::write(command.toLocal8Bit()+"\n");
}
void quit()
{
writeCommand("quit");
QProcess::waitForFinished(100);
if (QProcess::state() == QProcess::Running) {
QProcess::kill();
}
QProcess::waitForFinished(-1);
}
void pause()
{
writeCommand("pause");
}
void stop()
{
writeCommand("stop");
}
signals:
void stateChanged(int state);
void streamPositionChanged(double position);
void error(const QString &reason);
void readStandardOutput(const QString &line);
void readStandardError(const QString &line);
private slots:
void readStdout()
{
QStringList lines = QString::fromLocal8Bit(readAllStandardOutput()).split("\n", QString::SkipEmptyParts);
for (int i = 0; i < lines.count(); i++) {
lines[i].remove("\r");
#ifdef QMP_DEBUG_OUTPUT
qDebug("out: \"%s\"", qPrintable(lines[i]));
#endif
parseLine(lines[i]);
emit readStandardOutput(lines[i]);
}
}
void readStderr()
{
QStringList lines = QString::fromLocal8Bit(readAllStandardError()).split("\n", QString::SkipEmptyParts);
for (int i = 0; i < lines.count(); i++) {
lines[i].remove("\r");
#ifdef QMP_DEBUG_OUTPUT
qDebug("err: \"%s\"", qPrintable(lines[i]));
#endif
parseLine(lines[i]);
emit readStandardError(lines[i]);
}
}
void finished()
{
// Called if the *process* has finished
changeState(QMPwidget::NotStartedState);
}
void movieFinished()
{
if (m_state == QMPwidget::PlayingState) {
changeState(QMPwidget::IdleState);
}
}
private:
// Parses a line of MPlayer output
void parseLine(const QString &line)
{
if (line.startsWith("Playing ")) {
changeState(QMPwidget::LoadingState);
} else if (line.startsWith("Cache fill:")) {
changeState(QMPwidget::BufferingState);
} else if (line.startsWith("Starting playback...")) {
m_mediaInfo.ok = true; // No more info here
changeState(QMPwidget::PlayingState);
} else if (line.startsWith("File not found: ")) {
changeState(QMPwidget::ErrorState);
} else if (line.endsWith("ID_PAUSED")) {
changeState(QMPwidget::PausedState);
} else if (line.startsWith("ID_")) {
parseMediaInfo(line);
} else if (line.startsWith("No stream found")) {
changeState(QMPwidget::ErrorState, line);
} else if (line.startsWith("A:") || line.startsWith("V:")) {
if (m_state != QMPwidget::PlayingState) {
changeState(QMPwidget::PlayingState);
}
parsePosition(line);
} else if (line.startsWith("Exiting...")) {
changeState(QMPwidget::NotStartedState);
}
}
// Parses MPlayer's media identification output
void parseMediaInfo(const QString &line)
{
QStringList info = line.split("=");
if (info.count() < 2) {
return;
}
if (info[0] == "ID_VIDEO_FORMAT") {
m_mediaInfo.videoFormat = info[1];
} else if (info[0] == "ID_VIDEO_BITRATE") {
m_mediaInfo.videoBitrate = info[1].toInt();
} else if (info[0] == "ID_VIDEO_WIDTH") {
m_mediaInfo.size.setWidth(info[1].toInt());
} else if (info[0] == "ID_VIDEO_HEIGHT") {
m_mediaInfo.size.setHeight(info[1].toInt());
} else if (info[0] == "ID_VIDEO_FPS") {
m_mediaInfo.framesPerSecond = info[1].toDouble();
} else if (info[0] == "ID_AUDIO_FORMAT") {
m_mediaInfo.audioFormat = info[1];
} else if (info[0] == "ID_AUDIO_BITRATE") {
m_mediaInfo.audioBitrate = info[1].toInt();
} else if (info[0] == "ID_AUDIO_RATE") {
m_mediaInfo.sampleRate = info[1].toInt();
} else if (info[0] == "ID_AUDIO_NCH") {
m_mediaInfo.numChannels = info[1].toInt();
} else if (info[0] == "ID_LENGTH") {
m_mediaInfo.length = info[1].toDouble();
} else if (info[0] == "ID_SEEKABLE") {
m_mediaInfo.seekable = (bool)info[1].toInt();
} else if (info[0].startsWith("ID_CLIP_INFO_NAME")) {
m_currentTag = info[1];
} else if (info[0].startsWith("ID_CLIP_INFO_VALUE") && !m_currentTag.isEmpty()) {
m_mediaInfo.tags.insert(m_currentTag, info[1]);
}
}
// Parsas MPlayer's position output
void parsePosition(const QString &line)
{
static QRegExp rx("[ :]");
QStringList info = line.split(rx, QString::SkipEmptyParts);
double oldpos = m_streamPosition;
for (int i = 0; i < info.count(); i++) {
if ( ( info[i] == "A" || info[i] == "V" ) && info.count() > i) {
m_streamPosition = info[i+1].toDouble();
// If the movie is near its end, start a timer that will check whether
// the movie has really finished.
if (qAbs(m_streamPosition - m_mediaInfo.length) < 1) {
m_movieFinishedTimer.start();
}
}
}
if (oldpos != m_streamPosition) {
emit streamPositionChanged(m_streamPosition);
}
}
// Changes the current state, possibly emitting multiple signals
void changeState(QMPwidget::State state, const QString &comment = QString())
{
#ifdef QMP_USE_YUVPIPE
if (m_yuvReader != NULL && (state == QMPwidget::ErrorState || state == QMPwidget::NotStartedState)) {
m_yuvReader->stop();
m_yuvReader->deleteLater();
}
#endif
if (m_state == state) {
return;
}
if (m_state == QMPwidget::PlayingState) {
m_movieFinishedTimer.stop();
}
m_state = state;
emit stateChanged(m_state);
switch (m_state) {
case QMPwidget::NotStartedState:
resetValues();
break;
case QMPwidget::ErrorState:
emit error(comment);
resetValues();
break;
default: break;
}
}
// Resets the media info and position values
void resetValues()
{
m_mediaInfo = QMPwidget::MediaInfo();
m_streamPosition = -1;
}
// Writes a dummy input configuration to the given device
void writeFakeInputconf(QIODevice *device)
{
// Query list of supported keys
QProcess p;
p.start(m_mplayerPath, QStringList("-input") += "keylist");
if (!p.waitForStarted()) {
return;
}
if (!p.waitForFinished()) {
return;
}
QStringList keys = QString(p.readAll()).split("\n", QString::SkipEmptyParts);
// Write dummy command for each key
QTextStream out(device);
for (int i = 0; i < keys.count(); i++) {
keys[i].remove("\r");
out << keys[i] << " " << "ignored" << endl;
}
}
public:
QMPwidget::State m_state;
QString m_mplayerPath;
QString m_videoOutput;
QString m_pipe;
QMPwidget::Mode m_mode;
QMPwidget::MediaInfo m_mediaInfo;
double m_streamPosition; // This is the video position
QTimer m_movieFinishedTimer;
QString m_currentTag;
QTemporaryFile *m_fakeInputconf;
#ifdef QMP_USE_YUVPIPE
QPointer<QMPYuvReader> m_yuvReader;
#endif
};
// Initialize the media info structure
QMPwidget::MediaInfo::MediaInfo()
: videoBitrate(0), framesPerSecond(0), sampleRate(0), numChannels(0),
ok(false), length(0), seekable(false)
{
}
/*!
* \brief Constructor
*
* \param parent Parent widget
*/
QMPwidget::QMPwidget(QWidget *parent)
: QWidget(parent)
{
setFocusPolicy(Qt::StrongFocus);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
#ifdef QT_OPENGL_LIB
m_widget = new QMPOpenGLVideoWidget(this);
#else
m_widget = new QMPPlainVideoWidget(this);
#endif
QPalette p = palette();
p.setColor(QPalette::Window, Qt::black);
setPalette(p);
m_seekTimer.setInterval(50);
m_seekTimer.setSingleShot(true);
connect(&m_seekTimer, SIGNAL(timeout()), this, SLOT(delayedSeek()));
m_process = new QMPProcess(this);
connect(m_process, SIGNAL(stateChanged(int)), this, SLOT(mpStateChanged(int)));
connect(m_process, SIGNAL(streamPositionChanged(double)), this, SLOT(mpStreamPositionChanged(double)));
connect(m_process, SIGNAL(error(const QString &)), this, SIGNAL(error(const QString &)));
connect(m_process, SIGNAL(readStandardOutput(const QString &)), this, SIGNAL(readStandardOutput(const QString &)));
connect(m_process, SIGNAL(readStandardError(const QString &)), this, SIGNAL(readStandardError(const QString &)));
}
/*!
* \brief Destructor
* \details
* This function will ask the MPlayer process to quit and block until it has really
* finished.
*/
QMPwidget::~QMPwidget()
{
if (m_process->processState() == QProcess::Running) {
m_process->quit();
}
delete m_process;
}
/*!
* \brief Returns the current MPlayer process state
*
* \returns The process state
*/
QMPwidget::State QMPwidget::state() const
{
return m_process->m_state;
}
/*!
* \brief Returns the current media info object
* \details
* Please check QMPwidget::MediaInfo::ok to make sure the media
* information has been fully parsed.
*
* \returns The media info object
*/
QMPwidget::MediaInfo QMPwidget::mediaInfo() const
{
return m_process->m_mediaInfo;
}
/*!
* \brief Returns the current playback position
*
* \returns The current playback position in seconds
* \sa seek()
*/
double QMPwidget::tell() const
{
return m_process->m_streamPosition;
}
/*!
* \brief Returns the MPlayer process
*
* \returns The MPlayer process
*/
QProcess *QMPwidget::process() const
{
return m_process;
}
/*!
* \brief Sets the video playback mode
* \details
* Please see \ref playbackmodes for a discussion of the available modes.
*
* \param mode The video playback mode
* \sa mode()
*/
void QMPwidget::setMode(Mode mode)
{
#ifdef QMP_USE_YUVPIPE
m_process->m_mode = mode;
#else
Q_UNUSED(mode)
#endif
}
/*!
* \brief Returns the current video playback mode
*
* \returns The current video playback mode
* \sa setMode()
*/
QMPwidget::Mode QMPwidget::mode() const
{
return m_process->m_mode;
}
/*!
* \brief Sets the video output mode
* \details
* The video output mode string will be passed to MPlayer using its \p -vo option.
* Please see http://www.mplayerhq.hu/DOCS/HTML/en/video.html for an overview of
* available video output modes.
*
* Per default, this string will have the following values:
* <table>
* <tr><th>System</th><th>Configuration</th><th>Value</th></tr>
* <tr>
* <td>Windows</td>
* <td></td>
* <td>\p "directx,directx:noaccel"</td>
* </tr>
* <tr>
* <td>X11</td>
* <td>Compiled without OpenGL support</td>
* <td>\p "xv"</td>
* </tr>
* <tr>
* <td>X11</td>
* <td>Compiled with OpenGL support</td>
* <td>\p "gl2,gl,xv"</td>
* </tr>
* <tr>
* <td>Mac OS X</td>
* <td>Compiled without OpenGL support</td>
* <td>\p "quartz"</td>
* </tr>
* <tr>
* <td>Mac OS X</td>
* <td>Compiled with OpenGL support</td>
* <td>\p "gl,quartz"</td>
* </tr>
* </table>
*
*
* \param output The video output mode string
* \sa videoOutput()
*/
void QMPwidget::setVideoOutput(const QString &output)
{
m_process->m_videoOutput = output;
}
/*!
* \brief Returns the current video output mode
*
* \returns The current video output mode
* \sa setVideoOutput()
*/
QString QMPwidget::videoOutput() const
{
return m_process->m_videoOutput;
}
/*!
* \brief Sets the path to the MPlayer executable
* \details
* Per default, it is assumed the MPlayer executable is
* available in the current OS path. Therefore, this value is
* set to "mplayer".
*
* \param path Path to the MPlayer executable
* \sa mplayerPath()
*/
void QMPwidget::setMPlayerPath(const QString &path)
{
m_process->m_mplayerPath = path;
}
/*!
* \brief Returns the current path to the MPlayer executable
*
* \returns The path to the MPlayer executable
* \sa setMPlayerPath()
*/
QString QMPwidget::mplayerPath() const
{
return m_process->m_mplayerPath;
}
/*!
* \brief Returns the version string of the MPlayer executable
* \details
* If the mplayer
*
*
* \returns The version string of the MPlayer executable
*/
QString QMPwidget::mplayerVersion()
{
return m_process->mplayerVersion();
}
/*!
* \brief Sets a seeking slider for this widget
*/
void QMPwidget::setSeekSlider(QAbstractSlider *slider)
{
if (m_seekSlider) {
m_seekSlider->disconnect(this);
disconnect(m_seekSlider);
}
if (m_process->m_mediaInfo.ok) {
slider->setRange(0, m_process->m_mediaInfo.length);
}
if (m_process->m_mediaInfo.ok) {
slider->setEnabled(m_process->m_mediaInfo.seekable);
}
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(seek(int)));
m_seekSlider = slider;
}
/*!
* \brief Sets a volume slider for this widget
*/
void QMPwidget::setVolumeSlider(QAbstractSlider *slider)
{
if (m_volumeSlider) {
m_volumeSlider->disconnect(this);
disconnect(m_volumeSlider);
}
slider->setRange(0, 100);
slider->setValue(100); // TODO
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(setVolume(int)));
m_volumeSlider = slider;
}
/*!
* \brief Shows a custom image
* \details
* This function sets a custom image that will be shown instead of the MPlayer
* video output. In order to show MPlayer's output again, call this function
* with a null image.
*
* \note If the current playback mode is not set to \p PipeMode, this function
* will have no effect if MPlayer draws to the widget.
*
* \param image Custom image
*/
void QMPwidget::showImage(const QImage &image)
{
#ifdef QT_OPENGL_LIB
qobject_cast<QMPOpenGLVideoWidget *>(m_widget)->showUserImage(image);
#else
qobject_cast<QMPPlainVideoWidget*>(m_widget)->showUserImage(image);
#endif
}
/*!
* \brief Returns a suitable size hint for this widget
* \details
* This function is used internally by Qt.
*/
QSize QMPwidget::sizeHint() const
{
if (m_process->m_mediaInfo.ok && !m_process->m_mediaInfo.size.isNull()) {
return m_process->m_mediaInfo.size;
}
return QWidget::sizeHint();
}
/*!
* \brief Starts the MPlayer process with the given arguments
* \details
* If there's another process running, it will be terminated first. MPlayer
* will be run in idle mode and is avaiting your commands, e.g. via load().
*
* \param args MPlayer command line arguments
*/
void QMPwidget::start(const QStringList &args)
{
if (m_process->processState() == QProcess::Running) {
m_process->quit();
}
m_process->start(m_widget, args);
}
/*!
* \brief Loads a file or url and starts playback
*
* \param url File patho or url
*/
void QMPwidget::load(const QString &url)
{
Q_ASSERT_X(m_process->state() != QProcess::NotRunning, "QMPwidget::load()", "MPlayer process not started yet");
// From the MPlayer slave interface documentation:
// "Try using something like [the following] to switch to the next file.
// It avoids audio playback starting to play the old file for a short time
// before switching to the new one.
writeCommand("pausing_keep_force pt_step 1");
writeCommand("get_property pause");
writeCommand(QString("loadfile '%1'").arg(url));
}
/*!
* \brief Resumes playback
*/
void QMPwidget::play()
{
if (m_process->m_state == PausedState) {
m_process->pause();
}
}
/*!
* \brief Pauses playback
*/
void QMPwidget::pause()
{
if (m_process->m_state == PlayingState) {
m_process->pause();
}
}
/*!
* \brief Stops playback
*/
void QMPwidget::stop()
{
m_process->stop();
}
/*!
* \brief Media playback seeking
*
* \param offset Seeking offset in seconds
* \param whence Seeking mode
* \returns \p true If the seeking mode is valid
* \sa tell()
*/
bool QMPwidget::seek(int offset, int whence)
{
return seek(double(offset), whence);
}
/*!
* \brief Media playback seeking
*
* \param offset Seeking offset in seconds
* \param whence Seeking mode
* \returns \p true If the seeking mode is valid
* \sa tell()