Skip to content

Commit

Permalink
Random fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xaionaro committed Nov 11, 2024
1 parent 2da0f03 commit 26cd16b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/streampanel/FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Website = "https://github.com/xaionaro/streamctl"
Name = "streampanel"
ID = "center.dx.streampanel"
Version = "0.1.0"
Build = 301
Build = 308
2 changes: 2 additions & 0 deletions pkg/player/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/facebookincubator/go-belt/tool/logger"
"github.com/xaionaro-go/streamctl/pkg/player/types"
"github.com/xaionaro-go/streamctl/pkg/xsync"
)
Expand Down Expand Up @@ -44,6 +45,7 @@ func (m *Manager) NewPlayer(
title string,
backend Backend,
) (Player, error) {
logger.Debugf(ctx, "NewPlayer: '%s' '%s'", title, backend)
switch backend {
case BackendBuiltin:
return m.NewBuiltin(ctx, title)
Expand Down
20 changes: 3 additions & 17 deletions pkg/streamd/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,26 +470,12 @@ func (c *Client) processError(
ctx context.Context,
err error,
) error {
logger.Tracef(
ctx,
"processError(ctx, '%v'): %T",
err,
err,
)
logger.Tracef(ctx, "processError(ctx, '%v'): %T", err, err)
if s, ok := status.FromError(err); ok {
logger.Tracef(
ctx,
"processError(ctx, '%v'): code == %#+v; msg == %#+v",
err,
s.Code(),
s.Message(),
)
logger.Tracef(ctx, "processError(ctx, '%v'): code == %#+v; msg == %#+v", err, s.Code(), s.Message())
switch s.Code() {
case codes.Unavailable:
logger.Debugf(
ctx,
"suppressed the error (forcing a retry)",
)
logger.Debugf(ctx, "suppressed the error (forcing a retry)")
return nil
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/streamd/streamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,7 @@ func (d *StreamD) DialContext(
func (d *StreamD) initP2P(
ctx context.Context,
) error {
return nil
if d.Config.P2PNetwork.IsZero() {
d.Config.P2PNetwork = config.GetRandomP2PConfig()
if err := d.saveConfig(ctx); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/streampanel/camera.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package streampanel

type cameraUI struct {
}

func newCameraUI() *cameraUI {
return &cameraUI{}
}
1 change: 1 addition & 0 deletions pkg/streampanel/consts/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ const (
PageDashboard = Page("Dashboard")
PageOBS = Page("OBS")
PageRestream = Page("Restream")
PageCamera = Page("Camera")
)
27 changes: 20 additions & 7 deletions pkg/streamplayer/stream_player.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type StreamPlayer struct {
PlayerLocker xsync.Mutex
Player player.Player
StreamID streamtypes.StreamID
Backend player.Backend
Config Config
}

Expand All @@ -85,6 +86,7 @@ type StreamPlayerHandler struct {
func (sp *StreamPlayers) Create(
ctx context.Context,
streamID streamtypes.StreamID,
backend player.Backend,
opts ...Option,
) (_ret *StreamPlayerHandler, _err error) {
logger.Debugf(ctx, "StreamPlayers.Create(ctx, '%s', %#+v)", streamID, opts)
Expand All @@ -101,6 +103,7 @@ func (sp *StreamPlayers) Create(
Parent: sp,
Cancel: cancel,
StreamPlayer: StreamPlayer{
Backend: backend,
Config: resultingOpts.Config(),
StreamID: streamID,
},
Expand Down Expand Up @@ -191,7 +194,7 @@ func (p *StreamPlayerHandler) startU(ctx context.Context) error {

instanceCtx, cancelFn := context.WithCancel(ctx)

playerType := p.Parent.PlayerManager.SupportedBackends()[0]
playerType := p.Backend
player, err := p.Parent.PlayerManager.NewPlayer(
instanceCtx,
StreamID2Title(p.StreamID),
Expand All @@ -202,6 +205,11 @@ func (p *StreamPlayerHandler) startU(ctx context.Context) error {
cancelFn()
return fmt.Errorf("unable to run a video player '%s': %w", playerType, err)
}
if player == nil {
errmon.ObserveErrorCtx(ctx, p.Close())
cancelFn()
return fmt.Errorf("player == nil")
}
p.Player = player
logger.Debugf(ctx, "initialized player %#+v", player)

Expand All @@ -212,6 +220,9 @@ func (p *StreamPlayerHandler) startU(ctx context.Context) error {
func (p *StreamPlayerHandler) stopU(ctx context.Context) error {
logger.Debugf(ctx, "StreamPlayers.stopU(ctx): '%s'", p.StreamID)
defer logger.Debugf(ctx, "/StreamPlayers.stopU(ctx): '%s'", p.StreamID)
defer func(){
p.Player = nil
}()

if p.Player == nil {
return fmt.Errorf("p.Player == nil")
Expand All @@ -230,7 +241,7 @@ func (p *StreamPlayerHandler) restartU(ctx context.Context) error {
defer logger.Debugf(ctx, "/StreamPlayers.restartU(ctx): '%s'", p.StreamID)

if err := p.stopU(ctx); err != nil {
return fmt.Errorf("unable to stop the stream player: %w", err)
logger.Errorf(ctx, "unable to stop the stream player: %v", err)
}
if err := p.startU(ctx); err != nil {
return fmt.Errorf("unable to start the stream player: %w", err)
Expand Down Expand Up @@ -358,12 +369,14 @@ func (p *StreamPlayerHandler) controllerLoop(
}
isClosed = true
observability.Go(ctx, func() {
err := p.restartU(ctx)
errmon.ObserveErrorCtx(ctx, err)
if err != nil {
err := p.Parent.Remove(ctx, p.StreamID)
p.PlayerLocker.Do(ctx, func() {
err := p.restartU(ctx)
errmon.ObserveErrorCtx(ctx, err)
}
if err != nil {
err := p.Parent.Remove(ctx, p.StreamID)
errmon.ObserveErrorCtx(ctx, err)
}
})
})
}

Expand Down
1 change: 1 addition & 0 deletions pkg/streamserver/streamplayers/stream_players.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func setupStreamPlayers(
_, err := s.StreamPlayers.Create(
xcontext.DetachDone(ctx),
streamID,
playerCfg.Player,
ssOpts...,
)
if err != nil {
Expand Down

0 comments on commit 26cd16b

Please sign in to comment.