summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/DabMux.cpp2
-rw-r--r--src/MuxElements.cpp39
-rw-r--r--src/MuxElements.h13
-rw-r--r--src/utils.cpp9
4 files changed, 32 insertions, 31 deletions
diff --git a/src/DabMux.cpp b/src/DabMux.cpp
index 7f946d5..ecbedc4 100644
--- a/src/DabMux.cpp
+++ b/src/DabMux.cpp
@@ -1909,7 +1909,7 @@ int main(int argc, char *argv[])
subchannel =
getSubchannel(ensemble->subchannels, (*component)->subchId);
- if ((*component)->label.text()[0] != 0) {
+ if (!((*component)->label.long_label().empty())) {
if ((*service)->getType(ensemble) == 0) { // Programme
FIGtype1_4_programme *fig1_4;
fig1_4 = (FIGtype1_4_programme*)&etiFrame[index];
diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp
index 4b40b10..65045db 100644
--- a/src/MuxElements.cpp
+++ b/src/MuxElements.cpp
@@ -43,29 +43,29 @@ const unsigned short Sub_Channel_SizeTable[64] = {
using namespace std;
-int DabLabel::setLabel(const std::string& text)
+int DabLabel::setLabel(const std::string& label)
{
- int len = text.length();
- if (len > 16)
+ size_t len = label.length();
+ if (len > sizeof(m_text))
return -3;
- memset(m_text, 0, 17);
- memcpy(m_text, text.c_str(), len);
+ memcpy(m_text, label.c_str(), len);
+ memset(m_text + len, 0x20, sizeof(m_text) - len);
m_flag = 0xFF00; // truncate the label to the eight first characters
+ m_label = label;
+
return 0;
}
-int DabLabel::setLabel(const std::string& text, const std::string& short_label)
+int DabLabel::setLabel(const std::string& label, const std::string& short_label)
{
DabLabel newlabel;
- memset(newlabel.m_text, 0, 17);
- int len = text.length();
- if (len > 16)
- return -3;
- memcpy(newlabel.m_text, text.c_str(), len);
+ int result = newlabel.setLabel(label);
+ if (result < 0)
+ return result;
/* First check if we can actually create the short label */
int flag = newlabel.setShortLabel(short_label);
@@ -73,8 +73,9 @@ int DabLabel::setLabel(const std::string& text, const std::string& short_label)
return flag;
// short label is valid.
- memcpy(this->m_text, newlabel.m_text, 17);
- this->m_flag = flag & 0xFFFF;
+ memcpy(m_text, newlabel.m_text, sizeof(m_text));
+ m_flag = flag & 0xFFFF;
+ m_label = newlabel.m_label;
return 0;
}
@@ -105,7 +106,7 @@ int DabLabel::setShortLabel(const std::string& slabel)
* according to the characters in the slabel
*/
for (int i = 0; i < 32; ++i) {
- if (*slab == this->m_text[i]) {
+ if (*slab == m_text[i]) {
flag |= 0x8000 >> i;
if (*(++slab) == 0) {
break;
@@ -271,10 +272,7 @@ const string DabComponent::get_parameter(const string& parameter) const
{
stringstream ss;
if (parameter == "label") {
- char l[17];
- l[16] = '\0';
- memcpy(l, label.text(), 16);
- ss << l << "," << label.short_label();
+ ss << label.long_label() << "," << label.short_label();
}
else {
ss << "Parameter '" << parameter <<
@@ -366,10 +364,7 @@ const string DabService::get_parameter(const string& parameter) const
{
stringstream ss;
if (parameter == "label") {
- char l[17];
- l[16] = '\0';
- memcpy(l, label.text(), 16);
- ss << l << "," << label.short_label();
+ ss << label.long_label() << "," << label.short_label();
}
else {
ss << "Parameter '" << parameter <<
diff --git a/src/MuxElements.h b/src/MuxElements.h
index 3653ea4..22112db 100644
--- a/src/MuxElements.h
+++ b/src/MuxElements.h
@@ -61,7 +61,7 @@ class DabLabel
* -2 if the short_label is too long
* -3 if the text is too long
*/
- int setLabel(const std::string& text, const std::string& short_label);
+ int setLabel(const std::string& label, const std::string& short_label);
/* Same as above, but sets the flag to 0xff00, truncating at 8
* characters.
@@ -69,17 +69,20 @@ class DabLabel
* returns: 0 on success
* -3 if the text is too long
*/
- int setLabel(const std::string& text);
+ int setLabel(const std::string& label);
const char* text() const { return m_text; }
uint16_t flag() const { return m_flag; }
+ const std::string long_label() const { return m_label; }
const std::string short_label() const;
private:
- // In the DAB standard, the label is 16 chars.
- // We keep it here zero-terminated
- char m_text[17];
+ // In the DAB standard, the label is 16 bytes long.
+ // We use spaces for padding at the end if needed.
+ char m_text[16];
uint16_t m_flag;
+ std::string m_label;
+
int setShortLabel(const std::string& slabel);
};
diff --git a/src/utils.cpp b/src/utils.cpp
index 7c3c516..2c9c317 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -380,7 +380,8 @@ void printServices(vector<DabService*>& services)
for (current = services.begin(); current != services.end(); ++current) {
etiLog.level(info) << "Service " << (*current)->get_rc_name();
- etiLog.level(info) << " label: " << (*current)->label.text();
+ etiLog.level(info) << " label: " <<
+ (*current)->label.long_label();
etiLog.level(info) << " short label: " <<
(*current)->label.short_label();
@@ -413,7 +414,8 @@ void printComponent(DabComponent* component)
{
etiLog.log(info, " service id: %i", component->serviceId);
etiLog.log(info, " subchannel id: %i", component->subchId);
- etiLog.log(info, " label: %s", component->label.text());
+ etiLog.level(info) << " label: " <<
+ component->label.long_label();
etiLog.level(info) << " short label: " <<
component->label.short_label();
@@ -531,7 +533,8 @@ void printEnsemble(dabEnsemble* ensemble)
etiLog.log(info, "Ensemble");
etiLog.log(info, " id: 0x%lx (%lu)", ensemble->id, ensemble->id);
etiLog.log(info, " ecc: 0x%x (%u)", ensemble->ecc, ensemble->ecc);
- etiLog.log(info, " label: %s", ensemble->label.text());
+ etiLog.level(info) << " label: " <<
+ ensemble->label.long_label();
etiLog.level(info) << " short label: " <<
ensemble->label.short_label();