Changeset 119 for smplayer/trunk/src/mplayerprocess.cpp
- Timestamp:
- Dec 27, 2011, 5:44:12 PM (14 years ago)
- Location:
- smplayer/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/trunk
-
Property svn:mergeinfo
set to
/smplayer/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
smplayer/trunk/src/mplayerprocess.cpp
r112 r119 1 1 /* smplayer, GUI front-end for mplayer. 2 Copyright (C) 2006-201 0Ricardo Villalba <rvm@escomposlinux.org>2 Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org> 3 3 4 4 This program is free software; you can redistribute it and/or modify … … 83 83 return waitForStarted(); 84 84 #else 85 86 87 88 89 90 91 85 bool r = waitForStarted(); 86 if (r) { 87 pidMP = QProcess::pid(); 88 qDebug("MPlayer PID %i", pidMP); 89 MPpipeOpen(); 90 } 91 return r; 92 92 #endif 93 93 } … … 99 99 write( text.toLocal8Bit() + "\n"); 100 100 #else 101 101 MPpipeWrite( text.toLocal8Bit() + "\n"); 102 102 #endif 103 103 } else { … … 105 105 } 106 106 #ifdef Q_OS_OS2 107 if (text == "quit" || text == "quit\n") { 108 MPpipeClose(); 109 } 110 #endif 111 } 107 if (text == "quit" || text == "quit\n") { 108 MPpipeClose(); 109 } 110 #endif 111 } 112 112 113 #ifdef Q_OS_OS2 113 void MplayerProcess::MPpipeOpen() 114 { 115 char szPipeName[ 100 ]; 116 sprintf( szPipeName, "\\PIPE\\MPLAYER\\%x", pidMP ); 117 DosCreateNPipe( szPipeName, &hpipe, NP_ACCESS_DUPLEX, 1, 1024, 1024, 0 ); 118 } 119 120 void MplayerProcess::MPpipeClose( void ) 121 { 122 DosClose( hpipe ); 123 } 124 125 void MplayerProcess::MPpipeWrite( const QByteArray text ) 126 { 127 // MPlayer quitted ? 128 if ( !isRunning() ) 129 return; 114 void MplayerProcess::MPpipeOpen() { 115 char szPipeName[ 100 ]; 116 sprintf( szPipeName, "\\PIPE\\MPLAYER\\%x", pidMP ); 117 DosCreateNPipe( szPipeName, &hpipe, NP_ACCESS_DUPLEX, 1, 1024, 1024, 0 ); 118 } 119 120 void MplayerProcess::MPpipeClose( void ) { 121 DosClose( hpipe ); 122 } 123 124 void MplayerProcess::MPpipeWrite( const QByteArray text ) { 125 // MPlayer quitted ? 126 if ( !isRunning() ) 127 return; 130 128 131 129 // as things could hang when pipe communication is done direct here, i do a seperate thread for it 132 130 pipeThread = new PipeThread(text, hpipe); 133 131 134 135 136 137 138 132 pipeThread->start(); 133 while (!pipeThread->isRunning() && !pipeThread->isFinished()) { 134 qDebug("we sleep"); 135 DosSleep(10); 136 } 139 137 // we wait for max 2 seconds for the thread to be ended (we to this with max 20 loops) 140 int count = 0; 141 while (!pipeThread->wait(100) && count < 20) { 142 count ++; 143 } 144 if (count >= 20) { 145 pipeThread->terminate(); 146 qDebug("pipe communication terminated"); 147 } 148 delete pipeThread; 149 150 } 151 138 int count = 0; 139 while (!pipeThread->wait(100) && count < 20) { 140 count ++; 141 } 142 if (count >= 20) { 143 pipeThread->terminate(); 144 qDebug("pipe communication terminated"); 145 } 146 delete pipeThread; 147 } 152 148 #endif 153 149 … … 874 870 875 871 #ifdef Q_OS_OS2 876 PipeThread::PipeThread(const QByteArray t, const HPIPE pipe) 877 { 878 text = t; 879 hpipe = pipe; 880 } 881 882 PipeThread::~PipeThread() 883 { 884 885 } 886 887 void PipeThread::run() 888 { 889 ULONG cbActual; 890 APIRET rc = NO_ERROR; 891 892 rc = DosConnectNPipe( hpipe ); 893 if (rc != NO_ERROR) 894 return; 895 896 // qDebug("pipe connected"); 897 DosWrite( hpipe, text.data(), strlen( text.data() ), &cbActual ); 898 899 // Wait for ACK 900 DosRead( hpipe, &cbActual, sizeof( ULONG ), &cbActual ); 901 DosDisConnectNPipe( hpipe ); 902 return; 903 } 904 872 PipeThread::PipeThread(const QByteArray t, const HPIPE pipe) { 873 text = t; 874 hpipe = pipe; 875 } 876 877 PipeThread::~PipeThread() { 878 } 879 880 void PipeThread::run() { 881 ULONG cbActual; 882 APIRET rc = NO_ERROR; 883 884 rc = DosConnectNPipe( hpipe ); 885 if (rc != NO_ERROR) 886 return; 887 888 // qDebug("pipe connected"); 889 DosWrite( hpipe, text.data(), strlen( text.data() ), &cbActual ); 890 891 // Wait for ACK 892 DosRead( hpipe, &cbActual, sizeof( ULONG ), &cbActual ); 893 DosDisConnectNPipe( hpipe ); 894 return; 895 } 905 896 #endif 906 897
Note:
See TracChangeset
for help on using the changeset viewer.