From 24515e90e4c8214a3ed060131329b1af7c73fdbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Zavark=C3=B3?= Date: Tue, 8 Apr 2025 15:03:16 +0200 Subject: [PATCH] Include enums with no name --- .../generated/Enums.g.cs | 57 ++++++++++++ .../Processing/EnumerationProcessor.cs | 17 +++- .../StringHelper.cs | 88 +++++++++++++++++++ FFmpeg.AutoGen/generated/Enums.g.cs | 57 ++++++++++++ 4 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 FFmpeg.AutoGen.CppSharpUnsafeGenerator/StringHelper.cs diff --git a/FFmpeg.AutoGen.Abstractions/generated/Enums.g.cs b/FFmpeg.AutoGen.Abstractions/generated/Enums.g.cs index 11b4da87..c0f1055f 100644 --- a/FFmpeg.AutoGen.Abstractions/generated/Enums.g.cs +++ b/FFmpeg.AutoGen.Abstractions/generated/Enums.g.cs @@ -55,6 +55,17 @@ public enum AVAudioServiceType : int @AV_AUDIO_SERVICE_TYPE_NB = 9, } +/// @{ +public enum AVBuffersrcFlag : int +{ + /// Do not check for format changes. + @AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT = 1, + /// Immediately push the frame to the output. + @AV_BUFFERSRC_FLAG_PUSH = 4, + /// Keep a reference to the frame. If the frame if reference-counted, create a new reference; otherwise copy the frame data. + @AV_BUFFERSRC_FLAG_KEEP_REF = 8, +} + /// Audio channel layout utility functions public enum AVChannel : int { @@ -191,6 +202,18 @@ public enum AVCodecConfig : int @AV_CODEC_CONFIG_COLOR_SPACE = 6, } +public enum AVCodecHwConfigMethod : int +{ + /// The codec supports this format via the hw_device_ctx interface. + @AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX = 1, + /// The codec supports this format via the hw_frames_ctx interface. + @AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX = 2, + /// The codec supports this format by some internal method. + @AV_CODEC_HW_CONFIG_METHOD_INTERNAL = 4, + /// The codec supports this format by some ad-hoc method. + @AV_CODEC_HW_CONFIG_METHOD_AD_HOC = 8, +} + /// Identify the syntax and semantics of the bitstream. The principle is roughly: Two decoders with the same ID can decode the same streams. Two encoders with the same ID can encode compatible streams. There may be slight deviations from the principle due to implementation details. public enum AVCodecID : int { @@ -941,6 +964,21 @@ public enum AVFieldOrder : int @AV_FIELD_BT = 5, } +public enum AVFilterAutoConvert : int +{ + /// all automatic conversions enabled + @AVFILTER_AUTO_CONVERT_ALL = 0, + /// all automatic conversions disabled + @AVFILTER_AUTO_CONVERT_NONE = -1, +} + +/// Flags for frame cropping. +public enum AVFrameCrop : int +{ + /// Apply the maximum possible cropping, even if it requires setting the AVFrame.data[] entries to unaligned pointers. Passing unaligned data to FFmpeg API is generally not allowed, and causes undefined behavior (such as crashes). You can pass unaligned data only to FFmpeg APIs that are explicitly documented to accept it. Use this flag only if you absolutely know what you are doing. + @AV_FRAME_CROP_UNALIGNED = 1, +} + /// @{ AVFrame is an abstraction for reference-counted raw multimedia data. public enum AVFrameSideDataType : int { @@ -1030,6 +1068,19 @@ public enum AVHWDeviceType : int @AV_HWDEVICE_TYPE_D3D12VA = 12, } +/// Flags to apply to frame mappings. +public enum AVHwframeMap : int +{ + /// The mapping must be readable. + @AV_HWFRAME_MAP_READ = 1, + /// The mapping must be writeable. + @AV_HWFRAME_MAP_WRITE = 2, + /// The mapped frame will be overwritten completely in subsequent operations, so the current frame data need not be loaded. Any values which are not overwritten are unspecified. + @AV_HWFRAME_MAP_OVERWRITE = 4, + /// The mapping must be direct. That is, there must not be any copying in the map or unmap steps. Note that performance of direct mappings may be much lower than normal memory. + @AV_HWFRAME_MAP_DIRECT = 8, +} + public enum AVHWFrameTransferDirection : int { /// Transfer the data from the queried hw frame. @@ -1098,6 +1149,12 @@ public enum AVMediaType : int @AVMEDIA_TYPE_NB = 5, } +public enum AVOptFlagImplicit : int +{ + /// Accept to parse a value without a key; the key will then be returned as NULL. + @AV_OPT_FLAG_IMPLICIT_KEY = 1, +} + /// An option type determines: - for native access, the underlying C type of the field that an AVOption refers to; - for foreign access, the semantics of accessing the option through this API, e.g. which av_opt_get_*() and av_opt_set_*() functions can be called, or what format will av_opt_get()/av_opt_set() expect/produce. public enum AVOptionType : int { diff --git a/FFmpeg.AutoGen.CppSharpUnsafeGenerator/Processing/EnumerationProcessor.cs b/FFmpeg.AutoGen.CppSharpUnsafeGenerator/Processing/EnumerationProcessor.cs index 2e9db33e..a03e4e90 100644 --- a/FFmpeg.AutoGen.CppSharpUnsafeGenerator/Processing/EnumerationProcessor.cs +++ b/FFmpeg.AutoGen.CppSharpUnsafeGenerator/Processing/EnumerationProcessor.cs @@ -20,7 +20,22 @@ public void Process(TranslationUnit translationUnit) var enumerationName = enumeration.Name; if (string.IsNullOrEmpty(enumerationName)) - continue; + { + var items = enumeration.Items; + if (items.Count == 0) + continue; + + var firstItem = enumeration.Items[0]; + int idx = firstItem.Name.LastIndexOf('_'); + if (enumeration.Items.Count == 1 && idx != -1) + { + enumerationName = firstItem.Name.Substring(0, idx).ToCamelCase(); + } + else + { + enumerationName = enumeration.Items.Select(x => x.Name).FindCommonPrefix().ToCamelCase(); + } + } MakeDefinition(enumeration, enumerationName); } diff --git a/FFmpeg.AutoGen.CppSharpUnsafeGenerator/StringHelper.cs b/FFmpeg.AutoGen.CppSharpUnsafeGenerator/StringHelper.cs new file mode 100644 index 00000000..7b898eff --- /dev/null +++ b/FFmpeg.AutoGen.CppSharpUnsafeGenerator/StringHelper.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace FFmpeg.AutoGen.CppSharpUnsafeGenerator; + +internal static class StringHelper +{ + private static readonly HashSet IgnoreWords = new HashSet(StringComparer.InvariantCultureIgnoreCase) { "AV", "AVFilter" }; + + public static string FindCommonPrefix(this IEnumerable strs) + { + ReadOnlySpan common = default; + + foreach (var str in strs) + { + if (common.IsEmpty) + { + common = str.AsSpan(); + + if (common.IsEmpty) + { + break; + } + + continue; + } + + int minLength = Math.Min(common.Length, str.Length); + int commonLength = 0; + for (; commonLength < minLength; commonLength++) + { + if (common[commonLength] != str[commonLength]) + { + break; + } + } + + common = common.Slice(0, commonLength); + + if (commonLength == 0) + { + break; + } + } + + return common.Length == 0 ? string.Empty : common.ToString(); + } + + public static string ToCamelCase(this string str) + { + int idx; + var span = str.AsSpan(); + + var sb = new StringBuilder(span.Length); + while (span.Length > 0) + { + idx = span.IndexOf('_'); + ReadOnlySpan word; + + if (idx == -1) + { + word = span; + span = default; + } + else + { + word = span.Slice(0, idx); + span = span.Slice(idx + 1); + } + + if (word.Length > 0) + { + if (IgnoreWords.TryGetValue(word.ToString(), out string actual)) + { + sb.Append(actual); + } + else + { + sb.Append(char.ToUpperInvariant(word[0])); + sb.Append(word[1..].ToString().ToLowerInvariant()); + } + } + } + + return sb.ToString(); + } +} diff --git a/FFmpeg.AutoGen/generated/Enums.g.cs b/FFmpeg.AutoGen/generated/Enums.g.cs index 2a56af48..002454e7 100644 --- a/FFmpeg.AutoGen/generated/Enums.g.cs +++ b/FFmpeg.AutoGen/generated/Enums.g.cs @@ -55,6 +55,17 @@ public enum AVAudioServiceType : int @AV_AUDIO_SERVICE_TYPE_NB = 9, } +/// @{ +public enum AVBuffersrcFlag : int +{ + /// Do not check for format changes. + @AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT = 1, + /// Immediately push the frame to the output. + @AV_BUFFERSRC_FLAG_PUSH = 4, + /// Keep a reference to the frame. If the frame if reference-counted, create a new reference; otherwise copy the frame data. + @AV_BUFFERSRC_FLAG_KEEP_REF = 8, +} + /// Audio channel layout utility functions public enum AVChannel : int { @@ -191,6 +202,18 @@ public enum AVCodecConfig : int @AV_CODEC_CONFIG_COLOR_SPACE = 6, } +public enum AVCodecHwConfigMethod : int +{ + /// The codec supports this format via the hw_device_ctx interface. + @AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX = 1, + /// The codec supports this format via the hw_frames_ctx interface. + @AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX = 2, + /// The codec supports this format by some internal method. + @AV_CODEC_HW_CONFIG_METHOD_INTERNAL = 4, + /// The codec supports this format by some ad-hoc method. + @AV_CODEC_HW_CONFIG_METHOD_AD_HOC = 8, +} + /// Identify the syntax and semantics of the bitstream. The principle is roughly: Two decoders with the same ID can decode the same streams. Two encoders with the same ID can encode compatible streams. There may be slight deviations from the principle due to implementation details. public enum AVCodecID : int { @@ -941,6 +964,21 @@ public enum AVFieldOrder : int @AV_FIELD_BT = 5, } +public enum AVFilterAutoConvert : int +{ + /// all automatic conversions enabled + @AVFILTER_AUTO_CONVERT_ALL = 0, + /// all automatic conversions disabled + @AVFILTER_AUTO_CONVERT_NONE = -1, +} + +/// Flags for frame cropping. +public enum AVFrameCrop : int +{ + /// Apply the maximum possible cropping, even if it requires setting the AVFrame.data[] entries to unaligned pointers. Passing unaligned data to FFmpeg API is generally not allowed, and causes undefined behavior (such as crashes). You can pass unaligned data only to FFmpeg APIs that are explicitly documented to accept it. Use this flag only if you absolutely know what you are doing. + @AV_FRAME_CROP_UNALIGNED = 1, +} + /// @{ AVFrame is an abstraction for reference-counted raw multimedia data. public enum AVFrameSideDataType : int { @@ -1030,6 +1068,19 @@ public enum AVHWDeviceType : int @AV_HWDEVICE_TYPE_D3D12VA = 12, } +/// Flags to apply to frame mappings. +public enum AVHwframeMap : int +{ + /// The mapping must be readable. + @AV_HWFRAME_MAP_READ = 1, + /// The mapping must be writeable. + @AV_HWFRAME_MAP_WRITE = 2, + /// The mapped frame will be overwritten completely in subsequent operations, so the current frame data need not be loaded. Any values which are not overwritten are unspecified. + @AV_HWFRAME_MAP_OVERWRITE = 4, + /// The mapping must be direct. That is, there must not be any copying in the map or unmap steps. Note that performance of direct mappings may be much lower than normal memory. + @AV_HWFRAME_MAP_DIRECT = 8, +} + public enum AVHWFrameTransferDirection : int { /// Transfer the data from the queried hw frame. @@ -1098,6 +1149,12 @@ public enum AVMediaType : int @AVMEDIA_TYPE_NB = 5, } +public enum AVOptFlagImplicit : int +{ + /// Accept to parse a value without a key; the key will then be returned as NULL. + @AV_OPT_FLAG_IMPLICIT_KEY = 1, +} + /// An option type determines: - for native access, the underlying C type of the field that an AVOption refers to; - for foreign access, the semantics of accessing the option through this API, e.g. which av_opt_get_*() and av_opt_set_*() functions can be called, or what format will av_opt_get()/av_opt_set() expect/produce. public enum AVOptionType : int {