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/yapingcat/gomedia/codec
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
..
aac.go HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750) 2023-08-02 22:49:49 +08:00
bitstream.go HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750) 2023-08-02 22:49:49 +08:00
codec.go HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750) 2023-08-02 22:49:49 +08:00
h264.go HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750) 2023-08-02 22:49:49 +08:00
h265.go HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750) 2023-08-02 22:49:49 +08:00
LICENSE GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2022-10-06 17:40:58 +08:00
opus.go HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750) 2023-08-02 22:49:49 +08:00
README.md GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2022-10-06 17:40:58 +08:00
util.go HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750) 2023-08-02 22:49:49 +08:00
vp8.go HLS: Ignore empty NALU to avoid error. v6.0.65 (#3750) 2023-08-02 22:49:49 +08:00

USAGE

  1. 如何解析sps/pps/vps 以解析sps为例

    
    //sps原始数据,不带start code(0x00000001)
    var rawsps []byte = []byte{0x67,....}
    
    //step1 创建BitStream
    bs := codec.NewBitStream(rawsps)
    
    //step2 解析sps
    sps := &SPS{}
    sps.Decode(bs)
    
    
  2. 获取视频宽高 以h264为例子

    //sps原始数据,以startcode开头(0x00000001)
    var rawsps []byte = []byte{0x00,0x00,0x00,0x01,0x67,.....}
    w, h := codec.GetH264Resolution(rawsps)
    
  3. 生成Extradata 以h264为例子

    
    //多个sps原始数据,以startcode开头(0x00000001)
    var spss [][]byte = [][]byte{
        []byte{0x00,0x00,0x00,0x01,0x67,...},
        []byte{0x00,0x00,0x00,0x01,0x67,...},
        ....
    }
    
     //多个pps原始数据,以startcode开头(0x00000001)
    var ppss [][]byte = [][]byte{
        []byte{0x00,0x00,0x00,0x01,0x68,...},
        []byte{0x00,0x00,0x00,0x01,0x68,...},
        ....
    }
    extranData := codec.CreateH264AVCCExtradata(spss,ppss)
    
  4. Extradata转为Annex-B格式的sps,pps 以h264为例子

    
    //一般从flv/mp4格式中获取 extraData
    //解析出来多个sps,pps, 且sps pps 都以startcode开头
    spss,ppss := codec.CovertExtradata(extraData)
    
  5. 生成H265 extrandata

    // H265的extra data 生成过程稍微复杂一些
    //创建一个 HEVCRecordConfiguration 对象
    
    hvcc := codec.NewHEVCRecordConfiguration()
    
    //对每一个 sps/pps/vps,调用相应的UpdateSPS,UpdatePPS,UpdateVPS接口
    hvcc.UpdateSPS(sps)
    hvcc.UpdatePPS(pps)
    hvcc.UpdateVPS(vps)
    
    //调用Encode接口生成
    extran := hvcc.Encode()
    
  6. 获取对应的sps id/vps id/pps id

    //以h264为例子有四个接口
    //sps 以startcode 开头
    codec.GetSPSIdWithStartCode(sps)
    
    //sps2 不以startcode 开头
    codec.GetSPSId(sps2)
    
    //pps 以startcode 开头
    codec.GetPPSIdWithStartCode(pps)
    
    //pps2 不以startcode 开头
    codec.GetPPSId(pps2)