/* 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 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"<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"<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"<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<set(NULL,0,0); buffer_info->set(outptr,size,0); }