diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/odr-padenc.cpp | 110 | ||||
| -rw-r--r-- | src/odr-padenc.h | 2 | ||||
| -rw-r--r-- | src/sls.cpp | 20 | ||||
| -rw-r--r-- | src/sls.h | 6 | 
4 files changed, 76 insertions, 62 deletions
diff --git a/src/odr-padenc.cpp b/src/odr-padenc.cpp index 461502e..8ae06f2 100644 --- a/src/odr-padenc.cpp +++ b/src/odr-padenc.cpp @@ -56,43 +56,46 @@ static void header() {  static void usage(const char* name) {      PadEncoderOptions options_default;      fprintf(stderr, "Usage: %s [OPTIONS...]\n", name); -    fprintf(stderr, " -d, --dir=DIRNAME      Directory to read images from.\n" -                    " -e, --erase            Erase slides from DIRNAME once they have\n" -                    "                          been encoded.\n" -                    " -s, --sleep=DUR        Wait DUR seconds between each slide\n" -                    "                          Default: %d\n" -                    " -o, --output=FILENAME  FIFO to write PAD data into.\n" -                    "                          Default: %s\n" -                    " -t, --dls=FILENAME     FIFO or file to read DLS text from.\n" -                    "                          If specified more than once, use next file after slide switch (for uniform PAD encoder, -l is used instead).\n" -                    " -p, --pad=LENGTH       Set the PAD length.\n" -                    "                          Possible values: %s\n" -                    "                          Default: %zu\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 =  6: ISO/IEC 10646 using UCS-2 BE\n" -                    "                          ID = 15: ISO/IEC 10646 using UTF-8\n" -                    "                          Default: 15\n" -                    " -r, --remove-dls       Always insert a DLS Remove Label command when replacing a DLS text.\n" -                    " -C, --raw-dls          Do not convert DLS texts to Complete EBU Latin based repertoire\n" -                    "                          character set encoding.\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" -                    " -v, --verbose          Print more information to the console\n" +    fprintf(stderr, " -d, --dir=DIRNAME         Directory to read images from.\n" +                    " -e, --erase               Erase slides from DIRNAME once they have\n" +                    "                             been encoded.\n" +                    " -s, --sleep=DUR           Wait DUR seconds between each slide\n" +                    "                             Default: %d\n" +                    " -o, --output=FILENAME     FIFO to write PAD data into.\n" +                    "                             Default: %s\n" +                    " -t, --dls=FILENAME        FIFO or file to read DLS text from.\n" +                    "                             If specified more than once, use next file after slide switch (for uniform PAD encoder, -l is used instead).\n" +                    " -p, --pad=LENGTH          Set the PAD length in bytes.\n" +                    "                             Possible values: %s\n" +                    "                             Default: %zu\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 =  6: ISO/IEC 10646 using UCS-2 BE\n" +                    "                             ID = 15: ISO/IEC 10646 using UTF-8\n" +                    "                             Default: 15\n" +                    " -r, --remove-dls          Always insert a DLS Remove Label command when replacing a DLS text.\n" +                    " -C, --raw-dls             Do not convert DLS texts to Complete EBU Latin based repertoire\n" +                    "                             character set encoding.\n" +                    " -m, --max-slide-size=SIZE Recompress slide if above the specified maximum size in bytes.\n" +                    "                             Default: %zu (Simple Profile)\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" +                    " -v, --verbose             Print more information to the console\n"                      "\n"                      "Parameters for uniform PAD encoder only:\n" -                    " -f, --frame-dur=DUR    Enable the uniform PAD encoder and set the duration of one frame/AU in milliseconds.\n" -                    " -l, --label=DUR        Wait DUR seconds between each label (if more than one file used)\n" -                    "                          Default: %d\n" -                    " -L, --label-ins=DUR    Insert label every DUR milliseconds\n" -                    "                          Default: %d\n" -                    " -i, --init-burst=COUNT Sets a PAD burst amount to initially fill the output FIFO\n" -                    "                          Default: %d\n", +                    " -f, --frame-dur=DUR       Enable the uniform PAD encoder and set the duration of one frame/AU in milliseconds.\n" +                    " -l, --label=DUR           Wait DUR seconds between each label (if more than one file used)\n" +                    "                             Default: %d\n" +                    " -L, --label-ins=DUR       Insert label every DUR milliseconds\n" +                    "                             Default: %d\n" +                    " -i, --init-burst=COUNT    Sets a PAD burst amount to initially fill the output FIFO\n" +                    "                             Default: %d\n",                      options_default.slide_interval,                      options_default.output,                      PADPacketizer::ALLOWED_PADLEN.c_str(),                      options_default.padlen, +                    options_default.max_slide_size,                      options_default.label_interval,                      options_default.label_insertion,                      options_default.init_burst @@ -118,27 +121,28 @@ int main(int argc, char *argv[]) {      PadEncoderOptions options;      const struct option longopts[] = { -        {"charset",    required_argument,  0, 'c'}, -        {"raw-dls",    no_argument,        0, 'C'}, -        {"remove-dls", no_argument,        0, 'r'}, -        {"dir",        required_argument,  0, 'd'}, -        {"erase",      no_argument,        0, 'e'}, -        {"output",     required_argument,  0, 'o'}, -        {"dls",        required_argument,  0, 't'}, -        {"pad",        required_argument,  0, 'p'}, -        {"sleep",      required_argument,  0, 's'}, -        {"raw-slides", no_argument,        0, 'R'}, -        {"help",       no_argument,        0, 'h'}, -        {"frame-dur",  required_argument,  0, 'f'}, -        {"label",      required_argument,  0, 'l'}, -        {"label-ins",  required_argument,  0, 'L'}, -        {"init-burst", required_argument,  0, 'i'}, -        {"verbose",    no_argument,        0, 'v'}, +        {"charset",         required_argument,  0, 'c'}, +        {"raw-dls",         no_argument,        0, 'C'}, +        {"remove-dls",      no_argument,        0, 'r'}, +        {"dir",             required_argument,  0, 'd'}, +        {"erase",           no_argument,        0, 'e'}, +        {"output",          required_argument,  0, 'o'}, +        {"dls",             required_argument,  0, 't'}, +        {"pad",             required_argument,  0, 'p'}, +        {"sleep",           required_argument,  0, 's'}, +        {"max-slide-size",  required_argument,  0, 'm'}, +        {"raw-slides",      no_argument,        0, 'R'}, +        {"help",            no_argument,        0, 'h'}, +        {"frame-dur",       required_argument,  0, 'f'}, +        {"label",           required_argument,  0, 'l'}, +        {"label-ins",       required_argument,  0, 'L'}, +        {"init-burst",      required_argument,  0, 'i'}, +        {"verbose",         no_argument,        0, 'v'},          {0,0,0,0},      };      int ch; -    while((ch = getopt_long(argc, argv, "eChRrc:d:o:p:s:t:f:l:L:i:v", longopts, NULL)) != -1) { +    while((ch = getopt_long(argc, argv, "eChRrc:d:o:p:s:t:f:l:L:i:vm:", longopts, NULL)) != -1) {          switch (ch) {              case 'c':                  options.dl_params.charset = (DABCharset) atoi(optarg); @@ -167,6 +171,9 @@ int main(int argc, char *argv[]) {              case 'p':                  options.padlen = atoi(optarg);                  break; +            case 'm': +                options.max_slide_size = atoi(optarg); +                break;              case 'R':                  options.raw_slides = true;                  break; @@ -197,6 +204,11 @@ int main(int argc, char *argv[]) {                  options.padlen, PADPacketizer::ALLOWED_PADLEN.c_str());          return 2;      } +    if (options.max_slide_size > SLSEncoder::MAXSLIDESIZE_SIMPLE) { +        fprintf(stderr, "ODR-PadEnc Error: max slide size %zu exceeds Simple Profile limit %zu\n", +                options.max_slide_size, SLSEncoder::MAXSLIDESIZE_SIMPLE); +        return 2; +    }      if (options.sls_dir && not options.dls_files.empty()) {          fprintf(stderr, "ODR-PadEnc encoding Slideshow from '%s' and DLS from %s to '%s' (PAD length: %zu)\n", @@ -381,7 +393,7 @@ int PadEncoder::EncodeSlide(bool skip_if_already_queued) {          if (!slides.Empty()) {              slide_metadata_t slide = slides.GetSlide(); -            if (sls_encoder.encodeSlide(slide.filepath, slide.fidx, options.raw_slides)) { +            if (sls_encoder.encodeSlide(slide.filepath, slide.fidx, options.raw_slides, options.max_slide_size)) {                  slides_success = true;                  if (options.erase_after_tx) {                      if (unlink(slide.filepath.c_str())) diff --git a/src/odr-padenc.h b/src/odr-padenc.h index 9d941a4..10e2cae 100644 --- a/src/odr-padenc.h +++ b/src/odr-padenc.h @@ -57,6 +57,7 @@ struct PadEncoderOptions {      int label_interval;     // uniform PAD encoder only      int label_insertion;    // uniform PAD encoder only      int init_burst;         // uniform PAD encoder only +    size_t max_slide_size;      bool raw_slides;      DL_PARAMS dl_params; @@ -72,6 +73,7 @@ struct PadEncoderOptions {              label_interval(12),              label_insertion(1200),              init_burst(12), +            max_slide_size(SLSEncoder::MAXSLIDESIZE_SIMPLE),              raw_slides(false),              sls_dir(NULL),              output("/tmp/pad.fifo") diff --git a/src/sls.cpp b/src/sls.cpp index 8963b65..330454f 100644 --- a/src/sls.cpp +++ b/src/sls.cpp @@ -255,9 +255,9 @@ void MOTHeader::AddExtension(int param_id, const uint8_t* data_field, size_t dat  // --- SLSEncoder ----------------------------------------------------------------- -const size_t SLSEncoder::MAXSEGLEN       =  8189; // Bytes (EN 301 234 v2.1.1, ch. 5.1.1) -const size_t SLSEncoder::MAXSLIDESIZE    = 51200; // Bytes (TS 101 499 v3.1.1, ch. 9.1.2) -const int    SLSEncoder::MINQUALITY      =    40; // Do not allow the image compressor to go below JPEG quality 40 +const size_t SLSEncoder::MAXSEGLEN              =  8189; // Bytes (EN 301 234 v2.1.1, ch. 5.1.1) +const size_t SLSEncoder::MAXSLIDESIZE_SIMPLE    = 51200; // Bytes (TS 101 499 v3.1.1, ch. 9.1.2) +const int    SLSEncoder::MINQUALITY             =    40; // Do not allow the image compressor to go below JPEG quality 40  const std::string SLSEncoder::SLS_PARAMS_SUFFIX = ".sls_params";  const int SLSEncoder::APPTYPE_MOT_START = 12;  const int SLSEncoder::APPTYPE_MOT_CONT = 13; @@ -278,7 +278,7 @@ void SLSEncoder::warnOnSmallerImage(size_t height, size_t width, const std::stri   * \return the blobsize   */  #if HAVE_MAGICKWAND -size_t SLSEncoder::resizeImage(MagickWand* m_wand, unsigned char** blob, const std::string& fname, bool* jfif_not_png) +size_t SLSEncoder::resizeImage(MagickWand* m_wand, unsigned char** blob, const std::string& fname, bool* jfif_not_png, size_t max_slide_size)  {      unsigned char* blob_png;      unsigned char* blob_jpg; @@ -323,11 +323,11 @@ size_t SLSEncoder::resizeImage(MagickWand* m_wand, unsigned char** blob, const s          MagickSetImageCompressionQuality(m_wand, quality_jpg);          blob_jpg = MagickGetImageBlob(m_wand, &blobsize_jpg); -    } while (blobsize_jpg > MAXSLIDESIZE && quality_jpg > MINQUALITY); +    } while (blobsize_jpg > max_slide_size && quality_jpg > MINQUALITY);      // check for max size -    if (blobsize_png > MAXSLIDESIZE && blobsize_jpg > MAXSLIDESIZE) { +    if (blobsize_png > max_slide_size && blobsize_jpg > max_slide_size) {          fprintf(stderr, "ODR-PadEnc: Image Size too large after compression: %zu bytes (PNG), %zu bytes (JPEG)\n",                  blobsize_png, blobsize_jpg);          MagickRelinquishMemory(blob_png); @@ -357,7 +357,7 @@ size_t SLSEncoder::resizeImage(MagickWand* m_wand, unsigned char** blob, const s  #endif -bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides) +bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides, size_t max_slide_size)  {      bool result = false; @@ -441,7 +441,7 @@ bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides              // Don't recompress the image and check if the blobsize is suitable              blob = MagickGetImageBlob(m_wand, &blobsize); -            if (blobsize <= MAXSLIDESIZE) { +            if (blobsize <= max_slide_size) {                  if (verbose) {                      fprintf(stderr, "ODR-PadEnc image: '" ODR_COLOR_SLS "%s" ODR_COLOR_RST "' (id=%d).  No resize needed: %zu Bytes\n",                              fname.c_str(), fidx, blobsize); @@ -454,7 +454,7 @@ bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides          }          if (resize_required) { -            blobsize = resizeImage(m_wand, &blob, fname, &jfif_not_png); +            blobsize = resizeImage(m_wand, &blob, fname, &jfif_not_png, max_slide_size);          } else {              // warn if unresized image smaller than default dimension              warnOnSmallerImage(height, width, fname); @@ -483,7 +483,7 @@ bool SLSEncoder::encodeSlide(const std::string& fname, int fidx, bool raw_slides                      fname.c_str(), fidx, blobsize);          } -        if (blobsize > MAXSLIDESIZE) { +        if (blobsize > max_slide_size) {              fprintf(stderr, "ODR-PadEnc Warning: blob in raw-slide '%s' too large\n",                      fname.c_str());          } @@ -224,13 +224,12 @@ public:  class SLSEncoder {  private:      static const size_t MAXSEGLEN; -    static const size_t MAXSLIDESIZE;      static const int    MINQUALITY;      static const std::string SLS_PARAMS_SUFFIX;      void warnOnSmallerImage(size_t height, size_t width, const std::string& fname);  #if HAVE_MAGICKWAND -    size_t resizeImage(MagickWand* m_wand, unsigned char** blob, const std::string& fname, bool* jfif_not_png); +    size_t resizeImage(MagickWand* m_wand, unsigned char** blob, const std::string& fname, bool* jfif_not_png, size_t max_slide_size);  #endif      bool parse_sls_param_id(const std::string &key, const std::string &value, uint8_t &target);      bool check_sls_param_len(const std::string &key, size_t len, size_t len_max); @@ -246,13 +245,14 @@ private:      int cindex_header;      int cindex_body;  public: +    static const size_t MAXSLIDESIZE_SIMPLE;      static const int APPTYPE_MOT_START;      static const int APPTYPE_MOT_CONT;      static const std::string REQUEST_REREAD_FILENAME;      SLSEncoder(PADPacketizer* pad_packetizer) : pad_packetizer(pad_packetizer), cindex_header(0), cindex_body(0) {} -    bool encodeSlide(const std::string& fname, int fidx, bool raw_slides); +    bool encodeSlide(const std::string& fname, int fidx, bool raw_slides, size_t max_slide_size);      static bool isSlideParamFileFilename(const std::string& filename);  };  | 
