From 28d9c3e4c717b404b795bc113719f92dce1ac0f9 Mon Sep 17 00:00:00 2001 From: q191201771 <191201771@qq.com> Date: Fri, 28 Jun 2024 10:22:41 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20rtsp:=20=E9=9F=B3=E9=A2=91=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E4=B8=BAmp2=E6=97=B6=EF=BC=8Crtsp=20pub=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84rtsp=20sub=E5=8F=AF=E4=BB=A5=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E5=A3=B0=E9=9F=B3=20#285?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/base/avpacket.go | 1 + pkg/rtsp/base_in_session.go | 2 +- pkg/sdp/parse_logic.go | 25 ++++++++++++++++--------- pkg/sdp/sdp.go | 8 ++++++++ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pkg/base/avpacket.go b/pkg/base/avpacket.go index 6fc61f25..15b1ec71 100644 --- a/pkg/base/avpacket.go +++ b/pkg/base/avpacket.go @@ -23,6 +23,7 @@ const ( AvPacketPtUnknown AvPacketPt = -1 AvPacketPtG711U AvPacketPt = 0 // g711u AvPacketPtG711A AvPacketPt = 8 // g711a + AvPacketPtMp2 AvPacketPt = 14 // mp2 AvPacketPtAvc AvPacketPt = 96 // h264 AvPacketPtHevc AvPacketPt = 98 // h265 AvPacketPtAac AvPacketPt = 97 // aac diff --git a/pkg/rtsp/base_in_session.go b/pkg/rtsp/base_in_session.go index 3c92b7c7..11a2fa97 100644 --- a/pkg/rtsp/base_in_session.go +++ b/pkg/rtsp/base_in_session.go @@ -359,7 +359,7 @@ func (session *BaseInSession) handleRtpPacket(b []byte) error { packetType := int(b[1] & 0x7F) if !session.sdpCtx.IsPayloadTypeOrigin(packetType) { - Log.Errorf("[%s] handleRtpPacket but type invalid. type=%d", session.UniqueKey(), packetType) + //Log.Errorf("[%s] handleRtpPacket but type invalid. type=%d", session.UniqueKey(), packetType) return nazaerrors.Wrap(base.ErrRtsp) } diff --git a/pkg/sdp/parse_logic.go b/pkg/sdp/parse_logic.go index b4ffa4d9..522b94f2 100644 --- a/pkg/sdp/parse_logic.go +++ b/pkg/sdp/parse_logic.go @@ -134,23 +134,30 @@ func ParseSdp2LogicContext(b []byte) (LogicContext, error) { } else if strings.EqualFold(md.ARtpMap.EncodingName, ArtpMapEncodingNameOpus) { ret.audioPayloadTypeBase = base.AvPacketPtOpus } else { - if md.M.PT == 8 { - // ffmpeg推流情况下不会填充rtpmap字段,m中pt值为8也可以表示是PCMA,采样率默认为8000Hz - // RFC3551中表明G711A固定pt值为8 + // ffmpeg推流情况下不会填充rtpmap字段,m中pt值为8也可以表示是PCMA,采样率默认为8000Hz + // RFC3551中表明G711A固定pt值为8 + if md.M.PT == MediaDescPayloadTypeG711U { + ret.audioPayloadTypeBase = base.AvPacketPtG711U + ret.audioPayloadTypeOrigin = MediaDescPayloadTypeG711U + if ret.AudioClockRate == 0 { + ret.AudioClockRate = 8000 + } + } else if md.M.PT == MediaDescPayloadTypeG711A { ret.audioPayloadTypeBase = base.AvPacketPtG711A - ret.audioPayloadTypeOrigin = 8 + ret.audioPayloadTypeOrigin = MediaDescPayloadTypeG711A if ret.AudioClockRate == 0 { ret.AudioClockRate = 8000 } - } else if md.M.PT == 0 { - // ffmpeg推流情况下不会填充rtpmap字段,m中pt值为8也可以表示是PCMU,采样率默认为8000Hz - // RFC3551中表明G711U固定pt值为0 - ret.audioPayloadTypeBase = base.AvPacketPtG711U - ret.audioPayloadTypeOrigin = 0 + } else if md.M.PT == MediaDescPayloadTypeMp2 { + ret.audioPayloadTypeBase = base.AvPacketPtMp2 + ret.audioPayloadTypeOrigin = MediaDescPayloadTypeMp2 if ret.AudioClockRate == 0 { ret.AudioClockRate = 8000 } } else { + if md.M.PT != 0 { + Log.Warnf("unknown audio payload type. pt=%d", md.M.PT) + } ret.audioPayloadTypeBase = base.AvPacketPtUnknown } } diff --git a/pkg/sdp/sdp.go b/pkg/sdp/sdp.go index 6e62be77..1b0a6882 100644 --- a/pkg/sdp/sdp.go +++ b/pkg/sdp/sdp.go @@ -8,6 +8,8 @@ package sdp +import "github.com/q191201771/lal/pkg/base" + // rfc4566 const ( @@ -18,3 +20,9 @@ const ( ARtpMapEncodingNameG711U = "PCMU" ArtpMapEncodingNameOpus = "opus" ) + +const ( + MediaDescPayloadTypeG711U = int(base.AvPacketPtG711U) + MediaDescPayloadTypeG711A = int(base.AvPacketPtG711A) + MediaDescPayloadTypeMp2 = int(base.AvPacketPtMp2) +)