Replace Time::frames with Time::frames_round and Time::frames_floor.
authorCarl Hetherington <cth@carlh.net>
Tue, 28 Jul 2015 16:53:27 +0000 (17:53 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 29 Jul 2015 19:04:36 +0000 (20:04 +0100)
I believe both are necessary; doing floor instead of round caused #648.

16 files changed:
src/lib/analyse_audio_job.cc
src/lib/audio_decoder_stream.cc
src/lib/dcp_decoder.cc
src/lib/dcpomatic_time.h
src/lib/ffmpeg_examiner.cc
src/lib/image_decoder.cc
src/lib/player.cc
src/lib/sndfile_decoder.cc
src/lib/transcode_job.cc
src/lib/video_decoder.cc
src/lib/writer.cc
src/wx/timing_panel.cc
src/wx/video_panel.cc
test/audio_decoder_test.cc
test/dcpomatic_time_test.cc
test/seek_zero_test.cc

index 2f48d12a925b50502aa7051a551d783e365e49cd..e997c03c57b729ce274ec46b0a49a63ca8d9bd81 100644 (file)
@@ -66,7 +66,7 @@ AnalyseAudioJob::run ()
        shared_ptr<Player> player (new Player (_film, _playlist));
        player->set_ignore_video ();
 
-       int64_t const len = _playlist->length().frames (_film->audio_frame_rate());
+       int64_t const len = _playlist->length().frames_round (_film->audio_frame_rate());
        _samples_per_point = max (int64_t (1), len / _num_points);
 
        _current.resize (_film->audio_channels ());
index fdcebbc9f0648a24a22cc8770a56c1bf52e512b6..36274b502692e3d95bbd76e7a8162d7968a287b3 100644 (file)
@@ -145,7 +145,7 @@ AudioDecoderStream::audio (shared_ptr<const AudioBuffers> data, ContentTime time
        if (_seek_reference) {
                /* We've had an accurate seek and now we're seeing some data */
                ContentTime const delta = time - _seek_reference.get ();
-               Frame const delta_frames = delta.frames (frame_rate);
+               Frame const delta_frames = delta.frames_round (frame_rate);
                if (delta_frames > 0) {
                        /* This data comes after the seek time.  Pad the data with some silence. */
                        shared_ptr<AudioBuffers> padded (new AudioBuffers (data->channels(), data->frames() + delta_frames));
@@ -172,7 +172,7 @@ AudioDecoderStream::audio (shared_ptr<const AudioBuffers> data, ContentTime time
        }
 
        if (!_position) {
-               _position = time.frames (frame_rate);
+               _position = time.frames_round (frame_rate);
        }
 
        DCPOMATIC_ASSERT (_position.get() >= (_decoded.frame + _decoded.audio->frames()));
index 44450f7d9fb450173c4232b964472640e90e511d..053ff4f68b1198d33d760ffd55d25860e5f852c6 100644 (file)
@@ -64,7 +64,7 @@ DCPDecoder::pass ()
        }
 
        double const vfr = _dcp_content->video_frame_rate ();
-       int64_t const frame = _next.frames (vfr);
+       int64_t const frame = _next.frames_round (vfr);
 
        if ((*_reel)->main_picture ()) {
                shared_ptr<dcp::PictureAsset> asset = (*_reel)->main_picture()->asset ();
@@ -127,7 +127,7 @@ DCPDecoder::pass ()
        _next += ContentTime::from_frames (1, vfr);
 
        if ((*_reel)->main_picture ()) {
-               if (_next.frames (vfr) >= (*_reel)->main_picture()->duration()) {
+               if (_next.frames_round (vfr) >= (*_reel)->main_picture()->duration()) {
                        ++_reel;
                }
        }
index 41339d128b30270765ace032b5ddfcc4c0246dfd..c1d27407a90d2c4c8ba49fb57162109c087187bb 100644 (file)
@@ -132,7 +132,12 @@ public:
        }
 
        template <typename T>
-       int64_t frames (T r) const {
+       int64_t frames_round (T r) const {
+               return llrint (_t * r / HZ);
+       }
+
+       template <typename T>
+       int64_t frames_floor (T r) const {
                return floor (_t * r / HZ);
        }
 
@@ -143,7 +148,7 @@ public:
                /* Do this calculation with frames so that we can round
                   to a frame boundary at the start rather than the end.
                */
-               int64_t ff = frames (r);
+               int64_t ff = frames_round (r);
 
                h = ff / (3600 * r);
                ff -= h * 3600 * r;
index bcc5a86a68dbe2b093b95f76702de22df1b64e2e..78d97d21e52e4b4b9f5a12ed052ef33e711701d2 100644 (file)
@@ -139,7 +139,7 @@ FFmpegExaminer::video_packet (AVCodecContext* context)
                if (_need_video_length) {
                        _video_length = frame_time (
                                _format_context->streams[_video_stream]
-                               ).get_value_or (ContentTime ()).frames (video_frame_rate().get ());
+                               ).get_value_or (ContentTime ()).frames_round (video_frame_rate().get ());
                }
        }
 }
index 3d543eaf28562572a8ee3f0ce29d50cd3b921ec6..db7c5401fa3591c536fdf6083bf0a159e366e255 100644 (file)
@@ -71,5 +71,5 @@ void
 ImageDecoder::seek (ContentTime time, bool accurate)
 {
        VideoDecoder::seek (time, accurate);
-       _video_position = time.frames (_image_content->video_frame_rate ());
+       _video_position = time.frames_round (_image_content->video_frame_rate ());
 }
index e7348110759fbd61157e095215e4830fd8e8daae..147f08ae8ef18e62961402893493c24c40a37b44 100644 (file)
@@ -431,7 +431,7 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate)
                setup_pieces ();
        }
 
