Skip to content

Commit

Permalink
Fix mjpeg source for Foscam G2 camera #1258
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Jul 18, 2024
1 parent eaae7ae commit 3762bdb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/mpjpeg/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

if s == "\r\n" {
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
}

return nil, nil, errors.New("multipart: wrong boundary: " + s)
break
}

tp := textproto.NewReader(rd)
Expand All @@ -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
}

0 comments on commit 3762bdb

Please sign in to comment.