/* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Her Majesty the Queen in Right of Canada (Communications Research Center Canada) Copyright (C) 2013 Matthias P. Braendli http://mpb.li */ /* This file is part of CRC-DabMux. CRC-DabMux is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. CRC-DabMux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with CRC-DabMux. If not, see . */ #ifndef _INPUT_H_ #define _INPUT_H_ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include class InputBase { public: virtual int Open(); // Must return a string with a name, used for logging virtual const char* GetName(); // ReadFrame must return exactly the right number of bytes // for the format, which means it must fill the buffer to // bytes. virtual int ReadFrame(void* buffer, int size); virtual int Close(); virtual int Clean(); // TODO destructor }; enum BufferState { PREBUFFERING = 0, RUNNING }; class InputBuffered : public InputBase { public: virtual int ReadFrame(void* buffer, int size); protected: InputBuffered(int prebuffer_stages, int source_size, int overfull_thresh) : m_source_size(source_size), m_prebuffer_stages(prebuffer_stages), m_overfull_thresh(overfull_thresh), m_bufferstate(PREBUFFERING) { } ; // Reads a frame from the source, into the buffer virtual int ReadSource(void* buffer, int size); virtual bool FillBuffer(); private: InputBuffered() {}; int m_source_size; int m_prebuffer_count; int m_prebuffer_stages; int m_overfull_thresh; BufferState m_bufferstate; std::list< std::vector > m_buffer; }; /********************************************/ /** FILE INPUTS ***********************/ /********************************************/ #ifdef HAVE_INPUT_FILE // The InputFile is not used directly but defines some behaviour // for Fifo, and also for different file types. class InputFile : InputBase { public: InputFile(std::string fileName) : m_filename(fileName) {} virtual int Open(); virtual int Close(); virtual int Rewind(); protected: std::string m_filename; int file; // the file descriptor }; #ifdef HAVE_FORMAT_MPEG class InputMpegFile : public InputFile, public InputBuffered { public: InputMpegFile(std::string fileName) : InputFile(fileName), InputBuffered(prebuffer_stages, source_size, overfull_thresh) { m_name = "mpeg " + m_filename;} int ReadFrame(void* buffer, int size); const char* GetName(); private: std::string m_name; int ReadSource(void* buffer, int size); bool parity; }; #endif // HAVE_FORMAT_MPEG #ifdef HAVE_FORMAT_DABPLUS class InputDabplusFile : public InputFile, public InputBuffered { public: InputDabplusFile( std::string fileName, int prebuffer_stages, int frame_size, int overfull_thresh) : InputFile(fileName), InputBuffered(prebuffer_stages, frame_size, overfull_thresh) { m_name = "dabplus " + m_filename;} int ReadFrame(void* buffer, int size); const char* GetName(); private: std::string m_name; int ReadSuperFrame(void* buffer, int size); int ReadSource(void* buffer, int size); std::vector buffer; size_t bufferIndex; }; #endif #endif // INPUT_FILE /********************************************/ /** TEST INPUT ***********************/ /********************************************/ // Implement mostly everything, but don't do anything class InputTest : InputBase { public: InputTest() : counter(0) {} int Open(); int ReadFrame(void* buffer, int size); const char* GetName(); int Close(); int Clean(); private: unsigned long counter; }; #endif