Skip to content

Commit

Permalink
Merge pull request #8 from AMWA-TV/jf/dev/add_payload_type_sdp
Browse files Browse the repository at this point in the history
Sender gives the payload type when building the SDP
  • Loading branch information
joaofigueiredobisect authored Sep 18, 2024
2 parents 0825389 + 673ed06 commit 5e41bc9
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

namespace bisect::nmoscpp
{
struct sdp_info_t
{
uint8_t payload_type;
float packet_time;
};

class nmos_event_handler_t
{
public:
Expand All @@ -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<sdp_info_t> handle_sdp_info_request(const nmos::id& sender_id) = 0;
};

} // namespace bisect::nmoscpp
19 changes: 10 additions & 9 deletions cpp/libs/bisect_nmoscpp/lib/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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});

Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<sdp_info_t> 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();
}
3 changes: 3 additions & 0 deletions cpp/libs/ossrf_nmos_api/lib/src/context/nmos_event_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace ossrf
const nmos::resource& connection_resource,
const std::string& endpoint_staged) override;

[[nodiscard]] bisect::expected<bisect::nmoscpp::sdp_info_t>
handle_sdp_info_request(const nmos::id& resource_id) override;

private:
nmos_context_ptr const context_;
};
Expand Down
3 changes: 3 additions & 0 deletions cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "bisect/expected.h"
#include "bisect/nmoscpp/nmos_event_handler.h"
#include <nlohmann/json_fwd.hpp>
#include <nmos/id.h>
#include <string>
Expand All @@ -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<bisect::nmoscpp::sdp_info_t> handle_sdp_info_request() = 0;

[[nodiscard]] virtual const std::string& get_id() const = 0;

[[nodiscard]] virtual const std::string& get_device_id() const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ maybe_ok nmos_resource_receiver_t::handle_activation(bool master_enable, json& t
return {};
}

expected<sdp_info_t> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<bisect::nmoscpp::sdp_info_t> handle_sdp_info_request() override;

const std::string& get_id() const override;

const std::string& get_device_id() const override;
Expand Down
45 changes: 45 additions & 0 deletions cpp/libs/ossrf_nmos_api/lib/src/resources/nmos_resource_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,46 @@
#include "bisect/sdp/media_types.h"
#include "../serialization/sender.h"
#include <nmos/id.h>
#include <nmos/sdp_utils.h>

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
Expand Down Expand Up @@ -54,6 +84,21 @@ maybe_ok nmos_resource_sender_t::handle_patch(bool master_enable, const json& co
return {};
}

expected<sdp_info_t> 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<audio_sender_info_t>(config_.media);
info.packet_time = audio.packet_time;
}

return info;
};

nmos::type nmos_resource_sender_t::get_resource_type() const
{
return nmos::types::sender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include "bisect/expected/macros.h"
#include "nmos_resource.h"
#include "bisect/nmoscpp/configuration.h"
#include <functional>
Expand All @@ -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<bisect::nmoscpp::sdp_info_t> handle_sdp_info_request() override;

const std::string& get_id() const override;

const std::string& get_device_id() const override;
Expand Down

0 comments on commit 5e41bc9

Please sign in to comment.