diff options
| author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-08-07 14:50:09 +0200 | 
|---|---|---|
| committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-08-07 14:50:09 +0200 | 
| commit | 2773aecdea641ca8a0b362085eba3dc5273e0fa6 (patch) | |
| tree | b211a19d18cabecf26da3024167e86c34417b77a /src | |
| parent | b53125dffd58e96ec586c40320827100c039398f (diff) | |
| download | dabmux-2773aecdea641ca8a0b362085eba3dc5273e0fa6.tar.gz dabmux-2773aecdea641ca8a0b362085eba3dc5273e0fa6.tar.bz2 dabmux-2773aecdea641ca8a0b362085eba3dc5273e0fa6.zip | |
Create enum class subchannel_type_t
Diffstat (limited to 'src')
| -rw-r--r-- | src/ConfigParser.cpp | 20 | ||||
| -rw-r--r-- | src/DabMultiplexer.cpp | 56 | ||||
| -rw-r--r-- | src/MuxElements.cpp | 9 | ||||
| -rw-r--r-- | src/MuxElements.h | 19 | ||||
| -rw-r--r-- | src/fig/FIG0.cpp | 26 | ||||
| -rw-r--r-- | src/utils.cpp | 30 | 
6 files changed, 84 insertions, 76 deletions
| diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp index 6092e66..1ad9249 100644 --- a/src/ConfigParser.cpp +++ b/src/ConfigParser.cpp @@ -537,7 +537,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan,      if (0) {  #if defined(HAVE_FORMAT_MPEG)      } else if (type == "audio") { -        subchan->type = Audio; +        subchan->type = subchannel_type_t::Audio;          subchan->bitrate = 0;          if (0) { @@ -596,7 +596,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan,  #endif // defined(HAVE_INPUT_FILE) && defined(HAVE_FORMAT_MPEG)  #if defined(HAVE_FORMAT_DABPLUS)      } else if (type == "dabplus") { -        subchan->type = Audio; +        subchan->type = subchannel_type_t::Audio;          subchan->bitrate = 32;          if (0) { @@ -699,7 +699,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan,              throw runtime_error(ss.str());          } -        subchan->type = DataDmb; +        subchan->type = subchannel_type_t::DataDmb;          subchan->bitrate = DEFAULT_DATA_BITRATE;  #if defined(HAVE_INPUT_TEST) && defined(HAVE_FORMAT_RAW)      } else if (type == "test") { @@ -709,7 +709,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan,  #endif // defined(HAVE_INPUT_TEST)) && defined(HAVE_FORMAT_RAW)  #ifdef HAVE_FORMAT_PACKET      } else if (type == "packet") { -        subchan->type = Packet; +        subchan->type = subchannel_type_t::Packet;          subchan->bitrate = DEFAULT_PACKET_BITRATE;  #ifdef HAVE_INPUT_FILE          operations = dabInputPacketFileOperations; @@ -720,7 +720,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan,  #endif // defined(HAVE_INPUT_FILE)  #ifdef HAVE_FORMAT_EPM      } else if (type == "enhancedpacked") { -        subchan->type = Packet; +        subchan->type = subchannel_type_t::Packet;          subchan->bitrate = DEFAULT_PACKET_BITRATE;          operations = dabInputEnhancedPacketFileOperations;  #endif // defined(HAVE_FORMAT_EPM) @@ -743,7 +743,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan,              throw runtime_error(ss.str());          } -        subchan->type = DataDmb; +        subchan->type = subchannel_type_t::DataDmb;          subchan->bitrate = DEFAULT_DATA_BITRATE;  #endif      } else { @@ -785,7 +785,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan,      if (nonblock) {          switch (subchan->type) {  #ifdef HAVE_FORMAT_PACKET -            case Packet: +            case subchannel_type_t::Packet:                  if (operations == dabInputPacketFileOperations) {                      operations = dabInputFifoOperations;  #ifdef HAVE_FORMAT_EPM @@ -801,7 +801,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan,                  break;  #endif // defined(HAVE_FORMAT_PACKET)  #ifdef HAVE_FORMAT_MPEG -            case Audio: +            case subchannel_type_t::Audio:                  if (operations == dabInputMpegFileOperations) {                      operations = dabInputMpegFifoOperations;                  } else if (operations == dabInputDabplusFileOperations) { @@ -814,8 +814,8 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan,                  }                  break;  #endif // defined(HAVE_FORMAT_MPEG) -            case DataDmb: -            case Fidc: +            case subchannel_type_t::DataDmb: +            case subchannel_type_t::Fidc:              default:                  stringstream ss;                  ss << "Subchannel with uid " << subchanuid << diff --git a/src/DabMultiplexer.cpp b/src/DabMultiplexer.cpp index ff431b0..e775c96 100644 --- a/src/DabMultiplexer.cpp +++ b/src/DabMultiplexer.cpp @@ -260,12 +260,12 @@ void DabMultiplexer::prepare_services_components()          // Adjust service type from this first component          switch (service->getType(ensemble)) { -            case 0: // Audio +            case subchannel_type_t::Audio: // Audio                  service->program = true;                  break; -            case 1: -            case 2: -            case 3: +            case subchannel_type_t::DataDmb: +            case subchannel_type_t::Fidc: +            case subchannel_type_t::Packet:                  service->program = false;                  break;              default: @@ -290,16 +290,16 @@ void DabMultiplexer::prepare_services_components()              protection = &(*subchannel)->protection;              switch ((*subchannel)->type) { -                case Audio: +                case subchannel_type_t::Audio:                      {                          if (protection->form == EEP) {                              (*component)->type = 0x3f;  // DAB+                          }                      }                      break; -                case DataDmb: -                case Fidc: -                case Packet: +                case subchannel_type_t::DataDmb: +                case subchannel_type_t::Fidc: +                case subchannel_type_t::Packet:                      break;                  default:                      etiLog.log(error, @@ -323,7 +323,7 @@ void DabMultiplexer::prepare_services_components()                      component->subchId, component->serviceId);              throw MuxInitException();          } -        if ((*subchannel)->type != Packet) continue; +        if ((*subchannel)->type != subchannel_type_t::Packet) continue;          component->packet.id = cur_packetid++; @@ -765,7 +765,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                      continue;                  } -                if ((*serviceProgFIG0_2)->getType(ensemble) != 0) { +                if ((*serviceProgFIG0_2)->getType(ensemble) != subchannel_type_t::Audio) {                      continue;                  } @@ -819,7 +819,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                      }                      switch ((*subchannel)->type) { -                        case Audio: +                        case subchannel_type_t::Audio:                              audio_description =                                  (FIGtype0_2_audio_component*)&etiFrame[index];                              audio_description->TMid    = 0; @@ -828,7 +828,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                              audio_description->PS      = ((curCpnt == 0) ? 1 : 0);                              audio_description->CA_flag = 0;                              break; -                        case DataDmb: +                        case subchannel_type_t::DataDmb:                              data_description =                                  (FIGtype0_2_data_component*)&etiFrame[index];                              data_description->TMid    = 1; @@ -837,7 +837,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                              data_description->PS      = ((curCpnt == 0) ? 1 : 0);                              data_description->CA_flag = 0;                              break; -                        case Packet: +                        case subchannel_type_t::Packet:                              packet_description =                                  (FIGtype0_2_packet_component*)&etiFrame[index];                              packet_description->TMid    = 3; @@ -878,8 +878,9 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                      continue;                  } -                unsigned char type = (*serviceDataFIG0_2)->getType(ensemble); -                if ((type == 0) || (type == 2)) { +                auto type = (*serviceDataFIG0_2)->getType(ensemble); +                if (    type == subchannel_type_t::Audio || +                        type == subchannel_type_t::Fidc  ) {                      continue;                  } @@ -933,7 +934,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                      }                      switch ((*subchannel)->type) { -                        case Audio: +                        case subchannel_type_t::Audio:                              audio_description =                                  (FIGtype0_2_audio_component*)&etiFrame[index];                              audio_description->TMid = 0; @@ -942,7 +943,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                              audio_description->PS = ((curCpnt == 0) ? 1 : 0);                              audio_description->CA_flag = 0;                              break; -                        case DataDmb: +                        case subchannel_type_t::DataDmb:                              data_description =                                  (FIGtype0_2_data_component*)&etiFrame[index];                              data_description->TMid = 1; @@ -951,7 +952,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                              data_description->PS = ((curCpnt == 0) ? 1 : 0);                              data_description->CA_flag = 0;                              break; -                        case Packet: +                        case subchannel_type_t::Packet:                              packet_description =                                  (FIGtype0_2_packet_component*)&etiFrame[index];                              packet_description->TMid = 3; @@ -996,7 +997,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                      throw MuxInitException();                  } -                if ((*subchannel)->type != Packet) +                if ((*subchannel)->type != subchannel_type_t::Packet)                      continue;                  if (fig0_3_header == NULL) { @@ -1169,7 +1170,9 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                      figSize += 2;                  } -                if ((*subchannel)->type == Packet) { // Data packet +                if ((*subchannel)->type == subchannel_type_t::Packet) { +                    // Data packet +                      if (figSize > 30 - 5) {                          break;                      } @@ -1258,7 +1261,9 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                      figSize += 2;                  } -                if ((*subchannel)->type == Packet) { // Data packet +                if ((*subchannel)->type == subchannel_type_t::Packet) { +                    // Data packet +                      if (figSize > 30 - 7) {                          break;                      } @@ -1359,7 +1364,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                  }                  if (    transmitFIG0_13programme && -                        (*subchannel)->type == Audio && +                        (*subchannel)->type == subchannel_type_t::Audio &&                          (*componentFIG0_13)->audio.uaType != 0xffff) {                      if (fig0 == NULL) {                          fig0 = (FIGtype0*)&etiFrame[index]; @@ -1405,7 +1410,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu                      fig0->Length += 2 + app->length;                  }                  else if (!transmitFIG0_13programme && -                        (*subchannel)->type == Packet && +                        (*subchannel)->type == subchannel_type_t::Packet &&                          (*componentFIG0_13)->packet.appType != 0xffff) {                      if (fig0 == NULL) { @@ -1524,7 +1529,7 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu          service = ensemble->services.begin() + rotateFIB;          // FIG type 1/1, SI, Service label, one instance per subchannel -        if ((*service)->getType(ensemble) == 0) { +        if ((*service)->getType(ensemble) == subchannel_type_t::Audio) {              fig1_1 = (FIGtype1_1 *) & etiFrame[index];              fig1_1->FIGtypeNumber = 1; @@ -1567,7 +1572,8 @@ void DabMultiplexer::mux_frame(std::vector<boost::shared_ptr<DabOutput> >& outpu              getSubchannel(ensemble->subchannels, (*component)->subchId);          if (not (*component)->label.long_label().empty() ) { -            if ((*service)->getType(ensemble) == 0) {   // Programme +            if ((*service)->getType(ensemble) == subchannel_type_t::Audio) { +                // Programme                  FIGtype1_4_programme *fig1_4;                  fig1_4 = (FIGtype1_4_programme*)&etiFrame[index]; diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp index 3170fe1..6ecee76 100644 --- a/src/MuxElements.cpp +++ b/src/MuxElements.cpp @@ -220,7 +220,7 @@ bool DabComponent::isPacketComponent(vector<dabSubchannel*>& subchannels)                  "for defining packet ");          return false;      } -    if ((*getSubchannel(subchannels, subchId))->type != Packet) { +    if ((*getSubchannel(subchannels, subchId))->type != subchannel_type_t::Packet) {          return false;      }      return true; @@ -288,17 +288,18 @@ const string DabComponent::get_parameter(const string& parameter) const  } -unsigned char DabService::getType(boost::shared_ptr<dabEnsemble> ensemble) +subchannel_type_t DabService::getType(boost::shared_ptr<dabEnsemble> ensemble)  {      vector<dabSubchannel*>::iterator subchannel;      vector<DabComponent*>::iterator component =          getComponent(ensemble->components, id);      if (component == ensemble->components.end()) { -        return 4; +        throw std::runtime_error("No component found for service");      } +      subchannel = getSubchannel(ensemble->subchannels, (*component)->subchId);      if (subchannel == ensemble->subchannels.end()) { -        return 8; +        throw std::runtime_error("Could not find subchannel associated with service");      }      return (*subchannel)->type; diff --git a/src/MuxElements.h b/src/MuxElements.h index ebcf708..d714c76 100644 --- a/src/MuxElements.h +++ b/src/MuxElements.h @@ -39,6 +39,14 @@  #include "RemoteControl.h"  #include "Eti.h" +enum class subchannel_type_t { +    Audio = 0, +    DataDmb = 1, +    Fidc = 2, +    Packet = 3 +}; + +  struct dabOutput {      dabOutput(const char* proto, const char* name) :          outputProto(proto), outputName(name), output(NULL) { } @@ -172,13 +180,6 @@ struct dabProtection {      };  }; -enum dab_subchannel_type_t { -    Audio = 0, -    DataDmb = 1, -    Fidc = 2, -    Packet = 3 -}; -  class dabSubchannel  {  public: @@ -192,7 +193,7 @@ public:      std::string inputUri;      DabInputBase* input;      unsigned char id; -    dab_subchannel_type_t type; +    subchannel_type_t type;      uint16_t startAddress;      uint16_t bitrate;      dabProtection protection; @@ -297,7 +298,7 @@ class DabService : public RemoteControllable          unsigned char language;          bool program; -        unsigned char getType(boost::shared_ptr<dabEnsemble> ensemble); +        subchannel_type_t getType(boost::shared_ptr<dabEnsemble> ensemble);          unsigned char nbComponent(std::vector<DabComponent*>& components);          DabLabel label; diff --git a/src/fig/FIG0.cpp b/src/fig/FIG0.cpp index f8297ae..e8f341c 100644 --- a/src/fig/FIG0.cpp +++ b/src/fig/FIG0.cpp @@ -202,7 +202,7 @@ FillStatus FIG0_2::fill(uint8_t *buf, size_t max_size)          // Exclude Fidc type services, TODO why ?          auto type = (*serviceFIG0_2)->getType(ensemble); -        if (type == Fidc) { +        if (type == subchannel_type_t::Fidc) {              continue;          } @@ -215,25 +215,25 @@ FillStatus FIG0_2::fill(uint8_t *buf, size_t max_size)              fig0_2->Length = 1;              fig0_2->CN = 0;              fig0_2->OE = 0; -            fig0_2->PD = (type == Audio) ? 0 : 1; +            fig0_2->PD = (type == subchannel_type_t::Audio) ? 0 : 1;              fig0_2->Extension = 2;              buf += 2;              remaining -= 2;          } -        if (type == Audio and +        if (type == subchannel_type_t::Audio and                  remaining < 3 + 2 *                  (*serviceFIG0_2)->nbComponent(ensemble->components)) {              break;          } -        if (type != Audio and +        if (type != subchannel_type_t::Audio and                  remaining < 5 + 2 *                  (*serviceFIG0_2)->nbComponent(ensemble->components)) {              break;          } -        if (type == Audio) { +        if (type == subchannel_type_t::Audio) {              auto fig0_2serviceAudio = (FIGtype0_2_Service*)buf;              fig0_2serviceAudio->SId = htons((*serviceFIG0_2)->id); @@ -279,7 +279,7 @@ FillStatus FIG0_2::fill(uint8_t *buf, size_t max_size)              }              switch ((*subchannel)->type) { -                case Audio: +                case subchannel_type_t::Audio:                      {                          auto audio_description = (FIGtype0_2_audio_component*)buf;                          audio_description->TMid    = 0; @@ -289,7 +289,7 @@ FillStatus FIG0_2::fill(uint8_t *buf, size_t max_size)                          audio_description->CA_flag = 0;                      }                      break; -                case DataDmb: +                case subchannel_type_t::DataDmb:                      {                          auto data_description = (FIGtype0_2_data_component*)buf;                          data_description->TMid    = 1; @@ -299,7 +299,7 @@ FillStatus FIG0_2::fill(uint8_t *buf, size_t max_size)                          data_description->CA_flag = 0;                      }                      break; -                case Packet: +                case subchannel_type_t::Packet:                      {                          auto packet_description = (FIGtype0_2_packet_component*)buf;                          packet_description->TMid    = 3; @@ -359,7 +359,7 @@ FillStatus FIG0_3::fill(uint8_t *buf, size_t max_size)              throw MuxInitException();          } -        if ((*subchannel)->type != Packet) +        if ((*subchannel)->type != subchannel_type_t::Packet)              continue;          if (fig0_3_header == NULL) { @@ -471,7 +471,7 @@ FillStatus FIG0_8::fill(uint8_t *buf, size_t max_size)          }          if ((*service)->program) { -            if ((*subchannel)->type == Packet) { // Data packet +            if ((*subchannel)->type == subchannel_type_t::Packet) { // Data packet                  if (remaining < 5) {                      break;                  } @@ -515,7 +515,7 @@ FillStatus FIG0_8::fill(uint8_t *buf, size_t max_size)              }          }          else { // Data -            if ((*subchannel)->type == Packet) { // Data packet +            if ((*subchannel)->type == subchannel_type_t::Packet) { // Data packet                  if (remaining < 7) {                      break;                  } @@ -737,7 +737,7 @@ FillStatus FIG0_13::fill(uint8_t *buf, size_t max_size)          }          if (    m_transmit_programme && -                (*subchannel)->type == Audio && +                (*subchannel)->type == subchannel_type_t::Audio &&                  (*componentFIG0_13)->audio.uaType != 0xffff) {              if (fig0 == NULL) {                  fig0 = (FIGtype0*)buf; @@ -782,7 +782,7 @@ FillStatus FIG0_13::fill(uint8_t *buf, size_t max_size)              fig0->Length += 2 + app->length;          }          else if (!m_transmit_programme && -                (*subchannel)->type == Packet && +                (*subchannel)->type == subchannel_type_t::Packet &&                  (*componentFIG0_13)->packet.appType != 0xffff) {              if (fig0 == NULL) { diff --git a/src/utils.cpp b/src/utils.cpp index 42937c1..e79d023 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -479,21 +479,21 @@ void printSubchannels(vector<dabSubchannel*>& subchannels)          etiLog.log(info, " input");          etiLog.level(info) << "   URI:     " << (*subchannel)->inputUri;          switch ((*subchannel)->type) { -        case Audio: -            etiLog.log(info, " type:       audio"); -            break; -        case DataDmb: -            etiLog.log(info, " type:       data"); -            break; -        case Fidc: -            etiLog.log(info, " type:       fidc"); -            break; -        case Packet: -            etiLog.log(info, " type:       packet"); -            break; -        default: -            etiLog.log(info, " type:       unknown"); -            break; +            case subchannel_type_t::Audio: +                etiLog.log(info, " type:       audio"); +                break; +            case subchannel_type_t::DataDmb: +                etiLog.log(info, " type:       data"); +                break; +            case subchannel_type_t::Fidc: +                etiLog.log(info, " type:       fidc"); +                break; +            case subchannel_type_t::Packet: +                etiLog.log(info, " type:       packet"); +                break; +            default: +                etiLog.log(info, " type:       unknown"); +                break;          }          etiLog.log(info, " id:         %i",                  (*subchannel)->id); | 
