Commit graph

36 commits

Author SHA1 Message Date
Ederson de Souza
51d5aee94d avtp: Update documentation
- Mention that a new capability is required by "avtpsink" element;
 - Use "clockselect" element to change pipeline clock, instead of a
   gst-launch option that never saw the light of day.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1443>
2020-07-16 13:32:56 -07:00
Tim-Philipp Müller
395ecb3d2f avtp: rename tstamp-mode to timestamp-mode
I thnk w cn spre the xtra lttrs.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1397>
2020-07-11 00:14:44 +01:00
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
Mathieu Duponchelle
b33f10e7e2 docs: remove gst prefix from plugin titles 2020-07-02 18:10:21 +02:00
Tim-Philipp Müller
c229127b43 avtp: documentation fixes
Unclear why hotdoc wants 'gstavtp' as the plugin name here,
that's just wrong.

Add since marker and mark private subclasses as plugin API
so hotdoc knows they belong to the plugin and aren't external.

Fix GstAvtpAafTstampMode get_type() function.
2020-07-01 18:41:25 +01:00
Ederson de Souza
bafdade207 avtp: Ensure that the avtp plugin is only built on Linux
It uses some Linux only features. This also prevents gst-build trying to
get libavtp on non-Linux environments.
2020-06-01 11:37:16 -07:00
Ederson de Souza
a754c67c05 avtp: Add libavtp fallback dependence
So that libavtp can be found if added as subproject on gst-build.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1271>
2020-05-21 00:14:08 +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
Ederson de Souza
7edaeb3fae avtpcvfpay: Warn about timestamp issues on non-flushing seek
Seek events will cause new segments to be sent to avtpcvfpay, and for
flushing seeks, a pipeline running time reset. This running time
reset, which effectively changes pipeline base time, will cause
avtpcvfpay element to generate incorrect DTS for the initial set of
buffers sent after FLUSH_STOP.

This happens due the fact that base time change happens only when the
sink gets the first buffer after the FLUSH_STOP - so avtpcvfpay used
the wrong base time to do its calculations.

However, if the pipeline is paused before the seek, sink will update
base time when pipeline state goes to PLAYING again, before avtpcvfpay
gets the first buffers after the flush. Then avtpcvfpay element will be
able to normally calculate DTS for the outgoing packets.

This patch simply adds a warning message in case a flushing seek is
performed on a playing pipeline.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1004>
2020-05-02 17:42:15 +00:00
Ederson de Souza
12838af353 avtpcvfpay: Ensure NAL fragments are transmitted following stream specs
TSN streams are expected to send packets to the network in a well
defined "pace", which is arbitrarily defined for each stream. This pace
is defined by the "measurement interval" property of a stream.

When the AVTP CVF payloader element - avtpcvfpay - fragments a video
frame that is too big to be sent to the network, it currently defines
that all fragments should be transmitted at the same time (via DTS
property of GstBuffers generated, as sink will use those to time the
transmission of the AVTPDU). This doesn't comply with stream definition,
which also has a limit on how many packets can be sent on a given
measurement interval.

This patch solves that by spreading in time the DTS of the GstBuffers
containing the AVTPDUs. Two new properties, "measurement-interval" and
"max-interval-frames", added to avptcvfpay element so that it knows
stream measurement interval and how many AVTPDUs it can send on any of
them. More details on the method used to proper spread DTS/PTS according
to measurement interval can be found in a code commentary inside this patch.

Tests also added for the new property and behaviour.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1004>
2020-05-02 17:42:15 +00:00
Vedang Patel
e47fa2006f avtp: Introduce the CRF Check element
This commit introduces the AVTP Clock Reference Format (CRF) Checker
element. This element re-uses the GstAvtpCrfBase class introduced along
with the CRF Synchronizer element.

This element will typically be used along with the avtpsrc element to
ensure that the AVTP timestamp (and H264 timestamp in case of CVF-H264
packets) is "aligned" with the incoming CRF stream. Here, "aligned" means
that the timestamp value should be within 25% of the period of the media
clock recovered from the CRF stream.

