Skip to content

Commit

Permalink
Use ICustomMarshaler for missing UnmanagedType.LPUTF8Str in .NET Stan…
Browse files Browse the repository at this point in the history
…dard 2.0 or lower (#212)

Co-authored-by: Ruslan Balanukhin <[email protected]>
  • Loading branch information
Ruslan-B and Ruslan Balanukhin committed Aug 8, 2022
1 parent 5194d11 commit 44f6558
Show file tree
Hide file tree
Showing 8 changed files with 956 additions and 1,183 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<PackageId>$(AssemblyName)</PackageId>
<Version>5.1</Version>
<Version>5.1.1</Version>
<Authors>Ruslan Balanukhin</Authors>
<Company>Rational Core</Company>
<Product>FFmpeg.AutoGen</Product>
Expand Down
39 changes: 4 additions & 35 deletions FFmpeg.AutoGen.ClangMacroParser/Tokenization/Tokenizer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright 2017 Baker Hughes. All rights reserved. Company proprietary and confidential.

using System;
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -17,38 +15,9 @@ public static class Tokenizer

private static readonly HashSet<string> Keywords = new()
{
"auto",
"break",
"case",
"char",
"const",
"continue",
"default",
"do",
"double",
"else",
"enum",
"extern",
"float",
"for",
"goto",
"if",
"int",
"long",
"register",
"return",
"short",
"signed",
"sizeof",
"static",
"struct",
"switch",
"typedef",
"union",
"unsigned",
"void",
"volatile",
"while"
"auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float",
"for", "goto", "if", "int", "long", "register", "return", "short", "signed", "sizeof", "static", "struct", "switch",
"typedef", "union", "unsigned", "void", "volatile", "while"
};

public static IEnumerable<Token> Tokenize(string expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ internal class FunctionProcessor
{
private const string MarshalAsUtf8Macros =
"\r\n" +
" #if NET40\r\n" +
" #elif NET45 || NETSTANDARD2_0\r\n" +
" [MarshalAs((UnmanagedType)48)]\r\n" +
" #else\r\n" +
" #if NETSTANDARD2_1_OR_GREATER\r\n" +
" [MarshalAs(UnmanagedType.LPUTF8Str)]\r\n" +
" #else\r\n" +
" [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]\r\n" +
" #endif\r\n" +
" ";

Expand Down
4 changes: 2 additions & 2 deletions FFmpeg.AutoGen.Examples.ResamplingAudio/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ internal unsafe class Program
{
static int Main(string[] args)
{
int sourceChannelLayout = ffmpeg.AV_CH_LAYOUT_STEREO;
int destinationChannelLayout = ffmpeg.AV_CH_LAYOUT_SURROUND;
long sourceChannelLayout = (long)ffmpeg.AV_CH_LAYOUT_STEREO;
long destinationChannelLayout = (long)ffmpeg.AV_CH_LAYOUT_SURROUND;
int sourceSampleRate = 48000;
int destinationSampleRate = 44100;
byte** sourceData = null;
Expand Down
2 changes: 1 addition & 1 deletion FFmpeg.AutoGen/FFmpeg.AutoGen.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net472;net45;net40</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net472;net45</TargetFrameworks>
<GeneratePackageOnBuild Condition=" $(Configuration) == 'Release' ">true</GeneratePackageOnBuild>
<Description>FFmpeg auto generated unsafe bindings for C#/.NET and Mono.</Description>
</PropertyGroup>
Expand Down
35 changes: 15 additions & 20 deletions FFmpeg.AutoGen/FFmpeg.delegates.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ public unsafe struct AVClass_get_category_func

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate int AVClass_query_ranges (AVOptionRanges** @p0, void* @obj,
#if NET40
#elif NET45 || NETSTANDARD2_0
[MarshalAs((UnmanagedType)48)]
#else
#if NETSTANDARD2_1_OR_GREATER
[MarshalAs(UnmanagedType.LPUTF8Str)]
#else
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]
#endif
string @key, int @flags);
public unsafe struct AVClass_query_ranges_func
Expand Down Expand Up @@ -428,11 +427,10 @@ public unsafe struct AVFormatContext_control_message_cb_func

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate int AVFormatContext_io_open (AVFormatContext* @s, AVIOContext** @pb,
#if NET40
#elif NET45 || NETSTANDARD2_0
[MarshalAs((UnmanagedType)48)]
#else
#if NETSTANDARD2_1_OR_GREATER
[MarshalAs(UnmanagedType.LPUTF8Str)]
#else
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]
#endif
string @url, int @flags, AVDictionary** @options);
public unsafe struct AVFormatContext_io_open_func
Expand Down Expand Up @@ -595,18 +593,16 @@ public unsafe struct _query_func_func

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate int AVFilter_process_command (AVFilterContext* @p0,
#if NET40
#elif NET45 || NETSTANDARD2_0
[MarshalAs((UnmanagedType)48)]
#else
#if NETSTANDARD2_1_OR_GREATER
[MarshalAs(UnmanagedType.LPUTF8Str)]
#else
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]
#endif
string @cmd,
#if NET40
#elif NET45 || NETSTANDARD2_0
[MarshalAs((UnmanagedType)48)]
#else
#if NETSTANDARD2_1_OR_GREATER
[MarshalAs(UnmanagedType.LPUTF8Str)]
#else
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]
#endif
string @arg, byte* @res, int @res_len, int @flags);
public unsafe struct AVFilter_process_command_func
Expand Down Expand Up @@ -641,11 +637,10 @@ public unsafe struct AVFilterGraph_execute_func

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void av_log_set_callback_callback (void* @p0, int @p1,
#if NET40
#elif NET45 || NETSTANDARD2_0
[MarshalAs((UnmanagedType)48)]
#else
#if NETSTANDARD2_1_OR_GREATER
[MarshalAs(UnmanagedType.LPUTF8Str)]
#else
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]
#endif
string @p2, byte* @p3);
public unsafe struct av_log_set_callback_callback_func
Expand Down
Loading

0 comments on commit 44f6558

Please sign in to comment.