This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
packet.go
73 lines (63 loc) · 1.52 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
package reisen
// #cgo pkg-config: libavformat libavcodec libavutil libswscale
// #include <libavcodec/avcodec.h>
// #include <libavformat/avformat.h>
// #include <libavutil/avconfig.h>
// #include <libswscale/swscale.h>
import "C"
import "unsafe"
// Packet is a piece of encoded data
// acquired from the media container.
//
// It can be either a video frame or
// an audio frame.
type Packet struct {
media *Media
streamIndex int
data []byte
pts int64
dts int64
pos int64
duration int64
size int
flags int
}
// StreamIndex returns the index of the
// stream the packet belongs to.
func (pkt *Packet) StreamIndex() int {
return pkt.streamIndex
}
// Type returns the type of the packet
// (video or audio).
func (pkt *Packet) Type() StreamType {
return pkt.media.Streams()[pkt.streamIndex].Type()
}
// Data returns the data
// encoded in the packet.
func (pkt *Packet) Data() []byte {
buf := make([]byte, pkt.size)
copy(buf, pkt.data)
return buf
}
// Returns the size of the
// packet data.
func (pkt *Packet) Size() int {
return pkt.size
}
// newPacket creates a
// new packet info object.
func newPacket(media *Media, cPkt *C.AVPacket) *Packet {
pkt := &Packet{
media: media,
streamIndex: int(cPkt.stream_index),
data: C.GoBytes(unsafe.Pointer(
cPkt.data), cPkt.size),
pts: int64(cPkt.pts),
dts: int64(cPkt.dts),
pos: int64(cPkt.pos),
duration: int64(cPkt.duration),
size: int(cPkt.size),
flags: int(cPkt.flags),
}
return pkt
}