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)
|
# 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
|
# Create the executable
|
||||||
add_executable(text_reader src/main.cpp
|
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||||
src/camera_manager.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
# Copy data files to build directory
|
# Copy data files to build directory
|
||||||
file(COPY data/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/data)
|
file(COPY data/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/data)
|
||||||
|
|
||||||
# Set compiler warnings
|
# Set compiler warnings
|
||||||
target_compile_options(text_reader PRIVATE
|
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
|
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
|
||||||
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wextra -pedantic -Werror>
|
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wextra -pedantic -Werror>
|
||||||
)
|
)
|
||||||
|
|
||||||
# Platform-specific configurations
|
# Platform-specific configurations
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_compile_definitions(text_reader PRIVATE _CRT_SECURE_NO_WARNINGS)
|
target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Include current directory for headers
|
# 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;
|
std::vector<RtspCameraConfig> camera_list;
|
||||||
CameraManager();
|
CameraManager();
|
||||||
void add_rtsp_camera(const std::string&, int);
|
void add_rtsp_camera(const std::string&, int);
|
||||||
|
~CameraManager();
|
||||||
};
|
};
|
||||||
54
src/main.cpp
54
src/main.cpp
@ -1,18 +1,30 @@
|
|||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "camera_manager.hpp"
|
#include "camera_manager.hpp"
|
||||||
|
#include "pipeline_manager.hpp"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
int load_rtsp_address() {
|
gint *g_source_id_list = NULL;
|
||||||
// Path handling works across platforms
|
gboolean *g_eos_list = NULL;
|
||||||
fs::path data_dir = "/home/user2/temp_code/text_reader/data";
|
gboolean *check_finished_streams = NULL;
|
||||||
fs::path file_path = data_dir / "example.txt";
|
gboolean *g_source_enabled = NULL;
|
||||||
CameraManager* camera_manager = new CameraManager();
|
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 {
|
try {
|
||||||
std::ifstream file(file_path);
|
std::ifstream file(file_path);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
@ -37,4 +49,34 @@ int load_rtsp_address() {
|
|||||||
return EXIT_SUCCESS;
|
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