Blame doc/aaf.txt

Packit 675970
AVTP Audio Format (AAF) Plugin
Packit 675970
==============================
Packit 675970
Packit 675970
Overview
Packit 675970
--------
Packit 675970
Packit 675970
The AAF plugin is a PCM plugin that uses Audio Video Transport Protocol (AVTP)
Packit 675970
to transmit/receive audio samples through a Time-Sensitive Network (TSN)
Packit 675970
capable network. The plugin enables media applications to easily implement AVTP
Packit 675970
Talker and Listener functionalities.
Packit 675970
Packit 675970
AVTP is designed to take advantage of generalized Precision Time Protocol
Packit 675970
(gPTP) and Forwarding and Queuing Enhancements for Time-Sensitive Streams
Packit 675970
(FQTSS). gPTP ensures AVTP talkers and listeners share the same time reference
Packit 675970
so the presentation time from AVTP can be used to inform when PCM samples
Packit 675970
should be presented to the application layer. FQTSS provides bandwidth
Packit 675970
reservation and traffic prioritization for the AVTP stream.
Packit 675970
Packit 675970
gPTP functionality is provided by the Linuxptp project while FQTSS
Packit 675970
functionality is provided by Linux Traffic Control system since kernel version
Packit 675970
4.15.
Packit 675970
Packit 675970
gPTP Setup
Packit 675970
----------
Packit 675970
Packit 675970
The Linuxptp project provides the ptp4l daemon, which synchronizes the PTP
Packit 675970
clock from NIC, and the pmc tool which communicates with ptp4l to get/set
Packit 675970
some runtime settings. The project also provides the phc2sys daemon which
Packit 675970
synchronizes the PTP clock and system clock.
Packit 675970
Packit 675970
The AAF Plugin requires system clock is synchronized with PTP clock and TAI
Packit 675970
offset is properly set in the kernel. ptp4l and phc2sys can be set up in many
Packit 675970
different ways, below we provide an example that fullfils the plugin
Packit 675970
requirements. For further information check ptp4l(8) and phc2sys(8).
Packit 675970
Packit 675970
In the following instructions, replace $IFNAME by your PTP capable NIC
Packit 675970
interface. The gPTP.cfg file mentioned below can be found in /usr/share/
Packit 675970
doc/linuxptp/ (depending on your distro).
Packit 675970
Packit 675970
Synchronize PTP clock with PTP time:
Packit 675970
Packit 675970
	$ ptp4l -f gPTP.cfg -i $IFNAME
Packit 675970
Packit 675970
Enable TAI offset to be automatically set by phc2sys:
Packit 675970
Packit 675970
	$ pmc -u -t 1 -b 0 'SET GRANDMASTER_SETTINGS_NP \
Packit 675970
		clockClass 248 clockAccuracy 0xfe \
Packit 675970
		offsetScaledLogVariance 0xffff \
Packit 675970
		currentUtcOffset 37 leap61 0 leap59 0 \
Packit 675970
		currentUtcOffsetValid 1 pTimescale 1 \
Packit 675970
		timeTraceable 1 frequencyTraceable 0 timeSource 0xa0'
Packit 675970
Packit 675970
Synchronize system clock with PTP clock:
Packit 675970
Packit 675970
	$ phc2sys -f gPTP.cfg -s $IFNAME -c CLOCK_REALTIME -w
Packit 675970
Packit 675970
The commands above should be run on both AVTP Talker and Listener hosts.
Packit 675970
Packit 675970
Traffic Control Setup
Packit 675970
---------------------
Packit 675970
Packit 675970
The Linux Traffic Control system provides the mqprio and cbs qdiscs which
Packit 675970
enable FQTSS on Linux. Below we provide an example to configure those qdiscs in
Packit 675970
order to transmit an AAF stream with the following features: class A, 6 audio
Packit 675970
frames per AVTPDU, 48 kHz sampling rate, 16-bit sample size, stereo. For
Packit 675970
further information on how to configure these qdiscs check tc-mqprio(8) and
Packit 675970
tc-cbs(8) man pages.
Packit 675970
Packit 675970
On the host that will run as AVTP Talker (i.e. plugin in playback mode), run
Packit 675970
the following commands:
Packit 675970
Packit 675970
Configure mpqrio qdisc (replace $MQPRIO_HANDLE_ID by an unused handle ID):
Packit 675970
Packit 675970
	$ tc qdisc add dev $IFNAME parent root handle $MQPRIO_HANDLE_ID \
Packit 675970
			mqprio num_tc 3 map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \
Packit 675970
			queues 1@0 1@1 2@2 hw 0
Packit 675970
Packit 675970
Configure cbs qdisc (replace $CBS_HANDLE_ID by an unused handle ID):
Packit 675970
Packit 675970
	$ tc qdisc replace dev $IFNAME parent $MQPRIO_HANDLE_ID:1 \
