Skip to content

The CoreAudioController slow at InnerEnumerator.EnumAudioEndpoints #72

@EzEddinM

Description

@EzEddinM

The CoreControlAudio is slow because of the InnerEnumerator.EnumAudioEndpoints(EDataFlow.All, EDeviceState.All, out collection);
Namespace AudioSwitcher.AudioApi.CoreAudio, class CoreAudioController , Line 46
AudioSwitcher.AudioApi.CoreAudio/CoreAudioController.cs
, EDeviceState.All => will it be possible to create a new constructor with EDeviceState as a parameter?

something like this:

public CoreAudioController(EDeviceState eDeviceState)

and change the InnerEnumerator.EnumAudioEndpoints to InnerEnumerator.EnumAudioEndpoints(EDataFlow.All, eDeviceState, out collection);

`Code:

    public CoreAudioController(EDeviceState eDeviceState)
    {
        // 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, out collection);

            using (var coll = new MultimediaDeviceCollection(collection))
            {
                foreach (var mDev in coll)
                    CacheDevice(mDev);
            }
        });
    }

`

so if you do it we can get the Devices that we need and not all Devices.

Use of the constructor will be somthing like this:

CoreAudioController coreAudioController = new AudioSwitcher.AudioApi.CoreAudio.CoreAudioController(EDeviceState.Active);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions