#include #include #include #include #include #include "configuration.h" #include "miniwebcam.h" int running = 1; static void sig_int(int); int SetupSignals(); VideoFrame inputimage; VideoFrame currentimage; void ErrorExit(std::string text, int errorcode) { printf ("Error: %s\n", text.c_str()); exit (errorcode); }; int main(int argc, char **argv) { printf ("MiniWebCam:\n"); if (SetupSignals() == 0) return 0; config.LoadArgs (argc, argv); config.LoadFile (config.GetFilename()); if (config.GetInitFlags() & CONF_INITFLAGS_PRINT) { config.PrintConfig(); return 0; } if (config.GetInitFlags() & CONF_INITFLAGS_HELP) { config.Help(); return 0; } VideoDevice_V4L2 vdev; WebCamServer webserver; currentimage.TestScreen(1920, 1080); webserver.SetupPorts(config.http_port, config.https_port); webserver.SetupSSL(config.ssl_key, config.ssl_cert); webserver.Start(); if (vdev.SetDevice (config.vdev_device, config.vdev_width, config.vdev_height, convert_to_pixelformat(config.vdev_format)) == 0) { debug ("could not setup device.\n"); return 0; } if (vdev.SetIOMode (config.vdev_iomode) == 0) { debug ("could not setup iomode.\n"); return 0; } if (vdev.Start() == 0) { debug ("Error: could not start video.\n"); return 0; } currentimage.SetSize (config.web_width, config.web_height); while (running) { if (vdev.GetFrame(&inputimage) == 0) { vdev.Stop(); vdev.Start(); } inputimage.CopyTo(¤timage, config.web_width, config.web_height); webserver.Loop(); usleep (1000); } vdev.Stop(); webserver.Stop(); return 0; }; int SetupSignals() { if (signal(SIGINT, sig_int) == SIG_ERR) { errorexit ("%s:%d could not set signal for SIGINT\n", __FILE__, __LINE__); return 0; } if (signal(SIGTERM, sig_int) == SIG_ERR) { errorexit ("%s:%d could not set signal for SIGTERM\n", __FILE__, __LINE__); return 0; } if (signal(SIGHUP, sig_int) == SIG_ERR) { errorexit ("%s:%d could not set signal for SIGHUB\n", __FILE__, __LINE__); return 0; } if (signal(SIGUSR1, sig_int) == SIG_ERR) { errorexit ("%s:%d could not set signal for SIGHUB\n", __FILE__, __LINE__); return 0; } return 1; }; static void sig_int(int sig) { if (signal (SIGINT, sig_int) == SIG_ERR) errorexit ("could not set up signal SIGINT\n"); printf ("\n\nSignal Int\n\n"); running = 0; }