]> git.sesse.net Git - nageru/commitdiff
Fix a race where refresh frames could be put into the muxer with out-of-order pts.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 21 Oct 2018 21:08:30 +0000 (23:08 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 21 Oct 2018 21:27:38 +0000 (23:27 +0200)
video_stream.cpp
video_stream.h

index 015fa66613d473bc860841c41ea37598efd3b22a..f4ad33564b71ce4ced49064cec7678315ba0c6a7 100644 (file)
@@ -483,12 +483,13 @@ void VideoStream::schedule_interpolated_frame(int64_t output_pts, unsigned strea
 
 void VideoStream::schedule_refresh_frame(int64_t output_pts)
 {
-       AVPacket pkt;
-       av_init_packet(&pkt);
-       pkt.stream_index = 0;
-       pkt.data = (uint8_t *)last_frame.data();
-       pkt.size = last_frame.size();
-       stream_mux->add_packet(pkt, output_pts, output_pts);
+       QueuedFrame qf;
+       qf.type = QueuedFrame::REFRESH;
+       qf.output_pts = output_pts;
+
+       unique_lock<mutex> lock(queue_lock);
+       frame_queue.push_back(qf);
+       queue_nonempty.notify_all();
 }
 
 namespace {
@@ -600,6 +601,13 @@ void VideoStream::encode_thread_func()
                        // Put the frame resources back.
                        unique_lock<mutex> lock(queue_lock);
                        interpolate_resources.push_back(qf.resources);
+               } else if (qf.type == QueuedFrame::REFRESH) {
+                       AVPacket pkt;
+                       av_init_packet(&pkt);
+                       pkt.stream_index = 0;
+                       pkt.data = (uint8_t *)last_frame.data();
+                       pkt.size = last_frame.size();
+                       stream_mux->add_packet(pkt, qf.output_pts, qf.output_pts);
                } else {
                        assert(false);
                }
index 2bac2ad425bacc196926aca41db998590e9884f1..2dae6e06f01c7a626556090fa9050daf7e982727 100644 (file)
@@ -68,7 +68,7 @@ private:
 
        struct QueuedFrame {
                int64_t output_pts;
-               enum Type { ORIGINAL, FADED, INTERPOLATED, FADED_INTERPOLATED } type;
+               enum Type { ORIGINAL, FADED, INTERPOLATED, FADED_INTERPOLATED, REFRESH } type;
                unsigned stream_idx;
                int64_t input_first_pts;  // The only pts for original frames.