Various fixes to seek since changing fill code.
authorCarl Hetherington <cth@carlh.net>
Sun, 23 Nov 2014 12:47:16 +0000 (12:47 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 23 Nov 2014 12:47:16 +0000 (12:47 +0000)
src/lib/video_decoder.cc
src/lib/video_decoder.h
test/video_decoder_fill_test.cc

index 9b27055c73ba737b00fa86f55ed8a41bfe7b9c1e..711f047d14ca8c33a711f83ec682418f5d963841 100644 (file)
@@ -40,6 +40,7 @@ VideoDecoder::VideoDecoder (shared_ptr<const VideoContent> c)
        : _video_content (c)
 #endif
        , _same (false)
+       , _last_seek_accurate (true)
 {
        _black_image.reset (new Image (PIX_FMT_RGB24, _video_content->video_size(), true));
        _black_image->make_black ();
@@ -71,7 +72,7 @@ VideoDecoder::get_video (VideoFrame frame, bool accurate)
           method returned (and possibly a few more).  If the requested frame is not in _decoded_video and it is not the next
           one after the end of _decoded_video we need to seek.
        */
-          
+
        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);
        }
@@ -125,11 +126,11 @@ VideoDecoder::get_video (VideoFrame frame, bool accurate)
        return dec;
 }
 
-/** Fill _decoded_video up to, but not including, the specified frame */
+/** Fill _decoded_video from `from' up to, but not including, `to' */
 void
