dumpfile will now loop

master
Steffen Pohle 3 years ago
parent cd9d76c1f5
commit bb87f38375

@ -1,4 +1,5 @@
2022-12-07: 2022-12-07:
- dump files will continussly loop
- fixed: dumpfile is not setting the frame size to the videodev.conf_height - fixed: dumpfile is not setting the frame size to the videodev.conf_height
and width variable and width variable

@ -842,7 +842,7 @@ void cb_input_btnscale (GtkWidget *widget, gpointer data) {
videodev->GetVideoInfo(&ww, &wh, NULL); videodev->GetVideoInfo(&ww, &wh, NULL);
ww = dw + (scale * ww); ww = dw + (scale * ww) + 1;
wh = dh + (scale * wh); wh = dh + (scale * wh);
gtk_window_resize(GTK_WINDOW(win), ww, wh); gtk_window_resize(GTK_WINDOW(win), ww, wh);

@ -16,6 +16,7 @@
#include <ctype.h> #include <ctype.h>
#include <fcntl.h> #include <fcntl.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/stat.h>
#include "convert.h" #include "convert.h"
@ -24,7 +25,8 @@
VideoDev_Dumpfile::VideoDev_Dumpfile() { VideoDev_Dumpfile::VideoDev_Dumpfile() {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
filesize = 0;
filepos = 0;
fd = -1; fd = -1;
w = 0; w = 0;
h = 0; h = 0;
@ -88,17 +90,28 @@ int VideoDev_Dumpfile::GetDeviceList(std::list<std::string> *list) {
int VideoDev_Dumpfile::Open() { int VideoDev_Dumpfile::Open() {
if (config.readdumppath == NULL) return VDEV_STATUS_ERROR; if (config.readdumppath == NULL) return VDEV_STATUS_ERROR;
std::string fname = config.readdumppath;
fname = fname + "/" + conf_device;
uint32_t inbuf[3]; uint32_t inbuf[3];
int i; 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()); printf ("%s:%d %s file %s\n", __FILE__, __LINE__, __FUNCTION__, fname.c_str());
if (fd >= 0) close (fd); 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) { 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)); 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; return VDEV_STATUS_ERROR;
} }
i = 0; i = 0;
filepos = 12;
conf_width = w = ntohl(inbuf[i++]); conf_width = w = ntohl(inbuf[i++]);
conf_height = h = ntohl(inbuf[i++]); conf_height = h = ntohl(inbuf[i++]);
pixformat = ntohl(inbuf[i++]); pixformat = ntohl(inbuf[i++]);
@ -133,6 +147,8 @@ int VideoDev_Dumpfile::Close() {
if (fd >= 0) { if (fd >= 0) {
close(fd); close(fd);
fd = -1; fd = -1;
filesize = 0;
filepos = 0;
} }
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
@ -230,11 +246,28 @@ int VideoDev_Dumpfile::ReadFrame() {
if (fd < 0) return VDEV_STATUS_ERROR; 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) { if (read (fd, inbuf, 4*2) != 4*2) {
printf ("%s:%d could not read frame header\n", __FILE__, __LINE__); printf ("%s:%d could not read frame header\n", __FILE__, __LINE__);
Close(); Close();
} }
filepos += (4*2);
inframe_size = ntohl(inbuf[0]); inframe_size = ntohl(inbuf[0]);
inframe_nexttime = ntohl(inbuf[1]); inframe_nexttime = ntohl(inbuf[1]);
@ -259,6 +292,7 @@ int VideoDev_Dumpfile::ReadFrame() {
printf ("%s:%d could not read frame\n", __FILE__, __LINE__); printf ("%s:%d could not read frame\n", __FILE__, __LINE__);
Close(); Close();
} }
filepos += inframe_size;
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
} }

@ -34,6 +34,8 @@ private:
uint32_t w; uint32_t w;
uint32_t h; uint32_t h;
uint32_t pixformat; uint32_t pixformat;
off_t filesize;
off_t filepos;
struct timeval starttv; struct timeval starttv;
unsigned char *inframe; unsigned char *inframe;
uint32_t inframe_nexttime; uint32_t inframe_nexttime;

Loading…
Cancel
Save