Esempio n. 1
0
        private void ReloadLines()
        {
            MMErrors errorCode = 0;

            _audioLines.Clear();

            MIXERLINE mxl = new MIXERLINE();
            uint      dwDestination;

            unchecked
            {
                dwDestination = (uint)-1;
            }

            mxl.cbStruct        = (uint)Marshal.SizeOf(mxl);
            mxl.dwComponentType = _componentType;

            errorCode = (MMErrors)MixerNative.mixerGetLineInfo(_hMixer, ref mxl, MIXER_GETLINEINFOF.COMPONENTTYPE);
            if (errorCode != MMErrors.MMSYSERR_NOERROR)
            {
                throw new MixerException(errorCode, WMME.Audio.GetErrorDescription(FuncName.fnMixerGetLineInfo, errorCode));
            }

            dwDestination = mxl.dwDestination;

            var mixLine = new AudioLine(this, mxl);

            if (mixLine.CControls != 0 && !(mixLine.CControls == 1 && mixLine.Controls[0].ControlType == MIXERCONTROL_CONTROLTYPE.MUX))
            {
                _audioLines.Add(mixLine);
            }

            int cConnections = (int)mxl.cConnections;

            for (int i = 0; i < cConnections; i++)
            {
                mxl.cbStruct      = (uint)Marshal.SizeOf(mxl);
                mxl.dwDestination = dwDestination;
                mxl.dwSource      = (uint)i;

                errorCode = (MMErrors)MixerNative.mixerGetLineInfo(Handle, ref mxl, MIXER_GETLINEINFOF.SOURCE);
                if (errorCode != MMErrors.MMSYSERR_NOERROR)
                {
                    throw new MixerException(errorCode, WMME.Audio.GetErrorDescription(FuncName.fnMixerGetLineInfo, errorCode));
                }

                var mixLineNew = new AudioLine(this, mxl);

                if (mixLineNew.CControls != 0)
                {
                    _audioLines.Add(mixLineNew);
                }
            }
        }
Esempio n. 2
0
        private void ReloadAudioDevices()
        {
            if (_reloadDevicesInProgress)
            {
                return;
            }

            MMErrors errorCode = 0;
            IntPtr   hMixer    = IntPtr.Zero;

            try
            {
                _reloadDevicesInProgress = true;

                var       newAudioDevices = new List <AudioDeviceDescriptor>();
                MIXERCAPS wic             = new MIXERCAPS();

                int iNumDevs = MixerNative.mixerGetNumDevs();

                for (int i = 0; i < iNumDevs; i++)
                {
                    // Get info about the next device
                    errorCode = (MMErrors)MixerNative.mixerGetDevCaps(i, ref wic, Marshal.SizeOf(wic));
                    if (errorCode != MMErrors.MMSYSERR_NOERROR)
                    {
                        throw new MixerException(errorCode, GetErrorDescription(FuncName.fnMixerGetDevCaps, errorCode));
                    }

                    errorCode = (MMErrors)MixerNative.mixerOpen(out hMixer, i, IntPtr.Zero, IntPtr.Zero, 0);
                    if (errorCode != MMErrors.MMSYSERR_NOERROR)
                    {
                        throw new MixerException(errorCode, GetErrorDescription(FuncName.fnMixerOpen, errorCode));
                    }

                    MIXERLINE mxl = new MIXERLINE();
                    mxl.cbStruct = (uint)Marshal.SizeOf(mxl);

                    var deviceDescriptor = new AudioDeviceDescriptor()
                    {
                        DeviceId = i,
                        Name     = wic.szPname
                    };

                    foreach (var mixerlineComponenttype in AudioDevice.RecordingLineTypes)
                    {
                        mxl.dwComponentType = mixerlineComponenttype;
                        if (MixerNative.mixerGetLineInfo(hMixer, ref mxl, MIXER_GETLINEINFOF.COMPONENTTYPE) == 0)
                        {
                            deviceDescriptor.RecordingSupport       = true;
                            deviceDescriptor.RecordingComponentType = mixerlineComponenttype;

                            break;
                        }
                    }

                    foreach (var mixerlineComponenttype in AudioDevice.PlaybackLineTypes)
                    {
                        mxl.dwComponentType = mixerlineComponenttype;
                        if (MixerNative.mixerGetLineInfo(hMixer, ref mxl, MIXER_GETLINEINFOF.COMPONENTTYPE) == 0)
                        {
                            deviceDescriptor.PlaybackSupport       = true;
                            deviceDescriptor.PlaybackComponentType = mixerlineComponenttype;

                            break;
                        }
                    }

                    if (deviceDescriptor.PlaybackSupport || deviceDescriptor.RecordingSupport)
                    {
                        if (deviceDescriptor.PlaybackSupport && deviceDescriptor.RecordingSupport)
                        {
                            var playbackDeviceDescriptor = new AudioDeviceDescriptor()
                            {
                                DeviceId              = deviceDescriptor.DeviceId,
                                Name                  = deviceDescriptor.Name,
                                PlaybackSupport       = true,
                                RecordingSupport      = false,
                                PlaybackComponentType = deviceDescriptor.PlaybackComponentType
                            };

                            var recordingDeviceDescriptor = new AudioDeviceDescriptor()
                            {
                                DeviceId               = deviceDescriptor.DeviceId,
                                Name                   = deviceDescriptor.Name,
                                PlaybackSupport        = false,
                                RecordingSupport       = true,
                                RecordingComponentType = deviceDescriptor.RecordingComponentType
                            };

                            newAudioDevices.Add(playbackDeviceDescriptor);
                            newAudioDevices.Add(recordingDeviceDescriptor);
                        }
                        else
                        {
                            newAudioDevices.Add(deviceDescriptor);
                        }
                    }
                }

                if (newAudioDevices.Count > 0 || (_audioDevices.Count > 0 && iNumDevs == 0))
                {
                    UpdateAudioDevicesLists(newAudioDevices);
                }
            }
            finally
            {
                if (hMixer != IntPtr.Zero)
                {
                    MixerNative.mixerClose(hMixer);
                }

                _reloadDevicesInProgress = false;
            }
        }