inc_sdp.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # SDP template
  2. sdp_templ = \
  3. """v=0\r
  4. o=- 1 1 $NET_TYPE $ADDR_TYPE $LOCAL_IP\r
  5. s=pjmedia\r
  6. t=0 0\r
  7. $SDP_LINES"""
  8. sdp_media_templ = \
  9. """m=$MEDIA_TYPE $PORT $TRANSPORT 0\r
  10. c=$NET_TYPE $ADDR_TYPE $LOCAL_IP\r
  11. $SDP_LINES"""
  12. # Create SDP session
  13. def session(local_ip="127.0.0.1", extra_lines="", net_type="IN", addr_type="IP4"):
  14. sdp = sdp_templ
  15. sdp = sdp.replace("$NET_TYPE", net_type)
  16. sdp = sdp.replace("$ADDR_TYPE", addr_type)
  17. sdp = sdp.replace("$LOCAL_IP", local_ip)
  18. sdp = sdp.replace("$SDP_LINES", extra_lines)
  19. return sdp
  20. # Create basic SDP media
  21. def media(media_type="audio", local_port=4000, local_ip="127.0.0.1", extra_lines="",
  22. net_type = "IN", addr_type="IP4", transport="RTP/AVP"):
  23. sdp = sdp_media_templ
  24. sdp = sdp.replace("$MEDIA_TYPE", media_type)
  25. sdp = sdp.replace("$LOCAL_IP", local_ip)
  26. sdp = sdp.replace("$PORT", str(local_port))
  27. sdp = sdp.replace("$NET_TYPE", net_type)
  28. sdp = sdp.replace("$ADDR_TYPE", addr_type)
  29. sdp = sdp.replace("$TRANSPORT", transport)
  30. sdp = sdp.replace("$SDP_LINES", extra_lines)
  31. return sdp