-
-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First prototype * First - something is working version * Drop old generator and update example to use new packages * simplify bindings * Working version * Test Dynamically Linked version * Working version * Add bsf.h * FunctionLoader -> FunctionResolver * Fix typo * Fix namings * Add in modifier for const fixed arrays #221 * Fix build warnings * Fix example project * Improve solution navigation Co-authored-by: Ruslan Balanukhin <[email protected]>
- Loading branch information
Showing
124 changed files
with
52,536 additions
and
27,070 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace FFmpeg.AutoGen.Abstractions; | ||
|
||
public class ConstCharPtrMarshaler : ICustomMarshaler | ||
{ | ||
private static readonly ConstCharPtrMarshaler Instance = new(); | ||
public object MarshalNativeToManaged(IntPtr pNativeData) => Marshal.PtrToStringAnsi(pNativeData); | ||
|
||
public IntPtr MarshalManagedToNative(object managedObj) => IntPtr.Zero; | ||
|
||
public void CleanUpNativeData(IntPtr pNativeData) | ||
{ | ||
} | ||
|
||
public void CleanUpManagedData(object managedObj) | ||
{ | ||
} | ||
|
||
public int GetNativeDataSize() => IntPtr.Size; | ||
|
||
public static ICustomMarshaler GetInstance(string cookie) => Instance; | ||
} |
31 changes: 31 additions & 0 deletions
31
FFmpeg.AutoGen.Abstractions/FFmpeg.AutoGen.Abstractions.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.1;netstandard2.0;net45</TargetFrameworks> | ||
<Description>FFmpeg auto generated unsafe bindings for C#/.NET and Mono. Abstractions todo</Description> | ||
<GeneratePackageOnBuild Condition=" $(Configuration) == 'Release' ">true</GeneratePackageOnBuild> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||
<NoWarn>108;169;612;618;1573;1591;1701;1702;1705</NoWarn> | ||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> | ||
<WarningsAsErrors /> | ||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<!-- Build symbol package (.snupkg) to distribute the PDB containing Source Link --> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="4.2.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace FFmpeg.AutoGen.Abstractions; | ||
|
||
public static partial class ffmpeg | ||
{ | ||
public static readonly int EAGAIN; | ||
|
||
public static readonly int ENOMEM = 12; | ||
|
||
public static readonly int EINVAL = 22; | ||
|
||
public static readonly int EPIPE = 32; | ||
|
||
static ffmpeg() | ||
{ | ||
#if NET | ||
|
||
#elif NETSTANDARD2_0_OR_GREATER | ||
EAGAIN = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? 35 : 11; | ||
#else | ||
EAGAIN = Environment.OSVersion.Platform == PlatformID.MacOSX ? 35 : 11; | ||
#endif | ||
|
||
} | ||
|
||
public static ulong UINT64_C<T>(T a) | ||
=> Convert.ToUInt64(a); | ||
|
||
public static int AVERROR<T1>(T1 a) | ||
=> -Convert.ToInt32(a); | ||
|
||
public static int MKTAG<T1, T2, T3, T4>(T1 a, T2 b, T3 c, T4 d) | ||
=> (int)(Convert.ToUInt32(a) | (Convert.ToUInt32(b) << 8) | (Convert.ToUInt32(c) << 16) | | ||
(Convert.ToUInt32(d) << 24)); | ||
|
||
public static int FFERRTAG<T1, T2, T3, T4>(T1 a, T2 b, T3 c, T4 d) | ||
=> -MKTAG(a, b, c, d); | ||
|
||
public static int AV_VERSION_INT<T1, T2, T3>(T1 a, T2 b, T3 c) => | ||
(Convert.ToInt32(a) << 16) | (Convert.ToInt32(b) << 8) | Convert.ToInt32(c); | ||
|
||
public static string AV_VERSION_DOT<T1, T2, T3>(T1 a, T2 b, T3 c) | ||
=> $"{a}.{b}.{c}"; | ||
|
||
public static string AV_VERSION<T1, T2, T3>(T1 a, T2 b, T3 c) | ||
=> AV_VERSION_DOT(a, b, c); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace FFmpeg.AutoGen.Abstractions; | ||
|
||
public interface IFixedArray | ||
{ | ||
int Length { get; } | ||
} | ||
|
||
internal interface IFixedArray<T> : IFixedArray | ||
{ | ||
T this[uint index] { get; set; } | ||
T[] ToArray(); | ||
void UpdateFrom(T[] array); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace FFmpeg.AutoGen.Abstractions; | ||
|
||
public class UTF8Marshaler : ICustomMarshaler | ||
{ | ||
private static readonly UTF8Marshaler Instance = new(); | ||
|
||
public virtual object MarshalNativeToManaged(IntPtr pNativeData) => FromNative(Encoding.UTF8, pNativeData); | ||
|
||
public virtual IntPtr MarshalManagedToNative(object managedObj) | ||
{ | ||
if (managedObj == null) | ||
return IntPtr.Zero; | ||
|
||
if (managedObj is not string str) | ||
throw new MarshalDirectiveException($"{GetType().Name} must be used on a string."); | ||
|
||
return FromManaged(Encoding.UTF8, str); | ||
} | ||
|
||
public virtual void CleanUpNativeData(IntPtr pNativeData) | ||
{ | ||
//Free anything allocated by MarshalManagedToNative | ||
//This is called after the native function call completes | ||
|
||
if (pNativeData != IntPtr.Zero) | ||
Marshal.FreeHGlobal(pNativeData); | ||
} | ||
|
||
public void CleanUpManagedData(object managedObj) | ||
{ | ||
//Free anything allocated by MarshalNativeToManaged | ||
//This is called after the native function call completes | ||
} | ||
|
||
public int GetNativeDataSize() => -1; // Not a value type | ||
|
||
public static ICustomMarshaler GetInstance(string cookie) => Instance; | ||
|
||
public static unsafe string FromNative(Encoding encoding, IntPtr pNativeData) => FromNative(encoding, (byte*)pNativeData); | ||
|
||
public static unsafe string FromNative(Encoding encoding, byte* pNativeData) | ||
{ | ||
if (pNativeData == null) | ||
return null; | ||
|
||
var start = pNativeData; | ||
var walk = start; | ||
|
||
// Find the end of the string | ||
while (*walk != 0) walk++; | ||
|
||
if (walk == start) | ||
return string.Empty; | ||
|
||
return new string((sbyte*)pNativeData, 0, (int)(walk - start), encoding); | ||
} | ||
|
||
public static unsafe IntPtr FromManaged(Encoding encoding, string value) | ||
{ | ||
if (encoding == null || value == null) | ||
return IntPtr.Zero; | ||
|
||
var length = encoding.GetByteCount(value); | ||
var buffer = (byte*)Marshal.AllocHGlobal(length + 1).ToPointer(); | ||
|
||
if (length > 0) | ||
{ | ||
fixed (char* pValue = value) | ||
{ | ||
encoding.GetBytes(pValue, value.Length, buffer, length); | ||
} | ||
} | ||
|
||
buffer[length] = 0; | ||
|
||
return new IntPtr(buffer); | ||
} | ||
} |
Oops, something went wrong.