Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
60 changes: 60 additions & 0 deletions src/CoreMediaIO/CMIODeviceAvcCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#nullable enable

using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using ObjCRuntime;

namespace CoreMediaIO {

/// <summary>Represents an Audio Video Control (AVC) command to be sent to a CoreMediaIO device.</summary>
/// <remarks>
/// <para>The AVC protocol is used for device control over IEEE 1394 (FireWire) connections.</para>
/// <para>The <see cref="Command" /> and <see cref="Response" /> fields point to caller-owned byte buffers.
/// These buffers must remain valid for the duration of the native call that uses this struct.</para>
/// </remarks>
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst15.4")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("tvos")]
[NativeName ("CMIODeviceAVCCommand")]
[StructLayout (LayoutKind.Sequential)]
public struct CMIODeviceAvcCommand {
IntPtr mCommand;
uint mCommandLength;
IntPtr mResponse;
uint mResponseLength;
uint mResponseUsed;

#if !COREBUILD
/// <summary>Gets or sets a pointer to the buffer containing the AVC command bytes to send.</summary>
public IntPtr Command {
get => mCommand;
set => mCommand = value;
}

/// <summary>Gets or sets the size (in bytes) of the <see cref="Command" /> buffer.</summary>
public uint CommandLength {
get => mCommandLength;
set => mCommandLength = value;
}

/// <summary>Gets or sets a pointer to the buffer that will receive the AVC response bytes.</summary>
public IntPtr Response {
get => mResponse;
set => mResponse = value;
}

/// <summary>Gets or sets the size (in bytes) of the <see cref="Response" /> buffer.</summary>
public uint ResponseLength {
get => mResponseLength;
set => mResponseLength = value;
}

/// <summary>Gets the actual number of response bytes written to the <see cref="Response" /> buffer.</summary>
public uint ResponseUsed {
get => mResponseUsed;
}
#endif // !COREBUILD
}
}
60 changes: 60 additions & 0 deletions src/CoreMediaIO/CMIODeviceRS422Command.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#nullable enable

using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using ObjCRuntime;

namespace CoreMediaIO {

/// <summary>Represents an RS-422 serial protocol command to be sent to a CoreMediaIO device.</summary>
/// <remarks>
/// <para>RS-422 is a serial communication protocol commonly used for professional video deck control.</para>
/// <para>The <see cref="Command" /> and <see cref="Response" /> fields point to caller-owned byte buffers.
/// These buffers must remain valid for the duration of the native call that uses this struct.</para>
/// </remarks>
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst15.4")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("tvos")]
[NativeName ("CMIODeviceRS422Command")]
[StructLayout (LayoutKind.Sequential)]
public struct CMIODeviceRS422Command {
IntPtr mCommand;
uint mCommandLength;
IntPtr mResponse;
uint mResponseLength;
uint mResponseUsed;

#if !COREBUILD
/// <summary>Gets or sets a pointer to the buffer containing the RS-422 command bytes to send.</summary>
public IntPtr Command {
get => mCommand;
set => mCommand = value;
}

/// <summary>Gets or sets the size (in bytes) of the <see cref="Command" /> buffer.</summary>
public uint CommandLength {
get => mCommandLength;
set => mCommandLength = value;
}

/// <summary>Gets or sets a pointer to the buffer that will receive the RS-422 response bytes.</summary>
public IntPtr Response {
get => mResponse;
set => mResponse = value;
}

/// <summary>Gets or sets the size (in bytes) of the <see cref="Response" /> buffer.</summary>
public uint ResponseLength {
get => mResponseLength;
set => mResponseLength = value;
}

/// <summary>Gets the actual number of response bytes written to the <see cref="Response" /> buffer.</summary>
public uint ResponseUsed {
get => mResponseUsed;
}
#endif // !COREBUILD
}
}
124 changes: 124 additions & 0 deletions src/CoreMediaIO/CMIOInterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#nullable enable

using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using CoreMedia;
using ObjCRuntime;

namespace CoreMediaIO {

#if !COREBUILD
/// <summary>Low-level P/Invoke declarations for CoreMediaIO hardware object, device, stream, and sample buffer C functions.</summary>
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst15.4")]
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("tvos")]
internal static unsafe class CMIOInterop {

// CMIOHardwareObject.h

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern void CMIOObjectShow (uint objectId);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern byte CMIOObjectHasProperty (uint objectId, CMIOObjectPropertyAddress* address);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOObjectIsPropertySettable (uint objectId, CMIOObjectPropertyAddress* address, byte* isSettable);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOObjectGetPropertyDataSize (uint objectId, CMIOObjectPropertyAddress* address, uint qualifierDataSize, IntPtr qualifierData, uint* dataSize);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOObjectGetPropertyData (uint objectId, CMIOObjectPropertyAddress* address, uint qualifierDataSize, IntPtr qualifierData, uint dataSize, uint* dataUsed, IntPtr data);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOObjectSetPropertyData (uint objectId, CMIOObjectPropertyAddress* address, uint qualifierDataSize, IntPtr qualifierData, uint dataSize, IntPtr data);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOObjectAddPropertyListener (uint objectId, CMIOObjectPropertyAddress* address, IntPtr listener, IntPtr clientData);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOObjectRemovePropertyListener (uint objectId, CMIOObjectPropertyAddress* address, IntPtr listener, IntPtr clientData);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOObjectAddPropertyListenerBlock (uint objectId, CMIOObjectPropertyAddress* address, IntPtr dispatchQueue, IntPtr listener);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOObjectRemovePropertyListenerBlock (uint objectId, CMIOObjectPropertyAddress* address, IntPtr dispatchQueue, IntPtr listener);

// CMIOHardwareDevice.h

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIODeviceStartStream (uint deviceId, uint streamId);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIODeviceStopStream (uint deviceId, uint streamId);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIODeviceProcessAVCCommand (uint deviceId, CMIODeviceAvcCommand* ioAvcCommand);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIODeviceProcessRS422Command (uint deviceId, CMIODeviceRS422Command* ioRS422Command);

// CMIOHardwareStream.h

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOStreamCopyBufferQueue (uint streamId, IntPtr queueAlteredProc, IntPtr queueAlteredRefCon, IntPtr* queue);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOStreamDeckPlay (uint streamId);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOStreamDeckStop (uint streamId);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOStreamDeckJog (uint streamId, int speed);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOStreamDeckCueTo (uint streamId, ulong frameNumber, byte playOnCue);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOStreamClockCreate (IntPtr allocator, IntPtr clockName, IntPtr sourceIdentifier, CMTime getTimeCallMinimumInterval, uint numberOfEventsForRateSmoothing, uint numberOfAveragesForRateSmoothing, IntPtr* clock);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOStreamClockPostTimingEvent (CMTime eventTime, ulong hostTime, byte resynchronize, IntPtr clock);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOStreamClockInvalidate (IntPtr clock);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern CMTime CMIOStreamClockConvertHostTimeToDeviceTime (ulong hostTime, IntPtr clock);

// CMIOSampleBuffer.h

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOSampleBufferCreate (IntPtr allocator, IntPtr dataBuffer, IntPtr formatDescription, uint numSamples, uint numSampleTimingEntries, CMSampleTimingInfo* sampleTimingArray, uint numSampleSizeEntries, nuint* sampleSizeArray, ulong sequenceNumber, uint discontinuityFlags, IntPtr* sampleBufferOut);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOSampleBufferCreateForImageBuffer (IntPtr allocator, IntPtr imageBuffer, IntPtr formatDescription, CMSampleTimingInfo* sampleTiming, ulong sequenceNumber, uint discontinuityFlags, IntPtr* sampleBufferOut);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOSampleBufferCreateNoDataMarker (IntPtr allocator, uint noDataEvent, IntPtr formatDescription, ulong sequenceNumber, uint discontinuityFlags, IntPtr* sampleBufferOut);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern void CMIOSampleBufferSetSequenceNumber (IntPtr allocator, IntPtr sampleBuffer, ulong sequenceNumber);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern ulong CMIOSampleBufferGetSequenceNumber (IntPtr sampleBuffer);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern void CMIOSampleBufferSetDiscontinuityFlags (IntPtr allocator, IntPtr sampleBuffer, uint discontinuityFlags);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern uint CMIOSampleBufferGetDiscontinuityFlags (IntPtr sampleBuffer);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOSampleBufferCopyNonRequiredAttachments (IntPtr sourceSampleBuffer, IntPtr destinationSampleBuffer, uint attachmentMode);

[DllImport (Constants.CoreMediaIOLibrary)]
internal static extern int CMIOSampleBufferCopySampleAttachments (IntPtr sourceSampleBuffer, IntPtr destinationSampleBuffer);
}
#endif // !COREBUILD
}
Loading
Loading