summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-07-09 23:18:40 +0200
committerCarl Hetherington <cth@carlh.net>2024-01-28 02:01:57 +0100
commit305f0b5201b3e968f34c2780b43b8227b3559e7f (patch)
treeecd748bce0dc0cce2f2a3254e981c3e10484a648 /src/lib
parentdabc316eb22a4c84a15b266bf07f335a6cd9dca3 (diff)
Change end() to only do one thing, and copy the required stuff into pause()
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dcp_encoder.cc2
-rw-r--r--src/lib/j2k_encoder.cc82
-rw-r--r--src/lib/j2k_encoder.h2
3 files changed, 48 insertions, 38 deletions
diff --git a/src/lib/dcp_encoder.cc b/src/lib/dcp_encoder.cc
index a03f689b0..1b1b117be 100644
--- a/src/lib/dcp_encoder.cc
+++ b/src/lib/dcp_encoder.cc
@@ -114,7 +114,7 @@ DCPEncoder::go ()
}
_finishing = true;
- _j2k_encoder.end(true);
+ _j2k_encoder.end();
_writer.finish(_film->dir(_film->dcp_name()));
}
diff --git a/src/lib/j2k_encoder.cc b/src/lib/j2k_encoder.cc
index defde2227..0b0cadfeb 100644
--- a/src/lib/j2k_encoder.cc
+++ b/src/lib/j2k_encoder.cc
@@ -93,37 +93,48 @@ J2KEncoder::begin ()
void
J2KEncoder::pause()
{
- if (Config::instance()->enable_gpu()) {
- end(false);
+ if (!Config::instance()->enable_gpu()) {
+ return;
}
+
+ {
+ boost::mutex::scoped_lock lm (_threads_mutex);
+ terminate_threads ();
+ }
+
+ /* Something might have been thrown during terminate_threads */
+ rethrow ();
+
+ delete _context;
+ _context = nullptr;
}
void J2KEncoder::resume()
{
- if (Config::instance()->enable_gpu()) {
- _context = new grk_plugin::GrokContext(_dcpomatic_context);
- servers_list_changed();
+ if (!Config::instance()->enable_gpu()) {
+ return;
}
+
+ _context = new grk_plugin::GrokContext(_dcpomatic_context);
+ servers_list_changed();
}
void
-J2KEncoder::end (bool isFinal)
+J2KEncoder::end()
{
- if (isFinal) {
- boost::mutex::scoped_lock lock (_queue_mutex);
+ boost::mutex::scoped_lock lock (_queue_mutex);
- LOG_GENERAL (N_("Clearing queue of %1"), _queue.size ());
+ LOG_GENERAL (N_("Clearing queue of %1"), _queue.size ());
- /* Keep waking workers until the queue is empty */
- while (!_queue.empty ()) {
- rethrow ();
- _empty_condition.notify_all ();
- _full_condition.wait (lock);
- }
- lock.unlock ();
- }
+ /* Keep waking workers until the queue is empty */
+ while (!_queue.empty ()) {
+ rethrow ();
+ _empty_condition.notify_all ();
+ _full_condition.wait (lock);
+ }
+ lock.unlock ();
LOG_GENERAL_NC (N_("Terminating encoder threads"));
@@ -145,29 +156,28 @@ J2KEncoder::end (bool isFinal)
So just mop up anything left in the queue here.
*/
- if (isFinal) {
- for (auto & i: _queue) {
- if (Config::instance()->enable_gpu ()) {
- if (!_context->scheduleCompress(i)){
- LOG_GENERAL (N_("[%1] J2KEncoder thread pushes frame %2 back onto queue after failure"), thread_id(), i.index());
- // handle error
- }
+ for (auto & i: _queue) {
+ if (Config::instance()->enable_gpu ()) {
+ if (!_context->scheduleCompress(i)){
+ LOG_GENERAL (N_("[%1] J2KEncoder thread pushes frame %2 back onto queue after failure"), thread_id(), i.index());
+ // handle error
}
- else {
- LOG_GENERAL(N_("Encode left-over frame %1"), i.index());
- try {
- _writer.write(
- make_shared<dcp::ArrayData>(i.encode_locally()),
- i.index(),
- i.eyes()
- );
- frame_done ();
- } catch (std::exception& e) {
- LOG_ERROR (N_("Local encode failed (%1)"), e.what ());
- }
+ }
+ else {
+ LOG_GENERAL(N_("Encode left-over frame %1"), i.index());
+ try {
+ _writer.write(
+ make_shared<dcp::ArrayData>(i.encode_locally()),
+ i.index(),
+ i.eyes()
+ );
+ frame_done ();
+ } catch (std::exception& e) {
+ LOG_ERROR (N_("Local encode failed (%1)"), e.what ());
}
}
}
+
delete _context;
_context = nullptr;
}
diff --git a/src/lib/j2k_encoder.h b/src/lib/j2k_encoder.h
index 1d31274b3..433a0498f 100644
--- a/src/lib/j2k_encoder.h
+++ b/src/lib/j2k_encoder.h
@@ -74,7 +74,7 @@ public:
void resume();
/** Called when a processing run has finished */
- void end (bool isFinal);
+ void end();
boost::optional<float> current_encoding_rate () const;
int video_frames_enqueued () const;