Tweak logging format.
[dcpomatic.git] / src / lib / video_decoder.cc
index 1b4a625d6ef829b9fd58346d7e7b72da0ded4824..fd5779a657f0304124a28ef27980a62a85a1945a 100644 (file)
 
 #include "video_decoder.h"
 #include "image.h"
-#include "image_proxy.h"
-#include "raw_image_proxy.h"
 #include "raw_image_proxy.h"
 #include "film.h"
 #include "log.h"
+#include "compose.hpp"
+#include <iostream>
 
 #include "i18n.h"
 
@@ -44,7 +44,7 @@ VideoDecoder::VideoDecoder (shared_ptr<const VideoContent> c)
        , _last_seek_accurate (true)
        , _ignore_video (false)
 {
-       _black_image.reset (new Image (PIX_FMT_RGB24, _video_content->video_size(), true));
+       _black_image.reset (new Image (AV_PIX_FMT_RGB24, _video_content->video_size(), true));
        _black_image->make_black ();
 }
 
@@ -75,7 +75,7 @@ VideoDecoder::get_video (Frame frame, bool accurate)
           one after the end of _decoded_video we need to seek.
        */
 
-       _video_content->film()->log()->log (String::compose ("VD has request for %1", frame), Log::TYPE_DEBUG_DECODE);
+       _video_content->film()->log()->log (String::compose ("VD has request for %1", frame), LogEntry::TYPE_DEBUG_DECODE);
 
        if (_decoded_video.empty() || frame < _decoded_video.front().frame || frame > (_decoded_video.back().frame + 1)) {
                seek (ContentTime::from_frames (frame, _video_content->video_frame_rate()), accurate);
@@ -98,7 +98,7 @@ VideoDecoder::get_video (Frame frame, bool accurate)
                                break;
                        }
 
-                       if (pass ()) {
+                       if (pass (PASS_REASON_VIDEO, accurate)) {
                                /* The decoder has nothing more for us */
                                break;
                        }
@@ -115,7 +115,7 @@ VideoDecoder::get_video (Frame 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, accurate)) {}
                if (!_decoded_video.empty ()) {
                        dec.push_back (_decoded_video.front ());
                }
@@ -143,7 +143,7 @@ VideoDecoder::fill_one_eye (Frame from, Frame to, Eyes eye)
        }
 
        /* Fill with black... */
-       boost::shared_ptr<const ImageProxy> filler_image (new RawImageProxy (_black_image));
+       shared_ptr<const ImageProxy> filler_image (new RawImageProxy (_black_image));
        Part filler_part = PART_WHOLE;
 
        /* ...unless there's some video we can fill with */
@@ -174,8 +174,8 @@ VideoDecoder::fill_both_eyes (Frame from, Frame to, Eyes eye)
        }
 
        /* Fill with black... */
-       boost::shared_ptr<const ImageProxy> filler_left_image (new RawImageProxy (_black_image));
-       boost::shared_ptr<const ImageProxy> filler_right_image (new RawImageProxy (_black_image));
+       shared_ptr<const ImageProxy> filler_left_image (new RawImageProxy (_black_image));
+       shared_ptr<const ImageProxy> filler_right_image (new RawImageProxy (_black_image));
        Part filler_left_part = PART_WHOLE;
        Part filler_right_part = PART_WHOLE;
 
@@ -240,8 +240,7 @@ VideoDecoder::video (shared_ptr<const ImageProxy> image, Frame frame)
                return;
        }
 
-       _video_content->film()->log()->log (String::compose ("VD receives %1", frame), Log::TYPE_DEBUG_DECODE);
-       cout << "receive " << frame << " for " << _video_content->path(0) << "\n";
+       _video_content->film()->log()->log (String::compose ("VD receives %1", frame), LogEntry::TYPE_DEBUG_DECODE);
 
        /* We may receive the same frame index twice for 3D, and we need to know
           when that happens.
@@ -280,8 +279,8 @@ VideoDecoder::video (shared_ptr<const ImageProxy> image, Frame frame)
           and the things we are about to push.
        */
 
-       boost::optional<Frame> from;
-       boost::optional<Frame> to;
+       optional<Frame> from;
+       optional<Frame> to;
 
        if (_decoded_video.empty() && _last_seek_time && _last_seek_accurate) {
                from = _last_seek_time->frames_round (_video_content->video_frame_rate ());
@@ -319,10 +318,14 @@ VideoDecoder::video (shared_ptr<const ImageProxy> image, Frame 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.  We need to allow
-          the most frames that can exist between blocks of sound in a multiplexed file.
+       /* We can't let this build up too much or we will run out of memory.  There is a
+          `best' value for the allowed size of _decoded_video which balances memory use
+          with decoding efficiency (lack of seeks).  Throwing away video frames here
+          is not a problem for correctness, so do it.
        */
-       DCPOMATIC_ASSERT (_decoded_video.size() <= 96);
+       while (_decoded_video.size() > 96) {
+               _decoded_video.pop_back ();
+       }
 }
 
 void