aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/odr-padenc.cpp48
-rw-r--r--src/odr-padenc.h22
2 files changed, 46 insertions, 24 deletions
diff --git a/src/odr-padenc.cpp b/src/odr-padenc.cpp
index d42d688..01385d0 100644
--- a/src/odr-padenc.cpp
+++ b/src/odr-padenc.cpp
@@ -232,7 +232,7 @@ int main(int argc, char *argv[]) {
}
// invoke encoder
- pad_encoder = new PadEncoder(options);
+ pad_encoder = new BurstPadEncoder(options);
int result = pad_encoder->Main();
delete pad_encoder;
@@ -241,8 +241,6 @@ int main(int argc, char *argv[]) {
// --- PadEncoder -----------------------------------------------------------------
-const int PadEncoder::DLS_REPETITION_WHILE_SLS = 50; // PADs
-
void PadEncoder::DoExit() {
std::lock_guard<std::mutex> lock(status_mutex);
@@ -250,7 +248,7 @@ void PadEncoder::DoExit() {
}
int PadEncoder::Main() {
- int output_fd = open(options.output, O_WRONLY);
+ output_fd = open(options.output, O_WRONLY);
if (output_fd == -1) {
perror("ODR-PadEnc Error: failed to open output");
return 3;
@@ -262,11 +260,6 @@ int PadEncoder::Main() {
fprintf(stderr, "ODR-PadEnc using ImageMagick version '%s'\n", GetMagickVersion(NULL));
#endif
- PADPacketizer pad_packetizer(options.padlen);
- DLSManager dls_manager(&pad_packetizer);
- SLSManager sls_manager(&pad_packetizer);
- SlideStore slides;
-
// handle signals
if(signal(SIGINT, break_handler) == SIG_ERR) {
perror("ODR-PadEnc Error: could not set SIGINT handler");
@@ -281,6 +274,32 @@ int PadEncoder::Main() {
return 1;
}
+ // invoke actual encoder
+ int result = Encode();
+
+ // cleanup
+ if(close(output_fd)) {
+ perror("ODR-PadEnc Error: failed to close output");
+ return 1;
+ }
+
+#if HAVE_MAGICKWAND
+ MagickWandTerminus();
+#endif
+
+ return result;
+}
+
+
+// --- BurstPadEncoder -----------------------------------------------------------------
+const int BurstPadEncoder::DLS_REPETITION_WHILE_SLS = 50; // PADs
+
+int BurstPadEncoder::Encode() {
+ PADPacketizer pad_packetizer(options.padlen);
+ DLSManager dls_manager(&pad_packetizer);
+ SLSManager sls_manager(&pad_packetizer);
+ SlideStore slides;
+
std::chrono::steady_clock::time_point next_run = std::chrono::steady_clock::now();
int curr_dls_file = 0;
@@ -328,16 +347,5 @@ int PadEncoder::Main() {
std::this_thread::sleep_until(next_run);
}
-
- // cleanup
- if(close(output_fd)) {
- perror("ODR-PadEnc Error: failed to close output");
- return 1;
- }
-
-#if HAVE_MAGICKWAND
- MagickWandTerminus();
-#endif
-
return 0;
}
diff --git a/src/odr-padenc.h b/src/odr-padenc.h
index ce77c27..e29542b 100644
--- a/src/odr-padenc.h
+++ b/src/odr-padenc.h
@@ -69,16 +69,30 @@ struct PadEncoderOptions {
// --- PadEncoder -----------------------------------------------------------------
class PadEncoder {
-private:
- static const int DLS_REPETITION_WHILE_SLS;
-
+protected:
PadEncoderOptions options;
+ int output_fd;
std::mutex status_mutex;
bool do_exit;
+
+ PadEncoder(PadEncoderOptions options) : options(options), output_fd(-1), do_exit(false) {}
+
+ virtual int Encode() = 0;
public:
- PadEncoder(PadEncoderOptions options) : options(options), do_exit(false) {}
+ virtual ~PadEncoder() {}
int Main();
void DoExit();
};
+
+
+// --- BurstPadEncoder -----------------------------------------------------------------
+class BurstPadEncoder : public PadEncoder {
+private:
+ static const int DLS_REPETITION_WHILE_SLS;
+
+ int Encode();
+public:
+ BurstPadEncoder(PadEncoderOptions options) : PadEncoder(options) {}
+};