Add support pcm_s16le audio
This commit is contained in:
@@ -3,6 +3,7 @@ package webrtc
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/AlexxIT/go2rtc/pkg/h264"
|
||||
"github.com/AlexxIT/go2rtc/pkg/h265"
|
||||
@@ -63,13 +64,13 @@ func (c *Conn) AddTrack(media *core.Media, codec *core.Codec, track *core.Receiv
|
||||
sender.Handler = h265.RTPDepay(track.Codec, sender.Handler)
|
||||
}
|
||||
|
||||
case core.CodecPCMA, core.CodecPCMU, core.CodecPCM:
|
||||
case core.CodecPCMA, core.CodecPCMU, core.CodecPCM, core.CodecPCML:
|
||||
if codec.ClockRate == 0 {
|
||||
if codec.Name == core.CodecPCM {
|
||||
if codec.Name == core.CodecPCM || codec.Name == core.CodecPCML {
|
||||
codec.Name = core.CodecPCMA
|
||||
}
|
||||
codec.ClockRate = 8000
|
||||
sender.Handler = pcm.Resample(track.Codec, 8000, sender.Handler)
|
||||
sender.Handler = pcm.ResampleToPCMA(track.Codec, 8000, sender.Handler)
|
||||
}
|
||||
|
||||
// Fix audio quality https://github.com/AlexxIT/WebRTC/issues/500
|
||||
|
||||
+16
-6
@@ -3,16 +3,17 @@ package webrtc
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/pion/ice/v2"
|
||||
"github.com/pion/sdp/v3"
|
||||
"github.com/pion/stun"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"hash/crc32"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/pion/ice/v2"
|
||||
"github.com/pion/sdp/v3"
|
||||
"github.com/pion/stun"
|
||||
"github.com/pion/webrtc/v3"
|
||||
)
|
||||
|
||||
func UnmarshalMedias(descriptions []*sdp.MediaDescription) (medias []*core.Media) {
|
||||
@@ -52,13 +53,15 @@ func UnmarshalMedias(descriptions []*sdp.MediaDescription) (medias []*core.Media
|
||||
return
|
||||
}
|
||||
|
||||
// WithResampling - will add for consumer: PCMA/0, PCMU/0, PCM/0, PCML/0
|
||||
// so it can add resampling for PCMA/PCMU and repack for PCM/PCML
|
||||
func WithResampling(medias []*core.Media) []*core.Media {
|
||||
for _, media := range medias {
|
||||
if media.Kind != core.KindAudio || media.Direction != core.DirectionSendonly {
|
||||
continue
|
||||
}
|
||||
|
||||
var pcma, pcmu, pcm *core.Codec
|
||||
var pcma, pcmu, pcm, pcml *core.Codec
|
||||
|
||||
for _, codec := range media.Codecs {
|
||||
switch codec.Name {
|
||||
@@ -76,6 +79,8 @@ func WithResampling(medias []*core.Media) []*core.Media {
|
||||
}
|
||||
case core.CodecPCM:
|
||||
pcm = codec
|
||||
case core.CodecPCML:
|
||||
pcml = codec
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +99,11 @@ func WithResampling(medias []*core.Media) []*core.Media {
|
||||
pcm.Name = core.CodecPCM
|
||||
media.Codecs = append(media.Codecs, pcm)
|
||||
}
|
||||
if pcma != nil && pcml == nil {
|
||||
pcml = pcma.Clone()
|
||||
pcml.Name = core.CodecPCML
|
||||
media.Codecs = append(media.Codecs, pcml)
|
||||
}
|
||||
}
|
||||
|
||||
return medias
|
||||
|
||||
Reference in New Issue
Block a user