-VideoDecoder::fill_up_to_2d (VideoFrame frame)
+VideoDecoder::fill_2d (VideoFrame from, VideoFrame to)
 {
-       if (frame == 0) {
+       if (to == 0) {
                /* Already OK */
                return;
        }
@@ -144,13 +145,13 @@ VideoDecoder::fill_up_to_2d (VideoFrame frame)
                filler_part = _decoded_video.back().part;
        }
 
-       VideoFrame filler_frame = _decoded_video.empty() ? 0 : (_decoded_video.back().frame + 1);
-       while (filler_frame < frame) {
+       VideoFrame filler_frame = from;
+       
+       while (filler_frame < (to - 1)) {
 
 #ifdef DCPOMATIC_DEBUG
                test_gaps++;
 #endif
-
                _decoded_video.push_back (
                        ContentVideo (filler_image, EYES_BOTH, filler_part, filler_frame)
                        );
@@ -159,11 +160,11 @@ VideoDecoder::fill_up_to_2d (VideoFrame frame)
        }
 }
 
-/** Fill _decoded_video up to, but not including, the specified frame and eye */
+/** Fill _decoded_video from `from' up to, but not including, `to' */
 void
-VideoDecoder::fill_up_to_3d (VideoFrame frame, Eyes eye)
+VideoDecoder::fill_3d (VideoFrame from, VideoFrame to, Eyes eye)
 {
-       if (frame == 0 && eye == EYES_LEFT) {
+       if (to == 0 && eye == EYES_LEFT) {
                /* Already OK */
                return;
        }
@@ -189,7 +190,7 @@ VideoDecoder::fill_up_to_3d (VideoFrame frame, Eyes eye)
                }
        }
 
-       VideoFrame filler_frame = _decoded_video.empty() ? 0 : _decoded_video.back().frame;
+       VideoFrame filler_frame = from;
        Eyes filler_eye = _decoded_video.empty() ? EYES_LEFT : _decoded_video.back().eyes;
 
        if (_decoded_video.empty ()) {
@@ -203,7 +204,7 @@ VideoDecoder::fill_up_to_3d (VideoFrame frame, Eyes eye)
                filler_eye = EYES_LEFT;
        }
 
-       while (filler_frame != frame || filler_eye != eye) {
+       while (filler_frame != to || filler_eye != eye) {
 
 #ifdef DCPOMATIC_DEBUG
                test_gaps++;
@@ -268,18 +269,32 @@ VideoDecoder::video (shared_ptr<const ImageProxy> image, VideoFrame frame)
           and the things we are about to push.
        */
 
-       if (_video_content->video_frame_type() == VIDEO_FRAME_TYPE_2D) {
-               fill_up_to_2d (to_push.front().frame);
-       } else {
-               fill_up_to_3d (to_push.front().frame, to_push.front().eyes);
+       boost::optional<VideoFrame> from;
+       boost::optional<VideoFrame> to;
+       
+       if (_decoded_video.empty() && _last_seek_time && _last_seek_accurate) {
+               from = _last_seek_time->frames (_video_content->video_frame_rate ());
+               to = to_push.front().frame;
+       } else if (!_decoded_video.empty ()) {
+               from = _decoded_video.back().frame + 1;
+               to = to_push.front().frame;
+       }
+
+       if (from) {
+               if (_video_content->video_frame_type() == VIDEO_FRAME_TYPE_2D) {
+                       fill_2d (from.get(), to.get ());
+               } else {
+                       fill_3d (from.get(), to.get(), to_push.front().eyes);
+               }
        }
 
        copy (to_push.begin(), to_push.end(), back_inserter (_decoded_video));
 }
 
 void
-VideoDecoder::seek (ContentTime, bool)
+VideoDecoder::seek (ContentTime s, bool accurate)
 {
        _decoded_video.clear ();
+       _last_seek_time = s;
+       _last_seek_accurate = accurate;
 }
-
index 9e56546df952e5a659904b5be064f259c4b62fa8..24ee7f4e5f1948bcbf6dd897fbb324570bd62199 100644 (file)
@@ -60,13 +60,15 @@ protected:
        void seek (ContentTime time, bool accurate);
        void video (boost::shared_ptr<const ImageProxy>, VideoFrame frame);
        std::list<ContentVideo> decoded_video (VideoFrame frame);
-       void fill_up_to_2d (VideoFrame);
-       void fill_up_to_3d (VideoFrame, Eyes);
+       void fill_2d (VideoFrame from, VideoFrame to);
+       void fill_3d (VideoFrame from, VideoFrame to, Eyes);
 
        boost::shared_ptr<const VideoContent> _video_content;
        std::list<ContentVideo> _decoded_video;
        bool _same;
        boost::shared_ptr<Image> _black_image;
+       boost::optional<ContentTime> _last_seek_time;
+       bool _last_seek_accurate;
 };
 
 #endif
index ae54759031bea9d6b181d106a258a2f0c1d600a7..ff3fc0b9e0615e6d4cebe2d2e9098b95dc150e20 100644 (file)
@@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE (video_decoder_fill_test1)
        shared_ptr<ImageContent> c (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
        ImageDecoder decoder (c);
 
-       decoder.fill_up_to_2d (4);
+       decoder.fill_2d (0, 4);
        BOOST_CHECK_EQUAL (decoder._decoded_video.size(), 4);
        list<ContentVideo>::iterator i = decoder._decoded_video.begin();        
        for (int j = 0; j < 4; ++j) {
@@ -40,7 +40,7 @@ BOOST_AUTO_TEST_CASE (video_decoder_fill_test1)
                ++i;
        }
 
-       decoder.fill_up_to_2d (7);
+       decoder.fill_2d (0, 7);
        BOOST_CHECK_EQUAL (decoder._decoded_video.size(), 7);
        i = decoder._decoded_video.begin();     
        for (int j = 0; j < 7; ++j) {
@@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE (video_decoder_fill_test2)
        shared_ptr<ImageContent> c (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
        ImageDecoder decoder (c);
 
-       decoder.fill_up_to_3d (4, EYES_LEFT);
+       decoder.fill_3d (0, 4, EYES_LEFT);
        BOOST_CHECK_EQUAL (decoder._decoded_video.size(), 8);
        list<ContentVideo>::iterator i = decoder._decoded_video.begin();        
        for (int j = 0; j < 8; ++j) {
@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE (video_decoder_fill_test2)
                ++i;
        }
 
-       decoder.fill_up_to_3d (7, EYES_RIGHT);
+       decoder.fill_3d (0, 7, EYES_RIGHT);
        BOOST_CHECK_EQUAL (decoder._decoded_video.size(), 15);
        i = decoder._decoded_video.begin();     
        for (int j = 0; j < 15; ++j) {