diff --git a/configuration.cc b/configuration.cc index 5b16dd0..610086c 100644 --- a/configuration.cc +++ b/configuration.cc @@ -294,7 +294,7 @@ void Configuration::SetValue(std::string name, std::string value) { filter_ratio = atof(value.c_str()); debug ("Filter Ration set to : %g", filter_ratio); } - if (name.compare("auto_birghtness") == 0) { + if (name.compare("auto_brightness") == 0) { auto_brightness = atol(value.c_str()); debug ("Auto Brightness set to : %ld", auto_brightness); } @@ -341,4 +341,3 @@ std::string Configuration::GetValues() { jp.AddObject(je); return jp.ToString(); }; - diff --git a/convert.cc b/convert.cc index 7d4eb51..21820ed 100644 --- a/convert.cc +++ b/convert.cc @@ -132,8 +132,6 @@ int Convert (ConvertData *cdata, VideoFrame *dest, VideoFrameFloat *destf, unsig destf->SetSize(srcw, srch); ptrdstf = destf->GetPixBuf(); } - - switch (pixelformat) { case (V4L2_PIX_FMT_RGB32): for (ys = 0, yd = 0; ys < (signed int)srch; ys++) { diff --git a/main.cc b/main.cc index b77aebb..9c0b54a 100644 --- a/main.cc +++ b/main.cc @@ -47,13 +47,13 @@ static void *thread_webserver(void *ignored_argument) { static void *thread_video(void *ignored_argument) { - int cycle = 0; - timeval tv1; - time_t time1; + timeval tv_fps; + time_t time_fps, time_refreshctls; - time1 = time(NULL); + time_fps = time(NULL); + time_refreshctls = time(NULL); - gettimeofday(&tv1, NULL); + gettimeofday(&tv_fps, NULL); if (config.vdev_dumpfile.length() > 0) { vdev = new VideoDevice_Dump(); @@ -82,9 +82,12 @@ static void *thread_video(void *ignored_argument) { vdev->Stop(); vdev->Start(); } - if ((cycle++ % 10) == 0) vdev->RefreshCtrls(); - if (time(NULL) - time1 > 5) { - time1 = time(NULL); + if (time(NULL) - time_refreshctls > 10) { + vdev->RefreshCtrls(); + time_refreshctls = time(NULL); + } + if (time(NULL) - time_fps > 5) { + time_fps = time(NULL); debug ("FPS: %f", framespersecond); } Lock(); @@ -93,8 +96,8 @@ static void *thread_video(void *ignored_argument) { inputfloat.CopyTo(&inputfloatfilter); inputfloatfilter.CopyTo(¤timagefloat); UnLock(); - if (framespersecond == -1) framespersecond = 1.0/(timedeiff_ms(&tv1)/1000.0); - else framespersecond = (framespersecond * 59.0 + 1.0/(timedeiff_ms(&tv1)/1000.0)) / 60.0; + if (framespersecond == -1) framespersecond = 1.0/(timedeiff_ms(&tv_fps)/1000.0); + else framespersecond = (framespersecond * 59.0 + 1.0/(timedeiff_ms(&tv_fps)/1000.0)) / 60.0; } thread_video_exit: @@ -159,6 +162,9 @@ int main(int argc, char **argv) { usleep (1000); } + pthread_join(thr_webserver, NULL); + pthread_join(thr_video, NULL); + return 0; }; diff --git a/videodevice_v4l2.cc b/videodevice_v4l2.cc index 166d85a..67bacf4 100644 --- a/videodevice_v4l2.cc +++ b/videodevice_v4l2.cc @@ -435,9 +435,7 @@ int VideoDevice_V4L2::GetFrame(VideoFrame *destframe, VideoFrameFloat *destfloat buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; - Lock(); ret = xioctl(fd, VIDIOC_DQBUF, &buf); - UnLock(); if (ret == -1) { switch (errno) { case EAGAIN: @@ -457,9 +455,7 @@ int VideoDevice_V4L2::GetFrame(VideoFrame *destframe, VideoFrameFloat *destfloat Convert(&cdata, destframe, destfloat, inbuffer[buf.index].data, buf.bytesused, fmt.fmt.pix.pixelformat, fmt.fmt.pix.width, fmt.fmt.pix.height); } - Lock(); ret = xioctl(fd, VIDIOC_QBUF, &buf); - UnLock(); if (ret == -1) { debug ("error on VIDIOC_QBUF %s", strerror(errno)); @@ -542,6 +538,26 @@ int VideoDevice_V4L2::GetDevCtrl(unsigned int id, int *value) { }; +void VideoDevice_V4L2::RefreshCtrls() { + std::list::iterator i; + struct v4l2_queryctrl queryctrl; + int ret; + + for (i = vidctrls.begin(); i != vidctrls.end(); i++) { + CLEAR(queryctrl); + queryctrl.id = i->id; + Lock(); + ret = xioctl(cfd != -1 ? cfd : fd, VIDIOC_QUERYCTRL, &queryctrl); + UnLock(); + if (ret == 0) { + i->min = queryctrl.minimum; + i->max = queryctrl.maximum; + } + GetDevCtrl(i->id, &i->value); + } +}; + + void VideoDevice_V4L2::PrintCaps(uint32_t caps) { printf ("%s:%d %s Caps: %x\n", __FILE__, __LINE__, __FUNCTION__, caps); @@ -572,4 +588,3 @@ void VideoDevice_V4L2::PrintFmt(struct v4l2_format *f) { printf (" fmt.pix.bytesperline : %d\n", f->fmt.pix.bytesperline); printf (" fmt.pix.sizeimage : %d\n", f->fmt.pix.sizeimage); }; - diff --git a/videodevice_v4l2.h b/videodevice_v4l2.h index 750b647..11bd794 100644 --- a/videodevice_v4l2.h +++ b/videodevice_v4l2.h @@ -33,6 +33,7 @@ class VideoDevice_V4L2 : public VideoDevice { int GetFrame (VideoFrame *destframe, VideoFrameFloat *destfloat); int SetDevCtrl(unsigned int id, int value); int GetDevCtrl(unsigned int id, int *value); + void RefreshCtrls(); void PrintCaps(uint32_t caps); void PrintFmt(struct v4l2_format *f); diff --git a/videoframe.cc b/videoframe.cc index 5e78be4..2e36bc3 100644 --- a/videoframe.cc +++ b/videoframe.cc @@ -33,7 +33,7 @@ void VideoFrame::FreeFrame() { void VideoFrame::AllocateFrame() { int memnewsize = width * height * 3; - if (memnewsize < mem_allocated) return; + if (memnewsize <= mem_allocated) return; else if (memnewsize == 0) FreeFrame(); mem = (unsigned char *) realloc (mem, memnewsize); @@ -48,6 +48,7 @@ void VideoFrame::AllocateFrame() { int VideoFrame::SetSize(int w, int h) { if (w < 0 && h < 0) return 0; + if (w == width && h == height) return 1; width = w; height = h; @@ -188,7 +189,7 @@ void VideoFrameFloat::FreeFrame() { void VideoFrameFloat::AllocateFrame() { int memnewsize = width * height * 3 * sizeof(float); - if (memnewsize < memf_allocated) return; + if (memnewsize <= memf_allocated) return; else if (memnewsize == 0) { FreeFrame(); return; @@ -231,6 +232,7 @@ int VideoFrameFloat::TestScreen(int w, int h) { int VideoFrameFloat::SetSize(int w, int h) { if (w < 0 || h < 0) return 0; + if (width == w && height == h) return 1; width = w; height = h; diff --git a/www/default.css b/www/default.css index 822a93e..8bfe8fb 100644 --- a/www/default.css +++ b/www/default.css @@ -1,20 +1,632 @@ +:root { + color-scheme: dark; + --page: #101820; + --surface: #17232d; + --surface-raised: #1d2b37; + --border: #2a3a47; + --text: #edf4f7; + --muted: #91a2ae; + --accent: #55d6be; + --accent-dark: #143b39; + --danger: #ff817c; + font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; +} + +* { + box-sizing: border-box; +} + body { - background-color: #444; - color: #BBB; + min-width: 320px; + min-height: 100vh; + margin: 0; + background: + radial-gradient(ellipse at 50% -20%, rgba(47, 105, 114, 0.2), transparent 55%), + var(--page); + color: var(--text); +} + +button, +input { + font: inherit; +} + +.app-shell { + width: min(1440px, 100%); + margin: 0 auto; + padding: 0 36px; +} + +.topbar { + min-height: 78px; + display: flex; + align-items: center; + justify-content: space-between; + border-bottom: 1px solid rgba(145, 162, 174, 0.15); +} + +.brand { + display: inline-flex; + align-items: center; + gap: 12px; + color: var(--text); + text-decoration: none; +} + +.brand-mark { + width: 40px; + height: 40px; + display: grid; + place-items: center; + border: 1px solid rgba(85, 214, 190, 0.32); + border-radius: 12px; + background: var(--accent-dark); + color: var(--accent); +} + +.brand-mark svg { + width: 23px; + fill: none; + stroke: currentColor; + stroke-linecap: round; + stroke-linejoin: round; + stroke-width: 1.7; +} + +.brand strong, +.brand small { + display: block; +} + +.brand strong { + font-size: 15px; + letter-spacing: 0.01em; +} + +.brand small { + margin-top: 3px; + color: var(--muted); + font-size: 11px; +} + +.connection-status, +.section-title { + display: inline-flex; + align-items: center; + gap: 9px; +} + +.connection-status { + color: #b6c5cc; + font-size: 12px; +} + +.status-dot, +.live-indicator { + width: 8px; + height: 8px; + flex: 0 0 auto; + border-radius: 50%; + background: var(--accent); + box-shadow: 0 0 12px rgba(85, 214, 190, 0.55); +} + +.connection-status.offline .status-dot { + background: var(--danger); + box-shadow: 0 0 12px rgba(255, 129, 124, 0.4); +} + +main { + padding-top: 42px; +} + +.page-heading { + display: flex; + align-items: flex-end; + justify-content: space-between; + gap: 24px; + margin-bottom: 26px; +} + +.eyebrow { + margin: 0 0 8px; + color: var(--accent); + font-size: 10px; + font-weight: 750; + letter-spacing: 0.16em; +} + +h1, +h2, +h3, +p { + margin-top: 0; +} + +h1 { + margin-bottom: 8px; + font-size: clamp(26px, 3vw, 36px); + font-weight: 650; + letter-spacing: -0.035em; +} + +.subtitle { + margin-bottom: 0; + color: var(--muted); + font-size: 14px; +} + +.toggle-card { + position: relative; + display: flex; + align-items: center; + gap: 18px; + min-width: 238px; + padding: 13px 15px; + border: 1px solid var(--border); + border-radius: 12px; + background: rgba(23, 35, 45, 0.8); + cursor: pointer; +} + +.toggle-copy { + flex: 1; +} + +.toggle-copy strong, +.toggle-copy small { + display: block; +} + +.toggle-copy strong { + font-size: 12px; + font-weight: 650; +} + +.toggle-copy small { + margin-top: 4px; + color: var(--muted); + font-size: 10px; +} + +.toggle-card input { + position: absolute; + width: 1px; + height: 1px; + opacity: 0; +} + +.toggle-track { + position: relative; + width: 36px; + height: 21px; + flex: 0 0 auto; + border-radius: 20px; + background: #384852; + transition: background 160ms ease; +} + +.toggle-track::after { + position: absolute; + top: 3px; + left: 3px; + width: 15px; + height: 15px; + border-radius: 50%; + background: white; + content: ""; + transition: transform 160ms ease; +} + +.toggle-card input:checked + .toggle-track { + background: #258f7c; +} + +.toggle-card input:checked + .toggle-track::after { + transform: translateX(15px); +} + +.toggle-card input:focus-visible + .toggle-track { + outline: 2px solid var(--accent); + outline-offset: 3px; +} + +.preview-card, +.panel { + overflow: hidden; + border: 1px solid var(--border); + border-radius: 15px; + background: rgba(23, 35, 45, 0.92); + box-shadow: 0 18px 50px rgba(0, 0, 0, 0.14); +} + +.section-bar, +.preview-footer { + display: flex; + align-items: center; + justify-content: space-between; +} + +.section-bar { + min-height: 54px; + padding: 0 18px; +} + +.section-title { + gap: 10px; +} + +.section-title h2, +.panel-heading h2 { + margin: 0; + font-size: 13px; + font-weight: 650; +} + +.preview-label { + padding: 5px 9px; + border: 1px solid var(--border); + border-radius: 20px; + color: #b6c5cc; + font-size: 10px; +} + +.preview-stage { + position: relative; + display: grid; + min-height: 240px; + aspect-ratio: 16 / 8.5; + max-height: 68vh; + place-items: center; + overflow: hidden; + background: + linear-gradient(135deg, rgba(42, 58, 71, 0.35), transparent 50%), + #0a1117; +} + +.preview-stage img { + display: block; + width: 100%; + height: 100%; + object-fit: contain; +} + +.preview-error { + position: absolute; + padding: 10px 14px; + border: 1px solid var(--border); + border-radius: 8px; + background: rgba(16, 24, 32, 0.88); + color: var(--muted); + font-size: 12px; } -.noborder { - border: none; +.preview-footer { + min-height: 42px; + padding: 0 18px; + border-top: 1px solid rgba(145, 162, 174, 0.12); + color: var(--muted); + font-size: 10px; } -.withborder { - border: thin solid; - border-collapse: collapse; +.content-grid { + display: grid; + grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.85fr); + align-items: start; + gap: 18px; + margin-top: 20px; } -.float { - float: left; - padding: 10px; - border: thin solid; +.panel { + padding: 20px; } +.panel-heading { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + margin-bottom: 17px; +} + +.panel-heading .eyebrow { + margin-bottom: 6px; +} + +.panel-heading h2 { + font-size: 17px; + letter-spacing: -0.02em; +} + +.count-badge { + padding: 5px 9px; + border: 1px solid var(--border); + border-radius: 20px; + color: var(--muted); + font-size: 10px; + white-space: nowrap; +} + +.search-box { + display: flex; + align-items: center; + gap: 9px; + height: 38px; + margin-bottom: 14px; + padding: 0 11px; + border: 1px solid var(--border); + border-radius: 8px; + background: #121d26; + color: var(--muted); +} + +.search-box:focus-within { + border-color: rgba(85, 214, 190, 0.65); +} + +.search-box svg { + width: 16px; + fill: none; + stroke: currentColor; + stroke-linecap: round; + stroke-width: 1.8; +} + +.search-box input { + width: 100%; + border: 0; + outline: 0; + background: transparent; + color: var(--text); + font-size: 12px; +} + +.search-box input::placeholder { + color: #748591; +} + +.control-list, +.settings-list { + display: grid; + gap: 9px; +} + +.control-card, +.setting-row { + min-width: 0; + padding: 13px; + border: 1px solid rgba(145, 162, 174, 0.14); + border-radius: 10px; + background: rgba(29, 43, 55, 0.58); +} + +.control-card { + display: grid; + grid-template-columns: minmax(100px, 1fr) minmax(80px, 1.5fr) 78px auto; + align-items: center; + gap: 12px; +} + +.control-header { + display: flex; + flex-wrap: wrap; + align-items: baseline; + gap: 4px 8px; + min-width: 0; +} + +.control-header h3, +.setting-details h3 { + overflow-wrap: anywhere; + margin: 0; + font-size: 12px; + font-weight: 600; + text-transform: capitalize; +} + +.range-label { + color: var(--muted); + font-size: 10px; + white-space: nowrap; +} + +.control-input-row { + display: grid; + grid-column: 2 / -1; + grid-template-columns: minmax(0, 1fr) 78px auto; + align-items: center; + gap: 8px; +} + +.control-slider { + width: 100%; + height: 4px; + accent-color: var(--accent); + cursor: pointer; +} + +.control-slider:disabled { + cursor: not-allowed; + opacity: 0.4; +} + +.control-value, +.variable-value { + width: 100%; + min-width: 0; + height: 32px; + padding: 0 8px; + border: 1px solid var(--border); + border-radius: 6px; + outline: 0; + background: #111b23; + color: var(--text); + font-size: 12px; +} + +.control-value:focus, +.variable-value:focus { + border-color: var(--accent); +} + +.button { + border: 1px solid rgba(85, 214, 190, 0.32); + border-radius: 6px; + background: var(--accent-dark); + color: #90f0dc; + cursor: pointer; + font-weight: 650; + transition: background 140ms ease, border-color 140ms ease; +} + +.button:hover { + border-color: var(--accent); + background: #1b514b; +} + +.button:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; +} + +.button-small { + min-height: 32px; + padding: 0 10px; + font-size: 10px; +} + +.setting-row { + display: grid; + gap: 12px; +} + +.setting-details p { + margin: 5px 0 0; + color: var(--muted); + font-size: 10px; + line-height: 1.5; +} + +.setting-editor { + display: grid; + grid-template-columns: minmax(0, 1fr) auto; + gap: 8px; +} + +.panel-hint { + margin: 13px 1px 0; + color: var(--muted); + font-size: 10px; + line-height: 1.55; +} + +.empty-state { + padding: 18px 12px; + border: 1px dashed rgba(145, 162, 174, 0.25); + border-radius: 9px; + color: var(--muted); + font-size: 11px; + text-align: center; +} + +.notice { + margin-top: 18px; + padding: 12px 14px; + border: 1px solid rgba(255, 129, 124, 0.35); + border-radius: 9px; + background: rgba(83, 37, 39, 0.28); + color: #ffaaa5; + font-size: 12px; +} + +.footer { + display: flex; + justify-content: space-between; + padding: 24px 2px 28px; + color: #748591; + font-size: 10px; +} + +[hidden] { + display: none !important; +} + +@media (max-width: 850px) { + .app-shell { + padding: 0 22px; + } + + .content-grid { + grid-template-columns: minmax(0, 1fr); + } + + .preview-stage { + aspect-ratio: 16 / 10; + } +} + +@media (max-width: 560px) { + .app-shell { + padding: 0 14px; + } + + .topbar { + min-height: 68px; + } + + main { + padding-top: 28px; + } + + .page-heading { + align-items: stretch; + flex-direction: column; + gap: 17px; + } + + .toggle-card { + min-width: 0; + width: 100%; + } + + .preview-stage { + min-height: 190px; + aspect-ratio: 4 / 3; + } + + .section-bar, + .preview-footer { + padding-right: 12px; + padding-left: 12px; + } + + .panel { + padding: 15px; + } + + .control-card { + grid-template-columns: minmax(0, 0.9fr) minmax(35px, 1fr) 62px auto; + gap: 6px; + padding: 9px; + } + + .control-input-row { + display: contents; + } + + .control-slider { + grid-column: 2; + } + + .control-value { + grid-column: 3; + } + + .control-card .button { + grid-column: 4; + } + + .footer { + padding-bottom: 20px; + } +} diff --git a/www/index.html b/www/index.html index c136443..06a72e1 100644 --- a/www/index.html +++ b/www/index.html @@ -1,192 +1,397 @@ - + + - MiniWebCam - + + + + MiniWebCam - - - -
- - - -
-
- -
- -
- -
- -
-

Controls


-
-
-
-

Infos


-
-
- -
- -
-
- - +
+
+ + + + MiniWebCam + Camera dashboard + + +
+ + Connecting… +
+
+ +
+
+
+

LIVE MONITOR

+

Camera overview

+

Live video and device controls in one place.

+
+ +
+ +
+
+
+ +

Live preview

+
+ Standard image +
+
+ Live webcam preview + +
+ +
- - - \ No newline at end of file + window.setInterval(refresh, 500); + + +