Skip to content

Commit

Permalink
Merge pull request #17 from eTaulay/master
Browse files Browse the repository at this point in the history
add rs fec
  • Loading branch information
notedit authored Feb 29, 2024
2 parents 2a62954 + bed0ae8 commit 4ae033d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
41 changes: 28 additions & 13 deletions codecinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
)

type CodecInfo struct {
codec string
payload int
rtx int
params map[string]string
rtcpfbs []*RTCPFeedbackInfo
rate int
codec string
payload int
rtx int
params map[string]string
rtcpfbs []*RTCPFeedbackInfo
rate int
encoding int
}

func NewCodecInfo(codec string, payload int, rate int) *CodecInfo {
Expand All @@ -31,12 +32,13 @@ func NewCodecInfo(codec string, payload int, rate int) *CodecInfo {
func (c *CodecInfo) Clone() *CodecInfo {

codecInfo := &CodecInfo{
codec: c.codec,
payload: c.payload,
rtx: c.rtx,
params: make(map[string]string),
rtcpfbs: []*RTCPFeedbackInfo{},
rate: c.rate,
codec: c.codec,
payload: c.payload,
rtx: c.rtx,
params: make(map[string]string),
rtcpfbs: []*RTCPFeedbackInfo{},
rate: c.rate,
encoding: c.encoding,
}

for key, param := range c.params {
Expand Down Expand Up @@ -84,6 +86,14 @@ func (c *CodecInfo) SetRate(rate int) {
c.rate = rate
}

func (c *CodecInfo) GetEncoding() int {
return c.encoding
}

func (c *CodecInfo) SetEncoding(encoding int) {
c.encoding = encoding
}

func (c *CodecInfo) GetParam(key string) string {
if c.HasParam(key) {
return c.params[key]
Expand Down Expand Up @@ -134,12 +144,16 @@ func CodecMapFromNames(names []string, rtx bool, rtcpfbs []*RTCPFeedbackInfo) ma

var pt int
var rate int
var encParam int = 0
params := strings.Split(name, ";")
encoding := strings.Split(params[0], "/")
codecName := strings.TrimSpace(strings.ToLower(encoding[0]))
if len(encoding) == 2 {
if len(encoding) >= 2 {
rate, _ = strconv.Atoi(encoding[1])
}
if len(encoding) >= 3 {
encParam, _ = strconv.Atoi(encoding[2])
}
if codecName == "pcmu" {
pt = 0
} else if codecName == "pcma" {
Expand All @@ -150,6 +164,7 @@ func CodecMapFromNames(names []string, rtx bool, rtcpfbs []*RTCPFeedbackInfo) ma
}

codec := NewCodecInfo(codecName, pt, rate)
codec.SetEncoding(encParam)

if rtx && codecName != "ulpfec" && codecName != "flexfec-03" && codecName != "red" {
basePt++
Expand Down
1 change: 1 addition & 0 deletions mediainfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func (m *MediaInfo) AnswerCapability(cap *Capability) *MediaInfo {
cloned.SetRTX(codec.GetRTX())
}
cloned.SetRate(codec.GetRate())
cloned.SetEncoding(codec.GetEncoding())
cloned.AddParams(codec.GetParams())
answer.AddCodec(cloned)
}
Expand Down
20 changes: 19 additions & 1 deletion sdpinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ func (s *SDPInfo) String() string {
}

for _, codec := range media.GetCodecs() {

if strings.ToLower(codec.GetCodec()) == "rsfec" {
continue
}
if "video" == strings.ToLower(media.GetType()) {
mediaMap.Rtp = append(mediaMap.Rtp, &transform.RtpStruct{
Payload: codec.GetPayload(),
Expand Down Expand Up @@ -483,6 +485,18 @@ func (s *SDPInfo) String() string {
}
}

for _, codec := range media.GetCodecs() {
if len(mediaMap.Rtp) > 0 && strings.ToLower(codec.GetCodec()) == "rsfec" {
mediaMap.Rtp = append(mediaMap.Rtp, &transform.RtpStruct{
Payload: codec.GetPayload(),
Codec: codec.GetCodec(),
Rate: codec.GetRate(),
Encoding: codec.GetEncoding(),
})
break
}
}

payloads := []int{}

for _, rtp := range mediaMap.Rtp {
Expand Down Expand Up @@ -938,6 +952,10 @@ func Parse(sdp string) (*SDPInfo, error) {
aptint, _ := strconv.Atoi(apt)
apts[aptint] = payload
}
} else if strings.ToUpper(codec) == "RSFEC" {
codecInfo := NewCodecInfo(codec, payload, rate)
codecInfo.SetEncoding(fmt.Encoding)
mediaInfo.AddCodec(codecInfo)
} else {
codecInfo := NewCodecInfo(codec, payload, rate)
codecInfo.AddParams(params)
Expand Down

0 comments on commit 4ae033d

Please sign in to comment.