install go2rtc on bob

This commit is contained in:
2026-04-04 19:36:14 +02:00
parent f0b56e63d1
commit ccf88187b8
537 changed files with 69213 additions and 0 deletions
@@ -0,0 +1,60 @@
package mpjpeg
import (
"bufio"
"errors"
"io"
"net/http"
"net/textproto"
"strconv"
"strings"
)
func Next(rd *bufio.Reader) (http.Header, []byte, error) {
for {
// search next boundary and skip empty lines
s, err := rd.ReadString('\n')
if err != nil {
return nil, nil, err
}
if s == "\r\n" {
continue
}
if !strings.HasPrefix(s, "--") {
return nil, nil, errors.New("multipart: wrong boundary: " + s)
}
// Foscam G2 has a awful implementation of MJPEG
// https://github.com/AlexxIT/go2rtc/issues/1258
if b, _ := rd.Peek(2); string(b) == "--" {
continue
}
break
}
tp := textproto.NewReader(rd)
header, err := tp.ReadMIMEHeader()
if err != nil {
return nil, nil, err
}
s := header.Get("Content-Length")
if s == "" {
return nil, nil, errors.New("multipart: no content length")
}
size, err := strconv.Atoi(s)
if err != nil {
return nil, nil, err
}
buf := make([]byte, size)
if _, err = io.ReadFull(rd, buf); err != nil {
return nil, nil, err
}
return http.Header(header), buf, nil
}
@@ -0,0 +1,65 @@
package mpjpeg
import (
"bufio"
"errors"
"io"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/pion/rtp"
)
type Producer struct {
core.Connection
rd *bufio.Reader
}
func Open(rd io.Reader) (*Producer, error) {
return &Producer{
Connection: core.Connection{
ID: core.NewID(),
FormatName: "mpjpeg", // Multipart JPEG
Transport: rd,
Medias: []*core.Media{
{
Kind: core.KindVideo,
Direction: core.DirectionRecvonly,
Codecs: []*core.Codec{
{
Name: core.CodecJPEG,
ClockRate: 90000,
PayloadType: core.PayloadTypeRAW,
},
},
},
},
},
}, nil
}
func (c *Producer) Start() error {
if len(c.Receivers) != 1 {
return errors.New("mjpeg: no receivers")
}
rd := bufio.NewReader(c.Transport.(io.Reader))
mjpeg := c.Receivers[0]
for {
_, body, err := Next(rd)
if err != nil {
return err
}
c.Recv += len(body)
if mjpeg != nil {
packet := &rtp.Packet{
Header: rtp.Header{Timestamp: core.Now90000()},
Payload: body,
}
mjpeg.WriteRTP(packet)
}
}
}