mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 11:45:25 +00:00
udpsink: handle scather gather from buffers
Iterate the memory blocks on the buffer and send them using sendmsg.
This commit is contained in:
parent
4e7f1633e4
commit
6df597cbbf
1 changed files with 84 additions and 65 deletions
|
@ -488,6 +488,8 @@ socket_last_error_message (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
/* version without sendmsg */
|
||||
static GstFlowReturn
|
||||
gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
||||
{
|
||||
|
@ -565,49 +567,47 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
|||
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#ifndef G_OS_WIN32
|
||||
#else /* !G_OS_WIN32 */
|
||||
/* version with sendmsg */
|
||||
static GstFlowReturn
|
||||
gst_multiudpsink_render_list (GstBaseSink * bsink, GstBufferList * list)
|
||||
gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
||||
{
|
||||
GstMultiUDPSink *sink;
|
||||
GList *clients;
|
||||
gint ret, size = 0, num = 0, no_clients = 0;
|
||||
struct iovec *iov;
|
||||
struct msghdr msg = { 0 };
|
||||
GstBufferListIterator *it;
|
||||
guint gsize;
|
||||
GstBuffer *buf;
|
||||
guint n_mem, i;
|
||||
gpointer bdata;
|
||||
gsize bsize;
|
||||
GstMemory *mem;
|
||||
|
||||
sink = GST_MULTIUDPSINK (bsink);
|
||||
|
||||
g_return_val_if_fail (list != NULL, GST_FLOW_ERROR);
|
||||
|
||||
it = gst_buffer_list_iterate (list);
|
||||
g_return_val_if_fail (it != NULL, GST_FLOW_ERROR);
|
||||
|
||||
while (gst_buffer_list_iterator_next_group (it)) {
|
||||
msg.msg_iovlen = 0;
|
||||
size = 0;
|
||||
|
||||
if ((gsize = gst_buffer_list_iterator_n_buffers (it)) == 0) {
|
||||
goto invalid_list;
|
||||
}
|
||||
n_mem = gst_buffer_n_memory (buffer);
|
||||
if (n_mem == 0)
|
||||
goto no_data;
|
||||
|
||||
iov = (struct iovec *) g_malloc (gsize * sizeof (struct iovec));
|
||||
iov = (struct iovec *) g_malloc (n_mem * sizeof (struct iovec));
|
||||
msg.msg_iov = iov;
|
||||
|
||||
while ((buf = gst_buffer_list_iterator_next (it))) {
|
||||
if (GST_BUFFER_SIZE (buf) > UDP_MAX_SIZE) {
|
||||
for (i = 0; i < n_mem; i++) {
|
||||
mem = gst_buffer_peek_memory (buffer, i, GST_MAP_READ);
|
||||
bdata = gst_memory_map (mem, &bsize, NULL, GST_MAP_READ);
|
||||
|
||||
if (bsize > UDP_MAX_SIZE) {
|
||||
GST_WARNING ("Attempting to send a UDP packet larger than maximum "
|
||||
"size (%d > %d)", GST_BUFFER_SIZE (buf), UDP_MAX_SIZE);
|
||||
"size (%d > %d)", bsize, UDP_MAX_SIZE);
|
||||
}
|
||||
|
||||
msg.msg_iov[msg.msg_iovlen].iov_len = GST_BUFFER_SIZE (buf);
|
||||
msg.msg_iov[msg.msg_iovlen].iov_base = GST_BUFFER_DATA (buf);
|
||||
msg.msg_iov[msg.msg_iovlen].iov_len = bsize;
|
||||
msg.msg_iov[msg.msg_iovlen].iov_base = bdata;
|
||||
msg.msg_iovlen++;
|
||||
size += GST_BUFFER_SIZE (buf);
|
||||
|
||||
size += bsize;
|
||||
}
|
||||
|
||||
sink->bytes_to_serve += size;
|
||||
|
@ -635,6 +635,11 @@ gst_multiudpsink_render_list (GstBaseSink * bsink, GstBufferList * list)
|
|||
|
||||
if (ret < 0) {
|
||||
if (!socket_error_is_ignorable ()) {
|
||||
gchar *errormessage = socket_last_error_message ();
|
||||
GST_WARNING_OBJECT (sink, "client %p gave error %d (%s)", client,
|
||||
socket_last_error_code (), errormessage);
|
||||
g_free (errormessage);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -649,22 +654,36 @@ gst_multiudpsink_render_list (GstBaseSink * bsink, GstBufferList * list)
|
|||
}
|
||||
g_mutex_unlock (sink->client_lock);
|
||||
|
||||
/* unmap all memory again */
|
||||
for (i = 0; i < n_mem; i++) {
|
||||
mem = gst_buffer_peek_memory (buffer, i, GST_MAP_READ);
|
||||
|
||||
bsize = msg.msg_iov[i].iov_len;
|
||||
bdata = msg.msg_iov[i].iov_base;
|
||||
|
||||
gst_memory_unmap (mem, bdata, bsize);
|
||||
}
|
||||
g_free (iov);
|
||||
msg.msg_iov = NULL;
|
||||
|
||||
GST_LOG_OBJECT (sink, "sent %d bytes to %d (of %d) clients", size, num,
|
||||
no_clients);
|
||||
}
|
||||
|
||||
gst_buffer_list_iterator_free (it);
|
||||
|
||||
return GST_FLOW_OK;
|
||||
|
||||
invalid_list:
|
||||
gst_buffer_list_iterator_free (it);
|
||||
return GST_FLOW_ERROR;
|
||||
no_data:
|
||||
{
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* DISABLED, core sends buffers to our render one by one, we can't really do
|
||||
* much better */
|
||||
static GstFlowReturn
|
||||
gst_multiudpsink_render_list (GstBaseSink * bsink, GstBufferList * list)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue