-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented a small web frontend to get a video file, next i just need to convert it to a stream of matrices and pass it to hyperwall * initial implementation of using hyperwall through web ui * finished implementing file uploading and added some more convenience scripts * depends * depends * depends
- Loading branch information
1 parent
ae6eed4
commit a6c9b08
Showing
10 changed files
with
243 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
spdlog | ||
argparse | ||
catch2_3 | ||
httplib | ||
]; | ||
}; | ||
}) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <httplib.h> | ||
#include <spdlog/spdlog.h> | ||
|
||
namespace Web { | ||
|
||
class Server { | ||
httplib::Server server; | ||
public: | ||
|
||
Server() { | ||
server.set_logger([](httplib::Request req, httplib::Response res){ | ||
std::stringstream ss; | ||
ss << "Method: " << req.method << " | "; | ||
ss << "Path: " << req.path << " | "; | ||
ss << "Status: " << res.status << " | "; | ||
|
||
switch(((res.status + 50) / 100) * 100) { | ||
case 100: | ||
case 300: | ||
spdlog::warn(ss.str()); | ||
break; | ||
case 200: | ||
spdlog::info(ss.str()); | ||
break; | ||
case 400: | ||
case 500: | ||
spdlog::error(ss.str()); | ||
} | ||
}); | ||
} | ||
void run(std::string host, int port) { | ||
spdlog::info("Running server: {}:{}", host, port); | ||
server.listen(host, port); | ||
} | ||
|
||
void add(std::string path, std::string content) { | ||
server.Get(path, [content](httplib::Request req, httplib::Response& res) { | ||
res.set_content(content, "text/html"); | ||
}); | ||
} | ||
void add_page(std::string path, std::ifstream file) { | ||
std::stringstream ss; | ||
ss << file.rdbuf(); | ||
return add(path, ss.str()); | ||
} | ||
template<typename F> | ||
void Post (std::string path, F f) { | ||
server.Post(path, f); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
while true; do | ||
ffplay rtsp://${1}:8554/frame/${2}/${3} -fs -autoexit -window_title "frame-${2}x${3}" | ||
sleep 1 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
for ((x=0;x<$1;x++)); do | ||
for ((y=0;y<$2;y++)); do | ||
tmux new-session -d ./build/Receiver ${x}x${y} | ||
done | ||
for ((x=0;x<$2;x++)); do | ||
for ((y=0;y<$3;y++)); do | ||
tmux new-session -d ./scripts/ffplay-single.sh $1 $x $y | ||
done | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
#include <filesystem> | ||
#include <fstream> | ||
#include <opencv2/videoio.hpp> | ||
#include <spdlog/spdlog.h> | ||
|
||
#include "Hyperwall.hpp" | ||
#include "Sources/FileSource.hpp" | ||
#include "Utils.hpp" | ||
#include "Web/Server.hpp" | ||
|
||
std::vector<std::thread> threads; | ||
bool running; | ||
|
||
std::string layout(std::string input) { | ||
std::string style = R"( | ||
<style> | ||
html { | ||
font-family: sans-serif; | ||
} | ||
body { | ||
margin-left: 5%; | ||
margin-right: 5%; | ||
text-align: center; | ||
} | ||
form { | ||
text-align: right; | ||
} | ||
section { | ||
text-align: center; | ||
width: 400px; | ||
display: inline-flex; | ||
} | ||
footer { | ||
position: fixed; | ||
bottom: 0; | ||
left: 0; | ||
width: 100%; | ||
} | ||
</style> | ||
)"; | ||
return std::format( | ||
R"( | ||
<!DOCTYPE html> | ||
<html> | ||
{} | ||
<head> | ||
<title>Hyperwall</title> | ||
<link rel="icon" type="image/png" href="https://avatars.githubusercontent.com/u/126147587?s200&v=4"> | ||
</head> | ||
<body> | ||
<img style="position:fixed; left: 6%; top: 1%;" src="https://avatars.githubusercontent.com/u/126147587?s=200&v=4" width="100" height="100"> | ||
<h1>Hyperwall</h1> | ||
<br><br> | ||
<hr> | ||
{} | ||
</body> | ||
<footer> | ||
Available on <a href="https://github.com/aalborg-supercomputer-klubben/hyperwall">Github</a> | Created By: <a href="https://skade.dev">Mast3r_waf1z</a> | ||
</footer> | ||
</html> | ||
)", style, input); | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
Web::Server server; | ||
|
||
server.add("/", layout(R"( | ||
<section> | ||
<form id="videoUploadForm" method="POST" enctype="multipart/form-data" action="/run"> | ||
<label for="videoFile">Choose a video file: </label> | ||
<input type="file" id="videoFile" name="videoFile" accept="video/*" required> | ||
<br><br> | ||
<label for="dimensions">dimensions: </label> | ||
<input type="text" id="dimensions" name="dimensions" placeholder="2x2"> | ||
<br><br> | ||
<label for="resolution">resolution: </label> | ||
<input type="text" id="resolution" name="resolution" placeholder="1920x1080"> | ||
<br><br> | ||
<button type="submit">Run</button> | ||
</form> | ||
</section> | ||
)")); | ||
|
||
server.Post("/run", [](httplib::Request request, httplib::Response& response){ | ||
if(!request.has_file("videoFile")) { | ||
response.status = 400; | ||
response.set_content("No file uploaded.", "text/plain"); | ||
return; | ||
} | ||
std::tuple<int, int> dimensions, resolution; | ||
if(request.has_file("dimensions") && request.get_file_value("dimensions").content.contains("x")) { | ||
auto dim = request.get_file_value("dimensions"); | ||
dimensions = Util::split_resolution(dim.content); | ||
} | ||
else { | ||
spdlog::warn("No dim provided"); | ||
dimensions = {2, 2}; | ||
} | ||
if (request.has_file("resolution") && request.get_file_value("resolution").content.contains("x")) { | ||
auto res = request.get_file_value("resolution"); | ||
resolution = Util::split_resolution(res.content); | ||
} | ||
else { | ||
spdlog::warn("No res provided"); | ||
resolution = {1920, 1080}; | ||
} | ||
|
||
|
||
const auto& file = request.get_file_value("videoFile"); | ||
spdlog::info("Got file: {}", file.filename); | ||
|
||
if (running) { | ||
response.status = 400; | ||
response.set_content("Failed, hyperwall is already running", "text/plain"); | ||
return; | ||
} | ||
auto filename = std::format("./tmp/{}", file.filename); | ||
|
||
std::ofstream ofs("./tmp/" + file.filename, std::ios::binary); | ||
if (ofs) { | ||
ofs.write(file.content.data(), file.content.size()); | ||
ofs.close(); | ||
ofs.flush(); | ||
} | ||
|
||
threads.push_back(std::thread{[&filename, dimensions, resolution](){ | ||
running = true; | ||
Hyperwall::FileSource source(filename); | ||
Hyperwall::Settings settings( | ||
resolution, | ||
dimensions | ||
); | ||
Hyperwall::Hyperwall hyperwall(source, settings); | ||
hyperwall.run(); | ||
std::filesystem::remove(filename); | ||
running = false; | ||
}}); | ||
|
||
response.set_content(layout(R"( | ||
Successfully uploaded video!<br> | ||
<a href="/">Go back</a> | ||
)"), "text/html"); | ||
}); | ||
|
||
server.run("0.0.0.0", 8000); | ||
} |