mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
examples: prevent redundant checks in OnSetup when recording (#731)
This commit is contained in:
@@ -136,16 +136,21 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
||||||
log.Printf("setup request")
|
log.Printf("setup request")
|
||||||
|
|
||||||
|
// SETUP is used by both readers and publishers. In case of publishers, just return StatusOK.
|
||||||
|
if ctx.Session.State() == gortsplib.ServerSessionStatePreRecord {
|
||||||
|
return &base.Response{
|
||||||
|
StatusCode: base.StatusOK,
|
||||||
|
}, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Verify reader credentials.
|
// Verify reader credentials.
|
||||||
// In case of readers, credentials have to be verified during DESCRIBE and SETUP.
|
// In case of readers, credentials have to be verified during DESCRIBE and SETUP.
|
||||||
if ctx.Session.State() == gortsplib.ServerSessionStateInitial {
|
|
||||||
ok := ctx.Conn.VerifyCredentials(ctx.Request, readUser, readPass)
|
ok := ctx.Conn.VerifyCredentials(ctx.Request, readUser, readPass)
|
||||||
if !ok {
|
if !ok {
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
StatusCode: base.StatusUnauthorized,
|
StatusCode: base.StatusUnauthorized,
|
||||||
}, nil, liberrors.ErrServerAuth{}
|
}, nil, liberrors.ErrServerAuth{}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
sh.mutex.RLock()
|
sh.mutex.RLock()
|
||||||
defer sh.mutex.RUnlock()
|
defer sh.mutex.RUnlock()
|
||||||
|
@@ -108,6 +108,13 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
|
|
||||||
// called when receiving a SETUP request.
|
// called when receiving a SETUP request.
|
||||||
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
||||||
|
// prevent readers from using the server.
|
||||||
|
if ctx.Session.State() == gortsplib.ServerSessionStateInitial {
|
||||||
|
return &base.Response{
|
||||||
|
StatusCode: base.StatusNotImplemented,
|
||||||
|
}, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("setup request")
|
log.Printf("setup request")
|
||||||
|
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
|
@@ -108,6 +108,13 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
||||||
log.Printf("setup request")
|
log.Printf("setup request")
|
||||||
|
|
||||||
|
// SETUP is used by both readers and publishers. In case of publishers, just return StatusOK.
|
||||||
|
if ctx.Session.State() == gortsplib.ServerSessionStatePreRecord {
|
||||||
|
return &base.Response{
|
||||||
|
StatusCode: base.StatusOK,
|
||||||
|
}, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
sh.mutex.RLock()
|
sh.mutex.RLock()
|
||||||
defer sh.mutex.RUnlock()
|
defer sh.mutex.RUnlock()
|
||||||
|
|
||||||
|
@@ -107,6 +107,13 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
||||||
log.Printf("setup request")
|
log.Printf("setup request")
|
||||||
|
|
||||||
|
// SETUP is used by both readers and publishers. In case of publishers, just return StatusOK.
|
||||||
|
if ctx.Session.State() == gortsplib.ServerSessionStatePreRecord {
|
||||||
|
return &base.Response{
|
||||||
|
StatusCode: base.StatusOK,
|
||||||
|
}, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
sh.mutex.RLock()
|
sh.mutex.RLock()
|
||||||
defer sh.mutex.RUnlock()
|
defer sh.mutex.RUnlock()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user