sdp

package module
v0.0.0-...-c5b7349 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2018 License: BSD-3-Clause Imports: 7 Imported by: 0

README

Build Status

rtcsdp for golang

draft-nandakumar-rtcweb-sdp

Examples
package main

import (
	"log"

	"github.com/adwpc/rtcsdp"
)

const chromeOffer = `
v=0
o=- 2670773066989454674 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio video data
a=msid-semantic: WMS X0EclBo2L6ejdTpXYKIgSFxeEeuWSgrgkJxf
m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:MsTv
a=ice-pwd:ldzjCz3mvZHU7bdmQdvG9E7R
a=ice-options:trickle
a=fingerprint:sha-256 A1:3E:57:FD:06:C7:C2:75:7D:39:C7:EC:2C:94:EB:CD:D3:94:AD:6B:73:F7:68:31:63:B5:4F:81:43:CC:B7:82
a=setup:actpass
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=sendrecv
a=rtcp-mux
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:106 CN/32000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:112 telephone-event/32000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=ssrc:2674873303 cname:k40qiudEPhB/+NLQ
a=ssrc:2674873303 msid:X0EclBo2L6ejdTpXYKIgSFxeEeuWSgrgkJxf 96deaecd-ec83-4324-9eed-51641c51166d
a=ssrc:2674873303 mslabel:X0EclBo2L6ejdTpXYKIgSFxeEeuWSgrgkJxf
a=ssrc:2674873303 label:96deaecd-ec83-4324-9eed-51641c51166d
m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 123 127 122 125 107 108 109 124
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:MsTv
a=ice-pwd:ldzjCz3mvZHU7bdmQdvG9E7R
a=ice-options:trickle
a=fingerprint:sha-256 A1:3E:57:FD:06:C7:C2:75:7D:39:C7:EC:2C:94:EB:CD:D3:94:AD:6B:73:F7:68:31:63:B5:4F:81:43:CC:B7:82
a=setup:actpass
a=mid:video
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:3gpp:video-orientation
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=sendrecv
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 VP8/90000
a=rtcp-fb:96 goog-remb
a=rtcp-fb:96 transport-cc
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack
a=rtcp-fb:96 nack pli
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 VP9/90000
a=rtcp-fb:98 goog-remb
a=rtcp-fb:98 transport-cc
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack
a=rtcp-fb:98 nack pli
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 H264/90000
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=fmtp:100 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:102 H264/90000
a=rtcp-fb:102 goog-remb
a=rtcp-fb:102 transport-cc
a=rtcp-fb:102 ccm fir
a=rtcp-fb:102 nack
a=rtcp-fb:102 nack pli
a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtpmap:123 rtx/90000
a=fmtp:123 apt=102
a=rtpmap:127 H264/90000
a=rtcp-fb:127 goog-remb
a=rtcp-fb:127 transport-cc
a=rtcp-fb:127 ccm fir
a=rtcp-fb:127 nack
a=rtcp-fb:127 nack pli
a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d0032
a=rtpmap:122 rtx/90000
a=fmtp:122 apt=127
a=rtpmap:125 H264/90000
a=rtcp-fb:125 goog-remb
a=rtcp-fb:125 transport-cc
a=rtcp-fb:125 ccm fir
a=rtcp-fb:125 nack
a=rtcp-fb:125 nack pli
a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640032
a=rtpmap:107 rtx/90000
a=fmtp:107 apt=125
a=rtpmap:108 red/90000
a=rtpmap:109 rtx/90000
a=fmtp:109 apt=108
a=rtpmap:124 ulpfec/90000
a=ssrc-group:FID 3122697176 552506581
a=ssrc:3122697176 cname:k40qiudEPhB/+NLQ
a=ssrc:3122697176 msid:X0EclBo2L6ejdTpXYKIgSFxeEeuWSgrgkJxf 8b27d69c-993d-4f36-a529-dbcd15fc7e0e
a=ssrc:3122697176 mslabel:X0EclBo2L6ejdTpXYKIgSFxeEeuWSgrgkJxf
a=ssrc:3122697176 label:8b27d69c-993d-4f36-a529-dbcd15fc7e0e
a=ssrc:552506581 cname:k40qiudEPhB/+NLQ
a=ssrc:552506581 msid:X0EclBo2L6ejdTpXYKIgSFxeEeuWSgrgkJxf 8b27d69c-993d-4f36-a529-dbcd15fc7e0e
a=ssrc:552506581 mslabel:X0EclBo2L6ejdTpXYKIgSFxeEeuWSgrgkJxf
a=ssrc:552506581 label:8b27d69c-993d-4f36-a529-dbcd15fc7e0e
m=application 9 DTLS/SCTP 5000
c=IN IP4 0.0.0.0
a=ice-ufrag:MsTv
a=ice-pwd:ldzjCz3mvZHU7bdmQdvG9E7R
a=ice-options:trickle
a=fingerprint:sha-256 A1:3E:57:FD:06:C7:C2:75:7D:39:C7:EC:2C:94:EB:CD:D3:94:AD:6B:73:F7:68:31:63:B5:4F:81:43:CC:B7:82
a=setup:actpass
a=mid:data
a=sctpmap:5000 webrtc-datachannel 1024
`

