ai自主改之前
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include "Gallery_WebSocket.hpp"
|
||||
#include "Graph_WebSocket.hpp"
|
||||
#include "Gallery_Plots.hpp"
|
||||
#include <asio/thread_pool.hpp>
|
||||
#include <drogon/drogon.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <algorithm>
|
||||
@@ -42,46 +41,31 @@ std::shared_ptr<Plot> find_plot(const Plot_Map& plots, std::string_view id) {
|
||||
}
|
||||
|
||||
int run_web_server(std::uint16_t port, const std::filesystem::path& asset_root) {
|
||||
const auto hardware_threads = std::max(2U, std::thread::hardware_concurrency());
|
||||
const auto plot_workers = std::min(8U, hardware_threads);
|
||||
/* 2D 的同步 Blend2D 绘制不能占满 3D 的帧时钟与 Visual Prepare 域。
|
||||
* 两类 Plot 使用同一套 Plot/帧策略实现,但执行资源按渲染架构隔离。 */
|
||||
auto plot_2d_pool = std::make_shared<asio::thread_pool>(plot_workers);
|
||||
auto plot_3d_pool = std::make_shared<asio::thread_pool>(plot_workers);
|
||||
auto gallery_clock_pool = std::make_shared<asio::thread_pool>(1);
|
||||
// 原生 720x420 画质按四图一个媒体组并行编码。每路图集仍是完整像素
|
||||
// 视频,但较小的 access unit 缩短 libdatachannel packetize/DTLS 临界段;
|
||||
// 时钟只负责轻量 tick,六路编码各有独立 strand 和执行线程。
|
||||
auto gallery_encoding_pool = std::make_shared<asio::thread_pool>(
|
||||
std::min(6U, hardware_threads));
|
||||
const auto executor_2d = plot_2d_pool->get_executor();
|
||||
const auto executor_3d = plot_3d_pool->get_executor();
|
||||
|
||||
auto plots = std::make_shared<Plot_Map>();
|
||||
plots->emplace("axes", make_axes_plot(executor_2d));
|
||||
plots->emplace("spectrum", make_spectrum_plot(executor_2d));
|
||||
plots->emplace("frequency_trace", make_frequency_trace_plot(executor_2d));
|
||||
plots->emplace("sweep_spectrum", make_sweep_spectrum_plot(executor_2d));
|
||||
plots->emplace("afterglow", make_afterglow_plot(executor_2d));
|
||||
plots->emplace("waterfall", make_waterfall_plot(executor_2d));
|
||||
plots->emplace("constellation", make_constellation_plot(executor_2d));
|
||||
plots->emplace("selection_overlay", make_selection_overlay_plot(executor_2d));
|
||||
plots->emplace("datoviz_point", make_datoviz_point_plot(executor_3d));
|
||||
plots->emplace("datoviz_splat", make_datoviz_splat_plot(executor_3d));
|
||||
plots->emplace("datoviz_pixel", make_datoviz_pixel_plot(executor_3d));
|
||||
plots->emplace("datoviz_marker", make_datoviz_marker_plot(executor_3d));
|
||||
plots->emplace("datoviz_sphere", make_datoviz_sphere_plot(executor_3d));
|
||||
plots->emplace("datoviz_segment", make_datoviz_segment_plot(executor_3d));
|
||||
plots->emplace("datoviz_vector", make_datoviz_vector_plot(executor_3d));
|
||||
plots->emplace("datoviz_primitive", make_datoviz_primitive_plot(executor_3d));
|
||||
plots->emplace("datoviz_mesh", make_datoviz_mesh_plot(executor_3d));
|
||||
plots->emplace("datoviz_spectrogram", make_datoviz_spectrogram_plot(executor_3d));
|
||||
plots->emplace("datoviz_path", make_datoviz_path_plot(executor_3d));
|
||||
plots->emplace("datoviz_image", make_datoviz_image_plot(executor_3d));
|
||||
plots->emplace("datoviz_labels", make_datoviz_labels_plot(executor_3d));
|
||||
plots->emplace("datoviz_glyph", make_datoviz_glyph_plot(executor_3d));
|
||||
plots->emplace("datoviz_text", make_datoviz_text_plot(executor_3d));
|
||||
plots->emplace("datoviz_volume", make_datoviz_volume_plot(executor_3d));
|
||||
plots->emplace("axes", make_axes_plot());
|
||||
plots->emplace("spectrum", make_spectrum_plot());
|
||||
plots->emplace("frequency_trace", make_frequency_trace_plot());
|
||||
plots->emplace("sweep_spectrum", make_sweep_spectrum_plot());
|
||||
plots->emplace("afterglow", make_afterglow_plot());
|
||||
plots->emplace("waterfall", make_waterfall_plot());
|
||||
plots->emplace("constellation", make_constellation_plot());
|
||||
plots->emplace("selection_overlay", make_selection_overlay_plot());
|
||||
plots->emplace("datoviz_point", make_datoviz_point_plot());
|
||||
plots->emplace("datoviz_splat", make_datoviz_splat_plot());
|
||||
plots->emplace("datoviz_pixel", make_datoviz_pixel_plot());
|
||||
plots->emplace("datoviz_marker", make_datoviz_marker_plot());
|
||||
plots->emplace("datoviz_sphere", make_datoviz_sphere_plot());
|
||||
plots->emplace("datoviz_segment", make_datoviz_segment_plot());
|
||||
plots->emplace("datoviz_vector", make_datoviz_vector_plot());
|
||||
plots->emplace("datoviz_primitive", make_datoviz_primitive_plot());
|
||||
plots->emplace("datoviz_mesh", make_datoviz_mesh_plot());
|
||||
plots->emplace("datoviz_spectrogram", make_datoviz_spectrogram_plot());
|
||||
plots->emplace("datoviz_path", make_datoviz_path_plot());
|
||||
plots->emplace("datoviz_image", make_datoviz_image_plot());
|
||||
plots->emplace("datoviz_labels", make_datoviz_labels_plot());
|
||||
plots->emplace("datoviz_glyph", make_datoviz_glyph_plot());
|
||||
plots->emplace("datoviz_text", make_datoviz_text_plot());
|
||||
plots->emplace("datoviz_volume", make_datoviz_volume_plot());
|
||||
|
||||
std::vector<Gallery_Video_Stream::Plot_Entry> gallery_2d;
|
||||
std::vector<Gallery_Video_Stream::Plot_Entry> gallery_3d;
|
||||
@@ -99,18 +83,14 @@ int run_web_server(std::uint16_t port, const std::filesystem::path& asset_root)
|
||||
auto gallery_streams = std::make_shared<Gallery_Stream_Map>();
|
||||
auto plot_media = std::make_shared<
|
||||
std::unordered_map<std::string, std::string>>();
|
||||
const auto add_media_group = [&gallery_streams, &plot_media,
|
||||
&gallery_clock_pool,
|
||||
&gallery_encoding_pool](
|
||||
const auto add_media_group = [&gallery_streams, &plot_media](
|
||||
std::string id,
|
||||
std::vector<Gallery_Video_Stream::Plot_Entry> entries) {
|
||||
const auto path = "/ws/gallery?group=" + id;
|
||||
for (const auto& entry : entries)
|
||||
plot_media->emplace(entry.id, path);
|
||||
gallery_streams->emplace(
|
||||
std::move(id), Gallery_Video_Stream::create(
|
||||
gallery_clock_pool->get_executor(),
|
||||
gallery_encoding_pool->get_executor(), std::move(entries)));
|
||||
std::move(id), Gallery_Video_Stream::create(std::move(entries)));
|
||||
};
|
||||
constexpr std::size_t plots_per_media_group{4};
|
||||
const auto add_media_groups = [&add_media_group](
|
||||
@@ -260,23 +240,15 @@ int run_web_server(std::uint16_t port, const std::filesystem::path& asset_root)
|
||||
.setHomePage("index.html")
|
||||
.setStaticFileHeaders({{"Cache-Control", "no-store"}})
|
||||
.addListener("127.0.0.1", port)
|
||||
.setThreadNum(std::min(8U, hardware_threads))
|
||||
.setThreadNum(std::min(8U, std::max(2U, std::thread::hardware_concurrency())))
|
||||
.setIdleConnectionTimeout(90)
|
||||
.run();
|
||||
/* 先解除 Plot 完成帧订阅并停止页面时钟,再停止其执行资源。
|
||||
* 这样销毁期不存在回调访问已释放图集、计时器跨线程 cancel 或半途编码。 */
|
||||
/* 先解除 Plot 完成帧订阅并停止页面时钟;Taskflow 任务只捕获弱所有权,
|
||||
* 因而销毁期不会访问已经释放的图集,也不需要额外业务线程池排空。 */
|
||||
for (const auto& [id, stream] : *gallery_streams) {
|
||||
static_cast<void>(id);
|
||||
stream->shutdown();
|
||||
}
|
||||
plot_2d_pool->stop();
|
||||
plot_3d_pool->stop();
|
||||
gallery_clock_pool->stop();
|
||||
gallery_encoding_pool->stop();
|
||||
plot_2d_pool->join();
|
||||
plot_3d_pool->join();
|
||||
gallery_clock_pool->join();
|
||||
gallery_encoding_pool->join();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user