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/gobwas/pool
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
..
internal/pmath GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2022-10-06 17:40:58 +08:00
pbufio HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750) 2023-08-02 22:49:49 +08:00
pbytes HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750) 2023-08-02 22:49:49 +08:00
generic.go GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2022-10-06 17:40:58 +08:00
LICENSE GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2022-10-06 17:40:58 +08:00
option.go GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2022-10-06 17:40:58 +08:00
pool.go GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2022-10-06 17:40:58 +08:00
README.md GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2022-10-06 17:40:58 +08:00

pool

GoDoc

Tiny memory reuse helpers for Go.

generic

Without use of subpackages, pool allows to reuse any struct distinguishable by size in generic way:

package main

import "github.com/gobwas/pool"

func main() {
	x, n := pool.Get(100) // Returns object with size 128 or nil.
	if x == nil {
		// Create x somehow with knowledge that n is 128.
	}
	defer pool.Put(x, n)
	
	// Work with x.
}

Pool allows you to pass specific options for constructing custom pool:

package main

import "github.com/gobwas/pool"

func main() {
	p := pool.Custom(
        pool.WithLogSizeMapping(),      // Will ceil size n passed to Get(n) to nearest power of two.
        pool.WithLogSizeRange(64, 512), // Will reuse objects in logarithmic range [64, 512].
        pool.WithSize(65536),           // Will reuse object with size 65536.
    )
	x, n := p.Get(1000)  // Returns nil and 1000 because mapped size 1000 => 1024 is not reusing by the pool.
    defer pool.Put(x, n) // Will not reuse x.
	
	// Work with x.
}

Note that there are few non-generic pooling implementations inside subpackages.

pbytes

Subpackage pbytes is intended for []byte reuse.

package main

import "github.com/gobwas/pool/pbytes"

func main() {
	bts := pbytes.GetCap(100) // Returns make([]byte, 0, 128).
	defer pbytes.Put(bts)

	// Work with bts.
}

You can also create your own range for pooling:

package main

import "github.com/gobwas/pool/pbytes"

func main() {
	// Reuse only slices whose capacity is 128, 256, 512 or 1024.
	pool := pbytes.New(128, 1024) 

	bts := pool.GetCap(100) // Returns make([]byte, 0, 128).
	defer pool.Put(bts)

	// Work with bts.
}

pbufio

Subpackage pbufio is intended for *bufio.{Reader, Writer} reuse.

package main

import "github.com/gobwas/pool/pbufio"

func main() {
	bw := pbufio.GetWriter(os.Stdout, 100) // Returns bufio.NewWriterSize(128).
	defer pbufio.PutWriter(bw)

	// Work with bw.
}

Like with pbytes, you can also create pool with custom reuse bounds.