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
184
185
186
187
188
189
190
191
192
193
|
/*
Copyright (C) 2009 Her Majesty the Queen in Right of Canada (Communications
Research Center Canada)
Copyright (C) 2013, 2014 Matthias P. Braendli
http://www.opendigitalradio.org
ZeroMQ input. see www.zeromq.org for more info
For the AAC+ input, each zeromq message must contain one superframe.
For the MPEG input, each zeromq message must contain one frame.
Encryption is provided by zmq_curve, see the corresponding manpage.
From the ZeroMQ manpage 'zmq':
The 0MQ lightweight messaging kernel is a library which extends the standard
socket interfaces with features traditionally provided by specialised
messaging middleware products. 0MQ sockets provide an abstraction of
asynchronous message queues, multiple messaging patterns, message filtering
(subscriptions), seamless access to multiple transport protocols and more.
*/
/*
This file is part of ODR-DabMux.
It defines a ZeroMQ input for dabplus data.
ODR-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.
ODR-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 ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DAB_INPUT_ZMQ_H
#define DAB_INPUT_ZMQ_H
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_INPUT_ZEROMQ
#include <list>
#include <string>
#include "zmq.hpp"
#include "dabInput.h"
#include "StatsServer.h"
/* The frame_buffer contains DAB logical frames as defined in
* TS 102 563, section 6.
* Five elements of this buffer make one AAC superframe (120ms audio)
*/
// Number of elements to prebuffer before starting the pipeline
#define INPUT_ZMQ_DEF_PREBUFFERING (5*4) // 480ms
// Default frame_buffer size in number of elements
#define INPUT_ZMQ_DEF_BUFFER_SIZE (5*8) // 960ms
// Minimum frame_buffer size in number of elements
// This is one AAC superframe, but you probably don't want to
// go that low anyway.
#define INPUT_ZMQ_MIN_BUFFER_SIZE (5*1) // 120ms
// Maximum frame_buffer size in number of elements
// One minute is clearly way over what everybody would
// want.
#define INPUT_ZMQ_MAX_BUFFER_SIZE (5*500) // 60s
struct dab_input_zmq_config_t
{
/* The size of the internal buffer, measured in number
* of elements.
*
* Each element corresponds to five frames,
* or one AAC superframe.
*/
int buffer_size;
/* The amount of prebuffering to do before we start streaming
*
* Same units as buffer_size
*/
int prebuffering;
/* Whether to enforce encryption or not
*/
bool enable_encryption;
/* Full path to file containing public key.
*/
std::string curve_public_keyfile;
/* Full path to file containing secret key.
*/
std::string curve_secret_keyfile;
/* Full path to file containing encoder public key.
*/
std::string curve_encoder_keyfile;
};
class DabInputZmqBase : public DabInputBase, public RemoteControllable {
public:
DabInputZmqBase(const std::string name,
dab_input_zmq_config_t config)
: RemoteControllable(name),
m_zmq_context(1),
m_zmq_sock(m_zmq_context, ZMQ_SUB),
m_bitrate(0),
m_enable_input(true),
m_config(config),
m_prebuf_current(0) {
RC_ADD_PARAMETER(enable,
"If the input is enabled. Set to zero to empty the buffer.");
}
virtual int open(const std::string inputUri);
virtual int readFrame(void* buffer, int size);
virtual int setBitrate(int bitrate);
virtual int close();
/* Remote control */
virtual void set_parameter(const std::string& parameter,
const std::string& value);
/* Getting a parameter always returns a string. */
virtual const std::string get_parameter(const std::string& parameter) const;
protected:
virtual int readFromSocket(size_t framesize) = 0;
zmq::context_t m_zmq_context;
zmq::socket_t m_zmq_sock; // handle for the zmq socket
int m_bitrate;
/* set this to zero to empty the input buffer */
bool m_enable_input;
/* stores elements of type char[<superframesize>] */
std::list<char*> m_frame_buffer;
dab_input_zmq_config_t m_config;
private:
int m_prebuf_current;
};
class DabInputZmqMPEG : public DabInputZmqBase {
public:
DabInputZmqMPEG(const std::string name,
dab_input_zmq_config_t config)
: DabInputZmqBase(name, config) {
RC_ADD_PARAMETER(buffer,
"Size of the input buffer [mpeg frames]");
RC_ADD_PARAMETER(prebuffering,
"Min buffer level before streaming starts [mpeg frames]");
}
private:
virtual int readFromSocket(size_t framesize);
};
class DabInputZmqAAC : public DabInputZmqBase {
public:
DabInputZmqAAC(const std::string name,
dab_input_zmq_config_t config)
: DabInputZmqBase(name, config) {
RC_ADD_PARAMETER(buffer,
"Size of the input buffer [aac superframes]");
RC_ADD_PARAMETER(prebuffering,
"Min buffer level before streaming starts [aac superframes]");
}
private:
virtual int readFromSocket(size_t framesize);
};
#endif // HAVE_INPUT_ZMQ
#endif // DAB_INPUT_ZMQ_H
|