Skip to content

Commit

Permalink
Refactor gb28181 package to improve Invite handling
Browse files Browse the repository at this point in the history
  • Loading branch information
duiniuluantanqin committed Dec 24, 2024
1 parent 7416134 commit 5996985
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
30 changes: 26 additions & 4 deletions trunk/3rdparty/srs-bench/gb28181/gb28181.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (
"context"
"flag"
"fmt"
"github.com/ossrs/go-oryx-lib/errors"
"github.com/ossrs/go-oryx-lib/logger"
"io"
"os"
"strings"
"time"

"github.com/ossrs/go-oryx-lib/errors"
"github.com/ossrs/go-oryx-lib/logger"
)

type gbMainConfig struct {
Expand Down Expand Up @@ -116,8 +117,29 @@ func Run(ctx context.Context, r0 interface{}) (err error) {
return errors.Wrapf(err, "register %v", conf.sipConfig)
}

if err := session.Invite(ctx); err != nil {
return errors.Wrapf(err, "invite %v", conf.sipConfig)
// Start a goroutine to wait for Invite request
inviteChan := make(chan error, 1)
go func() {
for {
select {
case <-ctx.Done():
inviteChan <- ctx.Err()
return
default:
if err := session.WaitInvite(ctx); err != nil {
inviteChan <- err
return
}
// If successfully received Invite, exit loop
inviteChan <- nil
return
}
}
}()

// Wait for Invite request processing result
if err := <-inviteChan; err != nil {
return errors.Wrapf(err, "wait invite %v", conf.sipConfig)
}

if conf.psConfig.video == "" || conf.psConfig.audio == "" {
Expand Down
23 changes: 18 additions & 5 deletions trunk/3rdparty/srs-bench/gb28181/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ package gb28181

import (
"context"
"github.com/ghettovoice/gosip/sip"
"github.com/ossrs/go-oryx-lib/errors"
"github.com/ossrs/go-oryx-lib/logger"
"github.com/pion/webrtc/v3/pkg/media/h264reader"
"github.com/yapingcat/gomedia/mpeg2"
"io"
"os"
"path"
"strconv"
"strings"
"sync"
"time"

"github.com/ghettovoice/gosip/sip"
"github.com/ossrs/go-oryx-lib/errors"
"github.com/ossrs/go-oryx-lib/logger"
"github.com/pion/webrtc/v3/pkg/media/h264reader"
"github.com/yapingcat/gomedia/mpeg2"
)

type GBSessionConfig struct {
Expand Down Expand Up @@ -249,6 +250,18 @@ func (v *GBSession) UnRegister(ctx context.Context) error {
return ctx.Err()
}

func (v *GBSession) WaitInvite(ctx context.Context) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
if err := v.Invite(ctx); err != nil {
return errors.Wrapf(err, "handle invite request")
}
return nil
}
}

type IngesterConfig struct {
psConfig PSConfig
ssrc uint32
Expand Down

0 comments on commit 5996985

Please sign in to comment.