Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program params and enum Discardxx #119

Merged
merged 23 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
DiscardDefault = Discard(C.AVDISCARD_DEFAULT)
DiscardNonRef = Discard(C.AVDISCARD_NONREF)
DiscardBidirectional = Discard(C.AVDISCARD_BIDIR)
DiscardNonIntra = Discard(C.AVDISCARD_NONINTRA)
DiscardNonKey = Discard(C.AVDISCARD_NONKEY)
DiscardAll = Discard(C.AVDISCARD_ALL)
)
86 changes: 86 additions & 0 deletions program.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,89 @@ func (p *Program) Streams() (ss []*Stream) {
}
return
}

// 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 {
if p.c.stream_index == nil {
return nil
}
u := uint(C.uint(*p.c.stream_index))
return &u
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a7967d41af4812ed61a28762e988c7a02
func (p *Program) SetStreamIndex(n uint) {
if p.c.stream_index != nil {
*p.c.stream_index = C.uint(n)
}
}

// 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) ProgramNumber() int {
return int(p.c.program_num)
}

// https://ffmpeg.org/doxygen/7.0/structAVProgram.html#a4c1539ea3c98da979b95a59a3ea163cb
func (p *Program) SetProgramNumber(n int) {
p.c.program_num = C.int(n)
}

oldma3095 marked this conversation as resolved.
Show resolved Hide resolved
// 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#a02011963a63c291c6dc6d4eefa56cd69
func (p *Program) SetPmtPid(n int) {
p.c.pmt_pid = C.int(n)
}

// 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#a7e026323df87e84a72ec5e5c8ce341a5
func (p *Program) SetPcrPid(n int) {
p.c.pcr_pid = C.int(n)
}

// 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)
}
22 changes: 22 additions & 0 deletions program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,33 @@ func TestProgram(t *testing.T) {
require.Equal(t, 1, p.ID())
p.SetID(2)
require.Equal(t, 2, p.ID())
p.SetDiscard(DiscardAll)
require.Equal(t, DiscardAll, p.Discard())
d := NewDictionary()
require.NoError(t, 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")
p.SetProgramNumber(101)
require.Equal(t, 101, p.ProgramNumber())
p.SetPmtPid(201)
require.Equal(t, 201, p.PmtPid())
p.SetPcrPid(301)
require.Equal(t, 301, p.PcrPid())
require.Equal(t, p.StartTime(), NoPtsValue)
require.Equal(t, p.EndTime(), NoPtsValue)
require.Equal(t, p.PtsWrapReference(), NoPtsValue)
require.Equal(t, p.PtsWrapBehavior(), 0)
s := fc.NewStream(nil)
s.SetID(2)
require.Equal(t, 0, p.NbStreams())
require.Nil(t, p.StreamIndex(), nil)
p.AddStream(s)
require.Equal(t, 1, p.NbStreams())
require.Equal(t, uint(0), *p.StreamIndex())
var streamIndex uint = 1
p.SetStreamIndex(streamIndex)
require.Equal(t, streamIndex, *p.StreamIndex())
s.SetIndex(int(streamIndex))
ss := p.Streams()
require.Equal(t, 1, len(ss))
require.Equal(t, s.ID(), ss[0].ID())
Expand Down
Loading