Skip to content

Commit

Permalink
[CoreMedia] Remove !NET code. (#22159)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne authored Feb 12, 2025
1 parent 4687bcb commit 14642a5
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 507 deletions.
2 changes: 0 additions & 2 deletions src/CoreMedia/CMAttachmentBearer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@

namespace CoreMedia {

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public static class CMAttachmentBearer {

[DllImport (Constants.CoreMediaLibrary)]
Expand Down
6 changes: 0 additions & 6 deletions src/CoreMedia/CMBlockBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@
using CoreFoundation;
using ObjCRuntime;

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

namespace CoreMedia {

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public class CMBlockBuffer : NativeObject, ICMAttachmentBearer {
CMCustomBlockAllocator? customAllocator;

Expand Down
90 changes: 0 additions & 90 deletions src/CoreMedia/CMBufferQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ namespace CoreMedia {
public delegate bool CMBufferGetBool (INativeObject buffer);
public delegate int CMBufferCompare (INativeObject first, INativeObject second);

#if NET
// [SupportedOSPlatform ("ios")] - SupportedOSPlatform is not valid on this declaration type "delegate"
#endif
public delegate nint CMBufferGetSize (INativeObject buffer);

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public class CMBufferQueue : NativeObject {
#if !COREBUILD
GCHandle gch;
Expand All @@ -46,37 +42,17 @@ public class CMBufferQueue : NativeObject {
CMBufferCompare? compare;
CMBufferGetSize? getTotalSize;

#if !NET
delegate CMTime BufferGetTimeCallback (/* CMBufferRef */ IntPtr buf, /* void* */ IntPtr refcon);
[return: MarshalAs (UnmanagedType.I1)]
delegate bool BufferGetBooleanCallback (/* CMBufferRef */ IntPtr buf, /* void* */ IntPtr refcon);
delegate int BufferCompareCallback (/* CMBufferRef */ IntPtr buf1, /* CMBufferRef */ IntPtr buf2, /* void* */ IntPtr refcon);
delegate nint BufferGetSizeCallback (/* CMBufferRef */ IntPtr buffer, /* void* */ IntPtr refcon);
#endif

[StructLayout (LayoutKind.Sequential)]
struct CMBufferCallbacks {
internal uint version;
internal IntPtr refcon;
#if NET
internal unsafe delegate* unmanaged<IntPtr, IntPtr, CMTime> XgetDecodeTimeStamp;
internal unsafe delegate* unmanaged<IntPtr, IntPtr, CMTime> XgetPresentationTimeStamp;
internal unsafe delegate* unmanaged<IntPtr, IntPtr, CMTime> XgetDuration;
internal unsafe delegate* unmanaged<IntPtr, IntPtr, byte> XisDataReady;
internal unsafe delegate* unmanaged<IntPtr, IntPtr, IntPtr, int> Xcompare;
#else
internal IntPtr XgetDecodeTimeStamp;
internal IntPtr XgetPresentationTimeStamp;
internal IntPtr XgetDuration;
internal IntPtr XisDataReady;
internal IntPtr Xcompare;
#endif
internal IntPtr cfStringPtr_dataBecameReadyNotification;
#if NET
internal unsafe delegate* unmanaged<IntPtr, IntPtr, nint> XgetSize;
#else
internal IntPtr XgetSize;
#endif
}

// A version with no delegates, just native pointers
Expand Down Expand Up @@ -130,7 +106,6 @@ protected override void Dispose (bool disposing)
CMBufferGetBool? isDataReady, CMBufferCompare? compare, NSString dataBecameReadyNotification, CMBufferGetSize? getTotalSize)
{
var bq = new CMBufferQueue (count);
#if NET
CMBufferCallbacks cbacks;
unsafe {
cbacks = new CMBufferCallbacks () {
Expand All @@ -145,19 +120,6 @@ protected override void Dispose (bool disposing)
XgetSize = getTotalSize is not null ? &GetTotalSize : null
};
}
#else
var cbacks = new CMBufferCallbacks () {
version = (uint) (getTotalSize is null ? 0 : 1),
refcon = GCHandle.ToIntPtr (bq.gch),
XgetDecodeTimeStamp = getDecodeTimeStamp is not null ? Marshal.GetFunctionPointerForDelegate (GetDecodeTimeStampCallback) : IntPtr.Zero,
XgetPresentationTimeStamp = getPresentationTimeStamp is not null ? Marshal.GetFunctionPointerForDelegate (GetPresentationTimeStampCallback) : IntPtr.Zero,
XgetDuration = getDuration is not null ? Marshal.GetFunctionPointerForDelegate (GetDurationCallback) : IntPtr.Zero,
XisDataReady = isDataReady is not null ? Marshal.GetFunctionPointerForDelegate (GetDataReadyCallback) : IntPtr.Zero,
Xcompare = compare is not null ? Marshal.GetFunctionPointerForDelegate (CompareCallback) : IntPtr.Zero,
cfStringPtr_dataBecameReadyNotification = dataBecameReadyNotification is null ? IntPtr.Zero : dataBecameReadyNotification.Handle,
XgetSize = getTotalSize is not null ? Marshal.GetFunctionPointerForDelegate (GetTotalSizeCallback) : IntPtr.Zero
};
#endif

bq.getDecodeTimeStamp = getDecodeTimeStamp;
bq.getPresentationTimeStamp = getPresentationTimeStamp;
Expand Down Expand Up @@ -320,21 +282,17 @@ public CMTime Duration {
}
}

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
#endif
[DllImport (Constants.CoreMediaLibrary)]
extern static /* size_t */ nint CMBufferQueueGetTotalSize (/* CMBufferQueueRef */ IntPtr queue);

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
#endif
public nint GetTotalSize ()
{
return CMBufferQueueGetTotalSize (Handle);
Expand All @@ -347,14 +305,7 @@ INativeObject Surface (IntPtr v)
return queueObjects [v];
}

#if NET
[UnmanagedCallersOnly]
#else
static BufferGetTimeCallback GetDecodeTimeStampCallback = GetDecodeTimeStamp;
#if !MONOMAC
[MonoPInvokeCallback (typeof (BufferGetTimeCallback))]
#endif
#endif
static CMTime GetDecodeTimeStamp (IntPtr buffer, IntPtr refcon)
{
var queue = (CMBufferQueue?) GCHandle.FromIntPtr (refcon).Target;
Expand All @@ -363,14 +314,7 @@ static CMTime GetDecodeTimeStamp (IntPtr buffer, IntPtr refcon)
return queue.getDecodeTimeStamp (queue.Surface (buffer));
}

#if NET
[UnmanagedCallersOnly]
#else
static BufferGetTimeCallback GetPresentationTimeStampCallback = GetPresentationTimeStamp;
#if !MONOMAC
[MonoPInvokeCallback (typeof (BufferGetTimeCallback))]
#endif
#endif
static CMTime GetPresentationTimeStamp (IntPtr buffer, IntPtr refcon)
{
var queue = (CMBufferQueue?) GCHandle.FromIntPtr (refcon).Target;
Expand All @@ -379,14 +323,7 @@ static CMTime GetPresentationTimeStamp (IntPtr buffer, IntPtr refcon)
return queue.getPresentationTimeStamp (queue.Surface (buffer));
}

#if NET
[UnmanagedCallersOnly]
#else
static BufferGetTimeCallback GetDurationCallback = GetDuration;
#if !MONOMAC
[MonoPInvokeCallback (typeof (BufferGetTimeCallback))]
#endif
#endif
static CMTime GetDuration (IntPtr buffer, IntPtr refcon)
{
var queue = (CMBufferQueue?) GCHandle.FromIntPtr (refcon).Target;
Expand All @@ -395,36 +332,16 @@ static CMTime GetDuration (IntPtr buffer, IntPtr refcon)
return queue.getDuration (queue.Surface (buffer));
}

#if NET
[UnmanagedCallersOnly]
static byte GetDataReady (IntPtr buffer, IntPtr refcon)
#else
static BufferGetBooleanCallback GetDataReadyCallback = GetDataReady;
#if !MONOMAC
[MonoPInvokeCallback (typeof (BufferGetBooleanCallback))]
#endif
static bool GetDataReady (IntPtr buffer, IntPtr refcon)
#endif
{
var queue = (CMBufferQueue?) GCHandle.FromIntPtr (refcon).Target;
if (queue?.isDataReady is null)
#if NET
return 0;
return (byte) (queue.isDataReady (queue.Surface (buffer)) ? 1 : 0);
#else
return false;
return queue.isDataReady (queue.Surface (buffer));
#endif
}

#if NET
[UnmanagedCallersOnly]
#else
static BufferCompareCallback CompareCallback = Compare;
#if !MONOMAC
[MonoPInvokeCallback (typeof (BufferCompareCallback))]
#endif
#endif
static int Compare (IntPtr buffer1, IntPtr buffer2, IntPtr refcon)
{
var queue = (CMBufferQueue?) GCHandle.FromIntPtr (refcon).Target;
Expand All @@ -433,14 +350,7 @@ static int Compare (IntPtr buffer1, IntPtr buffer2, IntPtr refcon)
return queue.compare (queue.Surface (buffer1), queue.Surface (buffer2));
}

#if NET
[UnmanagedCallersOnly]
#else
static BufferGetSizeCallback GetTotalSizeCallback = GetTotalSize;
#if !MONOMAC
[MonoPInvokeCallback (typeof (BufferGetSizeCallback))]
#endif
#endif
static nint GetTotalSize (IntPtr buffer, IntPtr refcon)
{
var queue = (CMBufferQueue?) GCHandle.FromIntPtr (refcon).Target;
Expand Down
32 changes: 0 additions & 32 deletions src/CoreMedia/CMCustomBlockAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

namespace CoreMedia {

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public class CMCustomBlockAllocator : IDisposable {

GCHandle gch;
Expand All @@ -33,7 +31,6 @@ public CMCustomBlockAllocator ()
gch = GCHandle.Alloc (this);
// kCMBlockBufferCustomBlockSourceVersion = 0 <- this is the only and current value
Cblock.Version = 0;
#if NET
unsafe {
// Assign function pointers to temporary variable due to https://github.com/dotnet/runtime/issues/107396.
delegate* unmanaged<IntPtr, nuint, IntPtr> allocate = &AllocateCallback;
Expand All @@ -42,43 +39,20 @@ public CMCustomBlockAllocator ()
Cblock.Allocate = allocate;
Cblock.Free = free;
}
#else
Cblock.Allocate = Marshal.GetFunctionPointerForDelegate (static_AllocateCallback);
Cblock.Free = Marshal.GetFunctionPointerForDelegate (static_FreeCallback);
#endif
Cblock.RefCon = GCHandle.ToIntPtr (gch);
}

// 1:1 mapping to the real underlying structure
[StructLayout (LayoutKind.Sequential, Pack = 4)] // it's 28 bytes (not 32) on 64 bits iOS
internal struct CMBlockBufferCustomBlockSource {
public uint Version;
#if NET
public unsafe delegate* unmanaged<IntPtr, nuint, IntPtr> Allocate;
public unsafe delegate* unmanaged<IntPtr, IntPtr, nuint, void> Free;
#else
public IntPtr Allocate;
public IntPtr Free;
#endif
public IntPtr RefCon;
}
internal CMBlockBufferCustomBlockSource Cblock;

#if !NET
internal delegate IntPtr CMAllocateCallback (/* void* */ IntPtr refCon, /* size_t */ nuint sizeInBytes);
internal delegate void CMFreeCallback (/* void* */ IntPtr refCon, /* void* */ IntPtr doomedMemoryBlock, /* size_t */ nuint sizeInBytes);

static CMAllocateCallback static_AllocateCallback = AllocateCallback;
static CMFreeCallback static_FreeCallback = FreeCallback;
#endif

#if NET
[UnmanagedCallersOnly]
#else
#if !MONOMAC
[MonoPInvokeCallback (typeof (CMAllocateCallback))]
#endif
#endif
static IntPtr AllocateCallback (IntPtr refCon, nuint sizeInBytes)
{
var gch = GCHandle.FromIntPtr (refCon);
Expand All @@ -92,13 +66,7 @@ public virtual IntPtr Allocate (nuint sizeInBytes)
return Marshal.AllocHGlobal ((int) sizeInBytes);
}

#if NET
[UnmanagedCallersOnly]
#else
#if !MONOMAC
[MonoPInvokeCallback (typeof (CMFreeCallback))]
#endif
#endif
static void FreeCallback (IntPtr refCon, IntPtr doomedMemoryBlock, nuint sizeInBytes)
{
var gch = GCHandle.FromIntPtr (refCon);
Expand Down
Loading

10 comments on commit 14642a5

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

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