2016-05-26 16:06:52 +03:00
|
|
|
|
//
|
|
|
|
|
// Unit tests for VTMultiPassStorage
|
|
|
|
|
//
|
|
|
|
|
// Authors:
|
|
|
|
|
// Alex Soto <alex.soto@xamarin.com>
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Copyright 2015 Xamarin Inc. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2017-02-09 09:39:36 +03:00
|
|
|
|
#if !__WATCHOS__
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
using Foundation;
|
|
|
|
|
using VideoToolbox;
|
2020-08-25 00:39:35 +03:00
|
|
|
|
using CoreMedia;
|
2017-01-12 21:13:56 +03:00
|
|
|
|
#if MONOMAC
|
|
|
|
|
using AppKit;
|
|
|
|
|
#else
|
2016-05-26 16:06:52 +03:00
|
|
|
|
using UIKit;
|
2017-01-12 21:13:56 +03:00
|
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
|
using CoreMedia;
|
|
|
|
|
using AVFoundation;
|
|
|
|
|
using CoreFoundation;
|
|
|
|
|
using CoreVideo;
|
|
|
|
|
using CoreGraphics;
|
|
|
|
|
using ObjCRuntime;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
namespace MonoTouchFixtures.VideoToolbox {
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
|
public class VTUtilitiesTests {
|
|
|
|
|
|
|
|
|
|
[DllImport (Constants.CoreFoundationLibrary)]
|
|
|
|
|
extern static int CFGetRetainCount (IntPtr handle);
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void ToCGImageTest ()
|
|
|
|
|
{
|
2018-07-04 12:44:14 +03:00
|
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.iOS, 9, 0, throwIfOtherPlatform: false);
|
|
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 10, 11, throwIfOtherPlatform: false);
|
|
|
|
|
TestRuntime.AssertSystemVersion (PlatformName.TvOS, 10, 2, throwIfOtherPlatform: false);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
2017-01-12 21:13:56 +03:00
|
|
|
|
#if MONOMAC
|
|
|
|
|
var originalImage = new NSImage (NSBundle.MainBundle.PathForResource ("Xam", "png", "CoreImage"));
|
|
|
|
|
#else
|
2016-05-26 16:06:52 +03:00
|
|
|
|
var originalImage = UIImage.FromBundle ("CoreImage/Xam.png");
|
2017-01-12 21:13:56 +03:00
|
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
|
var originalCGImage = originalImage.CGImage;
|
|
|
|
|
|
|
|
|
|
var pxbuffer = new CVPixelBuffer (originalCGImage.Width, originalCGImage.Height, CVPixelFormatType.CV32ARGB,
|
|
|
|
|
new CVPixelBufferAttributes { CGImageCompatibility = true, CGBitmapContextCompatibility = true });
|
2017-02-09 09:39:36 +03:00
|
|
|
|
#if !__TVOS__
|
2016-05-26 16:06:52 +03:00
|
|
|
|
pxbuffer.Lock (CVOptionFlags.None);
|
2017-02-09 09:39:36 +03:00
|
|
|
|
#else
|
|
|
|
|
pxbuffer.Lock (CVPixelBufferLock.None);
|
|
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
|
using (var colorSpace = CGColorSpace.CreateDeviceRGB ())
|
|
|
|
|
using (var ctx = new CGBitmapContext (pxbuffer.BaseAddress, originalCGImage.Width, originalCGImage.Height, 8,
|
|
|
|
|
4 * originalCGImage.Width, colorSpace, CGBitmapFlags.NoneSkipLast)) {
|
|
|
|
|
ctx.RotateCTM (0);
|
2020-05-29 17:43:06 +03:00
|
|
|
|
ctx.DrawImage (new CGRect (0, 0, originalCGImage.Width, originalCGImage.Height), originalCGImage);
|
2017-02-09 09:39:36 +03:00
|
|
|
|
#if !__TVOS__
|
2016-05-26 16:06:52 +03:00
|
|
|
|
pxbuffer.Unlock (CVOptionFlags.None);
|
2017-02-09 09:39:36 +03:00
|
|
|
|
#else
|
|
|
|
|
pxbuffer.Unlock (CVPixelBufferLock.None);
|
|
|
|
|
#endif
|
2016-05-26 16:06:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.NotNull (pxbuffer, "VTUtilitiesTests.ToCGImageTest pxbuffer should not be null");
|
|
|
|
|
|
|
|
|
|
CGImage newImage;
|
|
|
|
|
var newImageStatus = pxbuffer.ToCGImage (out newImage);
|
|
|
|
|
|
|
|
|
|
Assert.That (newImageStatus == VTStatus.Ok, "VTUtilitiesTests.ToCGImageTest must be ok");
|
|
|
|
|
Assert.NotNull (newImage, "VTUtilitiesTests.ToCGImageTest pxbuffer should not be newImage");
|
|
|
|
|
Assert.AreEqual (originalCGImage.Width, newImage.Width, "VTUtilitiesTests.ToCGImageTest");
|
|
|
|
|
Assert.AreEqual (originalCGImage.Height, newImage.Height, "VTUtilitiesTests.ToCGImageTest");
|
|
|
|
|
|
|
|
|
|
var retainCount = CFGetRetainCount (newImage.Handle);
|
|
|
|
|
Assert.That (retainCount, Is.EqualTo (1), "RetainCount");
|
|
|
|
|
}
|
2020-08-25 00:39:35 +03:00
|
|
|
|
|
|
|
|
|
#if MONOMAC
|
|
|
|
|
|
|
|
|
|
[TestCase (CMVideoCodecType.YUV422YpCbCr8)]
|
|
|
|
|
[TestCase (CMVideoCodecType.Animation)]
|
|
|
|
|
[TestCase (CMVideoCodecType.Cinepak)]
|
|
|
|
|
[TestCase (CMVideoCodecType.JPEG)]
|
|
|
|
|
[TestCase (CMVideoCodecType.JPEG_OpenDML)]
|
|
|
|
|
[TestCase (CMVideoCodecType.SorensonVideo)]
|
|
|
|
|
[TestCase (CMVideoCodecType.SorensonVideo3)]
|
|
|
|
|
[TestCase (CMVideoCodecType.H263)]
|
|
|
|
|
[TestCase (CMVideoCodecType.H264)]
|
|
|
|
|
[TestCase (CMVideoCodecType.Mpeg4Video)]
|
|
|
|
|
[TestCase (CMVideoCodecType.Mpeg2Video)]
|
|
|
|
|
[TestCase (CMVideoCodecType.Mpeg1Video)]
|
|
|
|
|
[TestCase (CMVideoCodecType.VP9)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcNtsc)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcPal)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcProPal)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcPro50NTSC)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcPro50PAL)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcProHD720p60)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcProHD720p50)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcProHD1080i60)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcProHD1080i50)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcProHD1080p30)]
|
|
|
|
|
[TestCase (CMVideoCodecType.DvcProHD1080p25)]
|
|
|
|
|
[TestCase (CMVideoCodecType.AppleProRes4444)]
|
|
|
|
|
[TestCase (CMVideoCodecType.AppleProRes422HQ)]
|
|
|
|
|
[TestCase (CMVideoCodecType.AppleProRes422)]
|
|
|
|
|
[TestCase (CMVideoCodecType.AppleProRes422LT)]
|
|
|
|
|
[TestCase (CMVideoCodecType.AppleProRes422Proxy)]
|
|
|
|
|
[TestCase (CMVideoCodecType.Hevc)]
|
|
|
|
|
public void TestRegisterSupplementalVideoDecoder (CMVideoCodecType codec)
|
|
|
|
|
{
|
|
|
|
|
TestRuntime.AssertXcodeVersion (12, 0);
|
|
|
|
|
// ensure that the call does not crash, we do not have anyother thing to test since there is
|
|
|
|
|
// no way to know if it was a success
|
|
|
|
|
VTUtilities.RegisterSupplementalVideoDecoder (codec);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-05-26 16:06:52 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-09 09:39:36 +03:00
|
|
|
|
#endif // !__WATCHOS__
|