Skip to content

Commit

Permalink
Remove examples/internal
Browse files Browse the repository at this point in the history
Users find it frustrating that example code doesn't work out of tree.
This makes copying the examples out of the repo easier.

Relates to pion/webrtc#1981
  • Loading branch information
Sean-Der committed Sep 10, 2024
1 parent 96595fe commit c911db2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 150 deletions.
53 changes: 50 additions & 3 deletions ffmpeg-send/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
package main

import (
"bufio"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"strings"
"time"

"github.com/asticode/go-astiav"
"github.com/pion/example-webrtc-applications/v3/internal/signal"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3/pkg/media"
)
Expand Down Expand Up @@ -48,7 +53,7 @@ func main() {

// Wait for the offer to be pasted
offer := webrtc.SessionDescription{}
signal.Decode(signal.MustReadStdin(), &offer)
decode(readUntilNewline(), &offer)

// Set the remote SessionDescription
err = peerConnection.SetRemoteDescription(offer)
Expand All @@ -74,7 +79,7 @@ func main() {
<-gatherComplete

// Output the answer in base64 so we can paste it in browser
fmt.Println(signal.Encode(*peerConnection.LocalDescription()))
fmt.Println(encode(*peerConnection.LocalDescription()))

// Start pushing buffers on these tracks
writeH264ToTrack(videoTrack)
Expand Down Expand Up @@ -264,3 +269,45 @@ func freeVideoCoding() {
encodeCodecContext.Free()
encodePacket.Free()
}

// Read from stdin until we get a newline
func readUntilNewline() (in string) {
var err error

r := bufio.NewReader(os.Stdin)
for {
in, err = r.ReadString('\n')
if err != nil && !errors.Is(err, io.EOF) {
panic(err)
}

if in = strings.TrimSpace(in); len(in) > 0 {
break
}
}

fmt.Println("")
return
}

// JSON encode + base64 a SessionDescription
func encode(obj *webrtc.SessionDescription) string {
b, err := json.Marshal(obj)
if err != nil {
panic(err)
}

return base64.StdEncoding.EncodeToString(b)
}

// Decode a base64 and unmarshal JSON into a SessionDescription
func decode(in string, obj *webrtc.SessionDescription) {
b, err := base64.StdEncoding.DecodeString(in)
if err != nil {
panic(err)
}

if err = json.Unmarshal(b, obj); err != nil {
panic(err)
}
}
34 changes: 0 additions & 34 deletions internal/signal/http.go

This file was deleted.

113 changes: 0 additions & 113 deletions internal/signal/signal.go

This file was deleted.

0 comments on commit c911db2

Please sign in to comment.