The user can also set an option (drop-invalid) in order to drop any packet
whose timestamp is not within the thresholds of the incoming CRF stream.
2020-04-30 23:31:25 +00:00
Vedang Patel
12ad2a4bcd avtp: Introduce the CRF Sync Element
This commit introduces the AVTP Clock Reference Format (CRF) Synchronizer
element. This element implements the AVTP CRF Listener as described in IEEE
1722-2016 Section 10.

CRF is useful in synchronizing events within different systems by
distributing a common clock. This is useful in a scenario where there are
multiple talkers who are sending data to a single listener which is
processing that data. E.g.  CCTV cameras on a network sending AVTP video
streams to a base station to display on the same screen.

It is assumed that all the systems are already time-synchronized with each
other. So, the AVTP Talker essentially adjusts the AVTP Presentation Time
so it's phase-locked with the reference clock provided by the CRF stream.

There are 2 different roles of systems which participate in CRF data
exchange.  A system can either be a CRF Talker, which samples it's own
clock and generates a stream of timestamps to transmit over the network, or
a CRF Listener, the system which receives the generated timestamps and
recovers the media clock from the timestamps. It then adjusts it's own
clock to align with recovered media clock. The timestamps generated by the
talker may not be continuous and the listener might have to interpolate
some timestamps to recover the media clock. The number of timestamps to
interpolate is mentioned in the CRF stream AVTPDU (Refer IEEE 1722-2016
Section 10.4 for AVTPDU structure). Only CRF Listener has been implemented
in this commit.

The CRF Sync element will create a separate thread to listen for the CRF
stream. This thread will calculate and store the average period of the
recovered media clock. The pipeline thread will use this stored period
along with the first timestamp of the latest CRF AVTPDU received to
calculate adjustment for timestamps in the audio/video streams. In case of
CRF AVTPDUs with single timestamp, two consecutive CRF AVTPDUs will be used
to figure out the average period of the recovered media clock.

In case of H264 streams, both AVTP timestamp and H264 timestamp will be
adjusted.

In the future commits, another "CRF Checker" element will be introduced
which will validate the timestamps on the AVTP Listener side. Which is why
a lot of code has been implemented as part of the gstcrfbase class.
2020-04-30 23:31:25 +00:00
Ederson de Souza
916966606b avtp: Build with clang
Minor non-conformity on AVTP code made it not compile with clang.
2020-02-07 21:53:57 +00:00
Ederson de Souza
f1976e0de5 avtp: Plug several leaks
After finally running tests with valgrind enabled, some leaks were found
- both on code and on tests themselves. This patch plugs them all!
2020-02-07 21:53:57 +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
Ederson de Souza
484a272306 avtpcvfdepay: Don't hide gst_pad_push return
avtpcvfdepay was effectively hiding any return from gst_pad_push, so no
errors or GST_FLOW_EOS would be propagated upstream.

Tests also added.
2019-11-19 13:35:00 +00:00
Ederson de Souza
c45c235b2a avtpcvfpay: Do not hide or modify gst_pad_push errors
Current code would change any non-ok return from gst_pad_push to
GST_FLOW_ERROR, thus hiding meaningful returns such as GST_FLOW_EOS.

Tests also added.
2019-11-19 13:35:00 +00:00
Ederson de Souza
b09bc36160 avtpcvfdepay: Tone down some log messages
Most of avtpcvfdepay messages are currently logged as warnings, which can
make some scenarios - such as receiving two AVTP streams on the same
pipeline - too verbose.

