mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-01 14:11:15 +00:00
srt: Move cancellable into srtobject
Should produce no difference in behavior. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4087>
This commit is contained in:
parent
4cede7c472
commit
3f75836822
6 changed files with 74 additions and 88 deletions
|
@ -192,7 +192,7 @@ static gint srt_init_refcount = 0;
|
||||||
|
|
||||||
static GSocketAddress *
|
static GSocketAddress *
|
||||||
gst_srt_object_resolve (GstSRTObject * srtobject, const gchar * address,
|
gst_srt_object_resolve (GstSRTObject * srtobject, const gchar * address,
|
||||||
guint port, GCancellable * cancellable, GError ** err_out)
|
guint port, GError ** err_out)
|
||||||
{
|
{
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
GSocketAddress *saddr;
|
GSocketAddress *saddr;
|
||||||
|
@ -205,7 +205,9 @@ gst_srt_object_resolve (GstSRTObject * srtobject, const gchar * address,
|
||||||
GST_DEBUG_OBJECT (srtobject->element, "resolving IP address for host %s",
|
GST_DEBUG_OBJECT (srtobject->element, "resolving IP address for host %s",
|
||||||
address);
|
address);
|
||||||
resolver = g_resolver_get_default ();
|
resolver = g_resolver_get_default ();
|
||||||
results = g_resolver_lookup_by_name (resolver, address, cancellable, &err);
|
results =
|
||||||
|
g_resolver_lookup_by_name (resolver, address, srtobject->cancellable,
|
||||||
|
&err);
|
||||||
if (!results)
|
if (!results)
|
||||||
goto name_resolve;
|
goto name_resolve;
|
||||||
|
|
||||||
|
@ -347,6 +349,7 @@ gst_srt_object_new (GstElement * element)
|
||||||
|
|
||||||
srtobject = g_new0 (GstSRTObject, 1);
|
srtobject = g_new0 (GstSRTObject, 1);
|
||||||
srtobject->element = element;
|
srtobject->element = element;
|
||||||
|
srtobject->cancellable = g_cancellable_new ();
|
||||||
srtobject->parameters = gst_structure_new_empty ("application/x-srt-params");
|
srtobject->parameters = gst_structure_new_empty ("application/x-srt-params");
|
||||||
srtobject->sock = SRT_INVALID_SOCK;
|
srtobject->sock = SRT_INVALID_SOCK;
|
||||||
srtobject->poll_id = srt_epoll_create ();
|
srtobject->poll_id = srt_epoll_create ();
|
||||||
|
@ -382,6 +385,7 @@ gst_srt_object_destroy (GstSRTObject * srtobject)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_pointer (&srtobject->uri, gst_uri_unref);
|
g_clear_pointer (&srtobject->uri, gst_uri_unref);
|
||||||
|
g_clear_object (&srtobject->cancellable);
|
||||||
|
|
||||||
g_free (srtobject);
|
g_free (srtobject);
|
||||||
}
|
}
|
||||||
|
@ -1069,8 +1073,8 @@ reject:
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_srt_object_wait_connect (GstSRTObject * srtobject,
|
gst_srt_object_wait_connect (GstSRTObject * srtobject, gpointer sa,
|
||||||
GCancellable * cancellable, gpointer sa, size_t sa_len, GError ** error)
|
size_t sa_len, GError ** error)
|
||||||
{
|
{
|
||||||
SRTSOCKET sock = SRT_INVALID_SOCK;
|
SRTSOCKET sock = SRT_INVALID_SOCK;
|
||||||
const gchar *local_address = NULL;
|
const gchar *local_address = NULL;
|
||||||
|
@ -1093,8 +1097,7 @@ gst_srt_object_wait_connect (GstSRTObject * srtobject,
|
||||||
GST_OBJECT_UNLOCK (srtobject->element);
|
GST_OBJECT_UNLOCK (srtobject->element);
|
||||||
|
|
||||||
bind_addr =
|
bind_addr =
|
||||||
gst_srt_object_resolve (srtobject, local_address, local_port, cancellable,
|
gst_srt_object_resolve (srtobject, local_address, local_port, error);
|
||||||
error);
|
|
||||||
if (!bind_addr) {
|
if (!bind_addr) {
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
@ -1180,7 +1183,7 @@ failed:
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_srt_object_connect (GstSRTObject * srtobject, GCancellable * cancellable,
|
gst_srt_object_connect (GstSRTObject * srtobject,
|
||||||
GstSRTConnectionMode connection_mode, gpointer sa, size_t sa_len,
|
GstSRTConnectionMode connection_mode, gpointer sa, size_t sa_len,
|
||||||
GError ** error)
|
GError ** error)
|
||||||
{
|
{
|
||||||
|
@ -1242,8 +1245,7 @@ gst_srt_object_connect (GstSRTObject * srtobject, GCancellable * cancellable,
|
||||||
gsize bind_sa_len;
|
gsize bind_sa_len;
|
||||||
|
|
||||||
GSocketAddress *bind_addr =
|
GSocketAddress *bind_addr =
|
||||||
gst_srt_object_resolve (srtobject, local_address,
|
gst_srt_object_resolve (srtobject, local_address, local_port, error);
|
||||||
local_port, cancellable, error);
|
|
||||||
|
|
||||||
if (!bind_addr) {
|
if (!bind_addr) {
|
||||||
goto failed;
|
goto failed;
|
||||||
|
@ -1294,26 +1296,23 @@ failed:
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_srt_object_open_connection (GstSRTObject * srtobject,
|
gst_srt_object_open_connection (GstSRTObject * srtobject,
|
||||||
GCancellable * cancellable, GstSRTConnectionMode connection_mode,
|
GstSRTConnectionMode connection_mode, gpointer sa, size_t sa_len,
|
||||||
gpointer sa, size_t sa_len, GError ** error)
|
GError ** error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
if (connection_mode == GST_SRT_CONNECTION_MODE_LISTENER) {
|
if (connection_mode == GST_SRT_CONNECTION_MODE_LISTENER) {
|
||||||
ret =
|
ret = gst_srt_object_wait_connect (srtobject, sa, sa_len, error);
|
||||||
gst_srt_object_wait_connect (srtobject, cancellable, sa, sa_len, error);
|
|
||||||
} else {
|
} else {
|
||||||
ret =
|
ret =
|
||||||
gst_srt_object_connect (srtobject, cancellable, connection_mode, sa,
|
gst_srt_object_connect (srtobject, connection_mode, sa, sa_len, error);
|
||||||
sa_len, error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_srt_object_open_internal (GstSRTObject * srtobject,
|
gst_srt_object_open_internal (GstSRTObject * srtobject, GError ** error)
|
||||||
GCancellable * cancellable, GError ** error)
|
|
||||||
{
|
{
|
||||||
GSocketAddress *socket_address = NULL;
|
GSocketAddress *socket_address = NULL;
|
||||||
GstSRTConnectionMode connection_mode;
|
GstSRTConnectionMode connection_mode;
|
||||||
|
@ -1352,8 +1351,7 @@ gst_srt_object_open_internal (GstSRTObject * srtobject,
|
||||||
|
|
||||||
GST_OBJECT_UNLOCK (srtobject->element);
|
GST_OBJECT_UNLOCK (srtobject->element);
|
||||||
|
|
||||||
socket_address =
|
socket_address = gst_srt_object_resolve (srtobject, addr_str, port, error);
|
||||||
gst_srt_object_resolve (srtobject, addr_str, port, cancellable, error);
|
|
||||||
if (socket_address == NULL) {
|
if (socket_address == NULL) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -1368,8 +1366,8 @@ gst_srt_object_open_internal (GstSRTObject * srtobject,
|
||||||
srtobject->listener_poll_id = srt_epoll_create ();
|
srtobject->listener_poll_id = srt_epoll_create ();
|
||||||
|
|
||||||
ret =
|
ret =
|
||||||
gst_srt_object_open_connection
|
gst_srt_object_open_connection (srtobject, connection_mode, sa, sa_len,
|
||||||
(srtobject, cancellable, connection_mode, sa, sa_len, error);
|
error);
|
||||||
|
|
||||||
GST_OBJECT_LOCK (srtobject->element);
|
GST_OBJECT_LOCK (srtobject->element);
|
||||||
srtobject->opened = ret;
|
srtobject->opened = ret;
|
||||||
|
@ -1382,12 +1380,11 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gst_srt_object_open (GstSRTObject * srtobject, GCancellable * cancellable,
|
gst_srt_object_open (GstSRTObject * srtobject, GError ** error)
|
||||||
GError ** error)
|
|
||||||
{
|
{
|
||||||
srtobject->bytes = 0;
|
srtobject->bytes = 0;
|
||||||
|
|
||||||
return gst_srt_object_open_internal (srtobject, cancellable, error);
|
return gst_srt_object_open_internal (srtobject, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1443,8 +1440,7 @@ gst_srt_object_close (GstSRTObject * srtobject)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_srt_object_wait_caller (GstSRTObject * srtobject,
|
gst_srt_object_wait_caller (GstSRTObject * srtobject)
|
||||||
GCancellable * cancellable)
|
|
||||||
{
|
{
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
|
||||||
|
@ -1453,7 +1449,7 @@ gst_srt_object_wait_caller (GstSRTObject * srtobject,
|
||||||
ret = (srtobject->callers != NULL);
|
ret = (srtobject->callers != NULL);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
GST_INFO_OBJECT (srtobject->element, "Waiting for connection");
|
GST_INFO_OBJECT (srtobject->element, "Waiting for connection");
|
||||||
while (!ret && !g_cancellable_is_cancelled (cancellable)) {
|
while (!ret && !g_cancellable_is_cancelled (srtobject->cancellable)) {
|
||||||
g_cond_wait (&srtobject->sock_cond, &srtobject->sock_lock);
|
g_cond_wait (&srtobject->sock_cond, &srtobject->sock_lock);
|
||||||
ret = (srtobject->callers != NULL);
|
ret = (srtobject->callers != NULL);
|
||||||
}
|
}
|
||||||
|
@ -1469,9 +1465,8 @@ gst_srt_object_wait_caller (GstSRTObject * srtobject,
|
||||||
}
|
}
|
||||||
|
|
||||||
gssize
|
gssize
|
||||||
gst_srt_object_read (GstSRTObject * srtobject,
|
gst_srt_object_read (GstSRTObject * srtobject, guint8 * data, gsize size,
|
||||||
guint8 * data, gsize size, GCancellable * cancellable, GError ** error,
|
GError ** error, SRT_MSGCTRL * mctrl)
|
||||||
SRT_MSGCTRL * mctrl)
|
|
||||||
{
|
{
|
||||||
gssize len = 0;
|
gssize len = 0;
|
||||||
gint poll_timeout;
|
gint poll_timeout;
|
||||||
|
@ -1498,7 +1493,7 @@ gst_srt_object_read (GstSRTObject * srtobject,
|
||||||
GST_OBJECT_UNLOCK (srtobject->element);
|
GST_OBJECT_UNLOCK (srtobject->element);
|
||||||
|
|
||||||
if (connection_mode == GST_SRT_CONNECTION_MODE_LISTENER) {
|
if (connection_mode == GST_SRT_CONNECTION_MODE_LISTENER) {
|
||||||
if (!gst_srt_object_wait_caller (srtobject, cancellable))
|
if (!gst_srt_object_wait_caller (srtobject))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
g_mutex_lock (&srtobject->sock_lock);
|
g_mutex_lock (&srtobject->sock_lock);
|
||||||
|
@ -1514,7 +1509,7 @@ gst_srt_object_read (GstSRTObject * srtobject,
|
||||||
poll_id = srtobject->poll_id;
|
poll_id = srtobject->poll_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!g_cancellable_is_cancelled (cancellable)) {
|
while (!g_cancellable_is_cancelled (srtobject->cancellable)) {
|
||||||
|
|
||||||
SRTSOCKET rsock;
|
SRTSOCKET rsock;
|
||||||
gint rsocklen = 1;
|
gint rsocklen = 1;
|
||||||
|
@ -1526,7 +1521,8 @@ gst_srt_object_read (GstSRTObject * srtobject,
|
||||||
gint srt_errno = srt_getlasterror (NULL);
|
gint srt_errno = srt_getlasterror (NULL);
|
||||||
|
|
||||||
#if SRT_VERSION_VALUE >= 0x010402
|
#if SRT_VERSION_VALUE >= 0x010402
|
||||||
if (srt_errno == SRT_EPOLLEMPTY && g_cancellable_is_cancelled (cancellable))
|
if (srt_errno == SRT_EPOLLEMPTY
|
||||||
|
&& g_cancellable_is_cancelled (srtobject->cancellable))
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1578,7 +1574,7 @@ gst_srt_object_read (GstSRTObject * srtobject,
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_srt_object_close (srtobject);
|
gst_srt_object_close (srtobject);
|
||||||
if (!gst_srt_object_open_internal (srtobject, cancellable, error)) {
|
if (!gst_srt_object_open_internal (srtobject, error)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -1607,7 +1603,7 @@ gst_srt_object_read (GstSRTObject * srtobject,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_srt_object_wakeup (GstSRTObject * srtobject, GCancellable * cancellable)
|
gst_srt_object_unlock (GstSRTObject * srtobject)
|
||||||
{
|
{
|
||||||
GST_DEBUG_OBJECT (srtobject->element, "waking up SRT");
|
GST_DEBUG_OBJECT (srtobject->element, "waking up SRT");
|
||||||
|
|
||||||
|
@ -1623,15 +1619,20 @@ gst_srt_object_wakeup (GstSRTObject * srtobject, GCancellable * cancellable)
|
||||||
/* however, a race might be harmful ...
|
/* however, a race might be harmful ...
|
||||||
* the cancellation is used as 'flushing' flag here,
|
* the cancellation is used as 'flushing' flag here,
|
||||||
* so make sure it is so detected by the intended part at proper time */
|
* so make sure it is so detected by the intended part at proper time */
|
||||||
g_cancellable_cancel (cancellable);
|
g_cancellable_cancel (srtobject->cancellable);
|
||||||
g_cond_signal (&srtobject->sock_cond);
|
g_cond_signal (&srtobject->sock_cond);
|
||||||
g_mutex_unlock (&srtobject->sock_lock);
|
g_mutex_unlock (&srtobject->sock_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_srt_object_unlock_stop (GstSRTObject * srtobject)
|
||||||
|
{
|
||||||
|
g_cancellable_reset (srtobject->cancellable);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_srt_object_send_headers (GstSRTObject * srtobject, SRTSOCKET sock,
|
gst_srt_object_send_headers (GstSRTObject * srtobject, SRTSOCKET sock,
|
||||||
gint poll_id, gint poll_timeout, GstBufferList * headers,
|
gint poll_id, gint poll_timeout, GstBufferList * headers, GError ** error)
|
||||||
GCancellable * cancellable, GError ** error)
|
|
||||||
{
|
{
|
||||||
guint size, i;
|
guint size, i;
|
||||||
|
|
||||||
|
@ -1650,7 +1651,7 @@ gst_srt_object_send_headers (GstSRTObject * srtobject, SRTSOCKET sock,
|
||||||
GstBuffer *buffer = gst_buffer_list_get (headers, i);
|
GstBuffer *buffer = gst_buffer_list_get (headers, i);
|
||||||
GstMapInfo mapinfo;
|
GstMapInfo mapinfo;
|
||||||
|
|
||||||
if (g_cancellable_is_cancelled (cancellable)) {
|
if (g_cancellable_is_cancelled (srtobject->cancellable)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1659,7 +1660,8 @@ gst_srt_object_send_headers (GstSRTObject * srtobject, SRTSOCKET sock,
|
||||||
gint srt_errno = srt_getlasterror (NULL);
|
gint srt_errno = srt_getlasterror (NULL);
|
||||||
|
|
||||||
#if SRT_VERSION_VALUE >= 0x010402
|
#if SRT_VERSION_VALUE >= 0x010402
|
||||||
if (srt_errno == SRT_EPOLLEMPTY && g_cancellable_is_cancelled (cancellable))
|
if (srt_errno == SRT_EPOLLEMPTY
|
||||||
|
&& g_cancellable_is_cancelled (srtobject->cancellable))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1698,8 +1700,7 @@ gst_srt_object_send_headers (GstSRTObject * srtobject, SRTSOCKET sock,
|
||||||
|
|
||||||
static gssize
|
static gssize
|
||||||
gst_srt_object_write_to_callers (GstSRTObject * srtobject,
|
gst_srt_object_write_to_callers (GstSRTObject * srtobject,
|
||||||
GstBufferList * headers,
|
GstBufferList * headers, const GstMapInfo * mapinfo)
|
||||||
const GstMapInfo * mapinfo, GCancellable * cancellable)
|
|
||||||
{
|
{
|
||||||
GList *item, *next;
|
GList *item, *next;
|
||||||
|
|
||||||
|
@ -1713,18 +1714,18 @@ gst_srt_object_write_to_callers (GstSRTObject * srtobject,
|
||||||
|
|
||||||
next = item->next;
|
next = item->next;
|
||||||
|
|
||||||
if (g_cancellable_is_cancelled (cancellable)) {
|
if (g_cancellable_is_cancelled (srtobject->cancellable)) {
|
||||||
goto cancelled;
|
goto cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!caller->sent_headers) {
|
if (!caller->sent_headers) {
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!gst_srt_object_send_headers (srtobject, caller->sock, -1, 0,
|
if (!gst_srt_object_send_headers (srtobject, caller->sock, -1, 0, headers,
|
||||||
headers, cancellable, &error)) {
|
&error)) {
|
||||||
GST_WARNING_OBJECT (srtobject->element,
|
GST_WARNING_OBJECT (srtobject->element,
|
||||||
"Failed to send headers to caller %d: %s",
|
"Failed to send headers to caller %d: %s", caller->sock,
|
||||||
caller->sock, error->message);
|
error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@ -1767,9 +1768,8 @@ cancelled:
|
||||||
}
|
}
|
||||||
|
|
||||||
static gssize
|
static gssize
|
||||||
gst_srt_object_write_one (GstSRTObject * srtobject,
|
gst_srt_object_write_one (GstSRTObject * srtobject, GstBufferList * headers,
|
||||||
GstBufferList * headers,
|
const GstMapInfo * mapinfo, GError ** error)
|
||||||
const GstMapInfo * mapinfo, GCancellable * cancellable, GError ** error)
|
|
||||||
{
|
{
|
||||||
gssize len = 0;
|
gssize len = 0;
|
||||||
gint poll_timeout;
|
gint poll_timeout;
|
||||||
|
@ -1789,7 +1789,7 @@ gst_srt_object_write_one (GstSRTObject * srtobject,
|
||||||
|
|
||||||
if (!srtobject->sent_headers) {
|
if (!srtobject->sent_headers) {
|
||||||
if (!gst_srt_object_send_headers (srtobject, srtobject->sock,
|
if (!gst_srt_object_send_headers (srtobject, srtobject->sock,
|
||||||
srtobject->poll_id, poll_timeout, headers, cancellable, error)) {
|
srtobject->poll_id, poll_timeout, headers, error)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1805,7 +1805,7 @@ gst_srt_object_write_one (GstSRTObject * srtobject,
|
||||||
gint sent;
|
gint sent;
|
||||||
gint rest;
|
gint rest;
|
||||||
|
|
||||||
if (g_cancellable_is_cancelled (cancellable)) {
|
if (g_cancellable_is_cancelled (srtobject->cancellable)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1821,7 +1821,8 @@ gst_srt_object_write_one (GstSRTObject * srtobject,
|
||||||
gint srt_errno = srt_getlasterror (NULL);
|
gint srt_errno = srt_getlasterror (NULL);
|
||||||
|
|
||||||
#if SRT_VERSION_VALUE >= 0x010402
|
#if SRT_VERSION_VALUE >= 0x010402
|
||||||
if (srt_errno == SRT_EPOLLEMPTY && g_cancellable_is_cancelled (cancellable))
|
if (srt_errno == SRT_EPOLLEMPTY
|
||||||
|
&& g_cancellable_is_cancelled (srtobject->cancellable))
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1861,7 +1862,7 @@ gst_srt_object_write_one (GstSRTObject * srtobject,
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_srt_object_close (srtobject);
|
gst_srt_object_close (srtobject);
|
||||||
if (!gst_srt_object_open_internal (srtobject, cancellable, error)) {
|
if (!gst_srt_object_open_internal (srtobject, error)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -1889,9 +1890,8 @@ gst_srt_object_write_one (GstSRTObject * srtobject,
|
||||||
}
|
}
|
||||||
|
|
||||||
gssize
|
gssize
|
||||||
gst_srt_object_write (GstSRTObject * srtobject,
|
gst_srt_object_write (GstSRTObject * srtobject, GstBufferList * headers,
|
||||||
GstBufferList * headers,
|
const GstMapInfo * mapinfo, GError ** error)
|
||||||
const GstMapInfo * mapinfo, GCancellable * cancellable, GError ** error)
|
|
||||||
{
|
{
|
||||||
gssize len = 0;
|
gssize len = 0;
|
||||||
GstSRTConnectionMode connection_mode = GST_SRT_CONNECTION_MODE_NONE;
|
GstSRTConnectionMode connection_mode = GST_SRT_CONNECTION_MODE_NONE;
|
||||||
|
@ -1909,16 +1909,12 @@ gst_srt_object_write (GstSRTObject * srtobject,
|
||||||
|
|
||||||
if (connection_mode == GST_SRT_CONNECTION_MODE_LISTENER) {
|
if (connection_mode == GST_SRT_CONNECTION_MODE_LISTENER) {
|
||||||
if (wait_for_connection) {
|
if (wait_for_connection) {
|
||||||
if (!gst_srt_object_wait_caller (srtobject, cancellable))
|
if (!gst_srt_object_wait_caller (srtobject))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
len =
|
len = gst_srt_object_write_to_callers (srtobject, headers, mapinfo);
|
||||||
gst_srt_object_write_to_callers (srtobject, headers, mapinfo,
|
|
||||||
cancellable);
|
|
||||||
} else {
|
} else {
|
||||||
len =
|
len = gst_srt_object_write_one (srtobject, headers, mapinfo, error);
|
||||||
gst_srt_object_write_one (srtobject, headers, mapinfo, cancellable,
|
|
||||||
error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|
|
@ -49,6 +49,7 @@ typedef struct _GstSRTObject GstSRTObject;
|
||||||
struct _GstSRTObject
|
struct _GstSRTObject
|
||||||
{
|
{
|
||||||
GstElement *element;
|
GstElement *element;
|
||||||
|
GCancellable *cancellable;
|
||||||
GstUri *uri;
|
GstUri *uri;
|
||||||
|
|
||||||
GstStructure *parameters;
|
GstStructure *parameters;
|
||||||
|
@ -82,7 +83,6 @@ GstSRTObject *gst_srt_object_new (GstElement *element);
|
||||||
void gst_srt_object_destroy (GstSRTObject *srtobject);
|
void gst_srt_object_destroy (GstSRTObject *srtobject);
|
||||||
|
|
||||||
gboolean gst_srt_object_open (GstSRTObject *srtobject,
|
gboolean gst_srt_object_open (GstSRTObject *srtobject,
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
void gst_srt_object_close (GstSRTObject *srtobject);
|
void gst_srt_object_close (GstSRTObject *srtobject);
|
||||||
|
@ -101,18 +101,16 @@ gboolean gst_srt_object_set_uri (GstSRTObject * srtobject, const gchar *u
|
||||||
|
|
||||||
gssize gst_srt_object_read (GstSRTObject * srtobject,
|
gssize gst_srt_object_read (GstSRTObject * srtobject,
|
||||||
guint8 *data, gsize size,
|
guint8 *data, gsize size,
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **err,
|
GError **err,
|
||||||
SRT_MSGCTRL *mctrl);
|
SRT_MSGCTRL *mctrl);
|
||||||
|
|
||||||
gssize gst_srt_object_write (GstSRTObject * srtobject,
|
gssize gst_srt_object_write (GstSRTObject * srtobject,
|
||||||
GstBufferList * headers,
|
GstBufferList * headers,
|
||||||
const GstMapInfo * mapinfo,
|
const GstMapInfo * mapinfo,
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **err);
|
GError **err);
|
||||||
|
|
||||||
void gst_srt_object_wakeup (GstSRTObject * srtobject,
|
void gst_srt_object_unlock (GstSRTObject * srtobject);
|
||||||
GCancellable *cancellable);
|
void gst_srt_object_unlock_stop (GstSRTObject * srtobject);
|
||||||
|
|
||||||
GstStructure *gst_srt_object_get_stats (GstSRTObject * srtobject);
|
GstStructure *gst_srt_object_get_stats (GstSRTObject * srtobject);
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,6 @@ gst_srt_sink_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
GstSRTSink *self = GST_SRT_SINK (object);
|
GstSRTSink *self = GST_SRT_SINK (object);
|
||||||
|
|
||||||
g_clear_object (&self->cancellable);
|
|
||||||
gst_srt_object_destroy (self->srtobject);
|
gst_srt_object_destroy (self->srtobject);
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
|
@ -140,8 +139,6 @@ static void
|
||||||
gst_srt_sink_init (GstSRTSink * self)
|
gst_srt_sink_init (GstSRTSink * self)
|
||||||
{
|
{
|
||||||
self->srtobject = gst_srt_object_new (GST_ELEMENT (self));
|
self->srtobject = gst_srt_object_new (GST_ELEMENT (self));
|
||||||
self->cancellable = g_cancellable_new ();
|
|
||||||
|
|
||||||
gst_srt_object_set_uri (self->srtobject, GST_SRT_DEFAULT_URI, NULL);
|
gst_srt_object_set_uri (self->srtobject, GST_SRT_DEFAULT_URI, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +150,7 @@ gst_srt_sink_start (GstBaseSink * bsink)
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
ret = gst_srt_object_open (self->srtobject, self->cancellable, &error);
|
ret = gst_srt_object_open (self->srtobject, &error);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
/* ensure error is posted since state change will fail */
|
/* ensure error is posted since state change will fail */
|
||||||
|
@ -184,7 +181,7 @@ gst_srt_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
||||||
GstMapInfo info;
|
GstMapInfo info;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (g_cancellable_is_cancelled (self->cancellable)) {
|
if (g_cancellable_is_cancelled (self->srtobject->cancellable)) {
|
||||||
ret = GST_FLOW_FLUSHING;
|
ret = GST_FLOW_FLUSHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,8 +197,7 @@ gst_srt_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
||||||
return GST_FLOW_ERROR;
|
return GST_FLOW_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gst_srt_object_write (self->srtobject, self->headers, &info,
|
if (gst_srt_object_write (self->srtobject, self->headers, &info, &error) < 0) {
|
||||||
self->cancellable, &error) < 0) {
|
|
||||||
GST_ELEMENT_ERROR (self, RESOURCE, WRITE,
|
GST_ELEMENT_ERROR (self, RESOURCE, WRITE,
|
||||||
("Failed to write to SRT socket: %s",
|
("Failed to write to SRT socket: %s",
|
||||||
error ? error->message : "Unknown error"), (NULL));
|
error ? error->message : "Unknown error"), (NULL));
|
||||||
|
@ -229,7 +225,7 @@ gst_srt_sink_unlock (GstBaseSink * bsink)
|
||||||
{
|
{
|
||||||
GstSRTSink *self = GST_SRT_SINK (bsink);
|
GstSRTSink *self = GST_SRT_SINK (bsink);
|
||||||
|
|
||||||
gst_srt_object_wakeup (self->srtobject, self->cancellable);
|
gst_srt_object_unlock (self->srtobject);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -239,7 +235,7 @@ gst_srt_sink_unlock_stop (GstBaseSink * bsink)
|
||||||
{
|
{
|
||||||
GstSRTSink *self = GST_SRT_SINK (bsink);
|
GstSRTSink *self = GST_SRT_SINK (bsink);
|
||||||
|
|
||||||
g_cancellable_reset (self->cancellable);
|
gst_srt_object_unlock_stop (self->srtobject);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,6 @@ struct _GstSRTSink {
|
||||||
GstBufferList *headers;
|
GstBufferList *headers;
|
||||||
|
|
||||||
GstSRTObject *srtobject;
|
GstSRTObject *srtobject;
|
||||||
GCancellable *cancellable;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstSRTSinkClass {
|
struct _GstSRTSinkClass {
|
||||||
|
|
|
@ -116,7 +116,7 @@ gst_srt_src_start (GstBaseSrc * bsrc)
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
ret = gst_srt_object_open (self->srtobject, self->cancellable, &error);
|
ret = gst_srt_object_open (self->srtobject, &error);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
/* ensure error is posted since state change will fail */
|
/* ensure error is posted since state change will fail */
|
||||||
|
@ -157,7 +157,7 @@ gst_srt_src_fill (GstPushSrc * src, GstBuffer * outbuf)
|
||||||
SRT_MSGCTRL mctrl;
|
SRT_MSGCTRL mctrl;
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
if (g_cancellable_is_cancelled (self->cancellable)) {
|
if (g_cancellable_is_cancelled (self->srtobject->cancellable)) {
|
||||||
ret = GST_FLOW_FLUSHING;
|
ret = GST_FLOW_FLUSHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ retry:
|
||||||
base_time = gst_element_get_base_time (GST_ELEMENT (src));
|
base_time = gst_element_get_base_time (GST_ELEMENT (src));
|
||||||
|
|
||||||
recv_len = gst_srt_object_read (self->srtobject, info.data,
|
recv_len = gst_srt_object_read (self->srtobject, info.data,
|
||||||
gst_buffer_get_size (outbuf), self->cancellable, &err, &mctrl);
|
gst_buffer_get_size (outbuf), &err, &mctrl);
|
||||||
|
|
||||||
/* Capture clock values ASAP */
|
/* Capture clock values ASAP */
|
||||||
capture_time = gst_clock_get_time (clock);
|
capture_time = gst_clock_get_time (clock);
|
||||||
|
@ -197,7 +197,7 @@ retry:
|
||||||
"recv_len:%" G_GSIZE_FORMAT " pktseq:%d msgno:%d srctime:%"
|
"recv_len:%" G_GSIZE_FORMAT " pktseq:%d msgno:%d srctime:%"
|
||||||
G_GINT64_FORMAT, recv_len, mctrl.pktseq, mctrl.msgno, mctrl.srctime);
|
G_GINT64_FORMAT, recv_len, mctrl.pktseq, mctrl.msgno, mctrl.srctime);
|
||||||
|
|
||||||
if (g_cancellable_is_cancelled (self->cancellable)) {
|
if (g_cancellable_is_cancelled (self->srtobject->cancellable)) {
|
||||||
ret = GST_FLOW_FLUSHING;
|
ret = GST_FLOW_FLUSHING;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,6 @@ static void
|
||||||
gst_srt_src_init (GstSRTSrc * self)
|
gst_srt_src_init (GstSRTSrc * self)
|
||||||
{
|
{
|
||||||
self->srtobject = gst_srt_object_new (GST_ELEMENT (self));
|
self->srtobject = gst_srt_object_new (GST_ELEMENT (self));
|
||||||
self->cancellable = g_cancellable_new ();
|
|
||||||
|
|
||||||
gst_base_src_set_format (GST_BASE_SRC (self), GST_FORMAT_TIME);
|
gst_base_src_set_format (GST_BASE_SRC (self), GST_FORMAT_TIME);
|
||||||
gst_base_src_set_live (GST_BASE_SRC (self), TRUE);
|
gst_base_src_set_live (GST_BASE_SRC (self), TRUE);
|
||||||
|
@ -292,7 +291,6 @@ gst_srt_src_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
GstSRTSrc *self = GST_SRT_SRC (object);
|
GstSRTSrc *self = GST_SRT_SRC (object);
|
||||||
|
|
||||||
g_clear_object (&self->cancellable);
|
|
||||||
gst_srt_object_destroy (self->srtobject);
|
gst_srt_object_destroy (self->srtobject);
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
|
@ -303,7 +301,7 @@ gst_srt_src_unlock (GstBaseSrc * bsrc)
|
||||||
{
|
{
|
||||||
GstSRTSrc *self = GST_SRT_SRC (bsrc);
|
GstSRTSrc *self = GST_SRT_SRC (bsrc);
|
||||||
|
|
||||||
gst_srt_object_wakeup (self->srtobject, self->cancellable);
|
gst_srt_object_unlock (self->srtobject);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -313,7 +311,7 @@ gst_srt_src_unlock_stop (GstBaseSrc * bsrc)
|
||||||
{
|
{
|
||||||
GstSRTSrc *self = GST_SRT_SRC (bsrc);
|
GstSRTSrc *self = GST_SRT_SRC (bsrc);
|
||||||
|
|
||||||
g_cancellable_reset (self->cancellable);
|
gst_srt_object_unlock_stop (self->srtobject);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,6 @@ struct _GstSRTSrc {
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
|
|
||||||
GstSRTObject *srtobject;
|
GstSRTObject *srtobject;
|
||||||
GCancellable *cancellable;
|
|
||||||
|
|
||||||
guint32 next_pktseq;
|
guint32 next_pktseq;
|
||||||
gboolean keep_listening;
|
gboolean keep_listening;
|
||||||
|
|
Loading…
Reference in a new issue