mirror of
https://github.com/pion/webrtc.git
synced 2025-10-07 08:01:27 +08:00
Set directions on channels
This commit is contained in:
@@ -6,10 +6,11 @@ import (
|
||||
|
||||
"bufio"
|
||||
"encoding/base64"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/pions/webrtc"
|
||||
"github.com/pions/webrtc/examples/gstreamer/gst"
|
||||
"github.com/pions/webrtc/pkg/rtp"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
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
|
||||
// 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() {
|
||||
track := atomic.AddUint64(&trackCount, 1)
|
||||
fmt.Printf("Track %d has started \n", track)
|
||||
|
@@ -36,7 +36,7 @@ func main() {
|
||||
// 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.
|
||||
// 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() {
|
||||
track := atomic.AddUint64(&trackCount, 1)
|
||||
fmt.Printf("Track %d has started \n", track)
|
||||
|
@@ -17,7 +17,7 @@ func packetHandler(conn *ipv4.PacketConn, srcString string, remoteKey []byte, tl
|
||||
buffer := make([]byte, MTU)
|
||||
|
||||
dtlsStates := make(map[string]*dtls.DTLSState)
|
||||
bufferTransports := make(map[uint32]chan *rtp.Packet)
|
||||
bufferTransports := make(map[uint32]chan<- *rtp.Packet)
|
||||
|
||||
var srtpSession *srtp.Session
|
||||
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) {
|
||||
listener, err := net.ListenPacket("udp4", ip+":0")
|
||||
|
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/pions/pkg/stun"
|
||||
"github.com/pions/webrtc/internal/dtls"
|
||||
"github.com/pions/webrtc/internal/ice"
|
||||
"github.com/pions/webrtc/internal/network"
|
||||
@@ -29,7 +28,7 @@ const (
|
||||
)
|
||||
|
||||
type RTCPeerConnection struct {
|
||||
Ontrack func(mediaType MediaType, buffers chan *rtp.Packet)
|
||||
Ontrack func(mediaType MediaType, buffers <-chan *rtp.Packet)
|
||||
LocalDescription *sdp.SessionDescription
|
||||
|
||||
tlscfg *dtls.TLSCfg
|
||||
@@ -73,7 +72,7 @@ func (r *RTCPeerConnection) AddStream(mediaType MediaType) (buffers chan<- []byt
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user