forked from deepch/RTSPtoWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhlsFragment.go
46 lines (39 loc) · 1.02 KB
/
hlsFragment.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
package main
import (
"time"
"github.com/deepch/vdk/av"
)
//Fragment struct
type Fragment struct {
Independent bool //Fragment have i-frame (key frame)
Finish bool //Fragment Ready
Duration time.Duration //Fragment Duration
Packets []*av.Packet //Packet Slice
}
//NewFragment open new fragment
func (element *Segment) NewFragment() *Fragment {
res := &Fragment{}
element.Fragment[element.CurrentFragmentID] = res
return res
}
//GetDuration return fragment dur
func (element *Fragment) GetDuration() time.Duration {
return element.Duration
}
//WritePacket to fragment func
func (element *Fragment) WritePacket(packet *av.Packet) {
//increase fragment dur
element.Duration += packet.Duration
//Independent if have key
if packet.IsKeyFrame {
element.Independent = true
}
//append packet to slice of packet
element.Packets = append(element.Packets, packet)
}
//Close fragment block func
func (element *Fragment) Close() {
//TODO add callback func
//finalize fragment
element.Finish = true
}