Rename j2k_bandwidth -> video_bit_rate.
[dcpomatic.git] / src / lib / j2k_encoder.cc
index 795134d782c15354bad737bc4bf1687f3501c6ce..d5c7b3eed635a63334ebe5c806e10782baefa25d 100644 (file)
@@ -92,14 +92,15 @@ grk_plugin::IMessengerLogger* getMessengerLogger(void)
  *  @param writer Writer that we are using.
  */
 J2KEncoder::J2KEncoder(shared_ptr<const Film> film, Writer& writer)
-       : _film (film)
-       , _history (200)
-       , _writer (writer)
+       : VideoEncoder(film, writer)
+{
 #ifdef DCPOMATIC_GROK
-       , _dcpomatic_context(new grk_plugin::DcpomaticContext(film, writer, _history, Config::instance()->gpu_binary_location()))
-       , _context(Config::instance()->enable_gpu() ? new grk_plugin::GrokContext(_dcpomatic_context) : nullptr)
+       auto grok = Config::instance()->grok().get_value_or({});
+       _dcpomatic_context = new grk_plugin::DcpomaticContext(film, writer, _history, grok.binary_location);
+       if (grok.enable) {
+               _context = new grk_plugin::GrokContext(_dcpomatic_context);
+       }
 #endif
-{
 }
 
 
@@ -120,9 +121,14 @@ void
 J2KEncoder::servers_list_changed()
 {
        auto config = Config::instance();
+#ifdef DCPOMATIC_GROK
+       auto const grok_enable = config->grok().get_value_or({}).enable;
+#else
+       auto const grok_enable = false;
+#endif
 
-       auto const cpu = (config->enable_gpu() || config->only_servers_encode()) ? 0 : config->master_encoding_threads();
-       auto const gpu = config->enable_gpu() ? config->master_encoding_threads() : 0;
+       auto const cpu = (grok_enable || config->only_servers_encode()) ? 0 : config->master_encoding_threads();
+       auto const gpu = grok_enable ? config->master_encoding_threads() : 0;
 
        remake_threads(cpu, gpu, EncodeServerFinder::instance()->servers());
 }
@@ -141,16 +147,17 @@ J2KEncoder::begin ()
 void
 J2KEncoder::pause()
 {
-       if (!Config::instance()->enable_gpu()) {
+#ifdef DCPOMATIC_GROK
+       if (!Config::instance()->grok().get_value_or({}).enable) {
                return;
        }
+       return;
 
        terminate_threads ();
 
        /* Something might have been thrown during terminate_threads */
        rethrow ();
 
-#ifdef DCPOMATIC_GROK
        delete _context;
        _context = nullptr;
 #endif
@@ -159,14 +166,14 @@ J2KEncoder::pause()
 
 void J2KEncoder::resume()
 {
-       if (!Config::instance()->enable_gpu()) {
+#ifdef DCPOMATIC_GROK
+       if (!Config::instance()->grok().get_value_or({}).enable) {
                return;
        }
 
-#ifdef DCPOMATIC_GROK
        _context = new grk_plugin::GrokContext(_dcpomatic_context);
-#endif
        servers_list_changed();
+#endif
 }
 
 
@@ -203,7 +210,7 @@ J2KEncoder::end()
        */
        for (auto & i: _queue) {
 #ifdef DCPOMATIC_GROK
-               if (Config::instance()->enable_gpu ()) {
+               if (Config::instance()->grok().get_value_or({}).enable) {
                        if (!_context->scheduleCompress(i)){
                                LOG_GENERAL (N_("[%1] J2KEncoder thread pushes frame %2 back onto queue after failure"), thread_id(), i.index());
                                // handle error
@@ -233,28 +240,6 @@ J2KEncoder::end()
 }
 
 
-/** @return an estimate of the current number of frames we are encoding per second,
- *  if known.
- */
-optional<float>
-J2KEncoder::current_encoding_rate () const
-{
-       return _history.rate ();
-}
-
-
-/** @return Number of video frames that have been queued for encoding */
-int
-J2KEncoder::video_frames_enqueued () const
-{
-       if (!_last_player_video_time) {
-               return 0;
-       }
-
-       return _last_player_video_time->frames_floor (_film->video_frame_rate ());
-}
-
-
 /** Should be called when a frame has been encoded successfully */
 void
 J2KEncoder::frame_done ()
@@ -274,6 +259,8 @@ J2KEncoder::frame_done ()
 void
 J2KEncoder::encode (shared_ptr<PlayerVideo> pv, DCPTime time)
 {
+       VideoEncoder::encode(pv, time);
+
        _waker.nudge ();
 
        size_t threads = 0;
@@ -323,7 +310,7 @@ J2KEncoder::encode (shared_ptr<PlayerVideo> pv, DCPTime time)
                                pv,
                                position,
                                _film->video_frame_rate(),
-                               _film->j2k_bandwidth(),
+                               _film->video_bit_rate(),
                                _film->resolution()
                                );
                _queue.push_back (dcpv);
@@ -335,7 +322,6 @@ J2KEncoder::encode (shared_ptr<PlayerVideo> pv, DCPTime time)
        }
 
        _last_player_video[pv->eyes()] = pv;
-       _last_player_video_time = time;
 }
 
 
@@ -355,12 +341,10 @@ J2KEncoder::terminate_threads ()
 
 
 void
-#ifdef DCPOMATIC_GROK
 J2KEncoder::remake_threads(int cpu, int gpu, list<EncodeServerDescription> servers)
-#else
-J2KEncoder::remake_threads(int cpu, int, list<EncodeServerDescription> servers)
-#endif
 {
+       LOG_GENERAL("Making threads: CPU=%1, GPU=%2, Remote=%3", cpu, gpu, servers.size());
+
        boost::mutex::scoped_lock lm (_threads_mutex);
        if (_ending) {
                return;