GetVideoFrame() nil frame buffer validation
This commit is contained in:
parent
957b8dc191
commit
38101a377c
2 changed files with 27 additions and 5 deletions
10
frame.go
10
frame.go
|
@ -36,11 +36,11 @@ func GetVideoFrame(filename string, n int, frameBuffer []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if frameBuffer == nil {
|
if frameBuffer == nil {
|
||||||
frameBuffer = make([]byte, frameBufferSize)
|
return errors.New("vidio: provided frame buffer reference is nil")
|
||||||
} else {
|
}
|
||||||
if len(frameBuffer) < frameBufferSize {
|
|
||||||
return errors.New("vidio: provided frame buffer size is smaller than the frame size")
|
if len(frameBuffer) < frameBufferSize {
|
||||||
}
|
return errors.New("vidio: provided frame buffer size is smaller than the frame size")
|
||||||
}
|
}
|
||||||
|
|
||||||
selectExpression, err := buildSelectExpression(n)
|
selectExpression, err := buildSelectExpression(n)
|
||||||
|
|
|
@ -30,6 +30,28 @@ func TestGetFrameShouldReturnErrorOnOutOfRangeFrame(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetFrameShouldReturnErrorOnNilFrameBuffer(t *testing.T) {
|
||||||
|
path := "test/koala.mp4"
|
||||||
|
var buffer []byte = nil
|
||||||
|
|
||||||
|
err := GetVideoFrame(path, 0, buffer)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Error was expected to not be nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetFrameShouldReturnErrorOnInvalidFrameBufferSize(t *testing.T) {
|
||||||
|
path := "test/koala.mp4"
|
||||||
|
img := image.NewRGBA(image.Rect(0, 0, 480/2, 270/2))
|
||||||
|
|
||||||
|
err := GetVideoFrame(path, 0, img.Pix)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Error was expected to not be nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetFrameShouldReturnCorrectFrame(t *testing.T) {
|
func TestGetFrameShouldReturnCorrectFrame(t *testing.T) {
|
||||||
path := "test/koala.mp4"
|
path := "test/koala.mp4"
|
||||||
img := image.NewRGBA(image.Rect(0, 0, 480, 270))
|
img := image.NewRGBA(image.Rect(0, 0, 480, 270))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue