aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Pöschel <github@basicmaster.de>2017-02-11 10:48:54 +0100
committerStefan Pöschel <github@basicmaster.de>2017-02-11 10:57:21 +0100
commitdf9dd263f1a7be8f67a776af67cf4be1189f6616 (patch)
tree2d13a1ac7d156261f787c24ef54e6b28770cdab9
parent07be2a291ec5a235c881bac43fae80de6903d35d (diff)
downloadODR-PadEnc-df9dd263f1a7be8f67a776af67cf4be1189f6616.tar.gz
ODR-PadEnc-df9dd263f1a7be8f67a776af67cf4be1189f6616.tar.bz2
ODR-PadEnc-df9dd263f1a7be8f67a776af67cf4be1189f6616.zip
Slight refactorings
- DLSManager: store PADPacketizer ref - DABCharset: convert enum to enum class - DL cmd prefix: output reserved instead of charset (does not make a difference) - MOT header: get charset from enum class - .gitignore: add Eclipse files
-rw-r--r--.gitignore5
-rw-r--r--src/dls.cpp26
-rw-r--r--src/dls.h19
-rw-r--r--src/odr-padenc.cpp58
-rw-r--r--src/pad_common.h9
5 files changed, 56 insertions, 61 deletions
diff --git a/.gitignore b/.gitignore
index 858f85c..65c7488 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,3 +29,8 @@ missing
stamp-h1
mot-encoder
odr-padenc
+
+# Eclipse
+/.cproject
+/.project
+/.settings/
diff --git a/src/dls.cpp b/src/dls.cpp
index f41c9ff..eacd10d 100644
--- a/src/dls.cpp
+++ b/src/dls.cpp
@@ -51,8 +51,8 @@ DATA_GROUP* DLSManager::createDynamicLabelCommand(uint8_t command) {
(1 << 4) +
command;
- // prefix: charset (though irrelevant here)
- seg_data[1] = CHARSET_COMPLETE_EBU_LATIN;
+ // prefix: reserved
+ seg_data[1] = 0;
// CRC
dg->AppendCRC();
@@ -186,7 +186,7 @@ void DLSManager::parse_dl_params(std::ifstream &dls_fstream, DL_STATE &dl_state)
}
-void DLSManager::writeDLS(PADPacketizer& pad_packetizer, const std::string& dls_file, uint8_t charset, bool raw_dls, bool remove_dls) {
+void DLSManager::writeDLS(const std::string& dls_file, DABCharset charset, bool raw_dls, bool remove_dls) {
std::ifstream dls_fstream(dls_file);
if (!dls_fstream.is_open()) {
std::cerr << "Could not open " << dls_file << std::endl;
@@ -206,7 +206,7 @@ void DLSManager::writeDLS(PADPacketizer& pad_packetizer, const std::string& dls_
if (line == DL_PARAMS_OPEN) {
parse_dl_params(dls_fstream, dl_state);
} else {
- if (not raw_dls && charset == CHARSET_UTF8) {
+ if (not raw_dls && charset == DABCharset::UTF8) {
dls_lines.push_back(charset_converter.convert(line));
}
else {
@@ -219,14 +219,14 @@ void DLSManager::writeDLS(PADPacketizer& pad_packetizer, const std::string& dls_
std::stringstream ss;
for (size_t i = 0; i < dls_lines.size(); i++) {
if (i != 0) {
- if (charset == CHARSET_UCS2_BE)
+ if (charset == DABCharset::UCS2_BE)
ss << '\0' << '\n';
else
ss << '\n';
}
// UCS-2 BE: if from file the first byte of \0\n remains, remove it
- if (charset == CHARSET_UCS2_BE && dls_lines[i].size() % 2) {
+ if (charset == DABCharset::UCS2_BE && dls_lines[i].size() % 2) {
dls_lines[i].resize(dls_lines[i].size() - 1);
}
@@ -243,7 +243,7 @@ void DLSManager::writeDLS(PADPacketizer& pad_packetizer, const std::string& dls_
dl_state.dl_plus_tags.push_back(DL_PLUS_TAG());
if (not raw_dls)
- charset = CHARSET_COMPLETE_EBU_LATIN;
+ charset = DABCharset::COMPLETE_EBU_LATIN;
// toggle the toggle bit only on new DL state
@@ -275,9 +275,9 @@ void DLSManager::writeDLS(PADPacketizer& pad_packetizer, const std::string& dls_
dl_state_prev = dl_state;
}
- prepend_dl_dgs(pad_packetizer, dl_state, charset);
+ prepend_dl_dgs(dl_state, charset);
if (remove_label_dg)
- pad_packetizer.AddDG(remove_label_dg, true);
+ pad_packetizer->AddDG(remove_label_dg, true);
}
@@ -287,7 +287,7 @@ int DLSManager::dls_count(const std::string& text) {
}
-DATA_GROUP* DLSManager::dls_get(const std::string& text, uint8_t charset, int seg_index) {
+DATA_GROUP* DLSManager::dls_get(const std::string& text, DABCharset charset, int seg_index) {
bool first_seg = seg_index == 0;
bool last_seg = seg_index == dls_count(text) - 1;
@@ -306,7 +306,7 @@ DATA_GROUP* DLSManager::dls_get(const std::string& text, uint8_t charset, int se
(seg_text_len - 1);
// prefix: charset / seg index
- seg_data[1] = (first_seg ? charset : seg_index) << 4;
+ seg_data[1] = (first_seg ? (uint8_t) charset : seg_index) << 4;
// character field
memcpy(&seg_data[DLS_SEG_LEN_PREFIX], seg_text_start, seg_text_len);
@@ -324,7 +324,7 @@ DATA_GROUP* DLSManager::dls_get(const std::string& text, uint8_t charset, int se
}
-void DLSManager::prepend_dl_dgs(PADPacketizer& pad_packetizer, const DL_STATE& dl_state, uint8_t charset) {
+void DLSManager::prepend_dl_dgs(const DL_STATE& dl_state, DABCharset charset) {
// process all DL segments
int seg_count = dls_count(dl_state.dl_text);
std::vector<DATA_GROUP*> segs;
@@ -340,7 +340,7 @@ void DLSManager::prepend_dl_dgs(PADPacketizer& pad_packetizer, const DL_STATE& d
segs.push_back(createDynamicLabelPlus(dl_state));
// prepend to packetizer
- pad_packetizer.AddDGs(segs, true);
+ pad_packetizer->AddDGs(segs, true);
#ifdef DEBUG
fprintf(stderr, "PAD length: %d\n", padlen);
diff --git a/src/dls.h b/src/dls.h
index f9e5c57..547c1df 100644
--- a/src/dls.h
+++ b/src/dls.h
@@ -37,16 +37,6 @@
#include "charset.h"
-// Charsets from TS 101 756
-enum {
- CHARSET_COMPLETE_EBU_LATIN = 0, //!< Complete EBU Latin based repertoire
- CHARSET_EBU_LATIN_CY_GR = 1, //!< EBU Latin based common core, Cyrillic, Greek
- CHARSET_EBU_LATIN_AR_HE_CY_GR = 2, //!< EBU Latin based core, Arabic, Hebrew, Cyrillic and Greek
- CHARSET_ISO_LATIN_ALPHABET_2 = 3, //!< ISO Latin Alphabet No 2
- CHARSET_UCS2_BE = 6, //!< ISO/IEC 10646 using UCS-2 transformation format, big endian byte order
- CHARSET_UTF8 = 15 //!< ISO Latin Alphabet No 2
-};
-
// DL/DL+ commands
enum {
DLS_CMD_REMOVE_LABEL = 0b0001,
@@ -134,9 +124,10 @@ private:
bool parse_dl_param_int_dl_plus_tag(const std::string &key, const std::string &value, int &target);
void parse_dl_params(std::ifstream &dls_fstream, DL_STATE &dl_state);
int dls_count(const std::string& text);
- DATA_GROUP* dls_get(const std::string& text, uint8_t charset, int seg_index);
- void prepend_dl_dgs(PADPacketizer& pad_packetizer, const DL_STATE& dl_state, uint8_t charset);
+ DATA_GROUP* dls_get(const std::string& text, DABCharset charset, int seg_index);
+ void prepend_dl_dgs(const DL_STATE& dl_state, DABCharset charset);
+ PADPacketizer* pad_packetizer;
CharsetConverter charset_converter;
bool dls_toggle;
DL_STATE dl_state_prev;
@@ -148,8 +139,8 @@ public:
static const std::string DL_PARAMS_OPEN;
static const std::string DL_PARAMS_CLOSE;
- DLSManager() : dls_toggle(false) {}
- void writeDLS(PADPacketizer& pad_packetizer, const std::string& dls_file, uint8_t charset, bool raw_dls, bool remove_dls);
+ DLSManager(PADPacketizer* pad_packetizer) : pad_packetizer(pad_packetizer), dls_toggle(false) {}
+ void writeDLS(const std::string& dls_file, DABCharset charset, bool raw_dls, bool remove_dls);
};
#endif /* DLS_H_ */
diff --git a/src/odr-padenc.cpp b/src/odr-padenc.cpp
index c2a7c33..87fadb2 100644
--- a/src/odr-padenc.cpp
+++ b/src/odr-padenc.cpp
@@ -51,10 +51,7 @@
-#define SLEEPDELAY_DEFAULT 10 // seconds
-
-#define XSTR(x) #x
-#define STR(x) XSTR(x)
+static const int SLEEPDELAY_DEFAULT = 10; // seconds
static const size_t MAXSEGLEN = 8189; // Bytes (EN 301 234 v2.1.1, ch. 5.1.1)
static const size_t MAXSLIDESIZE = 51200; // Bytes (TS 101 499 v3.1.1, ch. 9.1.2)
@@ -332,7 +329,7 @@ void usage(char* name)
" -e, --erase Erase slides from DIRNAME once they have\n"
" been encoded.\n"
" -s, --sleep=DELAY Wait DELAY seconds between each slide\n"
- " Default: " STR(SLEEPDELAY_DEFAULT) "\n"
+ " Default: %d\n"
" -o, --output=FILENAME Fifo to write PAD data into.\n"
" Default: /tmp/pad.fifo\n"
" -t, --dls=FILENAME Fifo or file to read DLS text from.\n"
@@ -351,7 +348,7 @@ void usage(char* name)
" slides is skipped. Use this if you know what you are doing !\n"
" It is useful only when -d is used\n"
" -v, --verbose Print more information to the console\n",
- PADPacketizer::ALLOWED_PADLEN.c_str()
+ SLEEPDELAY_DEFAULT, PADPacketizer::ALLOWED_PADLEN.c_str()
);
}
@@ -366,7 +363,7 @@ int main(int argc, char *argv[])
bool erase_after_tx = false;
int sleepdelay = SLEEPDELAY_DEFAULT;
bool raw_slides = false;
- int charset = CHARSET_UTF8;
+ DABCharset charset = DABCharset::UTF8;
bool raw_dls = false;
bool remove_dls = false;
@@ -396,7 +393,7 @@ int main(int argc, char *argv[])
ch = getopt_long(argc, argv, "eChRrc:d:o:p:s:t:v", longopts, &index);
switch (ch) {
case 'c':
- charset = atoi(optarg);
+ charset = (DABCharset) atoi(optarg);
break;
case 'C':
raw_dls = true;
@@ -461,46 +458,39 @@ int main(int argc, char *argv[])
const char* user_charset;
switch (charset) {
- case CHARSET_COMPLETE_EBU_LATIN:
+ case DABCharset::COMPLETE_EBU_LATIN:
user_charset = "Complete EBU Latin";
break;
- case CHARSET_EBU_LATIN_CY_GR:
+ case DABCharset::EBU_LATIN_CY_GR:
user_charset = "EBU Latin core, Cyrillic, Greek";
break;
- case CHARSET_EBU_LATIN_AR_HE_CY_GR:
+ case DABCharset::EBU_LATIN_AR_HE_CY_GR:
user_charset = "EBU Latin core, Arabic, Hebrew, Cyrillic, Greek";
break;
- case CHARSET_ISO_LATIN_ALPHABET_2:
+ case DABCharset::ISO_LATIN_ALPHABET_2:
user_charset = "ISO Latin Alphabet 2";
break;
- case CHARSET_UCS2_BE:
+ case DABCharset::UCS2_BE:
user_charset = "UCS-2 BE";
break;
- case CHARSET_UTF8:
+ case DABCharset::UTF8:
user_charset = "UTF-8";
break;
default:
- user_charset = "Invalid";
- charset = -1;
- break;
+ fprintf(stderr, "ODR-PadEnc Error: Invalid charset!\n");
+ usage(argv[0]);
+ return 1;
}
- if (charset == -1) {
- fprintf(stderr, "ODR-PadEnc Error: Invalid charset!\n");
- usage(argv[0]);
- return 1;
- }
- else {
- fprintf(stderr, "ODR-PadEnc using charset %s (%d)\n",
- user_charset, charset);
- }
+ fprintf(stderr, "ODR-PadEnc using charset %s (%d)\n",
+ user_charset, charset);
if (not raw_dls) {
switch (charset) {
- case CHARSET_COMPLETE_EBU_LATIN:
+ case DABCharset::COMPLETE_EBU_LATIN:
// no conversion needed
break;
- case CHARSET_UTF8:
+ case DABCharset::UTF8:
fprintf(stderr, "ODR-PadEnc converting DLS texts to Complete EBU Latin\n");
break;
default:
@@ -520,7 +510,7 @@ int main(int argc, char *argv[])
#endif
PADPacketizer pad_packetizer(padlen);
- DLSManager dls_manager;
+ DLSManager dls_manager(&pad_packetizer);
std::list<slide_metadata_t> slides_to_transmit;
History slides_history(MAXHISTORYLEN);
@@ -569,7 +559,7 @@ int main(int argc, char *argv[])
// if ATM no slides, transmit at least DLS
if (slides_to_transmit.empty()) {
if (not dls_file.empty()) {
- dls_manager.writeDLS(pad_packetizer, dls_file, charset, raw_dls, remove_dls);
+ dls_manager.writeDLS(dls_file, charset, raw_dls, remove_dls);
pad_packetizer.WriteAllPADs(output_fd);
}
@@ -597,14 +587,14 @@ int main(int argc, char *argv[])
// while flushing, insert DLS after a certain PAD amout
while (pad_packetizer.QueueFilled()) {
if (not dls_file.empty())
- dls_manager.writeDLS(pad_packetizer, dls_file, charset, raw_dls, remove_dls);
+ dls_manager.writeDLS(dls_file, charset, raw_dls, remove_dls);
pad_packetizer.WriteAllPADs(output_fd, DLSManager::DLS_REPETITION_WHILE_SLS);
}
// after the slide, output a last DLS
if (not dls_file.empty())
- dls_manager.writeDLS(pad_packetizer, dls_file, charset, raw_dls, remove_dls);
+ dls_manager.writeDLS(dls_file, charset, raw_dls, remove_dls);
pad_packetizer.WriteAllPADs(output_fd);
sleep(sleepdelay);
@@ -614,7 +604,7 @@ int main(int argc, char *argv[])
}
} else { // only DLS
// Always retransmit DLS, we want it to be updated frequently
- dls_manager.writeDLS(pad_packetizer, dls_file, charset, raw_dls, remove_dls);
+ dls_manager.writeDLS(dls_file, charset, raw_dls, remove_dls);
pad_packetizer.WriteAllPADs(output_fd);
sleep(sleepdelay);
@@ -1064,7 +1054,7 @@ uint8_vector_t createMotHeader(size_t blobsize, int fidx, bool jfif_not_png, con
{
// prepare ContentName
uint8_t cntemp[10]; // = 1 + 8 + 1 = charset + name + terminator
- cntemp[0] = 0x0 << 4; // charset: 0 (Complete EBU Latin based) - doesn't really matter here
+ cntemp[0] = (uint8_t) DABCharset::COMPLETE_EBU_LATIN << 4;
snprintf((char*) (cntemp + 1), sizeof(cntemp) - 1, "%04d.%s", fidx, jfif_not_png ? "jpg" : "png");
// MOT header - content type: image, content subtype: JFIF / PNG
diff --git a/src/pad_common.h b/src/pad_common.h
index e855625..71e7b76 100644
--- a/src/pad_common.h
+++ b/src/pad_common.h
@@ -46,6 +46,15 @@ typedef std::vector<uint8_t> uint8_vector_t;
typedef uint8_vector_t pad_t;
+// Charsets from TS 101 756
+enum class DABCharset : uint8_t {
+ COMPLETE_EBU_LATIN = 0, //!< Complete EBU Latin based repertoire
+ EBU_LATIN_CY_GR = 1, //!< EBU Latin based common core, Cyrillic, Greek
+ EBU_LATIN_AR_HE_CY_GR = 2, //!< EBU Latin based core, Arabic, Hebrew, Cyrillic and Greek
+ ISO_LATIN_ALPHABET_2 = 3, //!< ISO Latin Alphabet No 2
+ UCS2_BE = 6, //!< ISO/IEC 10646 using UCS-2 transformation format, big endian byte order
+ UTF8 = 15 //!< ISO Latin Alphabet No 2
+};
// --- DATA_GROUP -----------------------------------------------------------------
struct DATA_GROUP {