diff options
Diffstat (limited to 'mpeglib/lib/oggvorbis')
-rw-r--r-- | mpeglib/lib/oggvorbis/Makefile.am | 32 | ||||
-rw-r--r-- | mpeglib/lib/oggvorbis/oggFrame.cpp | 29 | ||||
-rw-r--r-- | mpeglib/lib/oggvorbis/oggFrame.h | 50 | ||||
-rw-r--r-- | mpeglib/lib/oggvorbis/ovFramer.cpp | 128 | ||||
-rw-r--r-- | mpeglib/lib/oggvorbis/ovFramer.h | 69 | ||||
-rw-r--r-- | mpeglib/lib/oggvorbis/vorbisDecoder.cpp | 135 | ||||
-rw-r--r-- | mpeglib/lib/oggvorbis/vorbisDecoder.h | 53 | ||||
-rw-r--r-- | mpeglib/lib/oggvorbis/vorbisInfo.cpp | 150 | ||||
-rw-r--r-- | mpeglib/lib/oggvorbis/vorbisInfo.h | 76 |
9 files changed, 722 insertions, 0 deletions
diff --git a/mpeglib/lib/oggvorbis/Makefile.am b/mpeglib/lib/oggvorbis/Makefile.am new file mode 100644 index 00000000..2fe00b72 --- /dev/null +++ b/mpeglib/lib/oggvorbis/Makefile.am @@ -0,0 +1,32 @@ +# liboggvorbis - Makefile.am + + +INCLUDES = $(all_includes) + + +noinst_LTLIBRARIES = liboggvorbisbase.la + +kmpgincludedir = $(includedir)/$(THIS_LIB_NAME)/oggvorbis + +kmpginclude_HEADERS = ovFramer.h vorbisDecoder.h oggFrame.h \ + vorbisInfo.h + + +liboggvorbisbase_la_SOURCES = ovFramer.cpp vorbisDecoder.cpp \ + oggFrame.cpp vorbisInfo.cpp + + + + + + + + + + + + + + + + diff --git a/mpeglib/lib/oggvorbis/oggFrame.cpp b/mpeglib/lib/oggvorbis/oggFrame.cpp new file mode 100644 index 00000000..ace7dadc --- /dev/null +++ b/mpeglib/lib/oggvorbis/oggFrame.cpp @@ -0,0 +1,29 @@ +/* + here we have an ogg frame. Its still a raw 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 "oggFrame.h" + +#ifdef OGG_VORBIS + + +OGGFrame::OGGFrame() : RawFrame(_FRAME_RAW_OGG,0) { + setRemoteData((unsigned char*) &op,sizeof(op)); + +} + +OGGFrame::~OGGFrame() { +} + + + +#endif diff --git a/mpeglib/lib/oggvorbis/oggFrame.h b/mpeglib/lib/oggvorbis/oggFrame.h new file mode 100644 index 00000000..a069a33e --- /dev/null +++ b/mpeglib/lib/oggvorbis/oggFrame.h @@ -0,0 +1,50 @@ +/* + here we have an ogg frame. Its still a raw 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 __OGG_FRAME_H +#define __OGG_FRAME_H + + +/** + One Ogg Paket as frame. We pass the datapointer and the size + to the rawFrame and of course, set the PaktedID to: + _FRAME_RAW_OGG +*/ + +#include "../frame/rawFrame.h" + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef OGG_VORBIS + +#include <vorbis/codec.h> + +class OGGFrame : public RawFrame { + + ogg_packet op; + + public: + OGGFrame(); + ~OGGFrame(); + + +}; + +#endif + +#endif + diff --git a/mpeglib/lib/oggvorbis/ovFramer.cpp b/mpeglib/lib/oggvorbis/ovFramer.cpp new file mode 100644 index 00000000..ca3506af --- /dev/null +++ b/mpeglib/lib/oggvorbis/ovFramer.cpp @@ -0,0 +1,128 @@ +/* + frames raw data into Ogg/Vorbis 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 "ovFramer.h" + +#define OGG_SYNC_BUFF_SIZE 4096 + + +#define _OV_SETSERIAL 1 +#define _OV_STREAMIN 2 +#define _OV_STREAMOUT 3 + +#include <iostream> + +using namespace std; + + +#ifdef OGG_VORBIS + +OVFramer::OVFramer(OGGFrame* dest):Framer(1) { + if (dest == NULL) { + cout << "OGGFrame NULL in OVFramer"<<endl; + exit(-1); + } + this->dest=dest; + /********** Decode setup ************/ + ogg_sync_init(&oy); /* Now we can read pages */ + + vorbis_state=_OV_SETSERIAL; +} + + +OVFramer::~OVFramer() { + /* OK, clean up the framer */ + ogg_sync_clear(&oy); +} + + +int OVFramer::find_frame(RawDataBuffer* input,RawDataBuffer* store) { + while(input->eof()==true) { + cout << "input eof"<<endl; + return false; + } + + if (vorbis_state == _OV_STREAMOUT) { + if(ogg_stream_packetout(&os,(ogg_packet*)dest->getData())!=1){ + vorbis_state=_OV_STREAMIN; + return false; + } + return true; + } + + // do we have ogg packets in the ogg framer? + if (ogg_sync_pageout(&oy,&og) == 0) { + // no, ok insert some. + int bytes=input->untilend(); + input->inc(bytes); + store->inc(bytes); + ogg_sync_wrote(&oy,bytes); + // and setup the next buffer + /* submit a 4k block to libvorbis' Ogg layer */ + buffer=ogg_sync_buffer(&oy,OGG_SYNC_BUFF_SIZE); + /* override our own dummy buffer with size 1 */ + setRemoteFrameBuffer((unsigned char*)buffer,OGG_SYNC_BUFF_SIZE); + return false; + } + // we have an ogg page + // now try to build an ogg packet + switch(vorbis_state) { + case _OV_SETSERIAL: + /* Get the serial number and set up the rest of decode. */ + /* serialno first; use it to set up a logical stream */ + ogg_stream_init(&os,ogg_page_serialno(&og)); + vorbis_state=_OV_STREAMIN; + // yes we need to put this into the "pager" + // no break. + case _OV_STREAMIN: + if(ogg_stream_pagein(&os,&og)<0){ + /* error; stream version mismatch perhaps */ + fprintf(stderr,"Error reading first page of Ogg bitstream data.\n"); + exit(1); + } + vorbis_state=_OV_STREAMOUT; + break; + default: + cout << "unknow vorbis_state"<<endl; + exit(-1); + } + + return false; +} + +int OVFramer::read_frame(RawDataBuffer* ,RawDataBuffer* ) { + return true; +} + + + +void OVFramer::unsync(RawDataBuffer* store,int lReset) { + if (lReset) { + store->setpos(0); + ogg_sync_reset(&oy); + /* submit a 4k block to libvorbis' Ogg layer */ + buffer=ogg_sync_buffer(&oy,OGG_SYNC_BUFF_SIZE); + /* override our own dummy buffer with size 1 */ + setRemoteFrameBuffer((unsigned char*)buffer,OGG_SYNC_BUFF_SIZE); + } + +} + + +void OVFramer::printPrivateStates() { + cout << "OVFramer::printPrivateStates"<<endl; +} + + +#endif diff --git a/mpeglib/lib/oggvorbis/ovFramer.h b/mpeglib/lib/oggvorbis/ovFramer.h new file mode 100644 index 00000000..4845fddb --- /dev/null +++ b/mpeglib/lib/oggvorbis/ovFramer.h @@ -0,0 +1,69 @@ +/* + frames raw data into Ogg/Vorbis 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 __OVFRAMER_H +#define __OVFRAMER_H + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef OGG_VORBIS + +#include <vorbis/codec.h> +#include "../frame/framer.h" +#include "oggFrame.h" + +/** + + This framer works directly on the raw ogg_packet as output + Note: the internal setup makes sure, that we initialize + the ogg stream to the first found logical bitstream. + (For now this should mean: we found vorbis) + When the frame goes into the "HAS" state, you have the ogg + packet in the in the dest struct from the constructor. +*/ + +class OVFramer : public Framer { + + int vorbis_state; + + ogg_sync_state oy; /* sync and verify incoming physical bitstream */ + ogg_stream_state os; /* take physical pages, weld into a logical + stream of packets */ + ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */ + + char *buffer; /* sync buffer from ogg */ + + OGGFrame* dest; /* one raw packet of data for decode */ + + public: + // IMPORTANT: because we use this ptr internally the + // data to op cannot be on the stack! + OVFramer(OGGFrame* dest); + ~OVFramer(); + + + private: + + int find_frame(RawDataBuffer* input,RawDataBuffer* store); + int read_frame(RawDataBuffer* input,RawDataBuffer* store); + + void unsync(RawDataBuffer* store,int lReset); + void printPrivateStates(); + +}; +#endif + +#endif diff --git a/mpeglib/lib/oggvorbis/vorbisDecoder.cpp b/mpeglib/lib/oggvorbis/vorbisDecoder.cpp new file mode 100644 index 00000000..24e9370d --- /dev/null +++ b/mpeglib/lib/oggvorbis/vorbisDecoder.cpp @@ -0,0 +1,135 @@ +/* + converts ogg frames into audioFrames + 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 "vorbisDecoder.h" + +#ifdef OGG_VORBIS + +#define _VORBIS_NEED_SYNTHHEADER_1 1 +#define _VORBIS_NEED_SYNTHHEADER_2 2 +#define _VORBIS_NEED_SYNTHHEADER_3 3 + +#define _VORBIS_DECODE_SETUP 4 +#define _VORBIS_DECODE_LOOP 5 + +#include <iostream> + +using namespace std; + + +VorbisDecoder::VorbisDecoder() { + vorbis_info_init(&vi); + vorbis_comment_init(&vc); + reset(); +} + + +VorbisDecoder::~VorbisDecoder() { +} + +int VorbisDecoder::hasHeader() { + return (initState>=_VORBIS_DECODE_LOOP); +} + +int VorbisDecoder::decode(RawFrame* rawFrame,AudioFrame* dest) { + + if ((rawFrame == NULL) || (dest == NULL)) { + cout << "VorbisDecoder::decode NULL pointer!"<<endl; + exit(-1); + } + if (rawFrame->getFrameType() != _FRAME_RAW_OGG) { + cout << "VorbisDecoder::decode not _FRAME_RAW_OGG"<<endl; + exit(-1); + } + + ogg_packet* op=(ogg_packet*) rawFrame->getData(); + switch(initState) { + case _VORBIS_NEED_SYNTHHEADER_1: + case _VORBIS_NEED_SYNTHHEADER_2: + case _VORBIS_NEED_SYNTHHEADER_3: + cout << "_VORBIS_NEED_SYNTHHEADER:"<<initState<<endl; + if(vorbis_synthesis_headerin(&vi,&vc,op)<0){ + /* error case; not a vorbis header */ + fprintf(stderr,"This Ogg bitstream does not contain Vorbis " + "audio data.\n"); + exit(1); + } + initState++; + break; + case _VORBIS_DECODE_SETUP: + cout << "_VORBIS_DECODE_SETUP"<<endl; + vorbis_synthesis_init(&vd,&vi); /* central decode state */ + vorbis_block_init(&vd,&vb); /* local state for most of the decode + so multiple block decodes can + proceed in parallel. We could init + multiple vorbis_block structures + for vd here */ + initState=_VORBIS_DECODE_LOOP; + // yes right, we must decode the packet! + // so there is no break here. + case _VORBIS_DECODE_LOOP: { + if(vorbis_synthesis(&vb,op)==0) {/* test for success! */ + vorbis_synthesis_blockin(&vd,&vb); + } else { + cout << "vorbis_synthesis error"<<endl; + exit(0); + } + float **pcm; + /* + + **pcm is a multichannel float vector. In stereo, for + example, pcm[0] is left, and pcm[1] is right. samples is + the size of each channel. Convert the float values + (-1.<=range<=1.) to whatever PCM format and write it out + + */ + int samples=vorbis_synthesis_pcmout(&vd,&pcm); + if (samples > 0) { + int maxSamples=dest->getSize(); + if (samples > maxSamples) { + cout << "more samples in vorbis than we can store"<<endl; + exit(0); + } + dest->clearrawdata(); + dest->setFrameFormat(vi.channels-1,vi.rate); + + if (vi.channels == 2) { + dest->putFloatData(pcm[0],pcm[1],samples); + } else { + dest->putFloatData(pcm[0],NULL,samples); + } + + vorbis_synthesis_read(&vd,samples); /* tell libvorbis how + many samples we + actually consumed */ + return true; + } + + return false; + } + default: + cout << "unknown state in vorbis decoder"<<endl; + exit(0); + } + return false; +} + +void VorbisDecoder::reset() { + initState=_VORBIS_NEED_SYNTHHEADER_1; +} + +void VorbisDecoder::config(const char* ,const char* ,void* ) { + +} + +#endif diff --git a/mpeglib/lib/oggvorbis/vorbisDecoder.h b/mpeglib/lib/oggvorbis/vorbisDecoder.h new file mode 100644 index 00000000..e67a94bb --- /dev/null +++ b/mpeglib/lib/oggvorbis/vorbisDecoder.h @@ -0,0 +1,53 @@ +/* + converts ogg frames into audioFrames + 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 __VORBISDECODER_H +#define __VORBISDECODER_H + +#include "../frame/audioFrame.h" +#include <string.h> + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef OGG_VORBIS + +#include <vorbis/codec.h> +#include "oggFrame.h" + +class VorbisDecoder { + + vorbis_info vi; /* struct that stores all the static vorbis bitstream + settings */ + vorbis_comment vc; /* struct that stores all the bitstream user comments */ + vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ + vorbis_block vb; /* local working space for packet->PCM decode */ + + int initState; + + public: + VorbisDecoder(); + ~VorbisDecoder(); + + void reset(); + int hasHeader(); + + int decode(RawFrame* rawFrame,AudioFrame* dest); + void config(const char* key,const char* val,void* ret); +}; + +#endif + +#endif diff --git a/mpeglib/lib/oggvorbis/vorbisInfo.cpp b/mpeglib/lib/oggvorbis/vorbisInfo.cpp new file mode 100644 index 00000000..b71f99c3 --- /dev/null +++ b/mpeglib/lib/oggvorbis/vorbisInfo.cpp @@ -0,0 +1,150 @@ +/* + info about vorbis files. + 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 "vorbisInfo.h" + +#include <iostream> + +using namespace std; + +#ifdef OGG_VORBIS +#define CHUNKSIZE 4096 + +#define GETINPUT(stream,input) \ + VorbisInfo* info=(VorbisInfo*) stream; \ + FileAccess* input=info->getInput(); + + +size_t fread_func2(void *ptr, size_t size, size_t nmemb, void *stream) { + GETINPUT(stream,input); + + size_t want=size*nmemb; + size_t back=input->read((char*)ptr,want); + return back; +} + + +int fseek_func2(void *stream, ogg_int64_t offset, int whence) { + int ret; + GETINPUT(stream,input); + + if (whence==SEEK_SET) { + ret=input->seek(offset); + info->setSeekPos(offset); + return ret; + } + if (whence==SEEK_CUR) { + ret=input->seek(input->getBytePosition()+offset); + return ret; + } + if (whence==SEEK_END) { + ret=input->seek(input->getByteLength()); + return ret; + } + cout << "hm, strange call"<<endl; + return -1; +} + + +int fclose_func2 (void * stream) { + cout << "fclose_func"<<endl; + GETINPUT(stream,input); + // its handled different in kmpg + // we close the stream if the decoder signals eof. + return true; + +} + + +long ftell_func2 (void *stream) { + GETINPUT(stream,input); + return input->getBytePosition(); +} + + + + +VorbisInfo::VorbisInfo(FileAccess* input) { + this->input=input; + vf=new OggVorbis_File(); + + ov_callbacks callbacks; + + callbacks.read_func = fread_func2; + callbacks.seek_func = fseek_func2; + callbacks.close_func = fclose_func2; + callbacks.tell_func = ftell_func2; + + if(ov_open_callbacks(this, vf, NULL, 0, callbacks) < 0) { + cout << "error ov_open_callbacks"<<endl; + } + + // now init stream + vi=ov_info(vf,-1); + lastSeekPos=0; +} + + +VorbisInfo::~VorbisInfo() { + delete vf; + if (vi != NULL) { + //? + } +} + + +long VorbisInfo::getSeekPosition(int seconds) { + int back=0; + if (vi != NULL) { + lastSeekPos=0; + ov_time_seek(vf,seconds); + back=lastSeekPos; + } + return back; +} + + +long VorbisInfo::getLength() { + int back=0; + if (vi != NULL) { + back = (int) ov_time_total(vf, -1); + } + return back; +} + + + + +void VorbisInfo::print(const char* msg) { + cout << "VorbisInfo:"<<msg<<endl; + cout << "Length (sec):"<<getLength()<<endl; + +} + + +void VorbisInfo::setSeekPos(long pos) { + this->lastSeekPos=pos; +} + + +long VorbisInfo::getSeekPos() { + return lastSeekPos; +} + +FileAccess* VorbisInfo::getInput() { + return input; +} + + + +#endif diff --git a/mpeglib/lib/oggvorbis/vorbisInfo.h b/mpeglib/lib/oggvorbis/vorbisInfo.h new file mode 100644 index 00000000..70c1dc8a --- /dev/null +++ b/mpeglib/lib/oggvorbis/vorbisInfo.h @@ -0,0 +1,76 @@ +/* + info about vorbis files. + 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 __VORBISINFO_H +#define __VORBISINFO_H + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifdef OGG_VORBIS + +#include <vorbis/codec.h> +#include <vorbis/vorbisfile.h> +#include "../util/file/fileAccess.h" + +/** + callbacks from vorbisfile +*/ +extern "C" { + +extern size_t fread_func2 (void *ptr,size_t size,size_t nmemb, void *stream); +extern int fseek_func2 (void *stream, ogg_int64_t offset, int whence); +extern int fclose_func2 (void *stream); +extern long ftell_func2 (void *stream); + +} + + + +class VorbisInfo { + + FileAccess* input; + OggVorbis_File* vf; + vorbis_info *vi; + + long lastSeekPos; + + public: + VorbisInfo(FileAccess* input); + ~VorbisInfo(); + + // returns byte positions + long getSeekPosition(int second); + // returns length in seconds + long getLength(); + + void print(const char* msg); + + void setSeekPos(long pos); + long getSeekPos(); + + FileAccess* getInput(); + + +}; + +#endif + +#endif |