diff --git a/README.md b/README.md index e76b512..fb8d881 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,8 @@ 通过浏览器和monibuca交换sdp信息,然后读取rtp包或者发送rtp的方式进行 -# 界面操作 - -## publish -在后台管理界面,会自动获取摄像头,在streamPath中填入需要发布流的名称,点击publish开始发布 - -## play -在后台管理界面,点击上方play tab页此时会显示当前monibuca中所有正在发布的流,点击其中需要播放的流,会出现按钮,点击Play按钮即可弹出播放器界面并进行播放。 +# API +- /api/webrtc/play?streamPath=live/rtc +用于播放live/rtc的流,需要在请求的body中放入sdp的json数据,这个接口会返回服务端的sdp数据 +- /api/webrtc/publish?streamPath=live/rtc +同上 \ No newline at end of file diff --git a/main.go b/main.go index 9729dce..2d433ea 100644 --- a/main.go +++ b/main.go @@ -156,12 +156,25 @@ func (rtc *WebRTC) Publish(streamPath string) bool { } }() var etrack engine.Track + codec := track.Codec() if track.Kind() == RTPCodecTypeAudio { - //TODO: 判断音频格式 - at := engine.NewAudioTrack() - at.SoundFormat = 7 - rtc.SetOriginAT(at) - etrack = at + switch codec.MimeType { + case MimeTypePCMA: + at := engine.NewAudioTrack() + at.SoundFormat = 7 + at.SoundType = byte(codec.Channels) - 1 + rtc.SetOriginAT(at) + etrack = at + case MimeTypePCMU: + at := engine.NewAudioTrack() + at.SoundFormat = 8 + at.SoundType = byte(codec.Channels) - 1 + rtc.SetOriginAT(at) + etrack = at + default: + return + } + } else { vt := engine.NewVideoTrack() vt.CodecID = 7 @@ -214,7 +227,7 @@ func run() { } m.RegisterDefaultCodecs() api = NewAPI(WithMediaEngine(&m), WithSettingEngine(s)) - http.HandleFunc("/webrtc/play", func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc("/api/webrtc/play", func(w http.ResponseWriter, r *http.Request) { utils.CORS(w, r) w.Header().Set("Content-Type", "application/json") streamPath := r.URL.Query().Get("streamPath") @@ -337,7 +350,7 @@ func run() { } }) - http.HandleFunc("/webrtc/publish", func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc("/api/webrtc/publish", func(w http.ResponseWriter, r *http.Request) { streamPath := r.URL.Query().Get("streamPath") offer := SessionDescription{} bytes, err := ioutil.ReadAll(r.Body)