diff --git a/.gitignore b/.gitignore index e69de29..28e474c 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +miniwebcam +config.h + diff --git a/configuration.cc b/configuration.cc index b19b476..9ba2f64 100644 --- a/configuration.cc +++ b/configuration.cc @@ -44,6 +44,8 @@ Configuration::Configuration() { web_height = -1; web_width = -1; web_imagerefresh = 250; + + filter_ratio = 0.5; }; Configuration::~Configuration() { @@ -276,3 +278,59 @@ void Configuration::Help() { printf (" ./miniwebcam -sslkey ./ssl-key.pem -sslcert ./ssl-cert.pem -websize 800x600\n"); } + + + +void Configuration::SetValue(std::string name, std::string value) { + if (name.compare("filter_ratio") == 0) { + filter_ratio = atof(value.c_str()); + debug ("Filter Ration set to : %g", filter_ratio); + } + if (name.compare("auto_birghtness") == 0) { + auto_brightness = atol(value.c_str()); + debug ("Auto Brightness set to : %ld", auto_brightness); + } + if (name.compare("auto_birghtness_target") == 0) { + auto_brightness_target = atof(value.c_str()); + debug ("Filter Ration set to : %g", auto_brightness_target); + } +}; + + +std::string Configuration::GetValues() { + JSONParse jp; + JSONElement je; + + je.Clear(); + jp.Clear(); + + JSONParse jpe; + + // + jpe.Clear(); + jpe.AddObject("name", "filter_ratio"); + jpe.AddObject("value", filter_ratio); + jpe.AddObject("desc", "Ratio between new to old image (1.0 = new image)"); + je.SetAddArray("variables", jpe.ToString()); + + // + jpe.Clear(); + jpe.AddObject("name", "auto_brightness"); + jpe.AddObject("value", (int64_t) auto_brightness); + jpe.AddObject("desc", "Ctrl_ID for the brightness"); + je.SetAddArray("variables", jpe.ToString()); + + // + jpe.Clear(); + jpe.AddObject("name", "auto_brightness_target"); + jpe.AddObject("value", auto_brightness_target); + jpe.AddObject("desc", "target value for auto brightness"); + je.SetAddArray("variables", jpe.ToString()); + + // + + + jp.AddObject(je); + return jp.ToString(); +}; + diff --git a/configuration.h b/configuration.h index 7dc070f..76efa5c 100644 --- a/configuration.h +++ b/configuration.h @@ -47,12 +47,19 @@ public: std::string vdev_dumpfile; std::string vdev_dumppath; + unsigned int auto_brightness; + float auto_brightness_target; + float filter_ratio; + Configuration(); ~Configuration(); int LoadArgs(int argc, char **argv); int LoadFile(std::string fn); + void SetValue(std::string name, std::string value); + std::string GetValues(); + int GetInitFlags() { return initflags; }; std::string GetFilename() { return filename; }; diff --git a/convert.cc b/convert.cc index 950e071..62c2eb2 100644 --- a/convert.cc +++ b/convert.cc @@ -153,7 +153,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; @@ -188,7 +188,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; @@ -221,7 +221,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; @@ -255,7 +255,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; @@ -322,7 +322,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; @@ -365,7 +365,7 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig *(ptrdst++) = g; *(ptrdst++) = b; } - else { + if (ptrdstf) { *(ptrdstf++) = (float)r/255.0; *(ptrdstf++) = (float)g/255.0; *(ptrdstf++) = (float)b/255.0; diff --git a/main.cc b/main.cc index 1236689..e795018 100644 --- a/main.cc +++ b/main.cc @@ -43,6 +43,7 @@ static void *thread_webserver(void *ignored_argument) { static void *thread_video(void *ignored_argument) { + int cycle = 0; if (config.vdev_dumpfile.length() > 0) { vdev = new VideoDevice_Dump(); @@ -71,9 +72,10 @@ static void *thread_video(void *ignored_argument) { vdev->Stop(); vdev->Start(); } + if ((cycle++ % 2) == 0) vdev->RefreshCtrls(); Lock(); inputimage.CopyTo(¤timage, config.web_width, config.web_height); - if (inputfloatfilter.AddScaledImage(&inputfloat, 0.6, 0.4) == 0) + if (inputfloatfilter.AddScaledImage(&inputfloat, config.filter_ratio) == 0) inputfloat.CopyTo(&inputfloatfilter); inputfloatfilter.CopyTo(¤timagefloat); UnLock(); diff --git a/video.cc b/video.cc index 520fb04..eb44e5e 100644 --- a/video.cc +++ b/video.cc @@ -42,3 +42,13 @@ int VideoDevice::UnLock() { if (pthread_mutex_unlock(&mtx) == 0) return 1; else return 0; }; + + +void VideoDevice::RefreshCtrls() { + std::list::iterator i; + + for (i = vidctrls.begin(); i != vidctrls.end(); i++) { + GetDevCtrl(i->id, &(i->value)); + } + +}; diff --git a/video.h b/video.h index 732b366..327171d 100644 --- a/video.h +++ b/video.h @@ -88,6 +88,7 @@ class VideoDevice { virtual int SetDevCtrl(unsigned int id, int value) { debug (""); return 0; }; virtual int GetDevCtrl(unsigned int id, int *value) { debug (""); return 0; }; virtual std::list GetDevCtrls() { return vidctrls; }; + virtual void RefreshCtrls(); }; #include "videodevice_v4l2.h" diff --git a/videoframe.cc b/videoframe.cc index 72557b9..5e78be4 100644 --- a/videoframe.cc +++ b/videoframe.cc @@ -277,7 +277,7 @@ int VideoFrameFloat::CopyTo(VideoFrameFloat *dest) { }; -int VideoFrameFloat::AddScaledImage(VideoFrameFloat *vf, float f1, float f2) { +int VideoFrameFloat::AddScaledImage(VideoFrameFloat *vf, float ratio) { float *sptr, *dptr; int x, y; @@ -285,7 +285,7 @@ int VideoFrameFloat::AddScaledImage(VideoFrameFloat *vf, float f1, float f2) { for (dptr = memf, sptr = vf->GetPixBuf(), y = 0; y < height; y++) for (x = 0; x < width*3; x++) { - *dptr = f1 * (*dptr) + f2 * (*sptr); + *dptr = (1.0-ratio) * (*dptr) + ratio * (*sptr); dptr++; sptr++; } diff --git a/videoframe.h b/videoframe.h index 2fdfd21..75fd4b6 100644 --- a/videoframe.h +++ b/videoframe.h @@ -49,7 +49,7 @@ class VideoFrameFloat { int CopyTo(VideoFrame *dest); int CopyTo(VideoFrameFloat *dest); - int AddScaledImage(VideoFrameFloat *vf, float f1, float f2); + int AddScaledImage(VideoFrameFloat *vf, float ratio); }; diff --git a/webserver.cc b/webserver.cc index 02f0a02..a883979 100644 --- a/webserver.cc +++ b/webserver.cc @@ -10,6 +10,9 @@ extern VideoDevice *vdev; std::string API_Get_Ctrls(); std::string API_Set_Ctrl(std::string request); +std::string API_Get_Values(); +std::string API_Set_Value(std::string request); + // InMemoryFile GenerateJpgFile(VideoFrame *vf); InMemoryTar assets; @@ -44,9 +47,20 @@ int WebCamServer::HandleRequest (WebRequestBuffer *requestbuffer, WebServerClien if (webclient->SendResponseData(requestbuffer, API_Get_Ctrls(), "") != 1) return 0; } else if (request.find("/set/ctrl") != std::string::npos) { - debug ("set controls"); + debug ("set control"); if (webclient->SendResponseData(requestbuffer, API_Set_Ctrl(request), "") != 1) return 0; } + + else if (request.compare("/get/variables") == 0) { + debug ("get values"); + if (webclient->SendResponseData(requestbuffer, API_Get_Values(), "") != 1) return 0; + } + else if (request.find("/set/var") != std::string::npos) { + debug ("set value"); + if (webclient->SendResponseData(requestbuffer, API_Set_Value(request), "") != 1) return 0; + } + + else if (isfile("www"+request)) { if (webclient->SendResponseFile(requestbuffer, request, "") != 1) return 0; } @@ -102,14 +116,56 @@ std::string API_Set_Ctrl(std::string request) { while ((t = strchr (t, '/'))) { i++; t++; - if (i == 3) id = atol (t); - if (i == 4) value = atoi (t); + if (i == 3) { + char *v = strchr (t, '='); + id = atol (t); + if (v == NULL) break; + value = atoi(++v); + debug ("id:%d value:%d", id, value); + vdev->SetDevCtrl(id, value); + break; + } + if (i > 4) break; + } + + + JSONParse jp; + jp.Clear(); + return jp.ToString(); +} + + +std::string API_Get_Values() { + return config.GetValues(); +} + + + +std::string API_Set_Value(std::string request) { + std::string name; + std::string value; + char *t = (char*) request.c_str(); + + int i = 0; + while ((t = strchr (t, '/'))) { + i++; + t++; + printf ("%d %s\n", i, t); + if (i == 3) { + char *v = strchr (t, '='); + if (v == NULL) break; + name = ((std::string) t).substr(0, (v-t)); + value = (++v); + debug ("name:%s value:%s", name.c_str(), value.c_str()); + config.SetValue(name, value); + break; + } if (i > 4) break; } - vdev->SetDevCtrl(id, value); JSONParse jp; jp.Clear(); return jp.ToString(); -} \ No newline at end of file +} + diff --git a/www/default.css b/www/default.css index 810e7ef..822a93e 100644 --- a/www/default.css +++ b/www/default.css @@ -2,3 +2,19 @@ body { background-color: #444; color: #BBB; } + +.noborder { + border: none; +} + +.withborder { + border: thin solid; + border-collapse: collapse; +} + +.float { + float: left; + padding: 10px; + border: thin solid; +} + diff --git a/www/index.html b/www/index.html index 1ab02af..c136443 100644 --- a/www/index.html +++ b/www/index.html @@ -7,10 +7,12 @@ -
- -
- + +
+ + + +

@@ -19,20 +21,27 @@
-
+
+

Controls


+
+
+
+

Infos


+
+

- \ No newline at end of file