summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2022-08-24 14:09:59 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2022-08-24 14:09:59 +0200
commit691708e7fd4929e5d0835978e9a652e118c641f1 (patch)
tree47aac8621b0475a69080fa53f3c07132998db23f
parent210336e55efa9ccc6295f8767935570532e80a41 (diff)
downloaddabmux-691708e7fd4929e5d0835978e9a652e118c641f1.tar.gz
dabmux-691708e7fd4929e5d0835978e9a652e118c641f1.tar.bz2
dabmux-691708e7fd4929e5d0835978e9a652e118c641f1.zip
Support reading mux config in JSON
-rw-r--r--README.md2
-rw-r--r--doc/example.json94
-rw-r--r--doc/example.mux3
-rw-r--r--src/DabMux.cpp36
-rw-r--r--src/utils.cpp5
-rw-r--r--src/utils.h1
6 files changed, 124 insertions, 17 deletions
diff --git a/README.md b/README.md
index 830d76f..49ef277 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ ODR-mmbTools is available in the *guide*, available on the
Features of ODR-DabMux:
- Standards-compliant DAB multiplexer
-- Configuration file, see doc/example.mux
+- Configuration file, see doc/example.mux and doc/example.json
- Timestamping support required for SFN
- Logging to syslog
- Monitoring using munin tool
diff --git a/doc/example.json b/doc/example.json
new file mode 100644
index 0000000..6d543b6
--- /dev/null
+++ b/doc/example.json
@@ -0,0 +1,94 @@
+{
+ "_comment": "This is the same as example.mux, but in JSON format. JSON doesn't really support comments, so please refer to the example.mux and advanced.mux for documentation of the settings",
+ "general": {
+ "dabmode": 1,
+ "nbframes": 0,
+ "syslog": false,
+ "tist": false,
+ "tist_offset": 0,
+ "managementport": 12720
+ },
+ "remotecontrol": {
+ "telnetport": 12721,
+ "zmqendpoint": "tcp://lo:12722"
+ },
+ "ensemble": {
+ "id": "0x4fff",
+ "ecc": "0xe1",
+ "local-time-offset": "auto",
+ "reconfig-counter": "hash",
+ "label": "OpenDigitalRadio",
+ "shortlabel": "ODR"
+ },
+ "services": {
+ "srv-fu": {
+ "id": "0x4daa",
+ "label": "Fünk"
+ },
+ "srv-ri": {
+ "id": "0x5dab",
+ "ecc": "0xe0",
+ "label": "Rick"
+ }
+ },
+ "subchannels": {
+ "sub-fu": {
+ "type": "audio",
+ "bitrate": 128,
+ "id": 10,
+ "protection": 3,
+ "inputfile": "funk.mp2"
+ },
+ "sub-bla": {
+ "type": "audio",
+ "bitrate": 96,
+ "id": 1,
+ "protection": 1,
+
+ "inputproto": "edi",
+ "inputuri": "tcp://0.0.0.0:9001",
+ "buffer-management": "prebuffering",
+ "buffer": 40,
+ "prebuffering": 20
+ },
+ "sub-ri": {
+ "type": "dabplus",
+ "bitrate": 96,
+ "id": 1,
+ "protection": 3,
+
+ "inputproto": "edi",
+ "inputuri": "tcp://127.0.0.1:9000",
+ "buffer-management": "timestamped",
+
+ "buffer": 500,
+ "tist-delay": 10
+ }
+ },
+ "components": {
+ "comp-fu": {
+ "service": "srv-fu",
+ "subchannel": "sub-fu"
+ },
+ "comp-ri": {
+ "service": "srv-ri",
+ "subchannel": "sub-ri",
+
+ "user-applications": {
+ "userapp": "slideshow"
+ }
+ }
+ },
+ "outputs": {
+ "throttle": "simul://",
+ "stdout": "fifo:///dev/stdout?type=raw",
+ "edi": {
+ "destinations": {
+ "example_tcp": {
+ "protocol": "tcp",
+ "listenport": 13000
+ }
+ }
+ }
+ }
+}
diff --git a/doc/example.mux b/doc/example.mux
index 03fb3f0..9a5686b 100644
--- a/doc/example.mux
+++ b/doc/example.mux
@@ -3,6 +3,9 @@
; It doesn't show all possible options. A more detailed example
; is available in doc/advanced.mux
;
+; The configuration file can also be given in JSON format, an
+; example is given in doc/example.json
+;
; It contains two services, one DAB and one DAB+, and also shows
; both the file input useful for offline processing, and the
; EDI input useful in a 24/7 scenario.
diff --git a/src/DabMux.cpp b/src/DabMux.cpp
index f6a69bb..1a367da 100644
--- a/src/DabMux.cpp
+++ b/src/DabMux.cpp
@@ -33,6 +33,7 @@
#include <memory>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
+#include <boost/property_tree/json_parser.hpp>
#include <cstdio>
#include <iostream>
#include <fstream>
@@ -200,40 +201,29 @@ int main(int argc, char *argv[])
}
#endif
-
-
-
int returnCode = 0;
-
ptree pt;
std::vector<std::shared_ptr<DabOutput> > outputs;
try {
+ string conf_file = "";
+
if (argc == 2) { // Assume the only argument is a config file
- string conf_file = argv[1];
+ conf_file = argv[1];
if (conf_file == "-h") {
printUsage(argv[0], stdout);
throw MuxInitException("Nothing to do");
}
-
- try {
- read_info(conf_file, pt);
-
- }
- catch (runtime_error &e) {
- throw MuxInitException(e.what());
- }
}
else if (argc > 1 && strncmp(argv[1], "-e", 2) == 0) { // use external config file
try {
-
if (argc != 3) {
printUsage(argv[0], stderr);
throw MuxInitException();
}
- string conf_file = argv[2];
+ conf_file = argv[2];
read_info(conf_file, pt);
}
@@ -241,10 +231,24 @@ int main(int argc, char *argv[])
throw MuxInitException(e.what());
}
}
- else {
+
+ if (conf_file.empty()) {
+ printUsage(argv[0], stderr);
throw MuxInitException("No configuration file specified");
}
+ try {
+ if (stringEndsWith(conf_file, ".json")) {
+ read_json(conf_file, pt);
+ }
+ else {
+ read_info(conf_file, pt);
+ }
+ }
+ catch (runtime_error &e) {
+ throw MuxInitException(e.what());
+ }
+
/* Enable Logging to syslog conditionally */
if (pt.get<bool>("general.syslog", false)) {
etiLog.register_backend(std::make_shared<LogToSyslog>());
diff --git a/src/utils.cpp b/src/utils.cpp
index 71e2b5c..c9a2714 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -599,3 +599,8 @@ long hexparse(const std::string& input)
return value;
}
+bool stringEndsWith(const std::string& fullString, const std::string& ending)
+{
+ return fullString.length() >= ending.length() and
+ fullString.compare(fullString.length() - ending.length(), ending.length(), ending) == 0;
+}
diff --git a/src/utils.h b/src/utils.h
index cf64c69..b844676 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -75,3 +75,4 @@ void printSubchannels(const vec_sp_subchannel& subchannels);
long hexparse(const std::string& input);
+bool stringEndsWith(std::string const &fullString, std::string const &ending);