aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputs/Input.h
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2013-12-22 16:11:43 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2013-12-24 18:09:27 +0100
commitb0183733ef4c6f08ef8c7b73155268e54ca3f152 (patch)
tree5aa855d5dc36badbf1b2268bef79db0257146853 /src/inputs/Input.h
parent7094945ef7ecb8a918dfe3b4619bdc6f239cbb50 (diff)
downloaddabmux-b0183733ef4c6f08ef8c7b73155268e54ca3f152.tar.gz
dabmux-b0183733ef4c6f08ef8c7b73155268e54ca3f152.tar.bz2
dabmux-b0183733ef4c6f08ef8c7b73155268e54ca3f152.zip
InputBuffered know how to split frames
Diffstat (limited to 'src/inputs/Input.h')
-rw-r--r--src/inputs/Input.h53
1 files changed, 32 insertions, 21 deletions
diff --git a/src/inputs/Input.h b/src/inputs/Input.h
index a6a7231..fe54160 100644
--- a/src/inputs/Input.h
+++ b/src/inputs/Input.h
@@ -30,6 +30,7 @@
# include "config.h"
#endif
+#include <stdexcept>
#include <vector>
#include <list>
#include <string>
@@ -38,18 +39,15 @@
class InputBase {
public:
- virtual int Open();
-
- // Must return a string with a name, used for logging
- virtual const char* GetName();
+ virtual int Open() = 0;
// 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);
+ virtual int ReadFrame(void* buffer, int size) = 0;
- virtual int Close();
- virtual int Clean(); // TODO destructor
+ virtual int Close() = 0;
+ //virtual int Clean() = 0; // TODO destructor
};
enum BufferState
@@ -58,30 +56,38 @@ enum BufferState
RUNNING
};
-class InputBuffered : public InputBase {
- public:
- virtual int ReadFrame(void* buffer, int size);
+class InputBuffered {
protected:
InputBuffered(int prebuffer_stages, int source_size,
- int overfull_thresh) :
+ int overfull_thresh, unsigned int frame_split) :
m_source_size(source_size),
+ m_prebuffer_count(prebuffer_stages),
m_prebuffer_stages(prebuffer_stages),
m_overfull_thresh(overfull_thresh),
+ m_framesplit(frame_split),
m_bufferstate(PREBUFFERING)
- { } ;
+ {
+ if (source_size % frame_split != 0) {
+ throw invalid_argument("Incorrect source size asked: ");
+ }
+ };
+
+ virtual int ReadFrameFromBuffer(void* buffer, int size);
// Reads a frame from the source, into the buffer
- virtual int ReadSource(void* buffer, int size);
+ virtual int ReadSource(void* buffer, int size) = 0;
+
+ // Must return a string with a name, used for logging
+ virtual const char* GetName() = 0;
virtual bool FillBuffer();
private:
- InputBuffered() {};
-
int m_source_size;
int m_prebuffer_count;
int m_prebuffer_stages;
int m_overfull_thresh;
+ unsigned int m_framesplit;
BufferState m_bufferstate;
std::list< std::vector<char> > m_buffer;
@@ -95,12 +101,15 @@ class InputBuffered : public InputBase {
// The InputFile is not used directly but defines some behaviour
// for Fifo, and also for different file types.
-class InputFile : InputBase {
+class InputFile : public InputBase {
public:
InputFile(std::string fileName) : m_filename(fileName) {}
virtual int Open();
virtual int Close();
virtual int Rewind();
+
+ int ReadFrame(void* buffer, int size) { return ReadData(buffer, size, 10); };
+ long ReadData(void* data, size_t size, unsigned int tries);
protected:
std::string m_filename;
int file; // the file descriptor
@@ -111,10 +120,10 @@ class InputMpegFile : public InputFile, public InputBuffered {
public:
InputMpegFile(std::string fileName) :
InputFile(fileName),
- InputBuffered(prebuffer_stages, source_size, overfull_thresh)
+ InputBuffered(prebuffer_stages, source_size, overfull_thresh, 1)
{ m_name = "mpeg " + m_filename;}
int ReadFrame(void* buffer, int size);
- const char* GetName();
+ const char* GetName() { return m_name.c_str(); }
private:
std::string m_name;
int ReadSource(void* buffer, int size);
@@ -131,14 +140,14 @@ class InputDabplusFile : public InputFile, public InputBuffered {
int frame_size,
int overfull_thresh) :
InputFile(fileName),
- InputBuffered(prebuffer_stages, frame_size, overfull_thresh)
+ InputBuffered(prebuffer_stages, frame_size, overfull_thresh, 5)
{ m_name = "dabplus " + m_filename;}
int ReadFrame(void* buffer, int size);
- const char* GetName();
+ const char* GetName() { return m_name.c_str(); }
private:
+ int ReadSource(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;
};
@@ -151,6 +160,7 @@ class InputDabplusFile : public InputFile, public InputBuffered {
/** TEST INPUT ***********************/
/********************************************/
+#if 0
// Implement mostly everything, but don't do anything
class InputTest : InputBase {
public:
@@ -164,6 +174,7 @@ class InputTest : InputBase {
private:
unsigned long counter;
};
+#endif
#endif