Multiple external video stream in one session
Is it possible to set multiple external video tracker in same session: My requirement is to send all the configured camera stream to mobile. My code to add single external video stream from EmguCV which is working fine:
var videoEncoderEndPoint = new VideoEncoderEndPoint();
MediaStreamTrack videoTrack = new MediaStreamTrack(videoEncoderEndPoint.GetVideoSourceFormats(), MediaStreamStatusEnum.SendOnly);
session.PeerConnection.addTrack(videoTrack);
var testPatternSource = new VideoTestPatternSource();
testPatternSource.SetFrameRate(30);
testPatternSource.OnVideoSourceRawSample += (durationMilliseconds, width, height, sample, pixelFormat) =>
{
//External video stream from EmguCV
DeviceFrameHandler.Invoke(_frames.First().Key, out byte[] frame, out int _width, out int _height);
if (frame != null)
{
videoEncoderEndPoint.ExternalVideoSourceRawSample(durationMilliseconds, _width, _height, frame, VideoPixelFormatsEnum.Bgr);
}
};
videoEncoderEndPoint.OnVideoSourceEncodedSample += session.PeerConnection.SendVideo;
session.PeerConnection.OnVideoFormatsNegotiated += (formats) => videoEncoderEndPoint.SetVideoSourceFormat(formats.First());
session.PeerConnection.onconnectionstatechange += async (state) =>
{
Console.WriteLine($"Peer connection state change to {state}.");
if (state == RTCPeerConnectionState.connected)
{
await testPatternSource.StartVideo();
}
else if (state == RTCPeerConnectionState.failed || state == RTCPeerConnectionState.disconnected || state == RTCPeerConnectionState.closed)
{
session.PeerConnection.Close($"ice {state}");
await testPatternSource.CloseVideo();
}
};
But when I try to add another video tracker, I'm getting this exception:
session.PeerConnection.addTrack(videoTrack);
//A local video track has already been set on this session.
//at SIPSorcery.Net.RTPSession.AddLocalTrack(MediaStreamTrack track)
//at SIPSorcery.Net.RTPSession.addTrack(MediaStreamTrack track)
No sadly multiple audio or video streams are not yet supported. It's something I think about regularly but then something else comes up.
Thanks for opening the issue though. It provides some extra motivation.
Any plans on implementing this soon?
Any plans on implementing this soon?
It's not something I'll be able to put any time into in the near future. So unless someone else picks it up, no, probably won't be implemented any time soon.
FYI,
I made a specific branch (Secondary_Video_Stream) in my own repository to support a secondary video stream (input and/or output) - more as proof of concept than a real update.
My goal was to understand how SIPSorcery should be updated to have this kind of feature but the way I did it it's not really accurate.
I'm currently working on a way to do it correctly. The goal being that it supports as many video streams as desired.
Then I'll work to have the same for audio streams.
Thank you so very much for starting this effort. Please keep us posted on when you think SIPSorcery can safely support multiple audio/video tracks in the same RTCPeerConnection.
Now in master branch and since release v6.0.8 it's possible to have on the same PeerConnection several Audio stream and/or several Video stream.
To manage them you have access to this new objects / events:
- PeerConnection.AudioStreamList
- PeerConnection.VideoStreamList
- PeerConnection.OnAudioFormatsNegotiatedByIndex
- PeerConnection.OnVideoFormatsNegotiatedByIndex
- PeerConnection.OnVideoFrameReceivedByIndex
- PeerConnection.OnRtpPacketReceivedByIndex
- PeerConnection.OnRtpEventByIndex