Fix mjpeg source for Foscam G2 camera #1258

This commit is contained in:
Alex X
2024-07-18 13:52:50 +03:00
parent eaae7aee39
commit 3762bdbccd
+10 -6
View File
@@ -18,17 +18,23 @@ func Next(rd *bufio.Reader) (http.Header, []byte, error) {
return nil, nil, err return nil, nil, err
} }
if strings.HasPrefix(s, "--") {
break
}
if s == "\r\n" { if s == "\r\n" {
continue continue
} }
if !strings.HasPrefix(s, "--") {
return nil, nil, errors.New("multipart: wrong boundary: " + 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) tp := textproto.NewReader(rd)
header, err := tp.ReadMIMEHeader() header, err := tp.ReadMIMEHeader()
if err != nil { if err != nil {
@@ -50,7 +56,5 @@ func Next(rd *bufio.Reader) (http.Header, []byte, error) {
return nil, nil, err return nil, nil, err
} }
_, _ = rd.Discard(2) // skip "\r\n"
return http.Header(header), buf, nil return http.Header(header), buf, nil
} }