diff --git a/av/av.go b/av/av.go index 8f30975..7e2a808 100644 --- a/av/av.go +++ b/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. diff --git a/format/rtspv2/demuxer.go b/format/rtspv2/demuxer.go index 396ca41..f0c04d4 100644 --- a/format/rtspv2/demuxer.go +++ b/format/rtspv2/demuxer.go @@ -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 }