mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-06 00:26:52 +08:00
Check if the frame is writable before copyPlanes (#84)
* check if the frame is writable before copyPlanes * apply review * make f2 writable
This commit is contained in:
@@ -280,7 +280,12 @@ func (f *frameDataFrame) bytes(align int) ([]byte, error) {
|
|||||||
return nil, errors.New("astiav: frame type not implemented")
|
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 {
|
switch {
|
||||||
// Video
|
// Video
|
||||||
case f.height() > 0 && f.width() > 0:
|
case f.height() > 0 && f.width() > 0:
|
||||||
@@ -300,9 +305,9 @@ func (f *frameDataFrame) copyPlanes(ps []frameDataPlane) (err error) {
|
|||||||
|
|
||||||
// Copy image
|
// 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)
|
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 {
|
func (f *frameDataFrame) height() int {
|
||||||
|
@@ -518,5 +518,14 @@ func TestFrameData(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
b9 := []byte(fmt.Sprintf("%+v", b8))
|
b9 := []byte(fmt.Sprintf("%+v", b8))
|
||||||
require.Equal(t, b3, b9)
|
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))
|
||||||
|
f2.MakeWritable()
|
||||||
|
require.NoError(t, fd2.FromImage(i1))
|
||||||
|
require.NoError(t, fd2.SetBytes(b1, align))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user