Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the frame is writable before copyPlanes #84

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions frame_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,12 @@ func (f *frameDataFrame) bytes(align int) ([]byte, error) {
return nil, errors.New("astiav: frame type not implemented")
}

func (f *frameDataFrame) copyPlanes(ps []frameDataPlane) (err error) {
func (f *frameDataFrame) copyPlanes(ps []frameDataPlane) error {
// Check writability
if !f.f.IsWritable() {
return errors.New("astiav: frame is not writable")
}

switch {
asticode marked this conversation as resolved.
Show resolved Hide resolved
// Video
case f.height() > 0 && f.width() > 0:
Expand All @@ -300,9 +305,9 @@ func (f *frameDataFrame) copyPlanes(ps []frameDataPlane) (err error) {

// Copy image
C.av_image_copy(&f.f.c.data[0], &f.f.c.linesize[0], &cdata[0], &clinesizes[0], (C.enum_AVPixelFormat)(f.f.c.format), f.f.c.width, f.f.c.height)
return
return nil
}
return
return nil
}

func (f *frameDataFrame) height() int {
Expand Down
9 changes: 9 additions & 0 deletions frame_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,5 +518,14 @@ func TestFrameData(t *testing.T) {
require.NoError(t, err)
b9 := []byte(fmt.Sprintf("%+v", b8))
require.Equal(t, b3, b9)

f3 := AllocFrame()
defer f3.Free()
require.NoError(t, f3.Ref(f2))
require.Error(t, fd2.FromImage(i1))
require.Error(t, fd2.SetBytes(b1, align))
f3.MakeWritable()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f2 should be the frame that we make writable here

require.NoError(t, fd2.FromImage(i1))
require.NoError(t, fd2.SetBytes(b1, align))
asticode marked this conversation as resolved.
Show resolved Hide resolved
}
}