Beispiel #1
0
        /// <summary>
        /// Attempts to add a new ACM driver from a file
        /// </summary>
        /// <param name="driverFile">Full path of the .acm or dll file containing the driver</param>
        /// <returns>Handle to the driver</returns>
        public static AcmDriver AddLocalDriver(string driverFile)
        {
            IntPtr handle = NativeMethods.LoadLibrary(driverFile);

            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException("Failed to load driver file");
            }
            var driverProc = NativeMethods.GetProcAddress(handle, "DriverProc");

            if (driverProc == IntPtr.Zero)
            {
                NativeMethods.FreeLibrary(handle);
                throw new ArgumentException("Failed to discover DriverProc");
            }
            IntPtr driverHandle;
            var    result = AcmInterop.acmDriverAdd(out driverHandle,
                                                    handle, driverProc, 0, AcmDriverAddFlags.Function);

            if (result != MmResult.NoError)
            {
                NativeMethods.FreeLibrary(handle);
                throw new MmException(result, "acmDriverAdd");
            }
            var driver = new AcmDriver(driverHandle);

            // long name seems to be missing when we use acmDriverAdd
            if (string.IsNullOrEmpty(driver.details.longName))
            {
                driver.details.longName = "Local driver: " + Path.GetFileName(driverFile);
                driver.localDllHandle   = handle;
            }
            return(driver);
        }
Beispiel #2
0
 /// <summary>
 /// Attempts to add a new ACM driver from a file
 /// </summary>
 /// <param name="driverFile">Full path of the .acm or dll file containing the driver</param>
 /// <returns>Handle to the driver</returns>
 public static AcmDriver AddLocalDriver(string driverFile)
 {
     IntPtr handle = NativeMethods.LoadLibrary(driverFile);
     if (handle == IntPtr.Zero)
     {
         throw new ArgumentException("Failed to load driver file");
     }
     var driverProc = NativeMethods.GetProcAddress(handle, "DriverProc");
     if (driverProc == IntPtr.Zero)
     {
         NativeMethods.FreeLibrary(handle);
         throw new ArgumentException("Failed to discover DriverProc");
     }
     IntPtr driverHandle;
     var result = AcmInterop.acmDriverAdd(out driverHandle,
         handle, driverProc, 0, AcmDriverAddFlags.Function);
     if (result != MmResult.NoError)
     {
         NativeMethods.FreeLibrary(handle);
         throw new MmException(result, "acmDriverAdd");
     }
     var driver = new AcmDriver(driverHandle);
     // long name seems to be missing when we use acmDriverAdd
     if (string.IsNullOrEmpty(driver.details.longName))
     {
         driver.details.longName = "Local driver: " + Path.GetFileName(driverFile);
         driver.localDllHandle = handle;
     }
     return driver;
 }
Beispiel #3
0
 private static void DescribeAcmDriver(AcmDriver driver, StringBuilder builder)
 {
     builder.AppendFormat("Long Name: {0}\r\n", driver.LongName);
     builder.AppendFormat("Short Name: {0}\r\n", driver.ShortName);
     builder.AppendFormat("Driver ID: {0}\r\n", driver.DriverId);
     builder.AppendFormat("FormatTags:\r\n");
 }
 public AcmDriverDetailsForm(AcmDriver driver)
 {
     InitializeComponent();
     AddLine("Long Name: {0}", driver.LongName);
     AddLine("Short Name: {0}", driver.ShortName);
     AddLine("Driver ID: {0}", driver.DriverId);
     driver.Open();
     AddLine("FormatTags:", driver.FormatTags);
     foreach (AcmFormatTag formatTag in driver.FormatTags)
     {
         AddLine("{0}: {1}", formatTag.FormatTagIndex, formatTag.FormatDescription);
         AddLine("   Standard Format Count: {0}", formatTag.StandardFormatsCount);
         AddLine("   Support Flags: {0}", formatTag.SupportFlags);
         AddLine("   Format Tag: {0}, Format Size: {1}", formatTag.FormatTag, formatTag.FormatSize);
         AddLine("   Formats:");
         foreach (AcmFormat format in driver.GetFormats(formatTag))
         {
             AddLine("   {0}: {1}", format.FormatIndex, format.FormatDescription);
             AddLine("      FormatTag: {0}, Support Flags: {1}", format.FormatTag, format.SupportFlags);
             AddLine("      WaveFormat: {0} {1}Hz {2} Channels {3} bits, Block Align: {4}, AverageBytesPerSecond: {5}, Extra Size: {6}",
                 format.WaveFormat.Encoding, format.WaveFormat.SampleRate, format.WaveFormat.Channels,
                 format.WaveFormat.BitsPerSample, format.WaveFormat.BlockAlign, format.WaveFormat.AverageBytesPerSecond,
                 format.WaveFormat.ExtraSize);
         }
     }
     driver.Close();
 }
