Exemplo n.º 1
0
        public void SetInvalidateCallback_Null()
        {
            using (var pixelBuffer = new CVPixelBuffer(20, 10, CVPixelFormatType.CV24RGB)) {
                CMFormatDescriptionError fde;
                using (var desc = CMVideoFormatDescription.CreateForImageBuffer(pixelBuffer, out fde)) {
                    var sampleTiming = new CMSampleTimingInfo();
                    CMSampleBufferError sbe;
                    using (var sb = CMSampleBuffer.CreateForImageBuffer(pixelBuffer, true, desc, sampleTiming, out sbe)) {
                        // ignore `null`, i.e. no crash
                        Assert.That(sb.SetInvalidateCallback(null), Is.EqualTo(CMSampleBufferError.None), "null");

                        int i      = 0;
                        var result = sb.SetInvalidateCallback(delegate(CMSampleBuffer buffer) {
                            i++;
                            Assert.AreSame(buffer, sb, "same");
                        });
                        Assert.That(result, Is.EqualTo(CMSampleBufferError.None), "SetInvalidateCallback/None");

                        // we can reset (nullify) the callback
                        Assert.That(sb.SetInvalidateCallback(null), Is.EqualTo(CMSampleBufferError.None), "null-2");

                        result = (CMSampleBufferError)sb.Invalidate();
                        Assert.That(result, Is.EqualTo(CMSampleBufferError.None), "Invalidate/None");
                        Assert.That(i, Is.EqualTo(0), "0");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void SetInvalidateCallback()
        {
            using (var pixelBuffer = new CVPixelBuffer(20, 10, CVPixelFormatType.CV24RGB)) {
                CMFormatDescriptionError fde;
                using (var desc = CMVideoFormatDescription.CreateForImageBuffer(pixelBuffer, out fde)) {
                    var sampleTiming = new CMSampleTimingInfo();
                    CMSampleBufferError sbe;
                    using (var sb = CMSampleBuffer.CreateForImageBuffer(pixelBuffer, true, desc, sampleTiming, out sbe)) {
                        int i      = 0;
                        var result = sb.SetInvalidateCallback(delegate(CMSampleBuffer buffer) {
                            i++;
                            Assert.AreSame(buffer, sb, "same");
                        });
                        Assert.That(result, Is.EqualTo(CMSampleBufferError.None), "SetInvalidateCallback/None");

                        result = (CMSampleBufferError)sb.Invalidate();
                        Assert.That(result, Is.EqualTo(CMSampleBufferError.None), "Invalidate/None");
                        Assert.That(i, Is.EqualTo(1), "1");

                        // a second call to Invalidate returns Invalidated
                        result = (CMSampleBufferError)sb.Invalidate();
                        Assert.That(result, Is.EqualTo(CMSampleBufferError.Invalidated), "Invalidated");
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void SetInvalidateCallback_Replace()
        {
            using (var pixelBuffer = new CVPixelBuffer(20, 10, CVPixelFormatType.CV24RGB)) {
                CMFormatDescriptionError fde;
                using (var desc = CMVideoFormatDescription.CreateForImageBuffer(pixelBuffer, out fde)) {
                    var sampleTiming = new CMSampleTimingInfo();
                    CMSampleBufferError sbe;
                    using (var sb = CMSampleBuffer.CreateForImageBuffer(pixelBuffer, true, desc, sampleTiming, out sbe)) {
                        int i      = 0;
                        var result = sb.SetInvalidateCallback(delegate(CMSampleBuffer buffer) {
                            i++;
                        });

                        // we cannot replace the (native) callback without getting an error (so we should not replace
                        // the managed one either, that would be confusing and make it hard to port code)
                        result = sb.SetInvalidateCallback(delegate(CMSampleBuffer buffer) {
                            i--;
                            Assert.AreSame(buffer, sb, "same");
                        });
                        Assert.That(result, Is.EqualTo(CMSampleBufferError.RequiredParameterMissing), "RequiredParameterMissing");

                        sb.Invalidate();
                        Assert.That(i, Is.EqualTo(1), "1");
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void CreateForImageBuffer()
        {
            var pixelBuffer = new CVPixelBuffer(20, 10, CVPixelFormatType.CV24RGB);

            CMFormatDescriptionError fde;
            var desc = CMVideoFormatDescription.CreateForImageBuffer(pixelBuffer, out fde);

            var sampleTiming = new CMSampleTimingInfo();

            CMSampleBufferError sbe;
            var sb = CMSampleBuffer.CreateForImageBuffer(pixelBuffer, true, desc, sampleTiming, out sbe);

            Assert.IsNotNull(sb, "#1");
            Assert.AreEqual(CMSampleBufferError.None, sbe, "#2");
        }
Exemplo n.º 5
0
        public void CreateReadyWithImageBuffer_ArrayValidations()
        {
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 8, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 10, throwIfOtherPlatform: false);

            CMFormatDescriptionError fde;

            using (var pixelBuffer = new CVPixelBuffer(20, 10, CVPixelFormatType.CV24RGB))
                using (var desc = CMVideoFormatDescription.CreateForImageBuffer(pixelBuffer, out fde)) {
                    CMSampleBufferError sbe;
                    Assert.Throws <ArgumentNullException> (() => CMSampleBuffer.CreateReadyWithImageBuffer(pixelBuffer, desc, null, out sbe), "null");

                    var stia = new CMSampleTimingInfo [0];
                    Assert.Throws <ArgumentException> (() => CMSampleBuffer.CreateReadyWithImageBuffer(pixelBuffer, desc, stia, out sbe), "empty");
                }
        }
Exemplo n.º 6
0
        public void CreateReadyWithImageBuffer()
        {
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 8, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 10, throwIfOtherPlatform: false);

            CMFormatDescriptionError fde;

            using (var pixelBuffer = new CVPixelBuffer(20, 10, CVPixelFormatType.CV24RGB))
                using (var desc = CMVideoFormatDescription.CreateForImageBuffer(pixelBuffer, out fde)) {
                    CMSampleBufferError sbe;
                    using (var sb = CMSampleBuffer.CreateReadyWithImageBuffer(pixelBuffer, desc, new CMSampleTimingInfo [0], out sbe)) {
                        Assert.That(sb.Handle, Is.Not.EqualTo(IntPtr.Zero), "CMSampleBuffer");
                        Assert.That(sbe, Is.EqualTo(CMSampleBufferError.None), "CMSampleBufferError");
                    }
                }
        }
Exemplo n.º 7
0
        public void CreateReadyWithImageBuffer()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(8, 0))
            {
                Assert.Inconclusive("Requires iOS8");
            }

            CMFormatDescriptionError fde;

            using (var pixelBuffer = new CVPixelBuffer(20, 10, CVPixelFormatType.CV24RGB))
                using (var desc = CMVideoFormatDescription.CreateForImageBuffer(pixelBuffer, out fde)) {
                    CMSampleBufferError sbe;
                    using (var sb = CMSampleBuffer.CreateReadyWithImageBuffer(pixelBuffer, desc, new CMSampleTimingInfo [0], out sbe)) {
                        Assert.That(sb.Handle, Is.Not.EqualTo(IntPtr.Zero), "CMSampleBuffer");
                        Assert.That(sbe, Is.EqualTo(CMSampleBufferError.None), "CMSampleBufferError");
                    }
                }
        }
Exemplo n.º 8
0
        protected ICMAttachmentBearer GetInstance(Type t)
        {
            if (!CMAttachmentInterfaceType.IsAssignableFrom(t))
            {
                throw new ArgumentException("t");
            }
            switch (t.Name)
            {
            case "CMBlockBuffer":
                CMBlockBufferError bbe;
                var result = CMBlockBuffer.CreateEmpty(0, CMBlockBufferFlags.AssureMemoryNow, out bbe);
                if (bbe == CMBlockBufferError.None)
                {
                    return(result);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Could not create the new instance {0}.", bbe.ToString()));
                }

            case "CMSampleBuffer":
                var pixelBuffer = new CVPixelBuffer(20, 10, CVPixelFormatType.CV24RGB);

                CMFormatDescriptionError fde;
                var desc = CMVideoFormatDescription.CreateForImageBuffer(pixelBuffer, out fde);

                var sampleTiming = new CMSampleTimingInfo();

                CMSampleBufferError sbe;
                var sb = CMSampleBuffer.CreateForImageBuffer(pixelBuffer, true, desc, sampleTiming, out sbe);
                if (sbe == CMSampleBufferError.None)
                {
                    return(sb);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Could not create the new instance {0}.", sbe.ToString()));
                }

            default:
                throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));
            }
        }
Exemplo n.º 9
0
        public void CallForEachSample()
        {
            using (var pixelBuffer = new CVPixelBuffer(20, 10, CVPixelFormatType.CV24RGB)) {
                CMFormatDescriptionError fde;
                using (var desc = CMVideoFormatDescription.CreateForImageBuffer(pixelBuffer, out fde)) {
                    var sampleTiming = new CMSampleTimingInfo();
                    CMSampleBufferError sbe;
                    using (var sb = CMSampleBuffer.CreateForImageBuffer(pixelBuffer, true, desc, sampleTiming, out sbe)) {
                        int i      = 0;
                        var result = sb.CallForEachSample(delegate(CMSampleBuffer buffer, int index) {
                            i++;
                            Assert.AreSame(buffer, sb, "same-1");
                            return(CMSampleBufferError.CannotSubdivide);
                        });
                        Assert.That(result, Is.EqualTo(CMSampleBufferError.CannotSubdivide), "custom error");
                        Assert.That(i, Is.EqualTo(1), "1");

                        Assert.Throws <ArgumentNullException> (delegate {
                            sb.CallForEachSample(null);
                        }, "null");
                    }
                }
            }
        }