Skip to content
Open
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
62 changes: 34 additions & 28 deletions FFmpeg.AutoGen.Abstractions/generated/Enums.g.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace FFmpeg.AutoGen.Abstractions;

public enum AVActiveFormatDescription : int
Expand Down Expand Up @@ -1051,10 +1053,11 @@ public enum AVFormatCommandID : int
}

/// <summary>Flags for frame cropping.</summary>
[Flags]
public enum AvFrameCrop : int
{
/// <summary>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.</summary>
@AV_FRAME_CROP_UNALIGNED = 1,
@AV_FRAME_CROP_UNALIGNED = 1 << 0,
}

/// <summary>@{ AVFrame is an abstraction for reference-counted raw multimedia data.</summary>
Expand Down Expand Up @@ -1153,16 +1156,17 @@ public enum AVHWDeviceType : int
}

/// <summary>Flags to apply to frame mappings.</summary>
[Flags]
public enum AvHwframeMap : int
{
/// <summary>The mapping must be readable.</summary>
@AV_HWFRAME_MAP_READ = 1,
@AV_HWFRAME_MAP_READ = 1 << 0,
/// <summary>The mapping must be writeable.</summary>
@AV_HWFRAME_MAP_WRITE = 2,
@AV_HWFRAME_MAP_WRITE = 1 << 1,
/// <summary>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.</summary>
@AV_HWFRAME_MAP_OVERWRITE = 4,
@AV_HWFRAME_MAP_OVERWRITE = 1 << 2,
/// <summary>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.</summary>
@AV_HWFRAME_MAP_DIRECT = 8,
@AV_HWFRAME_MAP_DIRECT = 1 << 3,
}

public enum AVHWFrameTransferDirection : int
Expand Down Expand Up @@ -2069,14 +2073,15 @@ public enum AVTimebaseSource : int
@AVFMT_TBCF_R_FRAMERATE = 2,
}

[Flags]
public enum AVTimecodeFlag : int
{
/// <summary>timecode is drop frame</summary>
@AV_TIMECODE_FLAG_DROPFRAME = 1,
@AV_TIMECODE_FLAG_DROPFRAME = 1 << 0,
/// <summary>timecode wraps after 24 hours</summary>
@AV_TIMECODE_FLAG_24HOURSMAX = 2,
@AV_TIMECODE_FLAG_24HOURSMAX = 1 << 1,
/// <summary>negative time values are allowed</summary>
@AV_TIMECODE_FLAG_ALLOWNEGATIVE = 4,
@AV_TIMECODE_FLAG_ALLOWNEGATIVE = 1 << 2,
}

/// <summary>Dithering algorithms</summary>
Expand Down Expand Up @@ -2143,48 +2148,49 @@ public enum SwsDither : int
@SWS_DITHER_MAX_ENUM = 2147483647,
}

