From 1566d416a42599b2eb6e03c06898d3e4b8b10989 Mon Sep 17 00:00:00 2001 From: LufeBisect Date: Wed, 22 Jan 2025 18:06:34 +0000 Subject: [PATCH] Refactor for reduced redundancy --- cpp/libs/CMakeLists.txt | 4 +- .../CMakeLists.txt | 67 ------ .../gst_nmos_audio_receiver_plugin/utils.cpp | 198 ------------------ .../gst_nmos_audio_receiver_plugin/utils.h | 116 ---------- cpp/libs/gst_nmos_plugins/CMakeLists.txt | 99 +++++++++ .../include/element_class.h} | 45 ---- .../include/nmos_configuration.h | 58 +++++ .../src}/gst_nmos_audio_receiver_plugin.cpp | 4 +- .../src}/gst_nmos_sender_plugin.cpp | 16 +- .../src}/gst_nmos_video_receiver_plugin.cpp | 4 +- .../src}/utils.cpp | 191 +++++++++++------ cpp/libs/gst_nmos_plugins/src/utils.h | 34 +++ .../gst_nmos_sender_plugin/CMakeLists.txt | 67 ------ cpp/libs/gst_nmos_sender_plugin/utils.h | 151 ------------- .../CMakeLists.txt | 67 ------ .../gst_nmos_video_receiver_plugin/utils.cpp | 198 ------------------ 16 files changed, 338 insertions(+), 981 deletions(-) delete mode 100644 cpp/libs/gst_nmos_audio_receiver_plugin/CMakeLists.txt delete mode 100644 cpp/libs/gst_nmos_audio_receiver_plugin/utils.cpp delete mode 100644 cpp/libs/gst_nmos_audio_receiver_plugin/utils.h create mode 100644 cpp/libs/gst_nmos_plugins/CMakeLists.txt rename cpp/libs/{gst_nmos_video_receiver_plugin/utils.h => gst_nmos_plugins/include/element_class.h} (61%) create mode 100644 cpp/libs/gst_nmos_plugins/include/nmos_configuration.h rename cpp/libs/{gst_nmos_audio_receiver_plugin => gst_nmos_plugins/src}/gst_nmos_audio_receiver_plugin.cpp (99%) rename cpp/libs/{gst_nmos_sender_plugin => gst_nmos_plugins/src}/gst_nmos_sender_plugin.cpp (97%) rename cpp/libs/{gst_nmos_video_receiver_plugin => gst_nmos_plugins/src}/gst_nmos_video_receiver_plugin.cpp (99%) rename cpp/libs/{gst_nmos_sender_plugin => gst_nmos_plugins/src}/utils.cpp (70%) create mode 100644 cpp/libs/gst_nmos_plugins/src/utils.h delete mode 100644 cpp/libs/gst_nmos_sender_plugin/CMakeLists.txt delete mode 100644 cpp/libs/gst_nmos_sender_plugin/utils.h delete mode 100644 cpp/libs/gst_nmos_video_receiver_plugin/CMakeLists.txt delete mode 100644 cpp/libs/gst_nmos_video_receiver_plugin/utils.cpp diff --git a/cpp/libs/CMakeLists.txt b/cpp/libs/CMakeLists.txt index 8c8a6c5..1bb41b6 100644 --- a/cpp/libs/CMakeLists.txt +++ b/cpp/libs/CMakeLists.txt @@ -2,9 +2,7 @@ add_subdirectory(bisect_expected) add_subdirectory(bisect_nmoscpp) add_subdirectory(bisect_sdp) add_subdirectory(bisect_gst) -add_subdirectory(gst_nmos_sender_plugin) -add_subdirectory(gst_nmos_video_receiver_plugin) -add_subdirectory(gst_nmos_audio_receiver_plugin) +add_subdirectory(gst_nmos_plugins) add_subdirectory(ossrf_nmos_api) add_subdirectory(ossrf_gstreamer_api) add_subdirectory(bisect_json) diff --git a/cpp/libs/gst_nmos_audio_receiver_plugin/CMakeLists.txt b/cpp/libs/gst_nmos_audio_receiver_plugin/CMakeLists.txt deleted file mode 100644 index 8865116..0000000 --- a/cpp/libs/gst_nmos_audio_receiver_plugin/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -cmake_minimum_required(VERSION 3.16) -project(gst_nmos_audio_receiver_plugin LANGUAGES CXX) - -find_package(nlohmann_json REQUIRED) -find_package(PkgConfig REQUIRED) - -# Locate GLib package -pkg_check_modules(GLIB REQUIRED glib-2.0) - -# Locate GStreamer packages -pkg_search_module(GSTREAMER REQUIRED gstreamer-1.0>=1.4) -pkg_search_module(GSTREAMER_APP REQUIRED gstreamer-app-1.0>=1.4) -pkg_search_module(GSTREAMER_AUDIO REQUIRED gstreamer-audio-1.0>=1.4) -pkg_search_module(GSTREAMER_VIDEO REQUIRED gstreamer-video-1.0>=1.4) - -# Include GLib directories and link libraries -include_directories(${GLIB_INCLUDE_DIRS}) -link_directories(${GLIB_LIBRARY_DIRS}) -add_definitions(${GLIB_CFLAGS_OTHER}) - -# Include source files for gst_nmos_audio_receiver_plugin -file(GLOB_RECURSE PLUGIN_SOURCE_FILES *.cpp *.h) - -# Include source files for utils -file(GLOB_RECURSE UTILS_SOURCE_FILES utils/*.cpp utils/*.h) - -# Combine utils and plugin sources -set(SOURCE_FILES ${PLUGIN_SOURCE_FILES} ${UTILS_SOURCE_FILES}) - -# Define the plugin as a shared library -add_library(${PROJECT_NAME} MODULE ${SOURCE_FILES}) - -# Include directories -target_include_directories(${PROJECT_NAME} - PRIVATE ${GSTREAMER_INCLUDE_DIRS} - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/utils/include -) - -# Link GStreamer libraries -target_compile_options(${PROJECT_NAME} PRIVATE ${GSTREAMER_CFLAGS_OTHER}) -target_link_libraries(${PROJECT_NAME} - PRIVATE - ${GSTREAMER_LIBRARIES} - ${GSTREAMER_APP_LIBRARIES} - ${GSTREAMER_AUDIO_LIBRARIES} - ${GSTREAMER_VIDEO_LIBRARIES} - PUBLIC - bisect::project_warnings - bisect::expected - bisect::bisect_nmoscpp - bisect::bisect_json - nlohmann_json::nlohmann_json - ossrf::ossrf_nmos_api - ${GLIB_LIBRARIES} -) - -# Specify the output directory and the library name -set_target_properties(${PROJECT_NAME} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins - OUTPUT_NAME "gstnmosaudioreceiver" -) - -add_library(ossrf::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) - -# Install the plugin to the system's GStreamer plugin directory -install(TARGETS ${PROJECT_NAME} - LIBRARY DESTINATION ~/.local/lib/gstreamer-1.0) diff --git a/cpp/libs/gst_nmos_audio_receiver_plugin/utils.cpp b/cpp/libs/gst_nmos_audio_receiver_plugin/utils.cpp deleted file mode 100644 index aac35f2..0000000 --- a/cpp/libs/gst_nmos_audio_receiver_plugin/utils.cpp +++ /dev/null @@ -1,198 +0,0 @@ -#include "utils.h" -#include "ossrf/nmos/api/nmos_client.h" -#include "bisect/nmoscpp/configuration.h" -#include "bisect/expected/macros.h" -#include "bisect/expected.h" -#include "bisect/json.h" -#include - -using namespace bisect; -using json = nlohmann::json; - -void create_default_config_fields(config_fields_t* config) -{ - if(!config) - { - g_critical("Config pointer is NULL"); - return; - } - - // Initialize node_fields_t - config->node.id = "d1073007-4099-452f-b8e8-837b8987d845"; - config->node.configuration_location = - "/home/nmos/repos/nmos-sender-receiver-framework/cpp/demos/config/nmos_plugin_node_config_receiver.json"; - - // Initialize device_fields_t - config->device.id = "093a1c56-4033-49f7-9e17-fbcb21a19383"; - config->device.label = "OSSRF Device2"; - config->device.description = "OSSRF Device2"; - - // Initialize config_fields_t - config->id = "af600517-a452-4c2c-8b60-2caa770d6435"; - config->label = "BISECT OSSRF Audio Receiver"; - config->description = "BISECT OSSRF Audio Receiver"; - config->interface_name = "wlp1s0"; - config->address = "192.168.1.36"; -} - -json create_node_config(config_fields_t& config) -{ - const std::string node_config_str = get_node_config(config.node.configuration_location); - if(node_config_str != "") - { - json node_config = json::parse(node_config_str); - node_config["id"] = config.node.id; - - return node_config; - } - else - { - return nullptr; - } -} - -json create_device_config(config_fields_t& config) -{ - json device = { - {"id", config.device.id}, {"label", config.device.label}, {"description", config.device.description}}; - return device; -} - -json create_receiver_config(config_fields_t& config) -{ - json sender = { - {"id", config.id}, - {"label", config.label}, - {"description", config.description}, - {"network", {{"primary", {{"interface_address", config.address}, {"interface_name", config.interface_name}}}}}, - {"capabilities", {"audio/L24"}}}; - return sender; -} - -std::string translate_video_format(const std::string& gst_format) -{ - static const std::unordered_map video_format_map = {{"UYVP", "YCbCr-4:2:2"}, - {"RGBA", "RGBA-8:8:8:8"}}; - - auto it = video_format_map.find(gst_format); - if(it != video_format_map.end()) - { - return it->second; - } - return gst_format; -} - -std::string translate_audio_format(const std::string& gst_format) -{ - static const std::unordered_map audio_format_map = {{"S24BE", "L24"}, {"S16LE", "L16"}}; - - auto it = audio_format_map.find(gst_format); - if(it != audio_format_map.end()) - { - return it->second; - } - return gst_format; -} - -expected load_configuration_from_file(std::string_view config_file) -{ - std::ifstream ifs(config_file.data()); - BST_ENFORCE(ifs.is_open(), "Failed opening file {}", config_file); - std::ostringstream buffer; - buffer << ifs.rdbuf(); - return parse_json(buffer.str()); -} - -std::string get_node_id(char* node_configuration_location) -{ - const auto configuration_result = load_configuration_from_file(node_configuration_location); - - const json& configuration = configuration_result.value(); - - auto node_result = find(configuration, "node"); - - const json& node = node_result.value(); - - auto node_id_result = find(node, "id"); - auto node_config_result = find(node, "configuration"); - - if(node_id_result.has_value() && node_config_result.has_value()) - { - const std::string node_id = node_id_result.value(); - const std::string node_configuration = node_config_result.value().dump(); - - return node_id; - } - - return ""; -} - -std::string get_node_config(std::string node_configuration_location) -{ - const auto configuration_result = load_configuration_from_file(node_configuration_location.c_str()); - - if(configuration_result.has_value()) - { - const json& configuration = configuration_result.value(); - - auto node_result = find(configuration, "node"); - - const json& node = node_result.value(); - - auto node_id_result = find(node, "id"); - auto node_config_result = find(node, "configuration"); - - if(node_id_result.has_value() && node_config_result.has_value()) - { - const std::string node_id = node_id_result.value(); - const std::string node_configuration = node_config_result.value().dump(); - - return node_configuration; - } - } - return ""; -} - -std::string get_device_id(char* device_configuration_location) -{ - const auto configuration_result = load_configuration_from_file(device_configuration_location); - - const json& configuration = configuration_result.value(); - - auto device_result = find(configuration, "device"); - - const json& device = device_result.value(); - - auto device_id_result = find(device, "id"); - - const std::string device_id = device_id_result.value(); - const std::string device_config = device.dump(); - - return device_id; -} - -std::string get_device_config(char* device_configuration_location) -{ - const auto configuration_result = load_configuration_from_file(device_configuration_location); - - const json& configuration = configuration_result.value(); - - auto device_result = find(configuration, "device"); - - const json& device = device_result.value(); - - auto device_id_result = find(device, "id"); - - const std::string device_id = device_id_result.value(); - const std::string device_config = device.dump(); - - return device_config; -} - -std::string get_sender_config(char* sender_configuration_location) -{ - // FIX ME: Gonna be hardcoded for now - const auto sender_config = load_configuration_from_file(sender_configuration_location); - - return sender_config.value().dump(); -} diff --git a/cpp/libs/gst_nmos_audio_receiver_plugin/utils.h b/cpp/libs/gst_nmos_audio_receiver_plugin/utils.h deleted file mode 100644 index b64513b..0000000 --- a/cpp/libs/gst_nmos_audio_receiver_plugin/utils.h +++ /dev/null @@ -1,116 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -typedef struct node_fields_t -{ - std::string id; - std::string configuration_location; -} node_fields_t; - -typedef struct device_fields_t -{ - std::string id; - std::string label; - std::string description; -} device_fields_t; - -typedef struct config_fields_t -{ - node_fields_t node; - device_fields_t device; - std::string id; - std::string label; - std::string description; - std::string address; - gint port; - std::string interface_name; -} config_fields_t; - -template class GstElementHandle -{ - public: - static std::variant create_element(const char* factory_name, - const char* element_name = nullptr) - { - T* elem = reinterpret_cast(gst_element_factory_make(factory_name, element_name)); - if(!elem) - { - return nullptr; - } - return GstElementHandle(elem); - } - - static std::variant create_bin(const char* bin_name) - { - T* bin = reinterpret_cast(gst_bin_new(bin_name)); - if(!bin) - { - return nullptr; - } - return GstElementHandle(bin); - } - - GstElementHandle(const GstElementHandle&) = delete; - GstElementHandle& operator=(const GstElementHandle&) = delete; - - // Move constructor - GstElementHandle(GstElementHandle&& other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; } - - // Move assignment - GstElementHandle& operator=(GstElementHandle&& other) noexcept - { - if(this != &other) - { - if(handle_ != nullptr) - { - gst_object_unref(handle_); - } - handle_ = other.handle_; - other.handle_ = nullptr; - } - return *this; - } - - ~GstElementHandle() - { - if(handle_) - { - gst_object_unref(handle_); - } - } - - void reset(T* new_ptr = nullptr) { handle_ = new_ptr; } - - T* get() const { return handle_; } - - explicit operator bool() const { return (handle_ != nullptr); } - - private: - explicit GstElementHandle(T* handle) : handle_(handle) {} - - T* handle_ = nullptr; -}; - -void create_default_config_fields(config_fields_t* config); - -nlohmann::json create_node_config(config_fields_t& config); -nlohmann::json create_device_config(config_fields_t& config); -nlohmann::json create_receiver_config(config_fields_t& config); - -std::string translate_video_format(const std::string& gst_format); - -std::string translate_audio_format(const std::string& gst_format); - -std::string get_node_id(char* node_configuration_location); - -std::string get_node_config(std::string node_configuration_location); - -std::string get_device_id(char* device_configuration_location); - -std::string get_device_config(char* device_configuration_location); - -std::string get_sender_config(char* sender_configuration_location); diff --git a/cpp/libs/gst_nmos_plugins/CMakeLists.txt b/cpp/libs/gst_nmos_plugins/CMakeLists.txt new file mode 100644 index 0000000..2c3304c --- /dev/null +++ b/cpp/libs/gst_nmos_plugins/CMakeLists.txt @@ -0,0 +1,99 @@ +cmake_minimum_required(VERSION 3.16) +project(gst_nmos_plugins LANGUAGES CXX) + +find_package(nlohmann_json REQUIRED) +find_package(PkgConfig REQUIRED) + +# Locate GLib package +pkg_check_modules(GLIB REQUIRED glib-2.0) + +# Locate GStreamer packages +pkg_search_module(GSTREAMER REQUIRED gstreamer-1.0>=1.4) +pkg_search_module(GSTREAMER_APP REQUIRED gstreamer-app-1.0>=1.4) +pkg_search_module(GSTREAMER_AUDIO REQUIRED gstreamer-audio-1.0>=1.4) +pkg_search_module(GSTREAMER_VIDEO REQUIRED gstreamer-video-1.0>=1.4) + +# Include the parent directory of gst_nmos_plugins +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) + +# Utils library (shared across plugins) +add_library(utils STATIC src/utils.cpp) + +# Enable -fPIC for utils +set_target_properties(utils PROPERTIES POSITION_INDEPENDENT_CODE ON) + +target_include_directories(utils + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/.. + PRIVATE ${GLIB_INCLUDE_DIRS} + PRIVATE ${GSTREAMER_INCLUDE_DIRS} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../bisect + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ossrf +) +target_link_libraries(utils + PUBLIC nlohmann_json::nlohmann_json + PRIVATE ${GLIB_LIBRARIES} + PRIVATE ${GSTREAMER_LIBRARIES} + PRIVATE ${GSTREAMER_APP_LIBRARIES} + PRIVATE ${GSTREAMER_AUDIO_LIBRARIES} + PRIVATE ${GSTREAMER_VIDEO_LIBRARIES} + PRIVATE bisect::project_warnings + PRIVATE bisect::expected + PRIVATE bisect::bisect_nmoscpp + PRIVATE bisect::bisect_json + PRIVATE ossrf::ossrf_nmos_api +) + +# Function to create a plugin target +function(create_plugin plugin_name plugin_sources output_name) + add_library(${plugin_name} MODULE ${plugin_sources}) + target_include_directories(${plugin_name} + PRIVATE ${GSTREAMER_INCLUDE_DIRS} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.. + PUBLIC $ + ) + target_link_libraries(${plugin_name} + PRIVATE + ${GSTREAMER_LIBRARIES} + ${GSTREAMER_APP_LIBRARIES} + ${GSTREAMER_AUDIO_LIBRARIES} + ${GSTREAMER_VIDEO_LIBRARIES} + utils + PUBLIC + bisect::project_warnings + bisect::expected + bisect::bisect_nmoscpp + bisect::bisect_json + nlohmann_json::nlohmann_json + ossrf::ossrf_nmos_api + ${GLIB_LIBRARIES} + ) + set_target_properties(${plugin_name} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins + OUTPUT_NAME ${output_name} + ) + add_library(ossrf::${plugin_name} ALIAS ${plugin_name}) + install(TARGETS ${plugin_name} + LIBRARY DESTINATION ~/.local/lib/gstreamer-1.0 + ) +endfunction() + +# Plugin: Video Receiver +create_plugin( + gst_nmos_video_receiver_plugin + src/gst_nmos_video_receiver_plugin.cpp + "gstnmosvideoreceiver" +) + +# Plugin: Audio Receiver +create_plugin( + gst_nmos_audio_receiver_plugin + src/gst_nmos_audio_receiver_plugin.cpp + "gstnmosaudioreceiver" +) + +# Plugin: Sender +create_plugin( + gst_nmos_sender_plugin + src/gst_nmos_sender_plugin.cpp + "gstnmossender" +) diff --git a/cpp/libs/gst_nmos_video_receiver_plugin/utils.h b/cpp/libs/gst_nmos_plugins/include/element_class.h similarity index 61% rename from cpp/libs/gst_nmos_video_receiver_plugin/utils.h rename to cpp/libs/gst_nmos_plugins/include/element_class.h index f3cb2a1..490b78f 100644 --- a/cpp/libs/gst_nmos_video_receiver_plugin/utils.h +++ b/cpp/libs/gst_nmos_plugins/include/element_class.h @@ -5,31 +5,6 @@ #include #include -typedef struct node_fields_t -{ - std::string id; - std::string configuration_location; -} node_fields_t; - -typedef struct device_fields_t -{ - std::string id; - std::string label; - std::string description; -} device_fields_t; - -typedef struct config_fields_t -{ - node_fields_t node; - device_fields_t device; - std::string id; - std::string label; - std::string description; - std::string address; - gint port; - std::string interface_name; -} config_fields_t; - template class GstElementHandle { public: @@ -97,23 +72,3 @@ template class GstElementHandle T* handle_ = nullptr; }; - -void create_default_config_fields(config_fields_t* config); - -nlohmann::json create_node_config(config_fields_t& config); -nlohmann::json create_device_config(config_fields_t& config); -nlohmann::json create_receiver_config(config_fields_t& config); - -std::string translate_video_format(const std::string& gst_format); - -std::string translate_audio_format(const std::string& gst_format); - -std::string get_node_id(char* node_configuration_location); - -std::string get_node_config(std::string node_configuration_location); - -std::string get_device_id(char* device_configuration_location); - -std::string get_device_config(char* device_configuration_location); - -std::string get_sender_config(char* sender_configuration_location); diff --git a/cpp/libs/gst_nmos_plugins/include/nmos_configuration.h b/cpp/libs/gst_nmos_plugins/include/nmos_configuration.h new file mode 100644 index 0000000..3f50d21 --- /dev/null +++ b/cpp/libs/gst_nmos_plugins/include/nmos_configuration.h @@ -0,0 +1,58 @@ +#pragma once +#include +#include + + +typedef struct node_fields_t +{ + std::string id; + std::string configuration_location; +} node_fields_t; + +typedef struct device_fields_t +{ + std::string id; + std::string label; + std::string description; +} device_fields_t; + +typedef struct video_media_fields_t +{ + gint width; + gint height; + gint frame_rate_num; + gint frame_rate_den; + std::string sampling; + std::string structure; +} video_media_fields_t; + +typedef struct audio_media_fields_t +{ + std::string format; + gint number_of_channels; + gint sampling_rate; + gint packet_time; +} audio_media_fields_t; + +typedef struct network_fields_t +{ + std::string source_address; + std::string interface_name; + std::string destination_address; + gint destination_port; +} network_fields_t; + +typedef struct config_fields_t +{ + node_fields_t node; + device_fields_t device; + gboolean is_audio; + video_media_fields_t video_media_fields; + audio_media_fields_t audio_sender_fields; + std::string id; + std::string label; + std::string description; + network_fields_t network; + std::string interface_name; + std::string address; +} config_fields_t; diff --git a/cpp/libs/gst_nmos_audio_receiver_plugin/gst_nmos_audio_receiver_plugin.cpp b/cpp/libs/gst_nmos_plugins/src/gst_nmos_audio_receiver_plugin.cpp similarity index 99% rename from cpp/libs/gst_nmos_audio_receiver_plugin/gst_nmos_audio_receiver_plugin.cpp rename to cpp/libs/gst_nmos_plugins/src/gst_nmos_audio_receiver_plugin.cpp index d821fbc..1589963 100644 --- a/cpp/libs/gst_nmos_audio_receiver_plugin/gst_nmos_audio_receiver_plugin.cpp +++ b/cpp/libs/gst_nmos_plugins/src/gst_nmos_audio_receiver_plugin.cpp @@ -27,6 +27,8 @@ #include "bisect/nmoscpp/configuration.h" #include "utils.h" #include "ossrf/nmos/api/nmos_client.h" +#include "../include/element_class.h" +#include "../include/nmos_configuration.h" #include #include @@ -469,7 +471,7 @@ static void gst_nmosaudioreceiver_init(GstNmosaudioreceiver* self) gst_object_unref(src_tmpl); gst_element_add_pad(GST_ELEMENT(self), ghost_src); - create_default_config_fields(&self->config); + create_default_config_fields_audio_receiver(&self->config); } static gboolean plugin_init(GstPlugin* plugin) diff --git a/cpp/libs/gst_nmos_sender_plugin/gst_nmos_sender_plugin.cpp b/cpp/libs/gst_nmos_plugins/src/gst_nmos_sender_plugin.cpp similarity index 97% rename from cpp/libs/gst_nmos_sender_plugin/gst_nmos_sender_plugin.cpp rename to cpp/libs/gst_nmos_plugins/src/gst_nmos_sender_plugin.cpp index 956a2d1..e6f280b 100644 --- a/cpp/libs/gst_nmos_sender_plugin/gst_nmos_sender_plugin.cpp +++ b/cpp/libs/gst_nmos_plugins/src/gst_nmos_sender_plugin.cpp @@ -23,6 +23,8 @@ #include "bisect/json.h" #include "utils.h" #include "ossrf/nmos/api/nmos_client.h" +#include "../include/element_class.h" +#include "../include/nmos_configuration.h" #include #include @@ -100,11 +102,11 @@ static void gst_nmossender_set_property(GObject* object, guint property_id, cons case PropertyId::DeviceDescription: self->config.device.description = g_value_dup_string(value); break; - case PropertyId::SenderId: self->config.sender_id = g_value_dup_string(value); break; + case PropertyId::SenderId: self->config.id = g_value_dup_string(value); break; - case PropertyId::SenderLabel: self->config.sender_label = g_value_dup_string(value); break; + case PropertyId::SenderLabel: self->config.label = g_value_dup_string(value); break; - case PropertyId::SenderDescription: self->config.sender_description = g_value_dup_string(value); break; + case PropertyId::SenderDescription: self->config.description = g_value_dup_string(value); break; case PropertyId::SourceAddress: self->config.network.source_address = g_value_dup_string(value); break; @@ -141,9 +143,9 @@ static void gst_nmossender_get_property(GObject* object, guint property_id, GVal case PropertyId::DeviceId: g_value_set_string(value, self->config.device.id.c_str()); break; case PropertyId::DeviceLabel: g_value_set_string(value, self->config.device.label.c_str()); break; case PropertyId::DeviceDescription: g_value_set_string(value, self->config.device.description.c_str()); break; - case PropertyId::SenderId: g_value_set_string(value, self->config.sender_id.c_str()); break; - case PropertyId::SenderLabel: g_value_set_string(value, self->config.sender_label.c_str()); break; - case PropertyId::SenderDescription: g_value_set_string(value, self->config.sender_description.c_str()); break; + case PropertyId::SenderId: g_value_set_string(value, self->config.id.c_str()); break; + case PropertyId::SenderLabel: g_value_set_string(value, self->config.label.c_str()); break; + case PropertyId::SenderDescription: g_value_set_string(value, self->config.description.c_str()); break; case PropertyId::SourceAddress: g_value_set_string(value, self->config.network.source_address.c_str()); break; case PropertyId::InterfaceName: g_value_set_string(value, self->config.network.interface_name.c_str()); break; case PropertyId::DestinationAddress: @@ -443,7 +445,7 @@ static void gst_nmossender_init(GstNmossender* self) // set properties g_object_set(G_OBJECT(self->queue.get()), "max-size-buffers", 1, nullptr); g_object_set(G_OBJECT(self->udpsink.get()), "host", "127.0.0.1", "port", 9999, nullptr); - create_default_config_fields(&self->config); + create_default_config_fields_sender(&self->config); gst_bin_add_many(GST_BIN(self), self->queue.get(), self->video_payloader.get(), self->audio_payloader_24.get(), self->audio_payloader_16.get(), self->udpsink.get(), nullptr); diff --git a/cpp/libs/gst_nmos_video_receiver_plugin/gst_nmos_video_receiver_plugin.cpp b/cpp/libs/gst_nmos_plugins/src/gst_nmos_video_receiver_plugin.cpp similarity index 99% rename from cpp/libs/gst_nmos_video_receiver_plugin/gst_nmos_video_receiver_plugin.cpp rename to cpp/libs/gst_nmos_plugins/src/gst_nmos_video_receiver_plugin.cpp index 0f77142..c2b715f 100644 --- a/cpp/libs/gst_nmos_video_receiver_plugin/gst_nmos_video_receiver_plugin.cpp +++ b/cpp/libs/gst_nmos_plugins/src/gst_nmos_video_receiver_plugin.cpp @@ -27,6 +27,8 @@ #include "bisect/nmoscpp/configuration.h" #include "utils.h" #include "ossrf/nmos/api/nmos_client.h" +#include "gst_nmos_plugins/include/element_class.h" +#include "gst_nmos_plugins/include/nmos_configuration.h" #include #include @@ -454,7 +456,7 @@ static void gst_nmosvideoreceiver_init(GstNmosvideoreceiver* self) gst_object_unref(src_tmpl); gst_element_add_pad(GST_ELEMENT(self), ghost_src); - create_default_config_fields(&self->config); + create_default_config_fields_video_receiver(&self->config); } static gboolean plugin_init(GstPlugin* plugin) diff --git a/cpp/libs/gst_nmos_sender_plugin/utils.cpp b/cpp/libs/gst_nmos_plugins/src/utils.cpp similarity index 70% rename from cpp/libs/gst_nmos_sender_plugin/utils.cpp rename to cpp/libs/gst_nmos_plugins/src/utils.cpp index 430769a..d8a9b0b 100644 --- a/cpp/libs/gst_nmos_sender_plugin/utils.cpp +++ b/cpp/libs/gst_nmos_plugins/src/utils.cpp @@ -4,12 +4,15 @@ #include "bisect/expected/macros.h" #include "bisect/expected.h" #include "bisect/json.h" +#include "gst_nmos_plugins/include/element_class.h" +#include "gst_nmos_plugins/include/nmos_configuration.h" #include using namespace bisect; using json = nlohmann::json; -void create_default_config_fields(config_fields_t* config) + +void create_default_config_fields_sender(config_fields_t* config) { if(!config) { @@ -48,19 +51,71 @@ void create_default_config_fields(config_fields_t* config) config->network.destination_port = 9999; // Initialize config_fields_t - config->sender_id = "1c920570-e0b4-4637-b02c-26c9d4275c71"; - config->sender_label = "BISECT OSSRF Media Sender"; - config->sender_description = "BISECT OSSRF Media Sender"; + config->id = "1c920570-e0b4-4637-b02c-26c9d4275c71"; + config->label = "BISECT OSSRF Media Sender"; + config->description = "BISECT OSSRF Media Sender"; } -json create_node_config(config_fields_t& config) +void create_default_config_fields_video_receiver(config_fields_t* config) { - const std::string node_config_str = get_node_config(config.node.configuration_location.data()); + if(!config) + { + g_critical("Config pointer is NULL"); + return; + } - if(node_config_str != "") + // Initialize node_fields_t + config->node.id = "d49c85db-1c33-4f21-b160-58edd2af1810"; + config->node.configuration_location = + "/home/nmos/repos/nmos-sender-receiver-framework/cpp/demos/config/nmos_plugin_node_config_receiver.json"; + + // Initialize device_fields_t + config->device.id = "1ad20d7c-8c58-4c84-8f14-3cf3e3af164c"; + config->device.label = "OSSRF Device2"; + config->device.description = "OSSRF Device2"; + + // Initialize config_fields_t + config->id = "db9f46cf-2414-4e25-b6c6-2078159857f9"; + config->label = "BISECT OSSRF Video Receiver"; + config->description = "BISECT OSSRF Video Receiver"; + config->interface_name = "wlp1s0"; + config->address = "192.168.1.36"; + config->is_audio = false; +} + +void create_default_config_fields_audio_receiver(config_fields_t* config) +{ + if(!config) { - json node_config = json::parse(node_config_str); + g_critical("Config pointer is NULL"); + return; + } + + // Initialize node_fields_t + config->node.id = "d1073007-4099-452f-b8e8-837b8987d845"; + config->node.configuration_location = + "/home/nmos/repos/nmos-sender-receiver-framework/cpp/demos/config/nmos_plugin_node_config_receiver.json"; + + // Initialize device_fields_t + config->device.id = "093a1c56-4033-49f7-9e17-fbcb21a19383"; + config->device.label = "OSSRF Device2"; + config->device.description = "OSSRF Device2"; + + // Initialize config_fields_t + config->id = "af600517-a452-4c2c-8b60-2caa770d6435"; + config->label = "BISECT OSSRF Audio Receiver"; + config->description = "BISECT OSSRF Audio Receiver"; + config->interface_name = "wlp1s0"; + config->address = "192.168.1.36"; + config->is_audio = true; +} +json create_node_config(config_fields_t& config) +{ + const std::string node_config_str = get_node_config(config.node.configuration_location); + if(node_config_str != "") + { + json node_config = json::parse(node_config_str); node_config["id"] = config.node.id; return node_config; @@ -78,63 +133,25 @@ json create_device_config(config_fields_t& config) return device; } -json create_video_sender_config(config_fields_t& config) -{ - json sender = { - {"id", config.sender_id}, - {"label", config.sender_label}, - {"description", config.sender_description}, - {"network", - {{"primary", - {{"source_address", config.network.source_address}, - {"interface_name", config.network.interface_name}, - {"destination_address", config.network.destination_address}, - {"destination_port", config.network.destination_port}}}}}, - {"payload_type", 97}, - {"media_type", "video/raw"}, - {"media", - {{"width", config.video_media_fields.width}, - {"height", config.video_media_fields.height}, - {"frame_rate", - {{"num", config.video_media_fields.frame_rate_num}, {"den", config.video_media_fields.frame_rate_den}}}, - {"sampling", config.video_media_fields.sampling}, - {"structure", config.video_media_fields.structure}}}}; - return sender; -} - -json create_audio_sender_config(config_fields_t& config) +json create_receiver_config(config_fields_t& config) { - std::string media_type = "audio/L16"; - if(config.audio_sender_fields.format == "S24BE") - { - media_type = "audio/L24"; + std::string caps = "video/raw"; + if(config.is_audio == true){ + caps = "audio/L24"; } - else if(config.audio_sender_fields.format == "S16BE") - { - media_type = "audio/L16"; - } - json sender = {{"id", config.sender_id}, - {"label", config.sender_label}, - {"description", config.sender_description}, - {"network", - {{"primary", - {{"source_address", config.network.source_address}, - {"interface_name", config.network.interface_name}, - {"destination_address", config.network.destination_address}, - {"destination_port", config.network.destination_port}}}}}, - {"payload_type", 97}, - {"media_type", media_type}, - {"media", - {{"number_of_channels", config.audio_sender_fields.number_of_channels}, - {"sampling_rate", config.audio_sender_fields.sampling_rate}, - {"packet_time", config.audio_sender_fields.packet_time}}}}; + json sender = { + {"id", config.id}, + {"label", config.label}, + {"description", config.description}, + {"network", {{"primary", {{"interface_address", config.address}, {"interface_name", config.interface_name}}}}}, + {"capabilities", {caps}}}; return sender; } std::string translate_video_format(const std::string& gst_format) { - static const std::unordered_map video_format_map = { - {"UYVP", "YCbCr-4:2:2"}, {"RGB", "RGB-8:8:8"}, {"RGBA", "RGBA-8:8:8:8"}}; + static const std::unordered_map video_format_map = {{"UYVP", "YCbCr-4:2:2"}, + {"RGBA", "RGBA-8:8:8:8"}}; auto it = video_format_map.find(gst_format); if(it != video_format_map.end()) @@ -189,9 +206,9 @@ std::string get_node_id(char* node_configuration_location) return ""; } -std::string get_node_config(char* node_configuration_location) +std::string get_node_config(std::string node_configuration_location) { - const auto configuration_result = load_configuration_from_file(node_configuration_location); + const auto configuration_result = load_configuration_from_file(node_configuration_location.c_str()); if(configuration_result.has_value()) { @@ -258,3 +275,57 @@ std::string get_sender_config(char* sender_configuration_location) return sender_config.value().dump(); } + + +json create_video_sender_config(config_fields_t& config) +{ + json sender = { + {"id", config.id}, + {"label", config.label}, + {"description", config.description}, + {"network", + {{"primary", + {{"source_address", config.network.source_address}, + {"interface_name", config.network.interface_name}, + {"destination_address", config.network.destination_address}, + {"destination_port", config.network.destination_port}}}}}, + {"payload_type", 97}, + {"media_type", "video/raw"}, + {"media", + {{"width", config.video_media_fields.width}, + {"height", config.video_media_fields.height}, + {"frame_rate", + {{"num", config.video_media_fields.frame_rate_num}, {"den", config.video_media_fields.frame_rate_den}}}, + {"sampling", config.video_media_fields.sampling}, + {"structure", config.video_media_fields.structure}}}}; + return sender; +} + +json create_audio_sender_config(config_fields_t& config) +{ + std::string media_type = "audio/L16"; + if(config.audio_sender_fields.format == "S24BE") + { + media_type = "audio/L24"; + } + else if(config.audio_sender_fields.format == "S16BE") + { + media_type = "audio/L16"; + } + json sender = {{"id", config.id}, + {"label", config.label}, + {"description", config.description}, + {"network", + {{"primary", + {{"source_address", config.network.source_address}, + {"interface_name", config.network.interface_name}, + {"destination_address", config.network.destination_address}, + {"destination_port", config.network.destination_port}}}}}, + {"payload_type", 97}, + {"media_type", media_type}, + {"media", + {{"number_of_channels", config.audio_sender_fields.number_of_channels}, + {"sampling_rate", config.audio_sender_fields.sampling_rate}, + {"packet_time", config.audio_sender_fields.packet_time}}}}; + return sender; +} diff --git a/cpp/libs/gst_nmos_plugins/src/utils.h b/cpp/libs/gst_nmos_plugins/src/utils.h new file mode 100644 index 0000000..425b4e6 --- /dev/null +++ b/cpp/libs/gst_nmos_plugins/src/utils.h @@ -0,0 +1,34 @@ +#pragma once +#include +#include +#include +#include +#include +#include "../include/element_class.h" +#include "../include/nmos_configuration.h" + +void create_default_config_fields_sender(config_fields_t* config); +void create_default_config_fields_video_receiver(config_fields_t* config); +void create_default_config_fields_audio_receiver(config_fields_t* config); + +nlohmann::json create_node_config(config_fields_t& config); +nlohmann::json create_device_config(config_fields_t& config); +nlohmann::json create_receiver_config(config_fields_t& config); + +std::string translate_video_format(const std::string& gst_format); + +std::string translate_audio_format(const std::string& gst_format); + +std::string get_node_id(char* node_configuration_location); + +std::string get_node_config(std::string node_configuration_location); + +std::string get_device_id(char* device_configuration_location); + +std::string get_device_config(char* device_configuration_location); + +std::string get_sender_config(char* sender_configuration_location); + +nlohmann::json create_video_sender_config(config_fields_t& config); + +nlohmann::json create_audio_sender_config(config_fields_t& config); diff --git a/cpp/libs/gst_nmos_sender_plugin/CMakeLists.txt b/cpp/libs/gst_nmos_sender_plugin/CMakeLists.txt deleted file mode 100644 index c51e312..0000000 --- a/cpp/libs/gst_nmos_sender_plugin/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -cmake_minimum_required(VERSION 3.16) -project(gst_nmos_sender_plugin LANGUAGES CXX) - -find_package(nlohmann_json REQUIRED) -find_package(PkgConfig REQUIRED) - -# Locate GLib package -pkg_check_modules(GLIB REQUIRED glib-2.0) - -# Locate GStreamer packages -pkg_search_module(GSTREAMER REQUIRED gstreamer-1.0>=1.4) -pkg_search_module(GSTREAMER_APP REQUIRED gstreamer-app-1.0>=1.4) -pkg_search_module(GSTREAMER_AUDIO REQUIRED gstreamer-audio-1.0>=1.4) -pkg_search_module(GSTREAMER_VIDEO REQUIRED gstreamer-video-1.0>=1.4) - -# Include GLib directories and link libraries -include_directories(${GLIB_INCLUDE_DIRS}) -link_directories(${GLIB_LIBRARY_DIRS}) -add_definitions(${GLIB_CFLAGS_OTHER}) - -# Include source files for gst_nmos_sender_plugin -file(GLOB_RECURSE PLUGIN_SOURCE_FILES *.cpp *.h) - -# Include source files for utils -file(GLOB_RECURSE UTILS_SOURCE_FILES utils/*.cpp utils/*.h) - -# Combine utils and plugin sources -set(SOURCE_FILES ${PLUGIN_SOURCE_FILES} ${UTILS_SOURCE_FILES}) - -# Define the plugin as a shared library -add_library(${PROJECT_NAME} MODULE ${SOURCE_FILES}) - -# Include directories -target_include_directories(${PROJECT_NAME} - PRIVATE ${GSTREAMER_INCLUDE_DIRS} - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/utils/include -) - -# Link GStreamer libraries -target_compile_options(${PROJECT_NAME} PRIVATE ${GSTREAMER_CFLAGS_OTHER}) -target_link_libraries(${PROJECT_NAME} - PRIVATE - ${GSTREAMER_LIBRARIES} - ${GSTREAMER_APP_LIBRARIES} - ${GSTREAMER_AUDIO_LIBRARIES} - ${GSTREAMER_VIDEO_LIBRARIES} - PUBLIC - bisect::project_warnings - bisect::expected - bisect::bisect_nmoscpp - bisect::bisect_json - nlohmann_json::nlohmann_json - ossrf::ossrf_nmos_api - ${GLIB_LIBRARIES} -) - -# Specify the output directory and the library name -set_target_properties(${PROJECT_NAME} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins - OUTPUT_NAME "gstnmossender" # Custom .so name -) - -add_library(ossrf::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) - -# Install the plugin to the system's GStreamer plugin directory -install(TARGETS ${PROJECT_NAME} - LIBRARY DESTINATION ~/.local/lib/gstreamer-1.0) diff --git a/cpp/libs/gst_nmos_sender_plugin/utils.h b/cpp/libs/gst_nmos_sender_plugin/utils.h deleted file mode 100644 index e3817b5..0000000 --- a/cpp/libs/gst_nmos_sender_plugin/utils.h +++ /dev/null @@ -1,151 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -typedef struct node_fields_t -{ - std::string id; - std::string configuration_location; -} node_fields_t; - -typedef struct device_fields_t -{ - std::string id; - std::string label; - std::string description; -} device_fields_t; - -typedef struct video_media_fields_t -{ - gint width; - gint height; - gint frame_rate_num; - gint frame_rate_den; - std::string sampling; - std::string structure; -} video_media_fields_t; - -typedef struct audio_media_fields_t -{ - std::string format; - gint number_of_channels; - gint sampling_rate; - gint packet_time; -} audio_media_fields_t; - -typedef struct network_fields_t -{ - std::string source_address; - std::string interface_name; - std::string destination_address; - gint destination_port; -} network_fields_t; - -typedef struct config_fields_t -{ - node_fields_t node; - device_fields_t device; - gboolean is_audio; - video_media_fields_t video_media_fields; - audio_media_fields_t audio_sender_fields; - std::string sender_id; - std::string sender_label; - std::string sender_description; - network_fields_t network; -} config_fields_t; - -template class GstElementHandle -{ - public: - static std::variant create_element(const char* factory_name, - const char* element_name = nullptr) - { - T* elem = reinterpret_cast(gst_element_factory_make(factory_name, element_name)); - if(!elem) - { - return nullptr; - } - return GstElementHandle(elem); - } - - static std::variant create_bin(const char* bin_name) - { - T* bin = reinterpret_cast(gst_bin_new(bin_name)); - if(!bin) - { - return nullptr; - } - return GstElementHandle(bin); - } - - GstElementHandle(const GstElementHandle&) = delete; - GstElementHandle& operator=(const GstElementHandle&) = delete; - - // Move constructor - GstElementHandle(GstElementHandle&& other) noexcept : handle_(other.handle_) { other.handle_ = nullptr; } - - // Move assignment - GstElementHandle& operator=(GstElementHandle&& other) noexcept - { - if(this != &other) - { - if(handle_ != nullptr) - { - gst_object_unref(handle_); - } - handle_ = other.handle_; - other.handle_ = nullptr; - } - return *this; - } - - ~GstElementHandle() - { - if(handle_) - { - gst_object_unref(handle_); - } - } - - void reset(T* new_ptr = nullptr) - { - if(handle_) - { - gst_object_unref(handle_); - } - handle_ = new_ptr; - } - - T* get() const { return handle_; } - - explicit operator bool() const { return (handle_ != nullptr); } - - private: - explicit GstElementHandle(T* handle) : handle_(handle) {} - - T* handle_ = nullptr; -}; - -void create_default_config_fields(config_fields_t* config); - -nlohmann::json create_node_config(config_fields_t& config); -nlohmann::json create_device_config(config_fields_t& config); -nlohmann::json create_video_sender_config(config_fields_t& config); -nlohmann::json create_audio_sender_config(config_fields_t& config); - -std::string translate_video_format(const std::string& gst_format); - -std::string translate_audio_format(const std::string& gst_format); - -std::string get_node_id(char* node_configuration_location); - -std::string get_node_config(char* node_configuration_location); - -std::string get_device_id(char* device_configuration_location); - -std::string get_device_config(char* device_configuration_location); - -std::string get_sender_config(char* sender_configuration_location); diff --git a/cpp/libs/gst_nmos_video_receiver_plugin/CMakeLists.txt b/cpp/libs/gst_nmos_video_receiver_plugin/CMakeLists.txt deleted file mode 100644 index ab5d707..0000000 --- a/cpp/libs/gst_nmos_video_receiver_plugin/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -cmake_minimum_required(VERSION 3.16) -project(gst_nmos_video_receiver_plugin LANGUAGES CXX) - -find_package(nlohmann_json REQUIRED) -find_package(PkgConfig REQUIRED) - -# Locate GLib package -pkg_check_modules(GLIB REQUIRED glib-2.0) - -# Locate GStreamer packages -pkg_search_module(GSTREAMER REQUIRED gstreamer-1.0>=1.4) -pkg_search_module(GSTREAMER_APP REQUIRED gstreamer-app-1.0>=1.4) -pkg_search_module(GSTREAMER_AUDIO REQUIRED gstreamer-audio-1.0>=1.4) -pkg_search_module(GSTREAMER_VIDEO REQUIRED gstreamer-video-1.0>=1.4) - -# Include GLib directories and link libraries -include_directories(${GLIB_INCLUDE_DIRS}) -link_directories(${GLIB_LIBRARY_DIRS}) -add_definitions(${GLIB_CFLAGS_OTHER}) - -# Include source files for gst_nmos_video_receiver_plugin -file(GLOB_RECURSE PLUGIN_SOURCE_FILES *.cpp *.h) - -# Include source files for utils -file(GLOB_RECURSE UTILS_SOURCE_FILES utils/*.cpp utils/*.h) - -# Combine utils and plugin sources -set(SOURCE_FILES ${PLUGIN_SOURCE_FILES} ${UTILS_SOURCE_FILES}) - -# Define the plugin as a shared library -add_library(${PROJECT_NAME} MODULE ${SOURCE_FILES}) - -# Include directories -target_include_directories(${PROJECT_NAME} - PRIVATE ${GSTREAMER_INCLUDE_DIRS} - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/utils/include -) - -# Link GStreamer libraries -target_compile_options(${PROJECT_NAME} PRIVATE ${GSTREAMER_CFLAGS_OTHER}) -target_link_libraries(${PROJECT_NAME} - PRIVATE - ${GSTREAMER_LIBRARIES} - ${GSTREAMER_APP_LIBRARIES} - ${GSTREAMER_AUDIO_LIBRARIES} - ${GSTREAMER_VIDEO_LIBRARIES} - PUBLIC - bisect::project_warnings - bisect::expected - bisect::bisect_nmoscpp - bisect::bisect_json - nlohmann_json::nlohmann_json - ossrf::ossrf_nmos_api - ${GLIB_LIBRARIES} -) - -# Specify the output directory and the library name -set_target_properties(${PROJECT_NAME} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins - OUTPUT_NAME "gstnmosvideoreceiver" -) - -add_library(ossrf::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) - -# Install the plugin to the system's GStreamer plugin directory -install(TARGETS ${PROJECT_NAME} - LIBRARY DESTINATION ~/.local/lib/gstreamer-1.0) diff --git a/cpp/libs/gst_nmos_video_receiver_plugin/utils.cpp b/cpp/libs/gst_nmos_video_receiver_plugin/utils.cpp deleted file mode 100644 index 76d5bb9..0000000 --- a/cpp/libs/gst_nmos_video_receiver_plugin/utils.cpp +++ /dev/null @@ -1,198 +0,0 @@ -#include "utils.h" -#include "ossrf/nmos/api/nmos_client.h" -#include "bisect/nmoscpp/configuration.h" -#include "bisect/expected/macros.h" -#include "bisect/expected.h" -#include "bisect/json.h" -#include - -using namespace bisect; -using json = nlohmann::json; - -void create_default_config_fields(config_fields_t* config) -{ - if(!config) - { - g_critical("Config pointer is NULL"); - return; - } - - // Initialize node_fields_t - config->node.id = "d49c85db-1c33-4f21-b160-58edd2af1810"; - config->node.configuration_location = - "/home/nmos/repos/nmos-sender-receiver-framework/cpp/demos/config/nmos_plugin_node_config_receiver.json"; - - // Initialize device_fields_t - config->device.id = "1ad20d7c-8c58-4c84-8f14-3cf3e3af164c"; - config->device.label = "OSSRF Device2"; - config->device.description = "OSSRF Device2"; - - // Initialize config_fields_t - config->id = "db9f46cf-2414-4e25-b6c6-2078159857f9"; - config->label = "BISECT OSSRF Video Receiver"; - config->description = "BISECT OSSRF Video Receiver"; - config->interface_name = "wlp1s0"; - config->address = "192.168.1.36"; -} - -json create_node_config(config_fields_t& config) -{ - const std::string node_config_str = get_node_config(config.node.configuration_location); - if(node_config_str != "") - { - json node_config = json::parse(node_config_str); - node_config["id"] = config.node.id; - - return node_config; - } - else - { - return nullptr; - } -} - -json create_device_config(config_fields_t& config) -{ - json device = { - {"id", config.device.id}, {"label", config.device.label}, {"description", config.device.description}}; - return device; -} - -json create_receiver_config(config_fields_t& config) -{ - json sender = { - {"id", config.id}, - {"label", config.label}, - {"description", config.description}, - {"network", {{"primary", {{"interface_address", config.address}, {"interface_name", config.interface_name}}}}}, - {"capabilities", {"video/raw"}}}; - return sender; -} - -std::string translate_video_format(const std::string& gst_format) -{ - static const std::unordered_map video_format_map = {{"UYVP", "YCbCr-4:2:2"}, - {"RGBA", "RGBA-8:8:8:8"}}; - - auto it = video_format_map.find(gst_format); - if(it != video_format_map.end()) - { - return it->second; - } - return gst_format; -} - -std::string translate_audio_format(const std::string& gst_format) -{ - static const std::unordered_map audio_format_map = {{"S24BE", "L24"}, {"S16LE", "L16"}}; - - auto it = audio_format_map.find(gst_format); - if(it != audio_format_map.end()) - { - return it->second; - } - return gst_format; -} - -expected load_configuration_from_file(std::string_view config_file) -{ - std::ifstream ifs(config_file.data()); - BST_ENFORCE(ifs.is_open(), "Failed opening file {}", config_file); - std::ostringstream buffer; - buffer << ifs.rdbuf(); - return parse_json(buffer.str()); -} - -std::string get_node_id(char* node_configuration_location) -{ - const auto configuration_result = load_configuration_from_file(node_configuration_location); - - const json& configuration = configuration_result.value(); - - auto node_result = find(configuration, "node"); - - const json& node = node_result.value(); - - auto node_id_result = find(node, "id"); - auto node_config_result = find(node, "configuration"); - - if(node_id_result.has_value() && node_config_result.has_value()) - { - const std::string node_id = node_id_result.value(); - const std::string node_configuration = node_config_result.value().dump(); - - return node_id; - } - - return ""; -} - -std::string get_node_config(std::string node_configuration_location) -{ - const auto configuration_result = load_configuration_from_file(node_configuration_location.c_str()); - - if(configuration_result.has_value()) - { - const json& configuration = configuration_result.value(); - - auto node_result = find(configuration, "node"); - - const json& node = node_result.value(); - - auto node_id_result = find(node, "id"); - auto node_config_result = find(node, "configuration"); - - if(node_id_result.has_value() && node_config_result.has_value()) - { - const std::string node_id = node_id_result.value(); - const std::string node_configuration = node_config_result.value().dump(); - - return node_configuration; - } - } - return ""; -} - -std::string get_device_id(char* device_configuration_location) -{ - const auto configuration_result = load_configuration_from_file(device_configuration_location); - - const json& configuration = configuration_result.value(); - - auto device_result = find(configuration, "device"); - - const json& device = device_result.value(); - - auto device_id_result = find(device, "id"); - - const std::string device_id = device_id_result.value(); - const std::string device_config = device.dump(); - - return device_id; -} - -std::string get_device_config(char* device_configuration_location) -{ - const auto configuration_result = load_configuration_from_file(device_configuration_location); - - const json& configuration = configuration_result.value(); - - auto device_result = find(configuration, "device"); - - const json& device = device_result.value(); - - auto device_id_result = find(device, "id"); - - const std::string device_id = device_id_result.value(); - const std::string device_config = device.dump(); - - return device_config; -} - -std::string get_sender_config(char* sender_configuration_location) -{ - // FIX ME: Gonna be hardcoded for now - const auto sender_config = load_configuration_from_file(sender_configuration_location); - - return sender_config.value().dump(); -}