func main() {
	log.Println("==================decode======================")

	if sdp, err := sdp.NewSDP(chromeOffer); err == nil {
		log.Println("==================encode======================")
		log.Println(sdp.Encode())
	} else {
		log.Println(err.Error())
	}
}

tested sdp
  • chrome_avd.sdp

    • audio
    • video
    • data
  • firefox_av.sdp

    • audio
    • video
  • janus_av.sdp

    • audio
    • video

Documentation

Index

Constants

View Source
const (
	CAND_UDP = "udp"
	CAND_TCP = "tcp"
)

candidate

View Source
const (
	CAND_RTP  = "rtp"
	CAND_RTCP = "rctp"
)
View Source
const (
	CAND_HOST  = "host"
	CAND_SRFLX = "srflx"
	CAND_RELAY = "relay"
)
View Source
const (
	MEDIA_UNKNOWN   = ""
	MEDIA_AUDIO     = "m=audio"
	MEDIA_VIDEO     = "m=video"
	MEDIA_DATA_CHAN = "m=application"
)
View Source
const (
	CAND_TCP_ACTIVE = "active"
)
View Source
const (
	DTLS_SHA256 = "sha-256"
)
View Source
const (
	SDP_ERR_NONE = ""
)

Variables

This section is empty.

Functions

func SdpErrFmt

func SdpErrFmt(errCode, errStr string) string

func SplitLines

func SplitLines(s *string) *[]Line

func UInt

func UInt(s string) uint

Types

type AVMedia

type AVMedia struct {
	MediaBase
	ExtMaps  []ExtMap        //extmap
	RTPMap   map[string]*RTP //codec parameters
	Maxptime string          //audio codec maxptime
}

func (*AVMedia) Decode

func (m *AVMedia) Decode(l *Line) (errStr string)

func (*AVMedia) Encode

func (m *AVMedia) Encode(l *Line)

type Candidate

type Candidate struct {
	ID         uint   //candidate id
	TransType  string //1 rtp 2 rtcp
	Proto      string //udp tcp
	Priority   uint   //priority, webrtc use bigger one
	IP         net.IP //ip
	Port       uint   //port
	HostType   string //typ host(p2p)    typ srflx(stun)    typ relay(turn)
	TcpType    string //tcptype  e.g. active
	RAddr      net.IP //used by turn or stun
	RPort      uint   //used by turn or stun
	Generation string //generation
	IsEnd      bool   //a=end-of-candidates
}

type Connection

type Connection struct {
	NetType  string
	AddrType string
	Addr     string
}

c=<nettype> <addrtype> <connection-address>

type DTLS

type DTLS struct {
	Finger     string //fingerprint
	FingerAlgo string //fingerprint algorithm
	Conn       string //connection e.g. a=connection:new
	Setup      string //setup
	TlsID      string //tls-id
}

func (*DTLS) Decode

func (d *DTLS) Decode(l *Line) (err string)

func (*DTLS) Encode

func (d *DTLS) Encode(l *Line)

type DataChannel

type DataChannel struct {
	MediaBase
	SctpMap SCTPMAP

	//a=sctp-port:5000
	//a=max-message-size:100000
	SctpPort   int
	MaxMsgSize int
}

func (*DataChannel) Decode

func (m *DataChannel) Decode(l *Line) (errStr string)

func (*DataChannel) Encode

func (m *DataChannel) Encode(l *Line)

type ExtMap

type ExtMap struct {
	Key string
	Val string
}

type ICE

type ICE struct {
	Cands    []*Candidate //ICE candidates
	Ufrag    string       //ICE ufrag
	Pwd      string       //ICE pwd
	Options  string       //ICE options e.g. trikle
	Identity string       //https://tools.ietf.org/html/draft-ietf-rtcweb-security-arch-14#section-5.6.4.2
}

func (*ICE) Decode

func (i *ICE) Decode(l *Line) (errStr string)

e.g. a=ice-ufrag:1eK7W+oSBMWFa8Pe a=ice-pwd:V7nbdVnnGGW0F+ZQfiz9841Z a=ice-options:trickle a=identity:...

func (*ICE) Encode

func (i *ICE) Encode(l *Line)

type Line

type Line string

func (*Line) Append

func (l *Line) Append(format string, a ...interface{})