Beispiel #5
0
        public static AcmDriver AddLocalDriver(string driverFile)
        {
            IntPtr intPtr = NativeMethods.LoadLibrary(driverFile);

            if (intPtr == IntPtr.Zero)
            {
                throw new ArgumentException("Failed to load driver file");
            }
            IntPtr procAddress = NativeMethods.GetProcAddress(intPtr, "DriverProc");

            if (procAddress == IntPtr.Zero)
            {
                NativeMethods.FreeLibrary(intPtr);
                throw new ArgumentException("Failed to discover DriverProc");
            }
            IntPtr   hAcmDriver;
            MmResult mmResult = AcmInterop.acmDriverAdd(out hAcmDriver, intPtr, procAddress, 0, AcmDriverAddFlags.Function);

            if (mmResult != MmResult.NoError)
            {
                NativeMethods.FreeLibrary(intPtr);
                throw new MmException(mmResult, "acmDriverAdd");
            }
            AcmDriver acmDriver = new AcmDriver(hAcmDriver);

            if (string.IsNullOrEmpty(acmDriver.details.longName))
            {
                acmDriver.details.longName = "Local driver: " + Path.GetFileName(driverFile);
                acmDriver.localDllHandle   = intPtr;
            }
            return(acmDriver);
        }
Beispiel #6
0
 /// <summary>
 /// Removes a driver previously added using AddLocalDriver
 /// </summary>
 /// <param name="localDriver">Local driver to remove</param>
 public static void RemoveLocalDriver(AcmDriver localDriver)
 {
     if (localDriver.localDllHandle == IntPtr.Zero)
     {
         throw new ArgumentException("Please pass in the AcmDriver returned by the AddLocalDriver method");
     }
     var removeResult = AcmInterop.acmDriverRemove(localDriver.driverId, 0); // gets stored as a driver Id
     NativeMethods.FreeLibrary(localDriver.localDllHandle);
     MmException.Try(removeResult, "acmDriverRemove");
 }
Beispiel #7
0
        /// <summary>
        /// Removes a driver previously added using AddLocalDriver
        /// </summary>
        /// <param name="localDriver">Local driver to remove</param>
        public static void RemoveLocalDriver(AcmDriver localDriver)
        {
            if (localDriver.localDllHandle == IntPtr.Zero)
            {
                throw new ArgumentException("Please pass in the AcmDriver returned by the AddLocalDriver method");
            }
            var removeResult = AcmInterop.acmDriverRemove(localDriver.driverId, 0); // gets stored as a driver Id

            NativeMethods.FreeLibrary(localDriver.localDllHandle);
            MmException.Try(removeResult, "acmDriverRemove");
        }
