Skip to content

Commit

Permalink
Added links to C doc
Browse files Browse the repository at this point in the history
  • Loading branch information
asticode committed Nov 14, 2024
1 parent 1841ad5 commit b15d5d0
Show file tree
Hide file tree
Showing 80 changed files with 539 additions and 115 deletions.
4 changes: 4 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.25.0

- `CodecParameters`.`CodecType` and `CodecParameters`.`SetCodecType` have been removed, use `CodecParameters`.`MediaType` and `CodecParameters`.`SetMediaType` instead

# v0.24.0

- use `FilterGraph`.`NewBuffersinkFilterContext` and `FilterGraph`.`NewBuffersrcFilterContext` instead of `FilterGraph`.`NewFilterContext` when creating `buffersink` and `buffersrc` filter contexts and use `BuffersinkFilterContext`.`GetFrame` and `BuffersrcFilterContext`.`AddFrame` to manipulate them. Use `BuffersinkFilterContext`.`FilterContext` and `BuffersrcFilterContext`.`FilterContext` in `FilterInOut`.`SetFilterContext`.
Expand Down
9 changes: 8 additions & 1 deletion audio_fifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package astiav
import "C"
import "unsafe"

// https://github.com/FFmpeg/FFmpeg/blob/n7.0/libavutil/audio_fifo.c#L37
// https://ffmpeg.org/doxygen/7.0/structAVAudioFifo.html
type AudioFifo struct {
c *C.AVAudioFifo
}
Expand All @@ -16,22 +16,27 @@ func newAudioFifoFromC(c *C.AVAudioFifo) *AudioFifo {
return &AudioFifo{c: c}
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga9d792394f0615a329aec47847f8f8784
func AllocAudioFifo(sampleFmt SampleFormat, channels int, nbSamples int) *AudioFifo {
return newAudioFifoFromC(C.av_audio_fifo_alloc(C.enum_AVSampleFormat(sampleFmt), C.int(channels), C.int(nbSamples)))
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga27c1e16e5f09940d6016b1971c0b5742
func (a *AudioFifo) Realloc(nbSamples int) error {
return newError(C.av_audio_fifo_realloc(a.c, C.int(nbSamples)))
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#gaa0a4742ecac52a999e8b4478d27f3b9b
func (a *AudioFifo) Size() int {
return int(C.av_audio_fifo_size(a.c))
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga2bed2f01fe34228ee8a73617b3177d00
func (a *AudioFifo) Space() int {
return int(C.av_audio_fifo_space(a.c))
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga51d81a165872919bbfdee3f00f6d6530
func (a *AudioFifo) Write(f *Frame) (int, error) {
ret := C.av_audio_fifo_write(a.c, (*unsafe.Pointer)(unsafe.Pointer(&f.c.data[0])), C.int(f.NbSamples()))
if err := newError(ret); err != nil {
Expand All @@ -40,6 +45,7 @@ func (a *AudioFifo) Write(f *Frame) (int, error) {
return int(ret), nil
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga5e2c87bbeefba0d229b4109b4b755529
func (a *AudioFifo) Read(f *Frame) (int, error) {
ret := C.av_audio_fifo_read(a.c, (*unsafe.Pointer)(unsafe.Pointer(&f.c.data[0])), C.int(f.NbSamples()))
if err := newError(ret); err != nil {
Expand All @@ -48,6 +54,7 @@ func (a *AudioFifo) Read(f *Frame) (int, error) {
return int(ret), nil
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga74e029e47f7aa99217ad1f315c434875
func (a *AudioFifo) Free() {
C.av_audio_fifo_free(a.c)
}
4 changes: 3 additions & 1 deletion bit_stream_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"unsafe"
)

// https://github.com/FFmpeg/FFmpeg/blob/release/5.1/libavcodec/bsf.h#L111
// https://ffmpeg.org/doxygen/7.0/structAVBitStreamFilter.html
type BitStreamFilter struct {
c *C.AVBitStreamFilter
}
Expand All @@ -19,12 +19,14 @@ func newBitStreamFilterFromC(c *C.AVBitStreamFilter) *BitStreamFilter {
return &BitStreamFilter{c: c}
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__bsf.html#gae491493190b45698ebd43db28c4e8fe9
func FindBitStreamFilterByName(n string) *BitStreamFilter {
cn := C.CString(n)
defer C.free(unsafe.Pointer(cn))
return newBitStreamFilterFromC(C.av_bsf_get_by_name(cn))
}

// https://ffmpeg.org/doxygen/7.0/structAVBitStreamFilter.html#a33c3cb51bd13060da35481655b41e4e5
func (bsf *BitStreamFilter) Name() string {
return C.GoString(bsf.c.name)
}
Expand Down
11 changes: 10 additions & 1 deletion bit_stream_filter_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"unsafe"
)

// https://github.com/FFmpeg/FFmpeg/blob/release/5.1/libavcodec/bsf.h#L68
// https://ffmpeg.org/doxygen/7.0/structAVBSFContext.html
type BitStreamFilterContext struct {
c *C.AVBSFContext
}
Expand All @@ -23,6 +23,7 @@ func newBSFContextFromC(c *C.AVBSFContext) *BitStreamFilterContext {

var _ Classer = (*BitStreamFilterContext)(nil)

// https://ffmpeg.org/doxygen/7.0/group__lavc__bsf.html#ga7da65af303e20c9546e15ec266b182c1
func AllocBitStreamFilterContext(f *BitStreamFilter) (*BitStreamFilterContext, error) {
if f == nil {
return nil, errors.New("astiav: bit stream filter must not be nil")
Expand All @@ -36,14 +37,17 @@ func AllocBitStreamFilterContext(f *BitStreamFilter) (*BitStreamFilterContext, e
return newBSFContextFromC(bsfc), nil
}

// https://ffmpeg.org/doxygen/7.0/structAVBSFContext.html#aa5d5018816daac804414c459ec8a1c5c
func (bsfc *BitStreamFilterContext) Class() *Class {
return newClassFromC(unsafe.Pointer(bsfc.c))
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__bsf.html#ga242529d54013acf87e94273d298a5ff2
func (bsfc *BitStreamFilterContext) Initialize() error {
return newError(C.av_bsf_init(bsfc.c))
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__bsf.html#gaada9ea8f08d3dcf23c14564dbc88992c
func (bsfc *BitStreamFilterContext) SendPacket(p *Packet) error {
var pc *C.AVPacket
if p != nil {
Expand All @@ -52,13 +56,15 @@ func (bsfc *BitStreamFilterContext) SendPacket(p *Packet) error {
return newError(C.av_bsf_send_packet(bsfc.c, pc))
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__bsf.html#ga7fffb6c87b91250956e7a2367af56b38
func (bsfc *BitStreamFilterContext) ReceivePacket(p *Packet) error {
if p == nil {
return errors.New("astiav: packet must not be nil")
}
return newError(C.av_bsf_receive_packet(bsfc.c, p.c))
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__bsf.html#ga08d53431e76355f88e27763b1940df4f
func (bsfc *BitStreamFilterContext) Free() {
if bsfc.c != nil {
// Make sure to clone the classer before freeing the object since
Expand All @@ -73,14 +79,17 @@ func (bsfc *BitStreamFilterContext) Free() {
}
}

// https://ffmpeg.org/doxygen/7.0/structAVBSFContext.html#ad75adf988c00f89202099c87ea39f0db
func (bsfc *BitStreamFilterContext) InputTimeBase() Rational {
return newRationalFromC(bsfc.c.time_base_in)
}

// https://ffmpeg.org/doxygen/7.0/structAVBSFContext.html#ad75adf988c00f89202099c87ea39f0db
func (bsfc *BitStreamFilterContext) SetInputTimeBase(r Rational) {
bsfc.c.time_base_in = r.c
}

// https://ffmpeg.org/doxygen/7.0/structAVBSFContext.html#a702ace639b8193475cf0a12ebdebd738
func (bsfc *BitStreamFilterContext) InputCodecParameters() *CodecParameters {
return newCodecParametersFromC(bsfc.c.par_in)
}
2 changes: 1 addition & 1 deletion buffersink_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package astiav
//#include <libavfilter/buffersink.h>
import "C"

// https://ffmpeg.org/doxygen/7.0/group__lavfi__buffersink.html#ga9453fc0e81d30237080b51575da0f0d8
type BuffersinkFlag int64

// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavfilter/buffersink.h#L89
const (
BuffersinkFlagPeek = BuffersinkFlag(C.AV_BUFFERSINK_FLAG_PEEK)
BuffersinkFlagNoRequest = BuffersinkFlag(C.AV_BUFFERSINK_FLAG_NO_REQUEST)
Expand Down
2 changes: 1 addition & 1 deletion buffersrc_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package astiav
//#include <libavfilter/buffersrc.h>
import "C"

// https://ffmpeg.org/doxygen/7.0/group__lavfi__buffersrc.html#gga9e9505a91a84992d04ba4e85217fb4e4a6efcf61145ec6d60d3a773fcd0797872
type BuffersrcFlag int64

// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavfilter/buffersrc.h#L36
const (
BuffersrcFlagNoCheckFormat = BuffersrcFlag(C.AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT)
BuffersrcFlagPush = BuffersrcFlag(C.AV_BUFFERSRC_FLAG_PUSH)
Expand Down
8 changes: 7 additions & 1 deletion channel_layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"unsafe"
)

// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/channel_layout.h#L90
// https://ffmpeg.org/doxygen/7.0/group__lavu__audio__channels.html#ga855bb7dede67971e95bd09d8fcca7293
var (
ChannelLayoutMono = newChannelLayoutFromC(C.astiavChannelLayoutMono)
ChannelLayoutStereo = newChannelLayoutFromC(C.astiavChannelLayoutStereo)
Expand Down Expand Up @@ -46,6 +46,7 @@ var (
ChannelLayout7Point1TopBack = newChannelLayoutFromC(C.astiavChannelLayout7Point1TopBack)
)

// https://ffmpeg.org/doxygen/7.0/structAVChannelLayout.html
type ChannelLayout struct {
c *C.AVChannelLayout
}
Expand All @@ -54,6 +55,7 @@ func newChannelLayoutFromC(c *C.AVChannelLayout) ChannelLayout {
return ChannelLayout{c: c}
}

// https://ffmpeg.org/doxygen/7.0/structAVChannelLayout.html#adfd3f460a8ea1575baa32852d9248d3c
func (l ChannelLayout) Channels() int {
if l.c == nil {
return 0
Expand All @@ -70,6 +72,7 @@ func (l ChannelLayout) String() string {
return string(b[:n])
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audio__channels.html#gacc7d7d1a280248aafb8f9196c9d4e24f
func (l ChannelLayout) Describe(b []byte) (int, error) {
if l.c == nil {
return 0, nil
Expand All @@ -84,13 +87,15 @@ func (l ChannelLayout) Describe(b []byte) (int, error) {
return int(ret), nil
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audio__channels.html#gad15a6bf80ee8551ee4a4789d970ccbea
func (l ChannelLayout) Valid() bool {
if l.c == nil {
return false
}
return C.av_channel_layout_check(l.c) > 0
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audio__channels.html#ga5da99475fc07b778522974a2e0a1f58c
func (l ChannelLayout) Compare(l2 ChannelLayout) (equal bool, err error) {
if l.c == nil || l2.c == nil {
return l.c == nil && l2.c == nil, nil
Expand All @@ -107,6 +112,7 @@ func (l ChannelLayout) Equal(l2 ChannelLayout) bool {
return v
}

// https://ffmpeg.org/doxygen/7.0/group__lavu__audio__channels.html#gad36be43b2a1b14b66492b8025b82f886
func (l ChannelLayout) copy(dst *C.AVChannelLayout) error {
return newError(C.av_channel_layout_copy(dst, l.c))
}
Expand Down
2 changes: 1 addition & 1 deletion chroma_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package astiav
//#include <libavutil/pixfmt.h>
import "C"

// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/pixfmt.h#L616
// https://ffmpeg.org/doxygen/7.0/pixfmt_8h.html#a1f86ed1b6a420faccacf77c98db6c1ff
type ChromaLocation C.enum_AVChromaLocation

const (
Expand Down
6 changes: 5 additions & 1 deletion class.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"unsafe"
)

// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/log.h#L66
// https://ffmpeg.org/doxygen/7.0/structAVClass.html
type Class struct {
c *C.AVClass
ptr unsafe.Pointer
Expand All @@ -28,18 +28,22 @@ func newClassFromC(ptr unsafe.Pointer) *Class {
}
}

// https://ffmpeg.org/doxygen/7.0/structAVClass.html#a5fc161d93a0d65a608819da20b7203ba
func (c *Class) Category() ClassCategory {
return ClassCategory(C.astiavClassCategory(c.c, c.ptr))
}

// https://ffmpeg.org/doxygen/7.0/structAVClass.html#ad763b2e6a0846234a165e74574a550bd
func (c *Class) ItemName() string {
return C.GoString(C.astiavClassItemName(c.c, c.ptr))
}

// https://ffmpeg.org/doxygen/7.0/structAVClass.html#aa8883e113a3f2965abd008f7667db7eb
func (c *Class) Name() string {
return C.GoString(c.c.class_name)
}

// https://ffmpeg.org/doxygen/7.0/structAVClass.html#a88948c8a7c6515181771615a54a808bf
func (c *Class) Parent() *Class {
return newClassFromC(unsafe.Pointer(C.astiavClassParent(c.c, c.ptr)))
}
Expand Down
2 changes: 1 addition & 1 deletion class_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package astiav
//#include <libavutil/log.h>
import "C"

// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/log.h#L28
// https://ffmpeg.org/doxygen/7.0/log_8h.html#aeb1c06cc3e47a029ca6afeac782ac8f9
type ClassCategory C.AVClassCategory

const (
Expand Down
15 changes: 14 additions & 1 deletion codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"unsafe"
)

// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/codec.h#L202
// https://ffmpeg.org/doxygen/7.0/structAVCodec.html
type Codec struct {
c *C.AVCodec
}
Expand All @@ -19,6 +19,7 @@ func newCodecFromC(c *C.AVCodec) *Codec {
return &Codec{c: c}
}

// https://ffmpeg.org/doxygen/7.0/structAVCodec.html#ad3daa3e729850b573c139a83be8938ca
func (c *Codec) Name() string {
return C.GoString(c.c.name)
}
Expand All @@ -27,10 +28,12 @@ func (c *Codec) String() string {
return c.Name()
}

// https://ffmpeg.org/doxygen/7.0/structAVCodec.html#a01a53d07936f4c7ee280444793b6967b
func (c *Codec) ID() CodecID {
return CodecID(c.c.id)
}

// https://ffmpeg.org/doxygen/7.0/structAVCodec.html#a710e3bd3081124ef3364b0c520379dd8
func (c *Codec) ChannelLayouts() (o []ChannelLayout) {
if c.c.ch_layouts == nil {
return nil
Expand All @@ -46,14 +49,17 @@ func (c *Codec) ChannelLayouts() (o []ChannelLayout) {
return
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__core.html#ga6dc18eef1afca3610644a52565cf8a31
func (c *Codec) IsDecoder() bool {
return int(C.av_codec_is_decoder(c.c)) != 0
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__core.html#ga2b665824e4d9144f8d4f6c01e3e85aa3
func (c *Codec) IsEncoder() bool {
return int(C.av_codec_is_encoder(c.c)) != 0
}

// https://ffmpeg.org/doxygen/7.0/structAVCodec.html#ac2b97bd3c19686025e1b7d577329c250
func (c *Codec) PixelFormats() (o []PixelFormat) {
if c.c.pix_fmts == nil {
return nil
Expand All @@ -69,6 +75,7 @@ func (c *Codec) PixelFormats() (o []PixelFormat) {
return
}

// https://ffmpeg.org/doxygen/7.0/structAVCodec.html#aac19f4c45370f715412ad5c7b78daacf
func (c *Codec) SampleFormats() (o []SampleFormat) {
if c.c.sample_fmts == nil {
return nil
Expand All @@ -84,26 +91,31 @@ func (c *Codec) SampleFormats() (o []SampleFormat) {
return
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__core.html#ga51e35d01da2b3833b3afa839212c58fa
func FindDecoder(id CodecID) *Codec {
return newCodecFromC(C.avcodec_find_decoder((C.enum_AVCodecID)(id)))
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__core.html#gad4e08a758f3560006145db074d16cb47
func FindDecoderByName(n string) *Codec {
cn := C.CString(n)
defer C.free(unsafe.Pointer(cn))
return newCodecFromC(C.avcodec_find_decoder_by_name(cn))
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__core.html#ga68e4b5f31de5e5fc25d5781a1be22331
func FindEncoder(id CodecID) *Codec {
return newCodecFromC(C.avcodec_find_encoder((C.enum_AVCodecID)(id)))
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__core.html#ga9fa02c1eae54a2ec67beb789c2688d6e
func FindEncoderByName(n string) *Codec {
cn := C.CString(n)
defer C.free(unsafe.Pointer(cn))
return newCodecFromC(C.avcodec_find_encoder_by_name(cn))
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__core.html#ga4f80582a2ea9c0e141de5d6f6152008f
func (c *Codec) HardwareConfigs() (configs []CodecHardwareConfig) {
var i int
for {
Expand All @@ -117,6 +129,7 @@ func (c *Codec) HardwareConfigs() (configs []CodecHardwareConfig) {
return
}

// https://ffmpeg.org/doxygen/7.0/group__lavc__core.html#ga7cd040fcc147340186deb0c54dc996b0
func Codecs() (cs []*Codec) {
var opq *C.void = nil
for {
Expand Down
Loading

0 comments on commit b15d5d0

Please sign in to comment.