Seek past trim on setting up player pieces.
authorCarl Hetherington <cth@carlh.net>
Tue, 29 Oct 2013 18:40:48 +0000 (18:40 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 29 Oct 2013 18:40:48 +0000 (18:40 +0000)
ChangeLog
src/lib/player.cc
src/lib/video_content.cc
src/lib/video_content.h

index af30932056326d0a35d9b4d985e75dd50b3c47eb..3a3dffd1241b2bdb3050296189db390879c79648 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2013-10-29  Carl Hetherington  <cth@carlh.net>
 
+       * Improve performance when start-trimming
+       large files.
+
        * Fix audio problems when start-trimming.
 
 2013-10-28  Carl Hetherington  <cth@carlh.net>
index 8370a3f9fa4373fc957238cf7d7fd3c88d93c0e9..53186af6e176480067ef3134421af7d419b51b7d 100644 (file)
@@ -102,7 +102,9 @@ public:
        
        shared_ptr<Content> content;
        shared_ptr<Decoder> decoder;
+       /** Time of the last video we emitted relative to the start of the DCP */
        Time video_position;
+       /** Time of the last audio we emitted relative to the start of the DCP */
        Time audio_position;
 
        IncomingVideo repeat_video;
@@ -408,20 +410,19 @@ Player::seek (Time t, bool accurate)
                if (!vc) {
                        continue;
                }
-               
+
+               /* s is the offset of t from the start position of this content */
                Time s = t - vc->position ();
                s = max (static_cast<Time> (0), s);
                s = min (vc->length_after_trim(), s);
 
+               /* Hence set the piece positions to the `global' time */
                (*i)->video_position = (*i)->audio_position = vc->position() + s;
 
-               FrameRateConversion frc (vc->video_frame_rate(), _film->video_frame_rate());
-               /* Here we are converting from time (in the DCP) to a frame number in the content.
-                  Hence we need to use the DCP's frame rate and the double/skip correction, not
-                  the source's rate.
-               */
-               VideoContent::Frame f = (s + vc->trim_start ()) * _film->video_frame_rate() / (frc.factor() * TIME_HZ);
-               dynamic_pointer_cast<VideoDecoder>((*i)->decoder)->seek (f, accurate);
+               /* And seek the decoder */
+               dynamic_pointer_cast<VideoDecoder>((*i)->decoder)->seek (
+                       vc->time_to_content_video_frames (s + vc->trim_start ()), accurate
+                       );
 
                (*i)->reset_repeat ();
        }
@@ -455,6 +456,7 @@ Player::setup_pieces ()
                        fd->Audio.connect (bind (&Player::process_audio, this, piece, _1, _2));
                        fd->Subtitle.connect (bind (&Player::process_subtitle, this, piece, _1, _2, _3, _4));
 
+                       fd->seek (fc->time_to_content_video_frames (fc->trim_start ()), true);
                        piece->decoder = fd;
                }
                
index 3478368555b8139944144170b05ab67198134d4b..d0eab4dbf93f870344b7c34228ed14d7813ad26d 100644 (file)
@@ -26,6 +26,8 @@
 #include "compose.hpp"
 #include "config.h"
 #include "colour_conversion.h"
+#include "util.h"
+#include "film.h"
 
 #include "i18n.h"
 
@@ -289,3 +291,21 @@ VideoContent::video_size_after_crop () const
 {
        return crop().apply (video_size_after_3d_split ());
 }
+
+/** @param t A time offset from the start of this piece of content.
+ *  @return Corresponding frame index.
+ */
+VideoContent::Frame
+VideoContent::time_to_content_video_frames (Time t) const
+{
+       shared_ptr<const Film> film = _film.lock ();
+       assert (film);
+       
+       FrameRateConversion frc (video_frame_rate(), film->video_frame_rate());
+
+       /* Here we are converting from time (in the DCP) to a frame number in the content.
+          Hence we need to use the DCP's frame rate and the double/skip correction, not
+          the source's rate.
+       */
+       return t * film->video_frame_rate() / (frc.factor() * TIME_HZ);
+}
index 36920977661169b0ccb1c1fb0d758cc4794a248e..6f80536fe4a4d6eb64c317a92b7789b107f025d4 100644 (file)
@@ -101,6 +101,8 @@ public:
        libdcp::Size video_size_after_3d_split () const;
        libdcp::Size video_size_after_crop () const;
 
+       VideoContent::Frame time_to_content_video_frames (Time) const;
+
 protected:
        void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);