Skip to content

Commit

Permalink
[VideoToolbox] Added support for Xcode 14 b1-3 (#15845)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Soto <[email protected]>
Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
Co-authored-by: Manuel de la Pena <[email protected]>
  • Loading branch information
4 people authored Oct 13, 2022
1 parent 216018c commit bac36c5
Show file tree
Hide file tree
Showing 19 changed files with 550 additions and 142 deletions.
21 changes: 21 additions & 0 deletions src/VideoToolbox/VTDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public enum VTStatus {
VideoDecoderMalfunction = -12911,
VideoEncoderMalfunction = -12912,
VideoDecoderNotAvailableNow = -12913,
[Obsolete ("Use PixelRotationNotSupported enum value instead.")]
ImageRotationNotSupported = -12914,
PixelRotationNotSupported = -12914,
VideoEncoderNotAvailableNow = -12915,
FormatDescriptionChangeNotSupported = -12916,
InsufficientSourceColorData = -12917,
Expand All @@ -53,6 +55,12 @@ public enum VTStatus {
DecoderNeedsRosetta = -17692,
[Mac (11, 0)]
EncoderNeedsRosetta = -17693,
[Mac (12,0), iOS (15,0), MacCatalyst (15,0), Watch (9,0), TV (15,0)]
VideoDecoderReferenceMissing = -17694,
[Mac (12,0), iOS (15,0), MacCatalyst (15,0), Watch (9,0), TV (15,0)]
VideoDecoderCallbackMessaging = -17695,
[Mac (13,0), iOS (16,0), MacCatalyst (16,0), Watch (9,0), TV (16,0)]
VideoDecoderUnknownErr = -17696,
}

// uint32_t -> VTErrors.h
Expand Down Expand Up @@ -266,4 +274,17 @@ public enum HdrMetadataInsertionMode {
[Field ("kVTHDRMetadataInsertionMode_Auto")]
Auto,
}

[Mac (13,0), iOS (16,0), MacCatalyst (16,0), Watch (9,0), TV (16,0)]
public enum VTRotation {
[DefaultEnumValue]
[Field ("kVTRotation_0")]
Zero,
[Field ("kVTRotation_CW90")]
ClockwiseNinety,
[Field ("kVTRotation_180")]
OneHundredAndEighty,
[Field ("kVTRotation_CCW90")]
CounterclockwiseNinety,
}
}
29 changes: 29 additions & 0 deletions src/VideoToolbox/VTPixelRotationProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// VTPixelRotationProperties.cs: Strongly Typed dictionary for VTPixelRotationPropertyKeys
//
// Authors: Israel Soto ([email protected])
//
// Copyright 2022 Microsoft Corporation.
//

#nullable enable

using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;

using CoreFoundation;
using ObjCRuntime;
using Foundation;
using CoreMedia;
using CoreVideo;
using AVFoundation;

namespace VideoToolbox {
public partial class VTPixelRotationProperties : DictionaryContainer {
public VTRotation Rotation {
get => VTRotationExtensions.GetValue (GetNSStringValue (VTPixelRotationPropertyKeys.Rotation)!);
set => SetStringValue (VTPixelRotationPropertyKeys.Rotation, value.GetConstant ());
}
}
}
107 changes: 107 additions & 0 deletions src/VideoToolbox/VTPixelRotationSession.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// VTPixelRotationSession.cs: VideoTools Pixel Rotation Session class
//
// Authors:
// Israel Soto ([email protected])
//
// Copyright 2022 Microsoft Corporation.
//

#nullable enable

using System;
using System.Runtime.InteropServices;

using CoreFoundation;
using ObjCRuntime;
using Foundation;
using CoreMedia;
using CoreVideo;

#if !NET
using NativeHandle = System.IntPtr;
#endif

namespace VideoToolbox {

#if NET
[SupportedOSPlatform ("macos13.0")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("watchos9.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (13,0), iOS (16,0), MacCatalyst (16,0), Watch (9,0), TV (16,0)]
#endif
public class VTPixelRotationSession : VTSession {

[DllImport (Constants.VideoToolboxLibrary)]
extern static /* CFTypeID */ nint VTPixelRotationSessionGetTypeID ();
public static nint GetTypeID () => VTPixelRotationSessionGetTypeID ();

#if !NET
/* invoked by marshallers */
protected internal VTPixelRotationSession (NativeHandle handle) : base (handle)
{
}
#endif

[Preserve (Conditional=true)]
internal VTPixelRotationSession (NativeHandle handle, bool owns) : base (handle, owns)
{
}

[DllImport (Constants.VideoToolboxLibrary)]
extern static void VTPixelRotationSessionInvalidate (/* VTPixelRotationSessionRef */ IntPtr session);

protected override void Dispose (bool disposing)
{
if (Handle != IntPtr.Zero)
VTPixelRotationSessionInvalidate (Handle);

base.Dispose (disposing);
}

[DllImport (Constants.VideoToolboxLibrary)]
unsafe extern static VTStatus VTPixelRotationSessionCreate (
/* CFAllocatorRef */ IntPtr allocator, /* can be null */
/* VTPixelRotationSessionRef* */ out IntPtr pixelRotationSessionOut);

public static VTPixelRotationSession? Create () => Create (null);

public static VTPixelRotationSession? Create (CFAllocator? allocator)
{
var result = VTPixelRotationSessionCreate (allocator.GetHandle (), out var ret);

if (result == VTStatus.Ok && ret != IntPtr.Zero)
return new VTPixelRotationSession (ret, true);

return null;
}

[DllImport (Constants.VideoToolboxLibrary)]
extern static VTStatus VTPixelRotationSessionRotateImage (
/* VTPixelRotationSessionRef */ IntPtr session,
/* CVPixelBuffer */ IntPtr sourceBuffer,
/* CVPixelBuffer */ IntPtr destinationBuffer);

public VTStatus RotateImage (CVPixelBuffer sourceBuffer, CVPixelBuffer destinationBuffer)
{
if (sourceBuffer is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (sourceBuffer));

if (destinationBuffer is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (destinationBuffer));

return VTPixelRotationSessionRotateImage (GetCheckedHandle (), sourceBuffer.Handle, destinationBuffer.Handle);
}

public VTStatus SetRotationProperties (VTPixelRotationProperties options)
{
if (options is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (options));

return VTSessionSetProperties (Handle, options.Dictionary.Handle);
}
}
}
106 changes: 106 additions & 0 deletions src/VideoToolbox/VTPixelTransferSession.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// VTPixelTransferSession.cs: VideoTools Pixel Transfer Session class
//
// Authors:
// Israel Soto ([email protected])
//
// Copyright 2022 Microsoft Corporation.
//

#nullable enable

using System;
using System.Runtime.InteropServices;

using CoreFoundation;
using ObjCRuntime;
using Foundation;
using CoreMedia;
using CoreVideo;

#if !NET
using NativeHandle = System.IntPtr;
#endif

namespace VideoToolbox {

#if NET
[SupportedOSPlatform ("macos10.9")]
[SupportedOSPlatform ("ios16.0")]
[SupportedOSPlatform ("maccatalyst16.0")]
[SupportedOSPlatform ("watchos9.0")]
[SupportedOSPlatform ("tvos16.0")]
#else
[Mac (10,9), iOS (16,0), MacCatalyst (16,0), Watch (9,0), TV (16,0)]
#endif
public class VTPixelTransferSession : VTSession {

[DllImport (Constants.VideoToolboxLibrary)]
extern static /* CFTypeID */ nint VTPixelTransferSessionGetTypeID ();
public static nint GetTypeID () => VTPixelTransferSessionGetTypeID ();

#if !NET
/* invoked by marshallers */
protected internal VTPixelTransferSession (NativeHandle handle) : base (handle)
{
}
#endif

[Preserve (Conditional=true)]
internal VTPixelTransferSession (NativeHandle handle, bool owns) : base (handle, owns)
{
}

[DllImport (Constants.VideoToolboxLibrary)]
extern static void VTPixelTransferSessionInvalidate (/* VTPixelTransferSessionRef */ IntPtr session);

protected override void Dispose (bool disposing)
{
if (Handle != IntPtr.Zero)
VTPixelTransferSessionInvalidate (Handle);

base.Dispose (disposing);
}

[DllImport (Constants.VideoToolboxLibrary)]
unsafe extern static VTStatus VTPixelTransferSessionCreate (
/* CFAllocatorRef */ IntPtr allocator, /* can be null */
/* VTPixelTransferSessionRef* */ out IntPtr pixelTransferSessionOut);

public static VTPixelTransferSession? Create () => Create (null);

public static VTPixelTransferSession? Create (CFAllocator? allocator) {
var result = VTPixelTransferSessionCreate (allocator.GetHandle (), out var ret);

if (result == VTStatus.Ok && ret != IntPtr.Zero)
return new VTPixelTransferSession (ret, true);

return null;
}

[DllImport (Constants.VideoToolboxLibrary)]
extern static VTStatus VTPixelTransferSessionTransferImage (
/* VTPixelTransferSessionRef */ IntPtr session,
/* CVPixelBuffer */ IntPtr sourceBuffer,
/* CVPixelBuffer */ IntPtr destinationBuffer);

public VTStatus TransferImage (CVPixelBuffer sourceBuffer, CVPixelBuffer destinationBuffer)
{
if (sourceBuffer is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (sourceBuffer));

if (destinationBuffer is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (destinationBuffer));

return VTPixelTransferSessionTransferImage (GetCheckedHandle (), sourceBuffer.Handle, destinationBuffer.Handle);
}

public VTStatus SetTransferProperties (VTPixelTransferProperties options)
{
if (options is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (options));

return VTSessionSetProperties (Handle, options.Dictionary.Handle);
}
}
}
40 changes: 40 additions & 0 deletions src/VideoToolbox/VTProfessionalVideoWorkflow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// VTProfessionalVideoWorkflow.cs: VideoTools Professional Video Workflow
//
// Authors:
// Israel Soto ([email protected])
//
// Copyright 2022 Microsoft Corporation.
//

#if __MACOS__

#nullable enable

using System;
using System.Runtime.InteropServices;

using ObjCRuntime;
using Foundation;

namespace VideoToolbox {

#if NET
[SupportedOSPlatform ("macos10.9")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("watchos")]
[UnsupportedOSPlatform ("tvos")]
#else
[Mac (10,9), NoiOS, NoMacCatalyst, NoWatch, NoTV]
#endif
public static class VTProfessionalVideoWorkflow {
[DllImport (Constants.VideoToolboxLibrary, EntryPoint = "VTRegisterProfessionalVideoWorkflowVideoDecoders")]
public extern static void RegisterVideoDecoders ();

[DllImport (Constants.VideoToolboxLibrary, EntryPoint = "VTRegisterProfessionalVideoWorkflowVideoEncoders")]
public extern static void RegisterVideoEncoders ();
}
}

#endif // __MACOS__
5 changes: 5 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,11 @@ VIDEOTOOLBOX_SOURCES = \
VideoToolbox/VTDecompressionSession.cs \
VideoToolbox/VTFrameSilo.cs \
VideoToolbox/VTMultiPassStorage.cs \
VideoToolbox/VTPixelRotationProperties.cs \
VideoToolbox/VTPixelRotationSession.cs \
VideoToolbox/VTPixelTransferProperties.cs \
VideoToolbox/VTPixelTransferSession.cs \
VideoToolbox/VTProfessionalVideoWorkflow.cs \
VideoToolbox/VTPropertyOptions.cs \
VideoToolbox/VTSession.cs \
VideoToolbox/VTVideoEncoder.cs \
Expand Down
Loading

4 comments on commit bac36c5

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.