diff --git a/README.md b/README.md index 68f3147..7128f79 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,11 @@ The configuration is loaded in the following order. here are some usefull commands, maybe it helps to set the resolution to a readonable value -media-ctl --device 3 --set-v4l2 '"imx219 10-0010":0 [fmt:SRGGB10_1X10/3280x2464]' -media-ctl --device 0 --set-v4l2 '"imx219 10-0010":0 [fmt:SRGGB8_1X8/3280x2464]' +media-ctl --set-v4l2 '"imx219 10-0010":0 [fmt:SRGGB10_1X10/1920x1080]' +media-ctl --set-v4l2 '"ov5647 10-0036":0 [fmt:SRGGB10_1X10/1920x1080]' +v4l2-ctl -d /dev/v4l-subdev0 --set-ctrl 0x009a0901=1 +v4l2-ctl -d /dev/v4l-subdev0 --set-ctrl 0x00980912=1 +v4l2-ctl -d /dev/v4l-subdev0 --set-ctrl 0x0098090c=1 ./miniwebcam -vdevsize 3280 2464 -vdevformat RG10 diff --git a/configuration.cc b/configuration.cc index 1aba1e1..680c381 100644 --- a/configuration.cc +++ b/configuration.cc @@ -8,6 +8,18 @@ #include "miniwebcam.h" #include "configuration.h" +int get_resolution(const char *text, int *width, int *height) { + char *c; + + if ((c = strchr ((char *)text, 'X')) == NULL) + if ((c = strchr ((char *)text, 'x')) == NULL) return 0; + + *width = atoi (text); + *height = atoi (c+1); + + return 1; +} + Configuration config; /* @@ -54,11 +66,9 @@ int Configuration::PrintConfig() { jp.AddObject("ssl-cert-file", ssl_cert); jp.AddObject("vdev-iomode", vdev_iomode); jp.AddObject("vdev-device", vdev_device); - jp.AddObject("vdev-height", vdev_height); - jp.AddObject("vdev-width", vdev_width); + jp.AddObject("vdev-size", to_string(vdev_width) + "x" + to_string(vdev_height)); jp.AddObject("vdev-format", vdev_format); - jp.AddObject("web-height", web_height); - jp.AddObject("web-width", web_width); + jp.AddObject("web-size" , to_string(web_width) + "x" + to_string(web_height)); jp.AddObject("web-refresh", web_imagerefresh); jp.AddObject("vdev-dumpath", vdev_dumppath); @@ -74,6 +84,7 @@ int Configuration::PrintConfig() { }; + int Configuration::LoadFile(std::string fn) { JSONParse jp; int i; @@ -86,7 +97,6 @@ int Configuration::LoadFile(std::string fn) { // read from file if (jp.LoadFromFile(fn) != 0) { - fprintf (stderr, "Could not read json file '%s'. Error: %s\n", fn.c_str(), strerror(errno)); return 0; } @@ -94,16 +104,21 @@ int Configuration::LoadFile(std::string fn) { if (jp.GetValueInt("https_port", &i)) https_port = i; if (jp.GetValueString("ssl-key-file", &s)) ssl_key = s; if (jp.GetValueString("ssl-cert-file", &s)) ssl_cert = s; - if (jp.GetValueInt("web-height", &i)) web_height = i; - if (jp.GetValueInt("web-width", &i)) web_width = i; + if (jp.GetValueString("web-size", &s)) + if (get_resolution(s.c_str(), &web_width, &web_height) == 0) { + debug ("Configfile: %s Wrong web-size: %s", fn.c_str(), s.c_str()); + } + if (jp.GetValueInt("web-refresh", &i)) web_imagerefresh = i; if (jp.GetValueString("vdev-device", &s)) vdev_device = s; if (jp.GetValueString("vdev-format", &s)) vdev_format = s; if (jp.GetValueString("vdev-dumppath", &s)) vdev_dumppath = s; if (jp.GetValueInt("vdev-iomode", &i)) vdev_iomode = i; - if (jp.GetValueInt("vdev-height", &i)) vdev_height = i; - if (jp.GetValueInt("vdev-width", &i)) vdev_width = i; + if (jp.GetValueString("vdev-size", &s)) + if (get_resolution(s.c_str(), &vdev_width, &vdev_height) == 0) { + debug ("Configfile: %s Wrong vdev-size: %s", fn.c_str(), s.c_str()); + } // // restore language @@ -151,21 +166,21 @@ int Configuration::LoadArgs(int argc, char **argv) { ErrorExit("missing ms refresh time", -1); } if (strcmp(argv[i], "-websize") == 0) { - if ((i=i+2) < argc) { - web_width = atoi(argv[i-1]); - web_height = atoi(argv[i]); + if (++i < argc) { + if (get_resolution(argv[i], &web_width, &web_height) == 0) + ErrorExit("wrong web resolution parameter", -1); } else ErrorExit("missing web resolution parameter", -1); } if (strcmp(argv[i], "-vdevsize") == 0) { - if ((i=i+2) < argc) { - vdev_width = atoi(argv[i-1]); - vdev_height = atoi(argv[i]); + if (++i < argc) { + if (get_resolution(argv[i], &vdev_width, &vdev_height) == 0) + ErrorExit("wrong video resolution parameter", -1); } else - ErrorExit("missing video device resolution parameter", -1); + ErrorExit("missing video resolution parameter", -1); } if (strcmp(argv[i], "-vdeviomode") == 0) { if (++i < argc) { @@ -232,12 +247,12 @@ void Configuration::Help() { printf (" -sslkey FILE ssl key file\n"); printf (" -sslcert FILE ssl certfile\n"); printf ("\n"); - printf (" -websize INT INT define the web output resolution\n"); + printf (" -websize INTxINT define the web output resolution\n"); printf (" -webrefresh INT refresh rate for the snapshot\n"); printf ("\n"); printf (" -vdeviomode INT IOMode to read the video data, 0-read, 1-MMap\n"); printf (" -vdevdevice FILE Device File i.e. /dev/video2\n"); - printf (" -vdevsize INT INT define video input resolution\n"); + printf (" -vdevsize INTxINT define video input resolution\n"); printf (" -vdevformat FORMAT 4 Char Format code - see v4l2 documentation (videodev2.h)\n"); printf (" -vdevdumpfile FILE file to read raw image data\n"); printf (" -vdevdumppath PATH path to save dump data to\n"); diff --git a/main.cc b/main.cc index b121f69..01b8a95 100644 --- a/main.cc +++ b/main.cc @@ -14,6 +14,8 @@ int running = 1; pthread_mutex_t mtx; static void sig_int(int); int SetupSignals(); +std::string GetDefaultConfig(std::string name); + VideoFrame inputimage; VideoFrame currentimage; @@ -104,21 +106,23 @@ int main(int argc, char **argv) { pthread_t thr_webserver; pthread_t thr_video; - printf ("MiniWebCam:\n"); - // prepare signals, mutex and test output image if (SetupSignals() == 0) return 0; pthread_mutex_init(&mtx, NULL); currentimage.TestScreen(1920, 1080); // read and setup config - config.LoadArgs (argc, argv); config.LoadFile (config.GetFilename()); + config.LoadFile (GetDefaultConfig("miniwebcam.conf")); + config.LoadArgs (argc, argv); if (config.GetInitFlags() & CONF_INITFLAGS_PRINT) { config.PrintConfig(); return 0; } + printf ("MiniWebCam:\n"); + + if (config.GetInitFlags() & CONF_INITFLAGS_HELP) { config.Help(); return 0; @@ -135,6 +139,19 @@ int main(int argc, char **argv) { }; +std::string GetDefaultConfig(std::string name) { + std::string fn = ""; + char *hd = getenv ((char*)"HOME"); + + if (hd != NULL) { + fn = hd; + fn = fn + "/." + name; + } + + return fn; +}; + + int SetupSignals() { if (signal(SIGINT, sig_int) == SIG_ERR) { errorexit ("%s:%d could not set signal for SIGINT\n", __FILE__, __LINE__);