From ad279f82072b0dffa376e95abb67b655fbf902ed Mon Sep 17 00:00:00 2001 From: Stefan Pöschel Date: Thu, 23 Apr 2015 18:04:45 +0200 Subject: Make DLS conversion from (ATM only) UTF-8 to EBU Latin optional This (re-)introduces the ability to use DLS texts already having EBU Latin based charset (e.g. DAB retransmission of an FM station having RDS). The conversion from (ATM only) UTF-8 to EBU Latin based must now be enabled via parameter. If used, the charset parameter only affects the DLS text input. --- src/mot-encoder.cpp | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/mot-encoder.cpp b/src/mot-encoder.cpp index 0fd8859..60109f8 100644 --- a/src/mot-encoder.cpp +++ b/src/mot-encoder.cpp @@ -235,7 +235,7 @@ void writeMotPAD(int output_fd, unsigned short int padlen); void create_dls_pads(const std::string& text, const int padlen, const uint8_t charset); -void writeDLS(int output_fd, const std::string& dls_file, int padlen, uint8_t charset); +void writeDLS(int output_fd, const std::string& dls_file, int padlen, uint8_t charset, bool dls_to_ebu); int get_xpadlengthmask(int padlen); @@ -292,13 +292,15 @@ void usage(char* name) " -p, --pad=LENGTH Set the pad length.\n" " Possible values: " ALLOWED_PADLEN "\n" " Default: 58\n" - " -c, --charset=ID Signal the character set encoding defined by ID\n" - " ID = 0: Complete EBU Latin based repertoire\n" - " ID = 1: Latin based common core, Cyrillic, Greek\n" - " ID = 2: EBU Latin based core, Arabic, Hebrew, Cyrillic and Greek\n" - " ID = 3: ISO Latin Alphabet No 2\n" + " -c, --charset=ID ID of the character set encoding used for DLS text input.\n" + " ID = 0: Complete EBU Latin based repertoire\n" + " ID = 1: Latin based common core, Cyrillic, Greek\n" + " ID = 2: EBU Latin based core, Arabic, Hebrew, Cyrillic and Greek\n" + " ID = 3: ISO Latin Alphabet No 2\n" " ID = 15: ISO/IEC 10646 using UTF-8\n" " Default: 0\n" + " -C, --dls-to-ebu Convert each DLS text to Complete EBU Latin based repertoire\n" + " character set encoding (currently only from UTF-8).\n" " -R, --raw-slides Do not process slides. Integrity checks and resizing\n" " slides is skipped. Use this if you know what you are doing !\n" " It is useful only when -d is used\n" @@ -319,6 +321,7 @@ int main(int argc, char *argv[]) int sleepdelay = SLEEPDELAY_DEFAULT; bool raw_slides = false; int charset = CHARSET_COMPLETE_EBU_LATIN; + bool dls_to_ebu = false; const char* dir = NULL; const char* output = "/tmp/pad.fifo"; @@ -326,6 +329,7 @@ int main(int argc, char *argv[]) const struct option longopts[] = { {"charset", required_argument, 0, 'c'}, + {"dls-to-ebu", no_argument, 0, 'C'}, {"dir", required_argument, 0, 'd'}, {"erase", no_argument, 0, 'e'}, {"output", required_argument, 0, 'o'}, @@ -341,11 +345,14 @@ int main(int argc, char *argv[]) int ch=0; int index; while(ch != -1) { - ch = getopt_long(argc, argv, "ehRc:d:o:p:s:t:v", longopts, &index); + ch = getopt_long(argc, argv, "eChRc:d:o:p:s:t:v", longopts, &index); switch (ch) { case 'c': charset = atoi(optarg); break; + case 'C': + dls_to_ebu = true; + break; case 'd': dir = optarg; break; @@ -439,6 +446,14 @@ int main(int argc, char *argv[]) user_charset, charset); } + if (dls_to_ebu) { + if (charset != CHARSET_UTF8) { + fprintf(stderr, "mot-encoder Error: DLS conversion to EBU is currently only supported for UTF-8 input!\n"); + return 1; + } + fprintf(stderr, "mot-encoder converting DLS texts to Complete EBU Latin\n"); + } + int output_fd = open(output, O_WRONLY); if (output_fd == -1) { perror("mot-encoder Error: failed to open output"); @@ -486,7 +501,7 @@ int main(int argc, char *argv[]) if (not dls_file.empty()) { // Maybe we have no slides, always update DLS - writeDLS(output_fd, dls_file, padlen, charset); + writeDLS(output_fd, dls_file, padlen, charset, dls_to_ebu); sleep(sleepdelay); } @@ -510,7 +525,7 @@ int main(int argc, char *argv[]) // Always retransmit DLS after each slide, we want it to be updated frequently if (not dls_file.empty()) { - writeDLS(output_fd, dls_file, padlen, charset); + writeDLS(output_fd, dls_file, padlen, charset, dls_to_ebu); } sleep(sleepdelay); @@ -524,7 +539,7 @@ int main(int argc, char *argv[]) } else if (not dls_file.empty()) { // only DLS // Always retransmit DLS, we want it to be updated frequently - writeDLS(output_fd, dls_file, padlen, charset); + writeDLS(output_fd, dls_file, padlen, charset, dls_to_ebu); sleep(sleepdelay); } @@ -920,7 +935,7 @@ void packMscDG(unsigned char* b, MSCDG* msc, unsigned short int* bsize) } -void writeDLS(int output_fd, const std::string& dls_file, int padlen, uint8_t charset) +void writeDLS(int output_fd, const std::string& dls_file, int padlen, uint8_t charset, bool dls_to_ebu) { std::ifstream dls_fstream(dls_file.c_str()); if (!dls_fstream.is_open()) { @@ -935,7 +950,7 @@ void writeDLS(int output_fd, const std::string& dls_file, int padlen, uint8_t ch // line endings while (std::getline(dls_fstream, line)) { if (not line.empty()) { - if (charset == CHARSET_COMPLETE_EBU_LATIN) { + if (dls_to_ebu) { dls_lines.push_back(charset_converter.convert(line)); } else { @@ -944,6 +959,8 @@ void writeDLS(int output_fd, const std::string& dls_file, int padlen, uint8_t ch // TODO handle the other charsets accordingly } } + if (dls_to_ebu) + charset = CHARSET_COMPLETE_EBU_LATIN; std::stringstream ss; for (size_t i = 0; i < dls_lines.size(); i++) { -- cgit v1.2.3