update docs

This commit is contained in:
aler9
2022-05-13 23:04:03 +02:00
parent 811e189b43
commit 3bd8ad810f
2 changed files with 10 additions and 4 deletions

View File

@@ -43,7 +43,8 @@ func (sh *serverHandler) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionClo
sh.mutex.Lock() sh.mutex.Lock()
defer sh.mutex.Unlock() defer sh.mutex.Unlock()
// close stream-related listeners and disconnect every reader // if the session is the publisher,
// close the stream and disconnect any reader.
if sh.stream != nil && ctx.Session == sh.publisher { if sh.stream != nil && ctx.Session == sh.publisher {
sh.stream.Close() sh.stream.Close()
sh.stream = nil sh.stream = nil
@@ -64,6 +65,7 @@ func (sh *serverHandler) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (
}, nil, nil }, nil, nil
} }
// send the track list that is being published to the client
return &base.Response{ return &base.Response{
StatusCode: base.StatusOK, StatusCode: base.StatusOK,
}, sh.stream, nil }, sh.stream, nil
@@ -82,6 +84,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
}, fmt.Errorf("someone is already publishing") }, fmt.Errorf("someone is already publishing")
} }
// save the track list and the publisher
sh.stream = gortsplib.NewServerStream(ctx.Tracks) sh.stream = gortsplib.NewServerStream(ctx.Tracks)
sh.publisher = ctx.Session sh.publisher = ctx.Session
@@ -129,7 +132,7 @@ func (sh *serverHandler) OnPacketRTP(ctx *gortsplib.ServerHandlerOnPacketRTPCtx)
sh.mutex.Lock() sh.mutex.Lock()
defer sh.mutex.Unlock() defer sh.mutex.Unlock()
// if we are the publisher, route the RTP packet to readers // if we are the publisher, route the RTP packet to all readers
if ctx.Session == sh.publisher { if ctx.Session == sh.publisher {
sh.stream.WritePacketRTP(ctx.TrackID, ctx.Packet, ctx.PTSEqualsDTS) sh.stream.WritePacketRTP(ctx.TrackID, ctx.Packet, ctx.PTSEqualsDTS)
} }

View File

@@ -42,7 +42,8 @@ func (sh *serverHandler) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionClo
sh.mutex.Lock() sh.mutex.Lock()
defer sh.mutex.Unlock() defer sh.mutex.Unlock()
// close stream-related listeners and disconnect every reader // if the session is the publisher,
// close the stream and disconnect any reader.
if sh.stream != nil && ctx.Session == sh.publisher { if sh.stream != nil && ctx.Session == sh.publisher {
sh.stream.Close() sh.stream.Close()
sh.stream = nil sh.stream = nil
@@ -63,6 +64,7 @@ func (sh *serverHandler) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (
}, nil, nil }, nil, nil
} }
// send the track list that is being published to the client
return &base.Response{ return &base.Response{
StatusCode: base.StatusOK, StatusCode: base.StatusOK,
}, sh.stream, nil }, sh.stream, nil
@@ -81,6 +83,7 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
}, fmt.Errorf("someone is already publishing") }, fmt.Errorf("someone is already publishing")
} }
// save the track list and the publisher
sh.stream = gortsplib.NewServerStream(ctx.Tracks) sh.stream = gortsplib.NewServerStream(ctx.Tracks)
sh.publisher = ctx.Session sh.publisher = ctx.Session
@@ -128,7 +131,7 @@ func (sh *serverHandler) OnPacketRTP(ctx *gortsplib.ServerHandlerOnPacketRTPCtx)
sh.mutex.Lock() sh.mutex.Lock()
defer sh.mutex.Unlock() defer sh.mutex.Unlock()
// if we are the publisher, route the RTP packet to readers // if we are the publisher, route the RTP packet to all readers
if ctx.Session == sh.publisher { if ctx.Session == sh.publisher {
sh.stream.WritePacketRTP(ctx.TrackID, ctx.Packet, ctx.PTSEqualsDTS) sh.stream.WritePacketRTP(ctx.TrackID, ctx.Packet, ctx.PTSEqualsDTS)
} }