99 lines
4.1 KiB
C#
99 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Vav1Player.Native
|
|
{
|
|
public static class Dav1dErrorCodes
|
|
{
|
|
// Common errno values (Windows/POSIX)
|
|
public const int ENOENT = 2; // No such file or directory
|
|
public const int EIO = 5; // I/O error
|
|
public const int ENOMEM = 12; // Out of memory
|
|
public const int EAGAIN = 11; // Try again (Windows uses 11, POSIX uses 35)
|
|
public const int EWOULDBLOCK = EAGAIN;
|
|
public const int ENOPROTOOPT = 42; // Protocol not available
|
|
|
|
// DAV1D-specific error interpretation
|
|
private static readonly Dictionary<int, string> ErrorDescriptions = new Dictionary<int, string>
|
|
{
|
|
{ 0, "Success" },
|
|
{ -ENOENT, "No Sequence Header OBUs found in buffer" },
|
|
{ -EIO, "I/O error occurred during operation" },
|
|
{ -ENOMEM, "Insufficient memory to allocate decoder context" },
|
|
{ -EAGAIN, "Operation cannot proceed - need more data or output buffer full" },
|
|
{ -ENOPROTOOPT, "Unsupported protocol or codec options" },
|
|
};
|
|
|
|
// Additional context-specific errors
|
|
private static readonly Dictionary<int, string> OpenSpecificErrors = new Dictionary<int, string>
|
|
{
|
|
{ -ENOMEM, "Failed to allocate memory for decoder context. Try reducing thread count or frame delay." },
|
|
{ -22, "Invalid argument - check Dav1dSettings structure values" }, // EINVAL
|
|
{ -1, "Generic error - decoder initialization failed" },
|
|
};
|
|
|
|
public static string GetErrorDescription(int errorCode)
|
|
{
|
|
if (errorCode == 0)
|
|
return "Success";
|
|
|
|
if (ErrorDescriptions.TryGetValue(errorCode, out string description))
|
|
return description;
|
|
|
|
// Handle negative errno values
|
|
int absError = Math.Abs(errorCode);
|
|
return $"Error code {errorCode} (errno {absError}): {GetGenericErrorName(absError)}";
|
|
}
|
|
|
|
public static string GetOpenErrorDescription(int errorCode)
|
|
{
|
|
if (errorCode == 0)
|
|
return "Decoder opened successfully";
|
|
|
|
if (OpenSpecificErrors.TryGetValue(errorCode, out string description))
|
|
return description;
|
|
|
|
return GetErrorDescription(errorCode);
|
|
}
|
|
|
|
public static string GetGenericErrorName(int errno)
|
|
{
|
|
return errno switch
|
|
{
|
|
ENOENT => "ENOENT (No such file or directory)",
|
|
EIO => "EIO (I/O error)",
|
|
ENOMEM => "ENOMEM (Out of memory)",
|
|
EAGAIN => "EAGAIN (Resource temporarily unavailable)",
|
|
ENOPROTOOPT => "ENOPROTOOPT (Protocol not available)",
|
|
22 => "EINVAL (Invalid argument)",
|
|
_ => $"Unknown errno {errno}"
|
|
};
|
|
}
|
|
|
|
public static bool IsRecoverable(int errorCode)
|
|
{
|
|
return errorCode switch
|
|
{
|
|
-EAGAIN => true, // Can retry with more data
|
|
-EIO => false, // I/O errors are typically not recoverable
|
|
-ENOMEM => false, // Memory allocation failures
|
|
-ENOENT => false, // Missing sequence headers
|
|
-ENOPROTOOPT => false, // Unsupported features
|
|
_ => false
|
|
};
|
|
}
|
|
|
|
public static string GetTroubleshootingSuggestion(int errorCode)
|
|
{
|
|
return errorCode switch
|
|
{
|
|
-ENOMEM => "Try reducing n_threads or max_frame_delay in Dav1dSettings, or close other applications to free memory.",
|
|
-22 => "Check that all Dav1dSettings values are within valid ranges (threads: 0-256, frame_delay: 0-256).",
|
|
-ENOENT => "Ensure the input data contains valid AV1 sequence headers.",
|
|
-EAGAIN => "This is normal during streaming - provide more input data.",
|
|
-ENOPROTOOPT => "The AV1 stream uses features not supported by this dav1d version.",
|
|
_ => "Check dav1d documentation for this error code."
|
|
};
|
|
}
|
|
}
|
|
} |