Skip to content

Commit

Permalink
Improve codec not matched error by including kind
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus committed Nov 10, 2024
1 parent 340fd81 commit fde04bd
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions internal/streams/add_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,45 @@ func formatError(consMedias, prodMedias []*core.Media, prodErrors []error) error

// 2. Return "codecs not matched"
if prodMedias != nil {
var prod, cons string
var prod, cons map[string]string = make(map[string]string), make(map[string]string)

for _, media := range prodMedias {
if media.Direction == core.DirectionRecvonly {
for _, codec := range media.Codecs {
prod = appendString(prod, codec.PrintName())
if _, ok := prod[codec.Name]; !ok {
prod[media.Kind] = ""
}
prod[media.Kind] = appendString(prod[media.Kind], codec.PrintName())
}
}
}

for _, media := range consMedias {
if media.Direction == core.DirectionSendonly {
for _, codec := range media.Codecs {
cons = appendString(cons, codec.PrintName())
if _, ok := cons[codec.Name]; !ok {
cons[media.Kind] = ""
}
cons[media.Kind] = appendString(cons[media.Kind], codec.PrintName())
}
}
}

return errors.New("streams: codecs not matched: " + prod + " => " + cons)
return errors.New("streams: codecs not matched: " + mapToString(prod) + " => " + mapToString(cons))
}

// 3. Return unknown error
return errors.New("streams: unknown error")
}

func mapToString(m map[string]string) string {
var s string
for k, v := range m {
s = appendString(s, "("+k+": "+v+")")
}
return s
}

func appendString(s, elem string) string {
if strings.Contains(s, elem) {
return s
Expand Down

0 comments on commit fde04bd

Please sign in to comment.