1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/*
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 <http://www.gnu.org/licenses/>.
*/
#ifndef _INPUT_H_
#define _INPUT_H_
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdexcept>
#include <vector>
#include <list>
#include <string>
#include <stdint.h>
class InputBase {
public:
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) = 0;
virtual int Close() = 0;
//virtual int Clean() = 0; // TODO destructor
};
enum BufferState
{
PREBUFFERING = 0,
RUNNING
};
class InputBuffered {
protected:
InputBuffered(int prebuffer_stages, int source_size,
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) = 0;
// Must return a string with a name, used for logging
virtual const char* GetName() = 0;
virtual bool FillBuffer();
private:
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;
};
/********************************************/
/** 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 : 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
};
#ifdef HAVE_FORMAT_MPEG
class InputMpegFile : public InputFile, public InputBuffered {
public:
InputMpegFile(std::string fileName,
int prebuffer_stages,
int frame_size,
int overfull_thresh) :
InputFile(fileName),
InputBuffered(prebuffer_stages, frame_size, overfull_thresh, 1)
{ m_name = "mpeg " + m_filename;}
int ReadFrame(void* buffer, int size);
const char* GetName() { return m_name.c_str(); }
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, 5)
{ m_name = "dabplus " + m_filename;}
int ReadFrame(void* buffer, int size);
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);
std::vector<uint8_t> buffer;
size_t bufferIndex;
};
#endif
#endif // INPUT_FILE
/********************************************/
/** TEST INPUT ***********************/
/********************************************/
#if 0
// 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
#endif
|