-
hi, i want to send multiple streams on one peerconnection. i have tried this between webpage and webpage. it works. but when i tried newVideoStream(iceConnectedCtx, peerConnection, videoFileName, "video_a", "pion_a")
newVideoStream(iceConnectedCtx, peerConnection, videoFileName, "video_b", "pion_b") i can only got one stream here is func newVideoStream(iceConnectedCtx context.Context, peerConnection *webrtc.PeerConnection, fileName, id, streamID string) {
videoTrack, videoTrackErr := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeH264}, id, streamID)
if videoTrackErr != nil {
panic(videoTrackErr)
}
rtpSender, videoTrackErr := peerConnection.AddTrack(videoTrack)
if videoTrackErr != nil {
panic(videoTrackErr)
}
go func() {
rtcpBuf := make([]byte, 1500)
for {
if _, _, rtcpErr := rtpSender.Read(rtcpBuf); rtcpErr != nil {
return
}
}
}()
go func() {
// Open a H264 file and start reading using our IVFReader
file, h264Err := os.Open(fileName)
if h264Err != nil {
panic(h264Err)
}
h264, h264Err := h264reader.NewReader(file)
if h264Err != nil {
panic(h264Err)
}
// Wait for connection established
<-iceConnectedCtx.Done()
log.Printf("fucking video ...")
ticker := time.NewTicker(h264FrameDuration)
for ; true; <-ticker.C {
nal, h264Err := h264.NextNAL()
if h264Err == io.EOF {
fmt.Printf("All video frames parsed and sent")
os.Exit(0)
}
if h264Err != nil {
panic(h264Err)
}
if h264Err = videoTrack.WriteSample(media.Sample{Data: nal.Data, Duration: time.Second}); h264Err != nil {
panic(h264Err)
}
}
}()
} and init the peerconnection like this: // Enable Extension Headers needed for Simulcast
m := &webrtc.MediaEngine{}
if err := m.RegisterDefaultCodecs(); err != nil {
panic(err)
}
for _, extension := range []string{
"urn:ietf:params:rtp-hdrext:sdes:mid",
"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id",
"urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id",
} {
if err := m.RegisterHeaderExtension(webrtc.RTPHeaderExtensionCapability{URI: extension}, webrtc.RTPCodecTypeVideo); err != nil {
panic(err)
}
if err := m.RegisterHeaderExtension(webrtc.RTPHeaderExtensionCapability{URI: extension}, webrtc.RTPCodecTypeAudio); err != nil {
panic(err)
}
}
// Create a InterceptorRegistry. This is the user configurable RTP/RTCP Pipeline.
// This provides NACKs, RTCP Reports and other features. If you use `webrtc.NewPeerConnection`
// this is enabled by default. If you are manually managing You MUST create a InterceptorRegistry
// for each PeerConnection.
i := &interceptor.Registry{}
// Use the default set of Interceptors
if err := webrtc.RegisterDefaultInterceptors(m, i); err != nil {
panic(err)
}
config := webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
URLs: []string{"stun:stun.l.google.com:19302"},
},
},
}
// Create a new RTCPeerConnection
//peerConnection, err := webrtc.NewPeerConnection(config)
peerConnection, err := webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithInterceptorRegistry(i)).NewPeerConnection(config)
if err != nil {
panic(err)
} so, my question is:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @acevest pion/webrtc does support multiple audio/video tracks per PeerConnection. I am not exactly sure what the problem is. I would try play-from-disk-renegotation. This example shows adding/removing multiple tracks to a single PeerConnection. |
Beta Was this translation helpful? Give feedback.
Hey @acevest
pion/webrtc does support multiple audio/video tracks per PeerConnection.
I am not exactly sure what the problem is. I would try play-from-disk-renegotation. This example shows adding/removing multiple tracks to a single PeerConnection.