解析 RTP 包时,将 RTP 的扩展部分解析出来
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (go) (push) Waiting to run

This commit is contained in:
kunmeng 2025-01-24 11:46:13 +08:00
parent dc22c36964
commit bcb44378a5
2 changed files with 19 additions and 3 deletions

View File

@ -191,7 +191,7 @@ const avCodecTypeMagic = 233333
// CodecData is some important bytes for initializing audio/video decoder, // CodecData is some important bytes for initializing audio/video decoder,
// can be converted to VideoCodecData or AudioCodecData using: // can be converted to VideoCodecData or AudioCodecData using:
// //
// codecdata.(AudioCodecData) or codecdata.(VideoCodecData) // codecdata.(AudioCodecData) or codecdata.(VideoCodecData)
// //
// for H264, CodecData is AVCDecoderConfigure bytes, includes SPS/PPS. // for H264, CodecData is AVCDecoderConfigure bytes, includes SPS/PPS.
type CodecData interface { type CodecData interface {
@ -255,6 +255,8 @@ type Packet struct {
Time time.Duration // packet decode time Time time.Duration // packet decode time
Duration time.Duration //packet duration Duration time.Duration //packet duration
Data []byte // packet data Data []byte // packet data
Extension bool
Extensions []byte
} }
// Raw audio frame. // Raw audio frame.

View File

@ -35,6 +35,8 @@ func (client *RTSPClient) RTPDemuxer(payloadRAW *[]byte) ([]*av.Packet, bool) {
if client.end-client.offset >= 4*CSRCCnt { if client.end-client.offset >= 4*CSRCCnt {
client.offset += 4 * CSRCCnt client.offset += 4 * CSRCCnt
} }
extensionStart := 0
extensionEnd := 0
if extension && len(content) < 4+client.offset+2+2 { if extension && len(content) < 4+client.offset+2+2 {
return nil, false return nil, false
} }
@ -42,6 +44,8 @@ func (client *RTSPClient) RTPDemuxer(payloadRAW *[]byte) ([]*av.Packet, bool) {
extLen := 4 * int(binary.BigEndian.Uint16(content[4+client.offset+2:])) extLen := 4 * int(binary.BigEndian.Uint16(content[4+client.offset+2:]))
client.offset += 4 client.offset += 4
if client.end-client.offset >= extLen { if client.end-client.offset >= extLen {
extensionStart = client.offset
extensionEnd = client.offset + extLen
client.offset += extLen client.offset += extLen
} }
} }
@ -58,9 +62,19 @@ func (client *RTSPClient) RTPDemuxer(payloadRAW *[]byte) ([]*av.Packet, bool) {
switch int(content[1]) { switch int(content[1]) {
case client.videoID: case client.videoID:
return client.handleVideo(content) pck, ok := client.handleVideo(content)
for _, p := range pck {
p.Extension = extension
p.Extensions = content[extensionStart+4 : extensionEnd+4]
}
return pck, ok
case client.audioID: case client.audioID:
return client.handleAudio(content) pck, ok := client.handleAudio(content)
for _, p := range pck {
p.Extension = extension
p.Extensions = content[extensionStart+4 : extensionEnd+4]
}
return pck, ok
} }
return nil, false return nil, false
} }