88
99namespace WinAudioAssistant . Models
1010{
11+ public enum EndpointFormFactor
12+ {
13+ RemoteNetworkDevice = 0 ,
14+ Speakers = 1 ,
15+ LineLevel = 2 ,
16+ Headphones = 3 ,
17+ Microphone = 4 ,
18+ Headset = 5 ,
19+ Handset = 6 ,
20+ UnknownDigitalPassthrough = 7 ,
21+ SPDIF = 8 ,
22+ DigitalAudioDisplayDevice = 9 ,
23+ UnknownFormFactor = 10 ,
24+ }
25+
1126 public struct AudioEndpointInfo
1227 {
1328 public readonly DataFlow DataFlow { get ; }
14- public readonly Guid AudioEndpoint_GUID { get ; }
29+ public readonly Guid AudioEndpoint_GUID { get ; } // Globally unique to this endpoint
1530 public DeviceState ? DeviceState { get ; private set ; }
16- public int ? AudioEndpoint_FormFactor { get ; private set ; }
17- public string ? AudioEndpoint_JackSubType { get ; private set ; }
18- public Guid ? Device_ContainerId { get ; private set ; }
19- public string ? Device_DeviceDesc { get ; private set ; }
31+ public EndpointFormFactor ? AudioEndpoint_FormFactor { get ; private set ; } // Speakers, headphones, headset, SPDIF, etc.
32+ public Guid ? AudioEndpoint_JackSubType { get ; private set ; } // Contains a GUID for a type of jack, more specific than FormFactor
33+ public Guid ? Device_ContainerId { get ; private set ; } // Perhaps points to the parent device? Not populated for virtual devices
34+ public string ? Device_DeviceDesc { get ; private set ; } // The endpoint's name, which can be changed in the control panel
2035 public string ? DeviceClass_IconPath { get ; private set ; }
21- public string ? DeviceInterface_FriendlyName { get ; private set ; }
36+ public string ? DeviceInterface_FriendlyName { get ; private set ; } // Set by the driver, but may have a different value if there are duplicate devices
37+ public string ? HostDeviceDesc { get ; private set ; } // (Actual property name unkown) Appears to be the name of the host device. Usually same as DeviceInterface_FriendlyName.
2238
2339 public readonly string ID => ( DataFlow == DataFlow . Render ? "{0.0.0.00000000}.{" : "{0.0.1.00000000}.{" ) + AudioEndpoint_GUID . ToString ( ) + "}" ;
2440
@@ -28,12 +44,13 @@ public struct AudioEndpointInfo
2844 /// <remarks>Test remark.</remarks>
2945 public AudioEndpointInfo ( DataFlow dataFlow ,
3046 Guid audioEndpoint_GUID ,
31- int ? audioEndpoint_FormFactor = null ,
32- string ? audioEndpoint_JackSubType = null ,
47+ EndpointFormFactor ? audioEndpoint_FormFactor = null ,
48+ Guid ? audioEndpoint_JackSubType = null ,
3349 Guid ? device_ContainerId = null ,
3450 string ? device_DeviceDesc = null ,
3551 string ? deviceClass_IconPath = null ,
36- string ? deviceInterface_FriendlyName = null )
52+ string ? deviceInterface_FriendlyName = null ,
53+ string ? hostDeviceDesc = null )
3754 {
3855 Trace . Assert ( dataFlow != DataFlow . All , "AudioEndpointInfo created with DataFlow.All" ) ;
3956 DataFlow = dataFlow ;
@@ -44,12 +61,20 @@ public AudioEndpointInfo(DataFlow dataFlow,
4461 Device_DeviceDesc = device_DeviceDesc ;
4562 DeviceClass_IconPath = deviceClass_IconPath ;
4663 DeviceInterface_FriendlyName = deviceInterface_FriendlyName ;
64+ HostDeviceDesc = hostDeviceDesc ;
4765 }
4866 public AudioEndpointInfo ( MMDevice device )
4967 {
5068 Trace . Assert ( device . DataFlow != DataFlow . All , "AudioEndpointInfo created with DataFlow.All" ) ;
5169 DataFlow = device . DataFlow ;
52- AudioEndpoint_GUID = device . Properties [ propertyKeys . AudioEndpoint_GUID ] . Value is Guid guid ? guid : Guid . Empty ;
70+ if ( Guid . TryParse ( device . Properties [ propertyKeys . AudioEndpoint_GUID ] ? . Value as string , out var guid ) )
71+ {
72+ AudioEndpoint_GUID = guid ;
73+ }
74+ else
75+ {
76+ AudioEndpoint_GUID = Guid . Empty ;
77+ }
5378 Debug . Assert ( AudioEndpoint_GUID != Guid . Empty , "AudioEndpointInfo created with empty GUID" ) ;
5479 UpdateFromDevice ( device ) ;
5580 }
@@ -75,9 +100,9 @@ public bool UpdateFromSystem()
75100 public void UpdateFromDevice ( MMDevice device )
76101 {
77102 DeviceState = device . State ;
78- if ( device . Properties [ propertyKeys . AudioEndpoint_FormFactor ] ? . Value is int formFactor )
79- AudioEndpoint_FormFactor = formFactor ;
80- if ( device . Properties [ propertyKeys . AudioEndpoint_JackSubType ] ? . Value is string jackSubType )
103+ if ( device . Properties [ propertyKeys . AudioEndpoint_FormFactor ] ? . Value is uint formFactor )
104+ AudioEndpoint_FormFactor = ( EndpointFormFactor ) formFactor ;
105+ if ( Guid . TryParse ( device . Properties [ propertyKeys . AudioEndpoint_JackSubType ] ? . Value as string , out var jackSubType ) )
81106 AudioEndpoint_JackSubType = jackSubType ;
82107 if ( device . Properties [ propertyKeys . Device_ContainerId ] ? . Value is Guid containerId &&
83108 containerId != new Guid ( 0x0 , 0x0 , 0x0 , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ) )
@@ -88,6 +113,8 @@ public void UpdateFromDevice(MMDevice device)
88113 DeviceClass_IconPath = iconPath ;
89114 if ( device . Properties [ propertyKeys . DeviceInterface_FriendlyName ] ? . Value is string friendlyName )
90115 DeviceInterface_FriendlyName = friendlyName ;
116+ if ( device . Properties [ propertyKeys . Device_DeviceDesc ] ? . Value is string hostDeviceDesc )
117+ HostDeviceDesc = hostDeviceDesc ;
91118 }
92119
93120 private static class propertyKeys
@@ -99,6 +126,7 @@ private static class propertyKeys
99126 internal static readonly PropertyKey Device_DeviceDesc = new ( new Guid ( 0xa45c254e , 0xdf1c , 0x4efd , 0x80 , 0x20 , 0x67 , 0xd1 , 0x46 , 0xa8 , 0x50 , 0xe0 ) , 2 ) ;
100127 internal static readonly PropertyKey DeviceClass_IconPath = new ( new Guid ( 0x259abffc , 0x50a7 , 0x47ce , 0xaf , 0x8 , 0x68 , 0xc9 , 0xa7 , 0xd7 , 0x33 , 0x66 ) , 12 ) ;
101128 internal static readonly PropertyKey DeviceInterface_FriendlyName = new ( new Guid ( 0x026e516e , 0xb814 , 0x414b , 0x83 , 0xcd , 0x85 , 0x6d , 0x6f , 0xef , 0x48 , 0x22 ) , 2 ) ;
129+ internal static readonly PropertyKey HostDeviceDesc = new ( new Guid ( 0xb3f8fa53 , 0x0004 , 0x438e , 0x90 , 0x03 , 0x51 , 0xa4 , 0x6e , 0x13 , 0x9b , 0xfc ) , 6 ) ;
102130 }
103131
104132 }
0 commit comments