From 123f5937d0477026502610a96d18399d1dc9445d Mon Sep 17 00:00:00 2001 From: nixx quality Date: Fri, 2 May 2014 14:14:51 +0200 Subject: [PATCH] Bye bye, ErrorHandling.cs Fixes #1 --- FFMSsharp/ErrorHandling.cs | 293 ------------------------------------- FFMSsharp/FFMS.cs | 42 ++++++ FFMSsharp/FFMSsharp.csproj | 1 - FFMSsharp/FFMSsharp.xml | 184 +---------------------- 4 files changed, 43 insertions(+), 477 deletions(-) delete mode 100644 FFMSsharp/ErrorHandling.cs diff --git a/FFMSsharp/ErrorHandling.cs b/FFMSsharp/ErrorHandling.cs deleted file mode 100644 index d045b4a..0000000 --- a/FFMSsharp/ErrorHandling.cs +++ /dev/null @@ -1,293 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Runtime.Serialization; - -namespace FFMSsharp -{ - #region Interop - - [StructLayout(LayoutKind.Sequential)] - unsafe struct FFMS_ErrorInfo - { - internal FFMS_Errors ErrorType; - internal FFMS_Errors SubType; - public int BufferSize; - [MarshalAs(UnmanagedType.LPStr)] - public string Buffer; - } - - #endregion - - #region Constants - - /// Used to identify errors. - public enum FFMS_Errors - { - /// No error. - FFMS_ERROR_SUCCESS = 0, - - // Main types - where the error occurred - /// Index file handling - FFMS_ERROR_INDEX = 1, - /// Indexing - FFMS_ERROR_INDEXING, - /// Video post-processing (libpostproc) - FFMS_ERROR_POSTPROCESSING, - /// Image scaling (libswscale) - FFMS_ERROR_SCALING, - /// Audio/Video decoding - FFMS_ERROR_DECODING, - /// Seeking - FFMS_ERROR_SEEKING, - /// File parsing - FFMS_ERROR_PARSER, - /// Track handling - FFMS_ERROR_TRACK, - /// WAVE64 file writer - FFMS_ERROR_WAVE_WRITER, - /// Operation aborted - FFMS_ERROR_CANCELLED, - /// Audio re-sampling (libavresample) - FFMS_ERROR_RESAMPLING, - - // Subtypes - what caused the error - /// Unknown error - FFMS_ERROR_UNKNOWN = 20, - /// Format or operation is not supported with this binary - FFMS_ERROR_UNSUPPORTED, - /// Cannot read from file - FFMS_ERROR_FILE_READ, - /// Cannot write to file - FFMS_ERROR_FILE_WRITE, - /// No such file or directory - FFMS_ERROR_NO_FILE, - /// Wrong version - FFMS_ERROR_VERSION, - /// Out of memory - FFMS_ERROR_ALLOCATION_FAILED, - /// Invalid or nonsensical argument - FFMS_ERROR_INVALID_ARGUMENT, - /// Decoder error - FFMS_ERROR_CODEC, - /// Requested mode or operation unavailable in this binary - FFMS_ERROR_NOT_AVAILABLE, - /// Provided index does not match the file - FFMS_ERROR_FILE_MISMATCH, - /// Problem exists between keyboard and chair - FFMS_ERROR_USER - } - - #endregion - - #region Exceptions - - /// - /// Generic parent class for all other FFMS exceptions - /// - [Serializable()] - public class FFMSException : Exception - { - private FFMS_Errors ErrorType; - - /// - protected FFMSException() - : base() - { } - - internal FFMSException(FFMS_Errors errorType) : - base("") - { - ErrorType = errorType; - } - - internal FFMSException(FFMS_Errors errorType, string message) : - base(message) - { - ErrorType = errorType; - } - - internal FFMSException(FFMS_Errors errorType, string message, Exception innerException) : - base(message, innerException) - { - ErrorType = errorType; - } - - /// - protected FFMSException(SerializationInfo info, StreamingContext context) - : base(info, context) - { } - - internal FFMS_Errors Where - { get { return ErrorType; } } - } - - /// - /// Unknown error - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_UNKNOWN. - /// - public class FFMSUnknownErrorException : FFMSException - { - internal FFMSUnknownErrorException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// Format or operation is not supported with this binary - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_UNSUPPORTED. - /// - public class FFMSUnsupportedException : FFMSException - { - internal FFMSUnsupportedException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// Cannot read from file - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_FILE_READ. - /// - public class FFMSFileReadException : FFMSException - { - internal FFMSFileReadException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// Cannot write to file - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_FILE_WRITE. - /// - public class FFMSFileWriteException : FFMSException - { - internal FFMSFileWriteException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// No such file or directory - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_NO_FILE. - /// - public class FFMSNoFileException : FFMSException - { - internal FFMSNoFileException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// Wrong version - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_VERSION. - /// - public class FFMSVersionException : FFMSException - { - internal FFMSVersionException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// Out of memory - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_ALLOCATION_FAILED. - /// - public class FFMSAllocationFailedException : FFMSException - { - internal FFMSAllocationFailedException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// Invalid or nonsensical argument - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_INVALID_ARGUMENT. - /// - public class FFMSInvalidArgumentException : FFMSException - { - internal FFMSInvalidArgumentException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// Decoder error - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_CODEC. - /// - public class FFMSCodecException : FFMSException - { - internal FFMSCodecException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// Requested mode or operation unavailable in this binary - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_NOT_AVAILABLE. - /// - public class FFMSNotAvailableException : FFMSException - { - internal FFMSNotAvailableException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// Provided index does not match the file - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_FILE_MISMATCH. - /// - public class FFMSFileMismatchException : FFMSException - { - internal FFMSFileMismatchException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - /// - /// Problem exists between keyboard and chair - /// - /// - /// In FFMS2, the equivalent is FFMS_ERROR_USER. - /// - public class FFMSUserException : FFMSException - { - internal FFMSUserException(FFMS_Errors errorType, string message) : base(errorType, message) { } - } - - #endregion - - static class ErrorHandling - { - public static Exception ExceptionFromErrorInfo(FFMS_ErrorInfo ErrorInfo) - { - switch (ErrorInfo.SubType) - { - case FFMS_Errors.FFMS_ERROR_UNKNOWN: - return new FFMSUnknownErrorException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_UNSUPPORTED: - return new FFMSUnsupportedException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_FILE_READ: - return new FFMSFileReadException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_FILE_WRITE: - return new FFMSFileWriteException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_NO_FILE: - return new FFMSNoFileException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_VERSION: - return new FFMSVersionException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_ALLOCATION_FAILED: - return new FFMSAllocationFailedException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_INVALID_ARGUMENT: - return new FFMSInvalidArgumentException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_CODEC: - return new FFMSCodecException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_NOT_AVAILABLE: - return new FFMSNotAvailableException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_FILE_MISMATCH: - return new FFMSFileMismatchException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - case FFMS_Errors.FFMS_ERROR_USER: - return new FFMSUserException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - } - - return new FFMSException(ErrorInfo.ErrorType, ErrorInfo.Buffer); - } - } -} \ No newline at end of file diff --git a/FFMSsharp/FFMS.cs b/FFMSsharp/FFMS.cs index aeafc83..11d886b 100644 --- a/FFMSsharp/FFMS.cs +++ b/FFMSsharp/FFMS.cs @@ -6,6 +6,16 @@ namespace FFMSsharp { #region Interop + [StructLayout(LayoutKind.Sequential)] + unsafe struct FFMS_ErrorInfo + { + internal FFMS_Errors ErrorType; + internal FFMS_Errors SubType; + public int BufferSize; + [MarshalAs(UnmanagedType.LPStr)] + public string Buffer; + } + static partial class NativeMethods { [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] @@ -38,6 +48,38 @@ static partial class NativeMethods #region Constants + enum FFMS_Errors + { + FFMS_ERROR_SUCCESS = 0, + + // Main types - where the error occurred + FFMS_ERROR_INDEX = 1, + FFMS_ERROR_INDEXING, + FFMS_ERROR_POSTPROCESSING, + FFMS_ERROR_SCALING, + FFMS_ERROR_DECODING, + FFMS_ERROR_SEEKING, + FFMS_ERROR_PARSER, + FFMS_ERROR_TRACK, + FFMS_ERROR_WAVE_WRITER, + FFMS_ERROR_CANCELLED, + FFMS_ERROR_RESAMPLING, + + // Subtypes - what caused the error + FFMS_ERROR_UNKNOWN = 20, + FFMS_ERROR_UNSUPPORTED, + FFMS_ERROR_FILE_READ, + FFMS_ERROR_FILE_WRITE, + FFMS_ERROR_NO_FILE, + FFMS_ERROR_VERSION, + FFMS_ERROR_ALLOCATION_FAILED, + FFMS_ERROR_INVALID_ARGUMENT, + FFMS_ERROR_CODEC, + FFMS_ERROR_NOT_AVAILABLE, + FFMS_ERROR_FILE_MISMATCH, + FFMS_ERROR_USER + } + /// /// Log level for libavformat /// diff --git a/FFMSsharp/FFMSsharp.csproj b/FFMSsharp/FFMSsharp.csproj index 2441108..3d9274d 100644 --- a/FFMSsharp/FFMSsharp.csproj +++ b/FFMSsharp/FFMSsharp.csproj @@ -45,7 +45,6 @@ - diff --git a/FFMSsharp/FFMSsharp.xml b/FFMSsharp/FFMSsharp.xml index 8d37915..bdd84f1 100644 --- a/FFMSsharp/FFMSsharp.xml +++ b/FFMSsharp/FFMSsharp.xml @@ -253,9 +253,9 @@ Sample numbers start from zero and hence the last sample in the stream is number minus 1. The raw audio data - Trying to access audio samples that are out of range of the stream. + Trying to start half-way into an unseekable audio stream. @@ -338,188 +338,6 @@ Note that the Track object is only valid until its parent AudioSource object is destroyed. - - Used to identify errors. - - - No error. - - - Index file handling - - - Indexing - - - Video post-processing (libpostproc) - - - Image scaling (libswscale) - - - Audio/Video decoding - - - Seeking - - - File parsing - - - Track handling - - - WAVE64 file writer - - - Operation aborted - - - Audio re-sampling (libavresample) - - - Unknown error - - - Format or operation is not supported with this binary - - - Cannot read from file - - - Cannot write to file - - - No such file or directory - - - Wrong version - - - Out of memory - - - Invalid or nonsensical argument - - - Decoder error - - - Requested mode or operation unavailable in this binary - - - Provided index does not match the file - - - Problem exists between keyboard and chair - - - - Generic parent class for all other FFMS exceptions - - - - - - - - - - - Unknown error - - - In FFMS2, the equivalent is FFMS_ERROR_UNKNOWN. - - - - - Format or operation is not supported with this binary - - - In FFMS2, the equivalent is FFMS_ERROR_UNSUPPORTED. - - - - - Cannot read from file - - - In FFMS2, the equivalent is FFMS_ERROR_FILE_READ. - - - - - Cannot write to file - - - In FFMS2, the equivalent is FFMS_ERROR_FILE_WRITE. - - - - - No such file or directory - - - In FFMS2, the equivalent is FFMS_ERROR_NO_FILE. - - - - - Wrong version - - - In FFMS2, the equivalent is FFMS_ERROR_VERSION. - - - - - Out of memory - - - In FFMS2, the equivalent is FFMS_ERROR_ALLOCATION_FAILED. - - - - - Invalid or nonsensical argument - - - In FFMS2, the equivalent is FFMS_ERROR_INVALID_ARGUMENT. - - - - - Decoder error - - - In FFMS2, the equivalent is FFMS_ERROR_CODEC. - - - - - Requested mode or operation unavailable in this binary - - - In FFMS2, the equivalent is FFMS_ERROR_NOT_AVAILABLE. - - - - - Provided index does not match the file - - - In FFMS2, the equivalent is FFMS_ERROR_FILE_MISMATCH. - - - - - Problem exists between keyboard and chair - - - In FFMS2, the equivalent is FFMS_ERROR_USER. - - Identifies the color coefficients used for a YUV stream