Skip to content

Commit

Permalink
[feat] rtsp: 音频格式为mp2时,rtsp pub对应的rtsp sub可以播放声音 #285
Browse files Browse the repository at this point in the history
  • Loading branch information
q191201771 committed Jun 28, 2024
1 parent 323d639 commit 28d9c3e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions pkg/base/avpacket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/rtsp/base_in_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
25 changes: 16 additions & 9 deletions pkg/sdp/parse_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/sdp/sdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

package sdp

import "github.com/q191201771/lal/pkg/base"

// rfc4566

const (
Expand All @@ -18,3 +20,9 @@ const (
ARtpMapEncodingNameG711U = "PCMU"
ArtpMapEncodingNameOpus = "opus"
)

const (
MediaDescPayloadTypeG711U = int(base.AvPacketPtG711U)
MediaDescPayloadTypeG711A = int(base.AvPacketPtG711A)
MediaDescPayloadTypeMp2 = int(base.AvPacketPtMp2)
)

0 comments on commit 28d9c3e

Please sign in to comment.