mirror of
https://github.com/asticode/go-astiav.git
synced 2025-09-27 04:26:30 +08:00
Removed AllocImage and AllocSamples
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
# v0.31.0
|
||||||
|
|
||||||
|
- removed `AllocImage` and `AllocSamples` that are considered useless using CGO until proven otherwise
|
||||||
|
|
||||||
# v0.30.0
|
# v0.30.0
|
||||||
|
|
||||||
- `HardwareFrameContext` has been renamed to `HardwareFramesContext`
|
- `HardwareFrameContext` has been renamed to `HardwareFramesContext`
|
||||||
|
@@ -44,11 +44,6 @@ func main() {
|
|||||||
log.Fatal(fmt.Errorf("main: allocating buffer failed: %w", err))
|
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
|
// When writing data manually into a frame, you need to make sure the frame is writable
|
||||||
if err := audioFrame.MakeWritable(); err != nil {
|
if err := audioFrame.MakeWritable(); err != nil {
|
||||||
log.Fatal(fmt.Errorf("main: making frame writable failed: %w", err))
|
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))
|
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
|
// When writing data manually into a frame, you need to make sure the frame is writable
|
||||||
if err := videoFrame.MakeWritable(); err != nil {
|
if err := videoFrame.MakeWritable(); err != nil {
|
||||||
log.Fatal(fmt.Errorf("main: making frame writable failed: %w", err))
|
log.Fatal(fmt.Errorf("main: making frame writable failed: %w", err))
|
||||||
|
@@ -131,9 +131,6 @@ func main() {
|
|||||||
if err := resampledFrame.AllocBuffer(align); err != nil {
|
if err := resampledFrame.AllocBuffer(align); err != nil {
|
||||||
log.Fatal(fmt.Errorf("main: allocating buffer failed: %w", err))
|
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
|
// 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
|
// 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 {
|
if err := finalFrame.AllocBuffer(align); err != nil {
|
||||||
log.Fatal(fmt.Errorf("main: allocating buffer failed: %w", err))
|
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())
|
af = astiav.AllocAudioFifo(finalFrame.SampleFormat(), finalFrame.ChannelLayout().Channels(), finalFrame.NbSamples())
|
||||||
defer af.Free()
|
defer af.Free()
|
||||||
|
|
||||||
|
10
frame.go
10
frame.go
@@ -41,16 +41,6 @@ func (f *Frame) AllocHardwareBuffer(hfc *HardwareFramesContext) error {
|
|||||||
return newError(C.av_hwframe_get_buffer(hfc.c, f.c, 0))
|
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
|
// https://ffmpeg.org/doxygen/7.0/structAVFrame.html#ae291cdec7758599e765bc9e3edbb3065
|
||||||
func (f *Frame) ChannelLayout() ChannelLayout {
|
func (f *Frame) ChannelLayout() ChannelLayout {
|
||||||
l, _ := newChannelLayoutFromC(&f.c.ch_layout).clone()
|
l, _ := newChannelLayoutFromC(&f.c.ch_layout).clone()
|
||||||
|
@@ -521,14 +521,12 @@ func TestFrameData(t *testing.T) {
|
|||||||
f2.SetSampleFormat(f1.SampleFormat())
|
f2.SetSampleFormat(f1.SampleFormat())
|
||||||
f2.SetSampleRate(f1.SampleRate())
|
f2.SetSampleRate(f1.SampleRate())
|
||||||
require.NoError(t, f2.AllocBuffer(align))
|
require.NoError(t, f2.AllocBuffer(align))
|
||||||
require.NoError(t, f2.AllocSamples(align))
|
|
||||||
case MediaTypeVideo:
|
case MediaTypeVideo:
|
||||||
align = 1
|
align = 1
|
||||||
f2.SetHeight(f1.Height())
|
f2.SetHeight(f1.Height())
|
||||||
f2.SetPixelFormat(f1.PixelFormat())
|
f2.SetPixelFormat(f1.PixelFormat())
|
||||||
f2.SetWidth(f1.Width())
|
f2.SetWidth(f1.Width())
|
||||||
require.NoError(t, f2.AllocBuffer(align))
|
require.NoError(t, f2.AllocBuffer(align))
|
||||||
require.NoError(t, f2.AllocImage(align))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch v.md {
|
switch v.md {
|
||||||
|
@@ -77,7 +77,6 @@ func TestFrame(t *testing.T) {
|
|||||||
f4.SetSampleRate(48000)
|
f4.SetSampleRate(48000)
|
||||||
align := 0
|
align := 0
|
||||||
require.NoError(t, f4.AllocBuffer(align))
|
require.NoError(t, f4.AllocBuffer(align))
|
||||||
require.NoError(t, f4.AllocSamples(align))
|
|
||||||
require.NoError(t, f4.SamplesFillSilence())
|
require.NoError(t, f4.SamplesFillSilence())
|
||||||
n, err := f4.SamplesBufferSize(align)
|
n, err := f4.SamplesBufferSize(align)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -113,7 +112,6 @@ func TestFrame(t *testing.T) {
|
|||||||
f6.SetWidth(4)
|
f6.SetWidth(4)
|
||||||
align = 1
|
align = 1
|
||||||
require.NoError(t, f6.AllocBuffer(align))
|
require.NoError(t, f6.AllocBuffer(align))
|
||||||
require.NoError(t, f6.AllocImage(align))
|
|
||||||
require.NoError(t, f6.ImageFillBlack())
|
require.NoError(t, f6.ImageFillBlack())
|
||||||
n, err = f6.ImageBufferSize(align)
|
n, err = f6.ImageBufferSize(align)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -138,7 +136,6 @@ func TestFrame(t *testing.T) {
|
|||||||
f7.SetPixelFormat(f6.PixelFormat())
|
f7.SetPixelFormat(f6.PixelFormat())
|
||||||
f7.SetWidth(f6.Width())
|
f7.SetWidth(f6.Width())
|
||||||
require.NoError(t, f7.AllocBuffer(align))
|
require.NoError(t, f7.AllocBuffer(align))
|
||||||
require.NoError(t, f7.AllocImage(align))
|
|
||||||
require.NoError(t, f6.Copy(f7))
|
require.NoError(t, f6.Copy(f7))
|
||||||
f6b, err := f6.Data().Bytes(align)
|
f6b, err := f6.Data().Bytes(align)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@@ -20,7 +20,6 @@ func TestSoftwareResampleContext(t *testing.T) {
|
|||||||
f2.SetSampleFormat(SampleFormatS16)
|
f2.SetSampleFormat(SampleFormatS16)
|
||||||
f2.SetSampleRate(24000)
|
f2.SetSampleRate(24000)
|
||||||
require.NoError(t, f2.AllocBuffer(0))
|
require.NoError(t, f2.AllocBuffer(0))
|
||||||
require.NoError(t, f2.AllocSamples(0))
|
|
||||||
|
|
||||||
for _, v := range []struct {
|
for _, v := range []struct {
|
||||||
expectedDelay int64
|
expectedDelay int64
|
||||||
|
Reference in New Issue
Block a user