]> git.sesse.net Git - nageru/blobdiff - futatabi/video_stream.cpp
Fix an issue where the stop button would be disabled too soon.
[nageru] / futatabi / video_stream.cpp
index 27e2c4a81e499ddc031b21434c05fd0490f1f37f..66323b88749afc17a7142c51cc7b2e017ee61758 100644 (file)
@@ -6,14 +6,14 @@ extern "C" {
 }
 
 #include "chroma_subsampler.h"
-#include "shared/context.h"
 #include "flags.h"
 #include "flow.h"
-#include "shared/httpd.h"
 #include "jpeg_frame_view.h"
 #include "movit/util.h"
-#include "shared/mux.h"
 #include "player.h"
+#include "shared/context.h"
+#include "shared/httpd.h"
+#include "shared/mux.h"
 #include "util.h"
 #include "ycbcr_converter.h"
 
@@ -264,8 +264,7 @@ void VideoStream::start()
 
        size_t width = global_flags.width, height = global_flags.height;  // Doesn't matter for MJPEG.
        mux.reset(new Mux(avctx, width, height, Mux::CODEC_MJPEG, /*video_extradata=*/"", /*audio_codec_parameters=*/nullptr,
-               AVCOL_SPC_BT709, Mux::WITHOUT_AUDIO,
-               COARSE_TIMEBASE, /*write_callback=*/nullptr, Mux::WRITE_FOREGROUND, {}));
+                         AVCOL_SPC_BT709, COARSE_TIMEBASE, /*write_callback=*/nullptr, Mux::WRITE_FOREGROUND, {}));
 
        encode_thread = thread(&VideoStream::encode_thread_func, this);
 }
@@ -283,7 +282,7 @@ void VideoStream::clear_queue()
        deque<QueuedFrame> q;
 
        {
-               unique_lock<mutex> lock(queue_lock);
+               lock_guard<mutex> lock(queue_lock);
                q = move(frame_queue);
        }
 
@@ -324,7 +323,7 @@ void VideoStream::schedule_original_frame(steady_clock::time_point local_pts,
        qf.display_func = move(display_func);
        qf.queue_spot_holder = move(queue_spot_holder);
 
-       unique_lock<mutex> lock(queue_lock);
+       lock_guard<mutex> lock(queue_lock);
        frame_queue.push_back(move(qf));
        queue_changed.notify_all();
 }
@@ -343,7 +342,7 @@ void VideoStream::schedule_faded_frame(steady_clock::time_point local_pts, int64
        // separate pools around.)
        BorrowedInterpolatedFrameResources resources;
        {
-               unique_lock<mutex> lock(queue_lock);
+               lock_guard<mutex> lock(queue_lock);
                if (interpolate_resources.empty()) {
                        fprintf(stderr, "WARNING: Too many interpolated frames already in transit; dropping one.\n");
                        return;
@@ -392,7 +391,7 @@ void VideoStream::schedule_faded_frame(steady_clock::time_point local_pts, int64
        qf.resources = move(resources);
        qf.local_pts = local_pts;
 
-       unique_lock<mutex> lock(queue_lock);
+       lock_guard<mutex> lock(queue_lock);
        frame_queue.push_back(move(qf));
        queue_changed.notify_all();
 }
@@ -412,7 +411,7 @@ void VideoStream::schedule_interpolated_frame(steady_clock::time_point local_pts
        // Get the temporary OpenGL resources we need for doing the interpolation.
        BorrowedInterpolatedFrameResources resources;
        {
-               unique_lock<mutex> lock(queue_lock);
+               lock_guard<mutex> lock(queue_lock);
                if (interpolate_resources.empty()) {
                        fprintf(stderr, "WARNING: Too many interpolated frames already in transit; dropping one.\n");
                        return;
@@ -518,7 +517,7 @@ void VideoStream::schedule_interpolated_frame(steady_clock::time_point local_pts
        check_error();
        qf.resources = move(resources);
 
-       unique_lock<mutex> lock(queue_lock);
+       lock_guard<mutex> lock(queue_lock);
        frame_queue.push_back(move(qf));
        queue_changed.notify_all();
 }
@@ -533,7 +532,7 @@ void VideoStream::schedule_refresh_frame(steady_clock::time_point local_pts,
        qf.display_func = move(display_func);
        qf.queue_spot_holder = move(queue_spot_holder);
 
-       unique_lock<mutex> lock(queue_lock);
+       lock_guard<mutex> lock(queue_lock);
        frame_queue.push_back(move(qf));
        queue_changed.notify_all();
 }
@@ -586,7 +585,7 @@ void VideoStream::encode_thread_func()
                        unique_lock<mutex> lock(queue_lock);
 
                        // Wait until we have a frame to play.
-                       queue_changed.wait(lock, [this]{
+                       queue_changed.wait(lock, [this] {
                                return !frame_queue.empty() || should_quit;
                        });
                        if (should_quit) {
@@ -600,7 +599,7 @@ void VideoStream::encode_thread_func()
                        if (output_fast_forward) {
                                aborted = frame_queue.empty() || frame_queue.front().local_pts != frame_start;
                        } else {
-                               aborted = queue_changed.wait_until(lock, frame_start, [this, frame_start]{
+                               aborted = queue_changed.wait_until(lock, frame_start, [this, frame_start] {
                                        return frame_queue.empty() || frame_queue.front().local_pts != frame_start;
                                });
                        }