Fix audio analysis; make sure we don't decode video and let it pile up unwanted.
[dcpomatic.git] / src / lib / video_decoder.cc
index 1bb460da357c2b28c21b3eac7f21c8d93450702b..b7cf1641b57d6b999c7c62b3c05f405e1f7b7075 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 ();
@@ -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 ());
@@ -303,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;
+}