Fix running backchannel exec without start #1080

This commit is contained in:
Alex X
2024-05-03 15:57:18 +03:00
parent 2ea66deb08
commit a03db503c3
3 changed files with 13 additions and 38 deletions
+11 -2
View File
@@ -2,6 +2,7 @@ package stdin
import (
"encoding/json"
"errors"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtp"
@@ -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)
}
}
@@ -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) {