Merge master.
[dcpomatic.git] / src / lib / player_video.cc
index f8e4a3e668cfbf3249701215a579c2fca4258735..a44264ceddd23bcad2c3e5dea92512e6e8d0c9ec 100644 (file)
 #include "player_video.h"
 #include "image.h"
 #include "image_proxy.h"
+#include "j2k_image_proxy.h"
 #include "scaler.h"
 
 using std::string;
 using std::cout;
-using boost::shared_ptr;
 using dcp::raw_convert;
+using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
 
 PlayerVideo::PlayerVideo (
        shared_ptr<const ImageProxy> in,
+       DCPTime time,
        Crop crop,
        dcp::Size inter_size,
        dcp::Size out_size,
@@ -39,6 +42,7 @@ PlayerVideo::PlayerVideo (
        ColourConversion colour_conversion
        )
        : _in (in)
+       , _time (time)
        , _crop (crop)
        , _inter_size (inter_size)
        , _out_size (out_size)
@@ -52,6 +56,7 @@ PlayerVideo::PlayerVideo (
 
 PlayerVideo::PlayerVideo (shared_ptr<cxml::Node> node, shared_ptr<Socket> socket, shared_ptr<Log> log)
 {
+       _time = DCPTime (node->number_child<DCPTime::Type> ("Time"));
        _crop = Crop (node);
 
        _inter_size = dcp::Size (node->number_child<int> ("InterWidth"), node->number_child<int> ("InterHeight"));
@@ -82,7 +87,7 @@ PlayerVideo::set_subtitle (PositionImage image)
 }
 
 shared_ptr<Image>
-PlayerVideo::image () const
+PlayerVideo::image (bool burn_subtitle) const
 {
        shared_ptr<Image> im = _in->image ();
        
@@ -108,7 +113,7 @@ PlayerVideo::image () const
 
        Position<int> const container_offset ((_out_size.width - _inter_size.width) / 2, (_out_size.height - _inter_size.width) / 2);
 
-       if (_subtitle.image) {
+       if (burn_subtitle && _subtitle.image) {
                out->alpha_blend (_subtitle.image, _subtitle.position);
        }
 
@@ -116,8 +121,9 @@ PlayerVideo::image () const
 }
 
 void
-PlayerVideo::add_metadata (xmlpp::Node* node) const
+PlayerVideo::add_metadata (xmlpp::Node* node, bool send_subtitles) const
 {
+       node->add_child("Time")->add_child_text (raw_convert<string> (_time.get ()));
        _crop.as_xml (node);
        _in->add_metadata (node->add_child ("In"));
        node->add_child("InterWidth")->add_child_text (raw_convert<string> (_inter_size.width));
@@ -128,7 +134,7 @@ PlayerVideo::add_metadata (xmlpp::Node* node) const
        node->add_child("Eyes")->add_child_text (raw_convert<string> (_eyes));
        node->add_child("Part")->add_child_text (raw_convert<string> (_part));
        _colour_conversion.as_xml (node);
-       if (_subtitle.image) {
+       if (send_subtitles && _subtitle.image) {
                node->add_child ("SubtitleWidth")->add_child_text (raw_convert<string> (_subtitle.image->size().width));
                node->add_child ("SubtitleHeight")->add_child_text (raw_convert<string> (_subtitle.image->size().height));
                node->add_child ("SubtitleX")->add_child_text (raw_convert<string> (_subtitle.position.x));
@@ -137,10 +143,31 @@ PlayerVideo::add_metadata (xmlpp::Node* node) const
 }
 
 void
-PlayerVideo::send_binary (shared_ptr<Socket> socket) const
+PlayerVideo::send_binary (shared_ptr<Socket> socket, bool send_subtitles) const
 {
        _in->send_binary (socket);
-       if (_subtitle.image) {
+       if (send_subtitles && _subtitle.image) {
                _subtitle.image->write_to_socket (socket);
        }
 }
+
+bool
+PlayerVideo::has_j2k () const
+{
+       /* XXX: burnt-in subtitle; maybe other things */
+       
+       shared_ptr<const J2KImageProxy> j2k = dynamic_pointer_cast<const J2KImageProxy> (_in);
+       if (!j2k) {
+               return false;
+       }
+       
+       return _crop == Crop () && _inter_size == j2k->size();
+}
+
+shared_ptr<EncodedData>
+PlayerVideo::j2k () const
+{
+       shared_ptr<const J2KImageProxy> j2k = dynamic_pointer_cast<const J2KImageProxy> (_in);
+       assert (j2k);
+       return j2k->j2k ();
+}