]> git.sesse.net Git - nageru/commitdiff
Factor out rewinding code in its own member function.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 14 Apr 2017 16:12:27 +0000 (18:12 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 14 Apr 2017 16:12:27 +0000 (18:12 +0200)
ffmpeg_capture.cpp
ffmpeg_capture.h

index 5474c52fd94f511491206e4f8a92b2545bc87475..e03382cec5418c8732bff8f0ecbc0d8346cb0544 100644 (file)
@@ -189,9 +189,7 @@ bool FFmpegCapture::play_video(const string &pathname)
        unique_ptr<AVCodecContext, decltype(avcodec_close)*> codec_ctx_cleanup(
                codec_ctx.get(), avcodec_close);
 
-       int64_t pts_origin = 0, last_pts = 0;
-       steady_clock::time_point start = steady_clock::now();
-       steady_clock::time_point next_frame_start = start;
+       internal_rewind();
        double rate = 1.0;
 
        unique_ptr<SwsContext, decltype(sws_freeContext)*> sws_ctx(nullptr, sws_freeContext);
@@ -211,8 +209,7 @@ bool FFmpegCapture::play_video(const string &pathname)
                                if (av_seek_frame(format_ctx.get(), /*stream_index=*/-1, /*timestamp=*/0, /*flags=*/0) < 0) {
                                        fprintf(stderr, "%s: Rewind failed, stopping play.\n", pathname.c_str());
                                }
-                               pts_origin = last_pts = 0;
-                               start = next_frame_start = steady_clock::now();
+                               internal_rewind();
                                break;
 
                        case QueuedCommand::CHANGE_RATE:
@@ -263,8 +260,7 @@ bool FFmpegCapture::play_video(const string &pathname)
                                fprintf(stderr, "%s: Rewind failed, not looping.\n", pathname.c_str());
                                return true;
                        }
-                       pts_origin = last_pts = 0;
-                       start = steady_clock::now();
+                       internal_rewind();
                        continue;
                }
 
@@ -314,3 +310,9 @@ bool FFmpegCapture::play_video(const string &pathname)
        }
        return true;
 }
+
+void FFmpegCapture::internal_rewind()
+{                              
+       pts_origin = last_pts = 0;
+       start = next_frame_start = steady_clock::now();
+}
index 24e6b5b40d3f9b780e71facdb7fb0dc347e5723c..095078267c1987d67e7e843ded7e90cb57641136 100644 (file)
@@ -141,6 +141,7 @@ public:
 private:
        void producer_thread_func();
        bool play_video(const std::string &pathname);
+       void internal_rewind();
 
        std::string description, filename;
        uint16_t timecode = 0;
@@ -161,6 +162,9 @@ private:
        QuittableSleeper producer_thread_should_quit;
        std::thread producer_thread;
 
+       int64_t pts_origin, last_pts;
+       std::chrono::steady_clock::time_point start, next_frame_start;
+
        std::mutex queue_mu;
        struct QueuedCommand {
                enum Command { REWIND, CHANGE_RATE } command;