diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-03-02 20:48:21 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-03-02 20:48:21 +0100 |
commit | 43635f1d8a96c9711d7004d9bf6114eedb8e6ccd (patch) | |
tree | 46b4ac99b84e2e9786a0337247d81dea49190d1b /src | |
parent | 5eb2814a6758a58f4f657e7f5b4957f92a2066b7 (diff) | |
download | dabmux-43635f1d8a96c9711d7004d9bf6114eedb8e6ccd.tar.gz dabmux-43635f1d8a96c9711d7004d9bf6114eedb8e6ccd.tar.bz2 dabmux-43635f1d8a96c9711d7004d9bf6114eedb8e6ccd.zip |
Remove char* from dabSubchannel
Diffstat (limited to 'src')
-rw-r--r-- | src/DabMux.cpp | 19 | ||||
-rw-r--r-- | src/MuxElements.h | 3 | ||||
-rw-r--r-- | src/ParserCmdline.cpp | 6 | ||||
-rw-r--r-- | src/ParserCmdline.h | 10 | ||||
-rw-r--r-- | src/ParserConfigfile.cpp | 159 | ||||
-rw-r--r-- | src/utils.cpp | 56 |
6 files changed, 133 insertions, 120 deletions
diff --git a/src/DabMux.cpp b/src/DabMux.cpp index 1597a9b..d0ec502 100644 --- a/src/DabMux.cpp +++ b/src/DabMux.cpp @@ -369,6 +369,7 @@ int main(int argc, char *argv[]) throw MuxInitException(); } } +#if ENABLE_CMDLINE_OPTIONS else if (argc > 1 && strncmp(argv[1], "-e", 2) == 0) { // use external config file try { @@ -395,6 +396,12 @@ int main(int argc, char *argv[]) throw MuxInitException(); } } +#else + else { + etiLog.level(error) << "You must specify the configuration file"; + throw MuxInitException(); + } +#endif if (statsserverport != 0) { global_stats = new StatsServer(statsserverport); @@ -555,7 +562,7 @@ int main(int argc, char *argv[]) (*output)->output = new DabOutputZMQ("epgm"); #endif // defined(HAVE_OUTPUT_ZEROMQ) } else { - etiLog.log(error, "Output protcol unknown: %s\n", + etiLog.log(error, "Output protocol unknown: %s\n", (*output)->outputProto.c_str()); throw MuxInitException(); } @@ -584,8 +591,8 @@ int main(int argc, char *argv[]) (*subchannel)->startAddress = (*(subchannel - 1))->startAddress + getSizeCu(*(subchannel - 1)); } - if ((*subchannel)->input->open((*subchannel)->inputName) == -1) { - perror((*subchannel)->inputName); + if ((*subchannel)->input->open((*subchannel)->inputUri) == -1) { + perror((*subchannel)->inputUri.c_str()); returnCode = -1; throw MuxInitException(); } @@ -593,8 +600,8 @@ int main(int argc, char *argv[]) // TODO Check errors int subch_bitrate = (*subchannel)->input->setBitrate( (*subchannel)->bitrate); if (subch_bitrate <= 0) { - etiLog.log(error, "can't set bitrate for source %s\n", - (*subchannel)->inputName); + etiLog.level(error) << "can't set bitrate for source " << + (*subchannel)->inputUri; returnCode = -1; throw MuxInitException(); } @@ -626,7 +633,7 @@ int main(int argc, char *argv[]) subch_bitrate % 32 != 0 ) { etiLog.level(error) << "Cannot use EEP_B protection for subchannel " << - (*subchannel)->inputName << + (*subchannel)->inputUri << ": bitrate not multiple of 32kbit/s"; returnCode = -1; throw MuxInitException(); diff --git a/src/MuxElements.h b/src/MuxElements.h index a061bc6..3653ea4 100644 --- a/src/MuxElements.h +++ b/src/MuxElements.h @@ -167,8 +167,7 @@ enum dab_subchannel_type_t { }; struct dabSubchannel { - const char* inputProto; - const char* inputName; + std::string inputUri; DabInputBase* input; unsigned char id; dab_subchannel_type_t type; diff --git a/src/ParserCmdline.cpp b/src/ParserCmdline.cpp index 6dcee55..6de319b 100644 --- a/src/ParserCmdline.cpp +++ b/src/ParserCmdline.cpp @@ -27,9 +27,7 @@ */ #include "ParserCmdline.h" -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#if ENABLE_CMDLINE_OPTIONS #include <vector> #include <stdint.h> @@ -773,3 +771,5 @@ EXIT: return false; } +#endif // ENABLE_CMDLINE_OPTIONS + diff --git a/src/ParserCmdline.h b/src/ParserCmdline.h index fc12490..1c4545b 100644 --- a/src/ParserCmdline.h +++ b/src/ParserCmdline.h @@ -28,9 +28,17 @@ #ifndef _PARSER_CMDLINE #define _PARSER_CMDLINE +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include <vector> #include "MuxElements.h" +#define ENABLE_CMDLINE_OPTIONS 0 + +#if ENABLE_CMDLINE_OPTIONS + bool parse_cmdline(char **argv, int argc, std::vector<dabOutput*> &outputs, @@ -42,3 +50,5 @@ bool parse_cmdline(char **argv, ); #endif + +#endif diff --git a/src/ParserConfigfile.cpp b/src/ParserConfigfile.cpp index 0a76c9f..976bbf1 100644 --- a/src/ParserConfigfile.cpp +++ b/src/ParserConfigfile.cpp @@ -567,24 +567,33 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, throw runtime_error(ss.str()); } - string inputfile = ""; - // fail if no inputfile given unless type is test + string inputUri = ""; + // fail if no inputUri given unless type is test if (type != "test") { - try { - inputfile = pt.get<string>("inputfile"); - } - catch (ptree_error &e) { - stringstream ss; - ss << "Subchannel with uid " << subchanuid << " has no type defined!"; - throw runtime_error(ss.str()); + inputUri = pt.get<string>("inputuri", ""); + + if (inputUri == "") { + try { + inputUri = pt.get<string>("inputfile"); + } + catch (ptree_error &e) { + stringstream ss; + ss << "Subchannel with uid " << subchanuid << " has no inputUri defined!"; + throw runtime_error(ss.str()); + } } } - char* inputName = new char[512]; - memset(inputName, 0, 512); - inputfile.copy(inputName, 511); + string proto; + size_t protopos = inputUri.find("://"); + if (protopos == string::npos) { + proto = "file"; + } + else { + proto = inputUri.substr(0, protopos); + } - subchan->inputName = inputName; + subchan->inputUri = inputUri; /* The input is of the old_style type, * with the struct of function pointers, @@ -594,37 +603,23 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, dabInputOperations operations; dabProtection* protection = &subchan->protection; + if (0) { #if defined(HAVE_FORMAT_MPEG) } else if (type == "audio") { subchan->type = Audio; subchan->bitrate = 0; - char* proto; - - char* full_inputName = new char[256]; - full_inputName[255] = '\0'; - memcpy(full_inputName, inputName, 255); - - proto = strstr(inputName, "://"); - if (proto == NULL) { - subchan->inputProto = "file"; - } else { - subchan->inputProto = inputName; - subchan->inputName = proto + 3; - *proto = 0; - } - if (0) { #if defined(HAVE_INPUT_FILE) - } else if (strcmp(subchan->inputProto, "file") == 0) { + } else if (proto == "file") { operations = dabInputMpegFileOperations; #endif // defined(HAVE_INPUT_FILE) #if defined(HAVE_INPUT_ZEROMQ) } - else if ((strcmp(subchan->inputProto, "tcp") == 0) || - (strcmp(subchan->inputProto, "epmg") == 0) || - (strcmp(subchan->inputProto, "ipc") == 0) ) { + else if (proto == "tcp" || + proto == "epmg" || + proto == "ipc") { input_is_old_style = false; dab_input_zmq_config_t zmqconfig; @@ -653,12 +648,11 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, new DabInputZmqMPEG(subchanuid, zmqconfig); inzmq->enrol_at(*rc); subchan->input = inzmq; - subchan->inputName = full_inputName; - if (strcmp(subchan->inputProto, "epmg") == 0) { + if (proto == "epmg") { etiLog.level(warn) << "Using untested epmg:// zeromq input"; } - else if (strcmp(subchan->inputProto, "ipc") == 0) { + else if (proto == "ipc") { etiLog.level(warn) << "Using untested ipc:// zeromq input"; } #endif // defined(HAVE_INPUT_ZEROMQ) @@ -666,7 +660,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, stringstream ss; ss << "Subchannel with uid " << subchanuid << ": Invalid protocol for MPEG input (" << - subchan->inputProto << ")" << endl; + proto << ")" << endl; throw runtime_error(ss.str()); } #endif // defined(HAVE_INPUT_FILE) && defined(HAVE_FORMAT_MPEG) @@ -675,31 +669,16 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, subchan->type = Audio; subchan->bitrate = 32; - char* proto; - - char* full_inputName = new char[256]; - full_inputName[255] = '\0'; - memcpy(full_inputName, inputName, 255); - - proto = strstr(inputName, "://"); - if (proto == NULL) { - subchan->inputProto = "file"; - } else { - subchan->inputProto = inputName; - subchan->inputName = proto + 3; - *proto = 0; - } - if (0) { #if defined(HAVE_INPUT_FILE) - } else if (strcmp(subchan->inputProto, "file") == 0) { + } else if (proto == "file") { operations = dabInputDabplusFileOperations; #endif // defined(HAVE_INPUT_FILE) #if defined(HAVE_INPUT_ZEROMQ) } - else if ((strcmp(subchan->inputProto, "tcp") == 0) || - (strcmp(subchan->inputProto, "epmg") == 0) || - (strcmp(subchan->inputProto, "ipc") == 0) ) { + else if (proto == "tcp" || + proto == "epmg" || + proto == "ipc") { input_is_old_style = false; dab_input_zmq_config_t zmqconfig; @@ -735,12 +714,11 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, inzmq->enrol_at(*rc); subchan->input = inzmq; - subchan->inputName = full_inputName; - if (strcmp(subchan->inputProto, "epmg") == 0) { + if (proto == "epmg") { etiLog.level(warn) << "Using untested epmg:// zeromq input"; } - else if (strcmp(subchan->inputProto, "ipc") == 0) { + else if (proto == "ipc") { etiLog.level(warn) << "Using untested ipc:// zeromq input"; } #endif // defined(HAVE_INPUT_ZEROMQ) @@ -748,64 +726,46 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, stringstream ss; ss << "Subchannel with uid " << subchanuid << ": Invalid protocol for DAB+ input (" << - subchan->inputProto << ")" << endl; + proto << ")" << endl; throw runtime_error(ss.str()); } #endif // defined(HAVE_FORMAT_DABPLUS) } else if (type == "bridge") { - char* proto; - - proto = strstr(inputName, "://"); - if (proto == NULL) { - subchan->inputProto = "udp"; - } else { - subchan->inputProto = inputName; - subchan->inputName = proto + 3; - *proto = 0; - } + // TODO default proto should be udp:// if (0) { #if defined(HAVE_FORMAT_BRIDGE) #if defined(HAVE_INPUT_UDP) - } else if (strcmp(subchan->inputProto, "udp") == 0) { + } else if (proto == "udp") { operations = dabInputBridgeUdpOperations; #endif // defined(HAVE_INPUT_UDP) #if defined(HAVE_INPUT_SLIP) - } else if (strcmp(subchan->inputProto, "slip") == 0) { + } else if (proto == "slip") { operations = dabInputSlipOperations; #endif // defined(HAVE_INPUT_SLIP) #endif // defined(HAVE_FORMAT_BRIDGE) } } else if (type == "data") { - char* proto; - - proto = strstr(inputName, "://"); - if (proto == NULL) { - subchan->inputProto = "udp"; - } else { - subchan->inputProto = inputName; - subchan->inputName = proto + 3; - *proto = 0; - } + // TODO default proto should be udp:// if (0) { #if defined(HAVE_INPUT_UDP) - } else if (strcmp(subchan->inputProto, "udp") == 0) { + } else if (proto == "udp") { operations = dabInputUdpOperations; #endif #if defined(HAVE_INPUT_PRBS) && defined(HAVE_FORMAT_RAW) - } else if (strcmp(subchan->inputProto, "prbs") == 0) { + } else if (proto == "prbs") { operations = dabInputPrbsOperations; #endif #if defined(HAVE_INPUT_FILE) && defined(HAVE_FORMAT_RAW) - } else if (strcmp(subchan->inputProto, "file") == 0) { + } else if (proto == "file") { operations = dabInputRawFileOperations; #endif - } else if (strcmp(subchan->inputProto, "fifo") == 0) { + } else if (proto == "fifo") { operations = dabInputRawFifoOperations; } else { stringstream ss; ss << "Subchannel with uid " << subchanuid << ": Invalid protocol for data input (" << - subchan->inputProto << ")" << endl; + proto << ")" << endl; throw runtime_error(ss.str()); } @@ -813,14 +773,12 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, subchan->bitrate = DEFAULT_DATA_BITRATE; #if defined(HAVE_INPUT_TEST) && defined(HAVE_FORMAT_RAW) } else if (type == "test") { - subchan->inputProto = "test"; subchan->type = DataDmb; subchan->bitrate = DEFAULT_DATA_BITRATE; operations = dabInputTestOperations; #endif // defined(HAVE_INPUT_TEST)) && defined(HAVE_FORMAT_RAW) #ifdef HAVE_FORMAT_PACKET } else if (type == "packet") { - subchan->inputProto = "file"; subchan->type = Packet; subchan->bitrate = DEFAULT_PACKET_BITRATE; #ifdef HAVE_INPUT_FILE @@ -828,11 +786,10 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, #elif defined(HAVE_INPUT_FIFO) operations = dabInputFifoOperations; #else -# pragma error("Must defined at least one packet input") +# pragma error("Must define at least one packet input") #endif // defined(HAVE_INPUT_FILE) #ifdef HAVE_FORMAT_EPM } else if (type == "enhancedpacked") { - subchan->inputProto = "file"; subchan->type = Packet; subchan->bitrate = DEFAULT_PACKET_BITRATE; operations = dabInputEnhancedPacketFileOperations; @@ -840,25 +797,19 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, #endif // defined(HAVE_FORMAT_PACKET) #ifdef HAVE_FORMAT_DMB } else if (type == "dmb") { - char* proto; - - proto = strstr(inputName, "://"); - if (proto == NULL) { - subchan->inputProto = "udp"; - } else { - subchan->inputProto = inputName; - subchan->inputName = proto + 3; - *proto = 0; - } - if (strcmp(subchan->inputProto, "udp") == 0) { + // TODO default proto should be UDP + if (0) { +#if defined(HAVE_INPUT_UDP) + } else if (proto == "udp") { operations = dabInputDmbUdpOperations; - } else if (strcmp(subchan->inputProto, "file") == 0) { +#endif + } else if (proto == "file") { operations = dabInputDmbFileOperations; } else { stringstream ss; ss << "Subchannel with uid " << subchanuid << ": Invalid protocol for DMB input (" << - subchan->inputProto << ")" << endl; + proto << ")" << endl; throw runtime_error(ss.str()); } @@ -917,7 +868,6 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, subchanuid; throw runtime_error(ss.str()); } - subchan->inputProto = "fifo"; break; #endif // defined(HAVE_FORMAT_PACKET) #ifdef HAVE_FORMAT_MPEG @@ -932,7 +882,6 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, subchanuid; throw runtime_error(ss.str()); } - subchan->inputProto = "fifo"; break; #endif // defined(HAVE_FORMAT_MPEG) default: diff --git a/src/utils.cpp b/src/utils.cpp index ab3d75a..7c3c516 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -145,6 +145,7 @@ void header_message() } +#if ENABLE_CMDLINE_OPTIONS void printUsage(char *name, FILE* out) { fprintf(out, "NAME\n"); @@ -300,6 +301,56 @@ void printUsage(char *name, FILE* out) " where scheme is (raw|udp|tcp|file|fifo|simul)\n" ); } +#else // no command line options +void printUsage(char *name, FILE* out) +{ + fprintf(out, "NAME\n"); + fprintf(out, " %s - A software DAB multiplexer\n", name); + fprintf(out, "\nSYNOPSYS\n"); + fprintf(out, " This software requires a configuration file:\n"); + fprintf(out, " %s configuration.mux\n", name); + fprintf(out, " See doc/example.config for an example format for the configuration file\n"); + fprintf(out, "\nDESCRIPTION\n"); + fprintf(out, + " %s is a software multiplexer that generates an ETI stream from\n" + " audio and data streams. Because of its software based architecture,\n" + " many typical DAB services can be generated and multiplexed on a single\n" + " PC platform with live or pre-recorded sources.\n" + "\n" + " A DAB multiplex configuration is composed of one ensemble. An ensemble\n" + " is the entity that receivers tune to and process. An ensemble contains\n" + " several services. A service is the listener-selectable output. Each\n" + " service contains one mandatory service component which is called pri-\n" + " mary component. An audio primary component define a program service\n" + " while a data primary component define a data service. Service can con-\n" + " tain additional components which are called secondary components. Maxi-\n" + " mum total number of components is 12 for program services and 11 for\n" + " data services. A service component is a link to one subchannel (of Fast\n" + " Information Data Channel). A subchannel is the physical space used\n" + " within the common interleaved frame.\n" + "\n" + " __________________________________________________\n" + " | CRC-Ensemble | ENSEMBLE\n" + " |__________________________________________________|\n" + " | | |\n" + " | | |\n" + " _______V______ _______V______ _______V______\n" + " | CRC-Service1 | | CRC-Service2 | | CRC-Service3 | SERVICES\n" + " |______________| |______________| |______________|\n" + " | | | | |______ |\n" + " | | | | | |\n" + " __V__ __V__ __V__ __V__ __V__ __V__\n" + " | SC1 | | SC2 | | SC3 | | SC4 | | SC5 | | SC6 | SERVICE\n" + " |_____| |_____| |_____| |_____| |_____| |_____| COMPONENTS\n" + " | | _____| | | ____|\n" + " | | | | | |\n" + " __V________V__V______________V________V___V_______ COMMON\n" + " | SubCh1 | SubCh9 | ... | SubCh3 | SubCh60 | ... | INTERLEAVED\n" + " |________|________|_______|________|_________|_____| FRAME\n" + " Figure 1: An example of a DAB multiplex configuration\n", + name); +} +#endif void printOutputs(vector<dabOutput*>& outputs) { @@ -431,10 +482,7 @@ void printSubchannels(vector<dabSubchannel*>& subchannels) dabProtection* protection = &(*subchannel)->protection; etiLog.log(info, "Subchannel %i", index); etiLog.log(info, " input"); - etiLog.log(info, " protocol: %s", - (*subchannel)->inputProto); - etiLog.log(info, " name: %s", - (*subchannel)->inputName); + etiLog.level(info) << " URI: " << (*subchannel)->inputUri; switch ((*subchannel)->type) { case Audio: etiLog.log(info, " type: audio"); |