Populate MediaEngine from Offer in broadcast

Use offerer PayloadType when generating answer. Before we would use the
hardcoded values, this is invalid behavior and would cause browsers to
just ignore our video when publishing.
This commit is contained in:
Ben Weitzman
2020-03-25 16:03:06 -04:00
committed by Sean DuBois
parent 25305542b9
commit 73f8db9316
4 changed files with 13 additions and 12 deletions

View File

@@ -144,6 +144,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
* [Quentin Renard](https://github.com/asticode) * [Quentin Renard](https://github.com/asticode)
* [opennota](https://github.com/opennota) * [opennota](https://github.com/opennota)
* [Simon Eisenmann](https://github.com/longsleep) * [Simon Eisenmann](https://github.com/longsleep)
* [Ben Weitzman](https://github.com/benweitzman)
### License ### License
MIT License - see [LICENSE](LICENSE) for full text MIT License - see [LICENSE](LICENSE) for full text

View File

@@ -10,7 +10,7 @@ go get github.com/pion/webrtc/examples/broadcast
``` ```
### Open broadcast example page ### Open broadcast example page
[jsfiddle.net](https://jsfiddle.net/zhpya3n9/) You should see two buttons 'Publish a Broadcast' and 'Join a Broadcast' [jsfiddle.net](https://jsfiddle.net/d2mt13y6/) You should see two buttons 'Publish a Broadcast' and 'Join a Broadcast'
### Run Broadcast ### Run Broadcast
#### Linux/macOS #### Linux/macOS

View File

@@ -27,7 +27,7 @@ window.createSession = isPublisher => {
.catch(log) .catch(log)
}).catch(log) }).catch(log)
} else { } else {
pc.addTransceiver('video', {'direction': 'recvonly'}) pc.addTransceiver('video')
pc.createOffer() pc.createOffer()
.then(d => pc.setLocalDescription(d)) .then(d => pc.setLocalDescription(d))
.catch(log) .catch(log)

View File

@@ -19,20 +19,20 @@ func main() {
sdpChan := signal.HTTPSDPServer() sdpChan := signal.HTTPSDPServer()
// Everything below is the Pion WebRTC API, thanks for using it ❤️. // Everything below is the Pion WebRTC API, thanks for using it ❤️.
// Create a MediaEngine object to configure the supported codec
m := webrtc.MediaEngine{}
// Setup the codecs you want to use.
// Only support VP8, this makes our proxying code simpler
m.RegisterCodec(webrtc.NewRTPVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000))
// Create the API object with the MediaEngine
api := webrtc.NewAPI(webrtc.WithMediaEngine(m))
offer := webrtc.SessionDescription{} offer := webrtc.SessionDescription{}
signal.Decode(<-sdpChan, &offer) signal.Decode(<-sdpChan, &offer)
fmt.Println("") fmt.Println("")
// Since we are answering use PayloadTypes declared by offerer
mediaEngine := webrtc.MediaEngine{}
err := mediaEngine.PopulateFromSDP(offer)
if err != nil {
panic(err)
}
// Create the API object with the MediaEngine
api := webrtc.NewAPI(webrtc.WithMediaEngine(mediaEngine))
peerConnectionConfig := webrtc.Configuration{ peerConnectionConfig := webrtc.Configuration{
ICEServers: []webrtc.ICEServer{ ICEServers: []webrtc.ICEServer{
{ {