From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- mpeglib/lib/output/Makefile.am | 52 ++++ mpeglib/lib/output/artsOutputStream.cpp | 205 ++++++++++++++ mpeglib/lib/output/artsOutputStream.h | 123 ++++++++ mpeglib/lib/output/audioData.cpp | 100 +++++++ mpeglib/lib/output/audioData.h | 71 +++++ mpeglib/lib/output/audioDataArray.cpp | 138 +++++++++ mpeglib/lib/output/audioDataArray.h | 55 ++++ mpeglib/lib/output/audioTime.cpp | 154 ++++++++++ mpeglib/lib/output/audioTime.h | 68 +++++ mpeglib/lib/output/avSyncer.cpp | 386 ++++++++++++++++++++++++++ mpeglib/lib/output/avSyncer.h | 96 +++++++ mpeglib/lib/output/dspX11OutputStream.cpp | 236 ++++++++++++++++ mpeglib/lib/output/dspX11OutputStream.h | 89 ++++++ mpeglib/lib/output/outPlugin.cpp | 71 +++++ mpeglib/lib/output/outPlugin.h | 44 +++ mpeglib/lib/output/outputStream.cpp | 238 ++++++++++++++++ mpeglib/lib/output/outputStream.h | 151 ++++++++++ mpeglib/lib/output/performance.cpp | 50 ++++ mpeglib/lib/output/performance.h | 34 +++ mpeglib/lib/output/pluginInfo.cpp | 65 +++++ mpeglib/lib/output/pluginInfo.h | 48 ++++ mpeglib/lib/output/threadSafeOutputStream.cpp | 153 ++++++++++ mpeglib/lib/output/threadSafeOutputStream.h | 67 +++++ mpeglib/lib/output/windowOut.cpp | 64 +++++ mpeglib/lib/output/windowOut.h | 53 ++++ mpeglib/lib/output/yuvDumper.cpp | 81 ++++++ mpeglib/lib/output/yuvDumper.h | 51 ++++ 27 files changed, 2943 insertions(+) create mode 100644 mpeglib/lib/output/Makefile.am create mode 100644 mpeglib/lib/output/artsOutputStream.cpp create mode 100644 mpeglib/lib/output/artsOutputStream.h create mode 100644 mpeglib/lib/output/audioData.cpp create mode 100644 mpeglib/lib/output/audioData.h create mode 100644 mpeglib/lib/output/audioDataArray.cpp create mode 100644 mpeglib/lib/output/audioDataArray.h create mode 100644 mpeglib/lib/output/audioTime.cpp create mode 100644 mpeglib/lib/output/audioTime.h create mode 100644 mpeglib/lib/output/avSyncer.cpp create mode 100644 mpeglib/lib/output/avSyncer.h create mode 100644 mpeglib/lib/output/dspX11OutputStream.cpp create mode 100644 mpeglib/lib/output/dspX11OutputStream.h create mode 100644 mpeglib/lib/output/outPlugin.cpp create mode 100644 mpeglib/lib/output/outPlugin.h create mode 100644 mpeglib/lib/output/outputStream.cpp create mode 100644 mpeglib/lib/output/outputStream.h create mode 100644 mpeglib/lib/output/performance.cpp create mode 100644 mpeglib/lib/output/performance.h create mode 100644 mpeglib/lib/output/pluginInfo.cpp create mode 100644 mpeglib/lib/output/pluginInfo.h create mode 100644 mpeglib/lib/output/threadSafeOutputStream.cpp create mode 100644 mpeglib/lib/output/threadSafeOutputStream.h create mode 100644 mpeglib/lib/output/windowOut.cpp create mode 100644 mpeglib/lib/output/windowOut.h create mode 100644 mpeglib/lib/output/yuvDumper.cpp create mode 100644 mpeglib/lib/output/yuvDumper.h (limited to 'mpeglib/lib/output') diff --git a/mpeglib/lib/output/Makefile.am b/mpeglib/lib/output/Makefile.am new file mode 100644 index 00000000..e430550e --- /dev/null +++ b/mpeglib/lib/output/Makefile.am @@ -0,0 +1,52 @@ +# liboutplugin - Makefile.am + +INCLUDES = $(all_includes) + + +noinst_LTLIBRARIES = liboutput.la + +noinst_HEADERS = windowOut.h \ + audioData.h audioDataArray.h \ + performance.h yuvDumper.h + +kmpgincludedir = $(includedir)/$(THIS_LIB_NAME)/output + +kmpginclude_HEADERS = outputStream.h pluginInfo.h \ + outPlugin.h dspX11OutputStream.h \ + artsOutputStream.h audioTime.h \ + avSyncer.h threadSafeOutputStream.h + + +liboutput_la_SOURCES = outPlugin.cpp outputStream.cpp \ + dspX11OutputStream.cpp \ + windowOut.cpp \ + audioTime.cpp \ + audioData.cpp audioDataArray.cpp \ + avSyncer.cpp performance.cpp \ + artsOutputStream.cpp \ + pluginInfo.cpp yuvDumper.cpp \ + threadSafeOutputStream.cpp + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mpeglib/lib/output/artsOutputStream.cpp b/mpeglib/lib/output/artsOutputStream.cpp new file mode 100644 index 00000000..571dd258 --- /dev/null +++ b/mpeglib/lib/output/artsOutputStream.cpp @@ -0,0 +1,205 @@ +/* + output to arts + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + +#include "artsOutputStream.h" +#include "windowOut.h" +#include "avSyncer.h" +#include "../util/abstract/threadQueue.h" + + +ArtsOutputStream::ArtsOutputStream(void (*streamStateChangeCallback)(void*)) { + + audioTime=new AudioTime(); + x11Window=new WindowOut(); + privateBufferSize=1024*32; + + // we can dynamically change the buffer size, + // over a config switch in avSyncer + // but for now this should be ok + // Arts must pass the total size of the audiobuffer + // from /dev/dsp + connected nodes + // or arts need a video interface + stream=new BufferInputStream(privateBufferSize,1024*64,"artsLoopback"); + avSyncer=new AVSyncer(privateBufferSize); + + // with the ThreadQueue we protect all calls to the + // x11 output. This is necessary, because arts may call + // in the future "config" entries to switch the video + // mode (full,double,desktop) + threadQueue=new ThreadQueue(); + // we set it, but its never used ! + this->streamStateChangeCallback=streamStateChangeCallback; +} + + +ArtsOutputStream::~ArtsOutputStream() { + delete stream; + delete audioTime; + delete x11Window; + delete avSyncer; + delete threadQueue; +} + + + + +int ArtsOutputStream::audioSetup(int freq,int stereo, + int sign,int big,int sampleSize) { + audioTime->setFormat(stereo,sampleSize,freq,sign,big); + avSyncer->audioSetup(freq,stereo,sign,big,sampleSize); + + OutputStream::audioSetup(freq,stereo,sign,big,sampleSize); + + return true; +} + +AudioTime* ArtsOutputStream::getAudioTime() { + return audioTime; +} + + +void ArtsOutputStream::audioClose() { + audioTime->setTime(0.0); + // if we close this stream the thread is kicked out. + stream->close(); + stream->clear(); + avSyncer->audioClose(); +} + +void ArtsOutputStream::audioFlush() { + OutputStream::audioFlush(); + audioClose(); +} + + +void ArtsOutputStream::audioOpen() { + audioTime->setTime(0.0); + // if we close this stream the thread is kicked out. + stream->open("artsLoopback"); +} + + +int ArtsOutputStream::audioPlay(TimeStamp* startStamp, + TimeStamp* endStamp,char *buffer, int size) { + int write=size; + + + // we call this for stream state handling + OutputStream::audioPlay(startStamp,endStamp,buffer,size); + + // store sync information + avSyncer->audioPlay(startStamp,endStamp,buffer,size); + + + // here we simulate our own blocking audio device + if (stream->isOpen()==false) { + audioTime->sleepWrite(size); + } else { + write=stream->write(buffer,size,startStamp); + } + return write; + +} + + +int ArtsOutputStream::read(char** buffer,int bytes) { + int back=stream->readRemote(buffer,bytes); + return back; +} + + +void ArtsOutputStream::forwardReadPtr(int bytes) { + audioTime->forwardTime(bytes); + stream->forwardReadPtr(bytes); + +} + + + + +int ArtsOutputStream::getPreferredDeliverSize() { + return avSyncer->getPreferredDeliverSize(); +} + + +int ArtsOutputStream::openWindow(int width, int height,const char *title) { + threadQueue->waitForExclusiveAccess(); + int back=x11Window->openWindow(width,height,title); + threadQueue->releaseExclusiveAccess(); + + return back; +} + +int ArtsOutputStream::x11WindowId() { + return x11Window->x11WindowId(); +} + +void ArtsOutputStream::closeWindow() { + threadQueue->waitForExclusiveAccess(); + x11Window->closeWindow(); + threadQueue->releaseExclusiveAccess(); +} + +void ArtsOutputStream::flushWindow() { + threadQueue->waitForExclusiveAccess(); + x11Window->flushWindow(); + threadQueue->releaseExclusiveAccess(); +} + + +PictureArray* ArtsOutputStream::lockPictureArray() { + PictureArray* back; + threadQueue->waitForExclusiveAccess(); + back=x11Window->lockPictureArray(); + threadQueue->releaseExclusiveAccess(); + return back; +} + + +void ArtsOutputStream::unlockPictureArray(PictureArray* pictureArray) { + + + YUVPicture* pic=pictureArray->getYUVPictureCallback(); + if (avSyncer->syncPicture(pic)==false) { + return; + } + threadQueue->waitForExclusiveAccess(); + x11Window->unlockPictureArray(pictureArray); + threadQueue->releaseExclusiveAccess(); + +} + +int ArtsOutputStream::getBufferFillgrade() { + return stream->getFillgrade(); +} + +int ArtsOutputStream::getFrameusec() { + return avSyncer->getFrameusec(); +} + + + +void ArtsOutputStream::setAudioBufferSize(int size) { + avSyncer->setAudioBufferSize(privateBufferSize+size); +} + + +void ArtsOutputStream::config(const char* key,const char* value, + void* user_data) { + + threadQueue->waitForExclusiveAccess(); + avSyncer->config(key,value,user_data); + x11Window->config(key,value,user_data); + threadQueue->releaseExclusiveAccess(); +} diff --git a/mpeglib/lib/output/artsOutputStream.h b/mpeglib/lib/output/artsOutputStream.h new file mode 100644 index 00000000..757022fd --- /dev/null +++ b/mpeglib/lib/output/artsOutputStream.h @@ -0,0 +1,123 @@ +/* + output to arts + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + + +#ifndef __ARTSOUTPUTSTREAM_H +#define __ARTSOUTPUTSTREAM_H + +#include "outputStream.h" +#include "../input/bufferInputStream.h" +#include "audioTime.h" + + +class WindowOut; +class AVSyncer; + + + + +/** + a word about synchronisation: Arts currently has not asynchronous + starting of stream, which means, poll if stream is initialized + or set a callbackfunction. + + mpeglib is threaded and would not have much problems + with a "callback" but currently we only support blocking wait + for initilisation. + + I think, if people realize that smooth mixing of streams + is impossible(because of the blocking start behaviour), + this will become a desired feature :-) + +*/ + + +/** + This class offers a blocking device, its behaviour is similar + to /dev/dsp we use a buffer to store the pcm data, if + we open/close the buffer the stored data is removed + and the blocking thread is "kicked" + + Arts must first wait for an init signal. it has its own + method to check for eof. during seek we close this + device, after seek we reopen it. + + close and open have the same functionality, they simply + clear the buffer. +*/ + + + +class ArtsOutputStream : public OutputStream { + + BufferInputStream* stream; + AudioTime* audioTime; + + void (*streamStateChangeCallback)(void*); + + WindowOut* x11Window; + AVSyncer* avSyncer; + int privateBufferSize; + class ThreadQueue* threadQueue; + + public: + ArtsOutputStream(void (*streamStateChangeCallback)(void*)); + ~ArtsOutputStream(); + + // Audio part + + int audioSetup(int freq,int stereo,int sign,int big,int sampleSize); + void audioClose(); + void audioOpen(); + void audioFlush(); + + int audioPlay(TimeStamp* startStamp, + TimeStamp* endStamp,char *buffer, int size); + + + AudioTime* getAudioTime(); + + int getPreferredDeliverSize(); + + // Video part + + int openWindow(int width, int height,const char *title); + int x11WindowId(); + void closeWindow(); + void flushWindow(); + + PictureArray* lockPictureArray(); + void unlockPictureArray(PictureArray* pictureArray); + + int getFrameusec(); + + void config(const char* key,const char* value,void* user_data); + + // Remote read extension + + int read(char** buffer,int bytes); + void forwardReadPtr(int bytes); + + // buffer control + int getBufferFillgrade(); + + // sync control + void setAudioBufferSize(int size); + + private: + void sendSignal(int state,int value); + void initStream(); + +}; +#endif diff --git a/mpeglib/lib/output/audioData.cpp b/mpeglib/lib/output/audioData.cpp new file mode 100644 index 00000000..d28e74cf --- /dev/null +++ b/mpeglib/lib/output/audioData.cpp @@ -0,0 +1,100 @@ +/* + describes a paket oriented audioData, because Im fed up + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + + +#include "audioData.h" + +#include + +using namespace std; + +AudioData::AudioData() { + pcmLen=0; + audioTime=new AudioTime(); + start=new TimeStamp(); + end=new TimeStamp(); + writeStamp=new TimeStamp(); +} + + +AudioData::~AudioData() { + delete audioTime; + delete start; + delete end; + delete writeStamp; +} + + +void AudioData::copyTo(AudioData* dest) { + dest->setAudioTime(getAudioTime()); + dest->setStart(getStart()); + dest->setEnd(getEnd()); + dest->setWrite(getWrite()); + dest->setPCMLen(getPCMLen()); +} + + +int AudioData::getPCMLen(){ + return pcmLen; +} + +void AudioData::setPCMLen(int pcmLen) { + this->pcmLen=pcmLen; +} + +void AudioData::setAudioTime(AudioTime* aTime) { + aTime->copyTo(audioTime); +} + +AudioTime* AudioData::getAudioTime() { + return audioTime; +} + + +void AudioData::setStart(TimeStamp* s) { + s->copyTo(start); +} + + +TimeStamp* AudioData::getStart() { + return start; +} + +void AudioData::setEnd(TimeStamp* e) { + e->copyTo(end); +} + + +TimeStamp* AudioData::getEnd() { + return end; +} + +void AudioData::setWrite(TimeStamp* e) { + e->copyTo(writeStamp); +} + + +TimeStamp* AudioData::getWrite() { + return writeStamp; +} + + + +void AudioData::print() { + cout << "AudioData::print [START]"<print("audioData start"); + end->print("audioData end"); + cout << "pcmlen:"< + +using namespace std; + + +AudioDataArray::AudioDataArray(int entries) { + + this->entries=entries; + fillgrade=0; + readPos=0; + writePos=0; + pcmSum=0; + abs_thread_mutex_init(&writeInMut); + abs_thread_mutex_init(&changeMut); + + audioDataArray=new AudioData*[entries]; + + int i; + for(i=0;igetPCMLen(); + readPos++; + fillgrade--; + if (readPos == entries-1) { + readPos=0; + } +} + +int AudioDataArray::getPCMSum() { + return pcmSum; +} + + + +int AudioDataArray::insertAudioData(AudioData* src) { + lockStampArray(); + + int back=true; + src->copyTo(audioDataArray[writePos]); + pcmSum+=src->getPCMLen(); + + writePos++; + fillgrade++; + if (writePos == entries-1) { + writePos=0; + } + if (fillgrade == entries) { + cout <<" Audiodata::array overfull forward"< + +using namespace std; + + +AudioTime::AudioTime(){ + time=0.0; +} + + +AudioTime::~AudioTime() { +} + + +void AudioTime::setFormat(int stereo,int samplesize,int speed,int sign, int bigendian) { + setStereo(stereo); + setSampleSize(samplesize); + setSpeed(speed); + setSign(sign); + setBigendian(bigendian); +} + + +int AudioTime::getStereo() { + return stereo; +} + + +int AudioTime::getSampleSize() { + return samplesize; +} + + +int AudioTime::getSpeed() { + return speed; +} + +int AudioTime::getSign() { + return _sign; +} + +int AudioTime::getBigendian() { + return _bigendian; +} + +void AudioTime::setStereo(int stereo) { + this->stereo=stereo; +} + + +void AudioTime::setSampleSize(int samplesize) { + this->samplesize=samplesize; +} + + +void AudioTime::setSpeed(int speed) { + this->speed=speed; +} + +void AudioTime::setSign(int sign) { + this->_sign=sign; +} + +void AudioTime::setBigendian(int bigendian) { + this->_bigendian = bigendian; +} + +float AudioTime::getTime() { + return time; +} + + +void AudioTime::setTime(float time) { + this->time=time; +} + + +void AudioTime::forwardTime(int bytes){ + time+=calculateTime(bytes); +} + + +float AudioTime::calculateTime(int bytes) { + float back=0; + + bytes=bytes/(samplesize/8); + if (stereo==1) { + bytes=bytes/2; + } + if (speed != 0) { + back=(float)bytes/(float)speed; + } + return back; +} + + +/** + How much byte we need for time usecs? +*/ +int AudioTime::calculateBytes(float time) { + float back=time; + + if (speed != 0) { + back=back*(float)speed; + } + back=back*(float)(samplesize/8); + if (stereo==1) { + back=back*2.0; + } + return (int)back; +} + + + +void AudioTime::sleepWrite(int size) { + timeval_t time; + float timeLength=calculateTime(size); + time.tv_sec=(long)timeLength; + time.tv_usec=(long)(1000000*(timeLength-time.tv_sec)); + TimeWrapper::usleep(&time); +} + + +void AudioTime::print() { + cout << "AudioTime-begin-"<setStereo(getStereo()); + dest->setSampleSize(getSampleSize()); + dest->setSpeed(getSpeed()); +} + diff --git a/mpeglib/lib/output/audioTime.h b/mpeglib/lib/output/audioTime.h new file mode 100644 index 00000000..3b16bb02 --- /dev/null +++ b/mpeglib/lib/output/audioTime.h @@ -0,0 +1,68 @@ +/* + defines the format of an audio stream + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + + +#ifndef __AUDIOTIME_H +#define __AUDIOTIME_H + +#include "../util/timeWrapper.h" + +class AudioTime { + + int stereo; + int samplesize; + int speed; + int _sign; + int _bigendian; + float time; + + public: + AudioTime(); + ~AudioTime(); + + //cd-quality:true,16,44100 + void setFormat(int stereo,int samplesize,int speed,int sign=true, int bigendian=false); + + int getStereo(); + int getSampleSize(); + int getSpeed(); + int getSign(); + int getBigendian(); + + void setStereo(int stereo); + void setSampleSize(int samplesize); + void setSpeed(int speed); + void setSign(int sign); + void setBigendian(int bigendian); + + + float getTime(); + void setTime(float time); + void forwardTime(int bytes); + + // do not modify the internal time + float calculateTime(int bytes); + int calculateBytes(float time); + + void sleepWrite(int size); + + + void copyTo(AudioTime* audioTime); + void print(); + +}; + + + +#endif diff --git a/mpeglib/lib/output/avSyncer.cpp b/mpeglib/lib/output/avSyncer.cpp new file mode 100644 index 00000000..ca12a21e --- /dev/null +++ b/mpeglib/lib/output/avSyncer.cpp @@ -0,0 +1,386 @@ +/* + encapsulates the syncing methods, to use it in other classes + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + +#include "avSyncer.h" + +#include "audioDataArray.h" +#include "performance.h" + +#include + +using namespace std; + +AVSyncer::AVSyncer(int bufferSize) { + oneFrameTime=0; + onePicFrameInAudioBytes=8192; + this->bufferSize=bufferSize; + + abs_thread_mutex_init(&writeInMut); + abs_thread_mutex_init(&changeMut); + + + audioDataInsert=new AudioData(); + audioDataArray=new AudioDataArray(400); + audioDataCurrent=audioDataArray->readAudioData(); + + startAudio=new TimeStamp(); + endAudio=new TimeStamp(); + audioTime=new AudioTime(); + lAudioRunning=false; + performance=new Performance(); + + waitTime=new TimeStamp(); + diffTime=new TimeStamp(); + videoTimeStamp=new TimeStamp(); + + lPerformance=false; + lavSync=true; + + +} + + +AVSyncer::~AVSyncer() { + delete audioDataArray; + delete audioDataInsert; + delete audioTime; + delete startAudio; + delete endAudio; + abs_thread_mutex_destroy(&writeInMut); + abs_thread_mutex_destroy(&changeMut); + delete waitTime; + delete diffTime; + delete performance; + delete videoTimeStamp; +} + + + +int AVSyncer::audioSetup(int frequency,int stereo,int sign, + int big,int sixteen) { + audioTime->setFormat(stereo,sixteen,frequency,sign,big); + setAudioRunning(true); + return true; +} + + +int AVSyncer::audioPlay(TimeStamp* startStamp, + TimeStamp* endStamp,char* , int size) { + + + + + audioDataInsert->setStart(startStamp); + audioDataInsert->setEnd(endStamp); + audioDataInsert->setAudioTime(audioTime); + audioDataInsert->setPCMLen(size); + + setAudioSync(audioDataInsert); + return size; +} + + + +void AVSyncer::audioClose(void) { + lockSyncData(); + setAudioRunning(false); + audioDataArray->clear(); + unlockSyncData(); +} + + + + + +int AVSyncer::getPreferredDeliverSize() { + return onePicFrameInAudioBytes; +} + + + +int AVSyncer::getFrameusec() { + lockSyncData(); + int back=oneFrameTime; + unlockSyncData(); + return back; +} + +void AVSyncer::setAudioBufferSize(int size) { + bufferSize=size; +} + + +void AVSyncer::config(const char* key,const char* value,void*) { + if (strcmp(key,"-s")==0) { + if (strcmp(value,"on")==0) { + lavSync=true; + cout << "******** lavSync on"<insertAudioData(audioData); + int pcmSum=audioDataArray->getPCMSum(); + if (pcmSum >= bufferSize) { + audioDataCurrent=audioDataArray->readAudioData(); + setAudioRunning(true); + audioDataArray->forward(); + } + TimeStamp* startAudio=audioDataCurrent->getStart(); + int lpts=startAudio->getPTSFlag(); + + if (lpts==true) { + SyncClock* syncClock=startAudio->getSyncClock(); + if (syncClock != NULL) { + double pts=startAudio->getPTSTimeStamp(); + double scr=startAudio->getSCRTimeStamp(); + + syncClock->syncAudio(pts,scr); + + } else { + cout <<"syncClock == NULL (audio)"<getPicturePerSecond(); + int oneFrameTime=0; + + if (picPerSec > 0.0) { + oneFrameTime=(int) (1000000.0/picPerSec); + } else { + syncPic->print("picPersec is 0"); + return true; + } + + if (lPerformance==true) { + waitTime->set(0,0); + syncPic->setWaitTime(waitTime); + performance->incPictureCount(); + return true; + } + + int lpacketSync=true; + + videoTimeStamp->gettimeofday(); + diffTime->minus(videoTimeStamp,videoTimeStamp); + + + if (lavSync==false) { + if (videoTimeStamp->isNegative()) { + diffTime->gettimeofday(); + diffTime->addOffset(0,oneFrameTime); + cout << "skip time based"<copyTo(waitTime); + + TimeStamp* earlyTime=syncPic->getEarlyTime(); + earlyTime->set(0,0); + + + if (lavSync) { + + lpacketSync=avSync(syncPic->getStartTimeStamp(), + waitTime, + earlyTime, + syncPic->getPicturePerSecond()); + + } + + + + + if (lpacketSync == false) { + //cout << "skip"<gettimeofday(); + diffTime->addOffset(0,oneFrameTime); + return false; + } + + syncPic->setWaitTime(waitTime); + + if (lavSync) { + waitTime->minus(videoTimeStamp,waitTime); + if (waitTime->isPositive()) { + diffTime->addOffset(waitTime); + } + } + diffTime->addOffset(0,oneFrameTime); + return true; + + +} + + + +/** + Heart of the sync routine is here! + + Currently its more in a state of "try/test" + + +*/ +int AVSyncer::avSync(TimeStamp* startVideo, + TimeStamp* waitTime, + TimeStamp* earlyTime, + float picPerSec ) { + + + double videoStartPTSTime=startVideo->getPTSTimeStamp(); + double videoStartSCRTime=startVideo->getSCRTimeStamp(); + int videoFrameCounter=startVideo->getVideoFrameCounter(); + double frameTime=0.0; + + + + lockSyncData(); + if (picPerSec > 0) { + oneFrameTime=(long)(1000000.0/picPerSec); + frameTime=1.0/picPerSec; + onePicFrameInAudioBytes=audioTime->calculateBytes(1.0/picPerSec); + + } + if (lAudioRunning==false) { + waitTime->set(0,oneFrameTime); + + unlockSyncData(); + return true; + } + + + /* + startAudio->print("audio"); + startVideo->print("video"); + */ + + + + + + + /* + cout << "audioStartAudioPacketNrMinor:"<set(0,0); + SyncClock* syncClock=startVideo->getSyncClock(); + int back=false; + double addPts=videoFrameCounter*frameTime; + double pts=videoStartPTSTime+addPts; + + if (syncClock != NULL) { + + back=syncClock->syncVideo(pts, + videoStartSCRTime,earlyTime,waitTime); + } else { + cout << "syncClock == NULL (video)"<print("earlyTime"); + earlyTime->waitForIt(); + /* + double tmp; + double time=syncClock->getPTSTime(&tmp); + cout << "time after wait:"<lAudioRunning=lAudioRunning; +} + + +void AVSyncer::lockSyncData() { + abs_thread_mutex_lock(&changeMut); + abs_thread_mutex_lock(&writeInMut); + abs_thread_mutex_unlock(&changeMut); +} + +void AVSyncer::unlockSyncData() { + abs_thread_mutex_unlock(&writeInMut); +} diff --git a/mpeglib/lib/output/avSyncer.h b/mpeglib/lib/output/avSyncer.h new file mode 100644 index 00000000..b5a7ae7d --- /dev/null +++ b/mpeglib/lib/output/avSyncer.h @@ -0,0 +1,96 @@ +/* + encapsulates the syncing methods, to use it in other classes + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + +#ifndef __AVSYNCER_H +#define __AVSYNCER_H + +#include + +#include "../util/render/yuvPicture.h" +#include "../util/syncClock.h" +#include "audioTime.h" + +class Performance; +class AudioDataArray; +class AudioData; + +class AVSyncer { + + AudioData* audioDataInsert; + AudioData* audioDataCurrent; + AudioDataArray* audioDataArray; + Performance* performance; + + AudioTime* audioTime; + int onePicFrameInAudioBytes; + int oneFrameTime; + + int lAudioRunning; + + abs_thread_mutex_t writeInMut; + abs_thread_mutex_t changeMut; + + + int bufferSize; + + TimeStamp* startAudio; + TimeStamp* endAudio; + + TimeStamp* videoTimeStamp; + TimeStamp* diffTime; + TimeStamp* waitTime; + + int lPerformance; + int lavSync; + int lastAudioPacket; + double pts_jitter; + + + public: + AVSyncer(int bufferSize); + ~AVSyncer(); + + // audio + int audioSetup(int frequency,int stereo,int sign,int big,int sixteen); + int audioPlay(TimeStamp* startStamp, + TimeStamp* endStamp,char *buffer, int size); + void audioClose(void); + void setAudioBufferSize(int size); + + int getPreferredDeliverSize(); + + // video + int getFrameusec(); + int syncPicture(YUVPicture* syncPic); + + void config(const char* key,const char* value,void* user_data); + + + + private: + int getAudioRunning(); + void setAudioRunning(int lAudioRunning); + + void lockSyncData(); + void unlockSyncData(); + void setAudioSync(AudioData* audioData); + + // methods which belong not to the OutputStream interface + int avSync(TimeStamp* startVideoStamp, + TimeStamp* waitTime, + TimeStamp* earlyTime, + float picPerSec); + +}; +#endif diff --git a/mpeglib/lib/output/dspX11OutputStream.cpp b/mpeglib/lib/output/dspX11OutputStream.cpp new file mode 100644 index 00000000..05503ffa --- /dev/null +++ b/mpeglib/lib/output/dspX11OutputStream.cpp @@ -0,0 +1,236 @@ +/* + concret OutputClass + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + +#include "dspX11OutputStream.h" +#include "../util/audio/dspWrapper.h" +#include "windowOut.h" +#include "avSyncer.h" +#include "yuvDumper.h" + +#include + +using namespace std; + +DspX11OutputStream::DspX11OutputStream(int bufferSize) { + dspWrapper=new DSPWrapper(); + x11Window=new WindowOut(); + avSyncer=new AVSyncer(bufferSize); + yuvDumper=new YUVDumper(); + + audioTime=new AudioTime(); + + lPerformance=false; + lneedInit=false; + lVideoInit=false; + lBufferSet=false; + lYUVDump=false; +} + + +DspX11OutputStream::~DspX11OutputStream() { + delete dspWrapper; + delete x11Window; + + delete avSyncer; + delete audioTime; + delete yuvDumper; +} + + + +int DspX11OutputStream::audioSetup(int frequency,int stereo, + int sign,int big,int sixteen) { + + dspWrapper->audioSetup(stereo,sixteen,sign,big,frequency); + audioTime->setFormat(stereo,sixteen,frequency,sign,big); + avSyncer->audioSetup(frequency,stereo,sign,big,sixteen); + if (dspWrapper->isOpenDevice() == true) { + if (lBufferSet==false) { + int size=dspWrapper->getAudioBufferSize(); + avSyncer->setAudioBufferSize(size); + } + } + return true; +} + + +void DspX11OutputStream::audioClose(void) { + avSyncer->audioClose(); + dspWrapper->closeDevice(); +} + + +void DspX11OutputStream::audioOpen() { + if (dspWrapper->isOpenDevice() == false) { + dspWrapper->openDevice(); + if (lBufferSet==false) { + int size=dspWrapper->getAudioBufferSize(); + avSyncer->setAudioBufferSize(size); + } + } +} + + + + +int DspX11OutputStream::audioPlay(TimeStamp* startStamp, + TimeStamp* endStamp,char *buffer, int size) { + + if (lneedInit) { + cout << "FIXME. work on audioFrames!!"< 0) { + len=rest; + if (len>inc) { + len=inc; + } + if (dspWrapper->isOpenDevice()) { + if (dspWrapper->audioPlay(buffer,len) != len) { + cout << "write error to dsp"<audioPlay(startStamp,endStamp,buffer,len); + buffer+=len; + rest-=len; + } + return size; + } else { + return size; + } +} + + +int DspX11OutputStream::getPreferredDeliverSize() { + if (avSyncer->getPreferredDeliverSize() <= 500) { + return 500; + } + return avSyncer->getPreferredDeliverSize(); +} + + +int DspX11OutputStream::openWindow(int width, int height,const char *title) { + int back=x11Window->openWindow(width,height,title); + setOutputInit(true); + if (lYUVDump) { + yuvDumper->openWindow(width,height,title); + } + return back; +} + +int DspX11OutputStream::x11WindowId() { + return x11Window->x11WindowId(); +} + + +void DspX11OutputStream::closeWindow() { + x11Window->closeWindow(); +} + +void DspX11OutputStream::flushWindow() { + x11Window->flushWindow(); +} + + +PictureArray* DspX11OutputStream::lockPictureArray() { + return x11Window->lockPictureArray(); +} + + +void DspX11OutputStream::unlockPictureArray(PictureArray* pictureArray) { + + + + YUVPicture* pic=pictureArray->getYUVPictureCallback(); + + if (lYUVDump) { + yuvDumper->unlockPictureArray(pictureArray); + } + if (avSyncer->syncPicture(pic)==false) { + return; + } + + x11Window->unlockPictureArray(pictureArray); + + +} + +int DspX11OutputStream::getFrameusec() { + return avSyncer->getFrameusec(); +} + + + +int DspX11OutputStream::getOutputInit() { + return lVideoInit; +} + + +void DspX11OutputStream::setOutputInit(int lInit) { + this->lVideoInit=lInit; +} + + + +void DspX11OutputStream::config(const char* key, + const char* value,void* user_data) { + + cout << "key:"<config(key,value,user_data); + } + if (strcmp(key,"-b")==0) { + lBufferSet=true; + int size=strtol(value,(char **)NULL,10); + cout << "simulated audio buffersize:"<setAudioBufferSize(size); + } + if (strcmp(key,"-p")==0) { + lPerformance=true; + avSyncer->config(key,value,user_data); + } + if (strcmp(key,"yufDump")==0) { + int method=atoi(value); + switch(method) { + case 2: + yuvDumper->setMethod(_DUMP_YUV_AS_STREAM); + break; + default: + cout << "unknown dump method"<config(key,value,user_data); +} + + +AVSyncer* DspX11OutputStream::getAVSyncer() { + return avSyncer; +} + + + diff --git a/mpeglib/lib/output/dspX11OutputStream.h b/mpeglib/lib/output/dspX11OutputStream.h new file mode 100644 index 00000000..9b3eb859 --- /dev/null +++ b/mpeglib/lib/output/dspX11OutputStream.h @@ -0,0 +1,89 @@ +/* + concret OutputClass + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + + +#ifndef __DSPX11OUTPUTSTREAM_H +#define __DSPX11OUTPUTSTREAM_H + +#include "outputStream.h" + + + +class DSPWrapper; +class WindowOut; +class AVSyncer; +class AudioTime; +class Performance; +class YUVDumper; + +class DspX11OutputStream : public OutputStream { + + DSPWrapper* dspWrapper; + WindowOut* x11Window; + AVSyncer* avSyncer; + + + int lBufferSet; + int lVideoInit; + int lavSync; + int lneedInit; + int lPerformance; + int lYUVDump; + + AudioTime* audioTime; + YUVDumper* yuvDumper; + + public: + DspX11OutputStream(int bufferSize); + ~DspX11OutputStream(); + + // Audio Output + + int audioSetup(int frequency,int stereo,int sign,int big,int sixteen); + void audioClose(); + void audioOpen(); + int audioPlay(TimeStamp* startStamp, + TimeStamp* endStamp,char *buffer, int size); + + + int getPreferredDeliverSize(); + + + // Video Output + + int openWindow(int width, int height,const char *title); + int x11WindowId(); + void closeWindow(); + void flushWindow(); + + PictureArray* lockPictureArray(); + void unlockPictureArray(PictureArray* pictureArray); + + int getFrameusec(); + + int getDepth(); + int getOutputInit(); + void setOutputInit(int lInit); + + void config(const char* key,const char* value,void* user_data); + + // methods which do not belong to the outputStream intferface; + AVSyncer* getAVSyncer(); + + +}; + + + +#endif diff --git a/mpeglib/lib/output/outPlugin.cpp b/mpeglib/lib/output/outPlugin.cpp new file mode 100644 index 00000000..cbae10ec --- /dev/null +++ b/mpeglib/lib/output/outPlugin.cpp @@ -0,0 +1,71 @@ +/* + generic output plugin + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + +#include "outPlugin.h" + +#include + +using namespace std; + + +OutPlugin::OutPlugin() { +} + + +OutPlugin::~OutPlugin() { +} + + + +OutputStream* OutPlugin::createOutputStream(int outputType) { + + // make checks which input routine to use + OutputStream* outputStream; + int method; + + outputStream=NULL; + method=outputType; + + switch(method) { + case _OUTPUT_LOCAL: { + outputStream=new DspX11OutputStream(1024*64); + break; + } + case _OUTPUT_ARTS: { + outputStream=new ArtsOutputStream(NULL); + break; + } + case _OUTPUT_EMPTY: { + outputStream=new OutputStream(); + break; + } + default: + cout << "error cannot create default output stream"< + +#define _OUTPUT_LOCAL 1 +#define _OUTPUT_EMPTY 2 +#define _OUTPUT_YAF 3 +#define _OUTPUT_ARTS 4 + +#define _OUTPUT_THREADSAFE 1 + +class KDE_EXPORT OutPlugin { + + public: + OutPlugin(); + ~OutPlugin(); + + static OutputStream* createOutputStream(int outputType); + static OutputStream* createOutputStream(int outputType,int lThreadSafe); + +}; +#endif + + + + diff --git a/mpeglib/lib/output/outputStream.cpp b/mpeglib/lib/output/outputStream.cpp new file mode 100644 index 00000000..ef209cbc --- /dev/null +++ b/mpeglib/lib/output/outputStream.cpp @@ -0,0 +1,238 @@ +/* + generic output class + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + +#include "outputStream.h" +#include "../util/mmx/mmx.h" + +#include + +using namespace std; + +OutputStream::OutputStream() { + // we call mm_support() here because it is the only position + // where we gurantee that not threads are + // running (the call is not thread safe) + // afer the call we never execute the asm part again + // and everything is fine + mm_support(); + abs_thread_mutex_init(&stateChangeMut); + abs_thread_cond_init(&stateChangeCond); + + audioState=0; + videoState=0; + audioInit(); + videoInit(); +} + + +OutputStream::~OutputStream() { + audioInit(); + videoInit(); + abs_thread_cond_destroy(&stateChangeCond); + abs_thread_mutex_destroy(&stateChangeMut); +} + + +int OutputStream::audioInit() { + sendSignal(_STREAM_MASK_IS_INIT,false,_STREAMTYPE_AUDIO); + sendSignal(_STREAM_MASK_IS_EOF,false,_STREAMTYPE_AUDIO); + sendSignal(_STREAM_MASK_IS_DATA,false,_STREAMTYPE_AUDIO); + return true; +} + + +int OutputStream::audioSetup(int ,int , + int ,int ,int ) { + sendSignal(_STREAM_MASK_IS_INIT,true,_STREAMTYPE_AUDIO); + return true; +} + + +int OutputStream::audioPlay(TimeStamp* , + TimeStamp* ,char* , int len) { + sendSignal(_STREAM_MASK_IS_DATA,true,_STREAMTYPE_AUDIO); + return len; +} + +void OutputStream::audioFlush() { + sendSignal(_STREAM_MASK_IS_EOF,true,_STREAMTYPE_AUDIO); +} + + +void OutputStream::audioClose() { + cerr << "direct virtual call OutputStream::audioClose"< + +#define _OUTPUT_WAIT_METHOD_BLOCK 1 +#define _OUTPUT_WAIT_METHOD_POLL 2 +#define _OUTPUT_WAIT_METHOD_CALLBACK 3 + + +#define _STREAM_MASK_IS_INIT 1 +#define _STREAM_MASK_IS_EOF 2 +#define _STREAM_MASK_IS_DATA 4 + +#define _STREAM_MASK_ALL 1+2+4 + +#define _STREAMTYPE_AUDIO 1 +#define _STREAMTYPE_VIDEO 2 + + +/** + Outputstream. A nice base class. Mostly obvious methods, + except PictureArray. + write your picture into this structure + and then put it on the surface with the unlock call. + +*/ + + +/** + life of stream states: + -------------- + method flag additional calls + construct audioInit() + + + + destruct audioInit() + + audioInit isInit=false + isEof=false + isData=false + + audioSetup isInit=true + audioFlush isEof=true + audioPlay isData=true + + + Note: after a call of streamInit we have an "invalid" state + obviously there is no stream where eof==false but + and has not been initialised. + + another invalid state is audioInit->audioPlay + +*/ + + + + +class KDE_EXPORT OutputStream { + + int audioState; + int videoState; + abs_thread_mutex_t stateChangeMut; + abs_thread_cond_t stateChangeCond; + + public: + OutputStream(); + + virtual ~OutputStream(); + + // Audio Stream handling + virtual int audioInit(); + virtual int audioSetup(int freq,int stereo,int sign,int big,int sampleSize); + virtual int audioPlay(TimeStamp* startStamp, + TimeStamp* endStamp,char *buffer, int size); + virtual void audioFlush(); + + // Audio device "/dev/dsp" handling + virtual void audioClose(); + virtual void audioOpen(); + + // hack: FIX it + virtual int getPreferredDeliverSize(); + + + // stream State handling + + // we return the mask which triggerd (by "AND") + // or the current polled mask when method is POLL + // Note: you can only wait for "true" signals + virtual int waitStreamState(int method,int mask,int streamType); + + + + + // Video Output + virtual int videoInit(); + virtual int openWindow(int width, int height,const char *title); + virtual int x11WindowId(); + virtual void closeWindow(); + virtual void flushWindow(); + + + // get the current surfaces to draw into + virtual PictureArray* lockPictureArray(); + virtual void unlockPictureArray(PictureArray* pictureArray); + + + + // maybe not needed: + virtual int getFrameusec(); + virtual int getOutputInit(); + virtual void setOutputInit(int lInit); + + // Info Output + virtual void writeInfo(class PluginInfo* pluginInfo); + + + // config Output + virtual void config(const char* key, + const char* value,void* user_data); + + private: + void initStream(); + + protected: + // sometimes useful, but use with care + void sendSignal(int signal,int value,int streamType); + +}; +#endif diff --git a/mpeglib/lib/output/performance.cpp b/mpeglib/lib/output/performance.cpp new file mode 100644 index 00000000..9e2b7f92 --- /dev/null +++ b/mpeglib/lib/output/performance.cpp @@ -0,0 +1,50 @@ +/* + measures picture/second + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + +#include "performance.h" + +#include + +using namespace std; + + +Performance::Performance() { + picCnt=0; + startTime=new TimeStamp(); + endTime=new TimeStamp(); + +} + + +Performance::~Performance() { + delete startTime; + delete endTime; +} + + +void Performance::incPictureCount() { + if (picCnt==0) { + startTime->gettimeofday(); + } + picCnt++; + if (picCnt==200) { + endTime->gettimeofday(); + TimeStamp diffTime; + endTime->minus(startTime,&diffTime); + double secs=(double)diffTime.getAsSeconds(); + + double picSec=(double)picCnt/secs; + cout << "picPerSec:"< + +using namespace std; + + +PluginInfo::PluginInfo() { + musicName=new DynBuffer(20); + + reset(); + +} + + +PluginInfo::~PluginInfo() { + delete musicName; +} + +void PluginInfo::setLength(int sec) { + this->sec=sec; +} + + +int PluginInfo::getLength() { + return sec; +} + + +void PluginInfo::reset(){ + sec=0; + musicName->clear(); + musicName->append("none"); +} + +void PluginInfo::print() { + cerr << "length in sec:"<clear(); + if (name != NULL) { + musicName->append(name); + } +} + + +char* PluginInfo::getUrl() { + return musicName->getData(); +} diff --git a/mpeglib/lib/output/pluginInfo.h b/mpeglib/lib/output/pluginInfo.h new file mode 100644 index 00000000..7026fce9 --- /dev/null +++ b/mpeglib/lib/output/pluginInfo.h @@ -0,0 +1,48 @@ +/* + add on information about plugin. + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + +#ifndef __PLUGININFO_H +#define __PLUGININFO_H + +#include "../util/dynBuffer.h" +#include + +/** + Here we have the base class for all additional information + about a plugin. + The len in time of the current song belongs here, as + well as the author, version number etc.. +*/ + + +class KDE_EXPORT PluginInfo { + + int sec; + DynBuffer* musicName; + + + public: + PluginInfo(); + ~PluginInfo(); + + void setLength(int sec); + int getLength(); + + void setUrl(char* name); + char* getUrl(); + + void reset(); + void print(); +}; +#endif diff --git a/mpeglib/lib/output/threadSafeOutputStream.cpp b/mpeglib/lib/output/threadSafeOutputStream.cpp new file mode 100644 index 00000000..ec7ab510 --- /dev/null +++ b/mpeglib/lib/output/threadSafeOutputStream.cpp @@ -0,0 +1,153 @@ +/* + thread safe wrapper for output Stream + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + +#include "threadSafeOutputStream.h" + + +ThreadSafeOutputStream::ThreadSafeOutputStream(OutputStream* output) { + threadQueueAudio=new ThreadQueue(); + threadQueueVideo=new ThreadQueue(); + this->output=output; +} + + +ThreadSafeOutputStream::~ThreadSafeOutputStream() { + delete threadQueueAudio; + delete threadQueueVideo; + delete output; +} + +int ThreadSafeOutputStream::audioInit() { + int back; + threadQueueAudio->waitForExclusiveAccess(); + back=output->audioInit(); + threadQueueAudio->releaseExclusiveAccess(); + return back; +} + + +int ThreadSafeOutputStream::audioSetup(int freq,int stereo, + int sign,int big,int sampleSize) { + int back; + threadQueueAudio->waitForExclusiveAccess(); + back=output->audioSetup(freq,stereo,sign,big,sampleSize); + threadQueueAudio->releaseExclusiveAccess(); + return back; +} + + +int ThreadSafeOutputStream::audioPlay(TimeStamp* start, + TimeStamp* end,char* buf, int len) { + int back; + threadQueueAudio->waitForExclusiveAccess(); + back=output->audioPlay(start,end,buf,len); + threadQueueAudio->releaseExclusiveAccess(); + return back; +} + +void ThreadSafeOutputStream::audioFlush() { + threadQueueAudio->waitForExclusiveAccess(); + output->audioFlush(); + threadQueueAudio->releaseExclusiveAccess(); +} + + +void ThreadSafeOutputStream::audioClose() { + threadQueueAudio->waitForExclusiveAccess(); + output->audioClose(); + threadQueueAudio->releaseExclusiveAccess(); +} + +void ThreadSafeOutputStream::audioOpen() { + threadQueueAudio->waitForExclusiveAccess(); + output->audioOpen(); + threadQueueAudio->releaseExclusiveAccess(); +} + + + +int ThreadSafeOutputStream::getPreferredDeliverSize() { + int back; + threadQueueAudio->waitForExclusiveAccess(); + back=output->getPreferredDeliverSize(); + threadQueueAudio->releaseExclusiveAccess(); + return back; +} + +int ThreadSafeOutputStream::videoInit() { + int back; + threadQueueVideo->waitForExclusiveAccess(); + back=output->videoInit(); + threadQueueVideo->releaseExclusiveAccess(); + return back; +} + +int ThreadSafeOutputStream::openWindow(int w, int h,const char* title) { + int back; + threadQueueVideo->waitForExclusiveAccess(); + back=output->openWindow(w,h,title); + threadQueueVideo->releaseExclusiveAccess(); + return back; +} + + +void ThreadSafeOutputStream::closeWindow() { + threadQueueVideo->waitForExclusiveAccess(); + output->closeWindow(); + threadQueueVideo->releaseExclusiveAccess(); +} + +void ThreadSafeOutputStream::flushWindow() { + threadQueueVideo->waitForExclusiveAccess(); + output->flushWindow(); + threadQueueVideo->releaseExclusiveAccess(); +} + + +PictureArray* ThreadSafeOutputStream::lockPictureArray() { + PictureArray* back; + threadQueueVideo->waitForExclusiveAccess(); + back=output->lockPictureArray(); + threadQueueVideo->releaseExclusiveAccess(); + return back; +} + + +void ThreadSafeOutputStream::unlockPictureArray(PictureArray* array) { + threadQueueVideo->waitForExclusiveAccess(); + output->unlockPictureArray(array); + threadQueueVideo->releaseExclusiveAccess(); +} + + +int ThreadSafeOutputStream::getFrameusec() { + int back; + threadQueueVideo->waitForExclusiveAccess(); + back=output->getFrameusec(); + threadQueueVideo->releaseExclusiveAccess(); + return back; +} + +void ThreadSafeOutputStream::config(const char* key, + const char* value,void* user_data) { + + threadQueueVideo->waitForExclusiveAccess(); + threadQueueAudio->waitForExclusiveAccess(); + output->config(key,value,user_data); + threadQueueVideo->releaseExclusiveAccess(); + threadQueueAudio->releaseExclusiveAccess(); + +} + + + diff --git a/mpeglib/lib/output/threadSafeOutputStream.h b/mpeglib/lib/output/threadSafeOutputStream.h new file mode 100644 index 00000000..c9852a37 --- /dev/null +++ b/mpeglib/lib/output/threadSafeOutputStream.h @@ -0,0 +1,67 @@ +/* + thread safe wrapper for output Stream + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + +#ifndef __THREADSAFEOUTPUTSTREAM_H +#define __THREADSAFEOUTPUTSTREAM_H + +// read INTRO in threadQueue.h +// This class makes the outputStream (given in constructor) +// threadsafe by wrapping each call with a threadqueue. +// +// Important NOTE: the output pointer is the owned by this class !!! +// which means: we call delete on it! +// More Important NOTES: +// +// We make the audio and video calls seperate threadsafe +// and ONLY the config call threadsafe to both! + +#include "../util/abstract/threadQueue.h" +#include "outputStream.h" + + +class ThreadSafeOutputStream : public OutputStream { + + ThreadQueue* threadQueueAudio; + ThreadQueue* threadQueueVideo; + OutputStream* output; + + public: + ThreadSafeOutputStream(OutputStream* output); + ~ThreadSafeOutputStream(); + + // Thread safe Audio Stream handling + int audioInit(); + int audioSetup(int freq,int stereo,int sign,int big,int sampleSize); + int audioPlay(TimeStamp* startStamp, + TimeStamp* endStamp,char *buffer, int size); + void audioFlush(); + void audioClose(); + void audioOpen(); + int getPreferredDeliverSize(); + + + // Video Output + int videoInit(); + int openWindow(int width, int height,const char *title); + void closeWindow(); + void flushWindow(); + PictureArray* lockPictureArray(); + void unlockPictureArray(PictureArray* pictureArray); + int getFrameusec(); + + // config Output + void config(const char* key, + const char* value,void* user_data); + + +}; +#endif diff --git a/mpeglib/lib/output/windowOut.cpp b/mpeglib/lib/output/windowOut.cpp new file mode 100644 index 00000000..3e199095 --- /dev/null +++ b/mpeglib/lib/output/windowOut.cpp @@ -0,0 +1,64 @@ +/* + wrapper for X11 Window + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + +#include "windowOut.h" + + + + + + + +WindowOut::WindowOut() { + + renderMachine=new RenderMachine(); + +} + + +WindowOut::~WindowOut() { + delete renderMachine; +} + +int WindowOut::openWindow(int width, int height,const char *title){ + return renderMachine->openWindow(width,height,title); +} + +int WindowOut::x11WindowId() { + return renderMachine->x11WindowId(); +} + +void WindowOut::flushWindow() { + renderMachine->flushWindow(); +} + + +void WindowOut::closeWindow() { + renderMachine->closeWindow(); +} + + +PictureArray* WindowOut::lockPictureArray() { + return renderMachine->lockPictureArray(); +} + + +void WindowOut::unlockPictureArray(PictureArray* pictureArray) { + renderMachine->unlockPictureArray(pictureArray); +} + + + +void WindowOut::config(const char* key, const char* value,void* user_data) { + renderMachine->config(key,value,user_data); +} diff --git a/mpeglib/lib/output/windowOut.h b/mpeglib/lib/output/windowOut.h new file mode 100644 index 00000000..648d1dc4 --- /dev/null +++ b/mpeglib/lib/output/windowOut.h @@ -0,0 +1,53 @@ +/* + wrapper for X11 Window + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + +#ifndef __WINDOWOUT_H +#define __WINDOWOUT_H + + +#include "../util/abstract/abs_thread.h" +#include "../util/timeStamp.h" +#include "../util/render/renderMachine.h" + +/** + Stupid class. survivor of ancient days. +*/ + + +class WindowOut { + + + RenderMachine* renderMachine; + + public: + WindowOut(); + ~WindowOut(); + + int openWindow(int width, int height,const char *title); + int x11WindowId(); + void closeWindow(); + void flushWindow(); + + // get the current surfaces to draw into + PictureArray* lockPictureArray(); + void unlockPictureArray(PictureArray* pictureArray); + + void config(const char* key, const char* value,void* user_data); + + + private: + + +}; +#endif diff --git a/mpeglib/lib/output/yuvDumper.cpp b/mpeglib/lib/output/yuvDumper.cpp new file mode 100644 index 00000000..1962b151 --- /dev/null +++ b/mpeglib/lib/output/yuvDumper.cpp @@ -0,0 +1,81 @@ +/* + writes yuv images on HD + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + +#include "yuvDumper.h" + +YUVDumper::YUVDumper() { + picCnt=1; + method=_DUMP_YUV_AS_STREAM; +} + +YUVDumper::~YUVDumper() { +} + + +int YUVDumper::openWindow(int w, int h,const char*) { + + FILE* formatFile=fopen("stream.yuv.format","w+"); + fprintf(formatFile,"Version 0.1\nw:%dh:%d\n",w,h); + fclose(formatFile); + + + + if (method == _DUMP_YUV_AS_STREAM) { + FILE* outFile=fopen("stream.yuv","w+"); + fclose(outFile); + } + return true; +} + +void YUVDumper::closeWindow() { +} + + +void YUVDumper::flushWindow() { +} + + +int YUVDumper::getMethod() { + return method; +} + + +void YUVDumper::setMethod(int method) { + this->method=method; +} + +void YUVDumper::unlockPictureArray(PictureArray* pictureArray) { + YUVPicture* pic=pictureArray->getYUVPictureCallback(); + if (pic == NULL) { + return; + } + + FILE* outFile=NULL; + + if (method == _DUMP_YUV_AS_STREAM) { + outFile=fopen("stream.yuv","a+"); + } + + if (outFile == NULL) { + perror("fopen"); + return; + } + + int lumSize=pic->getLumLength(); + int colorSize=pic->getColorLength(); + fwrite(pic->getLuminancePtr(),1,lumSize,outFile); + fwrite(pic->getCrPtr(),1,colorSize,outFile); + fwrite(pic->getCbPtr(),1,colorSize,outFile); + fclose(outFile); + +} diff --git a/mpeglib/lib/output/yuvDumper.h b/mpeglib/lib/output/yuvDumper.h new file mode 100644 index 00000000..2e4880b0 --- /dev/null +++ b/mpeglib/lib/output/yuvDumper.h @@ -0,0 +1,51 @@ +/* + writes yuv images on HD + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + +#ifndef __YUVDUMPER_H +#define __YUVDUMPER_H + +#include "outputStream.h" + +#include +#include +#include +#include + + +#define _DUMP_YUV_AS_STREAM 2 + + +class YUVDumper : public OutputStream { + + + int picCnt; + int method; + + public: + YUVDumper(); + ~YUVDumper(); + + // Video Output + + int openWindow(int width, int height,const char *title); + void closeWindow(); + void flushWindow(); + + void unlockPictureArray(PictureArray* pictureArray); + int getMethod(); + void setMethod(int method); + + +}; + +#endif -- cgit v1.2.1