Net::SIP::SDP(3pm)

πŸ’– Net::SIP::SDP πŸ’–

okay bestie, gather round, because this one is literally the SDP whisperer of the Net::SIP universe β€” parsing and manipulation of SDP data for SIP, no cap. It ships as part of the Perl user-contributed docs, and if you've ever squinted at a session description in a SIP packet like "what is this", this module is your girl. 🫢


✨ SYNOPSIS ✨

my $sdp = Net::SIP::SDP->new( sdp_string );
my @media = $sdp->get_media;

🌸 DESCRIPTION 🌸

So like, Net::SIP::SDP can parse and manipulate SDP data. That's the whole vibe. πŸ’…

But listen β€” it is not a general purpose SDP class (like Net::SDP, which is a whole different girl). This one was designed on purpose to work with SDP data contained in SIP packets, and to make extraction and manipulation of the media information inside the SDP easy peasy β€” you know, for NAT and stuff like that. 🧚

She's also designed for easy creation of SDP bodies in the context of the rest of Net::SIP::*. Main character energy, honestly. πŸ‘‘


πŸ¦‹ EXAMPLES πŸ¦‹

# creation based on media data
my $sdp = Net::SIP::SDP->new(
      { addr => '192.168.0.1' },
      { port => 2012, proto => 'RTP/AVP', media => 'audio', fmt => 0 },
      { port => 2014, proto => 'RTP/AVP', media => 'video', fmt => 0 },
);

# parse from string
my $sdp = Net::SIP::SDP->new( sdp_string );

# extract all media data
my @media = $sdp->get_media;

# and replace them with new addr + port (for NAT)
my @new_media,;
foreach (@media) {
      my ($port,@socks) = create_rtp_sockets( '192.168.178.1', $_->{range} );
      push @new_media, [ '192.168.178.1', $port ];
      ...
}
$sdp->replace_media_listen( @new_media );

πŸŽ€ CONSTRUCTOR πŸŽ€

new

The default constructor, bestie. Depending on the kind of arguments it branches into new_from_string or new_from_parts. Go read those, they're right below. ⬇️

new_from_string ( STRING )

Creates an object from STRING containing the SDP data. If the SDP is invalid it raises an exception (like die()). 🚨

new_from_parts ( \%GLOBAL, @MEDIA )

Creates an object from a specification. %GLOBAL describes the global keys β€” usually you just have a common "addr" for all the media, but any of the keys defined in RFC2327 can be used. 🌈

@MEDIA is a list of hash references, one hash for each media part. These hashes can contain as keys the one-letter keys specified in RFC2327 and/or the special keys for constructing the 'c' and 'm' line:

  • addr β€” the address, used in the 'c' line.
  • port β€” the port number
  • range β€” range of ports; for RTP/AVP defaults to 2, else 1
  • media β€” the media typ, e.g. 'audio','video',...
  • proto β€” transport protocol, usually 'RTP/AVP' or 'udp'

If the SDP should contain multiple values for the same key in the same media section, you can specify the value for the key as a \@list instead of a string. (This is often the case for 'a' lines, iykyk.) πŸ“


πŸ’œ METHODS πŸ’œ

as_string

Returns the string representation for the object. ✨

content_type

Returns 'application/sdp'. That's it. That's the whole method. Slay. πŸ’…

get_media

Returns a list of all media described in the SDP. If the caller expects an array the result will be a list, otherwise a reference to a list. 🎁

Each element of the list is a hash with these keys:

  • addr β€” IP4/IP6 address for media
  • port β€” start port
  • range β€” range for ports
  • proto β€” media proto, usually 'RTP/AVP' or 'udp'
  • media β€” media typ, usually 'audio', 'video' or 'data'
  • fmt β€” format info from media line as \@list, e.g "[ 0,10,5 ]".
  • lines β€” all lines from the media description as \@list of [ key,value ].
⚠️ WARNING! You should never manipulate the values you got from this function, because this might affect the object's internals. Like, do not touch. Hands off. It's giving "look, don't lick". πŸ˜­πŸ™ˆ

replace_media_listen ( NEW_MEDIA )

Replaces the existing media in the object with new media. Super useful for NAT. πŸ”₯

NEW_MEDIA is either an array or a reference to an array. Each element in the list consists of the new [ addr,port ] mapping for the matching media entry.

The number of entries in the list should be the same as the number of media entries in the object (see get_media). If that is not the case, it will die(). πŸ’€ No partial credit, bestie.

name2int ( NAME, INDEX )

Returns the RTP payload id for NAME (e.g. "telephone-event/8000"). 🎯

INDEX is the index into the list of media information, matching the list returned from get_media. INDEX can also be 'audio','video'.., which will then lookup at the first matching entry in the media list. Cute, right? πŸ₯°


and that's the whole page, bestie!! this was perl v5.40.1, dated 2025-12-07, straight from the Net::SIP::SDP(3pm) page itself. go forth and parse those session descriptions, you gorgeous genius πŸ«ΆπŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from