diff options
Diffstat (limited to 'mpeglib/lib/frame')
-rw-r--r-- | mpeglib/lib/frame/IOFrameQueue.cpp | 60 | ||||
-rw-r--r-- | mpeglib/lib/frame/IOFrameQueue.h | 60 | ||||
-rw-r--r-- | mpeglib/lib/frame/Makefile.am | 33 | ||||
-rw-r--r-- | mpeglib/lib/frame/README | 68 | ||||
-rw-r--r-- | mpeglib/lib/frame/audioFrame.cpp | 111 | ||||
-rw-r--r-- | mpeglib/lib/frame/audioFrame.h | 83 | ||||
-rw-r--r-- | mpeglib/lib/frame/audioFrameQueue.cpp | 339 | ||||
-rw-r--r-- | mpeglib/lib/frame/audioFrameQueue.h | 75 | ||||
-rw-r--r-- | mpeglib/lib/frame/floatFrame.cpp | 50 | ||||
-rw-r--r-- | mpeglib/lib/frame/floatFrame.h | 46 | ||||
-rw-r--r-- | mpeglib/lib/frame/frame.cpp | 73 | ||||
-rw-r--r-- | mpeglib/lib/frame/frame.h | 101 | ||||
-rw-r--r-- | mpeglib/lib/frame/frameQueue.cpp | 101 | ||||
-rw-r--r-- | mpeglib/lib/frame/frameQueue.h | 43 | ||||
-rw-r--r-- | mpeglib/lib/frame/framer.cpp | 241 | ||||
-rw-r--r-- | mpeglib/lib/frame/framer.h | 182 | ||||
-rw-r--r-- | mpeglib/lib/frame/pcmFrame.cpp | 140 | ||||
-rw-r--r-- | mpeglib/lib/frame/pcmFrame.h | 45 | ||||
-rw-r--r-- | mpeglib/lib/frame/rawDataBuffer.cpp | 21 | ||||
-rw-r--r-- | mpeglib/lib/frame/rawDataBuffer.h | 48 | ||||
-rw-r--r-- | mpeglib/lib/frame/rawFrame.cpp | 90 | ||||
-rw-r--r-- | mpeglib/lib/frame/rawFrame.h | 75 |
22 files changed, 2085 insertions, 0 deletions
diff --git a/mpeglib/lib/frame/IOFrameQueue.cpp b/mpeglib/lib/frame/IOFrameQueue.cpp new file mode 100644 index 00000000..9a13f1fa --- /dev/null +++ b/mpeglib/lib/frame/IOFrameQueue.cpp @@ -0,0 +1,60 @@ +/* + queues frames in a "empty" and "data" queue + Copyright (C) 2001 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 "IOFrameQueue.h" + + +IOFrameQueue::IOFrameQueue(int size) { + empty=new FrameQueue(size); + data=new FrameQueue(size); + +} + + +IOFrameQueue::~IOFrameQueue() { + delete empty; + delete data; +} + + +// +// empty queue +// +int IOFrameQueue::emptyQueueCanRead() { + return empty->canRead(); +} + + +int IOFrameQueue::emptyQueueCanWrite() { + return empty->canWrite(); +} + + + + +// +// data queue +// +int IOFrameQueue::dataQueueCanRead() { + return data->canRead(); +} + + +int IOFrameQueue::dataQueueCanWrite() { + return data->canWrite(); +} + + + + + diff --git a/mpeglib/lib/frame/IOFrameQueue.h b/mpeglib/lib/frame/IOFrameQueue.h new file mode 100644 index 00000000..d56f25aa --- /dev/null +++ b/mpeglib/lib/frame/IOFrameQueue.h @@ -0,0 +1,60 @@ +/* + queues frames in a "empty" and "data" queue + Copyright (C) 2001 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 __IOFRAMEQUEUE_H +#define __IOFRAMEQUEUE_H + +#include "frameQueue.h" +#include <kdemacros.h> + +/** + This class can store up to <size> frames. + The frames are marked "empty" these frames can be re-used + and filled with data. + The other queue stores "data" frames. These frames can + be dequeued and then are be passed to the "empty" queue. + + Note: you need to _fill_ the empty queue with allocated frames, + after constructions. The pointers then are owned by this + class (== deleted in destructor) + +*/ + +class KDE_EXPORT IOFrameQueue { + + + public: + IOFrameQueue(int size); + ~IOFrameQueue(); + + // + // empty queue + // + int emptyQueueCanRead(); + int emptyQueueCanWrite(); + + + // + // data queue + // + int dataQueueCanRead(); + int dataQueueCanWrite(); + + + protected: + FrameQueue* empty; + FrameQueue* data; + +}; +#endif diff --git a/mpeglib/lib/frame/Makefile.am b/mpeglib/lib/frame/Makefile.am new file mode 100644 index 00000000..753b5f18 --- /dev/null +++ b/mpeglib/lib/frame/Makefile.am @@ -0,0 +1,33 @@ + +# ---- @OS_TYPE@/@ARCH_TYPE@ ---- + +INCLUDES = $(all_includes) + +EXTRA_DIST = README + +kmpgincludedir = $(includedir)/$(THIS_LIB_NAME)/frame + +kmpginclude_HEADERS = pcmFrame.h audioFrame.h \ + floatFrame.h frameQueue.h frame.h \ + IOFrameQueue.h audioFrameQueue.h \ + framer.h rawDataBuffer.h rawFrame.h + +noinst_LTLIBRARIES = libframe.la + +libframe_la_SOURCES = pcmFrame.cpp \ + audioFrame.cpp floatFrame.cpp frame.cpp \ + frameQueue.cpp IOFrameQueue.cpp\ + audioFrameQueue.cpp framer.cpp \ + rawDataBuffer.cpp rawFrame.cpp + + + + + + + + + + + + diff --git a/mpeglib/lib/frame/README b/mpeglib/lib/frame/README new file mode 100644 index 00000000..9e21059f --- /dev/null +++ b/mpeglib/lib/frame/README @@ -0,0 +1,68 @@ + + + +Frames +====== + + +Frames are needed for passing data between decoders around. +A decoder gets an mpeg audio encoded frame as input and +writes data to an audioFrame (pcm/float) + + frame + | + audioFrame + / \ + pcmFrame floatFrame + + +FrameQueues +=========== + +FrameQueues are needed for storing some frames. (For example +you store 100 pre-decoded pcmFrames.) +A FrameQueue is a queue, simply not more. + +IOFrameQueues +============= + +IOFrameQueues deal with the problem, that you first start +with an empty FrameQueue (this is a FrameQueue which contains +prealloceated data, but the data is empty (eg:all pcm samples zero) +Only after converting an "empty" Frame by a decoder (mp3decoder) +the frame if "full" (== Frame with data) +So: IOFrameQueues mark frames with + +i) empty +ii) data + +You can get an empty Frame from the empty-frame-queue and +then enqueue it in the data-frame-queue. +After the frame was used (played) we dequeue it from the +data queue and put them back in the empty queue. +You can see IOFrameQueues as a ringbuffer. +(get free space. write to it. read data. mark space as free,....) + + + FrameQueue + | + IOFrameQueue + / + audioFrameQueue + + +AudioFrameQueue +=============== + +A IOFrameQueue, which allows converting "dataFrames back to continous +stream". +What is this? +Lets say an application wants only 20 byte from a dataFrame which +contains 3KB of data? +There must be some mechanism to read less or more data from the +queue. And the data should be written to a continus memory +segment. +AudioFrameQueue deals with this problem.You can read data from +the queue to a given pointer location. + + diff --git a/mpeglib/lib/frame/audioFrame.cpp b/mpeglib/lib/frame/audioFrame.cpp new file mode 100644 index 00000000..55464afa --- /dev/null +++ b/mpeglib/lib/frame/audioFrame.cpp @@ -0,0 +1,111 @@ +/* + abstract definition of an audio frame + Copyright (C) 2001 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 "audioFrame.h" + +#include <iostream> + +using namespace std; + +AudioFrame::AudioFrame() { + + stereo=-1; + frequencyHZ=-1; + + sampleSize=-1; + lBigEndian=-1; + lSigned=-1; + setFrameType(_FRAME_AUDIO_BASE); +} + + +AudioFrame::~AudioFrame() { +} + + +int AudioFrame::getLen() { + cout << "direct virtual call AudioFrame::getLen"<<endl; + return 0; +} + + +void AudioFrame::setLen(int ) { + cout << "direct virtual call AudioFrame::setLen"<<endl; +} + + +int AudioFrame::getSize() { + cout << "direct virtual call AudioFrame::getSize"<<endl; + return 0; +} + + +void AudioFrame::putFloatData(float* ,int ) { + cout << "direct virtual call AudioFrame::putFloatData"<<endl; +} + +void AudioFrame::putFloatData(float* ,float* ,int ) { + cout << "direct virtual call AudioFrame::putFloatData L/R version"<<endl; +} + +void AudioFrame::clearrawdata() { + cout << "direct virtual call AudioFrame::clearrawdata"<<endl; +} + +void AudioFrame::setFrameFormat(int stereo,int freq) { + this->stereo=stereo; + this->frequencyHZ=freq; +} + + + +int AudioFrame::isFormatEqual(AudioFrame* compare) { + if(compare->getStereo() != stereo) { + return false; + } + if(compare->getSampleSize() != sampleSize) { + return false; + } + if(compare->getBigEndian() != lBigEndian) { + return false; + } + if(compare->getFrequenceHZ() != frequencyHZ) { + return false; + } + if(compare->getSigned() != lSigned) { + return false; + } + return true; +} + +void AudioFrame::print(const char* msg) { + cout << "PCMFrame::print:"<<msg<<endl; + cout << "stereo:"<<stereo<<endl; + cout << "sampleSize:"<<sampleSize<<endl; + cout << "lBigEndian:"<<lBigEndian<<endl; + cout << "frequencyHZ:"<<frequencyHZ<<endl; + cout << "lSigned:"<<lSigned<<endl; +} + + +void AudioFrame::copyFormat(AudioFrame* dest) { + if (dest->getFrameType() != _FRAME_AUDIO_BASE) { + cout << "cannot copy frameFormat into frametype!= _FRAME_AUDIO_BASE"<<endl; + exit(0); + } + dest->setFrameFormat(getStereo(),getFrequenceHZ()); + dest->sampleSize=getSampleSize(); + dest->lBigEndian=getBigEndian(); + dest->lSigned=getSigned(); +} diff --git a/mpeglib/lib/frame/audioFrame.h b/mpeglib/lib/frame/audioFrame.h new file mode 100644 index 00000000..b1c586c3 --- /dev/null +++ b/mpeglib/lib/frame/audioFrame.h @@ -0,0 +1,83 @@ +/* + abstract definition of an audio frame + Copyright (C) 2001 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 __AUDIOFRAME_H +#define __AUDIOFRAME_H + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef WORDS_BIGENDIAN +#define AUDIOFRAME_BIGENDIAN 1 +#else +#define AUDIOFRAME_BIGENDIAN 0 +#endif + + +#include "frame.h" +#include <kdemacros.h> +#define SCALFACTOR SHRT_MAX +#define MP3FRAMESIZE (2*2*2*32*18) + + +class KDE_EXPORT AudioFrame : public Frame { + + int stereo; + int frequencyHZ; + + public: + AudioFrame(); + virtual ~AudioFrame(); + + // info about "import" data + void setFrameFormat(int stereo,int freq); + + inline int getStereo() { return stereo; } + inline int getFrequenceHZ() { return frequencyHZ; } + + // these return values depend on the implementation + // how the data is stored internally after "import" + inline int getSampleSize() { return sampleSize; } + inline int getBigEndian() { return lBigEndian; } + inline int getSigned() { return lSigned; } + + // info about output + virtual int getLen(); + virtual void setLen(int len); + virtual int getSize(); + virtual void clearrawdata(); + + // data import + virtual void putFloatData(float* data,int len); + virtual void putFloatData(float* left,float* right,int len); + + + int isFormatEqual(AudioFrame* compare); + // Note: this can only be called with _real_ AudioFrame's as dest + void copyFormat(AudioFrame* dest); + + void print(const char* msg); + + protected: + int sampleSize; + int lBigEndian; + int lSigned; + +}; + + +#endif diff --git a/mpeglib/lib/frame/audioFrameQueue.cpp b/mpeglib/lib/frame/audioFrameQueue.cpp new file mode 100644 index 00000000..16488748 --- /dev/null +++ b/mpeglib/lib/frame/audioFrameQueue.cpp @@ -0,0 +1,339 @@ +/* + queues audio frames in an IOQueue, allows streaming from frames + Copyright (C) 2001 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 "audioFrameQueue.h" + +#define _FLOAT_2_TRANSFER 1 +#define _FLOAT_1_TRANSFER 2 +#define _INT_2_TRANSFER 3 +#define _INT_1_TRANSFER 4 +#define _FORWARD_TRANSFER 5 + +#include <iostream> + +using namespace std; + +AudioFrameQueue::AudioFrameQueue(int queueSize, + int frameSize, + int frameType):IOFrameQueue(queueSize) { + switch(frameType) { + case _FRAME_AUDIO_PCM: { + // fill queue with elements + while(emptyQueueCanWrite()) { + PCMFrame* pcmFrame=new PCMFrame(frameSize); + emptyQueueEnqueue(pcmFrame); + } + break; + } + case _FRAME_AUDIO_FLOAT: { + // fill queue with elements + while(emptyQueueCanWrite()) { + FloatFrame* floatFrame=new FloatFrame(frameSize); + emptyQueueEnqueue(floatFrame); + } + break; + } + default: + cout << "unknown frameType:"<<Frame::getFrameName(frameType) + <<" in AudioFrameQueue"<<endl; + exit(0); + } + len=0; + currentAudioFrame=new AudioFrame(); + currentRead=0; + this->frameType=frameType; +} + + +AudioFrameQueue::~AudioFrameQueue() { + delete currentAudioFrame; +} + + +void AudioFrameQueue::emptyQueueEnqueue(AudioFrame* frame) { + empty->enqueue(frame); +} + + +AudioFrame* AudioFrameQueue::emptyQueueDequeue() { + return (AudioFrame*)empty->dequeue(); +} + + +void AudioFrameQueue::dataQueueEnqueue(AudioFrame* frame) { + if (data->getFillgrade() == 0) { + frame->copyFormat(currentAudioFrame); + } + + len+=frame->getLen(); + data->enqueue(frame); + +} + + +AudioFrame* AudioFrameQueue::dataQueueDequeue() { + AudioFrame* back=(AudioFrame*)data->dequeue(); + currentRead=0; + len-=back->getLen(); + back->copyFormat(currentAudioFrame); + return back; +} + +AudioFrame* AudioFrameQueue::getCurrent() { + return currentAudioFrame; +} + + +int AudioFrameQueue::getLen() { + return len-currentRead; +} + + +int AudioFrameQueue::copy(float* left,float* right,int wantLen) { + if (frameType != _FRAME_AUDIO_FLOAT) { + cout << "AudioFrameQueue::copy class is frameType short int"<<endl; + exit(0); + } + // whats mux? + // well the routines are badly broken and need a rewrite + // mux deals with the problem that + // if the src is stereo we expect the left/right pointers + // to have half the size of wantlen*2 + // ridicouls complex? + // right, as I said, this needs a clean solution + int mux=1; + + if (currentAudioFrame->getStereo()) { + wantLen*=2; + mux=2; + } + + int back=copygeneric((char*)left,(char*)right, + wantLen,_FLOAT_2_TRANSFER,mux); + if (currentAudioFrame->getStereo()) back/=2; + + return back; +} + +int AudioFrameQueue::copy(short int* left,short int* right,int wantLen) { + if (frameType != _FRAME_AUDIO_PCM) { + cout << "AudioFrameQueue::copy class is frameType float"<<endl; + exit(0); + } + // for this mux ugly hack read above + int mux=1; + + if (currentAudioFrame->getStereo()) { + wantLen*=2; + mux=2; + } + int back=copygeneric((char*)left,(char*)right, + wantLen,_INT_2_TRANSFER,mux); + if (currentAudioFrame->getStereo()) back/=2; + + return back; +} + +int AudioFrameQueue::copy(short int* dest,int wantLen) { + if (frameType != _FRAME_AUDIO_PCM) { + cout << "AudioFrameQueue::copy class is frameType int single"<<endl; + exit(0); + } + int back=copygeneric((char*)dest,(char*)NULL, + wantLen,_INT_1_TRANSFER,1); + return back; +} + +int AudioFrameQueue::copy(float* dest,int wantLen) { + if (frameType != _FRAME_AUDIO_FLOAT) { + cout << "AudioFrameQueue::copy class is frameType float single"<<endl; + exit(0); + } + int back=copygeneric((char*)dest,(char*)NULL, + wantLen,_FLOAT_1_TRANSFER,1); + return back; +} + +void AudioFrameQueue::forwardStreamSingle(int forwardLen) { + int back=copygeneric((char*)NULL,(char*)NULL, + forwardLen,_FORWARD_TRANSFER,1); + if (back != forwardLen) { + cout << "error while forwarding stream"<<endl; + exit(0); + } +} + +void AudioFrameQueue::forwardStreamDouble(int forwardLen) { + + int mux=1; + + if (currentAudioFrame->getStereo()) { + forwardLen*=2; + } + int back=copygeneric((char*)NULL,(char*)NULL, + forwardLen,_FORWARD_TRANSFER,mux); + + if (back != forwardLen) { + cout << "error while forwarding stream"<<endl; + exit(0); + } +} + + +int AudioFrameQueue::copygeneric(char* left,char* right, + int wantLen,int version,int mux) { + + + int processed=currentRead; + + if (wantLen > (len-processed)) { + wantLen=len-processed; + } + int pos=0; + int doLen=wantLen; + while(doLen > 0) { + AudioFrame* current=(AudioFrame*)data->peekqueue(pos); + int totallen=current->getLen(); + int restlen=totallen-processed; + int copylen=doLen; + if (doLen > restlen) { + copylen=restlen; + } + doLen-=copylen; + + switch(version) { + case _FLOAT_2_TRANSFER: + transferFrame((float*)left, + (float*)right, + (FloatFrame*) current,processed,copylen); + left+=copylen/mux*(sizeof(float)); + right+=copylen/mux*(sizeof(float)); + break; + case _FLOAT_1_TRANSFER: + transferFrame((float*)left, + (FloatFrame*) current,processed,copylen); + left+=copylen*sizeof(short int); + break; + case _INT_2_TRANSFER: + transferFrame((short int*)left, + (short int*)right, + (PCMFrame*) current,processed,copylen); + left+=copylen/mux*(sizeof(short int)); + right+=copylen/mux*(sizeof(short int)); + break; + case _INT_1_TRANSFER: + transferFrame((short int*)left, + (PCMFrame*) current,processed,copylen); + left+=copylen*sizeof(short int); + break; + case _FORWARD_TRANSFER: + break; + default: + cout << "unknown transfer method AudioFrameQueue::copygeneric"<<endl; + exit(0); + } + processed+=copylen; + if ( processed == totallen) { + processed=0; + if (version == _FORWARD_TRANSFER) { + current=dataQueueDequeue(); + emptyQueueEnqueue(current); + } else { + pos++; + } + } + } + if (version == _FORWARD_TRANSFER) { + currentRead=processed; + } + if (doLen < 0) { + cout << "error while copy in AudioFrameQueue"<<endl; + exit(0); + } + return wantLen; +} + + +void AudioFrameQueue::transferFrame(float* left,float* right, + FloatFrame* current,int start,int len) { + float* ptr=current->getData()+start; + switch(currentAudioFrame->getStereo()) { + case true: + len=len/2; + while(len) { + *left++=*ptr++; + *right++=*ptr++; + len--; + } + break; + case false: + while(len) { + *left++=*ptr; + *right++=*ptr++; + len--; + } + break; + default: + cout << "bad stereo value AudioFrameQueue::transferFrame (float)"<<endl; + exit(0); + } +} + +void AudioFrameQueue::transferFrame(short int* left,short int* right, + PCMFrame* current,int start,int len) { + short int* ptr=current->getData()+start; + switch(currentAudioFrame->getStereo()) { + case true: + len=len/2; + while(len) { + *left++=*ptr++; + *right++=*ptr++; + len--; + } + break; + case false: + while(len) { + *left++=*ptr; + *right++=*ptr++; + len--; + } + break; + default: + cout << "bad stereo value AudioFrameQueue::transferFrame (int)"<<endl; + exit(0); + } +} + + +void AudioFrameQueue::transferFrame(short int* dest, + PCMFrame* current,int start,int len) { + short int* ptr=current->getData()+start; + memcpy(dest,ptr,len*sizeof(short int)); + +} + + +void AudioFrameQueue::transferFrame(float* dest, + FloatFrame* current,int start,int len) { + float* ptr=current->getData()+start; + memcpy(dest,ptr,len*sizeof(float)); + +} + + +void AudioFrameQueue::clear() { + while(dataQueueCanRead()) { + AudioFrame* current=dataQueueDequeue(); + emptyQueueEnqueue(current); + } +} diff --git a/mpeglib/lib/frame/audioFrameQueue.h b/mpeglib/lib/frame/audioFrameQueue.h new file mode 100644 index 00000000..7e7a01c0 --- /dev/null +++ b/mpeglib/lib/frame/audioFrameQueue.h @@ -0,0 +1,75 @@ +/* + queues audio frames in an IOQueue, allows streaming from frames + Copyright (C) 2001 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 __AUDIOFRAMEQUE_H +#define __AUDIOFRAMEQUE_H + +#include "IOFrameQueue.h" +#include "floatFrame.h" +#include "pcmFrame.h" + +#include <kdemacros.h> + +/** + This class solves the problem that we produce audioFrames + in a packet, but often we want that these packets looks + like a stream. + This class can convert from packets back to a stream. +*/ + +class KDE_EXPORT AudioFrameQueue : public IOFrameQueue { + + int frameType; + int len; + AudioFrame* currentAudioFrame; + int currentRead; + + public: + AudioFrameQueue(int queueSize,int frameSize,int frameType); + ~AudioFrameQueue(); + + void emptyQueueEnqueue(AudioFrame* frame); + AudioFrame* emptyQueueDequeue(); + + void dataQueueEnqueue(AudioFrame* frame); + AudioFrame* dataQueueDequeue(); + + // Meta info about stream + AudioFrame* getCurrent(); + + // Data info about "stream" (calculated from the packets) + int getLen(); + + // copy from packets to destination + int copy(float* left,float* right,int len); + int copy(short int* left,short int* right,int len); + void forwardStreamDouble(int len); + + int copy(short int* dest,int len); + int copy(float* dest,int len); + void forwardStreamSingle(int len); + + void clear(); + + private: + void transferFrame(float* left,float* right,FloatFrame*,int start,int len); + void transferFrame(short int* left,short int* right, + PCMFrame*,int start,int len); + void transferFrame(short int* dest, + PCMFrame*,int start,int len); + void transferFrame(float* dest, + FloatFrame*,int start,int len); + int copygeneric(char* left,char* right,int wantLen,int version,int mux); +}; +#endif diff --git a/mpeglib/lib/frame/floatFrame.cpp b/mpeglib/lib/frame/floatFrame.cpp new file mode 100644 index 00000000..5e17d1e1 --- /dev/null +++ b/mpeglib/lib/frame/floatFrame.cpp @@ -0,0 +1,50 @@ +/* + stores frames as floats. + Copyright (C) 2001 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 "floatFrame.h" + +#include <iostream> + +using namespace std; + +FloatFrame::FloatFrame(int size) { + data=new float[size]; + len=0; + this->size=size; + this->sampleSize=sizeof(float)*8; + this->lSigned=true; + this->lBigEndian=AUDIOFRAME_BIGENDIAN; + setFrameType(_FRAME_AUDIO_FLOAT); +} + + +FloatFrame::~FloatFrame() { + delete [] data; +} + + +void FloatFrame::putFloatData(float* in,int lenCopy) { + if ((len+lenCopy) > size) { + cout << "cannot copy putFloatData. Does not fit"<<endl; + exit(0); + } + memcpy(data+len,in,lenCopy*sizeof(float)); + len+=lenCopy; + + +} + + +void FloatFrame::putFloatData(float* left,float* right,int len) { + cout << "not yet implemented"<<endl; +} diff --git a/mpeglib/lib/frame/floatFrame.h b/mpeglib/lib/frame/floatFrame.h new file mode 100644 index 00000000..4d817021 --- /dev/null +++ b/mpeglib/lib/frame/floatFrame.h @@ -0,0 +1,46 @@ +/* + stores frames as floats. + Copyright (C) 2001 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 __FLOATFRAME_H +#define __FLOATFRAME_H + +#include "audioFrame.h" + +// this format has a sampleSize of sizeof(float), signed, endian==machine + +class FloatFrame : public AudioFrame { + + float* data; + int len; + int size; + + + public: + FloatFrame(int size); + ~FloatFrame(); + + int getLen() { return len; } + void setLen(int len) { this->len=len; } + int getSize() { return size; } + float* getData() { return data; } + + void putFloatData(float* data,int len); + void putFloatData(float* left,float* right,int len); + + void clearrawdata() { len=0; } + + + +}; +#endif diff --git a/mpeglib/lib/frame/frame.cpp b/mpeglib/lib/frame/frame.cpp new file mode 100644 index 00000000..c6a43969 --- /dev/null +++ b/mpeglib/lib/frame/frame.cpp @@ -0,0 +1,73 @@ +/* + base class for frames + Copyright (C) 2001 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 "frame.h" + + +Frame::Frame() { + type=_FRAME_UNK; +} + + +Frame::~Frame() { +} + + +const char* Frame::getMajorFrameName(int type) { + int majorID=type >> 12; + switch(majorID) { + case _FRAME_UNK: + return "_FRAME_UNK"; + case _FRAME_RAW: + return "_FRAME_RAW"; + case _FRAME_AUDIO: + return "_FRAME_AUDIO"; + case _FRAME_VIDEO: + return "_FRAME_VIDEO"; + case _FRAME_PAKET: + return "_FRAME_PAKET"; + default: + return "unknown major frameType"; + } + return "never happens Frame::getMajorFrameName"; +} + + + +const char* Frame::getFrameName(int type) { + switch(type) { + // Raw + case _FRAME_RAW_BASE: + return "_FRAME_RAW_BASE"; + case _FRAME_RAW_OGG: + return "_FRAME_RAW_OGG"; + + + // Audio + case _FRAME_AUDIO_BASE: + return "_FRAME_AUDIO_BASE"; + case _FRAME_AUDIO_PCM: + return "_FRAME_AUDIO_PCM"; + case _FRAME_AUDIO_FLOAT: + return "_FRAME_AUDIO_FLOAT"; + + + + // Rest + default: + return "cannot find name"; + } + return "never happens Frame::getFrameName"; +} + diff --git a/mpeglib/lib/frame/frame.h b/mpeglib/lib/frame/frame.h new file mode 100644 index 00000000..301b997c --- /dev/null +++ b/mpeglib/lib/frame/frame.h @@ -0,0 +1,101 @@ +/* + base class for frames + Copyright (C) 2001 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 __FRAME_H +#define __FRAME_H + + +#include <stdio.h> +#include <limits.h> +#include <stdlib.h> +#include <string.h> + + + +/** + The base class for frames. Every derived class from this class + must belong to some "major" class type and it must have an unique + id for itsself. Even if it is a base class it must have a unique id. + + How does this work. We have an int for the Frame id. In the int + itsself we but the majorid as well. + The Start codes are all multiple of 2 so for example + 0..127 belongs to FRAME UNK + 128..255 belongs to FRAME RAW + + So we can with a simple shift operation find out the major class +*/ +#define _FRAME_SHIFT 7 +#define _FRAME_ID_MAX 128 //(2^_FRAME_SHIFT) + + +// Major Frame classes +#define _FRAME_UNK 0 +#define _FRAME_RAW 1 +#define _FRAME_AUDIO 2 +#define _FRAME_VIDEO 3 +#define _FRAME_PAKET 4 + +// start ids of minor classes + +#define _FRAME_UNK_START (0) +#define _FRAME_RAW_START (_FRAME_ID_MAX) +#define _FRAME_AUDIO_START (_FRAME_ID_MAX*2) +#define _FRAME_VIDEO_START (_FRAME_ID_MAX*2*2) +#define _FRAME_PAKET_START (_FRAME_ID_MAX*2*2*2) + +// Minor Frame type IDs + + +// Raw +#define _FRAME_RAW_BASE (_FRAME_RAW_START+1) +#define _FRAME_RAW_OGG (_FRAME_RAW_START+2) +#define _FRAME_RAW_MPEG_I_VIDEO (_FRAME_RAW_START+3) +#define _FRAME_RAW_MPEG_SYSTEM (_FRAME_RAW_START+4) + + +// Audio: +#define _FRAME_AUDIO_BASE (_FRAME_AUDIO_START+1) +#define _FRAME_AUDIO_PCM (_FRAME_AUDIO_START+2) +#define _FRAME_AUDIO_FLOAT (_FRAME_AUDIO_START+3) + +// Video: +#define _FRAME_VIDEO_BASE (_FRAME_VIDEO_START+1) +#define _FRAME_VIDEO_YUV (_FRAME_VIDEO_START+2) +#define _FRAME_VIDEO_RGB_8 (_FRAME_VIDEO_START+3) +#define _FRAME_VIDEO_RGB_16 (_FRAME_VIDEO_START+4) +#define _FRAME_VIDEO_RGB_32 (_FRAME_VIDEO_START+5) + +// Packet: +#define _FRAME_PACKET_SYNC (_FRAME_PAKET_START+1) +#define _FRAME_PACKET_PACKET_CONTAINER (_FRAME_PAKET_START+2) + + + + +class Frame { + int type; + + public: + Frame(); + ~Frame(); + inline int getMajorFrameType() { return (type>>_FRAME_SHIFT);} + inline int getFrameType() { return type; } + inline void setFrameType(int type) { this->type=type; } + + + static const char* getMajorFrameName(int type); + static const char* getFrameName(int type); +}; +#endif diff --git a/mpeglib/lib/frame/frameQueue.cpp b/mpeglib/lib/frame/frameQueue.cpp new file mode 100644 index 00000000..fe524976 --- /dev/null +++ b/mpeglib/lib/frame/frameQueue.cpp @@ -0,0 +1,101 @@ +/* + queues frames + Copyright (C) 2001 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 "frameQueue.h" + +#include <iostream> + +using namespace std; + +FrameQueue::FrameQueue(int maxsize) { + this->size=maxsize; + entries = new Frame*[size]; + int i; + for(i=0;i<size;i++) { + entries[i]=NULL; + } + fillgrade=0; + writepos=0; + readpos=0; +} + + +FrameQueue::~FrameQueue() { + int i; + for(i=0;i<size;i++) { + if (entries[i] != NULL) { + delete entries[i]; + } + } + delete entries; +} + +int FrameQueue::canRead() { + return (fillgrade > 0); +} + + +int FrameQueue::canWrite() { + return (fillgrade < size); +} + + +int FrameQueue::getFillgrade() { + return fillgrade; +} + + +void FrameQueue::enqueue(Frame* frame) { + if(canWrite() == false) { + cout << "FrameQueue full cannot enqueue"<<endl; + exit(0); + } + fillgrade++; + entries[writepos]=frame; + writepos++; + if (writepos == size) { + writepos=0; + } +} + + +Frame* FrameQueue::dequeue() { + if(canRead() == false) { + cout << "FrameQueue empty cannot dequeue"<<endl; + exit(0); + } + Frame* back=entries[readpos]; + // invalide this frame, we do not longer own it! + entries[readpos]=NULL; + fillgrade--; + readpos++; + if (readpos == size) { + readpos=0; + } + return back; +} + +Frame* FrameQueue::peekqueue(int pos) { + if(fillgrade-pos <= 0) { + cout << "FrameQueue : cannot peek this positon"<<endl; + cout << "fillgrade:"<<fillgrade<<endl; + cout << "pos:"<<pos<<endl; + exit(0); + } + int getpos=(readpos+pos) % size; + + + Frame* back=entries[getpos]; + return back; +} + diff --git a/mpeglib/lib/frame/frameQueue.h b/mpeglib/lib/frame/frameQueue.h new file mode 100644 index 00000000..27747aa3 --- /dev/null +++ b/mpeglib/lib/frame/frameQueue.h @@ -0,0 +1,43 @@ +/* + queues frames + Copyright (C) 2001 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 __FRAMEQUEUE_H +#define __FRAMEQUEUE_H + +#include "frame.h" + +class FrameQueue { + + Frame** entries; + int fillgrade; + int size; + int writepos; + int readpos; + + + public: + FrameQueue(int maxsize); + ~FrameQueue(); + + int getFillgrade(); + int canRead(); + int canWrite(); + void enqueue(Frame* frame); + Frame* dequeue(); + Frame* peekqueue(int pos); + + +}; +#endif diff --git a/mpeglib/lib/frame/framer.cpp b/mpeglib/lib/frame/framer.cpp new file mode 100644 index 00000000..d380b2ec --- /dev/null +++ b/mpeglib/lib/frame/framer.cpp @@ -0,0 +1,241 @@ +/* + base class for converting raw data(stream) into some frametype. + Copyright (C) 2001 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 "framer.h" + + + +#define PROCESS_FIND 0 +#define PROCESS_READ 1 + +#include <iostream> + +using namespace std; + +Framer::Framer(int outsize) { + unsigned char* outptr=new unsigned char[outsize]; + init(outsize,outptr,true); +} + + +Framer::Framer(int outsize,unsigned char* outptr) { + if (outptr == NULL) { + cout << "Framer::Framer outptr NULL"<<endl; + exit(0); + } + if (outsize <= 0) { + cout << "Framer::Framer size <= 0"<<endl; + exit(0); + } + init(outsize,outptr,false); +} + + +void Framer::init(int outsize,unsigned char* outptr,int lDeleteOutPtr) { + buffer_data=outptr; + this->lDeleteOutPtr=lDeleteOutPtr; + input_info=new RawDataBuffer(NULL,0); + buffer_info=new RawDataBuffer(buffer_data,outsize); + lConstruct=true; + reset(); +} + + +Framer::~Framer() { + if (lDeleteOutPtr) { + delete[] buffer_data; + } + delete buffer_info; + delete input_info; +} + + +int Framer::canStore() { + return buffer_info->untilend(); +} + +int Framer::restBytes() { + return (input_info->size()-input_info->pos()); +} + + +void Framer::store(unsigned char* start,int bytes) { + if (buffer_info->pos()+bytes > buffer_info->size()) { + cout << "too much bytes inserted. cannot store that"<<endl; + exit(0); + } + if (main_state != FRAME_NEED) { + cout << "cannot store data, when not in MPEGAUDIOFRAME_NEED"<<endl; + exit(0); + } + input_info->set(start,bytes,0); + int fillgrade=input_info->untilend(); + if (fillgrade > 0) { + main_state=FRAME_WORK; + } +} + + +int Framer::work() { + if (main_state != FRAME_WORK) { + cout << "cannot find_frame, when not in MPEGAUDIOFRAME_WORK"<<endl; + exit(0); + } + if (lAutoNext) { + next(); + } + switch(process_state) { + case PROCESS_FIND: + if (find_frame(input_info,buffer_info) == true) { + setState(PROCESS_READ); + } + break; + case PROCESS_READ: + if (read_frame(input_info,buffer_info) == true) { + main_state=FRAME_HAS; + } + break; + default: + cout << "unknown process state in work. "<<endl; + printMainStates("printing states"); + exit(0); + } + // do not go to NEED if we have a frame and now the input is empty + if (main_state == FRAME_WORK) { + if (input_info->eof()) { + main_state=FRAME_NEED; + } + } + if (main_state == FRAME_HAS) return true; + return false; +} + + +void Framer::reset() { + unsync(buffer_info,true); + lAutoNext=false; + main_state=FRAME_NEED; + input_info->set(NULL,0,0); + buffer_info->setpos(0); + setState(PROCESS_FIND); +} + + +void Framer::next() { + unsync(buffer_info,false); + lAutoNext=false; + main_state=FRAME_WORK; + setState(PROCESS_FIND); +} + + +int Framer::getState() { + int back=main_state; + if (main_state == FRAME_HAS) { + // autonext when we devlivered one frame + lAutoNext=true; + main_state=FRAME_WORK; + setState(PROCESS_FIND); + } + if (lConstruct == true) { + lConstruct=false; + unsync(buffer_info,true); + } + return back; +} + + +void Framer::setState(int state) { + this->process_state=state; +} + + + +unsigned char* Framer::outdata() { + return buffer_info->ptr(); +} + + +unsigned char* Framer::indata() { + return buffer_info->current(); +} + +int Framer::len() { + return buffer_info->pos(); +} + + + +void Framer::printMainStates(const char* msg) { + cout << msg<<endl; + switch(main_state) { + case FRAME_NEED: + cout << "main_state: FRAME_NEED"<<endl; + break; + case FRAME_WORK: + cout << "main_state: FRAME_WORK"<<endl; + break; + case FRAME_HAS: + cout << "main_state: FRAME_HAS"<<endl; + break; + default: + cout << "unknown illegal main_state:"<<main_state<<endl; + } + + switch(process_state) { + case PROCESS_FIND: + cout << "process_state: PROCESS_FIND"<<endl; + break; + case PROCESS_READ: + cout << "process_state: PROCESS_READ"<<endl; + break; + default: + cout << "unknown illegal process_state:"<<process_state<<endl; + } + printPrivateStates(); + + +} + + + + +int Framer::find_frame(RawDataBuffer* ,RawDataBuffer* ) { + cout << "direct virtual call Framer::find_frame"<<endl; + return false; +} + + +int Framer::read_frame(RawDataBuffer* ,RawDataBuffer* ) { + cout << "direct virtual call Framer::read_frame"<<endl; + return false; +} + +void Framer::unsync(RawDataBuffer* ,int ) { + if (lConstruct == false) { + // invalidate header in buffer + cout << "direct virtual call Framer::unsync"<<endl; + } +} + + +void Framer::printPrivateStates() { + cout << "direct virtual call Framer::printPrivateStates"<<endl; +} + + +void Framer::setRemoteFrameBuffer(unsigned char* outptr,int size) { + + input_info->set(NULL,0,0); + buffer_info->set(outptr,size,0); +} diff --git a/mpeglib/lib/frame/framer.h b/mpeglib/lib/frame/framer.h new file mode 100644 index 00000000..51c4b26e --- /dev/null +++ b/mpeglib/lib/frame/framer.h @@ -0,0 +1,182 @@ +/* + base class for converting raw data(stream) into some frametype. + Copyright (C) 2001 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 __FRAMER_H +#define __FRAMER_H + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <kdemacros.h> + +#define FRAME_NEED 0 +#define FRAME_WORK 1 +#define FRAME_HAS 2 + + +#include "rawDataBuffer.h" + + +/** + If we want to have a "push" interface, this means the decoder + does not read from an input interface, we must be sure + that we have a valid mpeg audio frame, before we feed + this whole frame to the decoder. + + This class tells you how many bytes it can read and + gives you information wether we have a valid frame or not. + + This class has three public states: + + FRAME_NEED + / \ + / \ + / \ + FRAME_WORK <----------> FRAME_HAS + + + after the "FRAME_HAS" state we devliver _excatly_ one time + this state, and then automatically go to "FRAME_WORK" state. + + + You can reset() the class which empties the buffer and then + starts searching for a new sync code, or you can + do a next() which searches for the sync code, without + emptying the buffer (this is done automatically, + after the first call, when we was ins state "FRAME_HAS" + + Note: i) You need a reset() if a "seek" occurs in your stream + ii) First call to the class must be "getState" which does the + Post-Constructor setup in derived classes! + + The FRAME_NEED state is entered if the input buffer is empty + you then need to "push" data in this class. + The FRAME_NEED state is necessary to avoid an additonal memcpy + and a ringbuffer.(This safes "overhead"/"cpu cycles") +*/ + + + + +class KDE_EXPORT Framer { + + // this is our destination buffer for the output frame + // this buffer must be able to store the maximum size + // a frame of this type can have. + // Examples: + // avi-Chunk : 65KB + // mpeg audio: 4KB is always enough + // mpeg video: 224K (spec says this) + + // this can be a remote buffer or a local one + unsigned char* buffer_data; + RawDataBuffer* buffer_info; + + // state from FIND->READ->HAS + int process_state; + // state between NEED <-> PROCESS + int main_state; + + RawDataBuffer* input_info; + int lAutoNext; + + // stores if we have alloceated outdata or not + int lDeleteOutPtr; + // internal: unsync not done + int lConstruct; + + public: + // allocate local output buffer + Framer(int outsize); + + // outbuffer is remote. + Framer(int outsize,unsigned char* outptr); + + virtual ~Framer(); + + // + // process states (transitions) [START] + // + + // stores pointer to input and len + void store(unsigned char* start,int bytes); + int work(); + void reset(); + void next(); + // returns pointer to outbuffer (frameheader+data) + unsigned char* outdata(); + + // returns pointer to inbuffer (raw data) + // Note: this ptr is not fixed! It may vary from time to time + // Cannot be stores in a variable! + unsigned char* indata(); + + + // + // process states (transitions) [END] + // + + + // + // state helper functions [START] + // + int getState(); + // returns number of bytes. + int canStore(); + + // returns length of frame == len(frameheader+data) + int len(); + + // returns number of bytes still in input(needed for a/v sync) + int restBytes(); + // + // state helper functions [END] + // + + // debugging + void printMainStates(const char* msg); + + private: + void init(int outsize,unsigned char* outptr,int lDeleteOutptr); + + void setState(int state); + + // + // Overload functions for specialized framers [START] + // + + // return true, if frame header found + virtual int find_frame(RawDataBuffer* input,RawDataBuffer* store); + // return true, if frame data read. + virtual int read_frame(RawDataBuffer* input,RawDataBuffer* store); + // makes buffer invalid, reset to begin of "find_frame" + virtual void unsync(RawDataBuffer* store,int lReset); + // debugging + virtual void printPrivateStates(); + + // + // Overload functions for specialized framers [END] + // + + protected: + // this can be used, if the outptr come from a different framer + // (eg: OGG framer). You then need to call the construtor with + // some "dummy" size. + void setRemoteFrameBuffer(unsigned char* outptr,int size); + +}; + + +#endif diff --git a/mpeglib/lib/frame/pcmFrame.cpp b/mpeglib/lib/frame/pcmFrame.cpp new file mode 100644 index 00000000..24ab9792 --- /dev/null +++ b/mpeglib/lib/frame/pcmFrame.cpp @@ -0,0 +1,140 @@ +/* + pcm frame description. + Copyright (C) 2001 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 "pcmFrame.h" + +#include <iostream> + +using namespace std; + +#ifndef WORDS_BIGENDIAN +// this is fast on INTEL, but maybe not work on other little +// endian machines. (are there any?) +#define convMacro(in,dtemp,tmp) \ + in[0]*=SCALFACTOR; \ + dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0))+(in[0]); \ + tmp = ((*(int *)&dtemp) - 0x80000000); \ + in++; \ + if(tmp>32767) { \ + tmp=32767; \ + } else if (tmp<-32768) { \ + tmp =-0x8000; \ + } + +#else /* big endian conversion: _AIX */ +static inline void convMacro(float*& in, double dtemp, int& tmp) +{ + in[0]*=SCALFACTOR; + tmp = (int)*in; + in++; + if(tmp>32767) { + tmp=32767; + } else if (tmp<-32768) { + tmp =-0x8000; + } + tmp = ((tmp & 0xff) << 8) | ((tmp >> 8) & 0xff); +} +#endif /* _AIX */ + + +PCMFrame::PCMFrame(int size) { + data=new short int[size]; + len=0; + this->size=size; + // this format has a sampleSize of 16, signed, endian==machine + this->sampleSize=sizeof(short int)*8; + this->lSigned=true; + this->lBigEndian=AUDIOFRAME_BIGENDIAN; + setFrameType(_FRAME_AUDIO_PCM); +} + + +PCMFrame::~PCMFrame() { + delete [] data; +} + + +void PCMFrame::putFloatData(float* left,float* right,int copyLen) { + int destSize=0; + if (left != NULL) destSize++; + if (right != NULL) destSize++; + destSize*=copyLen; + if ((len+destSize) > size) { + cout << "cannot copy putFloatData L/R version . Does not fit"<<endl; + cout << "size:"<<size<<endl; + cout << "len:"<<len<<endl; + cout << "destSize:"<<destSize<<endl; + exit(0); + } + double dtemp; + int tmp; + int i=copyLen; + switch(getStereo()) { + case 1: + while(i > 0) { + convMacro(left,dtemp,tmp); + data[len++]=(short int)tmp; + convMacro(right,dtemp,tmp); + data[len++]=(short int)tmp; + i--; + } + break; + case 0: + if (left != NULL) { + int i=copyLen; + while(i > 0) { + convMacro(left,dtemp,tmp); + data[len++]=(short int)tmp; + i--; + // right channel empty + len++; + } + } + if (right != NULL) { + int i=copyLen; + len=len-destSize; + while(i > 0) { + // select right channel + len++; + convMacro(right,dtemp,tmp); + data[len++]=(short int)tmp; + i--; + // left channel already copied + } + } + break; + default: + cout << "unknown stereo value in pcmFrame"<<endl; + exit(0); + } +} + +void PCMFrame::putFloatData(float* in,int lenCopy) { + + if ((len+lenCopy) > size) { + cout << "cannot copy putFloatData. Does not fit"<<endl; + exit(0); + } + double dtemp; + int tmp; + while(lenCopy > 0) { + convMacro(in,dtemp,tmp); + data[len++]=(short int)tmp; + lenCopy--; + } + +} + + + diff --git a/mpeglib/lib/frame/pcmFrame.h b/mpeglib/lib/frame/pcmFrame.h new file mode 100644 index 00000000..a19941bc --- /dev/null +++ b/mpeglib/lib/frame/pcmFrame.h @@ -0,0 +1,45 @@ +/* + pcm frame description. + Copyright (C) 2001 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 __PCMFRAME_H +#define __PCMFRAME_H + + +#include "audioFrame.h" +#include <kdemacros.h> +// this format has a sampleSize of 16, signed, endian==machine + +class KDE_EXPORT PCMFrame : public AudioFrame { + + short int* data; + int len; + int size; + + public: + PCMFrame(int size); + ~PCMFrame(); + + int getLen() { return len; } + void setLen(int len) { this->len=len; } + int getSize() { return size; } + short int* getData() { return data; } + + void putFloatData(float* data,int len); + void putFloatData(float* left,float* right,int len); + + void clearrawdata() { len=0; } + + +}; +#endif diff --git a/mpeglib/lib/frame/rawDataBuffer.cpp b/mpeglib/lib/frame/rawDataBuffer.cpp new file mode 100644 index 00000000..f8635211 --- /dev/null +++ b/mpeglib/lib/frame/rawDataBuffer.cpp @@ -0,0 +1,21 @@ +/* + stores simple buffer information. does not allocate anything + Copyright (C) 2001 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 "rawDataBuffer.h" + +// hm + +RawDataBuffer::~RawDataBuffer() { +} + + diff --git a/mpeglib/lib/frame/rawDataBuffer.h b/mpeglib/lib/frame/rawDataBuffer.h new file mode 100644 index 00000000..755818ea --- /dev/null +++ b/mpeglib/lib/frame/rawDataBuffer.h @@ -0,0 +1,48 @@ +/* + stores simple buffer information. does not allocate anything + Copyright (C) 2001 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 __RAWDATABUFFER_H +#define __RAWDATABUFFER_H + + +class RawDataBuffer { + + int _size; + unsigned char* _ptr; + int _pos; + + public: + RawDataBuffer(unsigned char* ptr,int size) { set(ptr,size,0); } + ~RawDataBuffer(); + + + + unsigned char* ptr() { return _ptr; } + unsigned char* current() { return _ptr+_pos; } + int size() { return _size; } + int pos() { return _pos; } + int untilend() { return _size-_pos; } + int eof() { return _pos>=_size; } + + void inc() { this->_pos++; } + void inc(int val) { this->_pos+=val; } + void setpos(int val) { this->_pos=val; } + void setptr(unsigned char* ptr) { this->_ptr=ptr; } + void setsize(int size) { this->_size=size; } + + void set(unsigned char* ptr, + int size,int pos) { setpos(pos);setptr(ptr);setsize(size);} + +}; +#endif diff --git a/mpeglib/lib/frame/rawFrame.cpp b/mpeglib/lib/frame/rawFrame.cpp new file mode 100644 index 00000000..fbe662c5 --- /dev/null +++ b/mpeglib/lib/frame/rawFrame.cpp @@ -0,0 +1,90 @@ +/* + base class for raw frames (encoded data, where only the type is known) + Copyright (C) 2001 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 "rawFrame.h" + +#include <iostream> + +using namespace std; + +RawFrame::RawFrame(int size) { + init(_FRAME_RAW_BASE,size); +} + + +RawFrame::RawFrame(int type,int size) { + init(type,size); +} + + +RawFrame::~RawFrame() { + if (data != NULL) { + if (lRemoteData==false) { + delete data; + } + } +} + + +void RawFrame::print(const char* msg) { + cout << msg<<endl; + cout << "major Frametype:"<<Frame::getFrameName(getFrameType()); + cout << "size:"<<getSize(); + cout << "len:"<<getLen(); + +} + + +void RawFrame::init(int type,int size) { + + if (size < 0) { + cout << "size <= 0 in RawFrame::RawFrame"<<endl; + exit(-1); + } + setFrameType(type); + int majorType=getMajorFrameType(); + if (majorType != _FRAME_RAW) { + cout << "invalid Major Frametype:"<<Frame::getFrameName(getFrameType()) + << " for this class"<<endl; + printf("ID:0x%x dec:%d majorID:%d\n",type,type,majorType); + cout << "RawFrame::init"<<endl; + exit(-1); + } + if (size == 0) { + data=NULL; + this->size=0; + } + if (size > 0) { + data=new unsigned char[size]; + if (data != NULL) { + cout <<"malloc error RawFrame"<<endl; + exit(-1); + } + this->size=size; + } + setLen(0); + lRemoteData=false; +} + + +void RawFrame::setRemoteData(unsigned char* data,int size) { + if (this->data != NULL) { + if (lRemoteData==false) { + delete this->data; + } + } + lRemoteData=true; + this->data=data; + this->size=size; +} diff --git a/mpeglib/lib/frame/rawFrame.h b/mpeglib/lib/frame/rawFrame.h new file mode 100644 index 00000000..e1a05e9e --- /dev/null +++ b/mpeglib/lib/frame/rawFrame.h @@ -0,0 +1,75 @@ +/* + base class for raw frames (encoded data, where only the type is known) + Copyright (C) 2001 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 __RAW_FRAME_H +#define __RAW_FRAME_H + +#include "frame.h" + +/** + Raw frames represents bitstreams. They most likely have have now + real value for anyone but a decoder. + In general you simply allocate a rawFrame with a given size, This + size should make sure, that the bitstream packet does fit into + the frame. Sometime, in derived classes you can set thes pointer + to the allocated directly by calling the protected method: setRemoteData. +*/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef WORDS_BIGENDIAN +#define RAWFRAME_BIGENDIAN 1 +#else +#define RAWFRAME_BIGENDIAN 0 +#endif + + +class RawFrame : public Frame { + + unsigned char* data; + int size; + int len; + int lRemoteData; + + public: + RawFrame(int size); + RawFrame(int type,int size); + ~RawFrame(); + + // access start of frameData + unsigned char* getData() { return data; } + + // current size in byte + int getLen() { return len; } + void setLen(int bytes) { this->len=bytes; } + + // maximum size of allocated memory + int getSize() { return size; } + + + void print(const char* msg); + + private: + void init(int type,int size); + + protected: + void setRemoteData(unsigned char* data,int size); +}; + + + +#endif |