Compare commits
No commits in common. "be67abaf64fc4086dac9ade2b29e8f0a7fb50d2a" and "faf091ac2c2c07b5f83d4e23b7b898e70f1bdda9" have entirely different histories.
be67abaf64
...
faf091ac2c
|
@ -18,9 +18,9 @@
|
|||
<PackageTags>EonaCat, Audio, Volume, Mixer .NET Standard, Jeroen, Saey</PackageTags>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
<Description>EonaCat VolumeMixer</Description>
|
||||
<Version>1.0.6</Version>
|
||||
<AssemblyVersion>1.0.0.6</AssemblyVersion>
|
||||
<FileVersion>1.0.0.6</FileVersion>
|
||||
<Version>1.0.5</Version>
|
||||
<AssemblyVersion>1.0.0.5</AssemblyVersion>
|
||||
<FileVersion>1.0.0.5</FileVersion>
|
||||
<PackageIcon>icon.png</PackageIcon>
|
||||
<RepositoryUrl>https://git.saey.me/EonaCat/EonaCat.VolumeMixer</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
|
|
|
@ -49,12 +49,9 @@ namespace EonaCat.VolumeMixer.Managers
|
|||
|
||||
lock (_syncLock)
|
||||
{
|
||||
IMultiMediaDeviceCollection deviceCollection = null;
|
||||
IMultiMediaDevice defaultDevice = null;
|
||||
|
||||
try
|
||||
{
|
||||
var result = _deviceEnumerator.EnumAudioEndpoints(dataFlow, DeviceState.Active, out deviceCollection);
|
||||
var result = _deviceEnumerator.EnumAudioEndpoints(dataFlow, DeviceState.Active, out var deviceCollection);
|
||||
if (result != 0 || deviceCollection == null)
|
||||
{
|
||||
return devices;
|
||||
|
@ -63,16 +60,18 @@ namespace EonaCat.VolumeMixer.Managers
|
|||
result = deviceCollection.GetCount(out var count);
|
||||
if (result != 0)
|
||||
{
|
||||
ComHelper.ReleaseComObject(deviceCollection);
|
||||
return devices;
|
||||
}
|
||||
|
||||
string defaultId = "";
|
||||
try
|
||||
{
|
||||
result = _deviceEnumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia, out defaultDevice);
|
||||
result = _deviceEnumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia, out var defaultDevice);
|
||||
if (result == 0 && defaultDevice != null)
|
||||
{
|
||||
defaultDevice.GetId(out defaultId);
|
||||
ComHelper.ReleaseComObject(defaultDevice);
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
@ -82,11 +81,9 @@ namespace EonaCat.VolumeMixer.Managers
|
|||
|
||||
for (uint i = 0; i < count; i++)
|
||||
{
|
||||
IMultiMediaDevice device = null;
|
||||
|
||||
try
|
||||
{
|
||||
result = deviceCollection.Item(i, out device);
|
||||
result = deviceCollection.Item(i, out var device);
|
||||
if (result == 0 && device != null)
|
||||
{
|
||||
result = device.GetId(out var id);
|
||||
|
@ -97,37 +94,24 @@ namespace EonaCat.VolumeMixer.Managers
|
|||
bool isDefault = id == defaultId;
|
||||
devices.Add(new AudioDevice(device, id, name, isDefault, dataFlow, type));
|
||||
}
|
||||
else
|
||||
{
|
||||
ComHelper.ReleaseComObject(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (device != null)
|
||||
{
|
||||
ComHelper.ReleaseComObject(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ComHelper.ReleaseComObject(deviceCollection);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (deviceCollection != null)
|
||||
{
|
||||
ComHelper.ReleaseComObject(deviceCollection);
|
||||
}
|
||||
|
||||
if (defaultDevice != null)
|
||||
{
|
||||
ComHelper.ReleaseComObject(defaultDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return devices;
|
||||
|
@ -145,11 +129,9 @@ namespace EonaCat.VolumeMixer.Managers
|
|||
|
||||
lock (_syncLock)
|
||||
{
|
||||
IMultiMediaDevice device = null;
|
||||
|
||||
try
|
||||
{
|
||||
var result = _deviceEnumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia, out device);
|
||||
var result = _deviceEnumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia, out var device);
|
||||
if (result == 0 && device != null)
|
||||
{
|
||||
result = device.GetId(out var id);
|
||||
|
@ -159,81 +141,58 @@ namespace EonaCat.VolumeMixer.Managers
|
|||
var type = GetDeviceType(device);
|
||||
return new AudioDevice(device, id, name, true, dataFlow, type);
|
||||
}
|
||||
|
||||
ComHelper.ReleaseComObject(device);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (device != null)
|
||||
{
|
||||
ComHelper.ReleaseComObject(device);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[DllImport("ole32.dll")]
|
||||
private static extern int PropVariantClear(ref PropVariant pvar);
|
||||
|
||||
private string GetDeviceName(IMultiMediaDevice device)
|
||||
{
|
||||
IPropertyStore? propertyStore = null;
|
||||
PropVariant propVariant = new PropVariant();
|
||||
|
||||
try
|
||||
{
|
||||
var result = device.OpenPropertyStore(0, out propertyStore);
|
||||
var result = device.OpenPropertyStore(0, out var propertyStore);
|
||||
if (result == 0 && propertyStore != null)
|
||||
{
|
||||
var propertyKey = PKEY_Device_FriendlyName;
|
||||
result = propertyStore.GetValue(ref propertyKey, out propVariant);
|
||||
if (result == 0)
|
||||
result = propertyStore.GetValue(ref propertyKey, out var propVariant);
|
||||
if (result == 0 && propVariant.data1 != IntPtr.Zero)
|
||||
{
|
||||
// Get string
|
||||
string name = Marshal.PtrToStringUni(propVariant.data1);
|
||||
ComHelper.ReleaseComObject(propertyStore);
|
||||
return !string.IsNullOrEmpty(name) ? name : "Unknown Device";
|
||||
}
|
||||
|
||||
ComHelper.ReleaseComObject(propertyStore);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Clear memory
|
||||
PropVariantClear(ref propVariant);
|
||||
|
||||
if (propertyStore != null)
|
||||
{
|
||||
ComHelper.ReleaseComObject(propertyStore);
|
||||
}
|
||||
}
|
||||
|
||||
return "Unknown Device";
|
||||
}
|
||||
|
||||
|
||||
private DeviceType GetDeviceType(IMultiMediaDevice device)
|
||||
{
|
||||
IPropertyStore propertyStore = null;
|
||||
PropVariant propVariant = new PropVariant();
|
||||
|
||||
try
|
||||
{
|
||||
int result = device.OpenPropertyStore(0, out propertyStore);
|
||||
int result = device.OpenPropertyStore(0, out var propertyStore);
|
||||
if (result == 0 && propertyStore != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var propertyKey = PKEY_AudioEndpoint_FormFactor;
|
||||
result = propertyStore.GetValue(ref propertyKey, out propVariant);
|
||||
result = propertyStore.GetValue(ref propertyKey, out var propVariant);
|
||||
|
||||
// 0x13 == VT_UI4
|
||||
if (result == 0 && propVariant.vt == 0x13)
|
||||
|
@ -268,7 +227,7 @@ namespace EonaCat.VolumeMixer.Managers
|
|||
}
|
||||
finally
|
||||
{
|
||||
|
||||
ComHelper.ReleaseComObject(propertyStore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -276,14 +235,7 @@ namespace EonaCat.VolumeMixer.Managers
|
|||
{
|
||||
// Do nothing
|
||||
}
|
||||
finally
|
||||
{
|
||||
PropVariantClear(ref propVariant);
|
||||
if (propertyStore != null)
|
||||
{
|
||||
ComHelper.ReleaseComObject(propertyStore);
|
||||
}
|
||||
}
|
||||
|
||||
return DeviceType.Unknown;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue