fixed alot of bugs..

master
Steffen Pohle 1 year ago
parent eb98013780
commit 7c4f88b596

@ -27,25 +27,142 @@ std::string convert_from_pixelformat (uint32_t fmt) {
int main(int argc, char **argv) { int fixfile(char *src, char *dest) {
int fd; int fd, fd2;
int cnt = 0; int cnt = 0;
char *inbuf = NULL; char *inbuf = NULL;
int inbufsize = 0; int inbufsize = 0;
int frmcnt = 0;
uint32_t i; uint32_t i;
uint32_t size; uint32_t size, size2;
printf ("fix file:'%s' output file:'%s'\n", src, dest);
if ((fd = open (src, O_RDONLY)) < 0) {
printf ("could not open input file: %s\n", strerror(errno));
return -1;
}
if ((fd2 = open (dest, O_WRONLY | O_CREAT | O_TRUNC), S_IRUSR | S_IWUSR) < 0) {
printf ("could not open output file: %s\n", strerror(errno));
close (fd);
return -1;
}
//
// read header w, h, pixfmt
if (read (fd, &i, 4) != 4) {
printf ("could not read all bytes.\n");
close (fd);
return -1;
}
if (write (fd2, &i, 4) != 4) {
printf ("could not write all bytes.\n");
close (fd2);
close (fd);
return -1;
}
printf (" Width: %d\n", ntohl(i));
if (read (fd, &i, 4) != 4) {
printf ("could not read all bytes.\n");
close (fd);
return -1;
}
if (write (fd2, &i, 4) != 4) {
printf ("could not write all bytes.\n");
close (fd2);
close (fd);
return -1;
}
printf (" Height: %d\n", ntohl(i));
if (argc != 2) { if (read (fd, &i, 4) != 4) {
printf ("please give a file name as parameter.\n"); printf ("could not read all bytes.\n");
printf ("checkdumpfile FILE\n"); close (fd);
printf ("\n");
return -1; return -1;
} }
if (write (fd2, &i, 4) != 4) {
printf ("could not write all bytes.\n");
close (fd2);
close (fd);
return -1;
}
printf(" Pixfmt: %s\n", convert_from_pixelformat(ntohl(i)).c_str());
printf ("reading file :'%s'\n", argv[1]);
if ((fd = open (argv[1], O_RDONLY)) < 0) { //
// read frame
while (read (fd, &size, 4) == 4) {
size = ntohl(size);
size2 = htonl(size / 2);
if (write (fd2, &size2, 4) != 4) {
printf ("could not write framesize of frame %d.\n", frmcnt);
close (fd2);
close (fd);
return -1;
}
if (read (fd, &i, 4) != 4) {
printf ("could not read all bytes.\n");
close (fd);
return -1;
}
if (write (fd2, &i, 4) != 4) {
printf ("could not write timestamp of frame %d.\n", frmcnt);
close (fd2);
close (fd);
return -1;
}
i = ntohl(i);
if (inbuf == NULL){
inbuf = (char*) malloc (size);
inbufsize = size;
}
else if (inbufsize < size) {
inbuf = (char*)realloc(inbuf, size);
inbufsize = size;
}
if (inbuf == NULL) {
printf ("Error could not allocate enough memory\n");
close (fd);
return -1;
}
if (read (fd, inbuf, size) != size) {
printf ("could not read to next frame.\n");
close (fd);
return -1;
}
if (write (fd2, inbuf, size/2) != size/2) {
printf ("could not write frame %d.\n", frmcnt);
close (fd2);
close (fd);
return -1;
}
printf ("Frame: %-9d Timestamp:%-9d Size:%d\n", cnt++, i, size);
}
close (fd);
close (fd2);
return 0;
}
int checkfile(char *src) {
uint32_t i;
uint32_t size;
int fd;
int cnt = 0;
char *inbuf = NULL;
int inbufsize = 0;
printf ("reading file :'%s'\n", src);
if ((fd = open (src, O_RDONLY)) < 0) {
printf ("could not open file: %s\n", strerror(errno)); printf ("could not open file: %s\n", strerror(errno));
} }
@ -111,5 +228,22 @@ int main(int argc, char **argv) {
close (fd); close (fd);
return 0; return 0;
} };
int main(int argc, char **argv) {
if (argc == 2) {
checkfile(argv[1]);
}
else if (argc == 3) {
fixfile(argv[1], argv[2]);
}
else {
printf ("please give a file name as parameter.\n");
printf ("checkdumpfile FILE to check file\n");
printf ("checkdumpfile SRCFILE DESTFILE to fix file\n");
printf ("\n");
}
return 0;
}

@ -532,20 +532,22 @@ int PixCopy(unsigned char *srcdata, uint32_t srcpixfmt, int srcw, int srch,
dsize = (*dsth) * (*dstw) * bytesperpixel; dsize = (*dsth) * (*dstw) * bytesperpixel;
if ((*dstsize) < dsize || (*dstdataptr) == NULL) { if ((*dstsize) < dsize || (*dstdataptr) == NULL) {
*dstdataptr = (unsigned char*) realloc (*dstdataptr, dsize); *dstdataptr = (unsigned char*) realloc (*dstdataptr, dsize);
if (*dstdataptr == NULL) {
errorexit((char*)"%s:%d could not realloc memory. dsize:%d error:%s\n", __FILE__, __LINE__, dsize, strerror(errno));
}
*dstsize = dsize; *dstsize = dsize;
printf ("%s:%d reallocate memory for destination raw image\n", __FILE__, __LINE__); printf ("%s:%d reallocate memory for destination raw image\n", __FILE__, __LINE__);
} }
unsigned char *dptr, *sptr; unsigned char *dptr, *sptr;
int y, dy, x, dx; int y, dy, x;
// debug_drawraw(srcdata, srcpixfmt, srcw, srch); // debug_drawraw(srcdata, srcpixfmt, srcw, srch);
for (y = regiony & (~1), dy = 0; dy < *dsth && y < srch; y++, dy++) { for (y = regiony & (~1), dy = 0; dy < *dsth && y < srch; y++, dy++) {
x = regionx & (~1); x = regionx & (~1);
dptr = (*dstdataptr) + bytesperpixel * (dy * *dstw); dptr = (*dstdataptr) + bytesperpixel * (dy * *dstw);
sptr = (srcdata) + bytesperpixel * ( y * srcw + x); sptr = (srcdata) + bytesperpixel * ( y * srcw + x);
for (dx = (*dstw*bytesperpixel); dx > 0; dx--, dptr++, sptr++) memcpy (dptr, sptr, *dstw * bytesperpixel);
*dptr = *sptr;
} }
if (config.show_debugwin) debug_drawraw(*dstdataptr, srcpixfmt, *dstw, *dsth); if (config.show_debugwin) debug_drawraw(*dstdataptr, srcpixfmt, *dstw, *dsth);

@ -6,6 +6,7 @@
#include <string> #include <string>
#include <time.h> #include <time.h>
#include <fcntl.h> #include <fcntl.h>
#include <execinfo.h>
#include "debug.h" #include "debug.h"
#include "convert.h" #include "convert.h"
@ -144,3 +145,27 @@ void debug_drawraw(unsigned char *data, int pixfmt, int w, int h) {
debug_unlock_mutex(); debug_unlock_mutex();
}; };
#define BT_BUF_SIZE 100
void debug_backtrace () {
unsigned int nptrs;
void *buffer[BT_BUF_SIZE];
char **strings;
nptrs = backtrace(buffer, BT_BUF_SIZE);
printf("backtrace() returned %d addresses\n", nptrs);
/* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO)
* would produce similar output to the following: */
strings = backtrace_symbols(buffer, nptrs);
if (strings == NULL) {
perror("backtrace_symbols");
exit(EXIT_FAILURE);
}
for (size_t j = 0; j < nptrs; j++)
printf("%s\n", strings[j]);
free(strings);
};

@ -28,6 +28,7 @@ extern void debug_tofile(char *fname, int isheader, char *fmt, ...);
extern inline void debug_lock_mutex(); extern inline void debug_lock_mutex();
extern inline void debug_unlock_mutex(); extern inline void debug_unlock_mutex();
void debug_drawraw(unsigned char *data, int pixfmt, int w, int h); void debug_drawraw(unsigned char *data, int pixfmt, int w, int h);
void debug_backtrace ();
#endif #endif

@ -204,7 +204,7 @@ void Output::Thread() {
} }
if (outputser) outputser->setObserver((char *)"FIXME:read username from OS"); if (outputser) outputser->setObserver((char *)"FIXME:read username from OS");
if (outputser) outputser->setTelescope((char *)"FIXME:not implemented yet"); if (outputser) outputser->setTelescope((char *)"FIXME:not implemented yet");
if (outputser) outputser->setInstrument((char *)"FIXME:just read device from dirver"); if (outputser) outputser->setInstrument((char *)"FIXME:just read device from driver");
if (outputser) outputser->setNumberOfFrames(0); if (outputser) outputser->setNumberOfFrames(0);
if (outputser) outputser->writeHeader(); if (outputser) outputser->writeHeader();
} }
@ -226,12 +226,13 @@ void Output::Thread() {
outputser->appendFrame(inFrame.data); outputser->appendFrame(inFrame.data);
} }
} }
inFrameNew = 0; inFrameNew = 0;
} }
UnLockInMutex(); UnLockInMutex();
usleep (10000); // sleep 10ms usleep (1000); // sleep 10ms
} }
} }

