Only build grok for Ubuntu 22.04.
[dcpomatic.git] / src / lib / j2k_encoder.h
index 1d31274b3f545741f323ada3c37152a7fa4af951..9d9d8589447baf83195438062f2c37f996821263 100644 (file)
  *  @brief J2KEncoder class.
  */
 
-#include "grok/context.h"
 
 #include "cross.h"
-#include "dcp_video.h"
 #include "enum_indexed_vector.h"
 #include "event_history.h"
 #include "exception_store.h"
+#ifdef DCPOMATIC_GROK
+#include "grok/context.h"
+#endif
+#include "j2k_encoder_thread.h"
 #include "writer.h"
 #include <boost/optional.hpp>
 #include <boost/signals2.hpp>
 #include <list>
 #include <stdint.h>
 
+
+class DCPVideo;
 class EncodeServerDescription;
 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.
@@ -74,18 +82,23 @@ 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;
 
-       void servers_list_changed ();
+       DCPVideo pop();
+       void retry(DCPVideo frame);
+       void write(std::shared_ptr<const dcp::Data> 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<EncodeServerDescription>);
+       void servers_list_changed ();
+       void remake_threads(int cpu, int gpu, std::list<EncodeServerDescription> servers);
        void terminate_threads ();
 
        /** Film that we are encoding */
@@ -94,7 +107,7 @@ private:
        EventHistory _history;
 
        boost::mutex _threads_mutex;
-       std::shared_ptr<boost::thread_group> _threads;
+       std::vector<std::shared_ptr<J2KEncoderThread>> _threads;
 
        mutable boost::mutex _queue_mutex;
        std::list<DCPVideo> _queue;
@@ -111,8 +124,12 @@ private:
 
        boost::signals2::scoped_connection _server_found_connection;
 
+#ifdef DCPOMATIC_GROK
        grk_plugin::DcpomaticContext _dcpomatic_context;
        grk_plugin::GrokContext *_context;
+#endif
+
+       bool _ending = false;
 };