Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate voctomix and cm-config based on detected format #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion HttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ int HttpServer::requestHandler(
else if(method == "GET" && url.find("/capture/") == 0) {
return captureRequestHandler(url.substr(sizeof("/capture/") - 1), responseHeaders, responseBody);
}
else if(method == "GET" && url.find("/config/") == 0) {
return configRequestHandler(url.substr(sizeof("/config/") - 1), responseHeaders, responseBody);
}
else
{
return MHD_HTTP_NOT_FOUND;
Expand Down Expand Up @@ -145,6 +148,69 @@ int HttpServer::captureRequestHandler(
return MHD_HTTP_NOT_FOUND;
}

int HttpServer::configRequestHandler(
std::string filename,
std::map<std::string, std::string>* responseHeaders,
std::stringstream* responseBody
) {
std::string index_str = filename;
unsigned long index;
try {
index = std::stoul(index_str);
}
catch(std::invalid_argument) {
return MHD_HTTP_NOT_FOUND;
}
catch(std::out_of_range) {
return MHD_HTTP_NOT_FOUND;
}

if(index < m_deviceProbers.size())
{
DeviceProber *deviceProber = m_deviceProbers[index];
(*responseHeaders)["Content-Type"] = "text/html; charset=UTF-8";

(*responseBody) <<
"<!DOCTYPE html>"
"<html>"
" <head>"
" <link rel=\"stylesheet\" type=\"text/css\" href=\"/static/style.css\">"
" </head>"
" <body>"
" <h1>Configuration-Snippets</h1>"
" <h2>for the c3voc cm</h2>"
" <code>"
"…\n"
" -\n"
" # " << deviceProber->GetDeviceName() << "\n"
" name: cam" << (index+1) << "\n"
" type: decklink-internal\n"
" devicenumber: " << index << "\n"
" video_connection: " << videoConnectionToString(deviceProber->GetActiveConnection()) << "\n"
" video_mode: \"" << deviceProber->GetDetectedMode() << "\"\n"
"…"
" </code>"
""
" <h2>for voctocore/config.ini</h2>"
" <code>"
"…\n"
"# " << deviceProber->GetDeviceName() << "\n"
"[source.cam" << (index+1) << "]\n"
"kind = decklink\n"
"devicenumber = " << index << "\n"
"video_connection = " << videoConnectionToString(deviceProber->GetActiveConnection()) << "\n"
"video_mode = " << deviceProber->GetDetectedMode() << "\n"
"audio_connection = embedded\n"
"deinterlace = assume-progressive\n"
"…"
" </code>"
" </body>"
"</html>";
return MHD_HTTP_OK;
}
return MHD_HTTP_NOT_FOUND;
}

int HttpServer::indexRequestHandler(
std::map<std::string, std::string>* responseHeaders,
std::stringstream* responseBody
Expand All @@ -156,7 +222,7 @@ int HttpServer::indexRequestHandler(
"<html>"
" <head>"
" <meta http-equiv=\"refresh\" content=\"1; URL=/\">"
" <link rel=\"stylesheet\" type=\"text/css\" href=\"static/style.css\">"
" <link rel=\"stylesheet\" type=\"text/css\" href=\"/static/style.css\">"
" </head>"
" <body>"
" <h1>DecklinkDebugger on <u>" << m_hostname << "</u></h1>"
Expand All @@ -170,6 +236,7 @@ int HttpServer::indexRequestHandler(
" <th>Detected Mode</th>"
" <th>Pixel Format</th>"
" <th>Capture</th>"
" <th>Config</th>"
" </thead>"
" <tbody>";

Expand Down Expand Up @@ -205,6 +272,18 @@ int HttpServer::indexRequestHandler(

(*responseBody) <<
" </td>"
" <td>";

if(deviceProber->GetSignalDetected())
{
(*responseBody) <<
" <a href=\"/config/" << deviceIndex << "\">"
" Config-Snippets"
" </a>";
}

(*responseBody) <<
" </td>"
" </tr>";

deviceIndex++;
Expand Down
6 changes: 6 additions & 0 deletions HttpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ class HttpServer
std::stringstream* responseBody
);

int configRequestHandler(
std::string filename,
std::map<std::string, std::string>* responseHeaders,
std::stringstream* responseBody
);

private:
int32_t m_refCount;
std::vector<DeviceProber*> m_deviceProbers;
Expand Down
3 changes: 3 additions & 0 deletions rc/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ table td img {
width: 160px;
height: 90px;
}
code {
white-space: pre;
}