source: smplayer/trunk/src/playerprocess.cpp@ 176

Last change on this file since 176 was 176, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.4

File size: 4.2 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "playerprocess.h"
20#include <QFileInfo>
21#include <QDir>
22#include <QDebug>
23
24#ifdef MPV_SUPPORT
25#include "mpvprocess.h"
26#endif
27
28#ifdef MPLAYER_SUPPORT
29#include "mplayerprocess.h"
30#endif
31
32
33PlayerProcess::PlayerProcess(QObject * parent) : MyProcess(parent) {
34#if NOTIFY_SUB_CHANGES
35 qRegisterMetaType<SubTracks>("SubTracks");
36#endif
37
38#if NOTIFY_AUDIO_CHANGES
39 qRegisterMetaType<Tracks>("Tracks");
40#endif
41
42#if NOTIFY_CHAPTER_CHANGES
43 qRegisterMetaType<Chapters>("Chapters");
44#endif
45}
46
47void PlayerProcess::writeToStdin(QString text) {
48 if (isRunning()) {
49 qDebug("PlayerProcess::writeToStdin: %s", text.toUtf8().constData());
50#if !defined(Q_OS_OS2)
51 #ifdef Q_OS_WIN
52 write( text.toUtf8() + "\n");
53 #else
54 write( text.toLocal8Bit() + "\n");
55 #endif
56#else
57 PpipeWrite( text.toLocal8Bit() + "\n");
58#endif
59 } else {
60 qWarning("PlayerProcess::writeToStdin: process not running");
61 }
62#ifdef Q_OS_OS2
63 if (text == "quit" || text == "quit\n") {
64 PpipeClose();
65 }
66#endif
67
68}
69
70PlayerProcess * PlayerProcess::createPlayerProcess(const QString & player_bin, QObject * parent) {
71 PlayerProcess * proc = 0;
72
73#if defined(MPV_SUPPORT) && defined(MPLAYER_SUPPORT)
74 if (PlayerID::player(player_bin) == PlayerID::MPLAYER) {
75 qDebug() << "PlayerProcess::createPlayerProcess: creating MplayerProcess";
76 proc = new MplayerProcess(parent);
77 } else {
78 qDebug() << "PlayerProcess::createPlayerProcess: creating MPVProcess";
79 proc = new MPVProcess(parent);
80 }
81#else
82 #ifdef MPV_SUPPORT
83 proc = new MPVProcess(parent);
84 #endif
85 #ifdef MPLAYER_SUPPORT
86 proc = new MplayerProcess(parent);
87 #endif
88#endif
89
90 return proc;
91}
92
93#ifdef CAPTURE_STREAM
94void PlayerProcess::setCaptureDirectory(const QString & dir) {
95 capture_filename = "";
96 if (!dir.isEmpty() && (QFileInfo(dir).isDir())) {
97 // Find a unique filename
98 QString prefix = "capture";
99 for (int n = 1; ; n++) {
100 QString c = QDir::toNativeSeparators(QString("%1/%2_%3.dump").arg(dir).arg(prefix).arg(n, 4, 10, QChar('0')));
101 if (!QFile::exists(c)) {
102 capture_filename = c;
103 return;
104 }
105 }
106 }
107}
108#endif
109
110#ifdef Q_OS_OS2
111void PlayerProcess::PpipeOpen(const char *szPipeName) {
112 DosCreateNPipe( szPipeName, &hpipe, NP_ACCESS_DUPLEX, 1, 1024, 1024, 0 );
113}
114
115void PlayerProcess::PpipeClose( void ) {
116 DosClose( hpipe );
117}
118
119void PlayerProcess::PpipeWrite( const QByteArray text ) {
120 // MPlayer quitted ?
121 if ( !isRunning() )
122 return;
123
124// as things could hang when pipe communication is done direct here, i do a seperate thread for it
125 pipeThread = new PipeThread(text, hpipe);
126
127 pipeThread->start();
128 while (!pipeThread->isRunning() && !pipeThread->isFinished()) {
129 qDebug("we sleep");
130 DosSleep(10);
131 }
132// we wait for max 2 seconds for the thread to be ended (we to this with max 20 loops)
133 int count = 0;
134 while (!pipeThread->wait(100) && count < 20) {
135 count ++;
136 }
137 if (count >= 20) {
138 pipeThread->terminate();
139 qDebug("pipe communication terminated");
140 }
141 delete pipeThread;
142}
143
144PipeThread::PipeThread(const QByteArray t, const HPIPE pipe) {
145 text = t;
146 hpipe = pipe;
147}
148
149PipeThread::~PipeThread() {
150}
151
152void PipeThread::run() {
153 ULONG cbActual;
154 APIRET rc = NO_ERROR;
155
156 rc = DosConnectNPipe( hpipe );
157 if (rc != NO_ERROR)
158 return;
159
160// qDebug("pipe connected");
161 DosWrite( hpipe, text.data(), strlen( text.data() ), &cbActual );
162
163 // Wait for ACK
164 DosRead( hpipe, &cbActual, sizeof( ULONG ), &cbActual );
165 DosDisConnectNPipe( hpipe );
166 return;
167}
168#endif
169
170#include "moc_playerprocess.cpp"
Note: See TracBrowser for help on using the repository browser.