Skip to content

Commit

Permalink
lib latest updates
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels committed Jan 24, 2024
1 parent 9f619ec commit 2deb485
Show file tree
Hide file tree
Showing 12 changed files with 1,422 additions and 9,351 deletions.
20 changes: 11 additions & 9 deletions cmd/stream_audio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ import (
"unsafe"

"github.com/edaniels/golog"
utils "github.com/edaniels/goutils"
"github.com/gen2brain/malgo"

// register microphone drivers.
_ "github.com/pion/mediadevices/pkg/driver/microphone"
"github.com/pion/webrtc/v3"
"github.com/pkg/errors"
"go.uber.org/multierr"
goutils "go.viam.com/utils"
vutils "go.viam.com/utils"
hopus "gopkg.in/hraban/opus.v2"

"github.com/edaniels/gostream"
"github.com/edaniels/gostream/codec/opus"
)

func main() {
goutils.ContextualMain(mainWithArgs, logger)
utils.ContextualMain(mainWithArgs, logger)
}

var (
Expand All @@ -35,14 +37,14 @@ var (

// Arguments for the command.
type Arguments struct {
Port goutils.NetPortFlag `flag:"0"`
Dump bool `flag:"dump"`
Playback bool `flag:"playback"`
Port vutils.NetPortFlag `flag:"0"`
Dump bool `flag:"dump"`
Playback bool `flag:"playback"`
}

func mainWithArgs(ctx context.Context, args []string, logger golog.Logger) error {
var argsParsed Arguments
if err := goutils.ParseFlags(args, &argsParsed); err != nil {
if err := vutils.ParseFlags(args, &argsParsed); err != nil {
return err
}
if argsParsed.Dump {
Expand All @@ -58,7 +60,7 @@ func mainWithArgs(ctx context.Context, args []string, logger golog.Logger) error
return nil
}
if argsParsed.Port == 0 {
argsParsed.Port = goutils.NetPortFlag(defaultPort)
argsParsed.Port = vutils.NetPortFlag(defaultPort)
}

return runServer(
Expand All @@ -77,7 +79,7 @@ func runServer(
) (err error) {
audioSource, err := gostream.GetAnyAudioSource(gostream.DefaultConstraints, logger)
if err != nil {
return err
return utils.ErrorWithStack(err)
}
defer func() {
err = multierr.Combine(err, audioSource.Close(ctx))
Expand Down Expand Up @@ -154,7 +156,7 @@ func decodeAndPlayTrack(ctx context.Context, track *webrtc.TrackRemote) {
panic(err)
}
defer func() {
goutils.UncheckedErrorFunc(mCtx.Uninit)
vutils.UncheckedErrorFunc(mCtx.Uninit)
mCtx.Free()
}()

Expand Down
18 changes: 10 additions & 8 deletions cmd/stream_av/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import (
"context"

"github.com/edaniels/golog"
utils "github.com/edaniels/goutils"

// register drivers.
_ "github.com/pion/mediadevices/pkg/driver/camera"
_ "github.com/pion/mediadevices/pkg/driver/microphone"
_ "github.com/pion/mediadevices/pkg/driver/screen"
"go.uber.org/multierr"
goutils "go.viam.com/utils"
vutils "go.viam.com/utils"

"github.com/edaniels/gostream"
"github.com/edaniels/gostream/codec/opus"
"github.com/edaniels/gostream/codec/vpx"
)

func main() {
goutils.ContextualMain(mainWithArgs, logger)
utils.ContextualMain(mainWithArgs, logger)
}

var (
Expand All @@ -28,14 +30,14 @@ var (

// Arguments for the command.
type Arguments struct {
Port goutils.NetPortFlag `flag:"0"`
Camera bool `flag:"camera,usage=use camera"`
Dump bool `flag:"dump"`
Port vutils.NetPortFlag `flag:"0"`
Camera bool `flag:"camera,usage=use camera"`
Dump bool `flag:"dump"`
}

func mainWithArgs(ctx context.Context, args []string, logger golog.Logger) error {
var argsParsed Arguments
if err := goutils.ParseFlags(args, &argsParsed); err != nil {
if err := vutils.ParseFlags(args, &argsParsed); err != nil {
return err
}
if argsParsed.Dump {
Expand Down Expand Up @@ -71,7 +73,7 @@ func mainWithArgs(ctx context.Context, args []string, logger golog.Logger) error
return nil
}
if argsParsed.Port == 0 {
argsParsed.Port = goutils.NetPortFlag(defaultPort)
argsParsed.Port = vutils.NetPortFlag(defaultPort)
}

return runServer(
Expand All @@ -90,7 +92,7 @@ func runServer(
) (err error) {
audioSource, err := gostream.GetAnyAudioSource(gostream.DefaultConstraints, logger)
if err != nil {
return err
return utils.ErrorWithStack(err)
}
defer func() {
err = multierr.Combine(err, audioSource.Close(ctx))
Expand Down
20 changes: 11 additions & 9 deletions cmd/stream_video/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import (
"context"

"github.com/edaniels/golog"
utils "github.com/edaniels/goutils"

// register video drivers.
_ "github.com/pion/mediadevices/pkg/driver/camera"
_ "github.com/pion/mediadevices/pkg/driver/screen"
"go.uber.org/multierr"
goutils "go.viam.com/utils"
vutils "go.viam.com/utils"

"github.com/edaniels/gostream"
"github.com/edaniels/gostream/codec/vpx"
"github.com/edaniels/gostream/codec/x264"
)

func main() {
goutils.ContextualMain(mainWithArgs, logger)
utils.ContextualMain(mainWithArgs, logger)
}

var (
Expand All @@ -27,15 +29,15 @@ var (

// Arguments for the command.
type Arguments struct {
Port goutils.NetPortFlag `flag:"0"`
Camera bool `flag:"camera,usage=use camera"`
DupeStream bool `flag:"dupe_stream,usage=duplicate stream"`
Dump bool `flag:"dump"`
Port vutils.NetPortFlag `flag:"0"`
Camera bool `flag:"camera,usage=use camera"`
DupeStream bool `flag:"dupe_stream,usage=duplicate stream"`
Dump bool `flag:"dump"`
}

func mainWithArgs(ctx context.Context, args []string, logger golog.Logger) error {
var argsParsed Arguments
if err := goutils.ParseFlags(args, &argsParsed); err != nil {
if err := vutils.ParseFlags(args, &argsParsed); err != nil {
return err
}
if argsParsed.Dump {
Expand All @@ -56,7 +58,7 @@ func mainWithArgs(ctx context.Context, args []string, logger golog.Logger) error
return nil
}
if argsParsed.Port == 0 {
argsParsed.Port = goutils.NetPortFlag(defaultPort)
argsParsed.Port = vutils.NetPortFlag(defaultPort)
}

return runServer(
Expand All @@ -82,7 +84,7 @@ func runServer(
videoSource, err = gostream.GetAnyScreenSource(gostream.DefaultConstraints, logger)
}
if err != nil {
return err
return utils.ErrorWithStack(err)
}
defer func() {
err = multierr.Combine(err, videoSource.Close(ctx))
Expand Down
4 changes: 3 additions & 1 deletion etc/buf.web.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ plugins:
opt:
- import_style=commonjs
- mode=grpcwebtext
- plugin: buf.build/community/stephenh-ts-proto:v1.163.0
- plugin: buf.build/community/stephenh-ts-proto:v1.166.4
out: dist/js
opt:
- outputClientImpl=grpc-web
- esModuleInterop=true
- importSuffix=.js
Loading

0 comments on commit 2deb485

Please sign in to comment.