整理代码

This commit is contained in:
蒲爽 2026-09-28 21:33:04 +08:00
commit c7b4e178ec
364 changed files with 59691 additions and 0 deletions

711
util/structs/ParamStruct.h Normal file
View file

@ -0,0 +1,711 @@
#ifndef PARAMSTRUCT_H
#define PARAMSTRUCT_H
#include <string>
#include <vector>
#include "Application.h"
#include "util/xpack/json.h"
namespace Util
{
namespace Structs
{
struct Channel_stream
{
std::string sn;
int enable = 0;
std::string name;
std::string appname;
std::string streamid;
int bitrate = 8192;
std::string bitrate_ctl;
std::string codec;
int encoded_size_mode = 0;
std::string encoded_size;
int fps = 30;
int gopmode = 0;
int goptxt = 30;
int video_flip_mirror_enable = 0;
int video_clipping_enable = 0;
int video_clipping_left = 0;
int video_clipping_right = 0;
int video_clipping_width = 100;
int video_clipping_height = 100;
int video_rotate = 0;
std::string pkey;
std::string rtmp_url;
std::string rtsp_url;
std::string flv_url;
std::string hls_url;
std::string webrtc_url;
std::string ts_url;
std::string srt_url;
std::string h5_url;
int multicast_enable = 1;
std::string multicast_ip_port;
int push_enable = 1;
std::string push_url;
int push_connected = 0;
Channel_stream() = default;
XPACK(O(enable, sn, name, appname, streamid, bitrate, bitrate_ctl, codec, encoded_size_mode, encoded_size, fps,
gopmode, goptxt, video_flip_mirror_enable, video_clipping_enable, video_clipping_left, video_clipping_right,
video_clipping_width, video_clipping_height, video_rotate, pkey, rtmp_url, rtsp_url, flv_url, hls_url,
webrtc_url, ts_url, srt_url, multicast_enable, multicast_ip_port, push_enable, push_url),
C(c_push_connected, F(0), push_connected))
template <class Decoder>
bool c_push_connected_decode(Decoder& de, Channel_stream& t, const char* name, int& data, const xpack::Extend* ext)
{
(void)t;
bool ret = false;
try
{
std::string raw;
ret = de.decode(name, raw, ext);
if (ret)
{
sscanf(raw.c_str(), "%i", &data);
}
}
catch (const std::exception& e)
{ // TODO:如果原则本身就是整数,会转换失败,怎么办???
ret = de.decode(name, data, ext);
}
return ret;
}
template <class Encoder>
bool c_push_connected_encode(Encoder& en, const Channel_stream& t, const char* name, const int& data,
const xpack::Extend* ext)
{
(void)t;
bool ret = en.encode(name, data, ext);
return ret;
}
};
struct Channel_input_type_mix_layer
{
int chn_id = 0;
int stream_id = 0;
int audio_status = 0;
float pos_x = 0.0f;
float pos_y = 0.0f;
float pos_w = 0.3333f;
float pos_h = 0.3333f;
int z_index = 0;
Channel_input_type_mix_layer() = default;
XPACK(O(chn_id, stream_id, audio_status, pos_x, pos_y, pos_w, pos_h, z_index))
};
struct Channel_input_type_mix
{
std::string layout_id;
std::vector<Channel_input_type_mix_layer> layers;
Channel_input_type_mix() = default;
XPACK(O(layout_id, layers))
};
struct Channel_input_type_ndi
{
std::string ndirecv_name;
Channel_input_type_ndi() = default;
XPACK(O(ndirecv_name))
};
struct Channel_input_type_net
{
int stream_mode = 0;
int min_delay = 500;
std::string path;
int rtp_type = 0;
std::string appname;
std::string streamid;
std::string push_remote_ip;
std::string pull_path;
int proxy_status;
int ipc_onvif = 0;
std::string ipc_ip;
int ipc_port = 8000;
int ipc_web_port = 80;
std::string ipc_username = "admin";
std::string ipc_password;
std::string ipc_ptz_xaddr;
std::string ipc_ptz_profile_token;
Channel_input_type_net() = default;
XPACK(O(stream_mode, min_delay, path, rtp_type, pull_path, proxy_status, appname, streamid, push_remote_ip,
ipc_onvif, ipc_ip, ipc_port, ipc_web_port, ipc_username, ipc_password, ipc_ptz_xaddr,
ipc_ptz_profile_token))
};
struct Channel_input_type_usb
{
std::string alsa;
int channel = -1;
std::string lnk;
Channel_input_type_usb() = default;
XPACK(O(alsa, channel, lnk))
};
struct Channel_audio_set
{
std::vector<int> audio_src = {0};
int audio_channel = 0;
int digital_volume_gain = 0;
int pts_offset = 0;
int encoder_bitrate = 128;
int encoder_methods = 0;
int sampling_rate = -1;
int collected_audio_frame = 0;
Channel_audio_set() = default;
XPACK(O(audio_src, audio_channel, digital_volume_gain, pts_offset, encoder_bitrate, encoder_methods, sampling_rate,
collected_audio_frame))
};
struct Channel_input_type_digimage_point
{
float x = 0;
float y = 0;
Channel_input_type_digimage_point() = default;
XPACK(O(x, y))
};
struct Channel_input_type_digimage
{
int auto_update = 0;
int tolerance = 0;
int src_fg_channel = 0;
std::string src_bg_type;
std::string src_bg_image;
int src_bg_channel = 0;
std::vector<Channel_input_type_digimage_point> point;
Channel_input_type_digimage() = default;
XPACK(O(auto_update, tolerance, src_fg_channel, src_bg_type, src_bg_image, src_bg_channel, point))
};
struct Channel_input_type_carousel_file
{
std::string filename;
int video_len = 0;
Channel_input_type_carousel_file() = default;
XPACK(O(filename, video_len))
};
struct Channel_input_type_carousel
{
int decodeA = 0;
int decodeV = 0;
int playing_file_index = -1;
long playing_file_position = 0;
std::vector<Channel_input_type_carousel_file> files;
Channel_input_type_carousel() = default;
XPACK(O(decodeA, decodeV, files), C(c_playing_file_index, F(0), playing_file_index))
template <class Decoder>
bool c_playing_file_index_decode(Decoder& de, Channel_input_type_carousel& t, const char* name, int& data,
const xpack::Extend* ext)
{
(void)t;
bool ret = false;
try
{
std::string raw;
ret = de.decode(name, raw, ext);
if (ret)
{
sscanf(raw.c_str(), "%i", &data);
}
}
catch (const std::exception& e)
{ // TODO:如果原则本身就是整数,会转换失败,怎么办???
ret = de.decode(name, data, ext);
}
return ret;
}
template <class Encoder>
bool c_playing_file_index_encode(Encoder& en, const Channel_input_type_carousel& t, const char* name,
const int& data, const xpack::Extend* ext)
{
(void)t;
bool ret = en.encode(name, data, ext);
return ret;
}
};
struct Channel_channel
{
int enable = 0;
std::string name = "HDMI";
std::string input_type = "HDMI";
int input_video_framerate = 0;
std::string input_video_size;
int input_video_collected_frame = 0;
int input_video_lost_frame = 0;
Channel_audio_set audio_set;
std::vector<Channel_stream> streams;
Channel_input_type_digimage input_type_digimage;
Channel_input_type_carousel input_type_carousel;
Channel_input_type_mix input_type_mix;
Channel_input_type_ndi input_type_ndi;
Channel_input_type_net input_type_net;
Channel_input_type_usb input_type_usb;
Channel_channel() = default;
XPACK(O(enable, name, input_type, input_video_framerate, input_video_size, input_video_collected_frame,
input_video_lost_frame, audio_set, streams, input_type_digimage, input_type_carousel, input_type_mix,
input_type_ndi, input_type_net, input_type_usb))
};
struct Channel_params
{
std::vector<Channel_channel> channels;
Channel_params() = default;
XPACK(O(channels))
};
struct Record_record
{
int enable = 0;
int flv = 0;
int mp4 = 1;
int mp4_max_second = 600;
int status = 0;
std::string start_time;
Record_record() = default;
XPACK(O(enable, flv, mp4, mp4_max_second, status, start_time))
};
struct Record_params
{
std::string base_path;
int loop_storage_enable = 0;
int loop_storage_min_size = 1024;
std::vector<std::vector<Record_record>> records;
Record_params() = default;
XPACK(O(base_path, loop_storage_enable, loop_storage_min_size, records))
};
struct Gb28181_chn
{
int enable = 0;
std::string gb_chn_id;
std::string gb_chn_name;
int stream_state = 0;
Gb28181_chn() = default;
XPACK(O(enable, gb_chn_id, gb_chn_name, stream_state))
};
struct Gb28181_params
{
int enable = 0;
std::string spec_model = "H.264/H.265 Encoder";
std::string manufacture = "Encoder";
int local_sip_port = 5061;
int con_state = 0;
std::string auth_id;
std::string auth_passwd;
int heartbeat_cycle = 30;
int heartbeat_timeout_cnt = 3;
int registration_period = 86400;
std::string sip_server_addr;
std::string sip_server_domain;
std::string sip_server_id;
int sip_server_port = 5060;
std::vector<std::vector<Gb28181_chn>> gb28181_chns;
Gb28181_params() = default;
XPACK(O(enable, spec_model, manufacture, local_sip_port, con_state, auth_id, auth_passwd, heartbeat_cycle,
heartbeat_timeout_cnt, registration_period, sip_server_addr, sip_server_domain, sip_server_id,
sip_server_port, gb28181_chns))
};
struct Loopout_audio
{
int enable = 1;
int chn_id = 0;
int audio_volume_gain;
Loopout_audio() = default;
XPACK(O(enable, chn_id, audio_volume_gain))
};
struct Loopout_video
{
int enable = 1;
int low_latency = 0;
std::string encoded_size;
int rotate = 0;
int mirror = 0;
int chn_id = 0;
int stream_id = 0;
std::string type;
int ui = 0;
int vid = 0;
std::string matrix;
int luma = 64;
int contrast = 64;
int saturation = 64;
int hue = 64;
int audio_volume_gain;
Loopout_video() = default;
XPACK(O(enable, low_latency, encoded_size, rotate, mirror, chn_id, stream_id, type, ui, vid, matrix, luma, contrast,
saturation, hue, audio_volume_gain))
};
struct Loopout_params
{
Loopout_audio audio;
Loopout_video hdmi;
Loopout_video sdi;
Loopout_params() = default;
XPACK(O(hdmi, sdi))
};
struct Mix_lay_def_layer
{
int chn_id = -1;
int stream_id = 0;
int audio_status = 0;
int lock = 0;
float pos_x = 0.0f;
float pos_y = 0.0f;
float pos_w = 0.3333f;
float pos_h = 0.3333f;
int z_index = 0;
Mix_lay_def_layer() = default;
XPACK(O(chn_id, stream_id, audio_status, lock, pos_x, pos_y, pos_w, pos_h, z_index))
};
struct Mix_lay_def_layout
{
std::string layout_id;
std::string layout_name;
int enable = 1;
std::vector<Mix_lay_def_layer> layers;
Mix_lay_def_layout() = default;
XPACK(O(layout_id, layout_name, layers))
};
struct Mix_lay_def
{
std::vector<Mix_lay_def_layout> layouts;
Mix_lay_def() = default;
XPACK(O(layouts))
};
struct Osd_osd
{
int enable = 0;
int chn_id = 0;
int stream_id = 0;
std::string type = "pic";
std::string content;
std::string font;
std::string color;
std::string bgcolor;
float alpha = 0;
float scale = 0;
int speed = 0;
float x = 0;
float y = 0;
int z = 0;
float w = 0;
float h = 0;
Osd_osd() = default;
XPACK(O(enable, chn_id, stream_id, type, content, font, color, bgcolor, alpha, scale, speed, x, y, z, w, h))
};
struct Osd_resource
{
std::string path;
std::string time;
std::string type;
Osd_resource() = default;
XPACK(O(path, time, type))
};
struct Osd_params
{
std::vector<std::vector<std::vector<Osd_osd>>> osds;
std::vector<Osd_resource> resources;
Osd_params() = default;
XPACK(O(osds, resources))
};
struct Push_url
{
int enable = 0;
std::string des;
std::string url;
int stream_state = 0;
Push_url() = default;
XPACK(O(enable, des, url, stream_state))
};
struct Push_params
{
int srcA = -1;
int srcV = 0;
int srcV_stream = 0;
int autorun = 0;
std::string start_day;
std::string start_time;
std::string stop_day;
std::string stop_time;
std::vector<Push_url> urls;
Push_params() = default;
XPACK(O(srcA, srcV, srcV_stream, autorun, start_day, start_time, stop_day, stop_time, urls))
};
struct Status_params
{
std::string version;
std::string image_version;
std::string serial_num;
float cpu_usage = 0;
float cpu_junc_tmp = 0;
float memory_free = 0;
float memory_total = 0;
std::string runtime;
std::string device_time;
int net_state_up = 0;
int net_state_dw = 0;
std::string fireware_download_url;
std::string fireware_upgrade_last_log;
Status_params() = default;
XPACK(O(version, serial_num, cpu_usage, cpu_junc_tmp, memory_free, memory_total, runtime, device_time, net_state_up,
net_state_dw, fireware_download_url, fireware_upgrade_last_log))
};
struct System_http
{
std::string user_name;
std::string user_password;
std::string language = "zh";
int api_auth = 0;
System_http() = default;
XPACK(O(user_name, user_password, language, api_auth))
};
struct System_service_ports
{
int nat_port_enable = 0;
std::string nat_port_host = "";
int http_api_port = 22112;
int http_api_port_nat_port = 22112;
int http_port = 80;
int http_port_nat_port = 80;
int rtmp_port = 1935;
int rtmp_port_nat_port = 1935;
int rtsp_port = 554;
int rtsp_port_nat_port = 554;
int srt_port = 9000;
int srt_port_nat_port = 9000;
int nat_frp_enable = 0;
int nat_frp_pid = 0;
System_service_ports() = default;
XPACK(O(nat_port_enable, nat_port_host, http_api_port, http_api_port_nat_port, http_port, http_port_nat_port,
rtmp_port, rtmp_port_nat_port, rtsp_port, rtsp_port_nat_port, srt_port, srt_port_nat_port, nat_frp_enable,
nat_frp_pid))
};
struct System_share_storage_cifs
{
int enable = 0;
std::string ip;
std::string path;
std::string username;
std::string password;
std::string local_path = "/mnt/storages/cifs";
std::string vers = "2.0";
System_share_storage_cifs() = default;
XPACK(O(enable, ip, path, username, password, local_path, vers))
};
struct System_share_storage_nfs
{
int enable = 0;
std::string ip;
std::string path;
std::string local_path = "/mnt/stroages/nfs";
std::string vers = "4";
System_share_storage_nfs() = default;
XPACK(O(enable, ip, path, local_path, vers))
};
struct System_share_storage
{
System_share_storage_cifs cifs;
System_share_storage_nfs nfs;
System_share_storage() = default;
XPACK(O(cifs, nfs))
};
struct Network_set_config
{
int enable = 0;
int dhcp_enable = 0;
std::string host_ip;
std::string mac_addr;
std::string netmask;
std::string gateway;
std::string dns1;
std::string dns2;
std::string ssid;
std::string ssid_pwd;
std::string ssid_mode = "STA";
Network_set_config() = default;
XPACK(O(enable, dhcp_enable, host_ip, mac_addr, netmask, gateway, dns1, dns2, ssid, ssid_pwd, ssid_mode))
};
struct Network_set
{
Network_set_config eth0;
Network_set_config wlan0;
Network_set() = default;
XPACK(O(eth0, wlan0))
};
struct Time_set
{
int ntp_enable = 1;
std::string ntp_server = "ntp.ntsc.ac.cn";
int ntp_server_port = 123;
int ntp_idle = 60;
std::string time_zone = "8";
Time_set() = default;
XPACK(O(ntp_enable, ntp_server, ntp_server_port, ntp_idle, time_zone))
};
struct Schedule_restart
{
int restart_enable = 0;
std::string restart_time = "06:10";
Schedule_restart() = default;
XPACK(O(restart_enable, restart_time))
};
struct System_serialtrans
{
std::string type = "232";
int work_mode = 0;
int baudrate = 9600;
std::string remote_addr;
int remote_port = 10000;
int listen_port = 10000;
System_serialtrans() = default;
XPACK(O(type, work_mode, baudrate, remote_addr, remote_port, listen_port))
};
struct System_nattraversal_frp
{
int enable = 0;
std::string remote_addr;
int remote_port = 10001;
int listen_port = 10001;
System_nattraversal_frp() = default;
XPACK(O(enable, remote_addr, remote_port, listen_port))
};
struct System_nattraversal_rtty
{
int enable = 0;
std::string name;
std::string remote_addr;
std::string id = "dfdfdsfdfdsfds";
std::string token;
System_nattraversal_rtty() = default;
XPACK(O(enable, name, remote_addr, id, token))
};
struct System_nattraversal
{
System_nattraversal_frp frp;
System_nattraversal_rtty rtty;
XPACK(O(frp, rtty))
};
struct System_moresettings
{
std::string logo_title = "H.265/H.264 Encoder";
std::string logo_image;
std::string menu_location = "left";
std::string h5play_title = "";
int screen_turn_time = 5;
System_moresettings() = default;
XPACK(O(logo_title, logo_image, menu_location, h5play_title, screen_turn_time))
};
struct System_params
{
System_http http;
Network_set network_set;
Time_set time_set;
Schedule_restart schedule_restart;
std::vector<System_serialtrans> serialtrans;
System_nattraversal nattraversal;
System_moresettings moresettings;
System_service_ports service_ports;
System_share_storage share_storage;
System_params() = default;
XPACK(O(http, network_set, time_set, schedule_restart, serialtrans, nattraversal, moresettings, service_ports,
share_storage))
};
struct Onvif_chn
{
uint32_t enable = 1;
Onvif_chn() = default;
XPACK(O(enable))
};
struct Onvif_params
{
int auth_enable = 0;
std::string auth_username = "admin";
std::string auth_password = "admin";
int time_sync_enable = 0;
uint32_t enable = 1;
std::string device_name = "H.264/H.265 Encoder";
std::string spec_model = "H.264/H.265 Encoder";
std::string manufacture = "DaweiVision";
std::string firmware_version;
std::string serial_number;
std::string hardware_id = "1.0";
std::string device_type = "Encoder";
std::string ip;
std::string mac;
uint web_service_bind_port = 8000;
std::string location_country = "China";
std::string location_city = "Chengdu";
std::vector<std::vector<Onvif_chn>> chns;
Onvif_params() = default;
XPACK(O(auth_enable, auth_username, auth_password, time_sync_enable, enable, device_name, spec_model, manufacture,
firmware_version, serial_number, hardware_id, device_type, ip, mac, web_service_bind_port, location_country,
location_city, chns))
};
struct Diskinfo
{
int status = 0;
std::string device = "";
std::string path = "";
unsigned long long total = 0;
unsigned long long used = 0;
unsigned long long available = 0;
unsigned long long free = 0;
Diskinfo() = default;
XPACK(O(status, device, path, total, used, available, free))
};
}
}
#endif