Skip to content

Commit

Permalink
RSDK-9602: Prevent lazyEncodedImage.Bounds from getting gostream into…
Browse files Browse the repository at this point in the history
… a panic loop. (#4650)
  • Loading branch information
dgottlieb authored Dec 20, 2024
1 parent fb3df2c commit 603d082
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion gostream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package gostream
import (
"context"
"errors"
"fmt"
"image"
"sync"
"time"
Expand Down Expand Up @@ -269,7 +270,31 @@ func (bs *basicStream) processInputFrames() {
if frame, ok := framePair.Media.(*rimage.LazyEncodedImage); ok && frame.MIMEType() == utils2.MimeTypeH264 {
encodedFrame = frame.RawData() // nothing to do; already encoded
} else {
bounds := framePair.Media.Bounds()
var bounds image.Rectangle
var boundsError any
func() {
defer func() {
if paniced := recover(); paniced != nil {
boundsError = paniced
}
}()

bounds = framePair.Media.Bounds()
}()

if boundsError != nil {
bs.logger.Errorw("Getting frame bounds failed", "err", fmt.Sprintf("%s", boundsError))
// Dan: It's unclear why we get this error. There's reason to believe this pops
// up when a camera is reconfigured/removed. In which case I'd expect the
// `basicStream` to soon be closed. Making this `initErr = true` assignment to
// exit the `processInputFrames` goroutine unnecessary. But I'm choosing to be
// conservative for the worst case. Where we may be in a permanent bad state and
// (until we understand the problem better) we would spew logs until the user
// stops the stream.
initErr = true
return
}

newDx, newDy := bounds.Dx(), bounds.Dy()
if bs.videoEncoder == nil || dx != newDx || dy != newDy {
dx, dy = newDx, newDy
Expand Down

0 comments on commit 603d082

Please sign in to comment.