-       Frame const length_frames = length.frames (_film->audio_frame_rate ());
+       Frame const length_frames = length.frames_round (_film->audio_frame_rate ());
 
        shared_ptr<AudioBuffers> audio (new AudioBuffers (_film->audio_channels(), length_frames));
        audio->make_silent ();
@@ -457,7 +457,7 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate)
                           the stuff we get back.
                        */
                        offset = -request;
-                       request_frames += request.frames (_film->audio_frame_rate ());
+                       request_frames += request.frames_round (_film->audio_frame_rate ());
                        if (request_frames < 0) {
                                request_frames = 0;
                        }
@@ -509,7 +509,7 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate)
                        audio->accumulate_frames (
                                all.audio.get(),
                                content_frame - all.frame,
-                               offset.frames (_film->audio_frame_rate()),
+                               offset.frames_round (_film->audio_frame_rate()),
                                min (Frame (all.audio->frames()), request_frames)
                                );
                }
@@ -524,7 +524,10 @@ Player::dcp_to_content_video (shared_ptr<const Piece> piece, DCPTime t) const
        shared_ptr<const VideoContent> vc = dynamic_pointer_cast<const VideoContent> (piece->content);
        DCPTime s = t - piece->content->position ();
        s = min (piece->content->length_after_trim(), s);
-       return max (ContentTime (), ContentTime (s, piece->frc) + piece->content->trim_start ()).frames (vc->video_frame_rate ());
+       /* We're returning a frame index here so we need to floor() the conversion since we want to know the frame
+          that contains t, I think
+       */
+       return max (ContentTime (), ContentTime (s, piece->frc) + piece->content->trim_start ()).frames_floor (vc->video_frame_rate ());
 }
 
 DCPTime
@@ -540,7 +543,8 @@ Player::dcp_to_resampled_audio (shared_ptr<const Piece> piece, DCPTime t) const
 {
        DCPTime s = t - piece->content->position ();
        s = min (piece->content->length_after_trim(), s);
-       return max (DCPTime (), DCPTime (piece->content->trim_start (), piece->frc) + s).frames (_film->audio_frame_rate ());
+       /* See notes in dcp_to_content_video */
+       return max (DCPTime (), DCPTime (piece->content->trim_start (), piece->frc) + s).frames_floor (_film->audio_frame_rate ());
 }
 
 ContentTime
index 2fa9ae2a3c48df0328f618016c65a5f1bc64e599..b2d35f3023937ae2b9471345b0f78e455fead2f5 100644 (file)
@@ -98,6 +98,6 @@ SndfileDecoder::seek (ContentTime t, bool accurate)
 {
        AudioDecoder::seek (t, accurate);
 
-       _done = t.frames (_info.samplerate);
+       _done = t.frames_round (_info.samplerate);
        _remaining = _info.frames - _done;
 }
index 4a2d768f479c7c67fa600ef46c56954d5a60bae2..122f7f79921545a79522c40bb185f3b6cccf5b1f 100644 (file)
@@ -123,5 +123,5 @@ TranscodeJob::remaining_time () const
        }
 
        /* Compute approximate proposed length here, as it's only here that we need it */
-       return (_film->length().frames (_film->video_frame_rate ()) - t->video_frames_out()) / fps;
+       return (_film->length().frames_round (_film->video_frame_rate ()) - t->video_frames_out()) / fps;
 }
