summaryrefslogtreecommitdiffstats
path: root/src/MuxElements.cpp
diff options
context:
space:
mode:
authorStefan Pöschel <github@basicmaster.de>2015-05-24 23:42:35 +0200
committerStefan Pöschel <github@basicmaster.de>2015-05-24 23:42:35 +0200
commitf470de09c4215c39387fbe6d85330c90fecea10d (patch)
tree31dbb58ab8864cbb3029e92e0ae029565f2cbee2 /src/MuxElements.cpp
parent2391d2a38ff9d85f802f2453ffe20fb58915c097 (diff)
downloaddabmux-f470de09c4215c39387fbe6d85330c90fecea10d.tar.gz
dabmux-f470de09c4215c39387fbe6d85330c90fecea10d.tar.bz2
dabmux-f470de09c4215c39387fbe6d85330c90fecea10d.zip
Labels: use spaces instead of NULs for trailing padding
The NULs ATM used for trailing label padding are not defined in the EBU Latin based charset we use. As all 16 label bytes must be used, use spaces instead, like real-world broadcasters do.
Diffstat (limited to 'src/MuxElements.cpp')
-rw-r--r--src/MuxElements.cpp39
1 files changed, 17 insertions, 22 deletions
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 <<