Skip to content

Commit

Permalink
[VideoToolbox] Implement Xcode 16.0 beta 1-6 changes. (#21157)
Browse files Browse the repository at this point in the history
Note: there were no changes in beta 6.
  • Loading branch information
rolfbjarne authored Sep 12, 2024
1 parent f7bddc6 commit d3dd195
Show file tree
Hide file tree
Showing 33 changed files with 1,443 additions and 308 deletions.
11 changes: 11 additions & 0 deletions src/Foundation/DictionaryContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ protected DictionaryContainer (NSDictionary? dictionary)
return ((NSNumber) value).Int64Value;
}

protected ulong? GetULongValue (NSString key)
{
if (key is null)
throw new ArgumentNullException (nameof (key));

if (!Dictionary.TryGetValue (key, out var value))
return null;

return ((NSNumber) value).UInt64Value;
}

protected uint? GetUIntValue (NSString key)
{
if (key is null)
Expand Down
28 changes: 28 additions & 0 deletions src/VideoToolbox/VTCompressionSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,5 +444,33 @@ public VTStatus SetCompressionProperties (VTCompressionProperties options)

return VTSessionSetProperties (GetCheckedHandle (), options.Dictionary.Handle);
}

#if !__WATCHOS__
#if NET
[SupportedOSPlatform ("macos14.0")]
[SupportedOSPlatform ("ios17.0")]
[SupportedOSPlatform ("tvos17.0")]
[SupportedOSPlatform ("maccatalyst17.0")]
#else
[iOS (17, 0), TV (17, 0), Mac (14, 0), NoWatch]
#endif
[DllImport (Constants.VideoToolboxLibrary)]
extern static /* Boolean */ byte VTIsStereoMVHEVCEncodeSupported ();

/// <summary>Returns whether the current system supports stereo MV-HEVC encode.</summary>
/// <returns>True if the current system supports stereo MV-HEVC encode, false otherwise.</returns>
#if NET
[SupportedOSPlatform ("macos14.0")]
[SupportedOSPlatform ("ios17.0")]
[SupportedOSPlatform ("tvos17.0")]
[SupportedOSPlatform ("maccatalyst17.0")]
#else
[iOS (17, 0), TV (17, 0), Mac (14, 0), NoWatch]
#endif
public static bool IsStereoMvHevcEncodeSupported ()
{
return VTIsStereoMVHEVCEncodeSupported () != 0;
}
#endif // !__WATCHOS__
}
}
28 changes: 28 additions & 0 deletions src/VideoToolbox/VTDecompressionSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,5 +392,33 @@ public static bool IsHardwareDecodeSupported (CMVideoCodecType codecType)
{
return VTIsHardwareDecodeSupported (codecType) != 0;
}

#if !__WATCHOS__
#if NET
[SupportedOSPlatform ("macos14.0")]
[SupportedOSPlatform ("ios17.0")]
[SupportedOSPlatform ("tvos17.0")]
[SupportedOSPlatform ("maccatalyst17.0")]
#else
[iOS (17, 0), TV (17, 0), Mac (14, 0), NoWatch]
#endif
[DllImport (Constants.VideoToolboxLibrary)]
extern static /* Boolean */ byte VTIsStereoMVHEVCDecodeSupported ();

/// <summary>Returns whether the current system supports stereo MV-HEVC decode.</summary>
/// <returns>True if the current system supports stereo MV-HEVC decode, false otherwise.</returns>
#if NET
[SupportedOSPlatform ("macos14.0")]
[SupportedOSPlatform ("ios17.0")]
[SupportedOSPlatform ("tvos17.0")]
[SupportedOSPlatform ("maccatalyst17.0")]
#else
[iOS (17, 0), TV (17, 0), Mac (14, 0), NoWatch]
#endif
public static bool IsStereoMvHevcDecodeSupported ()
{
return VTIsStereoMVHEVCDecodeSupported () != 0;
}
#endif // !__WATCHOS__
}
}
6 changes: 6 additions & 0 deletions src/VideoToolbox/VTDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public enum VTStatus {
VideoDecoderCallbackMessaging = -17695,
[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), Watch (9, 0), TV (16, 0)]
VideoDecoderUnknownErr = -17696,
ExtensionDisabledErr = -17697,
VideoEncoderMVHEVCVideoLayerIDsMismatchErr = -17698,
CouldNotOutputTaggedBufferGroupErr = -17699,
CouldNotFindExtensionErr = -19510,
ExtensionConflictErr = -19511,
}

// uint32_t -> VTErrors.h
Expand All @@ -83,6 +88,7 @@ public enum VTDecodeInfoFlags : uint {
Asynchronous = 1 << 0,
FrameDropped = 1 << 1,
ImageBufferModifiable = 1 << 2,
SkippedLeadingFrameDropped = 1 << 3,
}

// UInt32 -> VTErrors.h
Expand Down
92 changes: 92 additions & 0 deletions src/VideoToolbox/VTHdrPerFrameMetadataGenerationSession.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#if !WATCH && NET

