rtsp支持h265拉流

This commit is contained in:
yangjiechina
2024-04-17 17:21:14 +08:00
parent 1fd0a2f063
commit 0be53fbf4b
3 changed files with 13 additions and 9 deletions

View File

@@ -75,13 +75,7 @@ func (p *publisher) OnDiscardPacket(pkt interface{}) {
}
func (p *publisher) OnDeMuxStream(stream_ utils.AVStream) {
//AVStream的Data单独拷贝出来
//释放掉内存池中最新分配的内存
tmp := stream_.Extra()
bytes := make([]byte, len(tmp))
copy(bytes, tmp)
stream_.SetExtraData(bytes)
if utils.AVMediaTypeAudio == stream_.Type() {
p.audioMemoryPool.FreeTail()
} else if utils.AVMediaTypeVideo == stream_.Type() {
@@ -100,10 +94,11 @@ func (p *publisher) OnDeMuxPacket(packet utils.AVPacket) {
return
}
//未开启GOP缓存释放掉内存
if utils.AVMediaTypeAudio == packet.MediaType() {
p.audioMemoryPool.FreeHead()
p.audioMemoryPool.FreeTail()
} else if utils.AVMediaTypeVideo == packet.MediaType() {
p.videoMemoryPool.FreeHead()
p.videoMemoryPool.FreeTail()
}
}

View File

@@ -271,6 +271,7 @@ func (s *session) Input(method string, url_ *url.URL, headers textproto.MIMEHead
var err error
split := strings.Split(url_.Path, "/")
source := split[len(split)-1]
if MethodOptions == method {
err = s.onOptions(source, headers)
} else if MethodDescribe == method {

View File

@@ -49,10 +49,13 @@ func (t *tranStream) onAllocBuffer(params interface{}) []byte {
return t.rtpTracks[params.(int)].buffer[OverTcpHeaderSize:]
}
// onRtpPacket 所有封装后的RTP流都将回调于此
func (t *tranStream) onRtpPacket(data []byte, timestamp uint32, params interface{}) {
//params传递track索引
index := params.(int)
track := t.rtpTracks[index]
//保存sps和ssp等数据
if track.cache && track.header == nil {
bytes := make([]byte, OverTcpHeaderSize+len(data))
copy(bytes[OverTcpHeaderSize:], data)
@@ -155,11 +158,16 @@ func (t *tranStream) AddTrack(stream utils.AVStream) error {
//创建RTP封装
var muxer librtp.Muxer
if utils.AVCodecIdH264 == stream.CodecId() || utils.AVCodecIdH265 == stream.CodecId() {
if utils.AVCodecIdH264 == stream.CodecId() {
muxer = librtp.NewH264Muxer(payloadType.Pt, 0, 0xFFFFFFFF)
} else if utils.AVCodecIdH265 == stream.CodecId() {
muxer = librtp.NewH265Muxer(payloadType.Pt, 0, 0xFFFFFFFF)
} else if utils.AVCodecIdAAC == stream.CodecId() {
muxer = librtp.NewAACMuxer(payloadType.Pt, 0, 0xFFFFFFFF)
} else if utils.AVCodecIdPCMALAW == stream.CodecId() || utils.AVCodecIdPCMMULAW == stream.CodecId() {
muxer = librtp.NewMuxer(payloadType.Pt, 0, 0xFFFFFFFF)
}
muxer.SetAllocHandler(t.onAllocBuffer)
muxer.SetWriteHandler(t.onRtpPacket)