This patch tones those message down to INFO or DEBUG level - more in
sync with avtpaafdepay logging.
2019-11-19 13:35:00 +00:00
Tim-Philipp Müller
f218ec2794 Remove autotools build system 2019-10-14 13:54:27 +01:00
Ederson de Souza
416afd5fa9 avtp: CVF - fix error message
The error is about *not* being able to map a buffer.
2019-07-30 11:34:31 -07:00
Ederson de Souza
f9a16731d1 avtp: CVF - Do not infinite loop trying to fragment zero sized NAL unit
Zero sized NAL-units should not happen, but if they do, do not infinite
loop. Added also a unit test for this case.
2019-07-30 11:34:31 -07:00
Ederson de Souza
f18fab0eb1 avtp: Update documentation 2019-07-03 09:59:35 -07:00
Ederson de Souza
5592ab1769 docs: Add AVTP elements documentation 2019-07-03 09:59:35 -07:00
Ederson de Souza
45624661ba avtp: Add fragmented packets handling to CVF depayloader
This patch adds to the CVF depayloader the capability to regroup H.264
fragmented FU-A packets.

After all packets are regrouped, they are added to the "stash" of H.264
NAL units that will be sent as soon as an AVTP packet with M bit set is
found (usually, the last fragment).

Unrecognized fragments (such as first fragment seen, but with no Start
bit set) are discarded - and any NAL units on the "stash" are sent
downstream, as if a SEQNUM discontinuty happened.
2019-07-03 09:59:35 -07:00
Ederson de Souza
45d2f5a779 avtp: Introduce AVTP CVF depayloader element
This patch introduces the AVTP Compressed Video Format (CVF) depayloader
specified in IEEE 1722-2016 section 8. Currently, this depayloader only
supports H.264 encapsulation described in section 8.5.

Is also worth noting that only single NAL units are handled: aggregated
and fragmented payloads are not handled.

As stated in AVTP CVF payloader patch, AVTP timestamp is used to define
outgoing buffer DTS, while the H264_TIMESTAMP defines outgoing buffer
PTS.

When an AVTP packet is received, the extracted H.264 NAL unit is added to
a "stash" (the out_buffer) of H.264 NAL units. This "stash" is pushed
downstream as single buffer (with NAL units aggregated according to format
used on GStreamer, based on ISO/IEC 14496-15) as soon as we get the AVTP
packet with M bit set.

This patch groups NAL units using a fixed NAL size lenght, sent downstream
on the `codec_data` capability.

The "stash" of NAL units can be prematurely sent downstream if a
discontinuity (a missing SEQNUM) happens.

This patch reuses the infra provided by gstavtpbasedepayload.c.
2019-07-03 09:59:35 -07:00
Ederson de Souza
b056297eea avtp: Add fragmentation feature to CVF payloader
Based on `mtu` property, the CVF payloader is now capable of properly
fragmenting H.264 NAL units that are bigger than MTU in several AVTP
packets.

AVTP spec defines two methods for fragmenting H.264 packets, but this
patch only generates non-interleaved FU-A fragments.

