-
Notifications
You must be signed in to change notification settings - Fork 62
/
av.go
82 lines (66 loc) · 1.25 KB
/
av.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
package av
import (
"fmt"
"time"
"github.com/nareix/joy5/codec/aac"
"github.com/nareix/joy5/codec/h264"
)
const (
H264 = 1 + iota
AAC
H264DecoderConfig
H264SPSPPSNALU
AACDecoderConfig
Metadata
)
var PacketTypeString = map[int]string{
H264: "H264",
AAC: "AAC",
H264DecoderConfig: "H264DecoderConfig",
H264SPSPPSNALU: "H264SPSPPSNALU",
AACDecoderConfig: "AACDecoderConfig",
Metadata: "Metadata",
}
type Packet struct {
Type int
IsKeyFrame bool
CTime time.Duration
Time time.Duration
Data []byte
ASeqHdr []byte
VSeqHdr []byte
Metadata []byte
AAC *aac.Codec
H264 *h264.Codec
}
func (p Packet) String() string {
ret := ""
typeStr := PacketTypeString[p.Type]
if typeStr == "" {
typeStr = "UnknownPacketType"
}
ret += typeStr
if p.IsKeyFrame {
ret += " K"
}
ret += " " + fmt.Sprint(p.Time)
if p.CTime != 0 {
ret += " " + fmt.Sprint(p.CTime)
}
ret += " " + fmt.Sprint(len(p.Data))
return ret
}
type PacketReader interface {
ReadPacket() (Packet, error)
}
type PacketReadCloser interface {
PacketReader
Close() error
}
type PacketWriter interface {
WritePacket(Packet) error
}
type PacketWriteCloser interface {
PacketWriter
Close() error
}