Removed AllocImage and AllocSamples

This commit is contained in:
Quentin Renard
2025-02-08 16:12:34 +01:00
parent 27082bb9bc
commit 5ed56d0858
7 changed files with 4 additions and 32 deletions

View File

@@ -1,3 +1,7 @@
# v0.31.0
- removed `AllocImage` and `AllocSamples` that are considered useless using CGO until proven otherwise
# v0.30.0
- `HardwareFrameContext` has been renamed to `HardwareFramesContext`

View File

@@ -44,11 +44,6 @@ func main() {
log.Fatal(fmt.Errorf("main: allocating buffer failed: %w", err))
}
// Allocate samples
if err := audioFrame.AllocSamples(align); err != nil {
log.Fatal(fmt.Errorf("main: allocating image failed: %w", err))
}
// When writing data manually into a frame, you need to make sure the frame is writable
if err := audioFrame.MakeWritable(); err != nil {
log.Fatal(fmt.Errorf("main: making frame writable failed: %w", err))
@@ -86,11 +81,6 @@ func main() {
log.Fatal(fmt.Errorf("main: allocating buffer failed: %w", err))
}
// Allocate image
if err := videoFrame.AllocImage(align); err != nil {
log.Fatal(fmt.Errorf("main: allocating image failed: %w", err))
}
// When writing data manually into a frame, you need to make sure the frame is writable
if err := videoFrame.MakeWritable(); err != nil {
log.Fatal(fmt.Errorf("main: making frame writable failed: %w", err))

View File

@@ -131,9 +131,6 @@ func main() {
if err := resampledFrame.AllocBuffer(align); err != nil {
log.Fatal(fmt.Errorf("main: allocating buffer failed: %w", err))
}
if err := resampledFrame.AllocSamples(align); err != nil {
log.Fatal(fmt.Errorf("main: allocating samples failed: %w", err))
}
// For the sake of the example we use an audio FIFO to ensure final frames have an exact constant
// number of samples except for the last one. However this is optional and it depends on your use case
@@ -146,9 +143,6 @@ func main() {
if err := finalFrame.AllocBuffer(align); err != nil {
log.Fatal(fmt.Errorf("main: allocating buffer failed: %w", err))
}
if err := finalFrame.AllocSamples(align); err != nil {
log.Fatal(fmt.Errorf("main: allocating samples failed: %w", err))
}
af = astiav.AllocAudioFifo(finalFrame.SampleFormat(), finalFrame.ChannelLayout().Channels(), finalFrame.NbSamples())
defer af.Free()

View File

@@ -41,16 +41,6 @@ func (f *Frame) AllocHardwareBuffer(hfc *HardwareFramesContext) error {
return newError(C.av_hwframe_get_buffer(hfc.c, f.c, 0))
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__picture.html#ga841e0a89a642e24141af1918a2c10448
func (f *Frame) AllocImage(align int) error {
return newError(C.av_image_alloc(&f.c.data[0], &f.c.linesize[0], f.c.width, f.c.height, (C.enum_AVPixelFormat)(f.c.format), C.int(align)))
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__sampmanip.html#ga4db4c77f928d32c7d8854732f50b8c04
func (f *Frame) AllocSamples(align int) error {
return newError(C.av_samples_alloc(&f.c.data[0], &f.c.linesize[0], f.c.ch_layout.nb_channels, f.c.nb_samples, (C.enum_AVSampleFormat)(f.c.format), C.int(align)))
}
// https://ffmpeg.org/doxygen/7.0/structAVFrame.html#ae291cdec7758599e765bc9e3edbb3065
func (f *Frame) ChannelLayout() ChannelLayout {
l, _ := newChannelLayoutFromC(&f.c.ch_layout).clone()

View File

@@ -521,14 +521,12 @@ func TestFrameData(t *testing.T) {
f2.SetSampleFormat(f1.SampleFormat())
f2.SetSampleRate(f1.SampleRate())
require.NoError(t, f2.AllocBuffer(align))
require.NoError(t, f2.AllocSamples(align))
case MediaTypeVideo:
align = 1
f2.SetHeight(f1.Height())
f2.SetPixelFormat(f1.PixelFormat())
f2.SetWidth(f1.Width())
require.NoError(t, f2.AllocBuffer(align))
require.NoError(t, f2.AllocImage(align))
}
switch v.md {

View File

@@ -77,7 +77,6 @@ func TestFrame(t *testing.T) {
f4.SetSampleRate(48000)
align := 0
require.NoError(t, f4.AllocBuffer(align))
require.NoError(t, f4.AllocSamples(align))
require.NoError(t, f4.SamplesFillSilence())
n, err := f4.SamplesBufferSize(align)
require.NoError(t, err)
@@ -113,7 +112,6 @@ func TestFrame(t *testing.T) {
f6.SetWidth(4)
align = 1
require.NoError(t, f6.AllocBuffer(align))
require.NoError(t, f6.AllocImage(align))
require.NoError(t, f6.ImageFillBlack())
n, err = f6.ImageBufferSize(align)
require.NoError(t, err)
@@ -138,7 +136,6 @@ func TestFrame(t *testing.T) {
f7.SetPixelFormat(f6.PixelFormat())
f7.SetWidth(f6.Width())
require.NoError(t, f7.AllocBuffer(align))
require.NoError(t, f7.AllocImage(align))
require.NoError(t, f6.Copy(f7))
f6b, err := f6.Data().Bytes(align)
require.NoError(t, err)

View File

@@ -20,7 +20,6 @@ func TestSoftwareResampleContext(t *testing.T) {
f2.SetSampleFormat(SampleFormatS16)
f2.SetSampleRate(24000)
require.NoError(t, f2.AllocBuffer(0))
require.NoError(t, f2.AllocSamples(0))
for _, v := range []struct {
expectedDelay int64