Create pipeline class
This commit is contained in:
parent
ac7ea31705
commit
5044982c87
@ -24,26 +24,37 @@ endif()
|
||||
# install(DIRECTORY data/ DESTINATION share/text_reader/data)
|
||||
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/camera_manager.hpp)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(GLIB REQUIRED glib-2.0 gobject-2.0)
|
||||
|
||||
|
||||
|
||||
include_directories(/usr/lib/x86_64-linux-gnu/glib-2.0/include)
|
||||
include_directories(/usr/include/gstreamer-1.0)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/camera_manager.hpp)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/pipeline_manager.hpp)
|
||||
|
||||
set(SOURCES src/main.cpp src/camera_manager.cpp src/pipeline_manager.cpp)
|
||||
# Create the executable
|
||||
add_executable(text_reader src/main.cpp
|
||||
src/camera_manager.cpp
|
||||
)
|
||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||
|
||||
# Copy data files to build directory
|
||||
file(COPY data/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/data)
|
||||
|
||||
# Set compiler warnings
|
||||
target_compile_options(text_reader PRIVATE
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
|
||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wextra -pedantic -Werror>
|
||||
)
|
||||
|
||||
# Platform-specific configurations
|
||||
if(WIN32)
|
||||
target_compile_definitions(text_reader PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
# Include current directory for headers
|
||||
target_include_directories(text_reader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${GLIB_INCLUDE_DIRS})
|
||||
target_link_libraries(${PROJECT_NAME} ${GLIB_LIBRARIES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} gstbase-1.0 gstreamer-1.0 gstrtp-1.0 gstvideo-1.0)
|
||||
@ -13,4 +13,5 @@ class CameraManager {
|
||||
std::vector<RtspCameraConfig> camera_list;
|
||||
CameraManager();
|
||||
void add_rtsp_camera(const std::string&, int);
|
||||
~CameraManager();
|
||||
};
|
||||
56
src/main.cpp
56
src/main.cpp
@ -1,18 +1,30 @@
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "camera_manager.hpp"
|
||||
#include "pipeline_manager.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int load_rtsp_address() {
|
||||
// Path handling works across platforms
|
||||
fs::path data_dir = "/home/user2/temp_code/text_reader/data";
|
||||
fs::path file_path = data_dir / "example.txt";
|
||||
CameraManager* camera_manager = new CameraManager();
|
||||
gint *g_source_id_list = NULL;
|
||||
gboolean *g_eos_list = NULL;
|
||||
gboolean *check_finished_streams = NULL;
|
||||
gboolean *g_source_enabled = NULL;
|
||||
guint num_sources; // number of input cameras
|
||||
|
||||
void allocate_memory_variables_cameras(const int MAX_NUM_SOURCES) {
|
||||
g_source_id_list = (gint *)g_malloc0(sizeof(gint) * MAX_NUM_SOURCES);
|
||||
g_eos_list = (gboolean *)g_malloc0(sizeof(gboolean) * MAX_NUM_SOURCES);
|
||||
check_finished_streams =
|
||||
(gboolean *)g_malloc0(sizeof(gboolean) * MAX_NUM_SOURCES);
|
||||
g_source_enabled =
|
||||
(gboolean *)g_malloc0(sizeof(gboolean) * MAX_NUM_SOURCES);
|
||||
}
|
||||
|
||||
int load_rtsp_address(CameraManager *camera_manager, fs::path file_path) {
|
||||
try {
|
||||
std::ifstream file(file_path);
|
||||
if (!file.is_open()) {
|
||||
@ -29,7 +41,7 @@ int load_rtsp_address() {
|
||||
std::cout << "Line " << line_number++ << ": " << line << '\n';
|
||||
camera_manager->add_rtsp_camera(line, line_number);
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@ -37,4 +49,34 @@ int load_rtsp_address() {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main() { load_rtsp_address(); }
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 1) {
|
||||
std::cerr << "Usage: " << argv[0] << " <RTSP_URL>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
CameraManager *camera_manager = new CameraManager();
|
||||
// Path handling works across platforms
|
||||
fs::path data_dir = "../data";
|
||||
fs::path file_path = data_dir / "example.txt";
|
||||
load_rtsp_address(camera_manager, file_path);
|
||||
|
||||
char **url_camera = new char *[camera_manager->camera_list.size() + 1];
|
||||
num_sources = camera_manager->camera_list.size();
|
||||
const int MAX_NUM_SOURCES = camera_manager->camera_list.size();
|
||||
|
||||
allocate_memory_variables_cameras(MAX_NUM_SOURCES);
|
||||
url_camera[0] = argv[0];
|
||||
for (guint i = 0; i < num_sources; i++) {
|
||||
url_camera[i + 1] = &camera_manager->camera_list.at(i).address[0];
|
||||
}
|
||||
std::cout << "print content of camera urls" << std::endl;
|
||||
for (int i = 0; i < (int)num_sources + 1; i++) {
|
||||
std::cout << url_camera[i] << std::endl;
|
||||
}
|
||||
|
||||
PipelineManager *pipeline_manager =
|
||||
new PipelineManager(num_sources, url_camera);
|
||||
pipeline_manager->create_pipeline();
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
src/pipeline_manager.cpp
Normal file
23
src/pipeline_manager.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "pipeline_manager.hpp"
|
||||
|
||||
PipelineManager::PipelineManager() { ; }
|
||||
|
||||
PipelineManager::PipelineManager(int num_sources, char** url_camera) {
|
||||
g_setenv("GST_DEBUG_DUMP_DOT_DIR", ".", TRUE);
|
||||
gst_init(&num_sources, &url_camera);
|
||||
g_run_forever = atoi("0");
|
||||
loop = g_main_loop_new(NULL, FALSE);
|
||||
}
|
||||
|
||||
int PipelineManager::create_pipeline() {
|
||||
g_mutex_init(&eos_lock);
|
||||
|
||||
/* Create Pipeline element that will form a connection of other elements */
|
||||
pipeline = gst_pipeline_new("BodyDetectionPipeline");
|
||||
|
||||
if (!pipeline) {
|
||||
g_printerr("pipeline could not be created. Exiting.");
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
16
src/pipeline_manager.hpp
Normal file
16
src/pipeline_manager.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include <glib.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
class PipelineManager {
|
||||
private:
|
||||
gboolean g_run_forever = FALSE;
|
||||
GMainLoop *loop = NULL;
|
||||
GstElement *pipeline = NULL;
|
||||
GMutex eos_lock;
|
||||
|
||||
public:
|
||||
PipelineManager();
|
||||
PipelineManager(int, char **);
|
||||
int create_pipeline();
|
||||
~PipelineManager();
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user