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
+11 -7
View File
@@ -18,15 +18,21 @@ func Next(rd *bufio.Reader) (http.Header, []byte, error) {
return nil, nil, err
}
if strings.HasPrefix(s, "--") {
break
}
if s == "\r\n" {
continue
}
return nil, nil, errors.New("multipart: wrong boundary: " + s)
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)
@@ -50,7 +56,5 @@ func Next(rd *bufio.Reader) (http.Header, []byte, error) {
return nil, nil, err
}
_, _ = rd.Discard(2) // skip "\r\n"
return http.Header(header), buf, nil
}