From fde04bd62512cfc4eb998354381a31a7f9ed21cc Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Sun, 10 Nov 2024 19:27:59 +0100 Subject: [PATCH 1/2] 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 From 9ee8174d5f12382831f1f2b36c094f416738c153 Mon Sep 17 00:00:00 2001 From: Alex X Date: Mon, 11 Nov 2024 16:36:51 +0300 Subject: [PATCH 2/2] Code refactoring for #1448 --- internal/streams/add_consumer.go | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/internal/streams/add_consumer.go b/internal/streams/add_consumer.go index f1c9aebc..7400ce6e 100644 --- a/internal/streams/add_consumer.go +++ b/internal/streams/add_consumer.go @@ -130,15 +130,12 @@ func formatError(consMedias, prodMedias []*core.Media, prodErrors []error) error // 2. Return "codecs not matched" if prodMedias != nil { - var prod, cons map[string]string = make(map[string]string), make(map[string]string) + var prod, cons string for _, media := range prodMedias { if media.Direction == core.DirectionRecvonly { for _, codec := range media.Codecs { - if _, ok := prod[codec.Name]; !ok { - prod[media.Kind] = "" - } - prod[media.Kind] = appendString(prod[media.Kind], codec.PrintName()) + prod = appendString(prod, media.Kind+":"+codec.PrintName()) } } } @@ -146,29 +143,18 @@ func formatError(consMedias, prodMedias []*core.Media, prodErrors []error) error for _, media := range consMedias { if media.Direction == core.DirectionSendonly { for _, codec := range media.Codecs { - if _, ok := cons[codec.Name]; !ok { - cons[media.Kind] = "" - } - cons[media.Kind] = appendString(cons[media.Kind], codec.PrintName()) + cons = appendString(cons, media.Kind+":"+codec.PrintName()) } } } - return errors.New("streams: codecs not matched: " + mapToString(prod) + " => " + mapToString(cons)) + return errors.New("streams: codecs not matched: " + prod + " => " + 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