mirror of
https://github.com/easytarget/esp32-cam-webserver.git
synced 2024-02-16 18:18:24 +08:00
Streamviewer (#39)
* dedicated stream viewer * minimal functionality, but does rotate correctly * stream autostarts and scales to window size preserving aspect ratio
This commit is contained in:
@ -19,7 +19,7 @@
|
||||
|
||||
#include "index_ov2640.h"
|
||||
#include "index_ov3660.h"
|
||||
#include "miniviewer.h"
|
||||
#include "viewers.h"
|
||||
#include "css.h"
|
||||
#include "favicon/favicons.h"
|
||||
|
||||
@ -592,7 +592,6 @@ static esp_err_t cmd_handler(httpd_req_t *req){
|
||||
|
||||
static esp_err_t status_handler(httpd_req_t *req){
|
||||
|
||||
|
||||
static char json_response[1024];
|
||||
sensor_t * s = esp_camera_sensor_get();
|
||||
char * p = json_response;
|
||||
@ -629,8 +628,22 @@ static esp_err_t status_handler(httpd_req_t *req){
|
||||
p+=sprintf(p, "\"cam_name\":\"%s\",", myName);
|
||||
p+=sprintf(p, "\"code_ver\":\"%s\",", myVer);
|
||||
p+=sprintf(p, "\"rotate\":\"%s\",", myRotation);
|
||||
p+=sprintf(p, "\"stream_url\":\"%s\",", streamURL);
|
||||
p+=sprintf(p, "\"http\":%i", 80);
|
||||
p+=sprintf(p, "\"stream_url\":\"%s\"", streamURL);
|
||||
*p++ = '}';
|
||||
*p++ = 0;
|
||||
httpd_resp_set_type(req, "application/json");
|
||||
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
|
||||
return httpd_resp_send(req, json_response, strlen(json_response));
|
||||
}
|
||||
|
||||
static esp_err_t info_handler(httpd_req_t *req){
|
||||
static char json_response[256];
|
||||
char * p = json_response;
|
||||
*p++ = '{';
|
||||
p+=sprintf(p, "\"cam_name\":\"%s\",", myName);
|
||||
p+=sprintf(p, "\"code_ver\":\"%s\",", myVer);
|
||||
p+=sprintf(p, "\"rotate\":\"%s\",", myRotation);
|
||||
p+=sprintf(p, "\"stream_url\":\"%s\"", streamURL);
|
||||
*p++ = '}';
|
||||
*p++ = 0;
|
||||
httpd_resp_set_type(req, "application/json");
|
||||
@ -683,6 +696,15 @@ static esp_err_t miniviewer_handler(httpd_req_t *req){
|
||||
return httpd_resp_send(req, (const char *)miniviewer_html, miniviewer_html_len);
|
||||
}
|
||||
|
||||
static esp_err_t streamviewer_handler(httpd_req_t *req){
|
||||
flashLED(75); // a little feedback to user
|
||||
delay(75);
|
||||
flashLED(75);
|
||||
httpd_resp_set_type(req, "text/html");
|
||||
httpd_resp_set_hdr(req, "Content-Encoding", "identity");
|
||||
return httpd_resp_send(req, (const char *)streamviewer_html, streamviewer_html_len);
|
||||
}
|
||||
|
||||
static esp_err_t index_handler(httpd_req_t *req){
|
||||
flashLED(75); // a little feedback to user
|
||||
delay(75);
|
||||
@ -769,6 +791,19 @@ void startCameraServer(int hPort, int sPort){
|
||||
.user_ctx = NULL
|
||||
};
|
||||
|
||||
httpd_uri_t streamviewer_uri = {
|
||||
.uri = "/view",
|
||||
.method = HTTP_GET,
|
||||
.handler = streamviewer_handler,
|
||||
.user_ctx = NULL
|
||||
};
|
||||
|
||||
httpd_uri_t info_uri = {
|
||||
.uri = "/info",
|
||||
.method = HTTP_GET,
|
||||
.handler = info_handler,
|
||||
.user_ctx = NULL
|
||||
};
|
||||
|
||||
ra_filter_init(&ra_filter, 20);
|
||||
|
||||
@ -809,6 +844,8 @@ void startCameraServer(int hPort, int sPort){
|
||||
Serial.printf("Starting stream server on port: '%d'\n", config.server_port);
|
||||
if (httpd_start(&stream_httpd, &config) == ESP_OK) {
|
||||
httpd_register_uri_handler(stream_httpd, &stream_uri);
|
||||
httpd_register_uri_handler(stream_httpd, &info_uri);
|
||||
httpd_register_uri_handler(stream_httpd, &streamviewer_uri);
|
||||
httpd_register_uri_handler(stream_httpd, &favicon_16x16_uri);
|
||||
httpd_register_uri_handler(stream_httpd, &favicon_32x32_uri);
|
||||
httpd_register_uri_handler(stream_httpd, &favicon_ico_uri);
|
||||
|
6
css.h
6
css.h
@ -34,7 +34,7 @@ section.main {
|
||||
#menu {
|
||||
display: none;
|
||||
flex-wrap: nowrap;
|
||||
width: 340px;
|
||||
width: 380px;
|
||||
background: #363636;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
@ -63,10 +63,6 @@ figure {
|
||||
|
||||
figure img {
|
||||
display: block;
|
||||
/*
|
||||
no max-width:
|
||||
width: 100%;
|
||||
*/
|
||||
max-width: 100%;
|
||||
width: auto;
|
||||
height: auto;
|
||||
|
@ -8,7 +8,7 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>ESP32 OV3660</title>
|
||||
<title>ESP32 OV2640</title>
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
@ -19,15 +19,14 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
flex-wrap: nowrap;
|
||||
align-items: stretch
|
||||
}
|
||||
|
||||
|
||||
|
||||
figure img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
width: auto;
|
||||
height: auto
|
||||
}
|
||||
|
||||
|
||||
figure {
|
||||
padding: 0 0 0 0px;
|
||||
margin: 0;
|
||||
@ -270,11 +269,11 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
<div class="input-group" id="code_ver-group">
|
||||
<label for="code_ver">
|
||||
<a href="https://github.com/easytarget/esp32-cam-webserver"
|
||||
title="ESP32 Cam Webserver on GitHub" target="_blank">Firmware</a>:</label>
|
||||
title="ESP32 Cam Webserver on GitHub" target="_blank">Firmware</a></label>
|
||||
<div id="code_ver" class="default-action"></div>
|
||||
</div>
|
||||
<div class="input-group hidden" id="stream-group">
|
||||
<label for="stream_url">Stream URL:</label>
|
||||
<label for="stream_url" id="stream_link">Stream URL</label>
|
||||
<div id="stream_url" class="default-action">Unknown</div>
|
||||
</div>
|
||||
</nav>
|
||||
@ -307,7 +306,7 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
const streamButton = document.getElementById('toggle-stream')
|
||||
const enrollButton = document.getElementById('face_enroll')
|
||||
const closeButton = document.getElementById('close-stream')
|
||||
const streamLink = document.getElementById('stream_url')
|
||||
const streamLink = document.getElementById('stream_link')
|
||||
const detect = document.getElementById('face_detect')
|
||||
const recognize = document.getElementById('face_recognize')
|
||||
const framesize = document.getElementById('framesize')
|
||||
@ -341,7 +340,7 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
initialValue = el.value
|
||||
el.value = value
|
||||
}
|
||||
|
||||
|
||||
if (updateRemote && initialValue !== value) {
|
||||
updateConfig(el);
|
||||
} else if(!updateRemote){
|
||||
@ -377,9 +376,9 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
applyRotation();
|
||||
} else if(el.id === "stream_url"){
|
||||
stream_url.innerHTML = value;
|
||||
stream_url.setAttribute("title", "Open raw stream URL in new window");
|
||||
stream_url.style.textDecoration = "underline";
|
||||
stream_url.style.cursor = "pointer";
|
||||
stream_link.setAttribute("title", "Open stream viewer ( " + value + "view )");
|
||||
stream_link.style.textDecoration = "underline";
|
||||
stream_link.style.cursor = "pointer";
|
||||
streamURL = value;
|
||||
streamButton.setAttribute("title", `You can also browse to '${streamURL}' for a raw stream`);
|
||||
show(streamGroup)
|
||||
@ -479,7 +478,7 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
// Attach actions to controls
|
||||
|
||||
streamLink.onclick = () => {
|
||||
window.open(streamURL, "_blank");
|
||||
window.open(streamURL + "view", "_blank");
|
||||
}
|
||||
|
||||
stillButton.onclick = () => {
|
||||
@ -529,7 +528,7 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
show(agcGain)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Exposure
|
||||
const aec = document.getElementById('aec')
|
||||
const exposure = document.getElementById('aec_value-group')
|
||||
@ -537,7 +536,7 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
updateConfig(aec)
|
||||
aec.checked ? hide(exposure) : show(exposure)
|
||||
}
|
||||
|
||||
|
||||
// AWB
|
||||
const awb = document.getElementById('awb_gain')
|
||||
const wb = document.getElementById('wb_mode-group')
|
||||
@ -545,7 +544,7 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
updateConfig(awb)
|
||||
awb.checked ? show(wb) : hide(wb)
|
||||
}
|
||||
|
||||
|
||||
// Detection and framesize
|
||||
rotate.onchange = () => {
|
||||
applyRotation();
|
||||
@ -559,7 +558,7 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
updateValue(recognize, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
detect.onchange = () => {
|
||||
if (framesize.value > 5) {
|
||||
alert("Please select CIF or lower resolution before enabling this feature!");
|
||||
@ -572,7 +571,7 @@ const uint8_t index_ov2640_html[] = R"=====(
|
||||
updateValue(recognize, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
recognize.onchange = () => {
|
||||
if (framesize.value > 5) {
|
||||
alert("Please select CIF or lower resolution before enabling this feature!");
|
||||
|
@ -19,15 +19,14 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
flex-wrap: nowrap;
|
||||
align-items: stretch
|
||||
}
|
||||
|
||||
|
||||
|
||||
figure img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
width: auto;
|
||||
height: auto
|
||||
}
|
||||
|
||||
|
||||
figure {
|
||||
padding: 0 0 0 0px;
|
||||
margin: 0;
|
||||
@ -283,11 +282,11 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
<div class="input-group" id="code_ver-group">
|
||||
<label for="code_ver">
|
||||
<a href="https://github.com/easytarget/esp32-cam-webserver"
|
||||
title="ESP32 Cam Webserver on GitHub" target="_blank">Firmware</a>:</label>
|
||||
title="ESP32 Cam Webserver on GitHub" target="_blank">Firmware</a></label>
|
||||
<div id="code_ver" class="default-action"></div>
|
||||
</div>
|
||||
<div class="input-group hidden" id="stream-group">
|
||||
<label for="stream_url">Stream URL:</label>
|
||||
<label for="stream_url" id="stream_link">Stream URL</label>
|
||||
<div id="stream_url" class="default-action">Unknown</div>
|
||||
</div>
|
||||
</nav>
|
||||
@ -320,7 +319,7 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
const streamButton = document.getElementById('toggle-stream')
|
||||
const enrollButton = document.getElementById('face_enroll')
|
||||
const closeButton = document.getElementById('close-stream')
|
||||
const streamLink = document.getElementById('stream_url')
|
||||
const streamLink = document.getElementById('stream_link')
|
||||
const detect = document.getElementById('face_detect')
|
||||
const recognize = document.getElementById('face_recognize')
|
||||
const framesize = document.getElementById('framesize')
|
||||
@ -354,7 +353,7 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
initialValue = el.value
|
||||
el.value = value
|
||||
}
|
||||
|
||||
|
||||
if (updateRemote && initialValue !== value) {
|
||||
updateConfig(el);
|
||||
} else if(!updateRemote){
|
||||
@ -388,9 +387,9 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
applyRotation();
|
||||
} else if(el.id === "stream_url"){
|
||||
stream_url.innerHTML = value;
|
||||
stream_url.setAttribute("title", "Open raw stream URL in new window");
|
||||
stream_url.style.textDecoration = "underline";
|
||||
stream_url.style.cursor = "pointer";
|
||||
stream_link.setAttribute("title", "Open stream viewer ( " + value + "view )");
|
||||
stream_link.style.textDecoration = "underline";
|
||||
stream_link.style.cursor = "pointer";
|
||||
streamURL = value;
|
||||
streamButton.setAttribute("title", `You can also browse to '${streamURL}' for a raw stream`);
|
||||
show(streamGroup)
|
||||
@ -490,7 +489,7 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
// Attach actions to controls
|
||||
|
||||
streamLink.onclick = () => {
|
||||
window.open(streamURL, "_blank");
|
||||
window.open(streamURL + "view", "_blank");
|
||||
}
|
||||
|
||||
stillButton.onclick = () => {
|
||||
@ -537,7 +536,7 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
show(agcGain)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Exposure
|
||||
const aec = document.getElementById('aec')
|
||||
const exposure = document.getElementById('aec_value-group')
|
||||
@ -545,7 +544,7 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
updateConfig(aec)
|
||||
aec.checked ? hide(exposure) : show(exposure)
|
||||
}
|
||||
|
||||
|
||||
// AWB
|
||||
const awb = document.getElementById('awb_gain')
|
||||
const wb = document.getElementById('wb_mode-group')
|
||||
@ -553,7 +552,7 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
updateConfig(awb)
|
||||
awb.checked ? show(wb) : hide(wb)
|
||||
}
|
||||
|
||||
|
||||
// Detection and framesize
|
||||
rotate.onchange = () => {
|
||||
applyRotation();
|
||||
@ -567,7 +566,7 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
updateValue(recognize, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
detect.onchange = () => {
|
||||
if (framesize.value > 5) {
|
||||
alert("Please select CIF or lower resolution before enabling this feature!");
|
||||
@ -580,7 +579,7 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
updateValue(recognize, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
recognize.onchange = () => {
|
||||
if (framesize.value > 5) {
|
||||
alert("Please select CIF or lower resolution before enabling this feature!");
|
||||
@ -597,7 +596,7 @@ const uint8_t index_ov3660_html[] = R"=====(
|
||||
}
|
||||
|
||||
swapButton.onclick = () => {
|
||||
window.open('/','_self');
|
||||
window.open('/view','_self');
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -1,5 +1,8 @@
|
||||
//File: index_ov2640.html
|
||||
const uint8_t miniviewer_html[] = R"=====(
|
||||
/*
|
||||
* Miniviewer and streamviewer
|
||||
*/
|
||||
|
||||
const uint8_t miniviewer_html[] = R"=====(
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
@ -110,7 +113,7 @@ const uint8_t miniviewer_html[] = R"=====(
|
||||
initialValue = el.value
|
||||
el.value = value
|
||||
}
|
||||
|
||||
|
||||
if (updateRemote && initialValue !== value) {
|
||||
updateConfig(el);
|
||||
} else if(!updateRemote){
|
||||
@ -279,3 +282,185 @@ const uint8_t miniviewer_html[] = R"=====(
|
||||
)=====";
|
||||
|
||||
size_t miniviewer_html_len = sizeof(miniviewer_html);
|
||||
|
||||
/* Stream Viewer */
|
||||
|
||||
const uint8_t streamviewer_html[] = R"=====(
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title id="title">ESP32-CAM StreamViewer</title>
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<style>
|
||||
/* No stylesheet, define all style elements here */
|
||||
body {
|
||||
font-family: Arial,Helvetica,sans-serif;
|
||||
background: #181818;
|
||||
color: #EFEFEF;
|
||||
font-size: 16px;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
figure {
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
-webkit-margin-before: 0;
|
||||
margin-block-start: 0;
|
||||
-webkit-margin-after: 0;
|
||||
margin-block-end: 0;
|
||||
-webkit-margin-start: 0;
|
||||
margin-inline-start: 0;
|
||||
-webkit-margin-end: 0;
|
||||
margin-inline-end: 0
|
||||
}
|
||||
|
||||
figure img {
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.image-container {
|
||||
position: relative;
|
||||
transform-origin: top left
|
||||
}
|
||||
|
||||
.loader {
|
||||
border: 0.5em solid #f3f3f3;
|
||||
border-top: 0.5em solid #000000;
|
||||
border-radius: 50%;
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
-webkit-animation: spin 2s linear infinite; /* Safari */
|
||||
animation: spin 2s linear infinite;
|
||||
}
|
||||
|
||||
@-webkit-keyframes spin { /* Safari */
|
||||
0% { -webkit-transform: rotate(0deg); }
|
||||
100% { -webkit-transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<section class="main">
|
||||
<div id="logo">
|
||||
<div id="wait-settings" style="float:left;" class="loader" title="Waiting for stream settings to load"></div>
|
||||
</div>
|
||||
<div>
|
||||
<div style="display: none;">
|
||||
<!-- Hide the next entries, they are present in the body so that we
|
||||
can pass settings to/from them for use in the scripting -->
|
||||
<div id="rotate" class="action-setting hidden"></div>
|
||||
<div id="cam_name" class="action-setting hidden"></div>
|
||||
<div id="code_ver" class="action-setting hidden"></div>
|
||||
<div id="stream_url" class="action-setting hidden"></div>
|
||||
</div>
|
||||
<figure>
|
||||
<div id="stream-container" class="image-container" style="display: none;">
|
||||
<img id="stream" src="">
|
||||
</div>
|
||||
</figure>
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function (event) {
|
||||
var baseHost = document.location.origin;
|
||||
|
||||
const rotate = document.getElementById('rotate')
|
||||
const view = document.getElementById('stream')
|
||||
const viewContainer = document.getElementById('stream-container')
|
||||
const spinner = document.getElementById('wait-settings')
|
||||
|
||||
const updateValue = (el, value, updateRemote) => {
|
||||
updateRemote = updateRemote == null ? true : updateRemote
|
||||
let initialValue
|
||||
if (el.type === 'checkbox') {
|
||||
initialValue = el.checked
|
||||
value = !!value
|
||||
el.checked = value
|
||||
} else {
|
||||
initialValue = el.value
|
||||
el.value = value
|
||||
}
|
||||
|
||||
if (updateRemote && initialValue !== value) {
|
||||
updateConfig(el);
|
||||
} else if(!updateRemote){
|
||||
if(el.id === "cam_name"){
|
||||
window.document.title = value;
|
||||
viewContainer.setAttribute("title", value + "\n(doubleclick for fullscreen)");
|
||||
console.log('Name set to: ' + value);
|
||||
} else if(el.id === "code_ver"){
|
||||
console.log('Firmware Build: ' + value);
|
||||
} else if(el.id === "rotate"){
|
||||
rotate.value = value;
|
||||
applyRotation();
|
||||
} else if(el.id === "stream_url"){
|
||||
streamURL = value;
|
||||
console.log('Stream URL set to:' + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// read initial values
|
||||
fetch(`${baseHost}/info`)
|
||||
.then(function (response) {
|
||||
return response.json()
|
||||
})
|
||||
.then(function (state) {
|
||||
document
|
||||
.querySelectorAll('.action-setting')
|
||||
.forEach(el => {
|
||||
updateValue(el, state[el.id], false)
|
||||
})
|
||||
spinner.style.display = `none`;
|
||||
startStream();
|
||||
})
|
||||
|
||||
const startStream = () => {
|
||||
view.src = streamURL;
|
||||
view.scrollIntoView(false);
|
||||
viewContainer.style.display = `block`;
|
||||
}
|
||||
|
||||
const applyRotation = () => {
|
||||
rot = rotate.value;
|
||||
if (rot == -90) {
|
||||
viewContainer.style.transform = `rotate(-90deg) translate(-100%)`;
|
||||
} else if (rot == 90) {
|
||||
viewContainer.style.transform = `rotate(90deg) translate(0, -100%)`;
|
||||
} else {
|
||||
viewContainer.style.transform = `rotate(0deg)`;
|
||||
}
|
||||
console.log('Rotation ' + rot + ' applied');
|
||||
|
||||
view.ondblclick = () => {
|
||||
if (view.requestFullscreen) {
|
||||
view.requestFullscreen();
|
||||
} else if (view.mozRequestFullScreen) { /* Firefox */
|
||||
view.mozRequestFullScreen();
|
||||
} else if (view.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
|
||||
view.webkitRequestFullscreen();
|
||||
} else if (view.msRequestFullscreen) { /* IE/Edge */
|
||||
view.msRequestFullscreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
)=====";
|
||||
|
||||
size_t streamviewer_html_len = sizeof(streamviewer_html);
|
Reference in New Issue
Block a user