aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Pöschel <github@basicmaster.de>2018-02-15 16:28:39 +0100
committerStefan Pöschel <github@basicmaster.de>2018-02-15 16:28:39 +0100
commit6d7667155dca929544fbcc362286df2618ed60d0 (patch)
tree443f75e77c35a3e469b90ddbdb6b29f5ebfa39b2
parent434e6e95a04e96a3265c2394f2304cfb3a932f10 (diff)
downloadODR-PadEnc-6d7667155dca929544fbcc362286df2618ed60d0.tar.gz
ODR-PadEnc-6d7667155dca929544fbcc362286df2618ed60d0.tar.bz2
ODR-PadEnc-6d7667155dca929544fbcc362286df2618ed60d0.zip
SLS: skip to next working slide on problem
When a slide cannot be encoded, skip to the next slide that works. To prevent an infinite loop, no skipping is done when the last slide of the slide store doesn't work and also no earlier slide of it worked.
-rw-r--r--src/odr-padenc.cpp45
-rw-r--r--src/odr-padenc.h2
2 files changed, 32 insertions, 15 deletions
diff --git a/src/odr-padenc.cpp b/src/odr-padenc.cpp
index 6506012..94f3d68 100644
--- a/src/odr-padenc.cpp
+++ b/src/odr-padenc.cpp
@@ -350,23 +350,38 @@ int PadEncoder::EncodeSlide(bool skip_if_already_queued) {
return 0;
}
- // try to read slides dir (if present)
- if (slides.Empty()) {
- if (!slides.InitFromDir(options.sls_dir))
- return 1;
- }
-
- // if slides available, encode the first one
- if (!slides.Empty()) {
- slide_metadata_t slide = slides.GetSlide();
-
- if (!sls_encoder.encodeSlide(slide.filepath, slide.fidx, options.raw_slides))
- fprintf(stderr, "ODR-PadEnc Error: cannot encode file '%s'\n", slide.filepath.c_str());
+ // usually invoked once
+ for(;;) {
+ // try to read slides dir (if present)
+ if (slides.Empty()) {
+ if (!slides.InitFromDir(options.sls_dir))
+ return 1;
+ slides_success = false;
+ }
- if (options.erase_after_tx) {
- if (unlink(slide.filepath.c_str()) == -1)
- perror(("ODR-PadEnc Error: erasing file '" + slide.filepath +"' failed").c_str());
+ // if slides available, encode the first one
+ if (!slides.Empty()) {
+ slide_metadata_t slide = slides.GetSlide();
+
+ if (sls_encoder.encodeSlide(slide.filepath, slide.fidx, options.raw_slides)) {
+ slides_success = true;
+ if (options.erase_after_tx) {
+ if (unlink(slide.filepath.c_str()) == -1)
+ perror(("ODR-PadEnc Error: erasing file '" + slide.filepath +"' failed").c_str());
+ }
+ } else {
+ /* skip to next slide, except this is the last slide and so far
+ * no slide worked, to prevent an infinite loop and because
+ * re-reading the slides dir just moments later won't result in
+ * a different amount of slides. */
+ bool skipping = !(slides.Empty() && !slides_success);
+ fprintf(stderr, "ODR-PadEnc Error: cannot encode file '%s'; %s\n", slide.filepath.c_str(), skipping ? "skipping" : "giving up for now");
+ if (skipping)
+ continue;
+ }
}
+
+ break;
}
return 0;
diff --git a/src/odr-padenc.h b/src/odr-padenc.h
index 46290f5..9d941a4 100644
--- a/src/odr-padenc.h
+++ b/src/odr-padenc.h
@@ -90,6 +90,7 @@ protected:
DLSEncoder dls_encoder;
SLSEncoder sls_encoder;
SlideStore slides;
+ bool slides_success;
int curr_dls_file;
int output_fd;
steady_clock::time_point run_timeline;
@@ -101,6 +102,7 @@ protected:
pad_packetizer(PADPacketizer(options.padlen)),
dls_encoder(DLSEncoder(&pad_packetizer)),
sls_encoder(SLSEncoder(&pad_packetizer)),
+ slides_success(false),
curr_dls_file(0),
output_fd(-1),
run_timeline(steady_clock::now()),