From 6993496f6d3c3d6cb1d16b9726e49429409c6182 Mon Sep 17 00:00:00 2001 From: dexter <178529795@qq.com> Date: Tue, 17 Aug 2021 09:31:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E6=B5=81=E6=94=AF=E6=8C=81=E9=9F=B3?= =?UTF-8?q?=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index b87d9ef..3957e4b 100644 --- a/main.go +++ b/main.go @@ -94,7 +94,13 @@ type WebRTC struct { func (rtc *WebRTC) Publish(streamPath string) bool { if _, err := rtc.AddTransceiverFromKind(RTPCodecTypeVideo); err != nil { if err != nil { - utils.Println(err) + utils.Println("AddTransceiverFromKind video", err) + return false + } + } + if _, err := rtc.AddTransceiverFromKind(RTPCodecTypeAudio); err != nil { + if err != nil { + utils.Println("AddTransceiverFromKind audio", err) return false } } @@ -112,16 +118,21 @@ func (rtc *WebRTC) Publish(streamPath string) bool { }) //f, _ := os.OpenFile("resource/live/rtc.h264", os.O_TRUNC|os.O_WRONLY, 0666) rtc.OnTrack(func(track *TrackRemote, receiver *RTPReceiver) { - if codec := track.Codec(); track.Kind() == RTPCodecTypeAudio { var at *engine.RTPAudio - switch codec.MimeType { - case MimeTypePCMA: + switch codec.PayloadType { + case 8: at = stream.NewRTPAudio(7) - at.Channels = byte(codec.Channels) - case MimeTypePCMU: + at.SoundRate = 8000 + at.SoundSize = 16 + at.Channels = 1 + at.ExtraData = []byte{(at.CodecID << 4) | (1 << 1)} + case 0: at = stream.NewRTPAudio(8) - at.Channels = byte(codec.Channels) + at.SoundRate = 8000 + at.SoundSize = 16 + at.Channels = 1 + at.ExtraData = []byte{(at.CodecID << 4) | (1 << 1)} default: return }