gstreamer/subprojects/gst-examples/webrtc/sendrecv/gst/custom_agent.c
Philippe Normand 906b90287c webrtcbin: Relay add-ice-candidate errors from Ice implementation to Application
The `add_candidate` vfunc of the GstWebRTCICE interface gained a GstPromise
argument, which is an ABI break. We're not aware of any external user of this
interface yet so we think it's OK.

This change is useful in cases where the application needs to bubble up errors
from the underlying ICE agent, for instance when the agent was given an invalid
ICE candidate.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3960>
2023-02-27 09:09:47 +00:00

170 lines
5.6 KiB
C

#include "custom_agent.h"
#include <gst/webrtc/nice/nice.h>
struct _CustomICEAgent
{
GstWebRTCICE parent;
GstWebRTCNice *nice_agent;
};
/* *INDENT-OFF* */
G_DEFINE_TYPE (CustomICEAgent, customice_agent, GST_TYPE_WEBRTC_ICE)
/* *INDENT-ON* */
GstWebRTCICEStream *
customice_agent_add_stream (GstWebRTCICE * ice, guint session_id)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
return gst_webrtc_ice_add_stream (c_ice, session_id);
}
GstWebRTCICETransport *
customice_agent_find_transport (GstWebRTCICE * ice,
GstWebRTCICEStream * stream, GstWebRTCICEComponent component)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
return gst_webrtc_ice_find_transport (c_ice, stream, component);
}
void
customice_agent_add_candidate (GstWebRTCICE * ice,
GstWebRTCICEStream * stream, const gchar * candidate, GstPromise * promise)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
gst_webrtc_ice_add_candidate (c_ice, stream, candidate, promise);
}
gboolean
customice_agent_set_remote_credentials (GstWebRTCICE * ice,
GstWebRTCICEStream * stream, const gchar * ufrag, const gchar * pwd)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
return gst_webrtc_ice_set_remote_credentials (c_ice, stream, ufrag, pwd);
}
gboolean
customice_agent_add_turn_server (GstWebRTCICE * ice, const gchar * uri)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
return gst_webrtc_ice_add_turn_server (c_ice, uri);
}
gboolean
customice_agent_set_local_credentials (GstWebRTCICE * ice,
GstWebRTCICEStream * stream, const gchar * ufrag, const gchar * pwd)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
return gst_webrtc_ice_set_local_credentials (c_ice, stream, ufrag, pwd);
}
gboolean
customice_agent_gather_candidates (GstWebRTCICE * ice,
GstWebRTCICEStream * stream)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
return gst_webrtc_ice_gather_candidates (c_ice, stream);
}
void
customice_agent_set_is_controller (GstWebRTCICE * ice, gboolean controller)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
gst_webrtc_ice_set_is_controller (c_ice, controller);
}
gboolean
customice_agent_get_is_controller (GstWebRTCICE * ice)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
return gst_webrtc_ice_get_is_controller (c_ice);
}
void
customice_agent_set_force_relay (GstWebRTCICE * ice, gboolean force_relay)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
gst_webrtc_ice_set_force_relay (c_ice, force_relay);
}
void
customice_agent_set_tos (GstWebRTCICE * ice, GstWebRTCICEStream * stream,
guint tos)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
gst_webrtc_ice_set_tos (c_ice, stream, tos);
}
void
customice_agent_set_on_ice_candidate (GstWebRTCICE * ice,
GstWebRTCICEOnCandidateFunc func, gpointer user_data, GDestroyNotify notify)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
gst_webrtc_ice_set_on_ice_candidate (c_ice, func, user_data, notify);
}
void
customice_agent_set_stun_server (GstWebRTCICE * ice, const gchar * uri_s)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
gst_webrtc_ice_set_stun_server (c_ice, uri_s);
}
gchar *
customice_agent_get_stun_server (GstWebRTCICE * ice)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
return gst_webrtc_ice_get_stun_server (c_ice);
}
void
customice_agent_set_turn_server (GstWebRTCICE * ice, const gchar * uri_s)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
gst_webrtc_ice_set_turn_server (c_ice, uri_s);
}
gchar *
customice_agent_get_turn_server (GstWebRTCICE * ice)
{
GstWebRTCICE *c_ice = GST_WEBRTC_ICE (CUSTOMICE_AGENT (ice)->nice_agent);
return gst_webrtc_ice_get_turn_server (c_ice);
}
static void
customice_agent_class_init (CustomICEAgentClass * klass)
{
GstWebRTCICEClass *gst_webrtc_ice_class = GST_WEBRTC_ICE_CLASS (klass);
// override virtual functions
gst_webrtc_ice_class->add_candidate = customice_agent_add_candidate;
gst_webrtc_ice_class->add_stream = customice_agent_add_stream;
gst_webrtc_ice_class->add_turn_server = customice_agent_add_turn_server;
gst_webrtc_ice_class->find_transport = customice_agent_find_transport;
gst_webrtc_ice_class->gather_candidates = customice_agent_gather_candidates;
gst_webrtc_ice_class->get_is_controller = customice_agent_get_is_controller;
gst_webrtc_ice_class->get_stun_server = customice_agent_get_stun_server;
gst_webrtc_ice_class->get_turn_server = customice_agent_get_turn_server;
gst_webrtc_ice_class->set_force_relay = customice_agent_set_force_relay;
gst_webrtc_ice_class->set_is_controller = customice_agent_set_is_controller;
gst_webrtc_ice_class->set_local_credentials =
customice_agent_set_local_credentials;
gst_webrtc_ice_class->set_remote_credentials =
customice_agent_set_remote_credentials;
gst_webrtc_ice_class->set_stun_server = customice_agent_set_stun_server;
gst_webrtc_ice_class->set_tos = customice_agent_set_tos;
gst_webrtc_ice_class->set_turn_server = customice_agent_set_turn_server;
gst_webrtc_ice_class->set_on_ice_candidate =
customice_agent_set_on_ice_candidate;
}
static void
customice_agent_init (CustomICEAgent * ice)
{
ice->nice_agent = gst_webrtc_nice_new ("nice_agent");
}
CustomICEAgent *
customice_agent_new (const gchar * name)
{
return g_object_new (GST_TYPE_WEBRTC_NICE, "name", name, NULL);
}