-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathbridge.go
More file actions
58 lines (49 loc) · 1.72 KB
/
Copy pathbridge.go
File metadata and controls
58 lines (49 loc) · 1.72 KB
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
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 string, originTracks []*stream.Track, streams map[stream.TransStreamID]stream.TransStream) *stream.StreamEndInfo {
if len(streams) < 1 {
return nil
}
info := stream.StreamEndInfo{
ID: source,
Timestamps: make(map[stream.TransStreamID]map[utils.AVCodecID][2]int64, len(streams)),
OriginTracks: make(map[utils.AVCodecID]interface{}, len(originTracks)),
}
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[utils.AVCodecID]uint16, 8)
for _, track := range rtsp.RtspTracks {
info.RtspTracks[track.CodecID] = track.EndSeq
}
}
} else if stream.TransStreamFlv == transStream.GetProtocol() {
flv := transStream.(*flv.TransStream)
info.FLVPrevTagSize = flv.Muxer.PrevTagSize()
}
// 保存传输流最后的时间戳
tracks := transStream.GetTracks()
ts := make(map[utils.AVCodecID][2]int64, len(tracks))
for _, track := range tracks {
ts[track.Stream.CodecID] = [2]int64{track.Dts, track.Pts}
}
info.Timestamps[transStream.GetID()] = ts
}
for _, track := range originTracks {
info.OriginTracks[track.Stream.CodecID] = nil
}
return &info
}