支持G711A格式音频

This commit is contained in:
langhuihui
2020-09-21 07:58:58 +08:00
parent cee1064660
commit 04cae8469e
2 changed files with 26 additions and 17 deletions
+2 -1
View File
@@ -14,11 +14,12 @@ const (
const (
StreamTypeH264 = 0x1b
StreamTypeH265 = 0x24
G711Mu = 0x90
G711A = 0x90 //PCMA
G7221AUDIOTYPE = 0x92
G7231AUDIOTYPE = 0x93
G729AUDIOTYPE = 0x99
)
//
const (
StreamIDVideo = 0xe0
+24 -16
View File
@@ -42,21 +42,29 @@ type RTP_PS struct {
RTP
rtp.Packet
psPacket []byte
parser DecPSPackage
parser DecPSPackage
}
func (rtp *RTP_PS) PushPS (ps []byte) {
func (rtp *RTP_PS) PushPS(ps []byte) {
if err := rtp.Unmarshal(ps); err != nil {
Println(err)
}
if len(rtp.Payload) >= 4 && util.BigEndian.Uint32(rtp.Payload) == StartCodePS {
if rtp.psPacket != nil{
if rtp.psPacket != nil {
if err := rtp.parser.Read(rtp.psPacket); err == nil {
for _, payload := range avformat.SplitH264(rtp.parser.VideoPayload) {
rtp.WriteNALU(rtp.Timestamp, payload)
}
if rtp.parser.AudioPayload != nil{
//TODO: 需要增加一个字节的头
//rtpPublisher.PushAudio(psRtp.Timestamp, parser.AudioPayload)
if rtp.parser.AudioPayload != nil {
switch rtp.parser.AudioStreamType {
case G711A:
rtp.AudioInfo.SoundFormat = 7
rtp.AudioInfo.SoundRate = 8000
rtp.AudioInfo.SoundSize = 16
asc := rtp.AudioInfo.SoundFormat << 4
asc = asc + 1<<1
rtp.PushAudio(rtp.Timestamp, append([]byte{asc}, rtp.parser.AudioPayload...))
}
}
} else {
Print(err)
@@ -90,18 +98,18 @@ func (rtp *RTP) PushPack(pack *RTPPack) {
rtp.PushAudio(pack.Timestamp, append(addHead, payload[startOffset:endOffset]...))
startOffset = startOffset + auLen
}
case 7,8:
asc := rtp.AudioInfo.SoundFormat<<4
case 7, 8:
asc := rtp.AudioInfo.SoundFormat << 4
switch {
case rtp.AudioInfo.SoundRate>=44000:
asc = asc + (3<<2)
case rtp.AudioInfo.SoundRate>=22000:
asc = asc + (2<<2)
case rtp.AudioInfo.SoundRate>=11000:
asc = asc + (1<<2)
case rtp.AudioInfo.SoundRate >= 44000:
asc = asc + (3 << 2)
case rtp.AudioInfo.SoundRate >= 22000:
asc = asc + (2 << 2)
case rtp.AudioInfo.SoundRate >= 11000:
asc = asc + (1 << 2)
}
asc = asc+ 1<<1
rtp.PushAudio(pack.Timestamp,append([]byte{asc},payload...))
asc = asc + 1<<1
rtp.PushAudio(pack.Timestamp, append([]byte{asc}, payload...))
}
case RTP_TYPE_VIDEO:
rtp.WriteNALU(pack.Timestamp, pack.Payload)