forked from 3d0c/gmf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
packet_go16.go
118 lines (85 loc) · 2.2 KB
/
packet_go16.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
// +build go1.6,!go1.12
package gmf
/*
#cgo pkg-config: libavcodec
#include "libavcodec/avcodec.h"
void shift_data(AVPacket *pkt, int offset) {
pkt->data += offset;
pkt->size -= offset;
return;
}
*/
import "C"
import (
"fmt"
"unsafe"
)
type Packet struct {
avPacket C.struct_AVPacket
}
func NewPacket() *Packet {
p := &Packet{}
C.av_new_packet(&p.avPacket, 0)
return p
}
// Init same to NewPacket and av_new_packet
// Initialize optional fields of a packet with default values.
// Note, this does not touch the data and size members, which have to be
// initialized separately.
func Init() *Packet {
p := &Packet{}
C.av_new_packet(&p.avPacket, 0)
return p
}
func (p *Packet) Pts() int64 {
return int64(p.avPacket.pts)
}
func (p *Packet) SetPts(pts int64) {
p.avPacket.pts = C.int64_t(pts)
}
func (p *Packet) Dts() int64 {
return int64(p.avPacket.dts)
}
func (p *Packet) SetDts(val int64) {
p.avPacket.dts = _Ctype_int64_t(val)
}
func (p *Packet) Flags() int {
return int(p.avPacket.flags)
}
func (p *Packet) Duration() int64 {
return int64(p.avPacket.duration)
}
func (p *Packet) SetDuration(duration int64) {
p.avPacket.duration = C.int64_t(duration)
}
func (p *Packet) StreamIndex() int {
return int(p.avPacket.stream_index)
}
func (p *Packet) Size() int {
return int(p.avPacket.size)
}
func (p *Packet) Pos() int64 {
return int64(p.avPacket.pos)
}
func (p *Packet) Data() []byte {
return C.GoBytes(unsafe.Pointer(p.avPacket.data), C.int(p.avPacket.size))
}
func (p *Packet) Clone() *Packet {
np := NewPacket()
C.av_packet_ref(&np.avPacket, &p.avPacket)
return np
}
func (p *Packet) Dump() {
fmt.Printf("idx: %d\npts: %d\ndts: %d\nsize: %d\nduration:%d\npos:%d\ndata: % x\n", p.StreamIndex(), p.avPacket.pts, p.avPacket.dts, p.avPacket.size, p.avPacket.duration, p.avPacket.pos, C.GoBytes(unsafe.Pointer(p.avPacket.data), 128))
fmt.Println("------------------------------")
}
func (p *Packet) SetStreamIndex(val int) *Packet {
p.avPacket.stream_index = C.int(val)
return p
}
func (p *Packet) Free() {
C.av_packet_unref(&p.avPacket)
}
func (p *Packet) Time(timebase AVRational) int {
return int(float64(timebase.AVR().Num) / float64(timebase.AVR().Den) * float64(p.Pts()))
}