config.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef CONFIG_H
  2. #define CONFIG_H
  3. /**
  4. * @file config.h
  5. * @brief 项目配置管理头文件
  6. *
  7. * 本文件定义ISUP平台客户端的所有运行时配置参数,
  8. * 包括服务器地址、设备信息、流媒体配置等。
  9. */
  10. #include "common.h"
  11. /* ============================================================
  12. * CMS注册服务器配置
  13. * ============================================================ */
  14. typedef struct {
  15. char server_ip[MAX_IP_SIZE]; /* CMS服务器IP地址 */
  16. short server_port; /* CMS服务器端口 */
  17. char device_id[MAX_DEVICE_ID]; /* 设备ID(序列号) */
  18. char protocol_version[16]; /* 协议版本 */
  19. char encrypt_key[32]; /* 加密密钥 */
  20. int enable; /* 是否启用 */
  21. int auto_reconnect; /* 是否自动重连 */
  22. int reconnect_interval; /* 重连间隔(秒) */
  23. } CMSConfig;
  24. /* ============================================================
  25. * SMS流媒体服务器配置
  26. * ============================================================ */
  27. typedef struct {
  28. char listen_ip[MAX_IP_SIZE]; /* 监听IP */
  29. short listen_port; /* 监听端口 */
  30. int max_streams; /* 最大流数量 */
  31. int stream_timeout; /* 流超时时间(秒) */
  32. } SMSConfig;
  33. /* ============================================================
  34. * 报警服务器配置
  35. * ============================================================ */
  36. typedef struct {
  37. char listen_ip[MAX_IP_SIZE]; /* 监听IP */
  38. short listen_port; /* 监听端口 */
  39. int enable; /* 是否启用 */
  40. } AlarmConfig;
  41. /* ============================================================
  42. * RTMP推流配置(zlmediakit)
  43. * ============================================================ */
  44. typedef struct {
  45. char rtmp_server[MAX_IP_SIZE]; /* RTMP服务器地址 */
  46. short rtmp_port; /* RTMP端口 */
  47. char app_name[64]; /* 应用名称 */
  48. char stream_key[128]; /* 流密钥/流名称 */
  49. int enable; /* 是否启用推流 */
  50. int auto_start; /* 设备上线自动推流 */
  51. int reconnect; /* 断线重连 */
  52. int reconnect_interval; /* 重连间隔(秒) */
  53. } RTMPConfig;
  54. /* ============================================================
  55. * 录像回放配置
  56. * ============================================================ */
  57. typedef struct {
  58. int enable; /* 是否启用回放 */
  59. int max_concurrent; /* 最大并发回放数 */
  60. char save_path[MAX_PATH_SIZE]; /* 录像保存路径 */
  61. int record_duration; /* 单次回放最长时长(秒) */
  62. } PlaybackConfig;
  63. /* ============================================================
  64. * 模拟图片/视频配置
  65. * ============================================================ */
  66. typedef struct {
  67. int enable; /* 是否启用模拟模式 */
  68. char image_dir[MAX_PATH_SIZE]; /* 模拟图片目录 */
  69. int width; /* 模拟视频宽度 */
  70. int height; /* 模拟视频高度 */
  71. int fps; /* 帧率 */
  72. int bitrate; /* 码率(bps) */
  73. int gop_size; /* GOP大小 */
  74. int test_image_count; /* 测试图片数量 */
  75. } SimConfig;
  76. /* ============================================================
  77. * 全局配置结构
  78. * ============================================================ */
  79. typedef struct {
  80. CMSConfig cms; /* CMS注册配置 */
  81. SMSConfig sms; /* SMS流媒体配置 */
  82. AlarmConfig alarm; /* 报警配置 */
  83. RTMPConfig rtmp; /* RTMP推流配置 */
  84. PlaybackConfig playback; /* 录像回放配置 */
  85. SimConfig sim; /* 模拟配置 */
  86. char log_file[MAX_PATH_SIZE]; /* 日志文件路径 */
  87. int log_level; /* 日志级别 */
  88. int daemon_mode; /* 守护进程模式 */
  89. int pid_file[MAX_PATH_SIZE]; /* PID文件路径 */
  90. } AppConfig;
  91. /* ============================================================
  92. * 配置加载/保存函数声明
  93. * ============================================================ */
  94. /**
  95. * @brief 加载配置文件
  96. * @param config 配置结构指针
  97. * @param config_file 配置文件路径
  98. * @return SUCCESS成功, FAILURE失败
  99. */
  100. int config_load(AppConfig* config, const char* config_file);
  101. /**
  102. * @brief 保存配置到文件
  103. * @param config 配置结构指针
  104. * @param config_file 配置文件路径
  105. * @return SUCCESS成功, FAILURE失败
  106. */
  107. int config_save(const AppConfig* config, const char* config_file);
  108. /**
  109. * @brief 使用默认配置初始化
  110. * @param config 配置结构指针
  111. */
  112. void config_init_default(AppConfig* config);
  113. /**
  114. * @brief 打印配置信息
  115. * @param config 配置结构指针
  116. */
  117. void config_print(const AppConfig* config);
  118. /* ============================================================
  119. * 默认配置值(与图片中的设备配置对应)
  120. * ============================================================
  121. * 服务器地址: 117.131.63.98
  122. * 端口: 7031
  123. * 设备ID: AX5324540
  124. * 协议版本: ISUP5.0
  125. * 加密密钥: abc12345
  126. * ============================================================ */
  127. #endif /* CONFIG_H */