* @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
-{
}
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());
}
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
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
}
*/
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
}
-/** @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 ()
void
J2KEncoder::encode (shared_ptr<PlayerVideo> pv, DCPTime time)
{
+ VideoEncoder::encode(pv, time);
+
_waker.nudge ();
size_t threads = 0;
pv,
position,
_film->video_frame_rate(),
- _film->j2k_bandwidth(),
+ _film->video_bit_rate(),
_film->resolution()
);
_queue.push_back (dcpv);
}
_last_player_video[pv->eyes()] = pv;
- _last_player_video_time = time;
}
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;