if param exist append

func (*Line) AppendIfHas

func (l *Line) AppendIfHas(flag interface{}, format string, a ...interface{})

func (*Line) Decode

func (l *Line) Decode(format string, a ...interface{}) (errStr string)

func (*Line) DecodeIfHas

func (l *Line) DecodeIfHas(flag, format string, a ...interface{}) (errStr string)

func (*Line) Has

func (l *Line) Has(subStr string) bool

func (*Line) Str

func (l *Line) Str() string

type MediaBase

type MediaBase struct {
	//m=...
	Type   string //media type, audio video data ...
	Port   string //transport port
	Proto  string //transport protocol
	Format string //for DataChannel , audio video use rtpmap

	//c=...
	ConnData Connection //connection
	//a=rtcp:1 IN IP4 0.0.0.0
	Rtcp      RTCP //rtcp
	RtcpRsize bool
	//a=sendrecv
	Mode string //sendonly recvonly sendrecv
	//a=rtcp-mux
	RtcpMux     bool   //rtp and rtcp can use the same port
	RtcpMuxOnly bool   //rtp and rtcp can use the same port only
	BundleOnly  bool   //a=bundle-only
	Ice         ICE    //ICE
	Dtls        DTLS   //DTLS
	Mid         string //mid

	//如果ssrc>1才会有这行  =1不会有这行
	//a=ssrc-group:FID 2231627014 632943048
	// SSRCFIDS []string         //ssrc group fid array
	SSRCS map[string]*SSRC //Synchronisation Source

	MsID string //firefox webrtc media stream id
}

func (*MediaBase) DecodeDTLSFinger

func (m *MediaBase) DecodeDTLSFinger(l *Line) (errStr string)

func (*MediaBase) DecodeICE

func (m *MediaBase) DecodeICE(l *Line) (errStr string)

type Origin

type Origin struct {
	UserName    string
	SessID      string
	SessVersion string
	NetType     string
	AddrType    string
	Address     string
}

o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>

func (*Origin) Decode

func (o *Origin) Decode(l *Line) (errStr string)

func (*Origin) Encode

func (o *Origin) Encode() string

e.g. o=- 1464328034279435 1464328034279435 IN IP4 192.168.24.158

type RTCP

type RTCP struct {
	Port    string
	NetType string
	IPType  string
	IP      string
}

a=rtcp:9 IN IP4 0.0.0.0

type RTP

type RTP struct {
	RtpFmtID     string
	RtpFmtVal    string
	RtpFmtParam  string
	RtcpFbParams []string
}

e.g. a=rtpmap:111 opus/48000/2 a=rtcp-fb:111 transport-cc a=fmtp:111 minptime=10; useinbandfec=1 a=rtpmap:103 ISAC/16000 a=rtpmap:104 ISAC/32000 a=rtpmap:9 G722/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:106 CN/32000 a=rtpmap:105 CN/16000 a=rtpmap:13 CN/8000 a=rtpmap:126 telephone-event/8000

type SCTPMAP

type SCTPMAP struct {
	Number     uint
	App        string
	MaxMsgSize uint
	Streams    uint
}

a=sctpmap:50000 webrtc-datachannel 1024 a=sctpmap:sctpmap-number app [max-message-size] [streams]

func (*SCTPMAP) Decode

func (s *SCTPMAP) Decode(l *Line) (errStr string)

type SDP

type SDP struct {
	Version     uint      //v=  (protocol version, must be 0)
	Origin      Origin    //o=  (originator and session identifier)
	SessName    string    //s=  (session name)
	ConnInfo    string    //c=* (connection information -- not required if included in all media)
	Time        TIME      //t=  (time the session is active)
	GroupBundle [3]string //a=group:BUNDLE audio video data (audio video use same port)
	GroupLS     [2]string //a=group:LS audio video  (mid1 mid2)

	// LS
	IceTrickle bool   //a=ice-options:trickle
	Identity   string //a=identity:...
	MsIDSema   string //a=msid-semantic: WMS ...(webrtc media stream id semantic)
	//Media
	Medias []media
}

func NewSDP

func NewSDP(s string) (*SDP, error)

func (*SDP) Decode

func (sdp *SDP) Decode(s string) error

func (*SDP) DecodeGlobal

func (sdp *SDP) DecodeGlobal(s *string) error

func (*SDP) Encode

func (sdp *SDP) Encode() string

func (*SDP) EncodeGlobal

func (sdp *SDP) EncodeGlobal() string

func (*SDP) EncodeMedia

func (sdp *SDP) EncodeMedia() string

type SSRC

type SSRC struct {
	ID      string
	CName   string
	MsID    string
	MsLabel string
	Label   string
}

type TIME

type TIME struct {
	Start uint
	End   uint
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL