X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=main.cpp;h=e0518afb95421d3ad906cc9a910f2dee01aef9d0;hb=ce2e0615420b706e1ff2405fffcedfba37a9adac;hp=8f9530459149cc77dbf3389ca823b0267d98b948;hpb=3859580a69bf0242c70a2ff77da50deb4ac363d2;p=nageru diff --git a/main.cpp b/main.cpp index 8f95304..e0518af 100644 --- a/main.cpp +++ b/main.cpp @@ -39,6 +39,7 @@ extern "C" { #include #include #include +#include #include #include @@ -165,7 +166,12 @@ FrameOnDisk write_frame(int stream_idx, int64_t pts, const uint8_t *data, size_t } } } - db->store_frame_file(filename, size, frames_this_file); + + const char *basename = filename.c_str(); + while (strchr(basename, '/') != nullptr) { + basename = strchr(basename, '/'); + } + db->store_frame_file(basename, size, frames_this_file); } return frame; @@ -239,6 +245,8 @@ int main(int argc, char **argv) // TODO: Delete the surface, too. } + load_existing_frames(); + MainWindow main_window; main_window.show(); @@ -247,7 +255,6 @@ int main(int argc, char **argv) init_jpeg_vaapi(); - load_existing_frames(); thread record_thread(record_thread_func); int ret = app.exec(); @@ -259,7 +266,7 @@ int main(int argc, char **argv) return ret; } -void load_frame_file(const char *filename, unsigned filename_idx, DB *db) +void load_frame_file(const char *filename, const string &basename, unsigned filename_idx, DB *db) { struct stat st; if (stat(filename, &st) == -1) { @@ -267,7 +274,7 @@ void load_frame_file(const char *filename, unsigned filename_idx, DB *db) exit(1); } - vector all_frames = db->load_frame_file(filename, st.st_size, filename_idx); + vector all_frames = db->load_frame_file(basename, st.st_size, filename_idx); if (!all_frames.empty()) { // We already had this cached in the database, so no need to look in the file. for (const DB::FrameOnDiskAndStreamIdx &frame : all_frames) { @@ -356,12 +363,17 @@ void load_frame_file(const char *filename, unsigned filename_idx, DB *db) size_t size = ftell(fp); fclose(fp); - db->store_frame_file(filename, size, all_frames); + db->store_frame_file(basename, size, all_frames); } void load_existing_frames() { - DB db(global_flags.working_directory + "/futatabi.db"); + QProgressDialog progress("Scanning frame directory...", "Abort", 0, 1); + progress.setWindowTitle("Futatabi"); + progress.setWindowModality(Qt::WindowModal); + progress.setMinimumDuration(1000); + progress.setMaximum(1); + progress.setValue(0); string frame_dir = global_flags.working_directory + "/frames"; DIR *dir = opendir(frame_dir.c_str()); @@ -371,6 +383,7 @@ void load_existing_frames() return; } + vector frame_basenames; for ( ;; ) { errno = 0; dirent *de = readdir(dir); @@ -382,15 +395,35 @@ void load_existing_frames() break; } - if (de->d_type == DT_REG) { + if (de->d_type == DT_REG || de->d_type == DT_LNK) { string filename = frame_dir + "/" + de->d_name; - load_frame_file(filename.c_str(), frame_filenames.size(), &db); frame_filenames.push_back(filename); + frame_basenames.push_back(de->d_name); } - } + if (progress.wasCanceled()) { + exit(1); + } + } closedir(dir); + progress.setMaximum(frame_filenames.size() + 2); + progress.setValue(1); + + progress.setLabelText("Opening database..."); + DB db(global_flags.working_directory + "/futatabi.db"); + + progress.setLabelText("Reading frame files..."); + progress.setValue(2); + + for (size_t i = 0; i < frame_filenames.size(); ++i) { + load_frame_file(frame_filenames[i].c_str(), frame_basenames[i], i, &db); + progress.setValue(i + 3); + if (progress.wasCanceled()) { + exit(1); + } + } + if (start_pts == -1) { start_pts = 0; } else { @@ -402,6 +435,8 @@ void load_existing_frames() sort(frames[stream_idx].begin(), frames[stream_idx].end(), [](const auto &a, const auto &b) { return a.pts < b.pts; }); } + + db.clean_unused_frame_files(frame_basenames); } int record_thread_func()