Skip to content

Commit

Permalink
nmosvideoreceiver:Timeout detection, .h files to .hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
LufeBisect committed Jan 28, 2025
1 parent 6be94e7 commit b61ddee
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ template <typename T = GstElement> class GstElementHandle
const char* element_name = nullptr)
{
T* elem = reinterpret_cast<T*>(gst_element_factory_make(factory_name, element_name));
if(!elem)
if(elem == nullptr)
{
return nullptr;
}
Expand All @@ -32,10 +32,8 @@ template <typename T = GstElement> class GstElementHandle
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)
Expand All @@ -58,15 +56,14 @@ template <typename T = GstElement> class GstElementHandle
}
}

/// Destruction of this object will no longer unref the owned element.
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) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@
#include <string>
#include <glib.h>

typedef struct node_fields_t
struct node_fields_t
{
std::string id;
std::string configuration_location;
} node_fields_t;
};

typedef struct device_fields_t
struct device_fields_t
{
std::string id;
std::string label;
std::string description;
} device_fields_t;
};

typedef struct video_media_fields_t
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
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
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
struct config_fields_t
{
node_fields_t node;
device_fields_t device;
Expand All @@ -54,4 +54,4 @@ typedef struct config_fields_t
network_fields_t network;
std::string interface_name;
std::string address;
} config_fields_t;
};
117 changes: 49 additions & 68 deletions cpp/libs/gst_nmos_plugins/src/gst_nmos_audio_receiver_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#include "bisect/sdp.h"
#include "bisect/sdp/reader.h"
#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 "utils.hpp"
#include "../include/element_class.hpp"
#include "../include/nmos_configuration.hpp"
#include <gst/gst.h>
#include <gst/gstpad.h>

Expand Down Expand Up @@ -99,23 +99,15 @@ static void gst_nmosaudioreceiver_set_property(GObject* object, guint property_i
switch(static_cast<PropertyId>(property_id))
{
case PropertyId::NodeId: self->config.node.id = g_value_dup_string(value); break;

case PropertyId::NodeConfigFileLocation:
self->config.node.configuration_location = g_value_dup_string(value);
break;

case PropertyId::DeviceId: self->config.device.id = g_value_dup_string(value); break;

case PropertyId::DeviceLabel: self->config.device.label = g_value_dup_string(value); break;

case PropertyId::DeviceDescription: self->config.device.description = g_value_dup_string(value); break;

case PropertyId::ReceiverId: self->config.id = g_value_dup_string(value); break;

case PropertyId::ReceiverLabel: self->config.label = g_value_dup_string(value); break;

case PropertyId::ReceiverDescription: self->config.description = g_value_dup_string(value); break;

case PropertyId::DstAddress: self->config.address = g_value_dup_string(value); break;

default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); break;
Expand All @@ -128,7 +120,6 @@ static void gst_nmosaudioreceiver_get_property(GObject* object, guint property_i

switch(static_cast<PropertyId>(property_id))
{

case PropertyId::NodeId: g_value_set_string(value, self->config.node.id.c_str()); break;
case PropertyId::NodeConfigFileLocation:
g_value_set_string(value, self->config.node.configuration_location.c_str());
Expand Down Expand Up @@ -157,10 +148,10 @@ void remove_old_bin(GstNmosaudioreceiver* self)
return;
}
gulong block_id =
gst_pad_add_probe(self->element_pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, block_pad_probe_cb, NULL, NULL);
gst_pad_add_probe(self->element_pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, block_pad_probe_cb, nullptr, nullptr);

gst_element_send_event(GST_ELEMENT(self), gst_event_new_flush_start());
gst_element_send_event(GST_ELEMENT(self), gst_event_new_flush_stop(FALSE));
gst_element_send_event(GST_ELEMENT(self), gst_event_new_flush_stop(false));

self->clock = gst_element_get_clock(GST_ELEMENT(self));

Expand Down Expand Up @@ -245,8 +236,8 @@ void construct_pipeline(GstNmosaudioreceiver* self)

g_object_set(G_OBJECT(self->udp_src.get()), "caps", caps, nullptr);

g_object_set(G_OBJECT(self->rtp_jitter_buffer.get()), "do-retransmission", true, "do-lost", true, "mode", 0,
"latency", 0, nullptr);
g_object_set(G_OBJECT(self->rtp_jitter_buffer.get()), "do-lost", false, "do-retransmission", false, "mode", 0,
"latency", 10, nullptr);

g_object_set(G_OBJECT(self->queue.get()), "max-size-buffers", 3, nullptr);

Expand All @@ -263,14 +254,12 @@ void construct_pipeline(GstNmosaudioreceiver* self)

if(audio_info.bits_per_sample == 16)
{

if(gst_element_link_many(self->udp_src.get(), self->rtp_jitter_buffer.get(), self->queue.get(),
self->rtp_audio_depay_16.get(), nullptr) == false)
{
GST_ERROR_OBJECT(self, "Failed to link elements inside the bin.");
return;
}

// Create a ghost pad from the depay's src
bin_src_pad = gst_element_get_static_pad(self->rtp_audio_depay_16.get(), "src");
if(bin_src_pad == nullptr)
Expand Down Expand Up @@ -323,7 +312,6 @@ void construct_pipeline(GstNmosaudioreceiver* self)
GST_ERROR_OBJECT(self, "Failed to link plugin ghost pad to bin's ghost pad.");
return;
}

gst_object_unref(plugin_pad);
}
catch(std::bad_variant_access const& ex)
Expand Down Expand Up @@ -356,53 +344,47 @@ void create_nmos(GstNmosaudioreceiver* self)

// Add device and receiver configurations
self->client->add_device(create_device_config(self->config).dump());
self->client->add_receiver(
self->config.device.id, create_receiver_config(self->config).dump(),
[self](const std::optional<std::string>& sdp, bool master_enabled) {
fmt::print("Receiver Activation Callback: SDP={}, Master Enabled={}\n",
sdp.has_value() ? sdp.value() : "None", master_enabled);

if(master_enabled)
{
if(sdp)
{
fmt::print("Received SDP: {}\n", sdp.value());
auto sdp_settings = parse_sdp(sdp.value());
if(sdp_settings.has_value() && sdp.value() != self->sdp_string)
{
self->sdp_settings = sdp_settings.value();
self->sdp_string = sdp.value();
remove_old_bin(self);
construct_pipeline(self);
auto time = gst_element_get_base_time(GST_ELEMENT(self));
gst_element_set_state(GST_ELEMENT(self), GST_STATE_PLAYING);
gst_pad_set_offset(self->bin_pad, static_cast<long>(gst_clock_get_time(self->clock) - time));
}
}
else if(!sdp && self->sdp_string != "")
{
fmt::print("No new SDP provided, enabling master pipeline.\n");
remove_old_bin(self);
construct_pipeline(self);
auto time = gst_element_get_base_time(GST_ELEMENT(self));
gst_element_set_state(GST_ELEMENT(self), GST_STATE_PLAYING);
gst_pad_set_offset(self->bin_pad, static_cast<long>(gst_clock_get_time(self->clock) - time));
}
}
else
{
if(sdp)
{
fmt::print("Disabling master: SDP received but master is not enabled.\n");
remove_old_bin(self);
}
else
{
fmt::print("Master not enabled and no SDP provided.\n");
}
}
fmt::print("Master enabled: {}\n", master_enabled);
});
self->client->add_receiver(self->config.device.id, create_receiver_config(self->config).dump(),
[self](const std::optional<std::string>& sdp, bool master_enabled) {
fmt::print("Receiver Activation Callback: SDP={}, Master Enabled={}\n",
sdp.has_value() ? sdp.value() : "None", master_enabled);
if(master_enabled)
{
if(sdp)
{
fmt::print("Received SDP: {}\n", sdp.value());
auto sdp_settings = parse_sdp(sdp.value());
if(sdp_settings.has_value() && sdp.value() != self->sdp_string)
{
self->sdp_settings = sdp_settings.value();
self->sdp_string = sdp.value();
remove_old_bin(self);
construct_pipeline(self);
gst_element_set_state(GST_ELEMENT(self), GST_STATE_PLAYING);
}
}
else if(!sdp && self->sdp_string != "")
{
fmt::print("No new SDP provided, enabling master pipeline.\n");
remove_old_bin(self);
construct_pipeline(self);
gst_element_set_state(GST_ELEMENT(self), GST_STATE_PLAYING);
}
}
else
{
if(sdp)
{
fmt::print("Disabling master: SDP received but master is not enabled.\n");
remove_old_bin(self);
}
else
{
fmt::print("Master not enabled and no SDP provided.\n");
}
}
fmt::print("Master enabled: {}\n", master_enabled);
});

GST_INFO_OBJECT(self, "NMOS client initialized successfully.");
}
Expand All @@ -411,7 +393,6 @@ static GstStateChangeReturn gst_nmosaudioreceiver_change_state(GstElement* eleme
{
GstStateChangeReturn ret;
GstNmosaudioreceiver* self = GST_NMOSAUDIORECEIVER(element);

switch(transition)
{
case GST_STATE_CHANGE_NULL_TO_READY: {
Expand Down Expand Up @@ -491,7 +472,7 @@ static gboolean plugin_init(GstPlugin* plugin)
return gst_element_register(plugin, "nmosaudioreceiver", GST_RANK_NONE, GST_TYPE_NMOSAUDIORECEIVER);
}

#define VERSION "0.1"
#define VERSION "1.0"
#define PACKAGE "gst-nmos-audio-receiver-plugin"
#define PACKAGE_NAME "AMWA NMOS Sender and Receiver Framework Plugins"
#define GST_PACKAGE_ORIGIN "https://www.amwa.tv/"
Expand Down
Loading

0 comments on commit b61ddee

Please sign in to comment.