summaryrefslogtreecommitdiff
path: root/src/lib/remote_j2k_frame_encoder.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-05-20 11:12:55 +0200
committerCarl Hetherington <cth@carlh.net>2022-05-23 16:55:28 +0200
commitef051b519b678e0c8b59e2e1a13acdabccc36a67 (patch)
tree82b3a681da436aa110402223caddd0e99bae0492 /src/lib/remote_j2k_frame_encoder.cc
parent8e017c66d86c09a4689afeac0d7989d24daef745 (diff)
Move encode_{locally,remotely} into the frame encoder classes.
Diffstat (limited to 'src/lib/remote_j2k_frame_encoder.cc')
-rw-r--r--src/lib/remote_j2k_frame_encoder.cc62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/lib/remote_j2k_frame_encoder.cc b/src/lib/remote_j2k_frame_encoder.cc
index 3917cc07b..adaef495e 100644
--- a/src/lib/remote_j2k_frame_encoder.cc
+++ b/src/lib/remote_j2k_frame_encoder.cc
@@ -19,17 +19,30 @@
*/
+#include "config.h"
#include "cross.h"
#include "dcp_video.h"
#include "dcpomatic_log.h"
+#include "dcpomatic_socket.h"
+#include "exceptions.h"
+#include "player_video.h"
#include "remote_j2k_frame_encoder.h"
+#include <dcp/raw_convert.h>
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
+#include <libxml++/libxml++.h>
+LIBDCP_ENABLE_WARNINGS
+#include <boost/asio.hpp>
+#include <boost/thread.hpp>
#include "i18n.h"
using std::make_shared;
using std::shared_ptr;
+using std::string;
using boost::optional;
+using dcp::ArrayData;
using dcp::Data;
@@ -39,7 +52,54 @@ RemoteJ2KFrameEncoder::encode(DCPVideo const& vf)
optional<dcp::ArrayData> encoded;
try {
- encoded = vf.encode_remotely(_server);
+ boost::asio::io_service io_service;
+ boost::asio::ip::tcp::resolver resolver (io_service);
+ boost::asio::ip::tcp::resolver::query query (_server.host_name(), dcp::raw_convert<string>(ENCODE_FRAME_PORT));
+ auto endpoint_iterator = resolver.resolve (query);
+
+ auto socket = make_shared<Socket>(_timeout);
+
+ socket->connect (*endpoint_iterator);
+
+ /* Collect all XML metadata */
+ xmlpp::Document doc;
+ auto root = doc.create_root_node ("EncodingRequest");
+ root->add_child("Version")->add_child_text(dcp::raw_convert<string>(SERVER_LINK_VERSION));
+ root->add_child("Index")->add_child_text(dcp::raw_convert<string>(vf.index()));
+ root->add_child("FramesPerSecond")->add_child_text(dcp::raw_convert<string>(vf.frames_per_second()));
+ root->add_child("J2KBandwidth")->add_child_text(dcp::raw_convert<string>(vf.j2k_bandwidth()));
+ root->add_child("Resolution")->add_child_text(dcp::raw_convert<string>(int(vf.resolution())));
+ vf.frame()->add_metadata(root);
+
+ LOG_DEBUG_ENCODE(N_("Sending frame %1 to remote"), vf.index());
+
+ {
+ Socket::WriteDigestScope ds (socket);
+
+ /* Send XML metadata */
+ auto xml = doc.write_to_string ("UTF-8");
+ socket->write (xml.length() + 1);
+ socket->write (reinterpret_cast<uint8_t const *>(xml.c_str()), xml.bytes() + 1);
+
+ /* Send binary data */
+ LOG_TIMING("start-remote-send thread=%1", thread_id());
+ vf.frame()->write_to_socket(socket);
+ }
+
+ /* Read the response (JPEG2000-encoded data); this blocks until the data
+ is ready and sent back.
+ */
+ Socket::ReadDigestScope ds (socket);
+ LOG_TIMING("start-remote-encode thread=%1", thread_id());
+ encoded = ArrayData(socket->read_uint32());
+ LOG_TIMING("start-remote-receive thread=%1", thread_id());
+ socket->read (encoded->data(), encoded->size());
+ LOG_TIMING("finish-remote-receive thread=%1", thread_id());
+ if (!ds.check()) {
+ throw NetworkError ("Checksums do not match");
+ }
+
+ LOG_DEBUG_ENCODE (N_("Finished remotely-encoded frame %1"), vf.index());
if (_remote_backoff > 0) {
LOG_GENERAL ("%1 was lost, but now she is found; removing backoff", _server.host_name());