X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fmain.cpp;h=3efefd5e94a1a279c751e970fa8b27be69485f16;hb=0a3ea4312599886108fbd12e389ed3504c4dae60;hp=69ef55bedc33b89f2f85ad156e13e3b3708412c7;hpb=c20c3629e863bef3530f9f76b47fac0c93ba5b6f;p=nageru diff --git a/futatabi/main.cpp b/futatabi/main.cpp index 69ef55b..3efefd5 100644 --- a/futatabi/main.cpp +++ b/futatabi/main.cpp @@ -183,7 +183,7 @@ FrameOnDisk write_frame(int stream_idx, int64_t pts, const uint8_t *data, size_t HTTPD *global_httpd; void load_existing_frames(); -int record_thread_func(); +void record_thread_func(); int main(int argc, char **argv) { @@ -200,13 +200,11 @@ int main(int argc, char **argv) string frame_dir = global_flags.working_directory + "/frames"; - struct stat st; - if (stat(frame_dir.c_str(), &st) == -1) { + if (mkdir(frame_dir.c_str(), 0777) == 0) { fprintf(stderr, "%s does not exist, creating it.\n", frame_dir.c_str()); - if (mkdir(frame_dir.c_str(), 0777) == -1) { - perror(global_flags.working_directory.c_str()); - exit(1); - } + } else if (errno != EEXIST) { + perror(global_flags.working_directory.c_str()); + exit(1); } avformat_network_init(); @@ -344,6 +342,10 @@ void load_frame_file(const char *filename, const string &basename, unsigned file FrameOnDisk frame; frame.pts = hdr.pts(); frame.offset = ftell(fp); + if (frame.offset == -1) { + fprintf(stderr, "WARNING: %s: ftell() failed (%s).\n", filename, strerror(errno)); + break; + } frame.filename_idx = filename_idx; frame.size = hdr.file_size(); @@ -364,9 +366,14 @@ void load_frame_file(const char *filename, const string &basename, unsigned file filename, skipped_bytes); } - size_t size = ftell(fp); + off_t size = ftell(fp); fclose(fp); + if (size == -1) { + fprintf(stderr, "WARNING: %s: ftell() failed (%s).\n", filename, strerror(errno)); + return; + } + db->store_frame_file(basename, size, all_frames); } @@ -444,8 +451,13 @@ void load_existing_frames() db.clean_unused_frame_files(frame_basenames); } -int record_thread_func() +void record_thread_func() { + if (global_flags.stream_source.empty() || global_flags.stream_source == "/dev/null") { + // Save the user from some repetitive messages. + return; + } + pthread_setname_np(pthread_self(), "ReceiveFrames"); int64_t pts_offset; @@ -505,5 +517,4 @@ int record_thread_func() start_pts = last_pts + TIMEBASE; } - return 0; }