srt: Refactor gst_srt_*_sink_send_buffer, extract send

https://bugzilla.gnome.org/show_bug.cgi?id=793503
This commit is contained in:
Jan Alexander Steffens (heftig) 2018-02-16 09:16:12 +01:00 committed by Olivier Crête
parent 7463a93620
commit 8a5dab1c06
2 changed files with 44 additions and 18 deletions

View file

@ -167,6 +167,22 @@ gst_srt_client_sink_start (GstBaseSink * sink)
return (priv->sock != SRT_INVALID_SOCK);
}
static gboolean
send_buffer_internal (GstSRTBaseSink * sink,
const GstMapInfo * mapinfo, gpointer user_data)
{
SRTSOCKET sock = GPOINTER_TO_INT (user_data);
if (srt_sendmsg2 (sock, (char *) mapinfo->data, mapinfo->size,
0) == SRT_ERROR) {
GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, NULL,
("%s", srt_getlasterror_str ()));
return FALSE;
}
return TRUE;
}
static gboolean
gst_srt_client_sink_send_buffer (GstSRTBaseSink * sink,
const GstMapInfo * mapinfo)
@ -174,14 +190,7 @@ gst_srt_client_sink_send_buffer (GstSRTBaseSink * sink,
GstSRTClientSink *self = GST_SRT_CLIENT_SINK (sink);
GstSRTClientSinkPrivate *priv = GST_SRT_CLIENT_SINK_GET_PRIVATE (self);
if (srt_sendmsg2 (priv->sock, (char *) mapinfo->data, mapinfo->size,
0) == SRT_ERROR) {
GST_ELEMENT_ERROR (self, RESOURCE, WRITE, NULL,
("%s", srt_getlasterror_str ()));
return FALSE;
}
return TRUE;
return send_buffer_internal (sink, mapinfo, GINT_TO_POINTER (priv->sock));
}
static gboolean

View file

@ -390,6 +390,21 @@ failed:
return FALSE;
}
static gboolean
send_buffer_internal (GstSRTBaseSink * sink,
const GstMapInfo * mapinfo, gpointer user_data)
{
SRTClient *client = user_data;
if (srt_sendmsg2 (client->sock, (char *) mapinfo->data, mapinfo->size,
0) == SRT_ERROR) {
GST_WARNING_OBJECT (sink, "%s", srt_getlasterror_str ());
return FALSE;
}
return TRUE;
}
static gboolean
gst_srt_server_sink_send_buffer (GstSRTBaseSink * sink,
const GstMapInfo * mapinfo)
@ -403,17 +418,19 @@ gst_srt_server_sink_send_buffer (GstSRTBaseSink * sink,
SRTClient *client = clients->data;
clients = clients->next;
if (srt_sendmsg2 (client->sock, (char *) mapinfo->data, mapinfo->size,
0) == SRT_ERROR) {
GST_WARNING_OBJECT (self, "%s", srt_getlasterror_str ());
priv->clients = g_list_remove (priv->clients, client);
GST_OBJECT_UNLOCK (sink);
g_signal_emit (self, signals[SIG_CLIENT_REMOVED], 0, client->sock,
client->sockaddr);
srt_client_free (client);
GST_OBJECT_LOCK (sink);
}
if (!send_buffer_internal (sink, mapinfo, client))
goto err;
continue;
err:
priv->clients = g_list_remove (priv->clients, client);
GST_OBJECT_UNLOCK (sink);
g_signal_emit (self, signals[SIG_CLIENT_REMOVED], 0, client->sock,
client->sockaddr);
srt_client_free (client);
GST_OBJECT_LOCK (sink);
}
GST_OBJECT_UNLOCK (sink);