From 6374acc5477525f001188c5bd6d79dabb8f9cf3a Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Sun, 14 Apr 2024 01:14:47 +0200 Subject: [PATCH] positioning in videodump playbacks work --- ser.h | 2 +- video.cc | 2 +- videodev-dumpfile.cc | 52 ++++++++++++++++++++++++++++++++++++++++++++ videodev-dumpfile.h | 1 + 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/ser.h b/ser.h index 7253c30..8fdb811 100644 --- a/ser.h +++ b/ser.h @@ -90,7 +90,7 @@ class SER { void updateHeaderData(void); int64_t differenceLocalUTC(void); - + public: SER(); ~SER(); diff --git a/video.cc b/video.cc index a0f4d11..a65c6b8 100644 --- a/video.cc +++ b/video.cc @@ -411,7 +411,7 @@ void cb_video_btnrec (GtkWidget *widget, gpointer data) { videodev->SetConfig(device, w, h, format, parameter, cb_thread_video); videodev_thread = g_thread_new(driver.c_str(), videodev_threadprocess_wrapper, NULL); - // FIXME: workaround, soltuion should be: create a timer and request all controls + // FIXME: workaround, solution should be: create a timer and request all controls }; diff --git a/videodev-dumpfile.cc b/videodev-dumpfile.cc index 7f0f98a..9676899 100644 --- a/videodev-dumpfile.cc +++ b/videodev-dumpfile.cc @@ -98,6 +98,7 @@ int VideoDev_Dumpfile::GetDeviceList(std::list *list) { int VideoDev_Dumpfile::Open() { if (config.readdumppath == NULL) return VDEV_STATUS_ERROR; + VideoDevCtrl vctl; uint32_t inbuf[3]; int i; struct stat s; @@ -145,6 +146,14 @@ int VideoDev_Dumpfile::Open() { pixformat = ntohl(inbuf[i++]); conf_format = convert_from_pixelformat (pixformat); + vidctrls.clear(); + vctl.name = "FilePosition"; + vctl.id = 1; + vctl.min = 0; + vctl.max = 255; + vctl.value = 0; + vidctrls.push_back(vctl); + return VDEV_STATUS_OK; }; @@ -213,9 +222,12 @@ int VideoDev_Dumpfile::CaptureStop() { * If something goes wrong return an error code. * Return code VDEV_STATUS_AGAIN is not an error. There was no video image ready to read. */ +#define SIZE_FRAMEHEADER 8 +#define SIZE_DUMPHEADER 12 int VideoDev_Dumpfile::Grab(VideoFrameRaw *vf) { struct timeval curtv; unsigned int diff = 0; + std::list::iterator ctrl; if (fd == -1) return VDEV_STATUS_ERROR; @@ -236,6 +248,36 @@ int VideoDev_Dumpfile::Grab(VideoFrameRaw *vf) { LockMutex(); vf->CopyFrom(pixformat, w, h, inframe_size, inframe); + ctrl = vidctrls.begin(); + if (ctrl->value == 0) { + // fixed framesize -> calculate frames + switch (pixformat) { + case(V4L2_PIX_FMT_RGB24): + case(V4L2_PIX_FMT_BGR24): + fixedframesize = 3 * w * h; + break; + case(V4L2_PIX_FMT_RGB32): + case(V4L2_PIX_FMT_BGR32): + fixedframesize = 4 * w * h; + break; + case(V4L2_PIX_FMT_SGRBG8): + fixedframesize = 2 * w * h; + break; + case(V4L2_PIX_FMT_SGRBG16): + fixedframesize = 4 * w * h; + break; + default: + ctrl->max = 0; + ctrl->value = -1; + fixedframesize = 0; + break; + } + if (fixedframesize > 0) + ctrl->max = (filesize-SIZE_DUMPHEADER) / (fixedframesize + SIZE_FRAMEHEADER); + } + + if (ctrl->value != -1) ctrl->value++; + UnLockMutex(); // @@ -313,6 +355,16 @@ int VideoDev_Dumpfile::ReadFrame() { * set video control identified by id */ int VideoDev_Dumpfile::SetDevCtrl(unsigned int id, int value) { + std::list::iterator ctrl; + printf ("%s:%d VideoDev_Dumpfile::SetDevCtrl Set Offset to %d id:%d\n", __FILE__, __LINE__, value, id); + + if (id == 1) { + ctrl = vidctrls.begin(); + if (value != ctrl->value && value < ctrl->max) { + ctrl->value = value; + lseek (fd, SEEK_SET, SIZE_DUMPHEADER + (value * (SIZE_FRAMEHEADER + fixedframesize))); + } + } return VDEV_STATUS_OK; }; diff --git a/videodev-dumpfile.h b/videodev-dumpfile.h index b099047..fee41b0 100644 --- a/videodev-dumpfile.h +++ b/videodev-dumpfile.h @@ -39,6 +39,7 @@ private: uint32_t inframe_nexttime; int inframe_maxsize; int inframe_size; + int fixedframesize; int Grab(VideoFrameRaw *vf); int Open();