fix maxReaders limit in case of multiple tracks (#2246) (#2264)

This commit is contained in:
Alessandro Ros 2023-08-30 10:58:24 +02:00 committed by GitHub
parent bd1cb35022
commit 30a69a7722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 33 deletions

View File

@ -43,6 +43,21 @@ var testMediaH264 = &description.Media{
Formats: []format.Format{testFormatH264},
}
var testMediaAAC = &description.Media{
Type: description.MediaTypeAudio,
Formats: []format.Format{&format.MPEG4Audio{
PayloadTyp: 96,
Config: &mpeg4audio.Config{
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}},
}
func httpRequest(t *testing.T, hc *http.Client, method string, ur string, in interface{}, out interface{}) {
buf := func() io.Reader {
if in == nil {
@ -247,20 +262,7 @@ func TestAPIPathsList(t *testing.T) {
"rtsp://localhost:8554/mypath",
&description.Session{Medias: []*description.Media{
media0,
{
Type: description.MediaTypeAudio,
Formats: []format.Format{&format.MPEG4Audio{
PayloadTyp: 96,
Config: &mpeg4audio.Config{
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}},
},
testMediaAAC,
}})
require.NoError(t, err)
defer source.Close()
@ -314,24 +316,8 @@ func TestAPIPathsList(t *testing.T) {
source := gortsplib.Client{TLSConfig: &tls.Config{InsecureSkipVerify: true}}
err = source.StartRecording("rtsps://localhost:8322/mypath",
&description.Session{Medias: []*description.Media{
{
Type: description.MediaTypeVideo,
Formats: []format.Format{testFormatH264},
},
{
Type: description.MediaTypeAudio,
Formats: []format.Format{&format.MPEG4Audio{
PayloadTyp: 97,
Config: &mpeg4audio.Config{
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}},
},
testMediaH264,
testMediaAAC,
}})
require.NoError(t, err)
defer source.Close()

View File

@ -866,6 +866,14 @@ func (pa *path) handleAddReader(req pathAddReaderReq) {
}
func (pa *path) handleAddReaderPost(req pathAddReaderReq) {
if _, ok := pa.readers[req.author]; ok {
req.res <- pathAddReaderRes{
path: pa,
stream: pa.stream,
}
return
}
if pa.conf.MaxReaders != 0 && len(pa.readers) >= pa.conf.MaxReaders {
req.res <- pathAddReaderRes{
err: fmt.Errorf("maximum reader count reached"),

View File

@ -284,7 +284,10 @@ func TestPathMaxReaders(t *testing.T) {
source := gortsplib.Client{}
err := source.StartRecording(
"rtsp://localhost:8554/mystream",
&description.Session{Medias: []*description.Media{testMediaH264}})
&description.Session{Medias: []*description.Media{
testMediaH264,
testMediaAAC,
}})
require.NoError(t, err)
defer source.Close()