Packit 675970
			handle $CBS_HANDLE_ID cbs idleslope 5760 \
Packit 675970
			sendslope -994240 hicredit 9 locredit -89 offload 1
Packit 675970
Packit 675970
The plugin implements a transmission mechanism that relies on ETF qdisc so make
Packit 675970
sure it is properly configured in the system. It could be configured many way,
Packit 675970
below follows an example.
Packit 675970
Packit 675970
	$ tc qdisc add dev $IFNAME parent $CBS_HANDLE_ID:1 etf \
Packit 675970
			clockid CLOCK_TAI delta 500000 offload
Packit 675970
Packit 675970
No Traffic Control configuration is required at the host running as AVTP
Packit 675970
Listener.
Packit 675970
Packit 675970
Plugin Dependencies
Packit 675970
-------------------
Packit 675970
Packit 675970
The AAF plugin uses libavtp to handle AVTP packetization. Libavtp source code
Packit 675970
can be found in https://github.com/AVnu/libavtp as well as instructions to
Packit 675970
build and install it.
Packit 675970
Packit 675970
The plugin also depends on some kernel API headers such as linux/if_ether.h so
Packit 675970
make sure you have them installed in your system.
Packit 675970
Packit 675970
If libavtp or the kernel headers aren't detected by configure, the plugin isn't
Packit 675970
built.
Packit 675970
Packit 675970
Plugin Configuration
Packit 675970
--------------------
Packit 675970
Packit 675970
The plugin parameters are passed via ALSA configuration file. They are defined
Packit 675970
as follows:
Packit 675970
Packit 675970
	* ifname: Network interface used to transmit/receive AVTP packets.
Packit 675970
Packit 675970
	* addr: Stream destination MAC address.
Packit 675970
Packit 675970
	* prio: Priority used by the plugin to transmit AVTP traffic. This
Packit 675970
	  option is relevant only when operating in playback mode.
Packit 675970
Packit 675970
	* streamid: Stream ID associated with the AAF stream transmitted or
Packit 675970
	  received by the plugin.
Packit 675970
Packit 675970
	* mtt: Maximum Transit Time (in microseconds) as defined in AVTP spec
Packit 675970
	  section 4.3.3. This option is relevant only when operating in
Packit 675970
	  playback mode.
Packit 675970
Packit 675970
	* time_uncertainty: Maximum Time Uncertainty (in microseconds) as
Packit 675970
	  defined by AVTP spec section 4.3.3. This option is relevant only when
Packit 675970
	  operating in playback mode.
Packit 675970
Packit 675970
	* frames_per_pdu: Number of audio frames transmitted in one AVTPDU.
Packit 675970
Packit 675970
	* ptime_tolerance: Presentation time tolerance in microseconds.
Packit 675970
	  AVTPDUs with presentation time off by +- ptime_tolerance are not
Packit 675970
	  considered invalid. This option is relevant only when operating in
Packit 675970
	  capture mode.
Packit 675970
Packit 675970
Plugin Usage
Packit 675970
------------
Packit 675970
Packit 675970
The plugin provides the PCM type "aaf". Configure an AAF PCM virtual device
Packit 675970
according to the AAF stream you want to transmit or receive. A hypothetical
Packit 675970
configuration for the stream described in the 'FQTSS Setup' section is shown
Packit 675970
below:
Packit 675970
Packit 675970
	pcm.aaf0 {
Packit 675970
		type aaf
Packit 675970
		ifname eth0
Packit 675970
		addr 01:AA:AA:AA:AA:AA
Packit 675970
		prio 3
Packit 675970
		streamid AA:BB:CC:DD:EE:FF:0000
Packit 675970
		mtt 2000
Packit 675970
		time_uncertainty 125
Packit 675970
		frames_per_pdu 6
Packit 675970
		ptime_tolerance 100
Packit 675970
	}
Packit 675970
Packit 675970
Put the above to ~/.asoundrc (or /etc/asound.conf), and use the AAF PCM virtual
Packit 675970
device 'aaf0' with your favorite alsa-utils tool. Note that the plugin requires
Packit 675970
the period size is multiple of the 'frames_per_pdu' configuration.
Packit 675970
Packit 675970
For example, to stream the pink noise generated by 'speaker-test', run:
Packit 675970
Packit 675970
	$ speaker-test -F S16_BE -c 2 -r 48000 -D aaf0 -p 12500
Packit 675970
Packit 675970
To receive the AAF stream generated by the command above, run the following
Packit 675970
command in another host:
Packit 675970
Packit 675970
	$ arecord -t raw -f S16_BE -c 2 -r 48000 -D aaf0 -vv /dev/null -F 12500
Packit 675970
Packit 675970
If you want to playback the contents of the AAF stream, change the command-line
Packit 675970
above so the output from 'arecord' is redirected to 'aplay', or simply use the
Packit 675970
'alsaloop' tool.