解析 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

@ -255,6 +255,8 @@ type Packet struct {
Time time.Duration // packet decode time
Duration time.Duration //packet duration
Data []byte // packet data
Extension bool
Extensions []byte
}
// 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 {
client.offset += 4 * CSRCCnt
}
extensionStart := 0
extensionEnd := 0
if extension && len(content) < 4+client.offset+2+2 {
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:]))
client.offset += 4
if client.end-client.offset >= extLen {
extensionStart = client.offset
extensionEnd = client.offset + extLen
client.offset += extLen
}
}
@ -58,9 +62,19 @@ func (client *RTSPClient) RTPDemuxer(payloadRAW *[]byte) ([]*av.Packet, bool) {
switch int(content[1]) {
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:
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
}