Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix stream resetting #489

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pkg/pipeline/builder/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package builder

import (
"fmt"
"strings"
"sync"

"github.com/tinyzimmer/go-gst/gst"
Expand Down Expand Up @@ -98,9 +97,7 @@ func BuildStreamBin(pipeline *gstreamer.Pipeline, p *config.PipelineConfig) (*St
return sb, b, nil
}

func (sb *StreamBin) GetStreamUrl(element string) (string, error) {
name := strings.Split(element, "_")[1]

func (sb *StreamBin) GetStreamUrl(name string) (string, error) {
sb.mu.RLock()
url, ok := sb.urls[name]
sb.mu.RUnlock()
Expand Down
2 changes: 2 additions & 0 deletions pkg/pipeline/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ func New(ctx context.Context, conf *config.PipelineConfig) (*Controller, error)
// create sinks
c.sinks, err = sink.CreateSinks(conf, c.callbacks)
if err != nil {
c.src.Close()
return nil, err
}

// create pipeline
<-c.callbacks.GstReady
if err = c.BuildPipeline(); err != nil {
c.src.Close()
return nil, err
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/pipeline/source/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ func (s *WebSource) GetEndedAt() int64 {

func (s *WebSource) Close() {
if s.chromeCancel != nil {
logger.Debugw("closing chrome")
s.chromeCancel()
s.chromeCancel = nil
}

if s.xvfb != nil {
logger.Debugw("closing X display")
err := s.xvfb.Process.Signal(os.Interrupt)
if err != nil {
logger.Errorw("failed to kill xvfb", err)
Expand All @@ -118,6 +120,7 @@ func (s *WebSource) Close() {
}

if s.pulseSink != "" {
logger.Debugw("unloading pulse module")
err := exec.Command("pactl", "unload-module", s.pulseSink).Run()
if err != nil {
logger.Errorw("failed to unload pulse sink", err)
Expand All @@ -139,6 +142,7 @@ func (s *WebSource) createPulseSink(ctx context.Context, p *config.PipelineConfi
ctx, span := tracer.Start(ctx, "WebInput.createPulseSink")
defer span.End()

logger.Debugw("creating pulse sink")
cmd := exec.Command("pactl",
"load-module", "module-null-sink",
fmt.Sprintf("sink_name=\"%s\"", p.Info.EgressId),
Expand All @@ -162,7 +166,7 @@ func (s *WebSource) launchXvfb(ctx context.Context, p *config.PipelineConfig) er
defer span.End()

dims := fmt.Sprintf("%dx%dx%d", p.Width, p.Height, p.Depth)
logger.Debugw("launching xvfb", "display", p.Display, "dims", dims)
logger.Debugw("creating X display", "display", p.Display, "dims", dims)
xvfb := exec.Command("Xvfb", p.Display, "-screen", "0", dims, "-ac", "-nolisten", "tcp", "-nolisten", "unix")
xvfb.Stderr = &errorLogger{cmd: "xvfb"}
if err := xvfb.Start(); err != nil {
Expand Down Expand Up @@ -193,7 +197,7 @@ func (s *WebSource) launchChrome(ctx context.Context, p *config.PipelineConfig,
webUrl = inputUrl.String()
}

logger.Debugw("launching chrome", "url", webUrl, "enableChomeSandbox", p.EnableChromeSandbox, "insecure", p.Insecure)
logger.Debugw("launching chrome", "url", webUrl, "sandbox", p.EnableChromeSandbox, "insecure", p.Insecure)

opts := []chromedp.ExecAllocatorOption{
chromedp.NoFirstRun,
Expand Down
2 changes: 2 additions & 0 deletions pkg/pipeline/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func (c *Controller) handleMessageError(gErr *gst.GError) error {

switch {
case element == elementGstRtmp2Sink:
name = strings.Split(name, "_")[1]

if strings.HasPrefix(gErr.Error(), "Connection error") && !c.eos.IsBroken() {
// try reconnecting
ok, err := c.streamBin.ResetStream(name, gErr)
Expand Down