MCPcopy Create free account
hub / github.com/Monibuca/engine / Flush

Method Flush

track/media.go:229–316  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

227}
228
229func (av *Media) Flush() {
230 curValue, preValue, nextValue := av.Value, av.LastValue, av.Next()
231 useDts := curValue.Timestamp == 0
232 originDTS := curValue.DTS
233 if av.State == TrackStateOffline {
234 av.State = TrackStateOnline
235 if useDts {
236 av.deltaTs = curValue.DTS - preValue.DTS
237 } else {
238 av.deltaTs = curValue.Timestamp - preValue.Timestamp
239 }
240 curValue.DTS = preValue.DTS + 900
241 curValue.PTS = preValue.PTS + 900
242 curValue.Timestamp = preValue.Timestamp + time.Millisecond
243 av.Info("track back online", zap.Duration("delta", av.deltaTs))
244 } else if av.deltaTs != 0 {
245 if useDts {
246 curValue.DTS -= av.deltaTs
247 curValue.PTS -= av.deltaTs
248 } else {
249 rtpts := av.deltaTs * 90 / time.Millisecond
250 curValue.DTS -= rtpts
251 curValue.PTS -= rtpts
252 curValue.Timestamp -= av.deltaTs
253 }
254 }
255 if av.起始时间.IsZero() {
256 curValue.DeltaTime = 0
257 if useDts {
258 curValue.Timestamp = time.Since(av.Publisher.GetStream().GetStartTime())
259 }
260 av.重置(curValue.Timestamp, curValue.DTS)
261 } else {
262 if useDts {
263 deltaDts := curValue.DTS - preValue.DTS
264 if deltaDts > deltaDTSRange || deltaDts < -deltaDTSRange {
265 // 时间戳跳变,等同于离线重连
266 av.deltaTs = originDTS - preValue.DTS
267 curValue.DTS = preValue.DTS + 900
268 curValue.PTS = preValue.PTS + 900
269 av.Warn("track dts reset", zap.Int64("delta1", int64(deltaDts)), zap.Int64("delta2", int64(av.deltaTs)))
270 }
271 curValue.Timestamp = av.根据起始DTS计算绝对时间戳(curValue.DTS)
272 }
273
274 curValue.DeltaTime = uint32(deltaTS(curValue.Timestamp, preValue.Timestamp) / time.Millisecond)
275 }
276 if log.Trace {
277 av.Trace("write", zap.Uint32("seq", curValue.Sequence), zap.Int64("dts0", int64(preValue.DTS)), zap.Int64("dts1", int64(originDTS)), zap.Uint64("dts2", uint64(curValue.DTS)), zap.Uint32("delta", curValue.DeltaTime), zap.Duration("timestamp", curValue.Timestamp), zap.Int("au", curValue.AUList.Length), zap.Int("rtp", curValue.RTP.Length), zap.Int("avcc", curValue.AVCC.ByteLength), zap.Int("raw", curValue.AUList.ByteLength), zap.Int("bps", av.BPS))
278 }
279 bufferTime := av.BufferTime
280 if bufferTime > 0 && av.IDRingList.IDRList.Length > 1 && deltaTS(curValue.Timestamp, av.IDRingList.IDRList.Next.Next.Value.Value.Timestamp) > bufferTime {
281 av.ShiftIDR()
282 if canReduce := int(curValue.Sequence-av.HistoryRing.Value.Sequence) - 5; canReduce > 0 {
283 av.narrow(canReduce)
284 }
285 }
286 // 下一帧为订阅起始帧,即将覆盖,需要扩环

Callers

nothing calls this directly

Calls 15

narrowMethod · 0.95
deltaTSFunction · 0.85
重置Method · 0.80
ShiftIDRMethod · 0.80
GlowMethod · 0.80
ComputeBPSMethod · 0.80
StepMethod · 0.80
控制流速Method · 0.80
InfoMethod · 0.65
GetStartTimeMethod · 0.65
GetStreamMethod · 0.65

Tested by

no test coverage detected