Skip to content

Instantly share code, notes, and snippets.

@philhartung
Created December 8, 2021 15:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save philhartung/6f2905ea566bf5dbf5b0b3298008d1d3 to your computer and use it in GitHub Desktop.
Save philhartung/6f2905ea566bf5dbf5b0b3298008d1d3 to your computer and use it in GitHub Desktop.
Simple AES67 implementation using gstreamer. Does not implement any discovery.
import sys
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstNet', '1.0')
from gi.repository import Gst, GstNet, GObject, GLib
Gst.init([])
mainloop = GLib.MainLoop()
# audiotestsrc to aes67
pipelineString = """
audiotestsrc freq=480 volume=0.1 !
audioconvert !
audio/x-raw, format=S24BE, channels=2, rate=48000 !
rtpL24pay name=rtppay min-ptime=1000000 max-ptime=1000000 !
application/x-rtp, clock-rate=48000, channels=2, payload=98 !
udpsink host=239.69.0.121 port=5004 qos=true qos-dscp=34 multicast-iface=eth0
"""
if GstNet.ptp_init(GstNet.PTP_CLOCK_ID_NONE, ['eth0']):
print('PTP initialized')
else:
print('PTP failed to initialize')
sys.exit()
ptpClock = GstNet.PtpClock.new('PTP-Master', 0)
if ptpClock != None:
print('PTP clock obtained')
else:
print('PTP failed to obtain clock')
sys.exit()
print('PTP Syncing to Master')
ptpClock.wait_for_sync(Gst.CLOCK_TIME_NONE)
print('PTP successfully synced to Master')
pipeline = Gst.parse_launch(pipelineString)
pipeline.use_clock(ptpClock)
pipeline.set_start_time(Gst.CLOCK_TIME_NONE)
pipeline.set_base_time(ptpClock.get_time())
ptpOffset = (round((ptpClock.get_time()) * (48000 / 1000000000)) & 0xffffffff)
pipeline.get_by_name('rtppay').set_property('timestamp-offset', ptpOffset)
pipeline.set_state(Gst.State.PLAYING)
print('starting mainloop')
mainloop.run()
@philhartung
Copy link
Author

Command to start the script: sudo nice -n -20 python3 ptp.py.

Latency in Dante Controller seems acceptable on a Raspberry Pi 4, though some packets are still dropped:

@philhartung
Copy link
Author

SDP file:

v=0
o=- 1 1 IN IP4 192.168.1.100
s=GStreamer
c=IN IP4 239.69.0.121/32
t=0 0
m=audio 5004 RTP/AVP 98
a=recvonly
a=rtpmap:98 L24/48000/2
a=ptime:1
a=ts-refclk:ptp=IEEE1588-2008:00-1D-C1-FF-FE-AA-AA-AA:0
a=mediaclk:direct=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment