Singleton configuration reader
This commit is contained in:
parent
3986bcf378
commit
7680d7d7e3
@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.15)
|
cmake_minimum_required(VERSION 3.19)
|
||||||
project(TextReader LANGUAGES CXX)
|
project(BodyPipeline LANGUAGES CXX)
|
||||||
|
|
||||||
# Set C++ standard and enable modern practices
|
# Set C++ standard and enable modern practices
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
@ -66,12 +66,15 @@ include_directories(${PROJECT_SOURCE_DIR}/sink_manager.hpp)
|
|||||||
include_directories(${PROJECT_SOURCE_DIR}/message_handling.hpp)
|
include_directories(${PROJECT_SOURCE_DIR}/message_handling.hpp)
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/rtsp_streaming_manager.hpp)
|
include_directories(${PROJECT_SOURCE_DIR}/rtsp_streaming_manager.hpp)
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/metrics_manager.hpp)
|
include_directories(${PROJECT_SOURCE_DIR}/metrics_manager.hpp)
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/config_manager.hpp)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set(SOURCES src/main.cpp src/camera_manager.cpp src/pipeline_manager.cpp src/streammux_manager.cpp
|
set(SOURCES src/main.cpp src/camera_manager.cpp src/pipeline_manager.cpp src/streammux_manager.cpp
|
||||||
src/source_bin.cpp src/gstds_example_manager.cpp src/tiler_manager.cpp
|
src/source_bin.cpp src/gstds_example_manager.cpp src/tiler_manager.cpp
|
||||||
src/nv_video_convert_manager.cpp src/nv_osd_manager.cpp src/queue_manager.cpp
|
src/nv_video_convert_manager.cpp src/nv_osd_manager.cpp src/queue_manager.cpp
|
||||||
src/nv_ds_logger_manager.cpp src/sink_manager.cpp src/message_handling.cpp
|
src/nv_ds_logger_manager.cpp src/sink_manager.cpp src/message_handling.cpp
|
||||||
src/rtsp_streaming_manager.cpp src/metrics_manager.cpp)
|
src/rtsp_streaming_manager.cpp src/metrics_manager.cpp src/config_manager.cpp)
|
||||||
# Create the executable
|
# Create the executable
|
||||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||||
|
|
||||||
|
|||||||
16
src/config_manager.cpp
Normal file
16
src/config_manager.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "config_manager.hpp"
|
||||||
|
|
||||||
|
ConfigManager::ConfigManager() {
|
||||||
|
std::ifstream file("../data/configuration.json");
|
||||||
|
if (!file) {
|
||||||
|
throw std::runtime_error("Could not open configuration.json");
|
||||||
|
}
|
||||||
|
file >> config;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigManager& ConfigManager::get_instance() {
|
||||||
|
static ConfigManager instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nlohmann::json& ConfigManager::get_config() const { return config; }
|
||||||
19
src/config_manager.hpp
Normal file
19
src/config_manager.hpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <fstream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class ConfigManager {
|
||||||
|
public:
|
||||||
|
static ConfigManager& get_instance();
|
||||||
|
|
||||||
|
const nlohmann::json& get_config() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConfigManager(); // constructor loads the JSON file
|
||||||
|
ConfigManager(const ConfigManager&) = delete;
|
||||||
|
ConfigManager& operator=(const ConfigManager&) = delete;
|
||||||
|
|
||||||
|
nlohmann::json config;
|
||||||
|
};
|
||||||
@ -4,8 +4,6 @@
|
|||||||
g_object_set(G_OBJECT(object), "gpu-id", gpu_id, NULL);
|
g_object_set(G_OBJECT(object), "gpu-id", gpu_id, NULL);
|
||||||
#define GPU_ID 0
|
#define GPU_ID 0
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
GstRTSPServer *RtspStreamingManager::server;
|
GstRTSPServer *RtspStreamingManager::server;
|
||||||
std::string RtspStreamingManager::codec_rtsp_out = "";
|
std::string RtspStreamingManager::codec_rtsp_out = "";
|
||||||
std::string RtspStreamingManager::mount_address = "";
|
std::string RtspStreamingManager::mount_address = "";
|
||||||
@ -16,19 +14,17 @@ guint RtspStreamingManager::updsink_port_num = 1;
|
|||||||
guint RtspStreamingManager::payload = 1;
|
guint RtspStreamingManager::payload = 1;
|
||||||
|
|
||||||
RtspStreamingManager::RtspStreamingManager() {
|
RtspStreamingManager::RtspStreamingManager() {
|
||||||
json j;
|
const auto &config = ConfigManager::get_instance().get_config();
|
||||||
std::ifstream i("../data/configuration.json");
|
|
||||||
i >> j;
|
|
||||||
|
|
||||||
j.at("codec_rtsp_out").get_to(codec_rtsp_out);
|
config.at("codec_rtsp_out").get_to(codec_rtsp_out);
|
||||||
j.at("mount_address").get_to(mount_address);
|
config.at("mount_address").get_to(mount_address);
|
||||||
j.at("udp_buffer_size").get_to(udp_buffer_size);
|
config.at("udp_buffer_size").get_to(udp_buffer_size);
|
||||||
j.at("clock_rate").get_to(clock_rate);
|
config.at("clock_rate").get_to(clock_rate);
|
||||||
j.at("bitrate").get_to(bitrate);
|
config.at("bitrate").get_to(bitrate);
|
||||||
j.at("rtsp_port").get_to(rtsp_port);
|
config.at("rtsp_port").get_to(rtsp_port);
|
||||||
j.at("updsink_port_num").get_to(updsink_port_num);
|
config.at("updsink_port_num").get_to(updsink_port_num);
|
||||||
j.at("payload").get_to(payload);
|
config.at("payload").get_to(payload);
|
||||||
j.at("host").get_to(host);
|
config.at("host").get_to(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean RtspStreamingManager::start_rtsp_streaming() {
|
gboolean RtspStreamingManager::start_rtsp_streaming() {
|
||||||
|
|||||||
@ -3,10 +3,9 @@
|
|||||||
#include <gst/rtsp-server/rtsp-server.h>
|
#include <gst/rtsp-server/rtsp-server.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
|
#include "config_manager.hpp"
|
||||||
#include "cuda_runtime_api.h"
|
#include "cuda_runtime_api.h"
|
||||||
#include "json.hpp"
|
|
||||||
|
|
||||||
class RtspStreamingManager {
|
class RtspStreamingManager {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -4,15 +4,11 @@
|
|||||||
g_object_set(G_OBJECT(object), "gpu-id", gpu_id, NULL);
|
g_object_set(G_OBJECT(object), "gpu-id", gpu_id, NULL);
|
||||||
#define GPU_ID 0
|
#define GPU_ID 0
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
SinkManager::SinkManager() {
|
SinkManager::SinkManager() {
|
||||||
json j;
|
const auto& config = ConfigManager::get_instance().get_config();
|
||||||
std::ifstream i("../data/configuration.json");
|
config.at("output_video_path").get_to(output_video_path);
|
||||||
i >> j;
|
config.at("display_output").get_to(display_output);
|
||||||
j.at("output_video_path").get_to(output_video_path);
|
config.at("codec_rtsp_out").get_to(codec_rtsp_out);
|
||||||
j.at("display_output").get_to(display_output);
|
|
||||||
j.at("codec_rtsp_out").get_to(codec_rtsp_out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SinkManager::create_sink(cudaDeviceProp prop) {
|
bool SinkManager::create_sink(cudaDeviceProp prop) {
|
||||||
|
|||||||
@ -2,10 +2,9 @@
|
|||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
|
#include "config_manager.hpp"
|
||||||
#include "cuda_runtime_api.h"
|
#include "cuda_runtime_api.h"
|
||||||
#include "json.hpp"
|
|
||||||
|
|
||||||
class SinkManager {
|
class SinkManager {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -5,15 +5,11 @@
|
|||||||
#define GPU_ID 0
|
#define GPU_ID 0
|
||||||
#define MUXER_BATCH_TIMEOUT_USEC 40000
|
#define MUXER_BATCH_TIMEOUT_USEC 40000
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
StreammuxManager::StreammuxManager() {
|
StreammuxManager::StreammuxManager() {
|
||||||
json j;
|
const auto& config = ConfigManager::get_instance().get_config();
|
||||||
std::ifstream i("../data/configuration.json");
|
|
||||||
i >> j;
|
|
||||||
|
|
||||||
MUXER_OUTPUT_HEIGHT = j["MUXER_OUTPUT_HEIGHT"];
|
MUXER_OUTPUT_HEIGHT = config["MUXER_OUTPUT_HEIGHT"];
|
||||||
MUXER_OUTPUT_WIDTH = j["MUXER_OUTPUT_WIDTH"];
|
MUXER_OUTPUT_WIDTH = config["MUXER_OUTPUT_WIDTH"];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StreammuxManager::create_streammux(int num_sources) {
|
bool StreammuxManager::create_streammux(int num_sources) {
|
||||||
|
|||||||
@ -2,13 +2,11 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include "json.hpp"
|
#include "config_manager.hpp"
|
||||||
|
|
||||||
class StreammuxManager {
|
class StreammuxManager {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GstElement *streammux = NULL;
|
GstElement *streammux = NULL;
|
||||||
int MUXER_OUTPUT_WIDTH;
|
int MUXER_OUTPUT_WIDTH;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user