public void MethodsTest() { CMTime v, w, x, y; v = new CMTime(1, 2); w = new CMTime(1, 2); x = new CMTime(2, 1); y = new CMTime(2, 2); // equality operators Assert.That(v == w, "Equality #1"); Assert.That(!(v == x), "Equality #2"); Assert.That(v != x, "Inequality #1"); Assert.That(!(v != w), "Inequality #2"); Assert.That(CMTime.Compare(v, w), Is.EqualTo(0), "Compare #1"); Assert.That(CMTime.Compare(v, x) != 0, "Compare #2"); Assert.That(v.Equals(w), "Equals #1"); Assert.That(!x.Equals(v), "Equals #2"); // addition operator Assert.That(v + w == new CMTime(2, 2), "Addition #1"); Assert.That(CMTime.Add(v, w) == new CMTime(2, 2), "Addition #2"); // subtraction operator Assert.That(v - w == new CMTime(0, 2), "Subtraction #1"); Assert.That(CMTime.Subtract(v, w) == new CMTime(0, 2), "Subtraction #2"); // multiplication operators Assert.That(v * 2 == new CMTime(2, 2), "Multiplication * int, #1"); Assert.That(CMTime.Multiply(v, 3) == new CMTime(3, 2), "Multiplication * int, #2"); Assert.That(v * 4.0 == new CMTime(4, 2), "Multiplication * double, #1"); Assert.That(CMTime.Multiply(v, 5.0) == new CMTime(5, 2), "Multiplication * double, #2"); // ConvertScale Assert.That(new CMTime(10, 2).ConvertScale(1, CMTimeRoundingMethod.Default) == new CMTime(5, 1), "ConvertScale #1"); // FromSeconds Assert.That(CMTime.FromSeconds(20, 1) == new CMTime(20, 1), "FromSeconds #1"); // GetMaximum Assert.That(CMTime.GetMaximum(v, y) == y, "GetMaximum #1"); // GetMinimum Assert.That(CMTime.GetMinimum(v, y) == v, "GetMinimum #1"); #if XAMCORE_2_0 using (var d = x.ToDictionary()) { Assert.That(d.RetainCount, Is.EqualTo((nint)1), "RetainCount"); Assert.That(d.Count, Is.EqualTo((nuint)4), "Count"); var time = CMTime.FromDictionary(d); Assert.That(time, Is.EqualTo(x), "FromDictionary"); } #endif }
public double HorizontalPositionForTime(CMTime time) { double seconds = 0.0; if (CMTime.Compare(time, CMTime.Zero) == 1) { seconds = time.Seconds; } return(seconds * scaledDurationToWidth + LeftInsetToMatchTimeSlider + LeftMarginInset); }
private void ProcessVideoComposition(AVMutableVideoComposition videoComposition) { var stages = new List <APLVideoCompositionStageInfo> (); foreach (AVVideoCompositionInstruction instruction in videoComposition.Instructions) { var stage = new APLVideoCompositionStageInfo(); stage.TimeRange = instruction.TimeRange; var rampsDictionary = new Dictionary <string, List <CGPoint> > (); var layerNames = new List <string> (); foreach (AVVideoCompositionLayerInstruction layerInstruction in instruction.LayerInstructions) { var ramp = new List <CGPoint> (); CMTime startTime = CMTime.Zero; float startOpacity = 1f; float endOpacity = 1f; CMTimeRange timeRange = new CMTimeRange(); while (layerInstruction.GetOpacityRamp(startTime, ref startOpacity, ref endOpacity, ref timeRange)) { if (CMTime.Compare(startTime, CMTime.Zero) == 0 && CMTime.Compare(timeRange.Start, CMTime.Zero) == 1) { ramp.Add(new CGPoint((float)timeRange.Start.Seconds, startOpacity)); } CMTime endTime = CMTime.Add(timeRange.Start, timeRange.Duration); ramp.Add(new CGPoint((float)endTime.Seconds, endOpacity)); startTime = CMTime.Add(timeRange.Start, timeRange.Duration); } NSString name = new NSString(layerInstruction.TrackID.ToString()); layerNames.Add(name); rampsDictionary [name] = ramp; } if (layerNames.Count > 1) { stage.OpacityRamps = rampsDictionary; } stage.LayerNames = layerNames; stages.Add(stage); } videoCompositionStages = stages; }
public void CalculateFramerateAtTimestamp(CMTime timeStamp) { previousSecondTimestamps.Add(timeStamp); var oneSecond = CMTime.FromSeconds(1, 1); var oneSecondAgo = CMTime.Subtract(timeStamp, oneSecond); while (previousSecondTimestamps.Count > 0 && CMTime.Compare(previousSecondTimestamps[0], oneSecondAgo) < 0) { previousSecondTimestamps.RemoveAt(0); } double newRate = Convert.ToDouble(previousSecondTimestamps.Count); VideoFrameRate = (VideoFrameRate + newRate) / 2; }
private void ProcessAudioMix(AVMutableAudioMix audioMix) { var mixTracks = new List <List <CGPoint> > (); foreach (AVAudioMixInputParameters input in audioMix.InputParameters) { List <CGPoint> ramp = new List <CGPoint> (); CMTime startTime = CMTime.Zero; float startVolume = 1f; float endVolume = 1f; CMTimeRange timeRange = new CMTimeRange(); while (input.GetVolumeRamp(startTime, ref startVolume, ref endVolume, ref timeRange)) { if (CMTime.Compare(startTime, CMTime.Zero) == 0 && CMTime.Compare(timeRange.Start, CMTime.Zero) == 1) { ramp.Add(new CGPoint(0f, 1f)); ramp.Add(new CGPoint((float)timeRange.Start.Seconds, startVolume)); } ramp.Add(new CGPoint((float)timeRange.Start.Seconds, startVolume)); CMTime endTime = CMTime.Add(timeRange.Start, timeRange.Duration); ramp.Add(new CGPoint((float)endTime.Seconds, endVolume)); startTime = CMTime.Add(timeRange.Start, timeRange.Duration); } if (CMTime.Compare(startTime, duration) == -1) { ramp.Add(new CGPoint((float)duration.Seconds, endVolume)); } mixTracks.Add(ramp); } audioMixTracks = mixTracks; }