解析 RTP 包时,将 RTP 的扩展部分解析出来
This commit is contained in:
parent
dc22c36964
commit
bcb44378a5
4
av/av.go
4
av/av.go
@ -191,7 +191,7 @@ const avCodecTypeMagic = 233333
|
||||
// CodecData is some important bytes for initializing audio/video decoder,
|
||||
// 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.
|
||||
type CodecData interface {
|
||||
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user