1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00
srs/trunk/3rdparty/srs-bench/vendor/github.com/google/gopacket/time.go
Winlin 73dd8af4c9
HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750)
For the DJI M30, there is a bug where empty NALU packets with a size of
zero are causing issues with HLS streaming. This bug leads to random
unpublish events due to the SRS disconnecting the connection for the HLS
module when it fails to handle empty NALU packets.

To address this bug, we have patched the system to ignore any empty NALU
packets with a size of zero. Additionally, we have created a tool in the
srs-bench to replay pcapng files captured by tcpdump or Wireshark. We
have also added utest using mprotect and asan to detect any memory
corruption.

It is important to note that this bug has been fixed in versions 4.0.271
6477f31004 and 5.0.170
939f6b484b. This patch specifically
addresses the issue in SRS 6.0.

Please be aware that there is another commit related to this bug that
partially fixes the issue but still leaves a small problem for asan to
detect memory corruption. This commit,
577cd299e1, only ignores empty NALU
packets but still reads beyond the memory.

---------

Co-authored-by: chundonglinlin <chundonglinlin@163.com>
2023-08-02 22:49:49 +08:00

72 lines
2.4 KiB
Go

// Copyright 2018 The GoPacket Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
package gopacket
import (
"fmt"
"math"
"time"
)
// TimestampResolution represents the resolution of timestamps in Base^Exponent.
type TimestampResolution struct {
Base, Exponent int
}
func (t TimestampResolution) String() string {
return fmt.Sprintf("%d^%d", t.Base, t.Exponent)
}
// ToDuration returns the smallest representable time difference as a time.Duration
func (t TimestampResolution) ToDuration() time.Duration {
if t.Base == 0 {
return 0
}
if t.Exponent == 0 {
return time.Second
}
switch t.Base {
case 10:
return time.Duration(math.Pow10(t.Exponent + 9))
case 2:
if t.Exponent < 0 {
return time.Second >> uint(-t.Exponent)
}
return time.Second << uint(t.Exponent)
default:
// this might loose precision
return time.Duration(float64(time.Second) * math.Pow(float64(t.Base), float64(t.Exponent)))
}
}
// TimestampResolutionInvalid represents an invalid timestamp resolution
var TimestampResolutionInvalid = TimestampResolution{}
// TimestampResolutionMillisecond is a resolution of 10^-3s
var TimestampResolutionMillisecond = TimestampResolution{10, -3}
// TimestampResolutionMicrosecond is a resolution of 10^-6s
var TimestampResolutionMicrosecond = TimestampResolution{10, -6}
// TimestampResolutionNanosecond is a resolution of 10^-9s
var TimestampResolutionNanosecond = TimestampResolution{10, -9}
// TimestampResolutionNTP is the resolution of NTP timestamps which is 2^-32 ≈ 233 picoseconds
var TimestampResolutionNTP = TimestampResolution{2, -32}
// TimestampResolutionCaptureInfo is the resolution used in CaptureInfo, which his currently nanosecond
var TimestampResolutionCaptureInfo = TimestampResolutionNanosecond
// PacketSourceResolution is an interface for packet data sources that
// support reporting the timestamp resolution of the aqcuired timestamps.
// Returned timestamps will always have NanosecondTimestampResolution due
// to the use of time.Time, but scaling might have occured if acquired
// timestamps have a different resolution.
type PacketSourceResolution interface {
// Resolution returns the timestamp resolution of acquired timestamps before scaling to NanosecondTimestampResolution.
Resolution() TimestampResolution
}