mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-05 16:16:50 +08:00
Add AVPixFmtDescriptor to retrieve flags for AVPixelFormat (#154)
* 1. Adds hardware_frames_constraints to retrieve valid HWPixelFormats and SWPixelFormats for specific hardware frame configurations. 2. Implements a HardwareFramesConstraints method in hardware_device_context to obtain these constraints for a given hardware frames context. * Add AVPixFmtDescriptor to retrieve flags for AVPixelFormat feat(PixelFormat): Expose `AVPixFmtDescriptor` via `Descriptor()` method This commit introduces support for `AVPixFmtDescriptor`, which provides detailed information about an `AVPixelFormat`, including its flags. A new `Descriptor()` method has been added to the `PixelFormat` type (or class) to retrieve its corresponding `AVPixFmtDescriptor`. This allows for easier access to extended properties of pixel formats.
This commit is contained in:
20
flags.go
20
flags.go
@@ -305,6 +305,26 @@ func (fs PacketFlags) Del(f PacketFlag) PacketFlags {
|
|||||||
|
|
||||||
func (fs PacketFlags) Has(f PacketFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
func (fs PacketFlags) Has(f PacketFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||||
|
|
||||||
|
type PixelFormatDescriptorFlags astikit.BitFlags
|
||||||
|
|
||||||
|
func NewPixelFormatDescriptorFlags(fs ...PixelFormatDescriptorFlag) PixelFormatDescriptorFlags {
|
||||||
|
o := PixelFormatDescriptorFlags(0)
|
||||||
|
for _, f := range fs {
|
||||||
|
o = o.Add(f)
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fs PixelFormatDescriptorFlags) Add(f PixelFormatDescriptorFlag) PixelFormatDescriptorFlags {
|
||||||
|
return PixelFormatDescriptorFlags(astikit.BitFlags(fs).Add(uint64(f)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fs PixelFormatDescriptorFlags) Del(f PixelFormatDescriptorFlag) PixelFormatDescriptorFlags {
|
||||||
|
return PixelFormatDescriptorFlags(astikit.BitFlags(fs).Del(uint64(f)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fs PixelFormatDescriptorFlags) Has(f PixelFormatDescriptorFlag) bool { return astikit.BitFlags(fs).Has(uint64(f)) }
|
||||||
|
|
||||||
type SeekFlags astikit.BitFlags
|
type SeekFlags astikit.BitFlags
|
||||||
|
|
||||||
func NewSeekFlags(fs ...SeekFlag) SeekFlags {
|
func NewSeekFlags(fs ...SeekFlag) SeekFlags {
|
||||||
|
@@ -141,6 +141,15 @@ func TestPacketFlags(t *testing.T) {
|
|||||||
require.False(t, fs.Has(PacketFlag(2)))
|
require.False(t, fs.Has(PacketFlag(2)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPixelFormatDescriptorFlags(t *testing.T) {
|
||||||
|
fs := NewPixelFormatDescriptorFlags(PixelFormatDescriptorFlag(1))
|
||||||
|
require.True(t, fs.Has(PixelFormatDescriptorFlag(1)))
|
||||||
|
fs = fs.Add(PixelFormatDescriptorFlag(2))
|
||||||
|
require.True(t, fs.Has(PixelFormatDescriptorFlag(2)))
|
||||||
|
fs = fs.Del(PixelFormatDescriptorFlag(2))
|
||||||
|
require.False(t, fs.Has(PixelFormatDescriptorFlag(2)))
|
||||||
|
}
|
||||||
|
|
||||||
func TestSeekFlags(t *testing.T) {
|
func TestSeekFlags(t *testing.T) {
|
||||||
fs := NewSeekFlags(SeekFlag(1))
|
fs := NewSeekFlags(SeekFlag(1))
|
||||||
require.True(t, fs.Has(SeekFlag(1)))
|
require.True(t, fs.Has(SeekFlag(1)))
|
||||||
|
@@ -29,6 +29,7 @@ var list = []listItem{
|
|||||||
{Name: "IOFormat"},
|
{Name: "IOFormat"},
|
||||||
{Name: "OptionSearch"},
|
{Name: "OptionSearch"},
|
||||||
{Name: "Packet"},
|
{Name: "Packet"},
|
||||||
|
{Name: "PixelFormatDescriptor"},
|
||||||
{Name: "Seek"},
|
{Name: "Seek"},
|
||||||
{Name: "SoftwareScaleContext"},
|
{Name: "SoftwareScaleContext"},
|
||||||
{Name: "StreamEvent"},
|
{Name: "StreamEvent"},
|
||||||
|
@@ -211,6 +211,10 @@ func (f PixelFormat) String() string {
|
|||||||
return f.Name()
|
return f.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f PixelFormat) Descriptor() *PixelFormatDescriptor {
|
||||||
|
return newPixelFormatDescriptorFromC(C.av_pix_fmt_desc_get((C.enum_AVPixelFormat)(f)))
|
||||||
|
}
|
||||||
|
|
||||||
// https://ffmpeg.org/doxygen/7.0/pixdesc_8c.html#a925ef18d69c24c3be8c53d5a7dc0660e
|
// https://ffmpeg.org/doxygen/7.0/pixdesc_8c.html#a925ef18d69c24c3be8c53d5a7dc0660e
|
||||||
func FindPixelFormatByName(name string) PixelFormat {
|
func FindPixelFormatByName(name string) PixelFormat {
|
||||||
cn := C.CString(name)
|
cn := C.CString(name)
|
||||||
|
26
pixel_format_descriptor.go
Normal file
26
pixel_format_descriptor.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package astiav
|
||||||
|
|
||||||
|
//#include <libavutil/pixdesc.h>
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
// https://ffmpeg.org/doxygen/7.0/structAVPixFmtDescriptor.html
|
||||||
|
type PixelFormatDescriptor struct {
|
||||||
|
c *C.AVPixFmtDescriptor
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPixelFormatDescriptorFromC(c *C.AVPixFmtDescriptor) *PixelFormatDescriptor {
|
||||||
|
if c == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &PixelFormatDescriptor{c: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://ffmpeg.org/doxygen/7.0/structAVPixFmtDescriptor.html#a10736c3f1288eb87b23ede3ffdefb435
|
||||||
|
func (pfd *PixelFormatDescriptor) Name() string {
|
||||||
|
return C.GoString(pfd.c.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://ffmpeg.org/doxygen/7.0/structAVPixFmtDescriptor.html#a5047d1e6b045f637345dbc305bf4357d
|
||||||
|
func (pfd *PixelFormatDescriptor) Flags() PixelFormatDescriptorFlags {
|
||||||
|
return PixelFormatDescriptorFlags(pfd.c.flags)
|
||||||
|
}
|
20
pixel_format_descriptor_flag.go
Normal file
20
pixel_format_descriptor_flag.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package astiav
|
||||||
|
|
||||||
|
//#include <libavutil/pixdesc.h>
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
// https://ffmpeg.org/doxygen/7.0/pixdesc_8h.html#ac7c7d0be16fb9b6f05b3e0d463cd037b
|
||||||
|
type PixelFormatDescriptorFlag int64
|
||||||
|
|
||||||
|
const (
|
||||||
|
PixelFormatDescriptorFlagBe = PixelFormatDescriptorFlag(C.AV_PIX_FMT_FLAG_BE)
|
||||||
|
PixelFormatDescriptorFlagPal = PixelFormatDescriptorFlag(C.AV_PIX_FMT_FLAG_PAL)
|
||||||
|
PixelFormatDescriptorFlagBitStream = PixelFormatDescriptorFlag(C.AV_PIX_FMT_FLAG_BITSTREAM)
|
||||||
|
PixelFormatDescriptorFlagHwAccel = PixelFormatDescriptorFlag(C.AV_PIX_FMT_FLAG_HWACCEL)
|
||||||
|
PixelFormatDescriptorFlagPlanar = PixelFormatDescriptorFlag(C.AV_PIX_FMT_FLAG_PLANAR)
|
||||||
|
PixelFormatDescriptorFlagRgb = PixelFormatDescriptorFlag(C.AV_PIX_FMT_FLAG_RGB)
|
||||||
|
PixelFormatDescriptorFlagAlpha = PixelFormatDescriptorFlag(C.AV_PIX_FMT_FLAG_ALPHA)
|
||||||
|
PixelFormatDescriptorFlagBayer = PixelFormatDescriptorFlag(C.AV_PIX_FMT_FLAG_BAYER)
|
||||||
|
PixelFormatDescriptorFlagFloat = PixelFormatDescriptorFlag(C.AV_PIX_FMT_FLAG_FLOAT)
|
||||||
|
PixelFormatDescriptorFlagXyz = PixelFormatDescriptorFlag(C.AV_PIX_FMT_FLAG_XYZ)
|
||||||
|
)
|
15
pixel_format_descriptor_test.go
Normal file
15
pixel_format_descriptor_test.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package astiav
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPixelFormatDescriptor(t *testing.T) {
|
||||||
|
p := PixelFormatCuda
|
||||||
|
d := p.Descriptor()
|
||||||
|
require.NotNil(t, d)
|
||||||
|
require.Equal(t, d.Name(), p.String())
|
||||||
|
require.True(t, d.Flags().Has(PixelFormatDescriptorFlagHwAccel))
|
||||||
|
}
|
@@ -10,4 +10,7 @@ func TestPixelFormat(t *testing.T) {
|
|||||||
p := FindPixelFormatByName("yuv420p")
|
p := FindPixelFormatByName("yuv420p")
|
||||||
require.Equal(t, PixelFormatYuv420P, p)
|
require.Equal(t, PixelFormatYuv420P, p)
|
||||||
require.Equal(t, "yuv420p", p.String())
|
require.Equal(t, "yuv420p", p.String())
|
||||||
|
d := p.Descriptor()
|
||||||
|
require.NotNil(t, d)
|
||||||
|
require.Equal(t, d.Name(), p.String())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user