Browse Source

修复webrtc推流码率过低问题

v4
zhongyuan 3 years ago
parent
commit
5758c9f01e
  1. 17
      main.go

17
main.go

@ -3,6 +3,7 @@ package webrtc
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/pion/interceptor"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"regexp" "regexp"
@ -196,15 +197,25 @@ func (rtc *WebRTC) GetAnswer() ([]byte, error) {
func run() { func run() {
var m MediaEngine var m MediaEngine
var s SettingEngine var s SettingEngine
//m.RegisterDefaultCodecs()
webrtc.RegisterCodecs(&m)
i := &interceptor.Registry{}
if len(config.PublicIP) > 0 { if len(config.PublicIP) > 0 {
s.SetNAT1To1IPs(config.PublicIP, ICECandidateTypeHost) s.SetNAT1To1IPs(config.PublicIP, ICECandidateTypeHost)
} }
if config.PortMin > 0 && config.PortMax > 0 { if config.PortMin > 0 && config.PortMax > 0 {
s.SetEphemeralUDPPortRange(config.PortMin, config.PortMax) s.SetEphemeralUDPPortRange(config.PortMin, config.PortMax)
} }
// m.RegisterDefaultCodecs() if len(config.PublicIP) > 0 {
webrtc.RegisterCodecs(&m) s.SetNAT1To1IPs(config.PublicIP, ICECandidateTypeHost)
api = NewAPI(WithMediaEngine(&m), WithSettingEngine(s)) }
s.SetNetworkTypes([]NetworkType{NetworkTypeUDP4, NetworkTypeUDP6})
if err := RegisterDefaultInterceptors(&m, i); err != nil {
panic(err)
}
api := NewAPI(WithMediaEngine(&m),
WithInterceptorRegistry(i), WithSettingEngine(s))
http.HandleFunc("/api/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) utils.CORS(w, r)
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")

Loading…
Cancel
Save