How to use SIP OPTIONS to get the supported codec from another UA
- User
How to use SIP OPTIONS to get the supported codec from another UA
- Assistant
How to use SIP OPTIONS to get the supported codec from another UA
The SIP (Session Initiation Protocol) OPTIONS method is used to query the capabilities of another User Agent (UA) or SIP server without initiating a call. It is commonly used to discover supported methods, codecs, and other features of the remote UA. To specifically retrieve the supported codecs, you can use the SIP OPTIONS method and analyze the response, particularly the SDP (Session Description Protocol) body, if included.
Here’s a step-by-step guide on how to use SIP OPTIONS to get the supported codecs from another UA:
200 OK) may include an SDP body that lists the supported codecs, media types, and other capabilities.m= (media) and a= (attribute) lines of the SDP.A SIP OPTIONS request should include the following headers:
sip:user@domain.com).sip:requester@domain.com).1 OPTIONS).70).application/sdp).Example SIP OPTIONS request:
OPTIONS sip:user@domain.com SIP/2.0
Via: SIP/2.0/UDP 192.168.1.100:5060;branch=z9hG4bK12345
From: <sip:requester@domain.com>;tag=abcd1234
To: <sip:user@domain.com>
Call-ID: 987654321@192.168.1.100
CSeq: 1 OPTIONS
Contact: <sip:requester@192.168.1.100:5060>
Max-Forwards: 70
Accept: application/sdp
Content-Length: 0
200 OK if it supports the OPTIONS method.m=: Specifies the media type (e.g., m=audio 5004 RTP/AVP 0 8 101).
RTP/AVP (e.g., 0, 8, 101) are payload types that map to specific codecs.a=rtpmap:<payload type> <codec>/<clock rate>: Maps payload types to codec names (e.g., a=rtpmap:0 PCMU/8000).Example SIP 200 OK response with SDP:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.1.100:5060;branch=z9hG4bK12345
From: <sip:requester@domain.com>;tag=abcd1234
To: <sip:user@domain.com>;tag=xyz789
Call-ID: 987654321@192.168.1.100
CSeq: 1 OPTIONS
Contact: <sip:user@192.168.1.200:5060>
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS
Accept: application/sdp
Content-Type: application/sdp
Content-Length: 150
v=0
o=user 1234567890 1234567890 IN IP4 192.168.1.200
s=SIP Call
c=IN IP4 192.168.1.200
t=0 0
m=audio 5004 RTP/AVP 0 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
In this example:
m=audio line indicates the UA supports audio with payload types 0, 8, and 101.a=rtpmap lines map these payload types to codecs:
0 → PCMU (G.711 μ-law)8 → PCMA (G.711 A-law)101 → DTMF (telephone-event)m= and a= lines.0: PCMU (G.711 μ-law)8: PCMA (G.711 A-law)9: G.72218: G.72996-127: Dynamic payload types (check a=rtpmap for the codec name, e.g., Opus, AMR, etc.).m=video line with similar codec mappings.Allow header in the response to see if the UA supports INVITE, which implies media capabilities.If you are building an application, you can automate the process of sending OPTIONS requests and parsing responses using a SIP library. For example:
pysip or aiortc): Write a script to send OPTIONS requests and parse SDP.Example pseudocode in Python:
import sip
def send_options_request(target_uri):
client = sip.Client()
request = sip.Request("OPTIONS", target_uri)
request.add_header("Accept", "application/sdp")
response = client.send_request(request)
if response.status_code == 200 and "application/sdp" in response.content_type:
sdp = response.body
codecs = parse_sdp_codecs(sdp)
print("Supported codecs:", codecs)
else:
print("No SDP in response or error:", response.status_code)
def parse_sdp_codecs(sdp):
codecs = []
lines = sdp.split("\n")
for line in lines:
if line.startswith("a=rtpmap:"):
codec_info = line.split()[1]
codecs.append(codec_info)
return codecs
send_options_request("sip:user@domain.com")
tcpdump to capture SIP traffic and verify the OPTIONS request and response.405 Method Not Allowed if OPTIONS is not supported).a=rtpmap lines to identify the codec.Contact header in the response to verify the responding entity.sipp -sf options.xml -d 1000 target_ip
options.xml file with the SIP OPTIONS request template.asterisk -rx "sip show peer <peer_name>"
sip) to capture and analyze OPTIONS requests and responses.By following these steps, you can effectively use the SIP OPTIONS method to query and retrieve the supported codecs from another UA.