56 lines
2.1 KiB
C++
56 lines
2.1 KiB
C++
#pragma once
|
|
#include "H264_Encoder.hpp"
|
|
#include "Plot.hpp"
|
|
#include <asio/any_io_executor.hpp>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <nlohmann/json_fwd.hpp>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace aethera::web {
|
|
struct Gallery_Stream_Frame {
|
|
std::optional<Encoded_Video_Frame> video{}; /* 页面唯一 H.264 图集 access unit;交付时转移所有权。 */
|
|
std::string notification{}; /* 仅承载终止错误等低频控制通知。 */
|
|
};
|
|
|
|
class Gallery_Video_Stream final
|
|
: public std::enable_shared_from_this<Gallery_Video_Stream> {
|
|
public:
|
|
struct Plot_Entry {
|
|
std::string id; /* 图集布局和浏览器裁剪使用的业务图标识。 */
|
|
std::shared_ptr<Plot> plot; /* 当前图实际 Scene 与界面之间的连接对象。 */
|
|
};
|
|
using Stream_Id = std::uint64_t;
|
|
using Stream_Handler =
|
|
std::function<void(Gallery_Stream_Frame)>;
|
|
using Video_Readiness = std::function<bool()>;
|
|
|
|
[[nodiscard]] static std::shared_ptr<Gallery_Video_Stream> create(
|
|
asio::any_io_executor clock_executor,
|
|
asio::any_io_executor encoding_executor,
|
|
std::vector<Plot_Entry> plots);
|
|
~Gallery_Video_Stream();
|
|
Gallery_Video_Stream(const Gallery_Video_Stream&) = delete;
|
|
Gallery_Video_Stream& operator=(const Gallery_Video_Stream&) = delete;
|
|
|
|
[[nodiscard]] Stream_Id subscribe(Stream_Handler handler,
|
|
Video_Readiness video_readiness);
|
|
void unsubscribe(Stream_Id stream);
|
|
void request_video_key_frame();
|
|
void shutdown() noexcept;
|
|
[[nodiscard]] std::string layout_description() const;
|
|
[[nodiscard]] nlohmann::json diagnostics() const;
|
|
|
|
private:
|
|
struct Private;
|
|
Gallery_Video_Stream(asio::any_io_executor clock_executor,
|
|
asio::any_io_executor encoding_executor,
|
|
std::vector<Plot_Entry> plots);
|
|
void bind_plots();
|
|
std::unique_ptr<Private> d;
|
|
};
|
|
}
|