+ // Initialize Movit.
+ {
+ QSurface *surface = create_surface();
+ QOpenGLContext *context = create_context(surface);
+ make_current(context, surface);
+ CHECK(movit::init_movit(MOVIT_SHADER_DIR, movit::MOVIT_DEBUG_OFF));
+ delete_context(context);
+ // TODO: Delete the surface, too.
+ }
+
+ MainWindow main_window;
+ main_window.show();
+
+ global_httpd->add_endpoint("/queue_status", bind(&MainWindow::get_queue_status, &main_window), HTTPD::NO_CORS_POLICY);
+ global_httpd->start(DEFAULT_HTTPD_PORT);
+
+ init_jpeg_vaapi();
+
+ load_existing_frames();
+ thread record_thread(record_thread_func);
+
+ int ret = app.exec();
+
+ should_quit = true;
+ record_thread.join();
+ JPEGFrameView::shutdown();
+
+ return ret;
+}
+
+void load_existing_frames()
+{
+ string frame_dir = global_flags.working_directory + "/frames";
+ DIR *dir = opendir(frame_dir.c_str());
+ if (dir == nullptr) {
+ perror("frames/");
+ start_pts = 0;
+ return;
+ }
+
+ for ( ;; ) {
+ errno = 0;
+ dirent *de = readdir(dir);
+ if (de == nullptr) {
+ if (errno != 0) {
+ perror("readdir");
+ exit(1);
+ }
+ break;
+ }