Skip to content

Commit

Permalink
Merge cfa9d57 into 15d0ae0
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-Der committed Mar 4, 2019
2 parents 15d0ae0 + cfa9d57 commit d65e314
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 45 deletions.
44 changes: 44 additions & 0 deletions examples/gstreamer-send-offer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# gstreamer-send-offer
gstreamer-send-offer is a simple application that shows how to send video using pion-WebRTC and GStreamer. This is meant to be used with `gstreamer-receive`, if you want to send via to your browser try `gstreamer-send`

## Instructions
### Install GStreamer
This example requires you have GStreamer installed, these are the supported platforms
#### Debian/Ubuntu
`sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-good`
#### Windows MinGW64/MSYS2
`pacman -S mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gst-libav mingw-w64-x86_64-gst-plugins-good mingw-w64-x86_64-gst-plugins-bad mingw-w64-x86_64-gst-plugins-ugly`

### Run gstreamer-send-offer and make an offer to gstreamer-receive via stdin
```
go run examples/gstreamer-send-offer/*.go | go run examples/gstreamer-receive/*.go
```

### post the answer from gstreamer-receive back to gstreamer-send-offer
You will see a base64 SDP printed to your console. You now need to communicate this back to `gstreamer-send-offer` this can be done via a HTTP endpoint

`curl localhost:8080/sdp -d "BASE_64_SDP"`

### enjoy your video!
A video should start playing via GStreamer and will continue playing until you close the application.

Congrats, you have used pion-WebRTC! Now start building something cool

## Customizing your video or audio
`gstreamer-send-offer` also accepts the command line arguments `-video-src` and `-audio-src` allowing you to provide custom inputs.

When prototyping with GStreamer it is highly recommended that you enable debug output, this is done by setting the `GST_DEBUG` enviroment variable.
You can read about that [here](https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gst-running.html) a good default value is `GST_DEBUG=*:3`

You can also prototype a GStreamer pipeline by using `gst-launch-1.0` to see how things look before trying them with `gstreamer-send` for the examples below you
also may need additional setup to enable extra video codecs like H264. The output from GST_DEBUG should give you hints

These pipelines work on Linux, they may have issues on other platforms. We would love PRs for more example pipelines that people find helpful!

* a webcam, with computer generated audio.

`gstreamer-send-offer -video-src "autovideosrc ! video/x-raw, width=320, height=240 ! videoconvert ! queue"`

* a pre-recorded video, sintel.mkv is available [here](https://durian.blender.org/download/)

`gstreamer-send-offer -video-src "uridecodebin uri=file:///tmp/sintel.mkv ! videoscale ! video/x-raw, width=320, height=240 ! queue " -audio-src "uridecodebin uri=file:///tmp/sintel.mkv ! queue ! audioconvert"`
13 changes: 9 additions & 4 deletions examples/gstreamer-send-offer/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"math/rand"

Expand All @@ -11,6 +12,10 @@ import (
)

func main() {
audioSrc := flag.String("audio-src", "audiotestsrc", "GStreamer audio src")
videoSrc := flag.String("video-src", "videotestsrc", "GStreamer video src")
sdpChan := signal.HTTPSDPServer()

// Everything below is the pion-WebRTC API! Thanks for using it ❤️.

// Prepare the configuration
Expand Down Expand Up @@ -69,9 +74,9 @@ func main() {
// Output the offer in base64 so we can paste it in browser
fmt.Println(signal.Encode(offer))

// Wait for the answer to be pasted
// Wait for the answer to be submitted via HTTP
answer := webrtc.SessionDescription{}
signal.Decode(signal.MustReadStdin(), &answer)
signal.Decode(<-sdpChan, &answer)

// Set the remote SessionDescription
err = peerConnection.SetRemoteDescription(answer)
Expand All @@ -80,8 +85,8 @@ func main() {
}

// Start pushing buffers on these tracks
gst.CreatePipeline(webrtc.Opus, opusTrack, "audiotestsrc").Start()
gst.CreatePipeline(webrtc.VP8, vp8Track, "videotestsrc").Start()
gst.CreatePipeline(webrtc.Opus, opusTrack, *audioSrc).Start()
gst.CreatePipeline(webrtc.VP8, vp8Track, *videoSrc).Start()

// Block forever
select {}
Expand Down
31 changes: 31 additions & 0 deletions examples/internal/signal/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package signal

import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"strconv"
)

// HTTPSDPServer starts a HTTP Server that consumes SDPs
func HTTPSDPServer() chan string {
port := flag.Int("port", 8080, "http server port")
flag.Parse()

sdpChan := make(chan string)
http.HandleFunc("/sdp", func(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body)
fmt.Fprintf(w, "done")
sdpChan <- string(body)
})

go func() {
err := http.ListenAndServe(":"+strconv.Itoa(*port), nil)
if err != nil {
panic(err)
}
}()

return sdpChan
}
46 changes: 5 additions & 41 deletions examples/sfu/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package main

import (
"bufio"
"flag"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"time"

"github.com/pions/rtcp"
Expand All @@ -23,26 +18,14 @@ var peerConnectionConfig = webrtc.Configuration{
},
}

func mustReadStdin(reader *bufio.Reader) string {
rawSd, err := reader.ReadString('\n')
if err != nil {
panic(err)
}
fmt.Println("")

return rawSd
}

func mustReadHTTP(sdp chan string) string {
ret := <-sdp
return ret
}

const (
rtcpPLIInterval = time.Second * 3
)

func main() {
sdpChan := signal.HTTPSDPServer()

// Everything below is the pion-WebRTC API, thanks for using it ❤️.
// Create a MediaEngine object to configure the supported codec
m := webrtc.MediaEngine{}

Expand All @@ -53,29 +36,10 @@ func main() {
// Create the API object with the MediaEngine
api := webrtc.NewAPI(webrtc.WithMediaEngine(m))

port := flag.Int("port", 8080, "http server port")
flag.Parse()

sdp := make(chan string)
http.HandleFunc("/sdp", func(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body)
fmt.Fprintf(w, "done")
sdp <- string(body)
})

go func() {
err := http.ListenAndServe(":"+strconv.Itoa(*port), nil)
if err != nil {
panic(err)
}
}()

offer := webrtc.SessionDescription{}
signal.Decode(mustReadHTTP(sdp), &offer)
signal.Decode(<-sdpChan, &offer)
fmt.Println("")

// Everything below is the pion-WebRTC API, thanks for using it ❤️.

// Create a new RTCPeerConnection
peerConnection, err := api.NewPeerConnection(peerConnectionConfig)
if err != nil {
Expand Down Expand Up @@ -144,7 +108,7 @@ func main() {
fmt.Println("Curl an base64 SDP to start sendonly peer connection")

recvOnlyOffer := webrtc.SessionDescription{}
signal.Decode(mustReadHTTP(sdp), &recvOnlyOffer)
signal.Decode(<-sdpChan, &recvOnlyOffer)

// Create a new PeerConnection
peerConnection, err := api.NewPeerConnection(peerConnectionConfig)
Expand Down

0 comments on commit d65e314

Please sign in to comment.