#nullable enable

using System;
using System.Runtime.InteropServices;

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

namespace VideoToolbox {

/// <summary>This class can be used to perform HDR Per Frame Metadata Generation.</summary>
#if NET
[SupportedOSPlatform ("ios18.0")]
[SupportedOSPlatform ("maccatalyst18.0")]
[SupportedOSPlatform ("macos15.0")]
[SupportedOSPlatform ("tvos18.0")]
#else
[NoWatch, TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
#endif
public class VTHdrPerFrameMetadataGenerationSession : NativeObject {
[Preserve (Conditional = true)]
protected VTHdrPerFrameMetadataGenerationSession (NativeHandle handle, bool owns)
: base (handle, owns)
{
}

[DllImport (Constants.VideoToolboxLibrary)]
static extern nint VTHDRPerFrameMetadataGenerationSessionGetTypeID ();

/// <summary>Get this type's CFTypeID.</summary>
public static nint GetTypeId ()
{
return VTHDRPerFrameMetadataGenerationSessionGetTypeID ();
}

[DllImport (Constants.VideoToolboxLibrary)]
unsafe static extern int /* OSStatus */ VTHDRPerFrameMetadataGenerationSessionCreate (
IntPtr /* CM_NULLABLE CFAllocatorRef */ allocator,
float framesPerSecond,
IntPtr /* CM_NULLABLE CFDictionaryRef */ options,
IntPtr* /* CM_RETURNS_RETAINED_PARAMETER CM_NULLABLE VTHDRPerFrameMetadataGenerationSessionRef * CM_NONNULL */ hdrPerFrameMetadataGenerationSessionOut
);

/// <summary>Create a new <see cref="VTHdrPerFrameMetadataGenerationSession" /> instance.</summary>
/// <param name="framesPerSecond">This value must be greater than 0.0.</param>
/// <param name="options">An optional dictionary of options to use.</param>
/// <param name="error">An error code if the operation was unsuccessful, otherwise <see cref="VTStatus.Ok" />.</param>
/// <returns>A new <see cref="VTHdrPerFrameMetadataGenerationSession" /> instance, or null in case of failure. See the <paramref name="error" /> parameter for the error code.</returns>
public static VTHdrPerFrameMetadataGenerationSession? Create (float framesPerSecond, NSDictionary? options, out VTStatus error)
{
IntPtr handle;
unsafe {
error = (VTStatus) VTHDRPerFrameMetadataGenerationSessionCreate (IntPtr.Zero, framesPerSecond, options.GetHandle (), &handle);
}
if (error == VTStatus.Ok && handle != IntPtr.Zero)
return new VTHdrPerFrameMetadataGenerationSession (handle, owns: true);
return null;
}

/// <summary>Create a new <see cref="VTHdrPerFrameMetadataGenerationSession" /> instance.</summary>
/// <param name="framesPerSecond">This value must be greater than 0.0.</param>
/// <param name="options">An optional dictionary of options to use.</param>
/// <param name="error">An error code if the operation was unsuccessful, otherwise <see cref="VTStatus.Ok" />.</param>
/// <returns>A new <see cref="VTHdrPerFrameMetadataGenerationSession" /> instance, or null in case of failure. See the <paramref name="error" /> parameter for the error code.</returns>
public static VTHdrPerFrameMetadataGenerationSession? Create (float framesPerSecond, VTHdrPerFrameMetadataGenerationOptions? options, out VTStatus error)
{
return Create (framesPerSecond, options?.Dictionary, out error);
}

[DllImport (Constants.VideoToolboxLibrary)]
unsafe static extern VTStatus /* OSStatus */ VTHDRPerFrameMetadataGenerationSessionAttachMetadata (
IntPtr /* VTHDRPerFrameMetadataGenerationSessionRef */ hdrPerFrameMetadataGenerationSession,
IntPtr /* CVPixelBufferRef */ pixelBuffer,
byte /* Boolean */ sceneChange
);

/// <summary>Analyze and attach per-frame HDR metadata to the <see cref="CVPixelBuffer" /> and its backing <see cref="IOSurface" />.</summary>
/// <param name="pixelBuffer">The pixel buffer to attach the metadata to.</param>
/// <param name="sceneChange">Set this value to true if this frame's brightness changed significantly compared to the previous frame (for example if going from an outdoor scene to an indoor scene).</param>
/// <returns>An error code if the operation was unsuccessful, otherwise <see cref="VTStatus.Ok" />.</returns>
public VTStatus AttachMetadata (CVPixelBuffer pixelBuffer, bool sceneChange)
{
return VTHDRPerFrameMetadataGenerationSessionAttachMetadata (GetCheckedHandle (), pixelBuffer.GetNonNullHandle (nameof (pixelBuffer)), sceneChange.AsByte ());
}
}
}

#endif // !WATCH
Loading

5 comments on commit d3dd195

@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.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.