Set directions on channels

This commit is contained in:
Sean DuBois
2018-06-12 21:25:49 -07:00
parent 1f56c95444
commit c21bc319d2
4 changed files with 9 additions and 9 deletions

View File

@@ -6,10 +6,11 @@ import (
"bufio" "bufio"
"encoding/base64" "encoding/base64"
"sync/atomic"
"github.com/pions/webrtc" "github.com/pions/webrtc"
"github.com/pions/webrtc/examples/gstreamer/gst" "github.com/pions/webrtc/examples/gstreamer/gst"
"github.com/pions/webrtc/pkg/rtp" "github.com/pions/webrtc/pkg/rtp"
"sync/atomic"
) )
var trackCount uint64 var trackCount uint64
@@ -36,7 +37,7 @@ func startWebrtc(pipeline *gst.Pipeline) {
// Set a handler for when a new remote track starts, this handler starts a gstreamer pipeline // Set a handler for when a new remote track starts, this handler starts a gstreamer pipeline
// with the first track and assumes it is VP8 video data. // with the first track and assumes it is VP8 video data.
peerConnection.Ontrack = func(mediaType webrtc.MediaType, packets chan *rtp.Packet) { peerConnection.Ontrack = func(mediaType webrtc.MediaType, packets <-chan *rtp.Packet) {
go func() { go func() {
track := atomic.AddUint64(&trackCount, 1) track := atomic.AddUint64(&trackCount, 1)
fmt.Printf("Track %d has started \n", track) fmt.Printf("Track %d has started \n", track)

View File

@@ -36,7 +36,7 @@ func main() {
// Set a handler for when a new remote track starts, this handler saves buffers to disk as // Set a handler for when a new remote track starts, this handler saves buffers to disk as
// an ivf file, since we could have multiple video tracks we provide a counter. // an ivf file, since we could have multiple video tracks we provide a counter.
// In your application this is where you would handle/process video // In your application this is where you would handle/process video
peerConnection.Ontrack = func(mediaType webrtc.MediaType, packets chan *rtp.Packet) { peerConnection.Ontrack = func(mediaType webrtc.MediaType, packets <-chan *rtp.Packet) {
go func() { go func() {
track := atomic.AddUint64(&trackCount, 1) track := atomic.AddUint64(&trackCount, 1)
fmt.Printf("Track %d has started \n", track) fmt.Printf("Track %d has started \n", track)

View File

@@ -17,7 +17,7 @@ func packetHandler(conn *ipv4.PacketConn, srcString string, remoteKey []byte, tl
buffer := make([]byte, MTU) buffer := make([]byte, MTU)
dtlsStates := make(map[string]*dtls.DTLSState) dtlsStates := make(map[string]*dtls.DTLSState)
bufferTransports := make(map[uint32]chan *rtp.Packet) bufferTransports := make(map[uint32]chan<- *rtp.Packet)
var srtpSession *srtp.Session var srtpSession *srtp.Session
for { for {
@@ -95,7 +95,7 @@ func packetHandler(conn *ipv4.PacketConn, srcString string, remoteKey []byte, tl
} }
} }
type BufferTransportGenerator func(uint32) chan *rtp.Packet type BufferTransportGenerator func(uint32) chan<- *rtp.Packet
func UdpListener(ip string, remoteKey []byte, tlscfg *dtls.TLSCfg, b BufferTransportGenerator) (int, error) { func UdpListener(ip string, remoteKey []byte, tlscfg *dtls.TLSCfg, b BufferTransportGenerator) (int, error) {
listener, err := net.ListenPacket("udp4", ip+":0") listener, err := net.ListenPacket("udp4", ip+":0")

View File

@@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"github.com/pions/pkg/stun"
"github.com/pions/webrtc/internal/dtls" "github.com/pions/webrtc/internal/dtls"
"github.com/pions/webrtc/internal/ice" "github.com/pions/webrtc/internal/ice"
"github.com/pions/webrtc/internal/network" "github.com/pions/webrtc/internal/network"
@@ -29,7 +28,7 @@ const (
) )
type RTCPeerConnection struct { type RTCPeerConnection struct {
Ontrack func(mediaType MediaType, buffers chan *rtp.Packet) Ontrack func(mediaType MediaType, buffers <-chan *rtp.Packet)
LocalDescription *sdp.SessionDescription LocalDescription *sdp.SessionDescription
tlscfg *dtls.TLSCfg tlscfg *dtls.TLSCfg
@@ -73,7 +72,7 @@ func (r *RTCPeerConnection) AddStream(mediaType MediaType) (buffers chan<- []byt
} }
// Private // Private
func (r *RTCPeerConnection) generateChannel(ssrc uint32) (buffers chan *rtp.Packet) { func (r *RTCPeerConnection) generateChannel(ssrc uint32) (buffers chan<- *rtp.Packet) {
if r.Ontrack == nil { if r.Ontrack == nil {
return nil return nil
} }