Skip to content

Commit

Permalink
Program and Discard
Browse files Browse the repository at this point in the history
  • Loading branch information
oldma3095 committed Dec 13, 2024
1 parent 37d482b commit 9894cd7
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_STORE
coverage.out
coverage.out
.idea
17 changes: 17 additions & 0 deletions discard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package astiav

//#include <libavcodec/defs.h>
import "C"

// https://ffmpeg.org/doxygen/7.0/group__lavc__decoding.html#ga352363bce7d3ed82c101b3bc001d1c16
type Discard C.enum_AVDiscard

const (
DiscardNone = Discard(C.AVDISCARD_NONE) // discard nothing
DiscardDefault = Discard(C.AVDISCARD_DEFAULT) // discard useless packets like 0 size packets in avi
DiscardNonRef = Discard(C.AVDISCARD_NONREF) // discard all non reference
DiscardBidirectional = Discard(C.AVDISCARD_BIDIR) // discard all bidirectional frames
DiscardNonIntra = Discard(C.AVDISCARD_NONINTRA) // discard all non intra frames
DiscardNonKey = Discard(C.AVDISCARD_NONKEY) // discard all frames except keyframes
DiscardAll = Discard(C.AVDISCARD_ALL) // discard all
)
17 changes: 17 additions & 0 deletions discard_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package astiav

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestDiscard(t *testing.T) {
require.Equal(t, int(DiscardNone), -16)
require.Equal(t, int(DiscardDefault), 0)
require.Equal(t, int(DiscardNonRef), 8)
require.Equal(t, int(DiscardBidirectional), 16)
require.Equal(t, int(DiscardNonIntra), 24)
require.Equal(t, int(DiscardNonKey), 32)
require.Equal(t, int(DiscardAll), 48)
}
75 changes: 75 additions & 0 deletions program.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,78 @@ func (p *Program) Streams() (ss []*Stream) {
}
return
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a8c87564167b87f54be9171778d51fe49
func (p *Program) Flags() int {
return int(p.c.flags)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a8c87564167b87f54be9171778d51fe49
func (p *Program) SetFlags(f int) {
p.c.flags = C.int(f)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a9c7a07c08a1f960aaa49f3f47633af5c
func (p *Program) Discard() Discard {
return Discard(p.c.discard)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a9c7a07c08a1f960aaa49f3f47633af5c
func (p *Program) SetDiscard(d Discard) {
p.c.discard = int32(d)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a7967d41af4812ed61a28762e988c7a02
func (p *Program) StreamIndex() uint {
return uint(C.uint(*p.c.stream_index))
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#ae9dab38d4694e3da9cba0f882f4e43d3
func (p *Program) Metadata() *Dictionary {
return newDictionaryFromC(p.c.metadata)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#ae9dab38d4694e3da9cba0f882f4e43d3
func (p *Program) SetMetadata(d *Dictionary) {
p.c.metadata = d.c
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a4c1539ea3c98da979b95a59a3ea163cb
func (p *Program) ProgramNum() int {
return int(p.c.program_num)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a02011963a63c291c6dc6d4eefa56cd69
func (p *Program) PmtPid() int {
return int(p.c.pmt_pid)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a7e026323df87e84a72ec5e5c8ce341a5
func (p *Program) PcrPid() int {
return int(p.c.pcr_pid)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#acac8164436263b310d867ec650a2ea58
func (p *Program) PmtVersion() int {
return int(p.c.pmt_version)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a2276db4d51695120664d527f20b7c532
func (p *Program) StartTime() int64 {
return int64(p.c.start_time)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a5a7795c918153d0f64d68a838e172db4
func (p *Program) EndTime() int64 {
return int64(p.c.end_time)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a7e539e286876577e158039f6e7678452
func (p *Program) PtsWrapReference() int64 {
return int64(p.c.pts_wrap_reference)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#aa3f8af78093a910ff766ac5af381758b
func (p *Program) PtsWrapBehavior() int {
return int(p.c.pts_wrap_behavior)
}
9 changes: 9 additions & 0 deletions program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ func TestProgram(t *testing.T) {
ss := p.Streams()
require.Equal(t, 1, len(ss))
require.Equal(t, s.ID(), ss[0].ID())

p.SetFlags(1)
require.Equal(t, 1, p.Flags())
p.SetDiscard(DiscardAll)
require.Equal(t, DiscardAll, p.Discard())
d := NewDictionary()
_ = d.Set("service_name", "test_service_name", 0)
p.SetMetadata(d)
require.Equal(t, p.Metadata().Get("service_name", nil, 0).Value(), "test_service_name")
}

0 comments on commit 9894cd7

Please sign in to comment.