Add a 2-frame `delay' on content arriving at the player to give
[dcpomatic.git] / src / lib / player_video.cc
index 17d3dc52270db80dc48cd782d3bc29ce9b8ce6b0..4784b16378d129fe512a809158e3e367c320df15 100644 (file)
@@ -41,7 +41,6 @@ using dcp::raw_convert;
 
 PlayerVideo::PlayerVideo (
        shared_ptr<const ImageProxy> in,
-       DCPTime time,
        Crop crop,
        boost::optional<double> fade,
        dcp::Size inter_size,
@@ -51,7 +50,6 @@ PlayerVideo::PlayerVideo (
        optional<ColourConversion> colour_conversion
        )
        : _in (in)
-       , _time (time)
        , _crop (crop)
        , _fade (fade)
        , _inter_size (inter_size)
@@ -65,7 +63,6 @@ PlayerVideo::PlayerVideo (
 
 PlayerVideo::PlayerVideo (shared_ptr<cxml::Node> node, shared_ptr<Socket> socket)
 {
-       _time = DCPTime (node->number_child<DCPTime::Type> ("Time"));
        _crop = Crop (node);
        _fade = node->optional_number_child<double> ("Fade");
 
@@ -82,7 +79,7 @@ PlayerVideo::PlayerVideo (shared_ptr<cxml::Node> node, shared_ptr<Socket> socket
        if (node->optional_number_child<int> ("SubtitleX")) {
 
                shared_ptr<Image> image (
-                       new Image (AV_PIX_FMT_RGBA, dcp::Size (node->number_child<int> ("SubtitleWidth"), node->number_child<int> ("SubtitleHeight")), true)
+                       new Image (AV_PIX_FMT_BGRA, dcp::Size (node->number_child<int> ("SubtitleWidth"), node->number_child<int> ("SubtitleHeight")), true)
                        );
 
                image->read_from_socket (socket);
@@ -102,11 +99,13 @@ PlayerVideo::set_subtitle (PositionImage image)
  *  @param pixel_format Function which is called to decide what pixel format the output image should be;
  *  it is passed the pixel format of the input image from the ImageProxy, and should return the desired
  *  output pixel format.  Two functions always_rgb and keep_xyz_or_rgb are provided for use here.
+ *  @param aligned true if the output image should be aligned to 32-byte boundaries.
+ *  @param fast true to be fast at the expense of quality.
  */
 shared_ptr<Image>
 PlayerVideo::image (dcp::NoteHandler note, function<AVPixelFormat (AVPixelFormat)> pixel_format, bool aligned, bool fast) const
 {
-       shared_ptr<Image> im = _in->image (optional<dcp::NoteHandler> (note));
+       shared_ptr<Image> im = _in->image (optional<dcp::NoteHandler> (note), _inter_size);
 
        Crop total_crop = _crop;
        switch (_part) {
@@ -136,7 +135,7 @@ PlayerVideo::image (dcp::NoteHandler note, function<AVPixelFormat (AVPixelFormat
                );
 
        if (_subtitle) {
-               out->alpha_blend (_subtitle->image, _subtitle->position);
+               out->alpha_blend (Image::ensure_aligned (_subtitle->image), _subtitle->position);
        }
 
        if (_fade) {
@@ -149,7 +148,6 @@ PlayerVideo::image (dcp::NoteHandler note, function<AVPixelFormat (AVPixelFormat
 void
 PlayerVideo::add_metadata (xmlpp::Node* node) const
 {
-       node->add_child("Time")->add_child_text (raw_convert<string> (_time.get ()));
        _crop.as_xml (node);
        if (_fade) {
                node->add_child("Fade")->add_child_text (raw_convert<string> (_fade.get ()));
@@ -191,7 +189,7 @@ PlayerVideo::has_j2k () const
                return false;
        }
 
-       return _crop == Crop () && _inter_size == j2k->size() && !_subtitle && !_fade && !_colour_conversion;
+       return _crop == Crop () && _out_size == j2k->size() && !_subtitle && !_fade && !_colour_conversion;
 }
 
 Data
@@ -208,9 +206,7 @@ PlayerVideo::inter_position () const
        return Position<int> ((_out_size.width - _inter_size.width) / 2, (_out_size.height - _inter_size.height) / 2);
 }
 
-/** @return true if this PlayerVideo is definitely the same as another
- * (apart from _time), false if it is probably not
- */
+/** @return true if this PlayerVideo is definitely the same as another, false if it is probably not */
 bool
 PlayerVideo::same (shared_ptr<const PlayerVideo> other) const
 {
@@ -250,3 +246,33 @@ PlayerVideo::keep_xyz_or_rgb (AVPixelFormat p)
 {
        return p == AV_PIX_FMT_XYZ12LE ? AV_PIX_FMT_XYZ12LE : AV_PIX_FMT_RGB48LE;
 }
+
+void
+PlayerVideo::prepare ()
+{
+       _in->prepare (_inter_size);
+}
+
+size_t
+PlayerVideo::memory_used () const
+{
+       return _in->memory_used();
+}
+
+/** @return Shallow copy of this; _in and _subtitle are shared between the original and the copy */
+shared_ptr<PlayerVideo>
+PlayerVideo::shallow_copy () const
+{
+       return shared_ptr<PlayerVideo>(
+               new PlayerVideo(
+                       _in,
+                       _crop,
+                       _fade,
+                       _inter_size,
+                       _out_size,
+                       _eyes,
+                       _part,
+                       _colour_conversion
+                       )
+               );
+}