@ -249,6 +249,8 @@ int VideoDev_Dumpfile::Grab(VideoFrameRaw *vf) {
LockMutex(); LockMutex();
vf->CopyFrom(pixformat, w, h, inframe_size, inframe); vf->CopyFrom(pixformat, w, h, inframe_size, inframe);
UnLockMutex();
ctrl = vidctrls.begin(); ctrl = vidctrls.begin();
if (ctrl->value == 0) { if (ctrl->value == 0) {
// fixed framesize -> calculate frames // fixed framesize -> calculate frames
@ -262,10 +264,10 @@ int VideoDev_Dumpfile::Grab(VideoFrameRaw *vf) {
fixedframesize = 4 * w * h; fixedframesize = 4 * w * h;
break; break;
case(V4L2_PIX_FMT_SGRBG8): case(V4L2_PIX_FMT_SGRBG8):
fixedframesize = 2 * w * h; fixedframesize = 1 * w * h;
break; break;
case(V4L2_PIX_FMT_SGRBG16): case(V4L2_PIX_FMT_SGRBG16):
fixedframesize = 4 * w * h; fixedframesize = 2 * w * h;
break; break;
default: default:
ctrl->max = 0; ctrl->max = 0;
@ -279,11 +281,11 @@ int VideoDev_Dumpfile::Grab(VideoFrameRaw *vf) {
if (ctrl->value != -1) ctrl->value++; if (ctrl->value != -1) ctrl->value++;
UnLockMutex();
// //
// read next frame // read next frame
LockMutex();
ReadFrame(); ReadFrame();
UnLockMutex();
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
} }
@ -337,7 +339,7 @@ int VideoDev_Dumpfile::ReadFrame() {
// allocate memory and read frame // allocate memory and read frame
if (inframe == NULL) { if (inframe == NULL) {
Close(); Close();
printf ("%s:%d cloud not allocate enought memory\n", __FILE__, __LINE__); printf ("%s:%d could not allocate enough memory\n", __FILE__, __LINE__);
return VDEV_CBSTATUS_ERROR; return VDEV_CBSTATUS_ERROR;
} }
if (read (fd, inframe, inframe_size) != inframe_size) { if (read (fd, inframe, inframe_size) != inframe_size) {
@ -360,20 +362,40 @@ int VideoDev_Dumpfile::ReadFrame() {
*/ */
int VideoDev_Dumpfile::SetDevCtrl(unsigned int id, int value) { int VideoDev_Dumpfile::SetDevCtrl(unsigned int id, int value) {
std::list<VideoDevCtrl>::iterator ctrl; std::list<VideoDevCtrl>::iterator ctrl;
int framerest;
off_t newfilepos = 0;
printf ("%s:%d VideoDev_Dumpfile::SetDevCtrl Set Offset to %d id:%d fixedframesize:%d\n", __FILE__, __LINE__, value, id, fixedframesize); printf ("%s:%d VideoDev_Dumpfile::SetDevCtrl Set Offset to %d id:%d fixedframesize:%d\n", __FILE__, __LINE__, value, id, fixedframesize);
struct timeval curtv;
if (id == 1) { if (id == 1) {
ctrl = vidctrls.begin(); ctrl = vidctrls.begin();
if (value != ctrl->value && value < ctrl->max) { if (value != ctrl->value && value < ctrl->max) {
filepos = SIZE_DUMPHEADER + (value * (SIZE_FRAMEHEADER + fixedframesize)); filepos = SIZE_DUMPHEADER + ((off_t)value * (SIZE_FRAMEHEADER + (off_t)fixedframesize));
ctrl->value = value; printf ("%s:%d filepos:%ld\n", __FILE__, __LINE__, filepos);
if (lseek (fd, filepos, SEEK_SET) < 0) {
if ((newfilepos = lseek (fd, filepos, SEEK_SET)) < 0) {
printf ("%s:%d ******* lseek error:%s\n", __FILE__, __LINE__, strerror(errno)); printf ("%s:%d ******* lseek error:%s\n", __FILE__, __LINE__, strerror(errno));
} }
else {
framerest = (newfilepos - SIZE_DUMPHEADER)%(SIZE_FRAMEHEADER + fixedframesize);
ctrl->value = (newfilepos - SIZE_DUMPHEADER)/(SIZE_FRAMEHEADER + fixedframesize);
if (ctrl->value != value || framerest != 0) {
printf ("%s:%d could not set file to correct position. ctrl->value:%d value:%d Framerest:%d\n", __FILE__, __LINE__, ctrl->value, value, framerest);
}
else {
//
// read first frame
ReadFrame();
gettimeofday(&curtv, NULL);
starttv.tv_sec = curtv.tv_sec - (inframe_nexttime/1000);
}
}
} }
else printf ("%s:%d could not set video position (ctrl->value:%d value:%d max:%d)\n",
__FILE__, __LINE__, ctrl->value, value, ctrl->max); // else printf ("%s:%d could not set video position (ctrl->value:%d value:%d max:%d)\n",
// __FILE__, __LINE__, ctrl->value, value, ctrl->max);
} }
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
}; };

@ -289,8 +289,11 @@ int VideoDev_SVBCam::CaptureStart() {
// //
// allocate memory for frame data // allocate memory for frame data
if (inframe != NULL) free (inframe); if (inframe != NULL) free (inframe);
inframe_size = 4 * inframe_w * inframe_h; inframe_size = get_bytesperpixel(inframe_pixfmt) * inframe_w * inframe_h;
inframe = (unsigned char*) malloc(inframe_size); inframe = (unsigned char*) malloc(inframe_size);
if (inframe == NULL) {
errorexit ((char*)"%s:%d could not allocate memory for framebuffer. Error:%s\n", __FILE__, __LINE__, strerror(errno));
}
pixelformat = inframe_pixfmt; pixelformat = inframe_pixfmt;
return VDEV_STATUS_OK; return VDEV_STATUS_OK;
@ -326,7 +329,7 @@ int VideoDev_SVBCam::CaptureStop() {
* Return code VDEV_STATUS_AGAIN is not an error. There was no video image ready to read. * Return code VDEV_STATUS_AGAIN is not an error. There was no video image ready to read.
*/ */
// FIXME: SVBGetVideoData needs to be outside of Lock/UnLockMutex - using inside thread inbuffer // FIXME: SVBGetVideoData needs to be outside of Lock/UnLockMutex - using inside thread inbuffer
int VideoDev_SVBCam::Grab(VideoFrameRaw *vf) { int VideoDev_SVBCam::Grab(VideoFrameRaw *vfr) {
int err; int err;
if (inframe == NULL) return VDEV_STATUS_ERROR; if (inframe == NULL) return VDEV_STATUS_ERROR;
@ -341,7 +344,8 @@ int VideoDev_SVBCam::Grab(VideoFrameRaw *vf) {
} }
} }
LockMutex(); LockMutex();
vf->CopyFrom(inframe_pixfmt, inframe_w, inframe_h, inframe_size, inframe);
vfr->CopyFrom(inframe_pixfmt, inframe_w, inframe_h, inframe_size, inframe);
UnLockMutex(); UnLockMutex();
return VDEV_STATUS_OK; return VDEV_STATUS_OK;

@ -44,7 +44,7 @@ private:
ConvertData cdata; ConvertData cdata;
int camid; int camid;
int Grab(VideoFrameRaw *vf); int Grab(VideoFrameRaw *vfr);
int Open(); int Open();
int Close(); int Close();
int CaptureStart(); int CaptureStart();

@ -29,6 +29,7 @@
#include "convert.h" #include "convert.h"
VideoDev::VideoDev() { VideoDev::VideoDev() {
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__); printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
conf_device = ""; conf_device = "";
@ -235,3 +236,29 @@ list<VideoDevCtrl> VideoDev::GetCtrlsMinMaxValue() {
}; };
int VideoDev::get_bytesperpixel (uint32_t pixfmt) {
int bytesperpixel = 4;
switch (pixfmt) {
case (V4L2_PIX_FMT_SGRBG8):
bytesperpixel = 1;
break;
case (V4L2_PIX_FMT_SGRBG16):
bytesperpixel = 2;
break;
case (V4L2_PIX_FMT_BGR32):
case (V4L2_PIX_FMT_RGB32):
bytesperpixel = 4;
break;
case (V4L2_PIX_FMT_BGR24):
case (V4L2_PIX_FMT_RGB24):
bytesperpixel = 3;
break;
default:
errorexit((char*)"%s:%d unsupported pixelformat %s\n", convert_from_pixelformat(pixfmt).c_str());
break;
}
return bytesperpixel;
}

@ -136,6 +136,8 @@ public:
VideoDev(); VideoDev();
virtual ~VideoDev(); virtual ~VideoDev();
static int get_bytesperpixel (uint32_t pixfmt);
void SetConfig(std::string dev, int w, int h, std::string format, std::string parameter, gboolean (*callback_func)(gpointer data)); void SetConfig(std::string dev, int w, int h, std::string format, std::string parameter, gboolean (*callback_func)(gpointer data));
void ThreadProcess(); void ThreadProcess();
void Stop(); void Stop();

@ -72,6 +72,7 @@ int VideoFrameRaw::ReAlloc(int newsize) {
else if (size < newsize || size > newsize) { else if (size < newsize || size > newsize) {
if ((newdata = (unsigned char*) realloc (data, newsize)) == NULL) { if ((newdata = (unsigned char*) realloc (data, newsize)) == NULL) {
free (data); free (data);
data = NULL;
size = 0; size = 0;
return -1; return -1;
} }

Loading…
Cancel
Save