return;
}
- cxml::File f (file (false), "Config");
+ cxml::Document f ("Config");
+ f.read_file (file (false));
optional<string> c;
_num_local_encoding_threads = f.number_child<int> ("NumLocalEncodingThreads");
#include <libdcp/xyz_frame.h>
#include <libdcp/rgb_xyz.h>
#include <libdcp/colour_matrix.h>
+#include <libcxml/cxml.h>
#include "film.h"
#include "dcp_video_frame.h"
#include "config.h"
using std::ofstream;
using std::cout;
using boost::shared_ptr;
+using boost::lexical_cast;
using libdcp::Size;
#define DCI_COEFFICENT (48.0 / 52.37)
}
+DCPVideoFrame::DCPVideoFrame (shared_ptr<const Image> image, shared_ptr<const cxml::Node> node, shared_ptr<Log> log)
+ : _image (image)
+ , _log (log)
+{
+ _frame = node->number_child<int> ("Frame");
+ string const eyes = node->string_child ("Eyes");
+ if (eyes == "Both") {
+ _eyes = EYES_BOTH;
+ } else if (eyes == "Left") {
+ _eyes = EYES_LEFT;
+ } else if (eyes == "Right") {
+ _eyes = EYES_RIGHT;
+ } else {
+ assert (false);
+ }
+ _conversion = ColourConversion (node->node_child ("ColourConversion"));
+ _frames_per_second = node->number_child<int> ("FramesPerSecond");
+ _j2k_bandwidth = node->number_child<int> ("J2KBandwidth");
+}
+
/** J2K-encode this frame on the local host.
* @return Encoded data.
*/
socket->connect (*endpoint_iterator);
- /* XXX: colour conversion! */
+ xmlpp::Document doc;
+ xmlpp::Element* root = doc.create_root_node ("EncodingRequest");
- stringstream s;
- s << "encode please\n"
- << "width " << _image->size().width << "\n"
- << "height " << _image->size().height << "\n"
- << "eyes " << static_cast<int> (_eyes) << "\n"
- << "frame " << _frame << "\n"
- << "frames_per_second " << _frames_per_second << "\n"
- << "j2k_bandwidth " << _j2k_bandwidth << "\n";
+ root->add_child("Version")->add_child_text (lexical_cast<string> (SERVER_LINK_VERSION));
+ root->add_child("Width")->add_child_text (lexical_cast<string> (_image->size().width));
+ root->add_child("Height")->add_child_text (lexical_cast<string> (_image->size().height));
+ add_metadata (root);
+
+ stringstream xml;
+ doc.write_to_stream (xml);
_log->log (String::compose (
N_("Sending to remote; pixel format %1, components %2, lines (%3,%4,%5), line sizes (%6,%7,%8)"),
_image->line_size()[0], _image->line_size()[1], _image->line_size()[2]
));
- socket->write (s.str().length() + 1);
- socket->write ((uint8_t *) s.str().c_str(), s.str().length() + 1);
+ socket->write (xml.str().length() + 1);
+ socket->write ((uint8_t *) xml.str().c_str(), xml.str().length() + 1);
_image->write_to_socket (socket);
return e;
}
+void
+DCPVideoFrame::add_metadata (xmlpp::Element* el) const
+{
+ el->add_child("Frame")->add_child_text (lexical_cast<string> (_frame));
+
+ switch (_eyes) {
+ case EYES_BOTH:
+ el->add_child("Eyes")->add_child_text ("Both");
+ break;
+ case EYES_LEFT:
+ el->add_child("Eyes")->add_child_text ("Left");
+ break;
+ case EYES_RIGHT:
+ el->add_child("Eyes")->add_child_text ("Right");
+ break;
+ default:
+ assert (false);
+ }
+
+ _conversion.as_xml (el->add_child("ColourConversion"));
+
+ el->add_child("FramesPerSecond")->add_child_text (lexical_cast<string> (_frames_per_second));
+ el->add_child("J2KBandwidth")->add_child_text (lexical_cast<string> (_j2k_bandwidth));
+}
+
EncodedData::EncodedData (int s)
: _data (new uint8_t[s])
, _size (s)
{
public:
DCPVideoFrame (boost::shared_ptr<const Image>, int, Eyes, ColourConversion, int, int, boost::shared_ptr<Log>);
+ DCPVideoFrame (boost::shared_ptr<const Image>, boost::shared_ptr<const cxml::Node>, boost::shared_ptr<Log>);
boost::shared_ptr<EncodedData> encode_locally ();
boost::shared_ptr<EncodedData> encode_remotely (ServerDescription);
}
private:
+
+ void add_metadata (xmlpp::Element *) const;
+
boost::shared_ptr<const Image> _image;
int _frame; ///< frame index within the DCP's intrinsic duration
Eyes _eyes;
throw StringError (_("This film was created with an older version of DCP-o-matic, and unfortunately it cannot be loaded into this version. You will need to create a new Film, re-add your content and set it up again. Sorry!"));
}
- cxml::File f (file ("metadata.xml"), "Metadata");
+ cxml::Document f ("Metadata");
+ f.read_file (file ("metadata.xml"));
_name = f.string_child ("Name");
_use_dci_name = f.bool_child ("UseDCIName");
socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
stringstream s (buffer.get());
- multimap<string, string> kv = read_key_value (s);
-
- if (get_required_string (kv, "encode") != "please") {
+ shared_ptr<cxml::Document> xml (new cxml::Document ("EncodingRequest"));
+ xml->read_stream (s);
+ if (xml->number_child<int> ("Version") != SERVER_LINK_VERSION) {
+ _log->log ("Mismatched server/client versions");
return -1;
}
- libdcp::Size size (get_required_int (kv, "width"), get_required_int (kv, "height"));
- int frame = get_required_int (kv, "frame");
- int frames_per_second = get_required_int (kv, "frames_per_second");
- int j2k_bandwidth = get_required_int (kv, "j2k_bandwidth");
- Eyes eyes = static_cast<Eyes> (get_required_int (kv, "eyes"));
+ libdcp::Size size (
+ xml->number_child<int> ("Width"), xml->number_child<int> ("Height")
+ );
shared_ptr<Image> image (new Image (PIX_FMT_RGB24, size, true));
image->read_from_socket (socket);
-
- /* XXX: colour conversion... */
-
- DCPVideoFrame dcp_video_frame (
- image, frame, eyes, ColourConversion(), frames_per_second, j2k_bandwidth, _log
- );
+ DCPVideoFrame dcp_video_frame (image, xml, _log);
shared_ptr<EncodedData> encoded = dcp_video_frame.encode_locally ();
try {
encoded->send (socket);
} catch (std::exception& e) {
_log->log (String::compose (
- N_("Send failed; frame %1, data size %2, pixel format %3, image size %4x%5, %6 components"),
- frame, encoded->size(), image->pixel_format(), image->size().width, image->size().height, image->components()
+ "Send failed; frame %1, data size %2, pixel format %3, image size %4x%5, %6 components",
+ dcp_video_frame.frame(), encoded->size(), image->pixel_format(), image->size().width, image->size().height, image->components()
)
);
throw;
}
- return frame;
+ return dcp_video_frame.frame ();
}
void
class Content;
class AudioBuffers;
+/** The version number of the protocol used to communicate
+ * with servers. Intended to be bumped when incompatibilities
+ * are introduced.
+ */
+#define SERVER_LINK_VERSION 1
+
typedef int64_t Time;
#define TIME_MAX INT64_MAX
#define TIME_HZ ((Time) 96000)