public CoreAudioController()
        {
            // ReSharper disable once SuspiciousTypeConversion.Global
            var innerEnumerator = ComObjectFactory.GetDeviceEnumerator();

            _innerEnumeratorPtr = Marshal.GetIUnknownForObject(innerEnumerator);

            if (innerEnumerator == null)
            {
                throw new InvalidComObjectException("No Device Enumerator");
            }

            _innerEnumerator = new ThreadLocal <IMultimediaDeviceEnumerator>(() => Marshal.GetUniqueObjectForIUnknown(_innerEnumeratorPtr) as IMultimediaDeviceEnumerator);

            ComThread.Invoke(() =>
            {
                _systemEvents = new SystemEventNotifcationClient(() => InnerEnumerator);

                _systemEvents.DeviceAdded.Subscribe(x => OnDeviceAdded(x.DeviceId));
                _systemEvents.DeviceRemoved.Subscribe(x => OnDeviceRemoved(x.DeviceId));

                _deviceCache = new HashSet <CoreAudioDevice>();
                IMultimediaDeviceCollection collection;
                InnerEnumerator.EnumAudioEndpoints(EDataFlow.All, EDeviceState.All, out collection);

                using (var coll = new MultimediaDeviceCollection(collection))
                {
                    foreach (var mDev in coll)
                    {
                        CacheDevice(mDev);
                    }
                }
            });
        }
Пример #2
0
        public void LoadDevices(bool loadMeter = true, bool loadEndpoint = true, bool loadSession = true)
        {
            ComThread.Invoke(() =>
            {
                _systemEvents = new SystemEventNotifcationClient(() => InnerEnumerator);

                _systemEvents.DeviceAdded.Subscribe(x => OnDeviceAdded(x.DeviceId));
                _systemEvents.DeviceRemoved.Subscribe(x => OnDeviceRemoved(x.DeviceId));

                _deviceCache = new HashSet <CoreAudioDevice>();
                IMultimediaDeviceCollection collection;
                InnerEnumerator.EnumAudioEndpoints(EDataFlow.All, EDeviceState.All, out collection);

                using (var coll = new MultimediaDeviceCollection(collection))
                {
                    foreach (var mDev in coll)
                    {
                        CacheDevice(mDev, loadMeter, loadEndpoint, loadSession);
                    }
                }
            });
        }
Пример #3
0
        protected override void Dispose(bool disposing)
        {
            ComThread.BeginInvoke(() =>
            {
                _systemEvents?.Dispose();
                _systemEvents = null;
            })
            .ContinueWith(x =>
            {
                foreach (var device in _deviceCache)
                {
                    device.Dispose();
                }

                _deviceCache?.Clear();
                _lock?.Dispose();
                _innerEnumerator?.Dispose();

                base.Dispose(disposing);

                GC.SuppressFinalize(this);
            });
        }
Пример #4
0
 public ComMultimediaNotificationClient(SystemEventNotifcationClient client)
 {
     _client = client;
 }