index 944b1b695b1d708cb800acd8e73f392f1d6be438..2b9b13689434854de1fd9e9c385a4a27bb65ac22 100644 (file)
@@ -278,7 +278,7 @@ VideoDecoder::video (shared_ptr<const ImageProxy> image, Frame frame)
        boost::optional<Frame> to;
 
        if (_decoded_video.empty() && _last_seek_time && _last_seek_accurate) {
-               from = _last_seek_time->frames (_video_content->video_frame_rate ());
+               from = _last_seek_time->frames_round (_video_content->video_frame_rate ());
                to = to_push.front().frame;
        } else if (!_decoded_video.empty ()) {
                from = _decoded_video.back().frame + 1;
index ff6e4f63cba6b0caf44d81030d64d816b55c2a97..863b49959d750495ff8fb72688eb72ebfe72b95d 100644 (file)
@@ -396,7 +396,7 @@ try
 
                        shared_ptr<Job> job = _job.lock ();
                        DCPOMATIC_ASSERT (job);
-                       int64_t total = _film->length().frames (_film->video_frame_rate ());
+                       int64_t total = _film->length().frames_round (_film->video_frame_rate ());
                        if (_film->three_d ()) {
                                /* _full_written and so on are incremented for each eye, so we need to double the total
                                   frames to get the correct progress.
index f92505c333863e1e093e9496246ec3eea028fd34..53e1092248d3d0dfc44a74d4153d49f8e1954b0a 100644 (file)
@@ -296,7 +296,7 @@ TimingPanel::full_length_changed ()
                shared_ptr<ImageContent> ic = dynamic_pointer_cast<ImageContent> (*i);
                if (ic && ic->still ()) {
                        int const vfr = _parent->film()->video_frame_rate ();
-                       ic->set_video_length (_full_length->get (vfr).frames (vfr));
+                       ic->set_video_length (_full_length->get (vfr).frames_round (vfr));
                }
        }
 }
index aa8e946da92782245d1f2f144a7eb35e801c0769..68ff7c3693b50d1a2d0d2eeaae2c10f3e7bdb834 100644 (file)
@@ -426,7 +426,7 @@ VideoPanel::fade_in_changed ()
        VideoContentList vc = _parent->selected_video ();
        for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) {
                int const vfr = _parent->film()->video_frame_rate ();
-               (*i)->set_fade_in (_fade_in->get (vfr).frames (vfr));
+               (*i)->set_fade_in (_fade_in->get (vfr).frames_round (vfr));
        }
 }
 
@@ -436,6 +436,6 @@ VideoPanel::fade_out_changed ()
        VideoContentList vc = _parent->selected_video ();
        for (VideoContentList::const_iterator i = vc.begin(); i != vc.end(); ++i) {
                int const vfr = _parent->film()->video_frame_rate ();
-               (*i)->set_fade_out (_fade_out->get (vfr).frames (vfr));
+               (*i)->set_fade_out (_fade_out->get (vfr).frames_round (vfr));
        }
 }
index 6816c1fbb45532dc184ccd6f2afa5fb83b11cdb9..8af5dfb11102585764fe89bbc8678bca3801c7b0 100644 (file)
@@ -87,7 +87,7 @@ public:
        void seek (ContentTime t, bool accurate)
        {
                AudioDecoder::seek (t, accurate);
-               _position = t.frames (_test_audio_content->resampled_audio_frame_rate ());
+               _position = t.frames_round (_test_audio_content->resampled_audio_frame_rate ());
        }
 
 private:
index 4462ae870f59ce2dfa1738e0fd099abbda379e3b..2b42d22b880788907e276f33a1329c4cb5c1f13d 100644 (file)
@@ -28,8 +28,7 @@ BOOST_AUTO_TEST_CASE (dcpomatic_time_test)
        for (int64_t i = 0; i < 62000; i += 2000) {
                DCPTime d (i);
                ContentTime c (d, frc);
-               std::cout << i << " " << d << " " << c << " " << c.frames (24.0) << " " << j << "\n";
-               BOOST_CHECK_EQUAL (c.frames (24.0), j);
+               BOOST_CHECK_EQUAL (c.frames_floor (24.0), j);
                ++k;
                if (k == 2) {
                        ++j;
index 7f661b21cf11183ead22b494a080146837f5c0c6..5f870ba41f7605ceae92d2e28acb3cc1dcd2e37d 100644 (file)
@@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE (seek_zero_test)
                video_delay = ContentTime ();
        }
 
-       Frame const first_frame = video_delay.round_up (content->video_frame_rate ()).frames (content->video_frame_rate ());
+       Frame const first_frame = video_delay.round_up (content->video_frame_rate ()).frames_round (content->video_frame_rate ());
 
        FFmpegDecoder decoder (content, film->log());
        list<ContentVideo> a = decoder.get_video (first_frame, true);