mirror of
https://github.com/pion/webrtc.git
synced 2025-11-01 11:12:50 +08:00
Call RTCPeerConnection.Ontrack with a new goroutine
Every implementation should do this anyway. Also new users might not understand and block all events for RTCPeerConnections
This commit is contained in:
@@ -38,16 +38,14 @@ 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.TrackType, packets <-chan *rtp.Packet) {
|
peerConnection.Ontrack = func(mediaType webrtc.TrackType, packets <-chan *rtp.Packet) {
|
||||||
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)
|
if track == 1 && mediaType == webrtc.VP8 {
|
||||||
if track == 1 && mediaType == webrtc.VP8 {
|
for {
|
||||||
for {
|
p := <-packets
|
||||||
p := <-packets
|
pipeline.Push(p.Raw)
|
||||||
pipeline.Push(p.Raw)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the remote SessionDescription
|
// Set the remote SessionDescription
|
||||||
|
|||||||
@@ -37,18 +37,16 @@ func main() {
|
|||||||
// 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.TrackType, packets <-chan *rtp.Packet) {
|
peerConnection.Ontrack = func(mediaType webrtc.TrackType, packets <-chan *rtp.Packet) {
|
||||||
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)
|
|
||||||
|
|
||||||
i, err := newIVFWriter(fmt.Sprintf("output-%d.ivf", track))
|
i, err := newIVFWriter(fmt.Sprintf("output-%d.ivf", track))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
i.addPacket(<-packets)
|
i.addPacket(<-packets)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the remote SessionDescription
|
// Set the remote SessionDescription
|
||||||
|
|||||||
@@ -92,6 +92,6 @@ func (r *RTCPeerConnection) generateChannel(ssrc uint32) (buffers chan<- *rtp.Pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
bufferTransport := make(chan *rtp.Packet, 15)
|
bufferTransport := make(chan *rtp.Packet, 15)
|
||||||
r.Ontrack(VP8, bufferTransport) // TODO look up media via SSRC in remote SD
|
go r.Ontrack(VP8, bufferTransport) // TODO look up media via SSRC in remote SD
|
||||||
return bufferTransport
|
return bufferTransport
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user