12using File_uniq = std::unique_ptr<FILE, file_deleter>;
34 File_uniq outfile(fopen(path.c_str(),
"wb"));
36 fprintf(stderr,
"Can't open output file %s\n", path.c_str());
59int main(
int argc,
char **argv){
61 fprintf(stderr,
"Usage: %s <socket path> <output path> <fps>\n", argv[0]);
70 using clock = std::chrono::steady_clock;
71 auto frame_time = std::chrono::duration_cast<clock::duration>(std::chrono::duration<double>(1 / std::stod(argv[3])));
72 auto next_frame = clock::now();
75 printf(
"Waiting for connection...\n");
77 printf(
"Connected...\n");
79 auto now = clock::now();
83 std::string path = argv[2];
84 std::string tmp_path = path +
".swp";
86 img_writer.
write_img(ipc_frame.get(), tmp_path);
87 std::filesystem::rename(tmp_path, path);
89 next_frame = std::max(next_frame + frame_time, now);
91 fprintf(stderr,
"Failed to read frame\n");
struct jpeg_error_mgr err_mgr
Img_writer & operator=(const Img_writer &)=delete
struct jpeg_compress_struct compress_ctx
bool write_img(Ipc_frame *f, const std::string &path)
Img_writer(const Img_writer &)=delete
Ipc_frame * ipc_frame_new()
std::unique_ptr< Ipc_frame, Ipc_frame_deleter > Ipc_frame_uniq
void ipc_frame_reader_wait_connect(struct Ipc_frame_reader *reader)
Ipc_frame_reader * ipc_frame_reader_new(const char *path)
bool ipc_frame_reader_read(Ipc_frame_reader *reader, Ipc_frame *dst)
std::unique_ptr< Ipc_frame_reader, Ipc_frame_reader_deleter > Ipc_frame_reader_uniq
std::unique_ptr< FILE, file_deleter > File_uniq