diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-01-19 21:29:55 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-01-19 21:29:55 +0100 |
commit | 6c482c8f1fdd74f6e7a8a9481b9f2211c559ebad (patch) | |
tree | 12378c91fcfddc1974abf91a58662a6a4b70ed89 | |
parent | 72420013928a2d00855ed8ae9c42ac6e229a0b87 (diff) | |
download | dabmux-6c482c8f1fdd74f6e7a8a9481b9f2211c559ebad.tar.gz dabmux-6c482c8f1fdd74f6e7a8a9481b9f2211c559ebad.tar.bz2 dabmux-6c482c8f1fdd74f6e7a8a9481b9f2211c559ebad.zip |
Add wrapper class, and use it for all inputs
-rw-r--r-- | src/DabMux.cpp | 22 | ||||
-rw-r--r-- | src/MuxElements.h | 3 | ||||
-rw-r--r-- | src/ParserCmdline.cpp | 57 | ||||
-rw-r--r-- | src/ParserConfigfile.cpp | 59 | ||||
-rw-r--r-- | src/dabInput.h | 62 |
5 files changed, 126 insertions, 77 deletions
diff --git a/src/DabMux.cpp b/src/DabMux.cpp index f3edd39..2e6e1a6 100644 --- a/src/DabMux.cpp +++ b/src/DabMux.cpp @@ -531,17 +531,14 @@ int main(int argc, char *argv[]) (*subchannel)->startAddress = (*(subchannel - 1))->startAddress + getSizeCu(*(subchannel - 1)); } - if ((*subchannel)->operations.open((*subchannel)->data, - (*subchannel)->inputName) == -1) { + if ((*subchannel)->input->open((*subchannel)->inputName) == -1) { perror((*subchannel)->inputName); returnCode = -1; goto EXIT; } // TODO Check errors - int result = (*subchannel)->operations.setBitrate( - &(*subchannel)->operations, (*subchannel)->data, - (*subchannel)->bitrate); + result = (*subchannel)->input->setBitrate( (*subchannel)->bitrate); if (result <= 0) { etiLog.log(error, "can't set bitrate for source %s\n", (*subchannel)->inputName); @@ -1718,15 +1715,8 @@ int main(int argc, char *argv[]) subchannel != ensemble->subchannels.end(); ++subchannel) { int sizeSubchannel = getSizeByte(*subchannel); - if ((*subchannel)->operations.lock != NULL) { - (*subchannel)->operations.lock((*subchannel)->data); - } - result = (*subchannel)->operations.readFrame( - &(*subchannel)->operations, - (*subchannel)->data, &etiFrame[index], sizeSubchannel); - if ((*subchannel)->operations.unlock != NULL) { - (*subchannel)->operations.unlock((*subchannel)->data); - } + result = (*subchannel)->input->readFrame( + &etiFrame[index], sizeSubchannel); if (result < 0) { etiLog.log(info, "Subchannel %d read failed at ETI frame number: %i\n", (*subchannel)->id, currentFrame); } @@ -1823,8 +1813,8 @@ EXIT: for (subchannel = ensemble->subchannels.begin(); subchannel != ensemble->subchannels.end(); ++subchannel) { - (*subchannel)->operations.close((*subchannel)->data); - (*subchannel)->operations.clean(&(*subchannel)->data); + (*subchannel)->input->close(); + delete (*subchannel)->input; } for (output = outputs.begin() ; output != outputs.end(); ++output) { if ((*output)->output) { diff --git a/src/MuxElements.h b/src/MuxElements.h index 539d955..5556c0e 100644 --- a/src/MuxElements.h +++ b/src/MuxElements.h @@ -96,8 +96,7 @@ struct dabProtection { struct dabSubchannel { const char* inputProto; const char* inputName; - void* data; - dabInputOperations operations; + DabInputBase* input; unsigned char id; unsigned char type; uint16_t startAddress; diff --git a/src/ParserCmdline.cpp b/src/ParserCmdline.cpp index 44736c3..969f98e 100644 --- a/src/ParserCmdline.cpp +++ b/src/ParserCmdline.cpp @@ -107,6 +107,8 @@ bool parse_cmdline(char **argv, vector<dabService*>::iterator service = ensemble->services.end(); dabProtection* protection = NULL; + dabInputOperations operations; + int scids_temp = 0; char* progName = strrchr(argv[0], '/'); @@ -217,7 +219,7 @@ bool parse_cmdline(char **argv, (*subchannel)->inputProto = "file"; (*subchannel)->type = 0; (*subchannel)->bitrate = 0; - (*subchannel)->operations = dabInputMpegFileOperations; + operations = dabInputMpegFileOperations; #endif // defined(HAVE_INPUT_FILE) && defined(HAVE_FORMAT_MPEG) #if defined(HAVE_FORMAT_DABPLUS) } else if (c == 'F') { @@ -238,7 +240,7 @@ bool parse_cmdline(char **argv, if (0) { #if defined(HAVE_INPUT_FILE) } else if (strcmp((*subchannel)->inputProto, "file") == 0) { - (*subchannel)->operations = dabInputDabplusFileOperations; + operations = dabInputDabplusFileOperations; #endif // defined(HAVE_INPUT_FILE) } else { etiLog.log(error, @@ -263,11 +265,11 @@ bool parse_cmdline(char **argv, #if defined(HAVE_FORMAT_BRIDGE) #if defined(HAVE_INPUT_UDP) } else if (strcmp((*subchannel)->inputProto, "udp") == 0) { - (*subchannel)->operations = dabInputBridgeUdpOperations; + operations = dabInputBridgeUdpOperations; #endif // defined(HAVE_INPUT_UDP) #if defined(HAVE_INPUT_SLIP) } else if (strcmp((*subchannel)->inputProto, "slip") == 0) { - (*subchannel)->operations = dabInputSlipOperations; + operations = dabInputSlipOperations; #endif // defined(HAVE_INPUT_SLIP) #endif // defined(HAVE_FORMAT_BRIDGE) } @@ -285,18 +287,18 @@ bool parse_cmdline(char **argv, if (0) { #if defined(HAVE_INPUT_UDP) } else if (strcmp((*subchannel)->inputProto, "udp") == 0) { - (*subchannel)->operations = dabInputUdpOperations; + operations = dabInputUdpOperations; #endif #if defined(HAVE_INPUT_PRBS) && defined(HAVE_FORMAT_RAW) } else if (strcmp((*subchannel)->inputProto, "prbs") == 0) { - (*subchannel)->operations = dabInputPrbsOperations; + operations = dabInputPrbsOperations; #endif #if defined(HAVE_INPUT_FILE) && defined(HAVE_FORMAT_RAW) } else if (strcmp((*subchannel)->inputProto, "file") == 0) { - (*subchannel)->operations = dabInputRawFileOperations; + operations = dabInputRawFileOperations; #endif } else if (strcmp((*subchannel)->inputProto, "fifo") == 0) { - (*subchannel)->operations = dabInputRawFifoOperations; + operations = dabInputRawFifoOperations; } else { etiLog.log(error, "Invalid protocol for data input (%s)\n", @@ -312,7 +314,7 @@ bool parse_cmdline(char **argv, (*subchannel)->inputProto = "test"; (*subchannel)->type = 1; (*subchannel)->bitrate = DEFAULT_DATA_BITRATE; - (*subchannel)->operations = dabInputTestOperations; + operations = dabInputTestOperations; #endif // defined(HAVE_INPUT_TEST)) && defined(HAVE_FORMAT_RAW) #ifdef HAVE_FORMAT_PACKET } else if (c == 'P') { @@ -320,9 +322,9 @@ bool parse_cmdline(char **argv, (*subchannel)->type = 3; (*subchannel)->bitrate = DEFAULT_PACKET_BITRATE; #ifdef HAVE_INPUT_FILE - (*subchannel)->operations = dabInputPacketFileOperations; + operations = dabInputPacketFileOperations; #elif defined(HAVE_INPUT_FIFO) - (*subchannel)->operations = dabInputFifoOperations; + operations = dabInputFifoOperations; #else # pragma error("Must defined at least one packet input") #endif // defined(HAVE_INPUT_FILE) @@ -331,7 +333,7 @@ bool parse_cmdline(char **argv, (*subchannel)->inputProto = "file"; (*subchannel)->type = 3; (*subchannel)->bitrate = DEFAULT_PACKET_BITRATE; - (*subchannel)->operations = dabInputEnhancedPacketFileOperations; + operations = dabInputEnhancedPacketFileOperations; #endif // defined(HAVE_FORMAT_EPM) #endif // defined(HAVE_FORMAT_PACKET) #ifdef HAVE_FORMAT_DMB @@ -347,9 +349,9 @@ bool parse_cmdline(char **argv, *proto = 0; } if (strcmp((*subchannel)->inputProto, "udp") == 0) { - (*subchannel)->operations = dabInputDmbUdpOperations; + operations = dabInputDmbUdpOperations; } else if (strcmp((*subchannel)->inputProto, "file") == 0) { - (*subchannel)->operations = dabInputDmbFileOperations; + operations = dabInputDmbFileOperations; } else { etiLog.log(error, "Invalid protocol for DMB input (%s)\n", @@ -366,7 +368,8 @@ bool parse_cmdline(char **argv, "Service '%c' not yet coded!\n", c); goto EXIT; } - (*subchannel)->operations.init(&(*subchannel)->data); + (*subchannel)->input = new DabInputCompatible(operations); + for (int i = 0; i < 64; ++i) { // Find first free subchannel subchannel = getSubchannel(ensemble->subchannels, i); if (subchannel == ensemble->subchannels.end()) { @@ -588,36 +591,36 @@ bool parse_cmdline(char **argv, switch ((*subchannel)->type) { #ifdef HAVE_FORMAT_PACKET case 3: - (*subchannel)->operations.clean(&(*subchannel)->data); - if ((*subchannel)->operations == dabInputPacketFileOperations) { - (*subchannel)->operations = dabInputFifoOperations; + if ( ((DabInputCompatible*)(*subchannel)->input)->getOpts() == dabInputPacketFileOperations) { + operations = dabInputFifoOperations; #ifdef HAVE_FORMAT_EPM - } else if ((*subchannel)->operations == dabInputEnhancedPacketFileOperations) { - (*subchannel)->operations = dabInputEnhancedFifoOperations; + } else if ( ((DabInputCompatible*)(*subchannel)->input)->getOpts() == dabInputEnhancedPacketFileOperations) { + operations = dabInputEnhancedFifoOperations; #endif // defined(HAVE_FORMAT_EPM) } else { etiLog.log(error, "Error, wrong packet subchannel operations!\n"); goto EXIT; } - (*subchannel)->operations.init(&(*subchannel)->data); + delete (*subchannel)->input; + (*subchannel)->input = new DabInputCompatible(operations); (*subchannel)->inputProto = "fifo"; break; #endif // defined(HAVE_FORMAT_PACKET) #ifdef HAVE_FORMAT_MPEG case 0: - (*subchannel)->operations.clean(&(*subchannel)->data); - if ((*subchannel)->operations == dabInputMpegFileOperations) { - (*subchannel)->operations = dabInputMpegFifoOperations; - } else if ((*subchannel)->operations == + if ( ((DabInputCompatible*)(*subchannel)->input)->getOpts() == dabInputMpegFileOperations) { + operations = dabInputMpegFifoOperations; + } else if (((DabInputCompatible*)(*subchannel)->input)->getOpts() == dabInputDabplusFileOperations) { - (*subchannel)->operations = dabInputDabplusFifoOperations; + operations = dabInputDabplusFifoOperations; } else { etiLog.log(error, "Error, wrong audio subchannel operations!\n"); goto EXIT; } - (*subchannel)->operations.init(&(*subchannel)->data); + delete (*subchannel)->input; + (*subchannel)->input = new DabInputCompatible(operations); (*subchannel)->inputProto = "fifo"; break; #endif // defined(HAVE_FORMAT_MPEG) diff --git a/src/ParserConfigfile.cpp b/src/ParserConfigfile.cpp index ca9983b..1ef2b28 100644 --- a/src/ParserConfigfile.cpp +++ b/src/ParserConfigfile.cpp @@ -444,7 +444,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, subchan->inputName = inputName; - + dabInputOperations operations; dabProtection* protection = &subchan->protection; if (0) { @@ -453,7 +453,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, subchan->inputProto = "file"; subchan->type = 0; subchan->bitrate = 0; - subchan->operations = dabInputMpegFileOperations; + operations = dabInputMpegFileOperations; #endif // defined(HAVE_INPUT_FILE) && defined(HAVE_FORMAT_MPEG) #if defined(HAVE_FORMAT_DABPLUS) } else if (type == "dabplus") { @@ -474,22 +474,22 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, if (0) { #if defined(HAVE_INPUT_FILE) } else if (strcmp(subchan->inputProto, "file") == 0) { - subchan->operations = dabInputDabplusFileOperations; + operations = dabInputDabplusFileOperations; #endif // defined(HAVE_INPUT_FILE) #if defined(HAVE_INPUT_ZEROMQ) } else if (strcmp(subchan->inputProto, "tcp") == 0) { - subchan->operations = dabInputZmqOperations; + operations = dabInputZmqOperations; } else if (strcmp(subchan->inputProto, "epmg") == 0) { etiLog.log(warn, "Using untested epmg:// zeromq input\n"); - subchan->operations = dabInputZmqOperations; + operations = dabInputZmqOperations; } else if (strcmp(subchan->inputProto, "ipc") == 0) { etiLog.log(warn, "Using untested ipc:// zeromq input\n"); - subchan->operations = dabInputZmqOperations; + operations = dabInputZmqOperations; #endif // defined(HAVE_INPUT_ZEROMQ) } else { stringstream ss; @@ -514,11 +514,11 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, #if defined(HAVE_FORMAT_BRIDGE) #if defined(HAVE_INPUT_UDP) } else if (strcmp(subchan->inputProto, "udp") == 0) { - subchan->operations = dabInputBridgeUdpOperations; + operations = dabInputBridgeUdpOperations; #endif // defined(HAVE_INPUT_UDP) #if defined(HAVE_INPUT_SLIP) } else if (strcmp(subchan->inputProto, "slip") == 0) { - subchan->operations = dabInputSlipOperations; + operations = dabInputSlipOperations; #endif // defined(HAVE_INPUT_SLIP) #endif // defined(HAVE_FORMAT_BRIDGE) } @@ -536,18 +536,18 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, if (0) { #if defined(HAVE_INPUT_UDP) } else if (strcmp(subchan->inputProto, "udp") == 0) { - subchan->operations = dabInputUdpOperations; + operations = dabInputUdpOperations; #endif #if defined(HAVE_INPUT_PRBS) && defined(HAVE_FORMAT_RAW) } else if (strcmp(subchan->inputProto, "prbs") == 0) { - subchan->operations = dabInputPrbsOperations; + operations = dabInputPrbsOperations; #endif #if defined(HAVE_INPUT_FILE) && defined(HAVE_FORMAT_RAW) } else if (strcmp(subchan->inputProto, "file") == 0) { - subchan->operations = dabInputRawFileOperations; + operations = dabInputRawFileOperations; #endif } else if (strcmp(subchan->inputProto, "fifo") == 0) { - subchan->operations = dabInputRawFifoOperations; + operations = dabInputRawFifoOperations; } else { stringstream ss; ss << "Subchannel with uid " << subchanuid << @@ -563,7 +563,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, subchan->inputProto = "test"; subchan->type = 1; subchan->bitrate = DEFAULT_DATA_BITRATE; - subchan->operations = dabInputTestOperations; + operations = dabInputTestOperations; #endif // defined(HAVE_INPUT_TEST)) && defined(HAVE_FORMAT_RAW) #ifdef HAVE_FORMAT_PACKET } else if (type == "packet") { @@ -571,9 +571,9 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, subchan->type = 3; subchan->bitrate = DEFAULT_PACKET_BITRATE; #ifdef HAVE_INPUT_FILE - subchan->operations = dabInputPacketFileOperations; + operations = dabInputPacketFileOperations; #elif defined(HAVE_INPUT_FIFO) - subchan->operations = dabInputFifoOperations; + operations = dabInputFifoOperations; #else # pragma error("Must defined at least one packet input") #endif // defined(HAVE_INPUT_FILE) @@ -582,7 +582,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, subchan->inputProto = "file"; subchan->type = 3; subchan->bitrate = DEFAULT_PACKET_BITRATE; - subchan->operations = dabInputEnhancedPacketFileOperations; + operations = dabInputEnhancedPacketFileOperations; #endif // defined(HAVE_FORMAT_EPM) #endif // defined(HAVE_FORMAT_PACKET) #ifdef HAVE_FORMAT_DMB @@ -598,9 +598,9 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, *proto = 0; } if (strcmp(subchan->inputProto, "udp") == 0) { - subchan->operations = dabInputDmbUdpOperations; + operations = dabInputDmbUdpOperations; } else if (strcmp(subchan->inputProto, "file") == 0) { - subchan->operations = dabInputDmbFileOperations; + operations = dabInputDmbFileOperations; } else { stringstream ss; ss << "Subchannel with uid " << subchanuid << @@ -617,7 +617,6 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, ss << "Subchannel with uid " << subchanuid << " has unknown type!"; throw runtime_error(ss.str()); } - subchan->operations.init(&subchan->data); subchan->startAddress = 0; if (type == "audio") { @@ -649,37 +648,33 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, switch (subchan->type) { #ifdef HAVE_FORMAT_PACKET case 3: - subchan->operations.clean(&subchan->data); - if (subchan->operations == dabInputPacketFileOperations) { - subchan->operations = dabInputFifoOperations; + if (operations == dabInputPacketFileOperations) { + operations = dabInputFifoOperations; #ifdef HAVE_FORMAT_EPM - } else if (subchan->operations == dabInputEnhancedPacketFileOperations) { - subchan->operations = dabInputEnhancedFifoOperations; + } else if (operations == dabInputEnhancedPacketFileOperations) { + operations = dabInputEnhancedFifoOperations; #endif // defined(HAVE_FORMAT_EPM) } else { etiLog.log(error, "Error, wrong packet subchannel operations!\n"); throw runtime_error("Error, wrong packet subchannel operations!\n"); } - subchan->operations.init(&subchan->data); subchan->inputProto = "fifo"; break; #endif // defined(HAVE_FORMAT_PACKET) #ifdef HAVE_FORMAT_MPEG case 0: - subchan->operations.clean(&subchan->data); - if (subchan->operations == dabInputMpegFileOperations) { - subchan->operations = dabInputMpegFifoOperations; - } else if (subchan->operations == + if (operations == dabInputMpegFileOperations) { + operations = dabInputMpegFifoOperations; + } else if (operations == dabInputDabplusFileOperations) { - subchan->operations = dabInputDabplusFifoOperations; + operations = dabInputDabplusFifoOperations; } else { etiLog.log(error, "Error, wrong audio subchannel operations!\n"); throw runtime_error( "Error, wrong audio subchannel operations!\n"); } - subchan->operations.init(&subchan->data); subchan->inputProto = "fifo"; break; #endif // defined(HAVE_FORMAT_MPEG) @@ -735,4 +730,6 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, } catch (ptree_error &e) {} + /* Create object */ + subchan->input = new DabInputCompatible(operations); } diff --git a/src/dabInput.h b/src/dabInput.h index 685f7b2..0fc04db 100644 --- a/src/dabInput.h +++ b/src/dabInput.h @@ -26,8 +26,9 @@ # include "config.h" #endif #include "Log.h" -extern Logger etiLog; +#include <string> +extern Logger etiLog; struct dabInputOperations { int (*init)(void** args); @@ -44,6 +45,65 @@ struct dabInputOperations { bool operator==(const dabInputOperations&); }; +/* New input object base */ +class DabInputBase { + public: + virtual int open(const std::string name) = 0; + virtual int setbuf(int size) = 0; + virtual int readFrame(void* buffer, int size) = 0; + virtual int setBitrate(int bitrate) = 0; + virtual int close() = 0; + virtual int rewind() = 0; + + virtual ~DabInputBase() {}; +}; + +/* Wrapper class for old-style dabInputOperations inputs */ +class DabInputCompatible : public DabInputBase { + public: + DabInputCompatible(dabInputOperations ops) + : m_ops(ops) + { m_ops.init(&args); } + + virtual ~DabInputCompatible() + { m_ops.clean(&args); } + + virtual int open(const std::string name) + { return m_ops.open(args, name.c_str()); } + + virtual int setbuf(int size) + { return m_ops.setbuf(args, size); } + + virtual int readFrame(void* buffer, int size) + { + if (m_ops.lock) { + m_ops.lock(args); + } + int result = m_ops.readFrame(&m_ops, args, buffer, size); + if (m_ops.unlock) { + m_ops.unlock(args); + } + return result; + } + + virtual int setBitrate(int bitrate) + { return m_ops.setBitrate(&m_ops, args, bitrate); } + + virtual int close() + { return m_ops.close(args); } + + virtual int rewind() + { return m_ops.rewind(args); } + + virtual int read(void* buffer, int size) + { return m_ops.read(args, buffer, size); } + + virtual dabInputOperations getOpts() { return m_ops; } + + private: + dabInputOperations m_ops; + void* args; +}; int dabInputSetbuf(void* args, int size); int dabInputSetbitrate(dabInputOperations* ops, void* args, int bitrate); |