From 673ed068afd5751c8661b22ff9d358c9e46e0ea5 Mon Sep 17 00:00:00 2001 From: Joao Figueiredo Date: Tue, 17 Sep 2024 16:36:22 +0000 Subject: [PATCH] Sender gives the payload type when building the SDP --- .../bisect/nmoscpp/nmos_event_handler.h | 9 +++- cpp/libs/bisect_nmoscpp/lib/src/utils.cpp | 19 ++++---- .../lib/src/context/nmos_event_handler.cpp | 6 +++ .../lib/src/context/nmos_event_handler.h | 3 ++ .../lib/src/resources/nmos_resource.h | 3 ++ .../src/resources/nmos_resource_receiver.cpp | 5 +++ .../src/resources/nmos_resource_receiver.h | 2 + .../src/resources/nmos_resource_sender.cpp | 45 +++++++++++++++++++ .../lib/src/resources/nmos_resource_sender.h | 3 ++ 9 files changed, 85 insertions(+), 10 deletions(-) diff --git a/cpp/libs/bisect_nmoscpp/lib/include/bisect/nmoscpp/nmos_event_handler.h b/cpp/libs/bisect_nmoscpp/lib/include/bisect/nmoscpp/nmos_event_handler.h index 2c56d65..f7cb350 100644 --- a/cpp/libs/bisect_nmoscpp/lib/include/bisect/nmoscpp/nmos_event_handler.h +++ b/cpp/libs/bisect_nmoscpp/lib/include/bisect/nmoscpp/nmos_event_handler.h @@ -18,6 +18,12 @@ namespace bisect::nmoscpp { + struct sdp_info_t + { + uint8_t payload_type; + float packet_time; + }; + class nmos_event_handler_t { public: @@ -29,7 +35,8 @@ namespace bisect::nmoscpp [[nodiscard]] virtual maybe_ok handle_patch_request(const nmos::resource& resource, const nmos::resource& connection_resource, - const std::string& endpoint_staged) = 0; + const std::string& endpoint_staged) = 0; + [[nodiscard]] virtual bisect::expected handle_sdp_info_request(const nmos::id& sender_id) = 0; }; } // namespace bisect::nmoscpp diff --git a/cpp/libs/bisect_nmoscpp/lib/src/utils.cpp b/cpp/libs/bisect_nmoscpp/lib/src/utils.cpp index 1c91d79..01362b6 100644 --- a/cpp/libs/bisect_nmoscpp/lib/src/utils.cpp +++ b/cpp/libs/bisect_nmoscpp/lib/src/utils.cpp @@ -199,6 +199,8 @@ bisect::maybe_ok bisect::nmoscpp::build_transport_file(const nmos::resources& no fmt::print("setting transportfile for {}\n", utility::us2s(sender.id)); + BST_ASSIGN(info, event_handler->handle_sdp_info_request(sender.id)); + const auto node_id = nmos::find_self_resource(node_resources)->id.c_str(); const auto node = nmos::find_resource(node_resources, {node_id, nmos::types::node}); @@ -223,25 +225,24 @@ bisect::maybe_ok bisect::nmoscpp::build_transport_file(const nmos::resources& no const nmos::format format{nmos::fields::format(flow->data)}; if(nmos::formats::video == format) { - return nmos::make_video_sdp_parameters(node->data, source->data, flow->data, sender.data, 97, mids, {}, - conan_sdp::type_parameters::type_N); + return nmos::make_video_sdp_parameters(node->data, source->data, flow->data, sender.data, info.payload_type, + mids, {}, conan_sdp::type_parameters::type_N); } else if(nmos::formats::audio == format) { const double packet_time = nmos::fields::channels(source->data).size() > 8 ? 0.125 : 1; - return nmos::make_audio_sdp_parameters(node->data, source->data, flow->data, sender.data, - nmos::details::payload_type_audio_default, mids, {}, packet_time); + return nmos::make_audio_sdp_parameters(node->data, source->data, flow->data, sender.data, info.payload_type, + mids, {}, packet_time); } else if(nmos::formats::data == format) { - return nmos::make_data_sdp_parameters(node->data, source->data, flow->data, sender.data, - nmos::details::payload_type_data_default, mids, {}, {}); + return nmos::make_data_sdp_parameters(node->data, source->data, flow->data, sender.data, info.payload_type, + mids, {}, {}); } else if(nmos::formats::mux == format) { - return nmos::make_mux_sdp_parameters(node->data, source->data, flow->data, sender.data, - nmos::details::payload_type_mux_default, mids, {}, - conan_sdp::type_parameters::type_N); + return nmos::make_mux_sdp_parameters(node->data, source->data, flow->data, sender.data, info.payload_type, + mids, {}, conan_sdp::type_parameters::type_N); } else { diff --git a/cpp/libs/ossrf_nmos_api/lib/src/context/nmos_event_handler.cpp b/cpp/libs/ossrf_nmos_api/lib/src/context/nmos_event_handler.cpp index a7c3113..d20b721 100644 --- a/cpp/libs/ossrf_nmos_api/lib/src/context/nmos_event_handler.cpp +++ b/cpp/libs/ossrf_nmos_api/lib/src/context/nmos_event_handler.cpp @@ -56,3 +56,9 @@ maybe_ok nmos_event_handler::handle_patch_request(const nmos::resource& resource BST_CHECK(r->handle_patch(master_enable, json::parse(endpoint_staged))); return {}; } + +expected nmos_event_handler::handle_sdp_info_request(const nmos::id& resource_id) +{ + BST_ASSIGN(r, context_->resources().find_resource(resource_id)); + return r->handle_sdp_info_request(); +} diff --git a/cpp/libs/ossrf_nmos_api/lib/src/context/nmos_event_handler.h b/cpp/libs/ossrf_nmos_api/lib/src/context/nmos_event_handler.h index eabeb0f..a1defd9 100644 --- a/cpp/libs/ossrf_nmos_api/lib/src/context/nmos_event_handler.h +++ b/cpp/libs/ossrf_nmos_api/lib/src/context/nmos_event_handler.h @@ -31,6 +31,9 @@ namespace ossrf const nmos::resource& connection_resource, const std::string& endpoint_staged) override; + [[nodiscard]] bisect::expected + handle_sdp_info_request(const nmos::id& resource_id) override; + private: nmos_context_ptr const context_; }; diff --git a/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource.h b/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource.h index c9a97ad..89aa20e 100644 --- a/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource.h +++ b/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource.h @@ -15,6 +15,7 @@ #pragma once #include "bisect/expected.h" +#include "bisect/nmoscpp/nmos_event_handler.h" #include #include #include @@ -33,6 +34,8 @@ namespace ossrf [[nodiscard]] virtual bisect::maybe_ok handle_activation(bool master_enable, nlohmann::json& transport_params) = 0; + [[nodiscard]] virtual bisect::expected handle_sdp_info_request() = 0; + [[nodiscard]] virtual const std::string& get_id() const = 0; [[nodiscard]] virtual const std::string& get_device_id() const = 0; diff --git a/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_receiver.cpp b/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_receiver.cpp index 55927f9..b56bf3c 100644 --- a/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_receiver.cpp +++ b/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_receiver.cpp @@ -119,6 +119,11 @@ maybe_ok nmos_resource_receiver_t::handle_activation(bool master_enable, json& t return {}; } +expected nmos_resource_receiver_t::handle_sdp_info_request() +{ + return sdp_info_t{}; +}; + nmos::type nmos_resource_receiver_t::get_resource_type() const { return nmos::types::receiver; diff --git a/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_receiver.h b/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_receiver.h index 265c514..536c99f 100644 --- a/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_receiver.h +++ b/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_receiver.h @@ -30,6 +30,8 @@ namespace ossrf bisect::maybe_ok handle_activation(bool master_enable, nlohmann::json& transport_params) override; bisect::maybe_ok handle_patch(bool master_enable, const nlohmann::json& configuration) override; + bisect::expected handle_sdp_info_request() override; + const std::string& get_id() const override; const std::string& get_device_id() const override; diff --git a/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_sender.cpp b/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_sender.cpp index 7442af0..fa95506 100644 --- a/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_sender.cpp +++ b/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_sender.cpp @@ -16,16 +16,46 @@ #include "bisect/sdp/media_types.h" #include "../serialization/sender.h" #include +#include using namespace ossrf; using namespace bisect; using namespace bisect::nmoscpp; +using namespace bisect::sdp; using json = nlohmann::json; +namespace +{ + uint8_t get_default_pt(nmos::format format) + { + if(nmos::formats::video == format) + { + return nmos::details::payload_type_video_default; + } + else if(nmos::formats::audio == format) + { + return nmos::details::payload_type_audio_default; + } + else if(nmos::formats::data == format) + { + return nmos::details::payload_type_data_default; + } + else if(nmos::formats::mux == format) + { + return nmos::details::payload_type_mux_default; + } + else + { + throw std::logic_error("unexpected flow format"); + } + } +} // namespace + nmos_resource_sender_t::nmos_resource_sender_t(const std::string& device_id, const nmos_sender_t& config, sender_activation_callback_t callback) : config_(config), activation_callback_(callback), device_id_(device_id) { + sdp_ = config_.forced_sdp; } const std::string& nmos_resource_sender_t::get_device_id() const @@ -54,6 +84,21 @@ maybe_ok nmos_resource_sender_t::handle_patch(bool master_enable, const json& co return {}; } +expected nmos_resource_sender_t::handle_sdp_info_request() +{ + sdp_info_t info{}; + + info.payload_type = config_.payload_type.value_or(get_default_pt(config_.format)); + + if(config_.media_type == media_types::AUDIO_L24) + { + const auto& audio = std::get(config_.media); + info.packet_time = audio.packet_time; + } + + return info; +}; + nmos::type nmos_resource_sender_t::get_resource_type() const { return nmos::types::sender; diff --git a/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_sender.h b/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_sender.h index 34eb153..2f65bfe 100644 --- a/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_sender.h +++ b/cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_sender.h @@ -14,6 +14,7 @@ #pragma once +#include "bisect/expected/macros.h" #include "nmos_resource.h" #include "bisect/nmoscpp/configuration.h" #include @@ -30,6 +31,8 @@ namespace ossrf bisect::maybe_ok handle_activation(bool master_enable, nlohmann::json& transport_params) override; bisect::maybe_ok handle_patch(bool master_enable, const nlohmann::json& configuration) override; + bisect::expected handle_sdp_info_request() override; + const std::string& get_id() const override; const std::string& get_device_id() const override;