Move position variables into the video/audio/subtitle decoder classes.
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index 8f196542a1ea5b10005598c04fcd7290643f0235..ddc563b9855b2b5d5fdd7575d69bfbc9475960e9 100644 (file)
@@ -425,7 +425,7 @@ FFmpegDecoder::decode_audio_packet ()
                                LOG_WARNING ("Crazy timestamp %s", to_string (ct));
                        }
 
-                       update_position (_audio_position, ct);
+                       audio->set_position (ct);
 
                        /* Give this data provided there is some, and its time is sane */
                        if (ct >= ContentTime() && data->frames() > 0) {
@@ -478,7 +478,7 @@ FFmpegDecoder::decode_video_packet ()
                                shared_ptr<ImageProxy> (new RawImageProxy (image)),
                                llrint (pts * _ffmpeg_content->active_video_frame_rate ())
                                );
-                       update_position (_video_position, ContentTime::from_seconds (pts));
+                       video->set_position (ContentTime::from_seconds (pts));
                } else {
                        LOG_WARNING_NC ("Dropping frame without PTS");
                }
@@ -509,7 +509,7 @@ FFmpegDecoder::decode_subtitle_packet ()
        FFmpegSubtitlePeriod sub_period = subtitle_period (sub);
        ContentTimePeriod period;
        period.from = sub_period.from + _pts_offset;
-       update_position (_subtitle_position, period.from);
+       subtitle->set_position (period.from);
        if (sub_period.to) {
                /* We already know the subtitle period `to' time */
                period.to = sub_period.to.get() + _pts_offset;
@@ -644,16 +644,3 @@ FFmpegDecoder::decode_ass_subtitle (string ass, ContentTimePeriod period)
                subtitle->give_text (period, i);
        }
 }
-
-void
-FFmpegDecoder::update_position (optional<ContentTime>& current, ContentTime p)
-{
-       /* current should err on the side of being too big, as then there is less
-          chance that we will erroneously decide not to seek when current > request.
-       */
-       if (!current) {
-               current = p;
-       } else {
-               current = max (*current, p);
-       }
-}