]> git.sesse.net Git - nageru/blobdiff - futatabi/video_stream.cpp
Add metrics for reading frames from disk.
[nageru] / futatabi / video_stream.cpp
index ef56ee4a96711a703b900b3ab60121298803160d..6ee9608816f1940be13c06ba8ca9fc2edacd6afa 100644 (file)
@@ -208,10 +208,8 @@ VideoStream::VideoStream(AVFormatContext *file_avctx)
        check_error();
 
        OperatingPoint op;
-       if (global_flags.interpolation_quality == 0) {
-               // Allocate something just for simplicity; we won't be using it.
-               op = operating_point1;
-       } else if (global_flags.interpolation_quality == 1) {
+       if (global_flags.interpolation_quality == 0 ||
+           global_flags.interpolation_quality == 1) {
                op = operating_point1;
        } else if (global_flags.interpolation_quality == 2) {
                op = operating_point2;
@@ -220,6 +218,7 @@ VideoStream::VideoStream(AVFormatContext *file_avctx)
        } else if (global_flags.interpolation_quality == 4) {
                op = operating_point4;
        } else {
+               // Quality 0 will be changed to 1 in flags.cpp.
                assert(false);
        }
 
@@ -269,6 +268,7 @@ void VideoStream::start()
 void VideoStream::stop()
 {
        should_quit = true;
+       queue_changed.notify_all();
        clear_queue();
        encode_thread.join();
 }
@@ -560,8 +560,11 @@ void VideoStream::encode_thread_func()
 
                        // Wait until we have a frame to play.
                        queue_changed.wait(lock, [this]{
-                               return !frame_queue.empty();
+                               return !frame_queue.empty() || should_quit;
                        });
+                       if (should_quit) {
+                               break;
+                       }
                        steady_clock::time_point frame_start = frame_queue.front().local_pts;
 
                        // Now sleep until the frame is supposed to start (the usual case),
@@ -590,6 +593,7 @@ void VideoStream::encode_thread_func()
                        pkt.stream_index = 0;
                        pkt.data = (uint8_t *)jpeg.data();
                        pkt.size = jpeg.size();
+                       pkt.flags = AV_PKT_FLAG_KEY;
                        mux->add_packet(pkt, qf.output_pts, qf.output_pts);
 
                        last_frame.assign(&jpeg[0], &jpeg[0] + jpeg.size());
@@ -606,6 +610,7 @@ void VideoStream::encode_thread_func()
                        pkt.stream_index = 0;
                        pkt.data = (uint8_t *)jpeg.data();
                        pkt.size = jpeg.size();
+                       pkt.flags = AV_PKT_FLAG_KEY;
                        mux->add_packet(pkt, qf.output_pts, qf.output_pts);
                        last_frame = move(jpeg);
                } else if (qf.type == QueuedFrame::INTERPOLATED || qf.type == QueuedFrame::FADED_INTERPOLATED) {
@@ -630,6 +635,7 @@ void VideoStream::encode_thread_func()
                        pkt.stream_index = 0;
                        pkt.data = (uint8_t *)jpeg.data();
                        pkt.size = jpeg.size();
+                       pkt.flags = AV_PKT_FLAG_KEY;
                        mux->add_packet(pkt, qf.output_pts, qf.output_pts);
                        last_frame = move(jpeg);
                } else if (qf.type == QueuedFrame::REFRESH) {
@@ -638,6 +644,7 @@ void VideoStream::encode_thread_func()
                        pkt.stream_index = 0;
                        pkt.data = (uint8_t *)last_frame.data();
                        pkt.size = last_frame.size();
+                       pkt.flags = AV_PKT_FLAG_KEY;
                        mux->add_packet(pkt, qf.output_pts, qf.output_pts);
                } else {
                        assert(false);