[Flags]
public enum SwsFlags : int
{
/// <summary>fast bilinear filtering</summary>
@SWS_FAST_BILINEAR = 1,
@SWS_FAST_BILINEAR = 1 << 0,
/// <summary>bilinear filtering</summary>
@SWS_BILINEAR = 2,
@SWS_BILINEAR = 1 << 1,
/// <summary>2-tap cubic B-spline</summary>
@SWS_BICUBIC = 4,
@SWS_BICUBIC = 1 << 2,
/// <summary>experimental</summary>
@SWS_X = 8,
@SWS_X = 1 << 3,
/// <summary>nearest neighbor</summary>
@SWS_POINT = 16,
@SWS_POINT = 1 << 4,
/// <summary>area averaging</summary>
@SWS_AREA = 32,
@SWS_AREA = 1 << 5,
/// <summary>bicubic luma, bilinear chroma</summary>
@SWS_BICUBLIN = 64,
@SWS_BICUBLIN = 1 << 6,
/// <summary>gaussian approximation</summary>
@SWS_GAUSS = 128,
@SWS_GAUSS = 1 << 7,
/// <summary>unwindowed sinc</summary>
@SWS_SINC = 256,
@SWS_SINC = 1 << 8,
/// <summary>3-tap sinc/sinc</summary>
@SWS_LANCZOS = 512,
@SWS_LANCZOS = 1 << 9,
/// <summary>cubic Keys spline</summary>
@SWS_SPLINE = 1024,
@SWS_SPLINE = 1 << 10,
/// <summary>Return an error on underspecified conversions. Without this flag, unspecified fields are defaulted to sensible values.</summary>
@SWS_STRICT = 2048,
@SWS_STRICT = 1 << 11,
/// <summary>Emit verbose log of scaling parameters.</summary>
@SWS_PRINT_INFO = 4096,
@SWS_PRINT_INFO = 1 << 12,
/// <summary>Perform full chroma upsampling when upscaling to RGB.</summary>
@SWS_FULL_CHR_H_INT = 8192,
@SWS_FULL_CHR_H_INT = 1 << 13,
/// <summary>Perform full chroma interpolation when downscaling RGB sources.</summary>
@SWS_FULL_CHR_H_INP = 16384,
@SWS_FULL_CHR_H_INP = 1 << 14,
/// <summary>Force bit-exact output. This will prevent the use of platform-specific optimizations that may lead to slight difference in rounding, in favor of always maintaining exact bit output compatibility with the reference C code.</summary>
@SWS_ACCURATE_RND = 262144,
@SWS_ACCURATE_RND = 1 << 18,
/// <summary>Force bit-exact output. This will prevent the use of platform-specific optimizations that may lead to slight difference in rounding, in favor of always maintaining exact bit output compatibility with the reference C code.</summary>
@SWS_BITEXACT = 524288,
@SWS_BITEXACT = 1 << 19,
/// <summary>Allow using experimental new code paths. This may be faster, slower, or produce different output, with semantics subject to change at any point in time. For testing and debugging purposes only.</summary>
@SWS_UNSTABLE = 1048576,
@SWS_UNSTABLE = 1 << 20,
/// <summary>This flag has no effect</summary>
@SWS_DIRECT_BGR = 32768,
@SWS_DIRECT_BGR = 1 << 15,
/// <summary>Set `SwsContext.dither` instead</summary>
@SWS_ERROR_DIFFUSION = 8388608,
@SWS_ERROR_DIFFUSION = 1 << 23,
}

public enum SwsIntent : int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using FFmpeg.AutoGen.CppSharpUnsafeGenerator.Definitions;
using System.Collections.Generic;
using System.Linq;
using FFmpeg.AutoGen.CppSharpUnsafeGenerator.Definitions;

namespace FFmpeg.AutoGen.CppSharpUnsafeGenerator.Generation;

