Skip to content

Instantly share code, notes, and snippets.

@ThKr-FhG
Forked from philhartung/aes67.py
Created March 21, 2023 14:18
Show Gist options
  • Save ThKr-FhG/f13e6c077111de72ef67ef1df24f8056 to your computer and use it in GitHub Desktop.
Save ThKr-FhG/f13e6c077111de72ef67ef1df24f8056 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment