Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CoreMedia] Add support for xcode13 #12770

Merged
merged 13 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 188 additions & 24 deletions src/CoreMedia/CMSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using CoreFoundation;
using ObjCRuntime;

#nullable enable

namespace CoreMedia {

// CMSync.h
Expand Down Expand Up @@ -58,7 +60,7 @@ public CMTime CurrentTime {
[DllImport(Constants.CoreMediaLibrary)]
extern static /* OSStatus */ CMClockError CMAudioClockCreate (/* CFAllocatorRef */ IntPtr allocator, /* CMClockRef* */ out IntPtr clockOut);

public static CMClock CreateAudioClock (out CMClockError clockError)
public static CMClock? CreateAudioClock (out CMClockError clockError)
{
IntPtr ptr;
clockError = CMAudioClockCreate (IntPtr.Zero, out ptr);
Expand Down Expand Up @@ -118,6 +120,17 @@ private CMTimebase (IntPtr handle, bool owns)
}
#if !COREBUILD

#if !NET
[Deprecated (PlatformName.iOS, 8, 0)]
[Deprecated (PlatformName.TvOS, 9, 0)]
[Deprecated (PlatformName.MacOSX, 10, 10)]
[Deprecated (PlatformName.WatchOS, 6, 0)]
#else
[UnsupportedOSPlatform ("ios8.0")]
[UnsupportedOSPlatform ("tvos9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos10.10")]
#endif
[DllImport(Constants.CoreMediaLibrary)]
extern static /* OSStatus */ CMTimebaseError CMTimebaseCreateWithMasterClock (/* CFAllocatorRef */ IntPtr allocator, /* CMClockRef */ IntPtr masterClock, /* CMTimebaseRef* */ out IntPtr timebaseOut);

Expand All @@ -133,6 +146,17 @@ public CMTimebase (CMClock masterClock)
CFObject.CFRetain (Handle);
}

#if !NET
[Deprecated (PlatformName.iOS, 8, 0)]
[Deprecated (PlatformName.TvOS, 9, 0)]
[Deprecated (PlatformName.MacOSX, 10, 10)]
[Deprecated (PlatformName.WatchOS, 6, 0)]
#else
[UnsupportedOSPlatform ("ios8.0")]
[UnsupportedOSPlatform ("tvos9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos10.10")]
#endif
[DllImport(Constants.CoreMediaLibrary)]
extern static /* OSStatus */ CMTimebaseError CMTimebaseCreateWithMasterTimebase (/* CFAllocatorRef */ IntPtr allocator, /* CMTimebaseRef */ IntPtr masterTimebase, /* CMTimebaseRef* */ out IntPtr timebaseOut);

Expand All @@ -147,7 +171,40 @@ public CMTimebase (CMTimebase masterTimebase)

CFObject.CFRetain (Handle);
}

[Watch (6,0), TV (9,0), Mac (10,8), iOS (6,0)]
[DllImport(Constants.CoreMediaLibrary)]
static extern CMTimebaseError CMTimebaseCreateWithSourceClock (/* [NullAllowed] CFAllocatorRef */ IntPtr allocator, /* CMClock */ IntPtr sourceClock, /* CMTimebase */ out IntPtr timebaseOut);

[Watch (6,0), TV (9,0), Mac (10,8), iOS (6,0)]
public CMTimebase (CFAllocator? allocator, CMClock sourceClock)
{
if (sourceClock == null)
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
throw new ArgumentNullException (nameof(sourceClock));
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved

var error = CMTimebaseCreateWithSourceClock (allocator.GetHandle (), sourceClock.Handle, out handle);
if (error != CMTimebaseError.None)
throw new ArgumentException (error.ToString ());

CFObject.CFRetain (Handle);
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary, the handle parameter is marked as CM_RETURNS_RETAINED_PARAMETER in the header.

}

[Watch (6,0), TV (9,0), Mac (10,8), iOS (6,0)]
[DllImport(Constants.CoreMediaLibrary)]
static extern CMTimebaseError CMTimebaseCreateWithSourceTimebase (/* [NullAllowed] CFAllocatorRef */ IntPtr allocator, /* CMTimebase */ IntPtr sourceTimebase, /* CMTimebase */ out IntPtr timebaseOut);

[Watch (6,0), TV (9,0), Mac (10,8), iOS (6,0)]
public CMTimebase (CFAllocator? allocator, CMTimebase sourceTimebase)
{
if (sourceTimebase == null)
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
throw new ArgumentNullException (nameof(sourceTimebase));
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved

var error = CMTimebaseCreateWithSourceTimebase (allocator.GetHandle (), sourceTimebase.Handle, out handle);
if (error != CMTimebaseError.None)
throw new ArgumentException (error.ToString ());

CFObject.CFRetain (Handle);
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
}

[DllImport(Constants.CoreMediaLibrary)]
extern static /* Float64 */ double CMTimebaseGetEffectiveRate (/* CMTimebaseRef */ IntPtr timebase);
Expand Down Expand Up @@ -215,7 +272,7 @@ public double Rate {
[Obsolete ("Starting with macos10.11 use 'CopyMasterTimebase' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
#endif
public CMTimebase GetMasterTimebase ()
public CMTimebase? GetMasterTimebase ()
{
var ptr = CMTimebaseGetMasterTimebase (Handle);
if (ptr == IntPtr.Zero)
Expand Down Expand Up @@ -246,7 +303,7 @@ public CMTimebase GetMasterTimebase ()
[Obsolete ("Starting with macos10.11 use 'CopyMasterClock' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
#endif
public CMClock GetMasterClock ()
public CMClock? GetMasterClock ()
{
var ptr = CMTimebaseGetMasterClock (Handle);
if (ptr == IntPtr.Zero)
Expand Down Expand Up @@ -277,7 +334,7 @@ public CMClock GetMasterClock ()
[Obsolete ("Starting with macos10.11 use 'CopyMaster' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
#endif
public CMClockOrTimebase GetMaster ()
public CMClockOrTimebase? GetMaster ()
{
var ptr = CMTimebaseGetMaster (Handle);
if (ptr == IntPtr.Zero)
Expand Down Expand Up @@ -308,7 +365,7 @@ public CMClockOrTimebase GetMaster ()
[Obsolete ("Starting with macos10.11 use 'CopyUltimateMasterClock' instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")]
#endif
#endif
public CMClock GetUltimateMasterClock ()
public CMClock? GetUltimateMasterClock ()
{
var ptr = CMTimebaseGetUltimateMasterClock (Handle);
if (ptr == IntPtr.Zero)
Expand Down Expand Up @@ -411,20 +468,30 @@ public CMTimebaseError SetTimerToFireImmediately (NSTimer timer)

#if !NET
[TV (13,0), Mac (10,15), iOS (13,0)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this line be removed as well?

Copy link
Member Author

@mandel-macaque mandel-macaque Sep 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want me to remove? The deprecation is needed for classic. The unsupported is needed as well, else it will use the default, since the minimum versions are 10 for iOS/tvOS, 10.4 for mac OS x and no watch. Without the Unsupported it will be assumed that they are present in those platforms. If anything we could remove the os version number.

[Deprecated (PlatformName.iOS, 8, 0)]
[Deprecated (PlatformName.TvOS, 9, 0)]
[Deprecated (PlatformName.MacOSX, 10, 10)]
[Deprecated (PlatformName.WatchOS, 6, 0)]
#else
[SupportedOSPlatform ("ios13.0")]
[SupportedOSPlatform ("tvos13.0")]
[SupportedOSPlatform ("macos10.15")]
[UnsupportedOSPlatform ("ios8.0")]
[UnsupportedOSPlatform ("tvos9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos10.10")]
#endif
[DllImport(Constants.CoreMediaLibrary)]
extern static CMTimebaseError CMTimebaseSetMasterTimebase (/* CMTimebaseRef* */ IntPtr timebase, /* CMTimebaseRef* */ IntPtr newMasterTimebase);

#if !NET
[TV (13,0), Mac (10,15), iOS (13,0)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe same with this one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same.

[Deprecated (PlatformName.iOS, 8, 0)]
[Deprecated (PlatformName.TvOS, 9, 0)]
[Deprecated (PlatformName.MacOSX, 10, 10)]
[Deprecated (PlatformName.WatchOS, 6, 0)]
#else
[SupportedOSPlatform ("ios13.0")]
[SupportedOSPlatform ("tvos13.0")]
[SupportedOSPlatform ("macos10.15")]
[UnsupportedOSPlatform ("ios8.0")]
[UnsupportedOSPlatform ("tvos9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos10.10")]
#endif
public CMTimebaseError SetMasterTimebase (CMTimebase newMasterTimebase)
{
Expand All @@ -436,20 +503,30 @@ public CMTimebaseError SetMasterTimebase (CMTimebase newMasterTimebase)

#if !NET
[TV (13,0), Mac (10,15), iOS (13,0)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

[Deprecated (PlatformName.iOS, 8, 0)]
[Deprecated (PlatformName.TvOS, 9, 0)]
[Deprecated (PlatformName.MacOSX, 10, 10)]
[Deprecated (PlatformName.WatchOS, 6, 0)]
#else
[SupportedOSPlatform ("ios13.0")]
[SupportedOSPlatform ("tvos13.0")]
[SupportedOSPlatform ("macos10.15")]
[UnsupportedOSPlatform ("ios8.0")]
[UnsupportedOSPlatform ("tvos9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos10.10")]
#endif
[DllImport(Constants.CoreMediaLibrary)]
extern static CMTimebaseError CMTimebaseSetMasterClock (/* CMTimebaseRef* */ IntPtr timebase, /* CMClockRef* */ IntPtr newMasterClock);

#if !NET
[TV (13,0), Mac (10,15), iOS (13,0)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

[Deprecated (PlatformName.iOS, 8, 0)]
[Deprecated (PlatformName.TvOS, 9, 0)]
[Deprecated (PlatformName.MacOSX, 10, 10)]
[Deprecated (PlatformName.WatchOS, 6, 0)]
#else
[SupportedOSPlatform ("ios13.0")]
[SupportedOSPlatform ("tvos13.0")]
[SupportedOSPlatform ("macos10.15")]
[UnsupportedOSPlatform ("ios8.0")]
[UnsupportedOSPlatform ("tvos9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos10.10")]
#endif
public CMTimebaseError SetMasterClock (CMClock newMasterClock)
{
Expand Down Expand Up @@ -480,7 +557,7 @@ bool IsDeprecated ()
#endif
}

public CMTimebase CopyMasterTimebase ()
public CMTimebase? CopyMasterTimebase ()
{
IntPtr ptr = IntPtr.Zero;
bool deprecated = IsDeprecated ();
Expand All @@ -497,7 +574,7 @@ public CMTimebase CopyMasterTimebase ()
return new CMTimebase (ptr, deprecated);
}

public CMClock CopyMasterClock ()
public CMClock? CopyMasterClock ()
{
IntPtr ptr = IntPtr.Zero;
bool deprecated = IsDeprecated ();
Expand All @@ -514,7 +591,7 @@ public CMClock CopyMasterClock ()
return new CMClock (ptr, deprecated);
}

public CMClockOrTimebase CopyMaster ()
public CMClockOrTimebase? CopyMaster ()
{
IntPtr ptr = IntPtr.Zero;
bool deprecated = IsDeprecated ();
Expand All @@ -531,7 +608,7 @@ public CMClockOrTimebase CopyMaster ()
return new CMClockOrTimebase (ptr, deprecated);
}

public CMClock CopyUltimateMasterClock ()
public CMClock? CopyUltimateMasterClock ()
{
IntPtr ptr = IntPtr.Zero;
bool deprecated = IsDeprecated ();
Expand All @@ -549,25 +626,61 @@ public CMClock CopyUltimateMasterClock ()
}

#if !NET
[iOS (9,0)][Mac (10,11)]
[iOS (9,0)][Mac (10,11), NoMacCatalyst]
[Deprecated (PlatformName.iOS, 9, 0, message: "Use 'CMTimebaseGetMasterTimebase' instead.")]
[Deprecated (PlatformName.TvOS, 9, 0, message: "Use 'CMTimebaseGetMasterTimebase' instead.")]
[Deprecated (PlatformName.MacOSX, 10, 11, message: "Use 'CMTimebaseGetMasterTimebase' instead.")]
[Deprecated (PlatformName.WatchOS, 6, 0, message: "Use 'CMTimebaseGetMasterTimebase' instead.")]
#else
[UnsupportedOSPlatform ("ios15.0")]
[UnsupportedOSPlatform ("tvos15.0")]
[UnsupportedOSPlatform ("maccatalyst15.0")]
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
[UnsupportedOSPlatform ("macos12.0")]
#endif
[DllImport(Constants.CoreMediaLibrary)]
static extern unsafe /* CMTimebaseRef */ IntPtr CMTimebaseCopyMasterTimebase (/* CMTimebaseRef */ IntPtr timebase);

#if !NET
[iOS (9,0)][Mac (10,11)]
[Deprecated (PlatformName.iOS, 9, 0, message: "Use 'CMTimebaseGetMasterClock' instead.")]
[Deprecated (PlatformName.TvOS, 9, 0, message: "Use 'CMTimebaseGetMasterClock' instead.")]
[Deprecated (PlatformName.MacOSX, 10, 11, message: "Use 'CMTimebaseGetMasterClock' instead.")]
[Deprecated (PlatformName.WatchOS, 6, 0, message: "Use 'CMTimebaseGetMasterClock' instead.")]
#else
[UnsupportedOSPlatform ("ios9.0")]
[UnsupportedOSPlatform ("tvos9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos10.11")]
#endif
[DllImport(Constants.CoreMediaLibrary)]
static extern unsafe /* CMClockRef */ IntPtr CMTimebaseCopyMasterClock (/* CMTimebaseRef */ IntPtr timebase);

#if !NET
[iOS (9,0)][Mac (10,11)]
[iOS (9,0)][Mac (10,11), NoMacCatalyst]
[Deprecated (PlatformName.iOS, 9, 0, message: "Use 'CMTimebaseGetMaster' instead.")]
[Deprecated (PlatformName.TvOS, 9, 0, message: "Use 'CMTimebaseGetMaster' instead.")]
[Deprecated (PlatformName.MacOSX, 10, 11, message: "Use 'CMTimebaseGetMaster' instead.")]
[Deprecated (PlatformName.WatchOS, 6, 0, message: "Use 'CMTimebaseGetMaster' instead.")]
#else
[UnsupportedOSPlatform ("ios9.0")]
[UnsupportedOSPlatform ("tvos9.0")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos10.11")]
#endif
[DllImport(Constants.CoreMediaLibrary)]
static extern unsafe IntPtr /* void* */ CMTimebaseCopyMaster (/* CMTimebaseRef */ IntPtr timebase);

#if !NET
[iOS (9,0)][Mac (10,11)]
[iOS (9,0)][Mac (10,11), NoMacCatalyst]
[Deprecated (PlatformName.iOS, 9, 0, message: "Use 'CMTimebaseGetUltimateMasterClock' instead.")]
[Deprecated (PlatformName.TvOS, 9, 0, message: "Use 'CMTimebaseGetUltimateMasterClock' instead.")]
[Deprecated (PlatformName.MacOSX, 10, 11, message: "Use 'CMTimebaseGetUltimateMasterClock' instead.")]
[Deprecated (PlatformName.WatchOS, 6, 0, message: "Use 'CMTimebaseGetUltimateMasterClock' instead.")]
#else
[UnsupportedOSPlatform ("ios15.0")]
[UnsupportedOSPlatform ("tvos15.0")]
[UnsupportedOSPlatform ("maccatalyst15.0")]
[UnsupportedOSPlatform ("macos12.0")]
#endif
[DllImport(Constants.CoreMediaLibrary)]
static extern unsafe /* CMClockRef */ IntPtr CMTimebaseCopyUltimateMasterClock (/* CMTimebaseRef */ IntPtr timebase);
Expand Down Expand Up @@ -699,6 +812,57 @@ public static bool MightDrift (CMClockOrTimebase clockOrTimebaseA, CMClockOrTime

return CMSyncMightDrift (clockOrTimebaseA.Handle, clockOrTimebaseB.Handle);
}

[Watch (6,0), TV (9,0), Mac (10,11), iOS (9,0)]
[DllImport(Constants.CoreMediaLibrary)]
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
static extern /* CMTimebase */ IntPtr CMTimebaseCopySourceTimebase (/* CMTimebase */ IntPtr timebase);

[Watch (6,0), TV (9,0), Mac (10,8), iOS (6,0)]
[DllImport(Constants.CoreMediaLibrary)]
static extern int CMTimebaseSetSourceTimebase (/* CMTimebase */ IntPtr timebase, /* CMTimebase */ IntPtr newSourceTimebase);

[Watch (6,0), TV (9,0), Mac (10,11), iOS (9,0)]
public CMTimebase? SourceTimebase {
get {
var source = CMTimebaseCopySourceTimebase (Handle);
return source == IntPtr.Zero ? null : Runtime.GetINativeObject<CMTimebase> (source, true);
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
}
set {
CMTimebaseSetSourceTimebase (Handle, value?.GetHandle () ?? IntPtr.Zero);
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
}
}

[Watch (6,0), TV (9,0), Mac (10,11), iOS (9,0)]
[DllImport(Constants.CoreMediaLibrary)]
static extern /* CMClock */ IntPtr CMTimebaseCopySourceClock (/* CMTimebase */ IntPtr timebase);

[Watch (6,0), TV (9,0), Mac (10,8), iOS (6,0)]
[DllImport(Constants.CoreMediaLibrary)]
static extern int CMTimebaseSetSourceClock (/* CMTimebase */ IntPtr timebase, /* CMClock */ IntPtr newSourceClock);

[Watch (6,0), TV (9,0), Mac (10,11), iOS (9,0)]
public CMClock? SourceClock {
get {
var clock = CMTimebaseCopySourceClock (Handle);
return clock == IntPtr.Zero ? null : Runtime.GetINativeObject<CMClock> (clock, true);
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
}
set {
CMTimebaseSetSourceClock (Handle, value?.GetHandle() ?? IntPtr.Zero);
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
}
}

[Watch (6,0), TV (9,0), Mac (10,11), iOS (9,0)]
[DllImport(Constants.CoreMediaLibrary)]
static extern /* CMClock */ IntPtr CMTimebaseCopyUltimateSourceClock (/* CMTimebase */ IntPtr timebase);

[Watch (6,0), TV (9,0), Mac (10,11), iOS (9,0)]
public CMClock? UltimateSourceClock {
get {
var clock = CMTimebaseCopyUltimateSourceClock (Handle);
return clock == IntPtr.Zero ? null : Runtime.GetINativeObject<CMClock> (clock, true);
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
}
}

#endif // !COREBUILD
}
}
Loading