Expand All @@ -8,6 +10,11 @@ public EnumsGenerator(string path, GenerationContext context) : base(path, conte
{
}

public override IEnumerable<string> Usings()
{
yield return "System";
}

public static void Generate(string path, GenerationContext context)
{
using var g = new EnumsGenerator(path, context);
Expand All @@ -18,6 +25,12 @@ protected override void GenerateDefinition(EnumerationDefinition @enum)
{
this.WriteSummary(@enum);
this.WriteObsoletion(@enum);

// if every item in the enum is in the form 1 << n, then we will treat it
// as a flags enum
if (@enum.Items.All(test => test.Value.Contains("<<")))
WriteLine("[Flags]");

WriteLine($"public enum {@enum.Name} : {@enum.TypeName}");

using (BeginBlock())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using FFmpeg.AutoGen.CppSharpUnsafeGenerator.Definitions;

namespace FFmpeg.AutoGen.CppSharpUnsafeGenerator.Processing;

internal class EnumerationProcessor
internal partial class EnumerationProcessor
{
private readonly ProcessingContext _context;

Expand Down Expand Up @@ -81,7 +82,7 @@ public void MakeDefinition(Enumeration enumeration, string name)
new EnumerationItem
{
Name = x.Name,
Value = ConvertValue(x.Value, enumeration.BuiltinType.Type).ToString(),
Value = ConvertValue(x.Expression, x.Value, enumeration.BuiltinType.Type).ToString(),
Content = x.Comment?.BriefText
})
.ToArray()
Expand All @@ -90,15 +91,40 @@ public void MakeDefinition(Enumeration enumeration, string name)
_context.AddDefinition(definition);
}

private static object ConvertValue(ulong value, PrimitiveType primitiveType)
// A regular expression that looks if the expression ends in "= 1 << n" (with any
// number of spaces between the elements.
[GeneratedRegex(@"=\s*1\s*<<\s*(\d+)\s*$")]
private static partial Regex CheckForBitExpression();

private static string ConvertValue(string expression, ulong value, PrimitiveType primitiveType)
{
return primitiveType switch
// Check if the expression is of the form 1 << n. If it is, preserve the original definition
// instead of collapsing the value.
if (CheckForBitExpression().Match(expression) is { Success: true } match)
{
// Keep it as a 1 << n in the output. We will always
// return it in the form "1 << n" with that exact spacing.
var suffix = primitiveType switch
{
PrimitiveType.Int => "",
PrimitiveType.UInt => "u",
PrimitiveType.Long => "l",
PrimitiveType.ULong => "ul",
_ => throw new NotSupportedException()
};

return $"1{suffix} << {match.Groups[1].Value}";
}

// Otherwise, fallback on using the compiler's value
object compilerValue = primitiveType switch
{
PrimitiveType.Int => value > int.MaxValue ? (int)value : value,
PrimitiveType.UInt => value,
PrimitiveType.Long => value > long.MaxValue ? (long)value : value,
PrimitiveType.ULong => value,
_ => throw new NotSupportedException()
};
return compilerValue.ToString();
}
}
62 changes: 34 additions & 28 deletions FFmpeg.AutoGen/generated/Enums.g.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace FFmpeg.AutoGen;

public enum AVActiveFormatDescription : int
Expand Down Expand Up @@ -1051,10 +1053,11 @@ public enum AVFormatCommandID : int
}

/// <summary>Flags for frame cropping.</summary>
[Flags]
public enum AvFrameCrop : int
{
/// <summary>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.</summary>
@AV_FRAME_CROP_UNALIGNED = 1,
@AV_FRAME_CROP_UNALIGNED = 1 << 0,
}

/// <summary>@{ AVFrame is an abstraction for reference-counted raw multimedia data.</summary>
Expand Down Expand Up @@ -1153,16 +1156,17 @@ public enum AVHWDeviceType : int
}

/// <summary>Flags to apply to frame mappings.</summary>
[Flags]
public enum AvHwframeMap : int
{
/// <summary>The mapping must be readable.</summary>
@AV_HWFRAME_MAP_READ = 1,
@AV_HWFRAME_MAP_READ = 1 << 0,
/// <summary>The mapping must be writeable.</summary>
@AV_HWFRAME_MAP_WRITE = 2,
@AV_HWFRAME_MAP_WRITE = 1 << 1,
/// <summary>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.</summary>
@AV_HWFRAME_MAP_OVERWRITE = 4,
@AV_HWFRAME_MAP_OVERWRITE = 1 << 2,
/// <summary>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.</summary>
@AV_HWFRAME_MAP_DIRECT = 8,
@AV_HWFRAME_MAP_DIRECT = 1 << 3,
}

public enum AVHWFrameTransferDirection : int
Expand Down Expand Up @@ -2069,14 +2073,15 @@ public enum AVTimebaseSource : int
@AVFMT_TBCF_R_FRAMERATE = 2,
}

[Flags]
public enum AVTimecodeFlag : int
{
/// <summary>timecode is drop frame</summary>
@AV_TIMECODE_FLAG_DROPFRAME = 1,
@AV_TIMECODE_FLAG_DROPFRAME = 1 << 0,
/// <summary>timecode wraps after 24 hours</summary>
@AV_TIMECODE_FLAG_24HOURSMAX = 2,
@AV_TIMECODE_FLAG_24HOURSMAX = 1 << 1,
/// <summary>negative time values are allowed</summary>
@AV_TIMECODE_FLAG_ALLOWNEGATIVE = 4,
@AV_TIMECODE_FLAG_ALLOWNEGATIVE = 1 << 2,
}