Beispiel #8
0
 /// <summary>
 /// Helper function to determine whether a particular codec is installed
 /// </summary>
 /// <param name="shortName">The short name of the function</param>
 /// <returns>Whether the codec is installed</returns>
 public static bool IsCodecInstalled(string shortName)
 {
     foreach (AcmDriver driver in AcmDriver.EnumerateAcmDrivers())
     {
         if (driver.ShortName == shortName)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #9
0
 /// <summary>
 /// Finds a Driver by its short name
 /// </summary>
 /// <param name="shortName">Short Name</param>
 /// <returns>The driver, or null if not found</returns>
 public static AcmDriver FindByShortName(string shortName)
 {
     foreach (AcmDriver driver in AcmDriver.EnumerateAcmDrivers())
     {
         if (driver.ShortName == shortName)
         {
             return(driver);
         }
     }
     return(null);
 }
Beispiel #10
0
 private string DescribeCodec(AcmDriver driver)
 {
     try
     {
         driver.Open();
         var builder = new StringBuilder();
         DescribeAcmDriver(driver, builder);
         foreach (var formatTag in driver.FormatTags)
         {
             DescribeAcmFormatTag(builder, formatTag);
             foreach (var format in driver.GetFormats(formatTag))
             {
                 DescribeAcmFormat(builder, format);
             }
         }
         driver.Close();
         return builder.ToString();
     }
     catch (Exception e)
     {
         return e.ToString();
     }
 }
Beispiel #11
0
 private string DescribeCodec(AcmDriver driver)
 {
     try
     {
         StringBuilder builder = new StringBuilder();
         builder.AppendFormat("Long Name: {0}\r\n", driver.LongName);
         builder.AppendFormat("Short Name: {0}\r\n", driver.ShortName);
         builder.AppendFormat("Driver ID: {0}\r\n", driver.DriverId);
         driver.Open();
         builder.AppendFormat("FormatTags:\r\n");
         foreach (AcmFormatTag formatTag in driver.FormatTags)
         {
             builder.AppendFormat("===========================================\r\n");
             builder.AppendFormat("Format Tag {0}: {1}\r\n", formatTag.FormatTagIndex, formatTag.FormatDescription);
             builder.AppendFormat("   Standard Format Count: {0}\r\n", formatTag.StandardFormatsCount);
             builder.AppendFormat("   Support Flags: {0}\r\n", formatTag.SupportFlags);
             builder.AppendFormat("   Format Tag: {0}, Format Size: {1}\r\n", formatTag.FormatTag, formatTag.FormatSize);
             builder.AppendFormat("   Formats:\r\n");
             foreach (AcmFormat format in driver.GetFormats(formatTag))
             {
                 builder.AppendFormat("   ===========================================\r\n");
                 builder.AppendFormat("   Format {0}: {1}\r\n", format.FormatIndex, format.FormatDescription);
                 builder.AppendFormat("      FormatTag: {0}, Support Flags: {1}\r\n", format.FormatTag, format.SupportFlags);
                 builder.AppendFormat("      WaveFormat: {0} {1}Hz Channels: {2} Bits: {3} Block Align: {4}, AverageBytesPerSecond: {5} ({6:0.0} kbps), Extra Size: {7}\r\n",
                     format.WaveFormat.Encoding, format.WaveFormat.SampleRate, format.WaveFormat.Channels,
                     format.WaveFormat.BitsPerSample, format.WaveFormat.BlockAlign, format.WaveFormat.AverageBytesPerSecond,
                     (format.WaveFormat.AverageBytesPerSecond * 8) / 1000.0,
                     format.WaveFormat.ExtraSize);
                 if (format.WaveFormat is WaveFormatExtraData && format.WaveFormat.ExtraSize > 0)
                 {
                     WaveFormatExtraData wfed = (WaveFormatExtraData)format.WaveFormat;
                     builder.Append("      Extra Bytes:\r\n      ");
                     for (int n = 0; n < format.WaveFormat.ExtraSize; n++)
                     {
                         builder.AppendFormat("{0:X2} ", wfed.ExtraData[n]);
                     }
                     builder.Append("\r\n");
                 }
             }
         }
         driver.Close();
         return builder.ToString();
     }
     catch (Exception e)
     {
         return e.ToString();
     }
 }