- From: Bernard Aboba <Bernard.Aboba@microsoft.com>
- Date: Fri, 27 Jun 2014 17:49:45 +0000
- To: "public-ortc@w3.org" <public-ortc@w3.org>
Here is a code example (Section 4.4, Example 5) that shows how to support audio/video multiplexing and/or RTP/RTCP multiplexing. // This is an example of how to utilize distinct ICE transports for Audio and Video // As well as for RTP and RTCP. If both sides can multiplex audio/video // and/or RTP/RTCP then the multiplexing will occur. // // Assume we have an audioTrack and a videoTrack to send. // //create the RTP and RTCP ICE transports for audio and video var audioRtpIceTransport = new RTCIceTransport(...); var audioRtcpIceTransport = audioRtpIceTransport.createAssociatedTransport(); var videoRtpIceTransport = new RTCIceTransport(...); var videoRtcpIceTransport = audioRtpIceTransport.createAssociatedTransport(); // //create the DTLS transports var audioRtpDtlsTransport = new RTCDtlsTransport(audioRtpIceTransport); var audioRtcpDtlsTransport = new RTCDtlsTransport(audioRtcpIceTransport); var videoRtpDtlsTransport = new RTCDtlsTransport(videoRtpIceTransport); var videoRtcpDtlsTransport = new RTCDtlsTransport(videoRtcpIceTransport); // // Create the sender and receiver objects var audioSender = new RtpSender(audioTrack, audioRtpDtlsTransport, audioRtcpDtlsTransport); var videoSender = new RtpSender(videoTrack, videoRtpDtlsTransport, videoRtcpDtlsTransport); var audioReceiver = new RtpReceiver(audioRtpDtlsTransport, audioRtcpDtlsTransport); var videoReceiver = new RtpReceiver(videoRtpDtlsTransport, videoRtcpDtlsTransport); // // Retrieve the receiver and sender capabilities var recvAudioCaps = RTCRtpReceiver.getCapabilities("audio"); var recvVideoCaps = RTCRtpReceiver.getCapabiltiies("video"); var sendAudioCaps = RTCRtpSender.getCapabilities("audio"); var recvVideoCaps = RTCRtpSender.getCapabilities("video"); // // At this point, ICE/DTLS parameters and Send/Receive capabilities can be exchanged. mySignaller.myOfferTracks({ // Indicate that the initiator would prefer to multiplex both A/V and RTP/RTCP "bundle": true, // Indicate that the initiator is willing to multiplex RTP/RTCP without A/V mux "rtcpMux": true, // Offer the ICE parameters "audioRtpIce": audioRtpIceTransport.getLocalParameters(), "audioRtcpIce": audioRtcpIceTransport.getLocalParameters(), "videoRtpIce": videoRtpIceTransport.getLocalParameters(), "videoRtcpIce": videoRtcpIceTransport.getLocalParameters(), // Offer the DTLS parameters "audioRtpDtls": audioRtpDtlsTransport.getLocalParameters(), "audioRtcpDtls": audioRtcpDtlsTransport.getLocalParameters(), "videoRtpDtls": videoRtpDtlsTransport.getLocalParameters(), "videoRtcpDtls": videoRtcpDtlsTransport.getLocalParameters(), // Offer the receiver and sender audio and video capabilities. "recvAudioCaps": recvAudioCaps, "recvVideoCaps": recvVideoCaps, "sendAudioCaps": sendAudioCaps, "sendVideoCaps": sendVideoCaps }, function(answer) { // The responder answers with its preferences, parameters and capabilities // // Derive the send and receive parameters, assuming that RTP/RTCP mux will be enabled. var audioSendParams = myCapsToSendParams(sendAudioCaps, answer.recvAudioCaps); var videoSendParams = myCapsToSendParams(sendVideoCaps, answer.recvVideoCaps); var audioRecvParams = myCapsToRecvParams(recvAudioCaps, answer.sendAudioCaps); var videoRecvParams = myCapsToRecvParams(recvVideoCaps, answer.sendVideoCaps); // // If the responder wishes to enable bundle, we will enable it if (answer.bundle) { // Only start the single transport that is needed // No need for the ICE Transport Controller. audioRtpIceTransport.start(answer.audioRtpIce, RTCIceRole.controlling); audioRtpDtlsTransport.start(remote.audioRtpDtls); // // Replace the transport on the Sender and Receiver objects // audioSender.setTransport(audioRtpDtlsTransport); videoSender.setTransport(audioRtpDtlsTransport); audioReceiver.setTransport(audioRtpDtlsTransport); videoReceiver.setTransport(audioRtpDtlsTransoprt); // If bundle was requested, then implicitly RTP/RTCP mux must be done answer.rtcpMux = true; } else { if (answer.rtcpMux){ // We don't want to bundle, but we do want to multiplex RTP/RTCP // Create the ICE Transport Controller object var controller = new RTCIceTransportController(); controller.addTransport(audioRtpIceTransport); controller.addTransport(videoRtpIceTransport); // Start the audio and video ICE transports audioRtpIceTransport.start(answer.audioRtpIce, RTCIceRole.controlling); videoRtpIceTransport.start(answer.videoRtpIce, RTCIceRole.controlling); // Start the audio and video DTLS transports audioRtpDtlsTransport.start(answer.audioRtpDtls); videoRtpDtlsTransport.start(answer.videoRtpDtls); // Replace the transport on the Sender and Receiver objects // audioSender.setTransport(audioRtpDtlsTransport); videoSender.setTransport(videoRtpDtlsTransport); audioReceiver.setTransport(audioRtpDtlsTransport); videoReceiver.setTransport(videoRtpDtlsTransoprt); }; // Check if the responder does not want to bundle // and does not want RTP/RTCP multiplexing if (!answer.rtcpMux) { // Create the ICE Transport Controller object var controller = new RTCIceTransportController(); controller.addTransport(audioRtpIceTransport); controller.addTransport(videoRtpIceTransport); // Start the ICE transports that are needed audioRtpIceTransport.start(answer.audioRtpIce, RTCIceRole.controlling); audioRtcpIceTransport.start(answer.audioRtcpIce, RTCIceRole.controlling); videoRtpIceTransport.start(answer.videoRtpIce, RTCIceRole.controlling); videoRtcpIceTransport.start(answer.videoRtcpIce, RTCIceRole.controlling); // Start the DTLS transports that are needed audioRtpDtlsTransport.start(answer.audioRtpDtls); audioRtcpDtlsTransport.start(answer.audioRtcpDtls); videoRtpDtlsTransport.start(answer.videoRtpDtls); videoRtcpDtlsTransport.start(answer.videoRtcpDtls); // Disable RTP/RTCP multiplexing audioSendParams.rtcp.mux = false; videoSendParams.rtcp.mux = false; audioRecvParams.rtcp.mux = false; videoRecvParams.rtcp.mux = false; }; // // Set the audio and video send and receive parameters. audioSender.send(audioSendParams); videoSender.send(videoSendParams); audioReceiver.receive(audioRecvParams); videoReceiver.receive(videoRecvParams); }); // Now we can render/play // audioReceiver.track and videoReceiver.track.
Received on Friday, 27 June 2014 17:50:15 UTC