From bb87f38375cb353ca086a809c7ed5080b9175096 Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Wed, 7 Dec 2022 23:11:22 +0100 Subject: [PATCH] dumpfile will now loop --- ChangeLog | 1 + video.cc | 2 +- videodev-dumpfile.cc | 48 +++++++++++++++++++++++++++++++++++++------- videodev-dumpfile.h | 2 ++ 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index daa1dae..5adcc8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ 2022-12-07: +- dump files will continussly loop - fixed: dumpfile is not setting the frame size to the videodev.conf_height and width variable diff --git a/video.cc b/video.cc index 69eb607..3f2799b 100644 --- a/video.cc +++ b/video.cc @@ -842,7 +842,7 @@ void cb_input_btnscale (GtkWidget *widget, gpointer data) { videodev->GetVideoInfo(&ww, &wh, NULL); - ww = dw + (scale * ww); + ww = dw + (scale * ww) + 1; wh = dh + (scale * wh); gtk_window_resize(GTK_WINDOW(win), ww, wh); diff --git a/videodev-dumpfile.cc b/videodev-dumpfile.cc index eed818e..bb3b7ae 100644 --- a/videodev-dumpfile.cc +++ b/videodev-dumpfile.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include "convert.h" @@ -24,7 +25,8 @@ VideoDev_Dumpfile::VideoDev_Dumpfile() { printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); - + filesize = 0; + filepos = 0; fd = -1; w = 0; h = 0; @@ -88,17 +90,28 @@ int VideoDev_Dumpfile::GetDeviceList(std::list *list) { int VideoDev_Dumpfile::Open() { if (config.readdumppath == NULL) return VDEV_STATUS_ERROR; - std::string fname = config.readdumppath; - - - fname = fname + "/" + conf_device; - uint32_t inbuf[3]; int i; + struct stat s; + + std::string fname = config.readdumppath; + fname = fname + "/" + conf_device; printf ("%s:%d %s file %s\n", __FILE__, __LINE__, __FUNCTION__, fname.c_str()); if (fd >= 0) close (fd); + fd = -1; + + + // + // read filesize + if (stat (fname.c_str(), &s) != 0) { + printf ("%s:%d %s could not read stat of file '%s'. Error:%s\n", __FILE__, __LINE__, __FUNCTION__, + fname.c_str(), strerror(errno)); + Close(); + return VDEV_STATUS_ERROR; + } + filesize = s.st_size; if ((fd = open(fname.c_str(), O_RDONLY)) == -1) { printf ("%s:%d could not open file '%s' error:%s\n", __FILE__, __LINE__, fname.c_str(), strerror(errno)); @@ -114,6 +127,7 @@ int VideoDev_Dumpfile::Open() { return VDEV_STATUS_ERROR; } i = 0; + filepos = 12; conf_width = w = ntohl(inbuf[i++]); conf_height = h = ntohl(inbuf[i++]); pixformat = ntohl(inbuf[i++]); @@ -133,6 +147,8 @@ int VideoDev_Dumpfile::Close() { if (fd >= 0) { close(fd); fd = -1; + filesize = 0; + filepos = 0; } return VDEV_STATUS_OK; @@ -230,11 +246,28 @@ int VideoDev_Dumpfile::ReadFrame() { if (fd < 0) return VDEV_STATUS_ERROR; - // read header + // + // check position, if end of file restart from beginning + if (filepos == filesize) { + printf ("%s:%d end of file start with first frame\n", __FILE__, __LINE__); + if (lseek(fd, 12, SEEK_SET) != 12) { + printf ("%s:%d %s lseek returned: %s\n", __FILE__, __LINE__, __FUNCTION__, strerror(errno)); + Close(); + } + else { // reset filepos and starttime + filepos = 12; + gettimeofday(&starttv, NULL); + } + } + + // + // read frame if (read (fd, inbuf, 4*2) != 4*2) { printf ("%s:%d could not read frame header\n", __FILE__, __LINE__); Close(); + } + filepos += (4*2); inframe_size = ntohl(inbuf[0]); inframe_nexttime = ntohl(inbuf[1]); @@ -259,6 +292,7 @@ int VideoDev_Dumpfile::ReadFrame() { printf ("%s:%d could not read frame\n", __FILE__, __LINE__); Close(); } + filepos += inframe_size; return VDEV_STATUS_OK; } diff --git a/videodev-dumpfile.h b/videodev-dumpfile.h index 4f9396d..f8a731e 100644 --- a/videodev-dumpfile.h +++ b/videodev-dumpfile.h @@ -34,6 +34,8 @@ private: uint32_t w; uint32_t h; uint32_t pixformat; + off_t filesize; + off_t filepos; struct timeval starttv; unsigned char *inframe; uint32_t inframe_nexttime;