#include <stdint.h>
#include <sys/types.h>
+#include <atomic>
#include <chrono>
#include <condition_variable>
#include <memory>
#include "clip_list.h"
#include "context.h"
#include "defs.h"
+#include "disk_space_estimator.h"
#include "mainwindow.h"
#include "ffmpeg_raii.h"
#include "httpd.h"
using namespace std;
using namespace std::chrono;
-std::mutex RefCountedGLsync::fence_lock;
+mutex RefCountedGLsync::fence_lock;
+atomic<bool> should_quit{false};
int64_t start_pts = -1;
MainWindow mainWindow;
mainWindow.show();
+ init_jpeg_vaapi();
+
load_existing_frames();
- thread(record_thread_func).detach();
+ thread record_thread(record_thread_func);
- init_jpeg_vaapi();
+ int ret = app.exec();
+
+ should_quit = true;
+ record_thread.join();
+ JPEGFrameView::shutdown();
- return app.exec();
+ return ret;
}
void load_existing_frames()
int64_t last_pts = -1;
int64_t pts_offset;
- for ( ;; ) {
+ while (!should_quit.load()) {
AVPacket pkt;
unique_ptr<AVPacket, decltype(av_packet_unref)*> pkt_cleanup(
&pkt, av_packet_unref);
av_init_packet(&pkt);
pkt.data = nullptr;
pkt.size = 0;
+
+ // TODO: Make it possible to abort av_read_frame() (use an interrupt callback);
+ // right now, should_quit will be ignored if it's hung on I/O.
if (av_read_frame(format_ctx.get(), &pkt) != 0) {
break;
}
fwrite(pkt.data, pkt.size, 1, fp);
fclose(fp);
+ global_disk_space_estimator->report_write(filename, pts);
+
post_to_main_thread([pkt, pts] {
if (pkt.stream_index == 0) {
global_mainwindow->ui->input1_display->setFrame(pkt.stream_index, pts, /*interpolated=*/false);