/// <summary>Dithering algorithms</summary>
Expand Down Expand Up @@ -2143,48 +2148,49 @@ public enum SwsDither : int
@SWS_DITHER_MAX_ENUM = 2147483647,
}

[Flags]
public enum SwsFlags : int
{
/// <summary>fast bilinear filtering</summary>
@SWS_FAST_BILINEAR = 1,
@SWS_FAST_BILINEAR = 1 << 0,
/// <summary>bilinear filtering</summary>
@SWS_BILINEAR = 2,
@SWS_BILINEAR = 1 << 1,
/// <summary>2-tap cubic B-spline</summary>
@SWS_BICUBIC = 4,
@SWS_BICUBIC = 1 << 2,
/// <summary>experimental</summary>
@SWS_X = 8,
@SWS_X = 1 << 3,
/// <summary>nearest neighbor</summary>
@SWS_POINT = 16,
@SWS_POINT = 1 << 4,
/// <summary>area averaging</summary>
@SWS_AREA = 32,
@SWS_AREA = 1 << 5,
/// <summary>bicubic luma, bilinear chroma</summary>
@SWS_BICUBLIN = 64,
@SWS_BICUBLIN = 1 << 6,
/// <summary>gaussian approximation</summary>
@SWS_GAUSS = 128,
@SWS_GAUSS = 1 << 7,
/// <summary>unwindowed sinc</summary>
@SWS_SINC = 256,
@SWS_SINC = 1 << 8,
/// <summary>3-tap sinc/sinc</summary>
@SWS_LANCZOS = 512,
@SWS_LANCZOS = 1 << 9,
/// <summary>cubic Keys spline</summary>
@SWS_SPLINE = 1024,
@SWS_SPLINE = 1 << 10,
/// <summary>Return an error on underspecified conversions. Without this flag, unspecified fields are defaulted to sensible values.</summary>
@SWS_STRICT = 2048,
@SWS_STRICT = 1 << 11,
/// <summary>Emit verbose log of scaling parameters.</summary>
@SWS_PRINT_INFO = 4096,
@SWS_PRINT_INFO = 1 << 12,
/// <summary>Perform full chroma upsampling when upscaling to RGB.</summary>
@SWS_FULL_CHR_H_INT = 8192,
@SWS_FULL_CHR_H_INT = 1 << 13,
/// <summary>Perform full chroma interpolation when downscaling RGB sources.</summary>
@SWS_FULL_CHR_H_INP = 16384,
@SWS_FULL_CHR_H_INP = 1 << 14,
/// <summary>Force bit-exact output. This will prevent the use of platform-specific optimizations that may lead to slight difference in rounding, in favor of always maintaining exact bit output compatibility with the reference C code.</summary>
@SWS_ACCURATE_RND = 262144,
@SWS_ACCURATE_RND = 1 << 18,
/// <summary>Force bit-exact output. This will prevent the use of platform-specific optimizations that may lead to slight difference in rounding, in favor of always maintaining exact bit output compatibility with the reference C code.</summary>
@SWS_BITEXACT = 524288,
@SWS_BITEXACT = 1 << 19,
/// <summary>Allow using experimental new code paths. This may be faster, slower, or produce different output, with semantics subject to change at any point in time. For testing and debugging purposes only.</summary>
@SWS_UNSTABLE = 1048576,
@SWS_UNSTABLE = 1 << 20,
/// <summary>This flag has no effect</summary>
@SWS_DIRECT_BGR = 32768,
@SWS_DIRECT_BGR = 1 << 15,
/// <summary>Set `SwsContext.dither` instead</summary>
@SWS_ERROR_DIFFUSION = 8388608,
@SWS_ERROR_DIFFUSION = 1 << 23,
}

public enum SwsIntent : int
Expand Down