Usually, only the last NAL unit from a group of NAL units in a single
buffer will be big enough to be fragmented. Nevertheless, only the last
AVTP packet sent for a group of NAL units will have the M bit set (this
means that the AVTP packet for the last fragment will only have the M
bit set if there's no more NAL units in the group).
2019-07-03 09:59:35 -07:00
Ederson de Souza
3b4f3a0b3f avtp: Introduce AVTP CVF payloader element
This patch introduces the AVTP Compressed Video Format (CVF) payloader
specified in IEEE 1722-2016 section 8. Currently, this payload only
supports H.264 encapsulation described in section 8.5.

Is also worth noting that only single NAL units are encapsulated: no
aggregation or fragmentation is performed by the payloader.

An interesting characteristic of CVF H.264 spec is that it defines an
H264_TIMESTAMP, in addition to the AVTP timestamp. The later is
translated to the GST_BUFFER_DTS while the former is translated to the
GST_BUFFER_PTS. From AVTP CVF H.264 spec, it is clear that the AVTP
timestamp is related to the decoding order, while the H264_TIMESTAMP is
an ancillary information to the H.264 decoder.

Upon receiving a buffer containing a group of NAL units, the avtpcvfpay
element will extract each NAL unit and payload them into individual AVTP
packets. The last AVTP packet generated for a group of NAL units will
have the M bit set, so the depayloader is able to properly regroup them.

The exact format of the buffer of NAL units is described on the
'codec_data' capability, which is parsed by the avtpcvfpay, in the same
way done in rtph264pay.

This patch reuses the infra provided by gstavtpbasepayload.c.
2019-07-03 09:59:35 -07:00
Andre Guedes
5abe516c6c avtp: Introduce AVTP source element
This patch introduces the avtpsrc element which implements a typical
network source. The avtpsrc element receives AVTPDUs encapsulated into
Ethernet frames and push them downstream in the GStreamer pipeline.
Implementation if pretty straightforward since the burden is implemented
by GstPushSrc class.

Likewise the avtpsink element, applications that utilize this element
must have CAP_NET_RAW capability since it is required by Linux to open
sockets from AF_PACKET domain.
2019-07-03 09:59:35 -07: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
Andre Guedes
6477884a56 avtp: Introduce AAF depayloader element
This patch introduces the AAF depayloader element, the counterpart from
the AAF payloader. As expected, this element inputs AVTPDUs and outputs
audio raw data and supports AAF PCM encapsulation only.

The AAF depayloader srcpad produces a fixed format that is encoded
within the AVTPDU. Once the first AVTPDU is received by the element, the
audio features e.g. sample format, rate, number of channels, are decoded
and the srcpad caps are set accordingly. Also, at this point, the
element pushes a SEGMENT event downstream defining the segment according
to the AVTP presentation time.

All AVTP depayloaders will share some common code. For that reason, this
patch introduces the GstAvtpBaseDepayload abstract class that implements
common depayloader functionalities. AAF-specific functionalities are
implemented in the derived class GstAvtpAafDepay.
2019-07-03 09:59:35 -07:00
Andre Guedes
1e985f02f4 avtp: Introduce AAF payloader element
This patch introduces the AVTP Audio Format (AAF) payloader element from
the AVTP plugin. The element inputs audio raw data and outputs AVTP
packets (aka AVTPDUs), implementing a typical protocol payloader element
from GStreamer.

AAF is one of the available formats to transport audio data in an AVTP
system. AAF is specified in IEEE 1722-2016 section 7 and provides two
encapsulation mode: PCM and AES3. This patch implements PCM
encapsulation mode only.

The AAF payloader working mechanism consists of building the AAF header,
prepending it to the GstBuffer received on the sink pad, and pushing the
buffer downstream. Payloader parameters such as stream ID, maximum
transit time, time uncertainty, and timestamping mode are passed via
element properties. AAF doesn't support all possible sample format and
sampling rate values so the sink pad caps template from the payloader is
a subset of audio/x-raw. Additionally, this patch implements only
"normal" timestamping mode from AAF. "Sparse" mode should be implemented
in future.

Upcoming patches will introduce other AVTP payloader elements that will
have some common code. For that reason, this patch introduces the
GstAvtpBasePayload abstract class that implements common payloader
functionalities, and the GstAvtpAafPay class that extends the
GstAvtpBasePayload class, implementing AAF-specific functionalities.

The AAF payloader element is most likely to be used with the AVTP sink
element (to be introduced by a later patch) but it could also be used
with UDP sink element to implement AVTP over UDP as described in IEEE
1722-2016 Annex J.

This element was inspired by RTP payloader elements.
2019-07-03 09:59:35 -07:00
Andre Guedes
eaeab383bb avtp: AVTP plugin bootstrap code
This patch introduces the bootstrap code from the AVTP plugin (plugin
definition and init) as well as the build system files. Upcoming patches
will introduce payloaders, source and sink elements provided by the AVTP
plugin. These elements can be utilized by a GStreamer pipeline to
implement TSN audio/video applications.

Regarding the plugin build system files, both autotools and meson files
are introduced. The AVTP plugin is landed in ext/ since it has an
external dependency on libavtp, an opensource AVTP packetization
library. For further information about libavtp check [1].

[1] https://github.com/AVnu/libavtp
2019-07-03 09:59:35 -07:00