Don't bother decoding video frames when we're seeking around trying to find subtitles.
[dcpomatic.git] / src / lib / video_decoder.cc
index efcbb05ad3dbdca68a0683a6684636b333ce4aec..31dc3cdc204836e821b385b0280d2c13f2defb31 100644 (file)
@@ -21,7 +21,9 @@
 #include "image.h"
 #include "image_proxy.h"
 #include "raw_image_proxy.h"
-#include "content_video.h"
+#include "raw_image_proxy.h"
+#include "film.h"
+#include "log.h"
 
 #include "i18n.h"
 
@@ -39,8 +41,8 @@ VideoDecoder::VideoDecoder (shared_ptr<const VideoContent> c)
 #else
        : _video_content (c)
 #endif
-       , _same (false)
        , _last_seek_accurate (true)
+       , _ignore_video (false)
 {
        _black_image.reset (new Image (PIX_FMT_RGB24, _video_content->video_size(), true));
        _black_image->make_black ();
@@ -94,7 +96,7 @@ VideoDecoder::get_video (VideoFrame frame, bool accurate)
                                break;
                        }
 
-                       if (pass ()) {
+                       if (pass (PASS_REASON_VIDEO)) {
                                /* The decoder has nothing more for us */
                                break;
                        }
@@ -111,7 +113,7 @@ VideoDecoder::get_video (VideoFrame frame, bool accurate)
                dec = decoded_video (frame);
        } else {
                /* Any frame will do: use the first one that comes out of pass() */
-               while (_decoded_video.empty() && !pass ()) {}
+               while (_decoded_video.empty() && !pass (PASS_REASON_VIDEO)) {}
                if (!_decoded_video.empty ()) {
                        dec.push_back (_decoded_video.front ());
                }
@@ -232,10 +234,14 @@ VideoDecoder::fill_3d (VideoFrame from, VideoFrame to, Eyes eye)
 void
 VideoDecoder::video (shared_ptr<const ImageProxy> image, VideoFrame frame)
 {
+       if (_ignore_video) {
+               return;
+       }
+
        /* We may receive the same frame index twice for 3D, and we need to know
           when that happens.
        */
-       _same = (!_decoded_video.empty() && frame == _decoded_video.back().frame);
+       bool const same = (!_decoded_video.empty() && frame == _decoded_video.back().frame);
 
        /* Work out what we are going to push into _decoded_video next */
        list<ContentVideo> to_push;
@@ -244,7 +250,7 @@ VideoDecoder::video (shared_ptr<const ImageProxy> image, VideoFrame frame)
                to_push.push_back (ContentVideo (image, EYES_BOTH, PART_WHOLE, frame));
                break;
        case VIDEO_FRAME_TYPE_3D_ALTERNATE:
-               to_push.push_back (ContentVideo (image, _same ? EYES_RIGHT : EYES_LEFT, PART_WHOLE, frame));
+               to_push.push_back (ContentVideo (image, same ? EYES_RIGHT : EYES_LEFT, PART_WHOLE, frame));
                break;
        case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT:
                to_push.push_back (ContentVideo (image, EYES_LEFT, PART_LEFT_HALF, frame));
@@ -280,6 +286,17 @@ VideoDecoder::video (shared_ptr<const ImageProxy> image, VideoFrame frame)
                to = to_push.front().frame;
        }
 
+       /* It has been known that this method receives frames out of order; at this
+          point I'm not sure why, but we'll just ignore them.
+       */
+
+       if (from && to && from.get() > to.get()) {
+               _video_content->film()->log()->log (
+                       String::compose ("Ignoring out-of-order decoded frame %1 after %2", to.get(), from.get()), Log::TYPE_WARNING
+                       );
+               return;
+       }
+
        if (from) {
                if (_video_content->video_frame_type() == VIDEO_FRAME_TYPE_2D) {
                        fill_2d (from.get(), to.get ());
@@ -290,8 +307,10 @@ VideoDecoder::video (shared_ptr<const ImageProxy> image, VideoFrame frame)
 
        copy (to_push.begin(), to_push.end(), back_inserter (_decoded_video));
 
-       /* We can't let this build up too much or we will run out of memory */
-       DCPOMATIC_ASSERT (_decoded_video.size() < 32);
+       /* We can't let this build up too much or we will run out of memory.  We need to allow
+          the most frames that can exist between blocks of sound in a multiplexed file.
+       */
+       DCPOMATIC_ASSERT (_decoded_video.size() <= 96);
 }
 
 void
@@ -301,3 +320,10 @@ VideoDecoder::seek (ContentTime s, bool accurate)
        _last_seek_time = s;
        _last_seek_accurate = accurate;
 }
+
+/** Set this player never to produce any video data */
+void
+VideoDecoder::set_ignore_video ()
+{
+       _ignore_video = true;
+}