You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.3 KiB
115 lines
3.3 KiB
|
|
#include <unistd.h>
|
|
|
|
#include "miniwebcam.h"
|
|
#include "UDPTCPNetwork.h"
|
|
#include "inmemorytar.h"
|
|
|
|
extern VideoDevice *vdev;
|
|
|
|
std::string API_Get_Ctrls();
|
|
std::string API_Set_Ctrl(std::string request);
|
|
|
|
// InMemoryFile GenerateJpgFile(VideoFrame *vf);
|
|
InMemoryTar assets;
|
|
|
|
int WebCamServer::HandleRequest (WebRequestBuffer *requestbuffer, WebServerClient *webclient) {
|
|
if (requestbuffer == NULL || webclient == NULL) return 0;
|
|
|
|
std::string request = requestbuffer->GetRequest();
|
|
|
|
if (request.compare ("/") == 0) request = "/index.html";
|
|
|
|
InMemoryFile *imf_do_not_free = NULL;
|
|
if (request.find("/snapshot.jpg") != std::string::npos) {
|
|
InMemoryFile jpgfile;
|
|
Lock();
|
|
currentimage.ConvertToJpeg(&jpgfile, 99);
|
|
UnLock();
|
|
if (webclient->SendResponseFileFromMemory(requestbuffer, request, "",
|
|
(void*) jpgfile.mem,
|
|
jpgfile.memsize) != 1) return 0;
|
|
}
|
|
else if (request.find("/snapshot-float.jpg") != std::string::npos) {
|
|
InMemoryFile jpgfile;
|
|
Lock();
|
|
currentimagefloat.ConvertToJpeg(&jpgfile, 99);
|
|
UnLock();
|
|
if (webclient->SendResponseFileFromMemory(requestbuffer, request, "",
|
|
(void*) jpgfile.mem,
|
|
jpgfile.memsize) != 1) return 0;
|
|
}
|
|
else if (request.compare("/get/ctrls") == 0) {
|
|
debug ("get controls");
|
|
if (webclient->SendResponseData(requestbuffer, API_Get_Ctrls(), "") != 1) return 0;
|
|
}
|
|
else if (request.find("/set/ctrl") != std::string::npos) {
|
|
debug ("set controls");
|
|
if (webclient->SendResponseData(requestbuffer, API_Set_Ctrl(request), "") != 1) return 0;
|
|
}
|
|
else if (isfile("www"+request)) {
|
|
if (webclient->SendResponseFile(requestbuffer, request, "") != 1) return 0;
|
|
}
|
|
else if (assets.FindFile("www"+request, &imf_do_not_free)) {
|
|
if (imf_do_not_free == NULL) return 0;
|
|
if (webclient->SendResponseFileFromMemory(requestbuffer, request, "",
|
|
(void*) imf_do_not_free->mem,
|
|
imf_do_not_free->memsize) != 1) return 0;
|
|
}
|
|
else {
|
|
return 0;
|
|
}
|
|
|
|
requestbuffer->Clear();
|
|
return 1;
|
|
};
|
|
|
|
|
|
|
|
std::string API_Get_Ctrls() {
|
|
std::list<VideoDevCtrl> list;
|
|
std::list<VideoDevCtrl>::iterator i;
|
|
list = vdev->GetDevCtrls();
|
|
|
|
JSONParse jp;
|
|
JSONElement je;
|
|
|
|
je.Clear();
|
|
jp.Clear();
|
|
|
|
for (i = list.begin(); i != list.end(); i++) {
|
|
JSONParse jpe;
|
|
jpe.Clear();
|
|
jpe.AddObject("id", (int) i->id);
|
|
jpe.AddObject("name", i->name);
|
|
jpe.AddObject("value", i->value);
|
|
jpe.AddObject("min", i->min);
|
|
jpe.AddObject("max", i->max);
|
|
je.SetAddArray("ctrls", jpe.ToString());
|
|
}
|
|
|
|
jp.AddObject(je);
|
|
return jp.ToString();
|
|
}
|
|
|
|
|
|
std::string API_Set_Ctrl(std::string request) {
|
|
unsigned int id;
|
|
int value;
|
|
char *t = (char*) request.c_str();
|
|
|
|
int i = 0;
|
|
while ((t = strchr (t, '/'))) {
|
|
i++;
|
|
t++;
|
|
if (i == 3) id = atol (t);
|
|
if (i == 4) value = atoi (t);
|
|
if (i > 4) break;
|
|
}
|
|
|
|
vdev->SetDevCtrl(id, value);
|
|
|
|
JSONParse jp;
|
|
jp.Clear();
|
|
return jp.ToString();
|
|
} |