From f8d0dac871883c7cbfa6f31c182ca3e6d213aed1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 24 Sep 2023 00:34:15 +0200 Subject: Rearrange encoder threading. Soon we'll add a new encoder type, and the existing structure was already creaking a bit at the seams while handling local and remote encodes. Here we split out an encoder thread and introduce the concept of a "sync" thread (which blocks while the encoding is happening). Later we'll have another type which submits the encode request to a GPU and receives the reply back later. --- src/lib/j2k_encoder.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/lib/j2k_encoder.h') diff --git a/src/lib/j2k_encoder.h b/src/lib/j2k_encoder.h index 840602dbb..a6e190dcf 100644 --- a/src/lib/j2k_encoder.h +++ b/src/lib/j2k_encoder.h @@ -33,6 +33,7 @@ #include "enum_indexed_vector.h" #include "event_history.h" #include "exception_store.h" +#include "j2k_encoder_thread.h" #include "writer.h" #include #include @@ -49,6 +50,10 @@ class Film; class Job; class PlayerVideo; +struct local_threads_created_and_destroyed; +struct remote_threads_created_and_destroyed; +struct frames_not_lost_when_threads_disappear; + /** @class J2KEncoder * @brief Class to manage encoding to J2K. @@ -80,13 +85,18 @@ public: boost::optional current_encoding_rate () const; int video_frames_enqueued () const; - void servers_list_changed (); + DCPVideo pop(); + void retry(DCPVideo frame); + void write(std::shared_ptr data, int index, Eyes eyes); private: + friend struct ::local_threads_created_and_destroyed; + friend struct ::remote_threads_created_and_destroyed; + friend struct ::frames_not_lost_when_threads_disappear; void frame_done (); - - void encoder_thread (boost::optional); + void servers_list_changed (); + void remake_threads(int cpu, int gpu, std::list servers); void terminate_threads (); /** Film that we are encoding */ @@ -95,7 +105,7 @@ private: EventHistory _history; boost::mutex _threads_mutex; - std::shared_ptr _threads; + std::vector> _threads; mutable boost::mutex _queue_mutex; std::list _queue; @@ -114,6 +124,8 @@ private: grk_plugin::DcpomaticContext _dcpomatic_context; grk_plugin::GrokContext *_context; + + bool _ending = false; }; -- cgit v1.2.3