-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbridge.go
55 lines (46 loc) · 1.5 KB
/
bridge.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
package main
import (
"github.com/lkmio/avformat/utils"
"github.com/lkmio/lkm/flv"
"github.com/lkmio/lkm/hls"
"github.com/lkmio/lkm/rtsp"
"github.com/lkmio/lkm/stream"
)
// 处理不同包不能相互引用的需求
func NewStreamEndInfo(source stream.Source) *stream.StreamEndInfo {
tracks := source.OriginTracks()
streams := source.GetTransStreams()
if len(tracks) < 1 || len(streams) < 1 {
return nil
}
info := stream.StreamEndInfo{
ID: source.GetID(),
Timestamps: make(map[utils.AVCodecID][2]int64, len(tracks)),
}
for _, track := range tracks {
var timestamp [2]int64
timestamp[0] = track.Dts + int64(track.FrameDuration)
timestamp[1] = track.Pts + int64(track.FrameDuration)
info.Timestamps[track.Stream.CodecId()] = timestamp
}
for _, transStream := range streams {
// 获取ts切片序号
if stream.TransStreamHls == transStream.GetProtocol() {
if hls := transStream.(*hls.TransStream); hls.M3U8Writer.Size() > 0 {
info.M3U8Writer = hls.M3U8Writer
info.PlaylistFormat = hls.PlaylistFormat
}
} else if stream.TransStreamRtsp == transStream.GetProtocol() {
if rtsp := transStream.(*rtsp.TransStream); len(rtsp.Tracks) > 0 {
info.RtspTracks = make(map[byte]uint16, len(tracks))
for _, track := range rtsp.RtspTracks {
info.RtspTracks[track.PT] = track.EndSeq
}
}
} else if stream.TransStreamFlv == transStream.GetProtocol() {
stream := transStream.(*flv.TransStream)
info.FLVPrevTagSize = stream.Muxer.PrevTagSize()
}
}
return &info
}