Implement suggestion
This commit is contained in:
@@ -223,6 +223,8 @@ func parseArgs(s string) *ffmpeg.Args {
|
|||||||
s += "?video&audio"
|
s += "?video&audio"
|
||||||
}
|
}
|
||||||
s += "&source=ffmpeg:" + url.QueryEscape(source)
|
s += "&source=ffmpeg:" + url.QueryEscape(source)
|
||||||
|
// change codec not matched error level to debug
|
||||||
|
s += "&" + string(streams.CodecNotMatchedErrorCode) + "=" + zerolog.DebugLevel.String()
|
||||||
args.Input = inputTemplate("rtsp", s, query)
|
args.Input = inputTemplate("rtsp", s, query)
|
||||||
} else if i = strings.Index(s, "?"); i > 0 {
|
} else if i = strings.Index(s, "?"); i > 0 {
|
||||||
switch s[:i] {
|
switch s[:i] {
|
||||||
|
|||||||
@@ -194,9 +194,11 @@ func tcpHandler(conn *rtsp.Conn) {
|
|||||||
if err := stream.AddConsumer(conn); err != nil {
|
if err := stream.AddConsumer(conn); err != nil {
|
||||||
logEvent := log.Warn()
|
logEvent := log.Warn()
|
||||||
|
|
||||||
if _, ok := err.(*streams.CodecNotMatchedError); ok && strings.HasPrefix(query.Get("source"), "ffmpeg") {
|
if err, ok := err.(*streams.ErrorWithErrorCode); ok {
|
||||||
// lower codec not matched error for ffmpeg to debug
|
level, parseErr := zerolog.ParseLevel(query.Get(err.Code()))
|
||||||
logEvent = log.Debug()
|
if parseErr == nil {
|
||||||
|
logEvent = log.WithLevel(level)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logEvent.Err(err).Str("stream", name).Msg("[rtsp]")
|
logEvent.Err(err).Str("stream", name).Msg("[rtsp]")
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package streams
|
package streams
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||||
@@ -125,19 +124,34 @@ func formatError(consMedias, prodMedias []*core.Media, prodErrors []error) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(text) != 0 {
|
if len(text) != 0 {
|
||||||
return errors.New("streams: " + text)
|
return &ErrorWithErrorCode{MultipleErrorCode, "streams: " + text}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Return "codecs not matched"
|
// 2. Return "codecs not matched"
|
||||||
if prodMedias != nil {
|
if prodMedias != nil {
|
||||||
return &CodecNotMatchedError{
|
var prod, cons string
|
||||||
producerMedias: prodMedias,
|
|
||||||
consumerMedias: consMedias,
|
for _, media := range prodMedias {
|
||||||
|
if media.Direction == core.DirectionRecvonly {
|
||||||
|
for _, codec := range media.Codecs {
|
||||||
|
prod = appendString(prod, codec.PrintName())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, media := range consMedias {
|
||||||
|
if media.Direction == core.DirectionSendonly {
|
||||||
|
for _, codec := range media.Codecs {
|
||||||
|
cons = appendString(cons, codec.PrintName())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ErrorWithErrorCode{CodecNotMatchedErrorCode, "streams: codecs not matched: " + prod + " => " + cons}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Return unknown error
|
// 3. Return unknown error
|
||||||
return errors.New("streams: unknown error")
|
return &ErrorWithErrorCode{UnknownErrorCode, "streams: unknown error"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendString(s, elem string) string {
|
func appendString(s, elem string) string {
|
||||||
@@ -150,29 +164,23 @@ func appendString(s, elem string) string {
|
|||||||
return s + ", " + elem
|
return s + ", " + elem
|
||||||
}
|
}
|
||||||
|
|
||||||
type CodecNotMatchedError struct {
|
type ErrorCode string
|
||||||
producerMedias []*core.Media
|
|
||||||
consumerMedias []*core.Media
|
const (
|
||||||
|
CodecNotMatchedErrorCode ErrorCode = "codecNotMatched"
|
||||||
|
MultipleErrorCode ErrorCode = "multiple"
|
||||||
|
UnknownErrorCode ErrorCode = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ErrorWithErrorCode struct {
|
||||||
|
code ErrorCode
|
||||||
|
message string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *CodecNotMatchedError) Error() string {
|
func (e *ErrorWithErrorCode) Error() string {
|
||||||
var prod, cons string
|
return e.message
|
||||||
|
}
|
||||||
for _, media := range e.producerMedias {
|
|
||||||
if media.Direction == core.DirectionRecvonly {
|
func (e *ErrorWithErrorCode) Code() string {
|
||||||
for _, codec := range media.Codecs {
|
return string(e.code)
|
||||||
prod = appendString(prod, codec.PrintName())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, media := range e.consumerMedias {
|
|
||||||
if media.Direction == core.DirectionSendonly {
|
|
||||||
for _, codec := range media.Codecs {
|
|
||||||
cons = appendString(cons, codec.PrintName())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "streams: codecs not matched: " + prod + " => " + cons
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user