public void GuarenteedNumberOfVideoEncoderInstancesMixReduced() { MediaConfigurationChangeLog changeLog = new MediaConfigurationChangeLog(); // 4 StreamSetup types: // - RTPUDP - must be supported // - RTPRTSPHTTP - must be supported // - RTPRTSPTCP - optional // - RTPMulticastUDP - optional List <StreamSetup> supportedSetups = new List <StreamSetup>(); StreamSetup streamSetup1 = new StreamSetup(); streamSetup1.Transport = new Transport(); streamSetup1.Transport.Protocol = TransportProtocol.UDP; streamSetup1.Stream = StreamType.RTPUnicast; supportedSetups.Add(streamSetup1); StreamSetup streamSetup2 = new StreamSetup(); streamSetup2.Transport = new Transport(); streamSetup2.Transport.Protocol = TransportProtocol.HTTP; streamSetup2.Stream = StreamType.RTPUnicast; supportedSetups.Add(streamSetup2); bool TCP = Features.Contains(Feature.RTPRTSPTCP); StreamSetup streamSetup3 = new StreamSetup(); streamSetup3.Transport = new Transport(); if (TCP) { streamSetup3.Transport.Protocol = TransportProtocol.RTSP; streamSetup3.Stream = StreamType.RTPUnicast; supportedSetups.Add(streamSetup3); } bool Multicast = Features.Contains(Feature.RTPMulticastUDP); StreamSetup streamSetup4 = new StreamSetup(); streamSetup4.Transport = new Transport(); if (Multicast) { streamSetup4.Transport.Protocol = TransportProtocol.UDP; streamSetup4.Stream = StreamType.RTPMulticast; supportedSetups.Add(streamSetup4); } // list of used VEC tokens for RTP-Multicast streaming List <string> MulticastTokenList = new List <string>(); // list of used VSC tokens List <string> VscTokenList = new List <string>(); // lists of used ip addresses and ports for RTP-Multicast streaming List <int> usedMulticastPorts = new List <int>(); List <string> usedMulticastIPs = new List <string>(); RunTest( () => { int step = 0; MultipleStreamTestReduced(changeLog, (ref Profile profile) => { if (!VscTokenList.Contains(profile.VideoSourceConfiguration.token)) { VscTokenList.Add(profile.VideoSourceConfiguration.token); // we should clear this for every new Video Source Configuration if (0 != MulticastTokenList.Count) { MulticastTokenList.Clear(); } } int idx = step % supportedSetups.Count; StreamSetup current = supportedSetups[idx]; // setup multicast if (current.Stream == StreamType.RTPMulticast) { if (MulticastTokenList.Contains(profile.VideoEncoderConfiguration.token)) { idx = (++step) % supportedSetups.Count; current = supportedSetups[idx]; } else { MulticastTokenList.Add(profile.VideoEncoderConfiguration.token); string addressVideo = ""; int portVideo = 0; string addressAudio = ""; int portAudio = 0; string addressMetadata = ""; int portMetadata = 0; if (profile.VideoEncoderConfiguration != null) { addressVideo = GetMulticastAddress3(usedMulticastIPs); usedMulticastIPs.Add(addressVideo); portVideo = GetMulticastPort2(usedMulticastPorts); usedMulticastPorts.Add(portVideo); VideoEncoderConfiguration configCopy = Utils.CopyMaker.CreateCopy(profile.VideoEncoderConfiguration); changeLog.TrackModifiedConfiguration(configCopy); SetMulticast(profile.VideoEncoderConfiguration.Multicast, IPType.IPv4, addressVideo, portVideo); SetVideoEncoderConfiguration(profile.VideoEncoderConfiguration, false, true); } if (profile.AudioEncoderConfiguration != null) { addressAudio = GetMulticastAddress3(usedMulticastIPs); usedMulticastIPs.Add(addressAudio); portAudio = GetMulticastPort2(usedMulticastPorts); usedMulticastPorts.Add(portAudio); } if (profile.MetadataConfiguration != null) { addressMetadata = GetMulticastAddress3(usedMulticastIPs); usedMulticastIPs.Add(addressMetadata); portMetadata = GetMulticastPort2(usedMulticastPorts); usedMulticastPorts.Add(portMetadata); } SetMulticastSettings(profile, IPType.IPv4, changeLog, addressAudio, portAudio, addressVideo, portVideo, addressMetadata, portMetadata); } } ++step; return(current); }); }, () => { RestoreMediaConfiguration(changeLog); } ); }
public void GuarenteedNumberOfVideoEncoderInstancesMulticastReduced() { MediaConfigurationChangeLog changeLog = new MediaConfigurationChangeLog(); RunTest( () => { // list of used VEC tokens for RTP-Multicast streaming List <string> MulticastTokenList = new List <string>(); // list of used VSC tokens List <string> VscTokenList = new List <string>(); // lists of used ip addresses and ports for RTP-Multicast streaming List <int> usedMulticastPorts = new List <int>(); List <string> usedMulticastIPs = new List <string>(); MultipleStreamTestReduced(changeLog, (ref Profile profile) => { if (!VscTokenList.Contains(profile.VideoSourceConfiguration.token)) { VscTokenList.Add(profile.VideoSourceConfiguration.token); // we should clear this for every new Video Source Configuration if (0 != MulticastTokenList.Count) { MulticastTokenList.Clear(); } } StreamSetup streamSetup = new StreamSetup(); streamSetup.Transport = new Transport(); streamSetup.Transport.Protocol = TransportProtocol.UDP; streamSetup.Stream = StreamType.RTPMulticast; if (MulticastTokenList.Contains(profile.VideoEncoderConfiguration.token)) { profile = null; } else { MulticastTokenList.Add(profile.VideoEncoderConfiguration.token); string addressVideo = ""; int portVideo = 0; string addressAudio = ""; int portAudio = 0; string addressMetadata = ""; int portMetadata = 0; if (profile.VideoEncoderConfiguration != null) { addressVideo = GetMulticastAddress3(usedMulticastIPs); usedMulticastIPs.Add(addressVideo); portVideo = GetMulticastPort2(usedMulticastPorts); usedMulticastPorts.Add(portVideo); VideoEncoderConfiguration configCopy = Utils.CopyMaker.CreateCopy(profile.VideoEncoderConfiguration); changeLog.TrackModifiedConfiguration(configCopy); SetMulticast(profile.VideoEncoderConfiguration.Multicast, IPType.IPv4, addressVideo, portVideo); SetVideoEncoderConfiguration(profile.VideoEncoderConfiguration, false, true); } if (profile.AudioEncoderConfiguration != null) { addressAudio = GetMulticastAddress3(usedMulticastIPs); usedMulticastIPs.Add(addressAudio); portAudio = GetMulticastPort2(usedMulticastPorts); usedMulticastPorts.Add(portAudio); } if (profile.MetadataConfiguration != null) { addressMetadata = GetMulticastAddress3(usedMulticastIPs); usedMulticastIPs.Add(addressMetadata); portMetadata = GetMulticastPort2(usedMulticastPorts); usedMulticastPorts.Add(portMetadata); } SetMulticastSettings(profile, IPType.IPv4, changeLog, addressAudio, portAudio, addressVideo, portVideo, addressMetadata, portMetadata); } return(streamSetup); }); }, () => { RestoreMediaConfiguration(changeLog); } ); }
void SetResourcesUsageToMimimal(MediaConfigurationChangeLog changeLog, IEnumerable <Profile> profiles) { List <VideoEncoderConfiguration> modifiedConfigurations = new List <VideoEncoderConfiguration>(); // set resolutions and FPS to minimal values foreach (Profile profile in profiles) { // actually we change configurations // so we must track modified configurations and don't apply changes more than once VideoEncoderConfiguration AlreadyModifiedVec = null; AlreadyModifiedVec = modifiedConfigurations.Find(vec => null != profile.VideoEncoderConfiguration && vec.token == profile.VideoEncoderConfiguration.token); if (AlreadyModifiedVec != null) { profile.VideoEncoderConfiguration = AlreadyModifiedVec; continue; } if (null != profile.VideoEncoderConfiguration) { VideoEncoderConfigurationOptions options = GetVideoEncoderConfigurationOptions(profile.VideoEncoderConfiguration.token, null); #if true if (OptimizeVEC(changeLog, profile.VideoEncoderConfiguration, options)) { //SetVideoEncoderConfiguration(profile.VideoEncoderConfiguration, false); SetVideoEncoderConfiguration(Utils.CopyMaker.CreateCopy(profile.VideoEncoderConfiguration), false); modifiedConfigurations.Add(profile.VideoEncoderConfiguration); } #else VideoResolution[] resolutionsAvailable = null; IntRange fpsRange = null; switch (profile.VideoEncoderConfiguration.Encoding) { case VideoEncoding.JPEG: if (options.JPEG != null) { resolutionsAvailable = options.JPEG.ResolutionsAvailable; fpsRange = options.JPEG.FrameRateRange; } break; case VideoEncoding.H264: if (options.H264 != null) { resolutionsAvailable = options.H264.ResolutionsAvailable; fpsRange = options.H264.FrameRateRange; } break; case VideoEncoding.MPEG4: if (options.MPEG4 != null) { resolutionsAvailable = options.MPEG4.ResolutionsAvailable; fpsRange = options.MPEG4.FrameRateRange; } break; } VideoResolution minimalResolution = null; bool updateResolution = false; if (resolutionsAvailable != null) { VideoResolution currentResolution = profile.VideoEncoderConfiguration.Resolution; foreach (VideoResolution resolution in resolutionsAvailable) { if (minimalResolution == null) { minimalResolution = resolution; } else { if (minimalResolution.Height * minimalResolution.Width > resolution.Height * resolution.Width) { minimalResolution = resolution; } } } updateResolution = (minimalResolution.Width * minimalResolution.Height < currentResolution.Width * currentResolution.Height); } bool updateFps = false; if (fpsRange != null) { if (profile.VideoEncoderConfiguration.RateControl != null) { if (profile.VideoEncoderConfiguration.RateControl.FrameRateLimit > fpsRange.Min) { updateFps = true; } } else { updateFps = true; } } if (updateResolution || updateFps) { VideoEncoderConfiguration backup = Utils.CopyMaker.CreateCopy(profile.VideoEncoderConfiguration); changeLog.TrackModifiedConfiguration(backup); if (updateResolution) { profile.VideoEncoderConfiguration.Resolution = minimalResolution; } if (updateFps) { if (profile.VideoEncoderConfiguration.RateControl == null) { profile.VideoEncoderConfiguration.RateControl = new VideoRateControl(); } profile.VideoEncoderConfiguration.RateControl.FrameRateLimit = fpsRange.Min; } SetVideoEncoderConfiguration(profile.VideoEncoderConfiguration, false); modifiedConfigurations.Add(profile.VideoEncoderConfiguration); } #endif } } }