Browse Source

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

pull/2265/head
Alessandro Ros 2 years ago committed by GitHub
parent
commit
30a69a7722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 50
      internal/core/api_test.go
  2. 8
      internal/core/path.go
  3. 5
      internal/core/path_manager_test.go

50
internal/core/api_test.go

@ -43,6 +43,21 @@ var testMediaH264 = &description.Media{ @@ -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) { @@ -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) { @@ -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()

8
internal/core/path.go

@ -866,6 +866,14 @@ func (pa *path) handleAddReader(req pathAddReaderReq) { @@ -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"),

5
internal/core/path_manager_test.go

@ -284,7 +284,10 @@ func TestPathMaxReaders(t *testing.T) { @@ -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()

Loading…
Cancel
Save