udpsrc: more efficient memory handling
authorTim-Philipp Müller <tim@centricular.com>
Tue, 9 Sep 2014 12:46:56 +0000 (13:46 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Tue, 9 Sep 2014 16:38:52 +0000 (17:38 +0100)
commite6f77948acb5fdd5bac673a4ad669ed4360a6952
tree17e8b7df604f3142fa7db4e7e1aaf73dd3de6e45
parent39505584e14be177db8cc7b6c3ac39df21d72774
udpsrc: more efficient memory handling

Drop use of g_socket_get_available_bytes() which is
not useful on all systems (where it returns the size
of the entire buffer not that of the next pending
packet), and is yet another syscall and apparently
very inefficient on Windows in the UDP case.

Instead, when reading UDP packets, use the more featureful
g_socket_receive_message() call that allows to read into
scattered memory, and allocate one memory chunk which is
likely to be large enough for a packet, while also providing
a larger allocated memory chunk just in case the packet
is larger than expected. If the received data fits into the
first chunk, we'll just add that to the buffer we return
and re-use the fallback buffer for next time, otherwise we
add both chunks to the buffer.

This reduces memory waste more reliably on systems where
get_available_bytes() doesn't work properly.

In a multimedia streaming scenario, incoming UDP packets
are almost never fragmented and thus almost always smaller
than the MTU size, which is also why we don't try to do
something smarter with more fallback memory chunks of
different sizes. The fallback scenario is just for when
someone built a broken sender pipeline (not using a
payloader or somesuch)

https://bugzilla.gnome.org/show_bug.cgi?id=610364
gst/udp/gstudpsrc.c