Ignore:
Timestamp:
Dec 27, 2011, 5:44:12 PM (14 years ago)
Author:
Silvan Scherrer
Message:

SMPlayer: latest svn update

Location:
smplayer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • smplayer/trunk

  • smplayer/trunk/src/mplayerprocess.cpp

    r112 r119  
    11/*  smplayer, GUI front-end for mplayer.
    2     Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
     2    Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org>
    33
    44    This program is free software; you can redistribute it and/or modify
     
    8383        return waitForStarted();
    8484#else
    85         bool r = waitForStarted();
    86         if (r) {
    87            pidMP = QProcess::pid();
    88            qDebug("MPlayer PID %i", pidMP);
    89            MPpipeOpen();
    90         }
    91         return r;
     85        bool r = waitForStarted();
     86        if (r) {
     87                pidMP = QProcess::pid();
     88                qDebug("MPlayer PID %i", pidMP);
     89                MPpipeOpen();
     90        }
     91        return r;
    9292#endif
    9393}
     
    9999                write( text.toLocal8Bit() + "\n");
    100100#else
    101                 MPpipeWrite( text.toLocal8Bit() + "\n");
     101                MPpipeWrite( text.toLocal8Bit() + "\n");
    102102#endif
    103103        } else {
     
    105105        }
    106106#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
    112113#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;
     114void 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
     120void MplayerProcess::MPpipeClose( void ) {
     121        DosClose( hpipe );
     122}
     123
     124void MplayerProcess::MPpipeWrite( const QByteArray text ) {
     125        // MPlayer quitted ?
     126        if ( !isRunning() )
     127                return;
    130128
    131129// as things could hang when pipe communication is done direct here, i do a seperate thread for it
    132     pipeThread = new PipeThread(text, hpipe);
     130        pipeThread = new PipeThread(text, hpipe);
    133131   
    134     pipeThread->start();
    135     while (!pipeThread->isRunning() && !pipeThread->isFinished()) {
    136        qDebug("we sleep");
    137        DosSleep(10);
    138     }
     132        pipeThread->start();
     133        while (!pipeThread->isRunning() && !pipeThread->isFinished()) {
     134                qDebug("we sleep");
     135                DosSleep(10);
     136        }
    139137// 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}
    152148#endif
    153149
     
    874870
    875871#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 
     872PipeThread::PipeThread(const QByteArray t, const HPIPE pipe) {
     873        text = t;
     874        hpipe = pipe;
     875}
     876
     877PipeThread::~PipeThread() {
     878}
     879
     880void 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}
    905896#endif
    906897
Note: See TracChangeset for help on using the changeset viewer.