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/example/splay/Makefile.am | 41 ++++++ mpeglib/example/splay/mp3framing.cpp | 274 +++++++++++++++++++++++++++++++++++ mpeglib/example/splay/splay.cpp | 64 ++++++++ 3 files changed, 379 insertions(+) create mode 100644 mpeglib/example/splay/Makefile.am create mode 100644 mpeglib/example/splay/mp3framing.cpp create mode 100644 mpeglib/example/splay/splay.cpp (limited to 'mpeglib/example/splay') diff --git a/mpeglib/example/splay/Makefile.am b/mpeglib/example/splay/Makefile.am new file mode 100644 index 00000000..76e04cff --- /dev/null +++ b/mpeglib/example/splay/Makefile.am @@ -0,0 +1,41 @@ +# splay-yaf - Makefile.am + +INCLUDES = -I../../include $(all_includes) + +EXTRA_DIST = + +noinst_PROGRAMS = splay mp3framing + +splay_SOURCES = splay.cpp + +mp3framing_SOURCES = mp3framing.cpp + +noinst_HEADERS = + +splay_LDFLAGS = $(all_libraries) + +splay_LDADD = ../../lib/libmpeg.la \ + $(THIS_LIB_LIBS) + +mp3framing_LDFLAGS = $(all_libraries) +mp3framing_LDADD = ../../lib/libmpeg.la \ + $(THIS_LIB_LIBS) + + + + + + + + + + + + + + + + + + + diff --git a/mpeglib/example/splay/mp3framing.cpp b/mpeglib/example/splay/mp3framing.cpp new file mode 100644 index 00000000..586899a3 --- /dev/null +++ b/mpeglib/example/splay/mp3framing.cpp @@ -0,0 +1,274 @@ +/* + + Example how frame creation works. + + For the input we have std. file input. + We convert it to mpeg I encoded frames (mpegAudioFrame's job) + + The decoded pcmFrames are stores in a queue. + + If the queue if full, we "stream" the packets to /dev/dsp. + (The difference between directly playing the packets and "streaming" + is, that while streaming you can say: I want x bytes I don't care + about frame boundaries) + This is audioFrameQueue's job. + + + */ + + +#include "../../lib/splay/mpegAudioFrame.h" +#include "../../lib/splay/splayDecoder.h" +#include "../../lib/util/audio/dspWrapper.h" +#include "../../lib/frame/audioFrameQueue.h" + +#include + +using namespace std; + +// used for getopt +#include + +#define INPUT_SIZE 8192 +#define _QUEUE_FLOAT 1 +#define _QUEUE_INT 2 + + +void usage() { + printf("Usage:\n\n"); + printf("mp3framing [hf] filename\n\n"); + printf(" -f use float queue\n"); + printf(" -c [samples] checkout samples\n"); +} + + +void initDSP(DSPWrapper* dsp) { + if (dsp->openDevice()==false) { + cout << "cannot open /dev/dsp"<= argc ) { + usage(); + exit(-1); + } + FILE* file=fopen(argv[optind],"r"); + if (file == NULL) { + cout << "cannot open:"<dataQueueCanWrite() == true) ) { + + // + // This switch/case statement "partitions" the fileinput + // into mp3frames. We directly decode them to pcmFrames. + // + + // + // There are three states. One is "I want Input, give me input" + // The other is "I have enough input, dont' bother me and let + // me do my work" + // The last ist "I have a frame here, take care of this, or + // I will continue with my work" + + int state=frame->getState(); + switch(state) { + case FRAME_NEED: { + int bytes=frame->canStore(); + int read=fread(inputbuffer,1,bytes,file); + if (read != bytes) { + // read error. reset framer + frame->reset(); + continue; + } + frame->store(inputbuffer,bytes); + break; + } + case FRAME_WORK: + frame->work(); + break; + case FRAME_HAS:{ + AudioFrame* emptyFrame= frameQueue->emptyQueueDequeue(); + splay->decode(frame->outdata(),frame->len(),emptyFrame); + frameQueue->dataQueueEnqueue(emptyFrame); + cout << "storing decodec frame:"<getCurrent(); + dsp->audioSetup(audioFrame); + } + + if (queueType == _QUEUE_FLOAT) { + AudioFrame* audioFrame=frameQueue->getCurrent(); + dsp->audioSetup(audioFrame->getStereo(),16, + audioFrame->getSigned(), + audioFrame->getBigEndian(), + audioFrame->getFrequenceHZ()); + outFrame->setFrameFormat(audioFrame->getStereo(), + audioFrame->getFrequenceHZ()); + } + + + + // + // read from stream demo: + // + + while(frameQueue->getLen() > 0) { + int hasLen= frameQueue->getLen(); + + cout << "hasLen:"<copy(outFrame->getData(),samples); + dsp->audioPlay((char*)outFrame->getData(),hasRead*sizeof(short int)); + frameQueue->forwardStreamSingle(hasRead); + } + + + if (queueType == _QUEUE_FLOAT) { + int n; + + hasRead=frameQueue->copy(left,right,samples); + frameQueue->forwardStreamDouble(hasRead); + n=hasRead; + + /* + FloatFrame* floatFrame=( FloatFrame*) frameQueue->dataQueueDequeue(); + float* left=floatFrame->getData(); + n=floatFrame->getLen(); + */ + + int i=0; + while(i 32767) val=32767; + if (val < -32768) val=-32768; + dsp->audioPlay((char*)&val,2); + + if (outFrame->getStereo()) { + val=(int)(32768.0*right[i]); + if (val > 32767) val=32767; + if (val < -32768) val=-32768; + dsp->audioPlay((char*)&val,2); + } + + i++; + } + + } + } + + + delete frameQueue; + delete splay; + delete frame; + delete dsp; + delete left; + delete right; + delete outFrame; + return(0); +} + diff --git a/mpeglib/example/splay/splay.cpp b/mpeglib/example/splay/splay.cpp new file mode 100644 index 00000000..75254360 --- /dev/null +++ b/mpeglib/example/splay/splay.cpp @@ -0,0 +1,64 @@ +/* + + Example how the plugin interface works.(LINUX Open Sound System only!) + + + */ + + +#include "../../lib/decoder/splayPlugin.h" +#include "../../lib/decoder/tplayPlugin.h" +#include "../../lib/decoder/vorbisPlugin.h" +#include "../../lib/input/bufferInputStream.h" +#include "../../lib/output/avSyncer.h" + +#include + +using namespace std; + +int main(int argc, char** argv) { + + + + if (argc <= 1) { + printf("Usage:\n\n"); + printf("%s filename\n\n",argv[0]); + exit(0); + } + + // + // The order is important !!!! + // 1. construct + // 2. set Output + // 3. open input + // 4. set input + // + // you cannot set the input _before_ the output + // in fact you can, but this gives you a segfault! + + SplayPlugin* plugin=new SplayPlugin(); + OutputStream* out=OutPlugin::createOutputStream(_OUTPUT_LOCAL,true); + InputStream* in=InputPlugin::createInputStream(argv[1],true); + + in->open(argv[1]); + // watch the order! + plugin->setOutputPlugin(out); + plugin->setInputPlugin(in); + plugin->play(); + + while(plugin->getStreamState() != _STREAM_STATE_EOF) { + cout << "check state"<audioClose(); + plugin->close(); + + delete plugin; + delete in; + delete out; + return(0); +} + -- cgit v1.2.1