Agree - we need to use all the names found in the original SDP and try to keep those names correct on the SIP UA side.MikeTelis wrote: Thus, we need to use the names from original SDP (or am I missing something?).
Different codecs for different VSP
Re: Different codecs for different VSP
Re: Different codecs for different VSP
So, I've simplified the code by removing all a=* manipulations, and I added codecs() method returning a comma-separated list of codecs.
I gave it a whirl and it works just as expected. Check out and let me know if you find anything unusual.
Update: Optimized the code.
Code: Select all
class SDP
CRLF = "\r\n"
def initialize sdp, &block
@lines = sdp.split(CRLF); @codecs = {}
@lines.each_with_index do |ln, i|
ln =~ /^a=rtpmap:(\d+)\s+(.+)\// and @codecs[$2.upcase] = $1.to_i
!@m && ln =~ /^(m=.*RTP\/AVP\s+)(.+)$/ and (@mstr = $1; @m = $2.split(/\s+/).map {|x| x.to_i}; @pos = i)
end
instance_eval(&block) if block_given?
end
def priority(order); requested = codec2pt(order); @m = requested + (@m-requested); self; end
def delete(clist); @m = @m - codec2pt(clist); self; end
def supported?(codec); @codecs[codec.upcase]; end
def to_s; @pos && (@lines[@pos] = @mstr + @m.join(' '); @lines.join(CRLF)); end; alias :to_str :to_s
def codecs; @codecs.keys.join(', '); end
private
# Find PTs for requested codecs, remove codecs not listed in original m=*
def codec2pt(s); s.gsub(/\s+/,'').split(',').map{|x| supported?(x)}.compact; end
end
Update: Optimized the code.