public void PipelineGraphCanDetectCycles() { // create graph AnonymousNode node0 = new AnonymousNode() { Name = "node0" }; AnonymousNode node1 = new AnonymousNode(node0) { Name = "node1" }; AnonymousNode node2 = new AnonymousNode(node1) { Name = "node2" }; AnonymousNode node3 = new AnonymousNode(node2) { Name = "node3" }; PipelineGraph graph = new PipelineGraph { Nodes = { node0, node1, node2, node3 } }; Assert.Equal(false, graph.AddEdge(node3.Outputs[0], node1.Inputs[0])); Assert.Equal(true, graph.AddEdge(node2.Outputs[0], node3.Inputs[0])); }
public void RedrawOnTickSetBack() { // Add Input Node for DiagramNode with 3 Outputs. AnonymousNode sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); Frame[] inputs = sourceNode.Process(null, 0); // Generate DiagramNode and add referencevideo. Node.Input reference = new Node.Input(); reference.Source = sourceNode.Outputs[0]; DiagramNode diaNode = new DiagramNode(); diaNode.ReferenceVideo = reference; diaNode.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. Node.Input video = new Node.Input(); video.Source = sourceNode.Outputs[1]; diaNode.Inputs.Add(video); // Generate sample GraphType to DiagramGraph. DiagramGraph pixDiff = new DiagramGraph(); pixDiff.Video = video; pixDiff.Type = new PixelDiff(); diaNode.Graphs.Add(pixDiff); diaNode.Process(inputs, 0); diaNode.Process(inputs, 1); Assert.Equal(diaNode.Graphs[0].Data.Count, 2); diaNode.Process(inputs, 0); Assert.Equal(diaNode.Graphs[0].Data.Count, 1); }
public void TestNoDrawingIfDiagramNodeNotEnabled() { // Add Input Node for DiagramNode with 3 Outputs. AnonymousNode sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); Frame[] inputs = sourceNode.Process(null, 0); // Generate DiagramNode and add referencevideo. Node.Input reference = new Node.Input(); reference.Source = sourceNode.Outputs[0]; DiagramNode diaNode = new DiagramNode(); diaNode.ReferenceVideo = reference; diaNode.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. Node.Input video = new Node.Input(); video.Source = sourceNode.Outputs[1]; diaNode.Inputs.Add(video); // Generate sample GraphType to DiagramGraph. DiagramGraph pixDiff = new DiagramGraph(); pixDiff.Video = video; pixDiff.Type = new PixelDiff(); diaNode.Graphs.Add(pixDiff); diaNode.IsEnabled = false; diaNode.Process(inputs, 0); Assert.Empty(diaNode.Graphs[0].Data); }
public void DfsFindsCorrectNodes() { // create graph AnonymousNode node0 = new AnonymousNode() { Name = "node0" }; AnonymousNode node1 = new AnonymousNode() { Name = "node1" }; AnonymousNode node2 = new AnonymousNode(node0) { Name = "node2" }; AnonymousNode node3 = new AnonymousNode(node0, node1) { Name = "node3" }; AnonymousNode node4 = new AnonymousNode(node3) { Name = "node4" }; PipelineGraph graph = new PipelineGraph { Nodes = { node0, node1, node2, node3, node4 } }; Assert.Contains <Node>(node0, graph.DepthFirstSearch(node4)); Assert.Contains <Node>(node1, graph.DepthFirstSearch(node4)); Assert.DoesNotContain <Node>(node2, graph.DepthFirstSearch(node4)); Assert.DoesNotContain <Node>(node4, graph.DepthFirstSearch(node3)); }
public void RenderTicksPropagatesExceptions() { Node graph = new AnonymousNode(() => { throw new InvalidOperationException("trololo"); }); var ex = Assert.Throws <AggregateException>(() => new PipelineDriver().RenderTicks(new[] { graph }).Last()); ex = ex.Flatten(); Assert.True(ex.Flatten().InnerExceptions.All(e => e.Message == "trololo")); }
public void RenderTicksClosesObservable() { var cts = new CancellationTokenSource(); Node graph = new AnonymousNode(() => { cts.Cancel(); cts.Token.ThrowIfCancellationRequested(); }); Assert.Equal(0, new PipelineDriver().RenderTicks(new[] { graph }, token: cts.Token).Count().Last()); GC.Collect(); GC.WaitForPendingFinalizers(); }
public void RenderTicksEarlyCancellation() { var tokenSource = new CancellationTokenSource(); Node graph = new AnonymousNode( () => { throw new InvalidOperationException(); }, new AnonymousNode(() => tokenSource.Cancel()) ); Assert.Equal(0, new PipelineDriver().RenderTicks(new[] { graph }, token: tokenSource.Token).Count().Last()); // Looks like the InvalidOperationException hasn't been thrown. Yay! }
public void PipelineGraphCanDetectCycles() { // create graph AnonymousNode node0 = new AnonymousNode() { Name = "node0" }; AnonymousNode node1 = new AnonymousNode(node0) { Name = "node1" }; AnonymousNode node2 = new AnonymousNode(node1) { Name = "node2" }; AnonymousNode node3 = new AnonymousNode(node2) { Name = "node3" }; PipelineGraph graph = new PipelineGraph { Nodes = { node0, node1, node2, node3 } }; Assert.Equal(false, graph.AddEdge(node3.Outputs[0], node1.Inputs[0])); Assert.Equal(true, graph.AddEdge(node2.Outputs[0], node3.Inputs[0])); }
public void RenderTicksPropagatesRetardedExceptions() { var tick = 0; Node graph = new AnonymousNode(() => { if (tick++ == 50) { Thread.Sleep(1000); throw new InvalidOperationException("trololo"); } }); var ex = Assert.Throws <AggregateException>(() => new PipelineDriver().RenderTicks(new[] { graph }).Last()); Assert.True(ex.Flatten().InnerExceptions.All(e => e.Message == "trololo")); }
public void TestReturnNumberOfFramesToPrecompute() { // create graph AnonymousNode node0 = new AnonymousNode() { Name = "node0" }; AnonymousNode node1 = new AnonymousNode() { Name = "node1" }; AnonymousNode node2 = new AnonymousNode(node0) { Name = "node2" }; AnonymousNode node3 = new AnonymousNode(node0, node1) { Name = "node3" }; AnonymousNode node4 = new AnonymousNode(node3) { Name = "node4" }; PipelineGraph graph = new PipelineGraph { Nodes = { node0, node1, node2, node3, node4 } }; //set number of frames to precompute in the graph's nodes node0.SettableNumberOfFramesToPrecompute = 0; node1.SettableNumberOfFramesToPrecompute = 1; node2.SettableNumberOfFramesToPrecompute = 2; node3.SettableNumberOfFramesToPrecompute = 4; node4.SettableNumberOfFramesToPrecompute = 8; List <AnonymousNode> nodeList = new List <AnonymousNode>(); nodeList.Add(node0); Assert.Equal(0, graph.NumberOfTicksToPrecompute(nodeList)); nodeList.Add(node1); Assert.Equal(1, graph.NumberOfTicksToPrecompute(nodeList)); nodeList.Add(node2); Assert.Equal(2, graph.NumberOfTicksToPrecompute(nodeList)); nodeList.Add(node3); Assert.Equal(5, graph.NumberOfTicksToPrecompute(nodeList)); nodeList.Add(node4); Assert.Equal(13, graph.NumberOfTicksToPrecompute(nodeList)); }
public void RenderTicksNonReentrant() { var driver = new PipelineDriver(); bool firstInvocationCompleted = false; Node graph1 = new AnonymousNode(() => Assert.True(firstInvocationCompleted)); Task task = null; Node graph0 = new AnonymousNode(() => { task = driver.RenderTicks(new[] { graph1 }, tickCount: 1).ToTask(); Thread.Sleep(1000); firstInvocationCompleted = true; }); driver.RenderTicks(new[] { graph0 }).First(); task.Wait(); }
public void DfsFindsCorrectNodes() { // create graph AnonymousNode node0 = new AnonymousNode() { Name = "node0" }; AnonymousNode node1 = new AnonymousNode() { Name = "node1" }; AnonymousNode node2 = new AnonymousNode(node0) { Name = "node2" }; AnonymousNode node3 = new AnonymousNode(node0, node1) { Name = "node3" }; AnonymousNode node4 = new AnonymousNode(node3) { Name = "node4" }; PipelineGraph graph = new PipelineGraph { Nodes = { node0, node1, node2, node3, node4 } }; Assert.Contains<Node>(node0, graph.DepthFirstSearch(node4)); Assert.Contains<Node>(node1, graph.DepthFirstSearch(node4)); Assert.DoesNotContain<Node>(node2, graph.DepthFirstSearch(node4)); Assert.DoesNotContain<Node>(node4, graph.DepthFirstSearch(node3)); }
public void TestRemoveNode() { // create graph AnonymousNode node0 = new AnonymousNode() { Name = "node0" }; AnonymousNode node1 = new AnonymousNode() { Name = "node1" }; AnonymousNode node2 = new AnonymousNode(node0, node1) { Name = "node2" }; AnonymousNode node3 = new AnonymousNode(node2) { Name = "node3" }; AnonymousNode node4 = new AnonymousNode(node2) { Name = "node4" }; PipelineGraph graph = new PipelineGraph { Nodes = { node0, node1, node2, node3, node4 } }; graph.RemoveNode(node2); foreach (Node.Input input in node3.Inputs) { Assert.Equal(null, input.Source); } foreach (Node.Input input in node4.Inputs) { Assert.Equal(null, input.Source); } }
public void TestRemoveNode() { // create graph AnonymousNode node0 = new AnonymousNode() { Name = "node0" }; AnonymousNode node1 = new AnonymousNode() { Name = "node1" }; AnonymousNode node2 = new AnonymousNode(node0, node1) { Name = "node2" }; AnonymousNode node3 = new AnonymousNode(node2) { Name = "node3" }; AnonymousNode node4 = new AnonymousNode(node2) { Name = "node4" }; PipelineGraph graph = new PipelineGraph { Nodes = { node0, node1, node2, node3, node4 } }; graph.RemoveNode(node2); foreach (Node.Input input in node3.Inputs) { Assert.Equal(null, input.Source); } foreach (Node.Input input in node4.Inputs) { Assert.Equal(null, input.Source); } }
public void TestNoDrawingIfDiagramNodeNotEnabled() { // Add Input Node for DiagramNode with 3 Outputs. AnonymousNode sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); Frame[] inputs = sourceNode.Process(null, 0); // Generate DiagramNode and add referencevideo. Node.Input reference = new Node.Input(); reference.Source = sourceNode.Outputs[0]; DiagramNode diaNode = new DiagramNode(); diaNode.ReferenceVideo = reference; diaNode.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. Node.Input video = new Node.Input(); video.Source = sourceNode.Outputs[1]; diaNode.Inputs.Add(video); // Generate sample GraphType to DiagramGraph. DiagramGraph pixDiff = new DiagramGraph(); pixDiff.Video = video; pixDiff.Type = new PixelDiff(); diaNode.Graphs.Add(pixDiff); diaNode.IsEnabled = false; diaNode.Process(inputs, 0); Assert.Empty(diaNode.Graphs[0].Data); }
public void TestDiagramNode() { // Add Input Node for DiagramNode with 3 Outputs. AnonymousNode sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); Frame[] inputs = sourceNode.Process(null, 0); // Generate DiagramNode and add referencevideo. Node.Input reference = new Node.Input(); reference.Source = sourceNode.Outputs[0]; DiagramNode diaNode = new DiagramNode(); diaNode.ReferenceVideo = reference; diaNode.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. Node.Input video = new Node.Input(); video.Source = sourceNode.Outputs[1]; diaNode.Inputs.Add(video); Node.Input annVid = new Node.Input(); annVid.Source = sourceNode.Outputs[2]; diaNode.Inputs.Add(annVid); // Generate and add all GraphTypes to DiagramGraph once. DiagramGraph pixDiff = new DiagramGraph(); pixDiff.Video = video; pixDiff.Type = new PixelDiff(); DiagramGraph pseudoNoiseRatio = new DiagramGraph(); pseudoNoiseRatio.Video = video; pseudoNoiseRatio.Type = new PeakSignalNoiseRatio(); DiagramGraph inBlFreq = new DiagramGraph(); inBlFreq.Video = annVid; inBlFreq.Type = new IntraBlockFrequency(); DiagramGraph decDiff = new DiagramGraph(); decDiff.Video = annVid; decDiff.Type = new DecisionDiff(); DiagramGraph art = new DiagramGraph(); art.Video = video; art.Type = new Artifacts(); diaNode.Graphs.Add(pixDiff); diaNode.Graphs.Add(pseudoNoiseRatio); diaNode.Graphs.Add(inBlFreq); diaNode.Graphs.Add(decDiff); diaNode.Graphs.Add(art); diaNode.Process(inputs, 0); // Calculate expected results independently from DiagramGraph methods. double mse = 0.0; double pixDifference = 0.0; double intrablocks = 0.0; double artifacts = 0.0; for (int x = 0; x < inputs[0].Size.Width; x++) { for (int y = 0; y < inputs[0].Size.Height; y++) { pixDifference += Math.Abs(inputs[0][x, y].R - inputs[1][x, y].R) + Math.Abs(inputs[0][x, y].G - inputs[1][x, y].G) + Math.Abs(inputs[0][x, y].B - inputs[1][x, y].B); mse += Math.Pow(((inputs[0][x, y].R + inputs[0][x, y].G + inputs[0][x, y].B) - (inputs[1][x, y].R + inputs[1][x, y].G + inputs[1][x, y].B)), 2); var difference = Math.Abs(inputs[0][x, y].R - inputs[1].GetPixelOrBlack(x, y).R); difference += Math.Abs(inputs[0][x, y].G - inputs[1].GetPixelOrBlack(x, y).G); difference += Math.Abs(inputs[0][x, y].B - inputs[1].GetPixelOrBlack(x, y).B); if (difference >= 40) artifacts += 1; } } foreach (MacroblockDecision d in ((AnnotatedFrame)inputs[2]).Decisions) { if (d.PartitioningDecision == MacroblockPartitioning.Intra16x16 | d.PartitioningDecision == MacroblockPartitioning.Intra4x4 | d.PartitioningDecision == MacroblockPartitioning.Intra8x8 | d.PartitioningDecision == MacroblockPartitioning.IntraPCM) { intrablocks++; } } double decDifference = 0.0; if (((AnnotatedFrame)inputs[0]) is AnnotatedFrame && ((AnnotatedFrame)inputs[2]) is AnnotatedFrame && ((AnnotatedFrame)inputs[0]).Size.Height == ((AnnotatedFrame)inputs[2]).Size.Height && ((AnnotatedFrame)inputs[0]).Size.Width == ((AnnotatedFrame)inputs[2]).Size.Width) { AnnotatedFrame annFrame = ((AnnotatedFrame)inputs[0]); AnnotatedFrame annRef = ((AnnotatedFrame)inputs[2]); for (int i = 0; i < annFrame.Decisions.GetLength(0); i++) { for (int j = 0; j < annFrame.Decisions.GetLength(1); j++) { if (annFrame.Decisions[i, j].PartitioningDecision == annRef.Decisions[i, j].PartitioningDecision) decDifference++; } } decDifference /= annFrame.Decisions.Length; decDifference *= 100; } intrablocks = 100 * intrablocks / ((AnnotatedFrame) inputs[2]).Decisions.Length; pixDifference = 100 * pixDifference / (765 * inputs[0].Size.Height * inputs[0].Size.Width); mse *= (double)1 / (3 * inputs[1].Size.Height * inputs[1].Size.Width); double psnr; if (mse == 0.0) psnr = 0.0; psnr = 10 * Math.Log10((Math.Pow((Math.Pow(2, 24) - 1), 2)) / mse); artifacts = 100 * artifacts / (inputs[0].Size.Height * inputs[0].Size.Width); Assert.Equal(pixDifference, diaNode.Graphs[0].Data[0].Value); Assert.Equal(psnr, diaNode.Graphs[1].Data[0].Value); Assert.Equal(intrablocks, diaNode.Graphs[2].Data[0].Value, 7); Assert.Equal(decDifference, diaNode.Graphs[3].Data[0].Value, 7); Assert.Equal(artifacts, diaNode.Graphs[4].Data[0].Value, 7); }
public void TestDiagramNode() { // Add Input Node for DiagramNode with 3 Outputs. AnonymousNode sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); Frame[] inputs = sourceNode.Process(null, 0); // Generate DiagramNode and add referencevideo. Node.Input reference = new Node.Input(); reference.Source = sourceNode.Outputs[0]; DiagramNode diaNode = new DiagramNode(); diaNode.ReferenceVideo = reference; diaNode.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. Node.Input video = new Node.Input(); video.Source = sourceNode.Outputs[1]; diaNode.Inputs.Add(video); Node.Input annVid = new Node.Input(); annVid.Source = sourceNode.Outputs[2]; diaNode.Inputs.Add(annVid); // Generate and add all GraphTypes to DiagramGraph once. DiagramGraph pixDiff = new DiagramGraph(); pixDiff.Video = video; pixDiff.Type = new PixelDiff(); DiagramGraph pseudoNoiseRatio = new DiagramGraph(); pseudoNoiseRatio.Video = video; pseudoNoiseRatio.Type = new PeakSignalNoiseRatio(); DiagramGraph inBlFreq = new DiagramGraph(); inBlFreq.Video = annVid; inBlFreq.Type = new IntraBlockFrequency(); DiagramGraph decDiff = new DiagramGraph(); decDiff.Video = annVid; decDiff.Type = new DecisionDiff(); DiagramGraph art = new DiagramGraph(); art.Video = video; art.Type = new Artifacts(); diaNode.Graphs.Add(pixDiff); diaNode.Graphs.Add(pseudoNoiseRatio); diaNode.Graphs.Add(inBlFreq); diaNode.Graphs.Add(decDiff); diaNode.Graphs.Add(art); diaNode.Process(inputs, 0); // Calculate expected results independently from DiagramGraph methods. double mse = 0.0; double pixDifference = 0.0; double intrablocks = 0.0; double artifacts = 0.0; for (int x = 0; x < inputs[0].Size.Width; x++) { for (int y = 0; y < inputs[0].Size.Height; y++) { pixDifference += Math.Abs(inputs[0][x, y].R - inputs[1][x, y].R) + Math.Abs(inputs[0][x, y].G - inputs[1][x, y].G) + Math.Abs(inputs[0][x, y].B - inputs[1][x, y].B); mse += Math.Pow(((inputs[0][x, y].R + inputs[0][x, y].G + inputs[0][x, y].B) - (inputs[1][x, y].R + inputs[1][x, y].G + inputs[1][x, y].B)), 2); var difference = Math.Abs(inputs[0][x, y].R - inputs[1].GetPixelOrBlack(x, y).R); difference += Math.Abs(inputs[0][x, y].G - inputs[1].GetPixelOrBlack(x, y).G); difference += Math.Abs(inputs[0][x, y].B - inputs[1].GetPixelOrBlack(x, y).B); if (difference >= 40) { artifacts += 1; } } } foreach (MacroblockDecision d in ((AnnotatedFrame)inputs[2]).Decisions) { if (d.PartitioningDecision == MacroblockPartitioning.Intra16x16 | d.PartitioningDecision == MacroblockPartitioning.Intra4x4 | d.PartitioningDecision == MacroblockPartitioning.Intra8x8 | d.PartitioningDecision == MacroblockPartitioning.IntraPCM) { intrablocks++; } } double decDifference = 0.0; if (((AnnotatedFrame)inputs[0]) is AnnotatedFrame && ((AnnotatedFrame)inputs[2]) is AnnotatedFrame && ((AnnotatedFrame)inputs[0]).Size.Height == ((AnnotatedFrame)inputs[2]).Size.Height && ((AnnotatedFrame)inputs[0]).Size.Width == ((AnnotatedFrame)inputs[2]).Size.Width) { AnnotatedFrame annFrame = ((AnnotatedFrame)inputs[0]); AnnotatedFrame annRef = ((AnnotatedFrame)inputs[2]); for (int i = 0; i < annFrame.Decisions.GetLength(0); i++) { for (int j = 0; j < annFrame.Decisions.GetLength(1); j++) { if (annFrame.Decisions[i, j].PartitioningDecision == annRef.Decisions[i, j].PartitioningDecision) { decDifference++; } } } decDifference /= annFrame.Decisions.Length; decDifference *= 100; } intrablocks = 100 * intrablocks / ((AnnotatedFrame)inputs[2]).Decisions.Length; pixDifference = 100 * pixDifference / (765 * inputs[0].Size.Height * inputs[0].Size.Width); mse *= (double)1 / (3 * inputs[1].Size.Height * inputs[1].Size.Width); double psnr; if (mse == 0.0) { psnr = 0.0; } psnr = 10 * Math.Log10((Math.Pow((Math.Pow(2, 24) - 1), 2)) / mse); artifacts = 100 * artifacts / (inputs[0].Size.Height * inputs[0].Size.Width); Assert.Equal(pixDifference, diaNode.Graphs[0].Data[0].Value); Assert.Equal(psnr, diaNode.Graphs[1].Data[0].Value); Assert.Equal(intrablocks, diaNode.Graphs[2].Data[0].Value, 7); Assert.Equal(decDifference, diaNode.Graphs[3].Data[0].Value, 7); Assert.Equal(artifacts, diaNode.Graphs[4].Data[0].Value, 7); }
public void RedrawOnTickSetBack() { // Add Input Node for DiagramNode with 3 Outputs. AnonymousNode sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3); Frame[] inputs = sourceNode.Process(null, 0); // Generate DiagramNode and add referencevideo. Node.Input reference = new Node.Input(); reference.Source = sourceNode.Outputs[0]; DiagramNode diaNode = new DiagramNode(); diaNode.ReferenceVideo = reference; diaNode.Inputs.Add(reference); // Add other Outputs as Inputs to DiagramNode. Node.Input video = new Node.Input(); video.Source = sourceNode.Outputs[1]; diaNode.Inputs.Add(video); // Generate sample GraphType to DiagramGraph. DiagramGraph pixDiff = new DiagramGraph(); pixDiff.Video = video; pixDiff.Type = new PixelDiff(); diaNode.Graphs.Add(pixDiff); diaNode.Process(inputs, 0); diaNode.Process(inputs, 1); Assert.Equal(diaNode.Graphs[0].Data.Count, 2); diaNode.Process(inputs, 0); Assert.Equal(diaNode.Graphs[0].Data.Count, 1); }
public void TestReturnNumberOfFramesToPrecompute() { // create graph AnonymousNode node0 = new AnonymousNode() { Name = "node0" }; AnonymousNode node1 = new AnonymousNode() { Name = "node1" }; AnonymousNode node2 = new AnonymousNode(node0) { Name = "node2" }; AnonymousNode node3 = new AnonymousNode(node0, node1) { Name = "node3" }; AnonymousNode node4 = new AnonymousNode(node3) { Name = "node4" }; PipelineGraph graph = new PipelineGraph { Nodes = { node0, node1, node2, node3, node4 } }; //set number of frames to precompute in the graph's nodes node0.SettableNumberOfFramesToPrecompute = 0; node1.SettableNumberOfFramesToPrecompute = 1; node2.SettableNumberOfFramesToPrecompute = 2; node3.SettableNumberOfFramesToPrecompute = 4; node4.SettableNumberOfFramesToPrecompute = 8; List<AnonymousNode> nodeList = new List<AnonymousNode>(); nodeList.Add(node0); Assert.Equal(0, graph.NumberOfTicksToPrecompute(nodeList)); nodeList.Add(node1); Assert.Equal(1, graph.NumberOfTicksToPrecompute(nodeList)); nodeList.Add(node2); Assert.Equal(2, graph.NumberOfTicksToPrecompute(nodeList)); nodeList.Add(node3); Assert.Equal(5, graph.NumberOfTicksToPrecompute(nodeList)); nodeList.Add(node4); Assert.Equal(13, graph.NumberOfTicksToPrecompute(nodeList)); }