A back channel is aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/bluenviron/gortsplib/llms.txt
Use this file to discover all available pages before exploring further.
sendonly media track in the SDP that flows in the reverse direction — from the client to the server. ONVIF IP cameras use back channels to receive audio from a viewer (for example, to drive a speaker mounted on the camera). The codec is almost always G.711 (PCMU or PCMA) at 8 kHz.
The ONVIF Streaming Specification requires cameras to advertise a back channel in the SDP when two-way audio is supported. gortsplib handles back channels on both the client side (sending audio to a camera) and the server side (receiving audio from a viewer).
Back channel media entries have
IsBackChannel: true in description.Media. The SDP attribute a=sendonly is set on these tracks; the camera receives rather than sends on them.Client: sending audio to a camera
To send audio through a back channel, setRequestBackChannels: true on the client before connecting. After Describe, iterate the session medias to find a back channel that uses the codec you want to send (G.711 in this case), then call Setup on it and use c.WritePacketRTP to push encoded audio frames.
Enable back channel negotiation
Set
RequestBackChannels: true on the gortsplib.Client. Without this flag the client will not include the ONVIF Require: www.onvif.org/ver20/backchannel header and the camera will not expose back channel medias in the SDP.Find the G.711 back channel
After
Describe, walk desc.Medias looking for entries where media.IsBackChannel == true and the format list contains *format.G711.Setup and play
Call
c.Setup(desc.BaseURL, medi, 0, 0) for the back channel media only, then call c.Play(nil).Server: receiving audio from a client
To accept back-channel audio from a connecting viewer, declare adescription.Media with IsBackChannel: true alongside your normal (direct) media tracks. Register a packet handler inside OnPlay using ctx.Session.OnPacketRTPAny — this fires whenever the client pushes audio into the back channel.
Declare a back channel media
Add a
description.Media entry with IsBackChannel: true to the description.Session. The SDP will contain a=sendonly on that track, signalling to connecting clients that they should send audio on it.Create the ServerStream
Pass the
description.Session (containing both the direct and back channel medias) to gortsplib.ServerStream and call Initialize().ONVIF compliance notes
The ONVIF Streaming Specification (section 5.1.1) requires:- The
Require: www.onvif.org/ver20/backchannelheader in the client’sDESCRIBErequest — gortsplib sends this automatically whenRequestBackChannels: true. - A
sendonlyattribute on the back channelm=line in the SDP — gortsplib sets this fromIsBackChannel: truein the media description. - The back channel to be set up and played within the same RTSP session as the forward channel.