1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-27 05:28:44 +02:00

Update package srt with Quality structure

This commit is contained in:
Alexandre Iooss
2020-10-19 19:40:36 +02:00
parent c317d91b8d
commit 069b2155be
6 changed files with 61 additions and 31 deletions

View File

@ -25,13 +25,25 @@ func newStream() (s *Stream) {
return s
}
// Close stream.
func (s *Stream) Close() {
for quality := range s.qualities {
s.DeleteQuality(quality)
}
}
// CreateQuality creates a new quality associated with this stream.
func (s *Stream) CreateQuality(name string) (quality *Quality) {
func (s *Stream) CreateQuality(name string) (quality *Quality, err error) {
// If quality already exist, fail
if _, ok := s.qualities[name]; ok {
return nil, errors.New("quality already exists")
}
s.lockQualities.Lock()
quality = newQuality()
s.qualities[name] = quality
s.lockQualities.Unlock()
return quality
return quality, nil
}
// DeleteQuality removes a stream quality.

View File

@ -91,6 +91,7 @@ func (l *Streams) Delete(name string) {
// Make sure we did not already delete this stream
l.lockStreams.Lock()
if _, ok := l.streams[name]; ok {
l.streams[name].Close()
delete(l.streams, name)
}
l.lockStreams.Unlock()

View File

@ -22,7 +22,10 @@ func TestWithOneStream(t *testing.T) {
}
// Create a quality
quality := stream.CreateQuality("source")
quality, err := stream.CreateQuality("source")
if err != nil {
t.Errorf("Failed to create quality")
}
// Register one output
output := make(chan []byte, 64)