/*
- Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
*/
+
/** @file src/j2k_encoder.cc
* @brief J2K encoder class.
*/
-#include "j2k_encoder.h"
-#include "util.h"
-#include "film.h"
-#include "log.h"
-#include "dcpomatic_log.h"
+
+#include "compose.hpp"
#include "config.h"
-#include "dcp_video.h"
#include "cross.h"
-#include "writer.h"
+#include "dcp_video.h"
+#include "dcpomatic_log.h"
+#include "encode_server_description.h"
#include "encode_server_finder.h"
+#include "film.h"
+#include "j2k_encoder.h"
+#include "log.h"
#include "player.h"
#include "player_video.h"
-#include "encode_server_description.h"
-#include "compose.hpp"
+#include "util.h"
+#include "writer.h"
#include <libcxml/cxml.h>
#include <iostream>
#include "i18n.h"
-using std::list;
+
using std::cout;
using std::exception;
+using std::list;
+using std::make_shared;
using std::shared_ptr;
using std::weak_ptr;
-using std::make_shared;
using boost::optional;
using dcp::Data;
using namespace dcpomatic;
+
/** @param film Film that we are encoding.
* @param writer Writer that we are using.
*/
servers_list_changed ();
}
+
J2KEncoder::~J2KEncoder ()
{
boost::mutex::scoped_lock lm (_threads_mutex);
terminate_threads ();
}
+
void
J2KEncoder::begin ()
{
- weak_ptr<J2KEncoder> wp = shared_from_this ();
+ auto wp = shared_from_this ();
_server_found_connection = EncodeServerFinder::instance()->ServersListChanged.connect (
boost::bind (&J2KEncoder::call_servers_list_changed, wp)
);
}
+
/* We don't want the servers-list-changed callback trying to do things
during destruction of J2KEncoder, and I think this is the neatest way
to achieve that.
}
}
+
void
J2KEncoder::end ()
{
}
}
+
/** @return an estimate of the current number of frames we are encoding per second,
* if known.
*/
return _history.rate ();
}
+
/** @return Number of video frames that have been queued for encoding */
int
J2KEncoder::video_frames_enqueued () const
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 ()
_history.event ();
}
+
/** Called to request encoding of the next video frame in the DCP. This is called in order,
* so each time the supplied frame is the one after the previous one.
* pv represents one video frame, and could be empty if there is nothing to encode
_threads.reset ();
}
+
void
J2KEncoder::encoder_thread (optional<EncodeServerDescription> server)
try
{
+ start_of_thread ("J2KEncoder");
+
if (server) {
LOG_TIMING ("start-encoder-thread thread=%1 server=%2", thread_id (), server->host_name ());
} else {
_full_condition.notify_all ();
}
+
void
J2KEncoder::servers_list_changed ()
{