Ignore:
Timestamp:
Dec 22, 2011, 6:27:52 PM (14 years ago)
Author:
Silvan Scherrer
Message:

smplayer vendor udate

File:
1 edited

Legend:

Unmodified
Added
Removed
  • smplayer/vendor/current/src/mplayerprocess.cpp

    r90 r118  
    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
     
    7979
    8080        MyProcess::start();
     81
     82#if !defined(Q_OS_OS2)
    8183        return waitForStarted();
     84#else
     85        bool r = waitForStarted();
     86        if (r) {
     87                pidMP = QProcess::pid();
     88                qDebug("MPlayer PID %i", pidMP);
     89                MPpipeOpen();
     90        }
     91        return r;
     92#endif
    8293}
    8394
     
    8596        if (isRunning()) {
    8697                //qDebug("MplayerProcess::writeToStdin");
     98#if !defined(Q_OS_OS2)
    8799                write( text.toLocal8Bit() + "\n");
     100#else
     101                MPpipeWrite( text.toLocal8Bit() + "\n");
     102#endif
    88103        } else {
    89104                qWarning("MplayerProcess::writeToStdin: process not running");
    90105        }
    91 }
     106#ifdef Q_OS_OS2
     107        if (text == "quit" || text == "quit\n") {
     108                MPpipeClose();
     109        }
     110#endif
     111}
     112
     113#ifdef Q_OS_OS2
     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;
     128
     129// as things could hang when pipe communication is done direct here, i do a seperate thread for it
     130        pipeThread = new PipeThread(text, hpipe);
     131   
     132        pipeThread->start();
     133        while (!pipeThread->isRunning() && !pipeThread->isFinished()) {
     134                qDebug("we sleep");
     135                DosSleep(10);
     136        }
     137// we wait for max 2 seconds for the thread to be ended (we to this with max 20 loops)
     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}
     148#endif
    92149
    93150static QRegExp rx_av("^[AV]: *([0-9,:.-]+)");
     
    812869}
    813870
     871#ifdef Q_OS_OS2
     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}
     896#endif
     897
    814898#include "moc_mplayerprocess.cpp"
Note: See TracChangeset for help on using the changeset viewer.