Skip to content

Commit

Permalink
Fix running backchannel exec without start #1080
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed May 3, 2024
1 parent 2ea66de commit a03db50
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 38 deletions.
12 changes: 2 additions & 10 deletions pkg/stdin/client.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
package stdin

import (
"io"
"os/exec"

"github.com/AlexxIT/go2rtc/pkg/core"
)

type Client struct {
cmd *exec.Cmd
pipe io.WriteCloser
cmd *exec.Cmd

medias []*core.Media
sender *core.Sender
send int
}

func NewClient(cmd *exec.Cmd) (*Client, error) {
pipe, err := PipeCloser(cmd)
if err != nil {
return nil, err
}

c := &Client{
pipe: pipe,
cmd: cmd,
cmd: cmd,
medias: []*core.Media{
{
Kind: core.KindAudio,
Expand Down
13 changes: 11 additions & 2 deletions pkg/stdin/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stdin

import (
"encoding/json"
"errors"

"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtp"
Expand All @@ -17,9 +18,14 @@ func (c *Client) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver,

func (c *Client) AddTrack(media *core.Media, _ *core.Codec, track *core.Receiver) error {
if c.sender == nil {
stdin, err := c.cmd.StdinPipe()
if err != nil {
return err
}

c.sender = core.NewSender(media, track.Codec)
c.sender.Handler = func(packet *rtp.Packet) {
_, _ = c.pipe.Write(packet.Payload)
_, _ = stdin.Write(packet.Payload)
c.send += len(packet.Payload)
}
}
Expand All @@ -36,7 +42,10 @@ func (c *Client) Stop() (err error) {
if c.sender != nil {
c.sender.Close()
}
return c.pipe.Close()
if c.cmd.Process == nil {
return nil
}
return errors.Join(c.cmd.Process.Kill(), c.cmd.Wait())
}

func (c *Client) MarshalJSON() ([]byte, error) {
Expand Down
26 changes: 0 additions & 26 deletions pkg/stdin/pipe.go

This file was deleted.

0 comments on commit a03db50

Please sign in to comment.