From fde04bd62512cfc4eb998354381a31a7f9ed21cc Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Sun, 10 Nov 2024 19:27:59 +0100 Subject: [PATCH] Improve codec not matched error by including kind --- internal/streams/add_consumer.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/streams/add_consumer.go b/internal/streams/add_consumer.go index d72e17ee..f1c9aebc 100644 --- a/internal/streams/add_consumer.go +++ b/internal/streams/add_consumer.go @@ -130,12 +130,15 @@ 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()) } } } @@ -143,18 +146,29 @@ func formatError(consMedias, prodMedias []*core.Media, prodErrors []error) error 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