aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputs/Input.h
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2013-12-21 17:46:41 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2013-12-24 18:09:26 +0100
commit211d6a06ab5a286c623d2dce901115dec316a31d (patch)
tree40e60dc7b47aeea21292dec2748d4fc72663f5d0 /src/inputs/Input.h
parentabec4838d2536812a4fe382334a1c9f500f7728b (diff)
downloaddabmux-211d6a06ab5a286c623d2dce901115dec316a31d.tar.gz
dabmux-211d6a06ab5a286c623d2dce901115dec316a31d.tar.bz2
dabmux-211d6a06ab5a286c623d2dce901115dec316a31d.zip
Add InputBuffered
Diffstat (limited to 'src/inputs/Input.h')
-rw-r--r--src/inputs/Input.h111
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