Commit graph

8 commits

Author SHA1 Message Date
Ederson de Souza
f8bf84307f avtp: Use g_strerror instead of strerror
It should avoid some implicit declaration errors (and be utf-8 friendly).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1404>
2020-07-03 04:04:39 +00:00
Ederson de Souza
b68e47968b avtpsink: Log that AVTPDU transmission failure is due lateness
As ENOBUFS is not really clear about what is going on, let's check
socket error queue to see if packets are being dropped due being late.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1004>
2020-05-02 17:42:15 +00:00
Ederson de Souza
32281ddd33 avtpsink: Accept buffers that fall out of segment
Proper calculate running time for buffers that are out of current
segment and try to honor them.

A typical case is for AVTP packets coming from avtpcvfpay element, as
those may have DTS that falls out of segment (which is about PTS).

By using gst_segment_to_running_time_full(), avtpsink can properly
calculate when to transmit those buffers.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1004>
2020-05-02 17:42:15 +00:00
Andre Guedes
352bf28a35 avtpsink: Implement synchronization mechanism
The avtpsink element is expected to transmit AVTPDUs at specific times,
according to GstBuffer timestamps. Currently, the transmission time is
controlled in software via the rendering synchronization mechanism
provided by GstBaseSink class. However, that mechanism may not cope with
some AVB use-cases such as Class A streams, where AVTPDUs are expected
to be transmitted at every 125 us. Thus, this patch introduces avtpsink
own mechanism which leverages the socket transmission scheduling
infrastructure introduced in Linux kernel 4.19.  When supported by the
NIC, the transmission scheduling is offloaded to the hardware, improving
transmission time accuracy considerably.

To illustrate that, a before-after experiment was carried out. The
experimental setup consisted in 2 PCs with Intel i210 card connected
back-to-back running an up-to-date Archlinux with kernel 5.3.1. In one
host gst-launch-1.0 was used to generate a 2-minute Class A stream while
the other host captured the packets. The metric under evaluation is the
transmission interval and it is measured by checking the 'time_delta'
information from ethernet frames captured at the receiving side.

The table below shows the outcome for a 48 kHz, 16-bit sample, stereo
audio stream. The unit is nanoseconds.

       |   Mean |   Stdev |     Min |     Max |   Range |
-------+--------+---------+---------+---------+---------+
Before | 125000 │    2401 │  110056 │  288432 │  178376 |
After  | 125000 │      18 │  124943 │  125055 │     112 |

Before this patch, the transmission interval mean is equal to the
optimal value (Class A stream -> 125 us interval), and it is kept the
same after the patch.  The dispersion measurements, however, had
improved considerably, meaning the system is now consistently
transmitting AVTPDUs at the correct time.

Finally, the socket transmission scheduling infrastructure requires the
system clock to be synchronized with PTP clock so this patches modifies
the AVTP plugin documentation to cover how to achieve that.
2020-02-05 22:28:12 +00:00
Andre Guedes
4f0dc8cf58 avtpsink: Prepare code to new synchronization mechanism
This patch refactors gst_avtp_sink_start() by moving all socket
initialization code to its own function. This change prepares the code
to the next patch which will introduce avtpsink's own rendering
synchronization mechanism.
2020-02-05 22:28:12 +00:00
Andre Guedes
cd03c48f88 avtpsink: Remove SOCK_NONBLOCK from avtpsink
Current avtpsink code opens the AF_PACKET socket with SOCK_NONBLOCK
option. However, we actually want sendto() to block in case there isn't
available space in socket buffer.
2020-02-05 22:28:12 +00:00
Andre Guedes
e74c807633 avtp: Refactor if_index code
This patch refactors both avtpsink and avtpsrc code so we use the
if_nametoindex() helper instead of building a request and issuing an
ioctl to get the if_index.
2020-02-05 22:28:12 +00:00
Andre Guedes
37550226d8 avtp: Introduce AVTP sink element
This patch introduces the avtpsink elements which implements a typical
network sink. Implementation is pretty straightforward since the burden
is implemented by GstBaseSink class.

The avtpsink element defines three new properties: 1) network interface
from where AVTPDU should be transmitted, 2) destination MAC address
(usually a multicast address), and 3) socket priority (SO_PRIORITY).

Socket setup and teardown are done in start/stop virtual methods while
AVTPDU transmission is carried out by render(). AVTPDUs are encapsulated
into Ethernet frames and transmitted to the network via AF_PACKET socket
domain.  Linux requires CAP_NET_RAW capability in order to open an
AF_PACKET socket so the application that utilize this element must have
it. For further info about AF_PACKET socket domain see packet(7).

Finally, AVTPDUs are expected to be transmitted at specific times -
according to the GstBuffer presentation timestamp - so the 'sync'
property from GstBaseSink is set to TRUE by default.
2019-07-03 09:59:35 -07:00