update golangci-lint (#2868)
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
linters:
|
||||
enable:
|
||||
- asciicheck
|
||||
- bidichk
|
||||
- bodyclose
|
||||
- dupl
|
||||
- errorlint
|
||||
- exportloopref
|
||||
- gochecknoinits
|
||||
- gocritic
|
||||
@@ -13,6 +16,7 @@ linters:
|
||||
- prealloc
|
||||
- revive
|
||||
- unconvert
|
||||
- tparallel
|
||||
- wastedassign
|
||||
- whitespace
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
BASE_IMAGE = golang:1.21-alpine3.18
|
||||
LINT_IMAGE = golangci/golangci-lint:v1.55.0
|
||||
LINT_IMAGE = golangci/golangci-lint:v1.55.2
|
||||
NODE_IMAGE = node:16-alpine3.18
|
||||
ALPINE_IMAGE = alpine:3.18
|
||||
RPI32_IMAGE = balenalib/raspberry-pi:bullseye-run-20230712
|
||||
|
||||
Vendored
+5
-5
@@ -38,12 +38,12 @@ func loadEnvInternal(env map[string]string, prefix string, prv reflect.Value) er
|
||||
}
|
||||
err := i.UnmarshalEnv(prefix, ev)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %s", prefix, err)
|
||||
return fmt.Errorf("%s: %w", prefix, err)
|
||||
}
|
||||
} else if envHasAtLeastAKeyWithPrefix(env, prefix) {
|
||||
err := i.UnmarshalEnv(prefix, "")
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %s", prefix, err)
|
||||
return fmt.Errorf("%s: %w", prefix, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -66,7 +66,7 @@ func loadEnvInternal(env map[string]string, prefix string, prv reflect.Value) er
|
||||
}
|
||||
iv, err := strconv.ParseInt(ev, 10, 32)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %s", prefix, err)
|
||||
return fmt.Errorf("%s: %w", prefix, err)
|
||||
}
|
||||
prv.Elem().SetInt(iv)
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func loadEnvInternal(env map[string]string, prefix string, prv reflect.Value) er
|
||||
}
|
||||
iv, err := strconv.ParseUint(ev, 10, 32)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %s", prefix, err)
|
||||
return fmt.Errorf("%s: %w", prefix, err)
|
||||
}
|
||||
prv.Elem().SetUint(iv)
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func loadEnvInternal(env map[string]string, prefix string, prv reflect.Value) er
|
||||
}
|
||||
iv, err := strconv.ParseFloat(ev, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %s", prefix, err)
|
||||
return fmt.Errorf("%s: %w", prefix, err)
|
||||
}
|
||||
prv.Elem().SetFloat(iv)
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ func (pconf *Path) check(conf *Conf, name string) error {
|
||||
case name == "" || name[0] != '~': // normal path
|
||||
err := IsValidPathName(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid path name '%s': %s", name, err)
|
||||
return fmt.Errorf("invalid path name '%s': %w", name, err)
|
||||
}
|
||||
|
||||
default: // regular expression-based path
|
||||
@@ -320,14 +320,14 @@ func (pconf *Path) check(conf *Conf, name string) error {
|
||||
if pconf.SRTReadPassphrase != "" {
|
||||
err := srtCheckPassphrase(pconf.SRTReadPassphrase)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid 'readRTPassphrase': %v", err)
|
||||
return fmt.Errorf("invalid 'readRTPassphrase': %w", err)
|
||||
}
|
||||
}
|
||||
if pconf.Fallback != "" {
|
||||
if strings.HasPrefix(pconf.Fallback, "/") {
|
||||
err := IsValidPathName(pconf.Fallback[1:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("'%s': %s", pconf.Fallback, err)
|
||||
return fmt.Errorf("'%s': %w", pconf.Fallback, err)
|
||||
}
|
||||
} else {
|
||||
_, err := base.ParseURL(pconf.Fallback)
|
||||
@@ -384,7 +384,7 @@ func (pconf *Path) check(conf *Conf, name string) error {
|
||||
|
||||
err := srtCheckPassphrase(pconf.SRTPublishPassphrase)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid 'srtPublishPassphrase': %v", err)
|
||||
return fmt.Errorf("invalid 'srtPublishPassphrase': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ func doAuthentication(
|
||||
accessRequest,
|
||||
)
|
||||
if err != nil {
|
||||
return &defs.ErrAuthentication{Message: fmt.Sprintf("external authentication failed: %s", err)}
|
||||
return defs.AuthenticationError{Message: fmt.Sprintf("external authentication failed: %s", err)}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func doAuthentication(
|
||||
|
||||
if pathIPs != nil {
|
||||
if !ipEqualOrInRange(accessRequest.IP, pathIPs) {
|
||||
return &defs.ErrAuthentication{Message: fmt.Sprintf("IP %s not allowed", accessRequest.IP)}
|
||||
return defs.AuthenticationError{Message: fmt.Sprintf("IP %s not allowed", accessRequest.IP)}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,11 +132,11 @@ func doAuthentication(
|
||||
"IPCAM",
|
||||
accessRequest.RTSPNonce)
|
||||
if err != nil {
|
||||
return &defs.ErrAuthentication{Message: err.Error()}
|
||||
return defs.AuthenticationError{Message: err.Error()}
|
||||
}
|
||||
} else if !checkCredential(pathUser, accessRequest.User) ||
|
||||
!checkCredential(pathPass, accessRequest.Pass) {
|
||||
return &defs.ErrAuthentication{Message: "invalid credentials"}
|
||||
return defs.AuthenticationError{Message: "invalid credentials"}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -493,7 +493,7 @@ func (pa *path) doDescribe(req defs.PathDescribeReq) {
|
||||
return
|
||||
}
|
||||
|
||||
req.Res <- defs.PathDescribeRes{Err: defs.ErrPathNoOnePublishing{PathName: pa.name}}
|
||||
req.Res <- defs.PathDescribeRes{Err: defs.PathNoOnePublishingError{PathName: pa.name}}
|
||||
}
|
||||
|
||||
func (pa *path) doRemovePublisher(req defs.PathRemovePublisherReq) {
|
||||
@@ -584,7 +584,7 @@ func (pa *path) doAddReader(req defs.PathAddReaderReq) {
|
||||
return
|
||||
}
|
||||
|
||||
req.Res <- defs.PathAddReaderRes{Err: defs.ErrPathNoOnePublishing{PathName: pa.name}}
|
||||
req.Res <- defs.PathAddReaderRes{Err: defs.PathNoOnePublishingError{PathName: pa.name}}
|
||||
}
|
||||
|
||||
func (pa *path) doRemoveReader(req defs.PathRemoveReaderReq) {
|
||||
|
||||
@@ -38,7 +38,7 @@ func pathConfCanBeUpdated(oldPathConf *conf.Path, newPathConf *conf.Path) bool {
|
||||
func getConfForPath(pathConfs map[string]*conf.Path, name string) (string, *conf.Path, []string, error) {
|
||||
err := conf.IsValidPathName(name)
|
||||
if err != nil {
|
||||
return "", nil, nil, fmt.Errorf("invalid path name: %s (%s)", err, name)
|
||||
return "", nil, nil, fmt.Errorf("invalid path name: %w (%s)", err, name)
|
||||
}
|
||||
|
||||
// normal path
|
||||
|
||||
@@ -12,12 +12,12 @@ const (
|
||||
AuthProtocolSRT AuthProtocol = "srt"
|
||||
)
|
||||
|
||||
// ErrAuthentication is a authentication error.
|
||||
type ErrAuthentication struct {
|
||||
// AuthenticationError is a authentication error.
|
||||
type AuthenticationError struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *ErrAuthentication) Error() string {
|
||||
func (e AuthenticationError) Error() string {
|
||||
return "authentication failed: " + e.Message
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ import (
|
||||
"github.com/bluenviron/mediamtx/internal/stream"
|
||||
)
|
||||
|
||||
// ErrPathNoOnePublishing is returned when no one is publishing.
|
||||
type ErrPathNoOnePublishing struct {
|
||||
// PathNoOnePublishingError is returned when no one is publishing.
|
||||
type PathNoOnePublishingError struct {
|
||||
PathName string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ErrPathNoOnePublishing) Error() string {
|
||||
func (e PathNoOnePublishingError) Error() string {
|
||||
return fmt.Sprintf("no one is publishing to path '%s'", e.PathName)
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ func (e *Cmd) run() {
|
||||
|
||||
for {
|
||||
err := e.runOSSpecific()
|
||||
if err == errTerminated {
|
||||
if errors.Is(err, errTerminated) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package externalcmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -40,11 +41,11 @@ func (e *Cmd) runOSSpecific() error {
|
||||
if err == nil {
|
||||
return 0
|
||||
}
|
||||
ee, ok := err.(*exec.ExitError)
|
||||
if !ok {
|
||||
return 0
|
||||
var ee *exec.ExitError
|
||||
if errors.As(err, &ee) {
|
||||
ee.ExitCode()
|
||||
}
|
||||
return ee.ExitCode()
|
||||
return 0
|
||||
}()
|
||||
}()
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package formatprocessor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -98,7 +99,8 @@ func (t *formatProcessorAC3) ProcessRTPPacket( //nolint:dupl
|
||||
|
||||
frames, err := t.decoder.Decode(pkt)
|
||||
if err != nil {
|
||||
if err == rtpac3.ErrNonStartingPacketAndNoPrevious || err == rtpac3.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtpac3.ErrNonStartingPacketAndNoPrevious) ||
|
||||
errors.Is(err, rtpac3.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package formatprocessor //nolint:dupl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -100,7 +101,8 @@ func (t *formatProcessorAV1) ProcessRTPPacket( //nolint:dupl
|
||||
|
||||
tu, err := t.decoder.Decode(pkt)
|
||||
if err != nil {
|
||||
if err == rtpav1.ErrNonStartingPacketAndNoPrevious || err == rtpav1.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtpav1.ErrNonStartingPacketAndNoPrevious) ||
|
||||
errors.Is(err, rtpav1.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -2,6 +2,7 @@ package formatprocessor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
@@ -284,7 +285,8 @@ func (t *formatProcessorH264) ProcessRTPPacket( //nolint:dupl
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err == rtph264.ErrNonStartingPacketAndNoPrevious || err == rtph264.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtph264.ErrNonStartingPacketAndNoPrevious) ||
|
||||
errors.Is(err, rtph264.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -2,6 +2,7 @@ package formatprocessor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
@@ -303,7 +304,8 @@ func (t *formatProcessorH265) ProcessRTPPacket( //nolint:dupl
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err == rtph265.ErrNonStartingPacketAndNoPrevious || err == rtph265.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtph265.ErrNonStartingPacketAndNoPrevious) ||
|
||||
errors.Is(err, rtph265.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package formatprocessor //nolint:dupl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -99,7 +100,8 @@ func (t *formatProcessorMJPEG) ProcessRTPPacket( //nolint:dupl
|
||||
|
||||
frame, err := t.decoder.Decode(pkt)
|
||||
if err != nil {
|
||||
if err == rtpmjpeg.ErrNonStartingPacketAndNoPrevious || err == rtpmjpeg.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtpmjpeg.ErrNonStartingPacketAndNoPrevious) ||
|
||||
errors.Is(err, rtpmjpeg.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package formatprocessor //nolint:dupl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -98,7 +99,8 @@ func (t *formatProcessorMPEG1Audio) ProcessRTPPacket( //nolint:dupl
|
||||
|
||||
frames, err := t.decoder.Decode(pkt)
|
||||
if err != nil {
|
||||
if err == rtpmpeg1audio.ErrNonStartingPacketAndNoPrevious || err == rtpmpeg1audio.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtpmpeg1audio.ErrNonStartingPacketAndNoPrevious) ||
|
||||
errors.Is(err, rtpmpeg1audio.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package formatprocessor //nolint:dupl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -99,7 +100,8 @@ func (t *formatProcessorMPEG1Video) ProcessRTPPacket( //nolint:dupl
|
||||
|
||||
frame, err := t.decoder.Decode(pkt)
|
||||
if err != nil {
|
||||
if err == rtpmpeg1video.ErrNonStartingPacketAndNoPrevious || err == rtpmpeg1video.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtpmpeg1video.ErrNonStartingPacketAndNoPrevious) ||
|
||||
errors.Is(err, rtpmpeg1video.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package formatprocessor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -102,7 +103,7 @@ func (t *formatProcessorMPEG4Audio) ProcessRTPPacket( //nolint:dupl
|
||||
|
||||
aus, err := t.decoder.Decode(pkt)
|
||||
if err != nil {
|
||||
if err == rtpmpeg4audio.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtpmpeg4audio.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -2,6 +2,7 @@ package formatprocessor //nolint:dupl
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -140,7 +141,7 @@ func (t *formatProcessorMPEG4Video) ProcessRTPPacket( //nolint:dupl
|
||||
|
||||
frame, err := t.decoder.Decode(pkt)
|
||||
if err != nil {
|
||||
if err == rtpmpeg4video.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtpmpeg4video.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package formatprocessor //nolint:dupl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -99,7 +100,8 @@ func (t *formatProcessorVP8) ProcessRTPPacket( //nolint:dupl
|
||||
|
||||
frame, err := t.decoder.Decode(pkt)
|
||||
if err != nil {
|
||||
if err == rtpvp8.ErrNonStartingPacketAndNoPrevious || err == rtpvp8.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtpvp8.ErrNonStartingPacketAndNoPrevious) ||
|
||||
errors.Is(err, rtpvp8.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package formatprocessor //nolint:dupl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -99,7 +100,8 @@ func (t *formatProcessorVP9) ProcessRTPPacket( //nolint:dupl
|
||||
|
||||
frame, err := t.decoder.Decode(pkt)
|
||||
if err != nil {
|
||||
if err == rtpvp9.ErrNonStartingPacketAndNoPrevious || err == rtpvp9.ErrMorePacketsNeeded {
|
||||
if errors.Is(err, rtpvp9.ErrNonStartingPacketAndNoPrevious) ||
|
||||
errors.Is(err, rtpvp9.ErrMorePacketsNeeded) {
|
||||
return u, nil
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -311,7 +311,7 @@ func (r *Reader) Read() (*Message, error) {
|
||||
|
||||
msg, err := rc.readMessage(typ)
|
||||
if err != nil {
|
||||
if err == errMoreChunksNeeded {
|
||||
if errors.Is(err, errMoreChunksNeeded) {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -2,6 +2,7 @@ package rtmp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -111,7 +112,7 @@ func trackFromH264DecoderConfig(data []byte) (format.Format, error) {
|
||||
var conf h264conf.Conf
|
||||
err := conf.Unmarshal(data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse H264 config: %v", err)
|
||||
return nil, fmt.Errorf("unable to parse H264 config: %w", err)
|
||||
}
|
||||
|
||||
return &format.H264{
|
||||
@@ -201,7 +202,7 @@ func tracksFromMetadata(conn *Conn, payload []interface{}) (format.Format, forma
|
||||
} else if msg.Type == message.VideoTypeAU && msg.IsKeyFrame {
|
||||
nalus, err := h264.AVCCUnmarshal(msg.Payload)
|
||||
if err != nil {
|
||||
if err == h264.ErrAVCCNoNALUs {
|
||||
if errors.Is(err, h264.ErrAVCCNoNALUs) {
|
||||
continue
|
||||
}
|
||||
return nil, nil, err
|
||||
@@ -249,7 +250,7 @@ func tracksFromMetadata(conn *Conn, payload []interface{}) (format.Format, forma
|
||||
var hvcc mp4.HvcC
|
||||
_, err := mp4.Unmarshal(bytes.NewReader(msg.Config), uint64(len(msg.Config)), &hvcc, mp4.Context{})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("invalid H265 configuration: %v", err)
|
||||
return nil, nil, fmt.Errorf("invalid H265 configuration: %w", err)
|
||||
}
|
||||
|
||||
vps := h265FindNALU(hvcc.NaluArrays, h265.NALUType_VPS_NUT)
|
||||
@@ -270,13 +271,13 @@ func tracksFromMetadata(conn *Conn, payload []interface{}) (format.Format, forma
|
||||
var av1c mp4.Av1C
|
||||
_, err := mp4.Unmarshal(bytes.NewReader(msg.Config), uint64(len(msg.Config)), &av1c, mp4.Context{})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("invalid AV1 configuration: %v", err)
|
||||
return nil, nil, fmt.Errorf("invalid AV1 configuration: %w", err)
|
||||
}
|
||||
|
||||
// parse sequence header and metadata contained in ConfigOBUs, but do not use them
|
||||
_, err = av1.BitstreamUnmarshal(av1c.ConfigOBUs, false)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("invalid AV1 configuration: %v", err)
|
||||
return nil, nil, fmt.Errorf("invalid AV1 configuration: %w", err)
|
||||
}
|
||||
|
||||
videoTrack = &format.AV1{
|
||||
@@ -287,7 +288,7 @@ func tracksFromMetadata(conn *Conn, payload []interface{}) (format.Format, forma
|
||||
var vpcc mp4.VpcC
|
||||
_, err := mp4.Unmarshal(bytes.NewReader(msg.Config), uint64(len(msg.Config)), &vpcc, mp4.Context{})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("invalid VP9 configuration: %v", err)
|
||||
return nil, nil, fmt.Errorf("invalid VP9 configuration: %w", err)
|
||||
}
|
||||
|
||||
videoTrack = &format.VP9{
|
||||
@@ -464,7 +465,7 @@ func (r *Reader) OnDataAV1(cb OnDataAV1Func) {
|
||||
if msg, ok := msg.(*message.ExtendedCodedFrames); ok {
|
||||
tu, err := av1.BitstreamUnmarshal(msg.Payload, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode bitstream: %v", err)
|
||||
return fmt.Errorf("unable to decode bitstream: %w", err)
|
||||
}
|
||||
|
||||
cb(msg.DTS, tu)
|
||||
@@ -490,10 +491,10 @@ func (r *Reader) OnDataH265(cb OnDataH26xFunc) {
|
||||
case *message.Video:
|
||||
au, err := h264.AVCCUnmarshal(msg.Payload)
|
||||
if err != nil {
|
||||
if err == h264.ErrAVCCNoNALUs {
|
||||
if errors.Is(err, h264.ErrAVCCNoNALUs) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unable to decode AVCC: %v", err)
|
||||
return fmt.Errorf("unable to decode AVCC: %w", err)
|
||||
}
|
||||
|
||||
cb(msg.DTS+msg.PTSDelta, au)
|
||||
@@ -501,10 +502,10 @@ func (r *Reader) OnDataH265(cb OnDataH26xFunc) {
|
||||
case *message.ExtendedFramesX:
|
||||
au, err := h264.AVCCUnmarshal(msg.Payload)
|
||||
if err != nil {
|
||||
if err == h264.ErrAVCCNoNALUs {
|
||||
if errors.Is(err, h264.ErrAVCCNoNALUs) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unable to decode AVCC: %v", err)
|
||||
return fmt.Errorf("unable to decode AVCC: %w", err)
|
||||
}
|
||||
|
||||
cb(msg.DTS, au)
|
||||
@@ -512,10 +513,10 @@ func (r *Reader) OnDataH265(cb OnDataH26xFunc) {
|
||||
case *message.ExtendedCodedFrames:
|
||||
au, err := h264.AVCCUnmarshal(msg.Payload)
|
||||
if err != nil {
|
||||
if err == h264.ErrAVCCNoNALUs {
|
||||
if errors.Is(err, h264.ErrAVCCNoNALUs) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unable to decode AVCC: %v", err)
|
||||
return fmt.Errorf("unable to decode AVCC: %w", err)
|
||||
}
|
||||
|
||||
cb(msg.DTS+msg.PTSDelta, au)
|
||||
@@ -534,7 +535,7 @@ func (r *Reader) OnDataH264(cb OnDataH26xFunc) {
|
||||
var conf h264conf.Conf
|
||||
err := conf.Unmarshal(msg.Payload)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse H264 config: %v", err)
|
||||
return fmt.Errorf("unable to parse H264 config: %w", err)
|
||||
}
|
||||
|
||||
au := [][]byte{
|
||||
@@ -547,10 +548,10 @@ func (r *Reader) OnDataH264(cb OnDataH26xFunc) {
|
||||
case message.VideoTypeAU:
|
||||
au, err := h264.AVCCUnmarshal(msg.Payload)
|
||||
if err != nil {
|
||||
if err == h264.ErrAVCCNoNALUs {
|
||||
if errors.Is(err, h264.ErrAVCCNoNALUs) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unable to decode AVCC: %v", err)
|
||||
return fmt.Errorf("unable to decode AVCC: %w", err)
|
||||
}
|
||||
|
||||
cb(msg.DTS+msg.PTSDelta, au)
|
||||
|
||||
@@ -729,13 +729,13 @@ func (f *formatFMP4) initialize() {
|
||||
var syncInfo ac3.SyncInfo
|
||||
err := syncInfo.Unmarshal(frame)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid AC-3 frame: %s", err)
|
||||
return fmt.Errorf("invalid AC-3 frame: %w", err)
|
||||
}
|
||||
|
||||
var bsi ac3.BSI
|
||||
err = bsi.Unmarshal(frame[5:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid AC-3 frame: %s", err)
|
||||
return fmt.Errorf("invalid AC-3 frame: %w", err)
|
||||
}
|
||||
|
||||
if !parsed {
|
||||
|
||||
@@ -2,6 +2,7 @@ package hls
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -158,7 +159,8 @@ func (s *httpServer) onRequest(ctx *gin.Context) {
|
||||
},
|
||||
})
|
||||
if res.Err != nil {
|
||||
if terr, ok := res.Err.(*defs.ErrAuthentication); ok {
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
if !hasCredentials {
|
||||
ctx.Header("WWW-Authenticate", `Basic realm="mediamtx"`)
|
||||
ctx.Writer.WriteHeader(http.StatusUnauthorized)
|
||||
|
||||
@@ -269,7 +269,7 @@ func (m *muxer) runInner(innerCtx context.Context, innerReady chan struct{}) err
|
||||
|
||||
err := m.muxer.Start()
|
||||
if err != nil {
|
||||
return fmt.Errorf("muxer error: %v", err)
|
||||
return fmt.Errorf("muxer error: %w", err)
|
||||
}
|
||||
defer m.muxer.Close()
|
||||
|
||||
@@ -318,7 +318,7 @@ func (m *muxer) createVideoTrack(stream *stream.Stream) (*description.Media, *go
|
||||
|
||||
err := m.muxer.WriteAV1(tunit.NTP, tunit.PTS, tunit.TU)
|
||||
if err != nil {
|
||||
return fmt.Errorf("muxer error: %v", err)
|
||||
return fmt.Errorf("muxer error: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -342,7 +342,7 @@ func (m *muxer) createVideoTrack(stream *stream.Stream) (*description.Media, *go
|
||||
|
||||
err := m.muxer.WriteVP9(tunit.NTP, tunit.PTS, tunit.Frame)
|
||||
if err != nil {
|
||||
return fmt.Errorf("muxer error: %v", err)
|
||||
return fmt.Errorf("muxer error: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -366,7 +366,7 @@ func (m *muxer) createVideoTrack(stream *stream.Stream) (*description.Media, *go
|
||||
|
||||
err := m.muxer.WriteH26x(tunit.NTP, tunit.PTS, tunit.AU)
|
||||
if err != nil {
|
||||
return fmt.Errorf("muxer error: %v", err)
|
||||
return fmt.Errorf("muxer error: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -396,7 +396,7 @@ func (m *muxer) createVideoTrack(stream *stream.Stream) (*description.Media, *go
|
||||
|
||||
err := m.muxer.WriteH26x(tunit.NTP, tunit.PTS, tunit.AU)
|
||||
if err != nil {
|
||||
return fmt.Errorf("muxer error: %v", err)
|
||||
return fmt.Errorf("muxer error: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -428,7 +428,7 @@ func (m *muxer) createAudioTrack(stream *stream.Stream) (*description.Media, *go
|
||||
tunit.PTS,
|
||||
tunit.Packets)
|
||||
if err != nil {
|
||||
return fmt.Errorf("muxer error: %v", err)
|
||||
return fmt.Errorf("muxer error: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -462,7 +462,7 @@ func (m *muxer) createAudioTrack(stream *stream.Stream) (*description.Media, *go
|
||||
tunit.PTS,
|
||||
tunit.AUs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("muxer error: %v", err)
|
||||
return fmt.Errorf("muxer error: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -179,7 +179,8 @@ func (c *conn) runRead(conn *rtmp.Conn, u *url.URL) error {
|
||||
})
|
||||
|
||||
if res.Err != nil {
|
||||
if terr, ok := res.Err.(*defs.ErrAuthentication); ok {
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
// wait some seconds to stop brute force attacks
|
||||
<-time.After(rtmpPauseAfterAuthError)
|
||||
return terr
|
||||
@@ -410,7 +411,8 @@ func (c *conn) runPublish(conn *rtmp.Conn, u *url.URL) error {
|
||||
})
|
||||
|
||||
if res.Err != nil {
|
||||
if terr, ok := res.Err.(*defs.ErrAuthentication); ok {
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
// wait some seconds to stop brute force attacks
|
||||
<-time.After(rtmpPauseAfterAuthError)
|
||||
return terr
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
@@ -138,21 +139,22 @@ func (c *conn) onDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx,
|
||||
})
|
||||
|
||||
if res.Err != nil {
|
||||
switch terr := res.Err.(type) {
|
||||
case *defs.ErrAuthentication:
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
res, err := c.handleAuthError(terr)
|
||||
return res, nil, err
|
||||
}
|
||||
|
||||
case defs.ErrPathNoOnePublishing:
|
||||
var terr2 defs.PathNoOnePublishingError
|
||||
if errors.As(res.Err, &terr2) {
|
||||
return &base.Response{
|
||||
StatusCode: base.StatusNotFound,
|
||||
}, nil, res.Err
|
||||
|
||||
default:
|
||||
return &base.Response{
|
||||
StatusCode: base.StatusBadRequest,
|
||||
}, nil, res.Err
|
||||
}
|
||||
|
||||
return &base.Response{
|
||||
StatusCode: base.StatusBadRequest,
|
||||
}, nil, res.Err
|
||||
}
|
||||
|
||||
if res.Redirect != "" {
|
||||
|
||||
@@ -2,6 +2,7 @@ package rtsp
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
@@ -125,15 +126,14 @@ func (s *session) onAnnounce(c *conn, ctx *gortsplib.ServerHandlerOnAnnounceCtx)
|
||||
})
|
||||
|
||||
if res.Err != nil {
|
||||
switch terr := res.Err.(type) {
|
||||
case *defs.ErrAuthentication:
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
return c.handleAuthError(terr)
|
||||
|
||||
default:
|
||||
return &base.Response{
|
||||
StatusCode: base.StatusBadRequest,
|
||||
}, res.Err
|
||||
}
|
||||
|
||||
return &base.Response{
|
||||
StatusCode: base.StatusBadRequest,
|
||||
}, res.Err
|
||||
}
|
||||
|
||||
s.path = res.Path
|
||||
@@ -211,21 +211,22 @@ func (s *session) onSetup(c *conn, ctx *gortsplib.ServerHandlerOnSetupCtx,
|
||||
})
|
||||
|
||||
if res.Err != nil {
|
||||
switch terr := res.Err.(type) {
|
||||
case *defs.ErrAuthentication:
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
res, err := c.handleAuthError(terr)
|
||||
return res, nil, err
|
||||
}
|
||||
|
||||
case defs.ErrPathNoOnePublishing:
|
||||
var terr2 defs.PathNoOnePublishingError
|
||||
if errors.As(res.Err, &terr2) {
|
||||
return &base.Response{
|
||||
StatusCode: base.StatusNotFound,
|
||||
}, nil, res.Err
|
||||
|
||||
default:
|
||||
return &base.Response{
|
||||
StatusCode: base.StatusBadRequest,
|
||||
}, nil, res.Err
|
||||
}
|
||||
|
||||
return &base.Response{
|
||||
StatusCode: base.StatusBadRequest,
|
||||
}, nil, res.Err
|
||||
}
|
||||
|
||||
s.path = res.Path
|
||||
|
||||
@@ -195,7 +195,8 @@ func (c *conn) runPublish(req srtNewConnReq, pathName string, user string, pass
|
||||
})
|
||||
|
||||
if res.Err != nil {
|
||||
if terr, ok := res.Err.(*defs.ErrAuthentication); ok {
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
// TODO: re-enable. Currently this freezes the listener.
|
||||
// wait some seconds to stop brute force attacks
|
||||
// <-time.After(srtPauseAfterAuthError)
|
||||
@@ -294,11 +295,12 @@ func (c *conn) runRead(req srtNewConnReq, pathName string, user string, pass str
|
||||
})
|
||||
|
||||
if res.Err != nil {
|
||||
if terr, ok := res.Err.(*defs.ErrAuthentication); ok {
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
// TODO: re-enable. Currently this freezes the listener.
|
||||
// wait some seconds to stop brute force attacks
|
||||
// <-time.After(srtPauseAfterAuthError)
|
||||
return false, terr
|
||||
return false, res.Err
|
||||
}
|
||||
return false, res.Err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package webrtc
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@@ -123,7 +124,8 @@ func (s *httpServer) checkAuthOutsideSession(ctx *gin.Context, path string, publ
|
||||
},
|
||||
})
|
||||
if res.Err != nil {
|
||||
if terr, ok := res.Err.(*defs.ErrAuthentication); ok {
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
if !hasCredentials {
|
||||
ctx.Header("WWW-Authenticate", `Basic realm="mediamtx"`)
|
||||
ctx.Writer.WriteHeader(http.StatusUnauthorized)
|
||||
|
||||
@@ -3,6 +3,7 @@ package webrtc
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -368,7 +369,8 @@ func (s *session) runPublish() (int, error) {
|
||||
},
|
||||
})
|
||||
if res.Err != nil {
|
||||
if _, ok := res.Err.(*defs.ErrAuthentication); ok {
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
// wait some seconds to stop brute force attacks
|
||||
<-time.After(webrtcPauseAfterAuthError)
|
||||
|
||||
@@ -498,7 +500,8 @@ func (s *session) runRead() (int, error) {
|
||||
},
|
||||
})
|
||||
if res.Err != nil {
|
||||
if _, ok := res.Err.(*defs.ErrAuthentication); ok {
|
||||
var terr defs.AuthenticationError
|
||||
if errors.As(res.Err, &terr) {
|
||||
// wait some seconds to stop brute force attacks
|
||||
<-time.After(webrtcPauseAfterAuthError)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user