forked from asticode/go-astiav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet.go
121 lines (94 loc) · 2.14 KB
/
packet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package astiav
//#cgo pkg-config: libavcodec
//#include <libavcodec/avcodec.h>
import "C"
// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/packet.h#L350
type Packet struct {
c *C.struct_AVPacket
}
func newPacketFromC(c *C.struct_AVPacket) *Packet {
if c == nil {
return nil
}
return &Packet{c: c}
}
func AllocPacket() *Packet {
return newPacketFromC(C.av_packet_alloc())
}
func (p *Packet) Data() []byte {
if p.c.data == nil {
return nil
}
return bytesFromC(func(size *C.int) *C.uint8_t {
*size = p.c.size
return p.c.data
})
}
func (p *Packet) Dts() int64 {
return int64(p.c.dts)
}
func (p *Packet) SetDts(v int64) {
p.c.dts = C.int64_t(v)
}
func (p *Packet) Duration() int64 {
return int64(p.c.duration)
}
func (p *Packet) SetDuration(d int64) {
p.c.duration = C.int64_t(d)
}
func (p *Packet) Flags() PacketFlags {
return PacketFlags(p.c.flags)
}
func (p *Packet) SetFlags(f PacketFlags) {
p.c.flags = C.int(f)
}
func (p *Packet) Pos() int64 {
return int64(p.c.pos)
}
func (p *Packet) SetPos(v int64) {
p.c.pos = C.int64_t(v)
}
func (p *Packet) Pts() int64 {
return int64(p.c.pts)
}
func (p *Packet) SetPts(v int64) {
p.c.pts = C.int64_t(v)
}
func (p *Packet) SideData(t PacketSideDataType) []byte {
return bytesFromC(func(size *C.int) *C.uint8_t {
return C.av_packet_get_side_data(p.c, (C.enum_AVPacketSideDataType)(t), size)
})
}
func (p *Packet) Size() int {
return int(p.c.size)
}
func (p *Packet) SetSize(s int) {
p.c.size = C.int(s)
}
func (p *Packet) StreamIndex() int {
return int(p.c.stream_index)
}
func (p *Packet) SetStreamIndex(i int) {
p.c.stream_index = C.int(i)
}
func (p *Packet) Free() {
C.av_packet_free(&p.c)
}
func (p *Packet) Clone() *Packet {
return newPacketFromC(C.av_packet_clone(p.c))
}
func (p *Packet) AllocPayload(s int) error {
return newError(C.av_new_packet(p.c, C.int(s)))
}
func (p *Packet) Ref(src *Packet) error {
return newError(C.av_packet_ref(p.c, src.c))
}
func (p *Packet) Unref() {
C.av_packet_unref(p.c)
}
func (p *Packet) MoveRef(src *Packet) {
C.av_packet_move_ref(p.c, src.c)
}
func (p *Packet) RescaleTs(src, dst Rational) {
C.av_packet_rescale_ts(p.c, src.c, dst.c)
}