diff options
Diffstat (limited to 'src/inputs/Input.h')
-rw-r--r-- | src/inputs/Input.h | 111 |
1 files changed, 79 insertions, 32 deletions
diff --git a/src/inputs/Input.h b/src/inputs/Input.h index 42c2ef7..a6a7231 100644 --- a/src/inputs/Input.h +++ b/src/inputs/Input.h @@ -31,6 +31,7 @@ #endif #include <vector> +#include <list> #include <string> #include <stdint.h> @@ -38,41 +39,53 @@ class InputBase { public: virtual int Open(); - virtual int Lock(); // TODO get rid of lock/unlock - virtual int Unlock(); + + // 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 // <size> bytes. virtual int ReadFrame(void* buffer, int size); - // TODO: ehm, where do we need this ? - virtual int SetBitrate(int bitrate); - virtual int Close(); virtual int Clean(); // TODO destructor }; -/********************************************/ -/** TEST INPUT ***********************/ -/********************************************/ +enum BufferState +{ + PREBUFFERING = 0, + RUNNING +}; -// Implement mostly everything, but don't do anything -class InputTest : InputBase { +class InputBuffered : public InputBase { public: - InputTest() : counter(0) {} - int Open(); - int Lock(); - int Unlock(); - int ReadFrame(void* buffer, int size); - int SetBitrate(int bitrate); - int Close(); - int Clean(); + 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: - unsigned long counter; -}; + InputBuffered() {}; + int m_source_size; + int m_prebuffer_count; + int m_prebuffer_stages; + int m_overfull_thresh; + BufferState m_bufferstate; + + std::list< std::vector<char> > m_buffer; +}; /********************************************/ /** FILE INPUTS ***********************/ @@ -84,39 +97,73 @@ class InputTest : InputBase { // for Fifo, and also for different file types. class InputFile : InputBase { public: - InputFile(std::string fileName) : filename(fileName) {} - int Open(); - int Close(); - int Rewind(); + InputFile(std::string fileName) : m_filename(fileName) {} + virtual int Open(); + virtual int Close(); + virtual int Rewind(); protected: - long ReadData(void* data, size_t size, unsigned int tries); - std::string filename; + std::string m_filename; int file; // the file descriptor }; #ifdef HAVE_FORMAT_MPEG -class InputMpegFile : InputFile { +class InputMpegFile : public InputFile, public InputBuffered { public: - InputMpegFile(std::string fileName) : filename(fileName) {} + 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 : InputFile { +class InputDabplusFile : public InputFile, public InputBuffered { public: - InputMpegFile(std::string fileName) : filename(fileName) {} + 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: - int Read(void* buffer, int size); + std::string m_name; + int ReadSuperFrame(void* buffer, int size); + int ReadSource(void* buffer, int size); std::vector<uint8_t> buffer; size_t bufferIndex; }; #endif -#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 |