/// <summary>
        /// Check the registry and compare to the current list of speakers on
        /// the machine (in case there is a mismatch).  Or return the default
        /// system speaker if none were selected.
        /// </summary>
        /// <returns>
        /// The FilterInfo of the speaker that was selected and still exists
        /// </returns>
        public static FilterInfo SelectedSpeaker()
        {
            FilterInfo selectedSpeaker = AudioRenderer.DefaultFilterInfo();

            string[] regSelectedSpeaker = AVReg.ValueNames(AVReg.SelectedSpeaker);
            if (regSelectedSpeaker != null)
            {
                FilterInfo[] spkrs = AudioRenderer.Renderers();

                for (int i = 0; i < spkrs.Length; i++)
                {
                    for (int j = 0; j < regSelectedSpeaker.Length; j++)
                    {
                        if (spkrs[i].Moniker == regSelectedSpeaker[j])
                        {
                            selectedSpeaker = spkrs[i];
                            break;
                        }
                    }
                }
            }
            else
            {
                selectedSpeaker = AudioRenderer.DefaultFilterInfo();
            }

            return(selectedSpeaker);
        }
예제 #2
0
        private void RestoreLinkedCamera()
        {
            // List the selected cameras
            foreach (FilterInfo fi in VideoCapability.SelectedCameras())
            {
                cboLinkedCamera.Items.Add(fi);
            }

            // Read from registry and select camera, if in list
            string[] linkedCamera = AVReg.ValueNames(AVReg.LinkedCamera);
            if (linkedCamera != null && linkedCamera.Length > 0)
            {
                Debug.Assert(linkedCamera.Length == 1);

                for (int i = 0; i < cboLinkedCamera.Items.Count; i++)
                {
                    FilterInfo fi = (FilterInfo)cboLinkedCamera.Items[i];
                    if (fi.Moniker == linkedCamera[0])
                    {
                        cboLinkedCamera.SelectedItem = fi;
                    }
                }
            }

            if (cboLinkedCamera.SelectedIndex == -1 && cboLinkedCamera.Items.Count > 0)
            {
                cboLinkedCamera.SelectedIndex = 0;
            }

            cboLinkedCamera.Enabled = cboLinkedCamera.Items.Count > 1;
        }
예제 #3
0
        private void cboMicrophones_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            try
            {
                if (acg != null)
                {
                    AVReg.DeleteValue(AVReg.SelectedMicrophone, acg.Source.Moniker);
                    DeactivateAudioCapability();
                }

                if (cboMicrophones.SelectedIndex != 0)
                {
                    FilterInfo fi = (FilterInfo)cboMicrophones.SelectedItem;
                    ActivateAudioCapability(fi);

                    AVReg.WriteValue(AVReg.SelectedMicrophone, fi.Moniker, fi.Name);
                }

                btnAdvancedAudioSettings.Enabled = cboMicrophones.SelectedIndex > 0;
                ckPlayAudio.Enabled  = cboMicrophones.SelectedIndex > 0;
                lblTestAudio.Enabled = cboMicrophones.SelectedIndex > 0;
            }
            catch (COMException ex)
            {
                Log(DShowError._AMGetErrorText(ex.ErrorCode));
                Log(ex.ToString());
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
            }
        }
예제 #4
0
 /// <summary>
 /// Save the device's current settings to the registry
 /// </summary>
 protected void SaveDeviceSettings()
 {
     if (cg.Source.HasPhysConns)
     {
         AVReg.WriteValue(DeviceKey(), AVReg.PhysicalConnectorIndex, cg.Source.PhysicalConnectorIndex);
     }
 }
예제 #5
0
        /// <summary>
        /// Restore the camera's last settings from the registry
        /// </summary>
        private void RestoreCameraSettings()
        {
            object setting;

            if (cg is VideoCaptureGraph)
            {
                VideoCaptureGraph vcg = (VideoCaptureGraph)cg;
                if (vcg.VideoSource.HasVideoStandards)
                {
                    if ((setting = AVReg.ReadValue(DeviceKey(), AVReg.VideoStandardIndex)) != null)
                    {
                        vcg.VideoSource.VideoStandardIndex = (int)setting;
                    }
                }
            }
            else if (cg is DVCaptureGraph)
            {
                DVCaptureGraph dvcg = (DVCaptureGraph)cg;
                if (dvcg.VideoSource.HasVideoStandards)
                {
                    if ((setting = AVReg.ReadValue(DeviceKey(), AVReg.VideoStandardIndex)) != null)
                    {
                        dvcg.VideoSource.VideoStandardIndex = (int)setting;
                    }
                }
            }
            if (cg.Source.HasPhysConns)
            {
                if ((setting = AVReg.ReadValue(DeviceKey(), AVReg.PhysicalConnectorIndex)) != null)
                {
                    cg.Source.PhysicalConnectorIndex = (int)setting;
                }
            }
        }
예제 #6
0
        private void clbCameras_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
        {
            try
            {
                if (e.NewValue == CheckState.Checked)
                {
                    ActivateVideoCapability((FilterInfo)clbCameras.Items[e.Index]);

                    // Only save the camera after we were able to successfully activate it
                    AVReg.WriteValue(AVReg.SelectedCameras, vcg.Source.Moniker,
                                     vcg.Source.FriendlyName);
                }
                else if (e.NewValue == CheckState.Unchecked)
                {
                    // Remove the camera from the registry, even if we can't shut it down
                    AVReg.DeleteValue(AVReg.SelectedCameras, vcg.Source.Moniker);

                    DeactivateVideoCapability((FilterInfo)clbCameras.SelectedItem);
                }
            }
            catch (COMException ex)
            {
                Log(DShowError._AMGetErrorText(ex.ErrorCode));
                Log(ex.ToString());
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
            }
        }
예제 #7
0
        public void SaveVideoCompressorSettings()
        {
            VideoCompressorQualityInfo vcqi = vcg.VideoCompressor.QualityInfo;

            // Cast to int, otherwise it gets stored as a string
            AVReg.WriteValue(DeviceKey(), AVReg.CompressorBitRate, (int)vcqi.BitRate);
            AVReg.WriteValue(DeviceKey(), AVReg.CompressorKeyFrameRate, vcqi.KeyFrameRate);
        }
예제 #8
0
        /// <summary>
        /// Save the camera's current settings to the registry
        /// </summary>
        public void SaveCameraSettings()
        {
            if (vcg.VideoSource.HasVideoStandards)
            {
                AVReg.WriteValue(DeviceKey(), AVReg.VideoStandardIndex, vcg.VideoSource.VideoStandardIndex);
            }

            SaveDeviceSettings();
        }
예제 #9
0
        /// <summary>
        /// Restore the video compressor's last settings from the registry
        /// </summary>
        private void RestoreVideoCompressorSettings()
        {
            VideoCompressorQualityInfo vcqi = DefaultQualityInfo();

            vcqi.KeyFrameRate = (int)AVReg.ReadValue(DeviceKey(), AVReg.CompressorKeyFrameRate);
            vcqi.BitRate      = (uint)((int)AVReg.ReadValue(DeviceKey(), AVReg.CompressorBitRate));

            vcg.VideoCompressor.QualityInfo = vcqi;
        }
        /// <summary>
        /// Save the microphone's current settings to the registry.  This only applies to
        /// audio sources, not DV sources
        /// </summary>
        public void SaveMicrophoneSettings()
        {
            AudioCaptureGraph acg = cg as AudioCaptureGraph;

            if (acg != null)
            {
                AVReg.WriteValue(DeviceKey(), AVReg.MicrophoneSourceIndex,
                                 acg.Source.InputPinIndex);

                SaveDeviceSettings();
            }
        }
예제 #11
0
        public void SaveLinkedCamera(FilterInfo fi)
        {
            // Delete previous link value
            string[] linkedCamera = AVReg.ValueNames(AVReg.LinkedCamera);
            if (linkedCamera != null && linkedCamera.Length > 0)
            {
                Debug.Assert(linkedCamera.Length == 1);
                AVReg.DeleteValue(AVReg.LinkedCamera, linkedCamera[0]);
            }

            // Set the new value
            AVReg.WriteValue(AVReg.LinkedCamera, fi.Moniker, fi.Name);
        }
예제 #12
0
        private void frmAVDevices_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            SaveSettings();

            if (ac != null)
            {
                // If a camera hasn't been linked, link the first one
                if (clbCameras.CheckedItems.Count > 0)
                {
                    bool goodLink = false;

                    // Read from registry and select camera, if in list
                    string[] linkedCamera = AVReg.ValueNames(AVReg.LinkedCamera);
                    if (linkedCamera != null && linkedCamera.Length > 0)
                    {
                        Debug.Assert(linkedCamera.Length == 1);

                        for (int i = 0; i < clbCameras.CheckedItems.Count; i++)
                        {
                            FilterInfo fi = (FilterInfo)clbCameras.CheckedItems[i];
                            if (fi.Moniker == linkedCamera[0])
                            {
                                goodLink = true;
                                break;
                            }
                        }
                    }

                    if (!goodLink)
                    {
                        SaveLinkedCamera((FilterInfo)clbCameras.CheckedItems[0]);
                    }
                }

                ac.Dispose();
            }

            foreach (VideoCapability vc in vcs.Values)
            {
                vc.Dispose();
            }

            if (ckPlayVideo.Checked)
            {
                // To clean up any video windows
                GC.Collect();
            }

            tmrPerf.Stop();
            trouble.Close();
        }
        /// <summary>
        /// Restore the audio device input pin setting from the registry.  Not applicable to DV sources
        /// </summary>
        private void RestoreMicrophoneSettings()
        {
            AudioCaptureGraph acg = cg as AudioCaptureGraph;

            if (acg != null)
            {
                object setting = AVReg.ReadValue(DeviceKey(), AVReg.MicrophoneSourceIndex);
                if (setting != null)
                {
                    if ((int)setting < cg.Source.InputPins.Count)
                    {
                        acg.AudioSource.InputPinIndex = (int)setting;
                    }
                }
            }
        }
        /// <summary>
        /// Restore custom buffer settings from the registry, if any.  This doesn't seem to work with DV Sources.
        /// It is also not relevant for the Opus Encoder since the settings will be overridden later in that case.
        /// </summary>
        private void RestoreBufferSettings()
        {
            if (cg is AudioCaptureGraph)
            {
                AudioCaptureGraph acg   = (AudioCaptureGraph)cg;
                object            bufSz = AVReg.ReadValue(DeviceKey(), AVReg.AudioBufferSize);
                if (bufSz != null)
                {
                    acg.AudioSource.BufferSize = (int)bufSz;
                }

                object bufCnt = AVReg.ReadValue(DeviceKey(), AVReg.AudioBufferCount);
                if (bufCnt != null)
                {
                    acg.AudioSource.BufferCount = (int)bufCnt;
                }
            }
        }
예제 #15
0
        /// <summary>
        /// Restore the video stream's last settings from the registry
        /// </summary>
        private void RestoreVideoSettings()
        {
            // Read media type from registry
            byte[] bytes = (byte[])AVReg.ReadValue(DeviceKey(), AVReg.MediaType);

            if (bytes != null)
            {
                AVReg.ms.Position = 0;
                AVReg.ms.Write(bytes, 0, bytes.Length);

                AVReg.ms.Position = 0;
                _AMMediaType mt = (_AMMediaType)AVReg.bf.Deserialize(AVReg.ms);

                // Read format block from registry
                if (mt.cbFormat != 0)
                {
                    bytes = (byte[])AVReg.ReadValue(DeviceKey(), AVReg.FormatBlock);
                    Debug.Assert(bytes.Length == mt.cbFormat);

                    mt.pbFormat = Marshal.AllocCoTaskMem((int)mt.cbFormat);
                    Marshal.Copy(bytes, 0, mt.pbFormat, (int)mt.cbFormat);

                    Log("Restoring stream settings...");
                    Log(MediaType.Dump(mt));

                    try
                    {
                        // Set and free
                        cg.Source.SetMediaType(ref mt);
                    }
                    catch (COMException ex)
                    {
                        Log(DShowError._AMGetErrorText(ex.ErrorCode));
                        Log(ex.ToString());
                    }
                    catch (Exception ex)
                    {
                        Log(ex.ToString());
                    }
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Restore the camera's last settings from the registry
        /// </summary>
        private void RestoreCameraSettings()
        {
            object setting;

            if (vcg.VideoSource.HasVideoStandards)
            {
                if ((setting = AVReg.ReadValue(DeviceKey(), AVReg.VideoStandardIndex)) != null)
                {
                    vcg.VideoSource.VideoStandardIndex = (int)setting;
                }
            }

            if (vcg.Source.HasPhysConns)
            {
                if ((setting = AVReg.ReadValue(DeviceKey(), AVReg.PhysicalConnectorIndex)) != null)
                {
                    vcg.Source.PhysicalConnectorIndex = (int)setting;
                }
            }
        }
예제 #17
0
        private void cboSpeakers_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            // Delete previous value
            string[] selectedSpeaker = AVReg.ValueNames(AVReg.SelectedSpeaker);
            if (selectedSpeaker != null)
            {
                Debug.Assert(selectedSpeaker.Length == 1);
                AVReg.DeleteValue(AVReg.SelectedSpeaker, selectedSpeaker[0]);
            }

            // Store current value
            FilterInfo fi = (FilterInfo)cboSpeakers.SelectedItem;

            AVReg.WriteValue(AVReg.SelectedSpeaker, fi.Moniker, fi.Name);

            if (acg != null)
            {
                RenderAndRunAudio(acg, false);
                RenderAndRunAudio(acg);
            }
        }
예제 #18
0
        /// <summary>
        /// Save the camera's current settings to the registry
        /// </summary>
        public void SaveCameraSettings()
        {
            if (cg is VideoCaptureGraph)
            {
                VideoCaptureGraph vcg = (VideoCaptureGraph)cg;
                if (vcg.VideoSource.HasVideoStandards)
                {
                    AVReg.WriteValue(DeviceKey(), AVReg.VideoStandardIndex, vcg.VideoSource.VideoStandardIndex);
                }
            }
            else if (cg is DVCaptureGraph)
            {
                DVCaptureGraph dvcg = (DVCaptureGraph)cg;
                if (dvcg.VideoSource.HasVideoStandards)    //Always false for DV devices?
                {
                    AVReg.WriteValue(DeviceKey(), AVReg.VideoStandardIndex, dvcg.VideoSource.VideoStandardIndex);
                }
            }

            SaveDeviceSettings();
        }
예제 #19
0
        /// <summary>
        /// Save the stream's current settings to the registry.
        /// </summary>
        protected void SaveStreamSettings()
        {
            _AMMediaType mt = cg.Source.GetMediaType();

            // Copy the pbFormat block into a byte array
            if (mt.pbFormat != IntPtr.Zero && mt.cbFormat > 0)
            {
                byte[] pbFormat = new byte[mt.cbFormat];
                Marshal.Copy(mt.pbFormat, pbFormat, 0, (int)mt.cbFormat);

                Marshal.FreeCoTaskMem(mt.pbFormat);
                mt.pbFormat = IntPtr.Zero;
                // Don't adjust cbFormat, will use on restore

                AVReg.WriteValue(DeviceKey(), AVReg.FormatBlock, pbFormat);
            }

            AVReg.ms.Position = 0;
            AVReg.bf.Serialize(AVReg.ms, mt);
            AVReg.WriteValue(DeviceKey(), AVReg.MediaType, AVReg.ms.ToArray());
        }
        /// <summary>
        /// Get the selected audio compressor from the registry.  It may be a moniker of a compressor that is enabled
        /// on the system or "Uncompressed".  Otherwise return the default compressor.
        /// </summary>
        /// <returns></returns>
        public static FilterInfo SelectedCompressor()
        {
            FilterInfo selectedCompressor    = AudioCompressor.DefaultFilterInfo();
            string     regSelectedCompressor = (string)AVReg.ReadValue(AVReg.SelectedDevices, AVReg.AudioCompressor);

            if (regSelectedCompressor != null)
            {
                if (regSelectedCompressor == "Uncompressed")
                {
                    return(new FilterInfo("Uncompressed", "Uncompressed", Guid.Empty));
                }

                foreach (FilterInfo fi in AudioCompressor.EnabledCompressors)
                {
                    if (fi.Moniker == regSelectedCompressor)
                    {
                        selectedCompressor = fi;
                        break;
                    }
                }
            }

            return(selectedCompressor);
        }
예제 #21
0
        /// <summary>
        /// Check the registry and compare to the current list of cameras on
        /// the machine (in case there is a mismatch).
        /// </summary>
        /// <returns>
        /// Return the FilterInfo for cameras that were selected and still exist
        /// </returns>
        public static FilterInfo[] SelectedCameras()
        {
            ArrayList selectedCameras = new ArrayList();

            string[] regSelectedCameras = AVReg.ValueNames(AVReg.SelectedCameras);
            if (regSelectedCameras != null)
            {
                FilterInfo[] cameras = VideoSource.Sources();

                for (int i = 0; i < cameras.Length; i++)
                {
                    for (int j = 0; j < regSelectedCameras.Length; j++)
                    {
                        if (cameras[i].Moniker == regSelectedCameras[j])
                        {
                            selectedCameras.Add(cameras[i]);
                            break;
                        }
                    }
                }
            }

            return((FilterInfo[])selectedCameras.ToArray(typeof(FilterInfo)));
        }
        /// <summary>
        /// Check the registry and compare to the current list of microphones on
        /// the machine (in case there is a mismatch).
        /// </summary>
        /// <returns>
        /// The FilterInfo for the mics that were selected and still exist
        /// </returns>
        public static FilterInfo[] SelectedMicrophones()
        {
            ArrayList selectedMics = new ArrayList();

            string[] regSelectedMics = AVReg.ValueNames(AVReg.SelectedMicrophone);
            if (regSelectedMics != null)
            {
                FilterInfo[] mics = AudioSource.Sources();

                for (int i = 0; i < mics.Length; i++)
                {
                    for (int j = 0; j < regSelectedMics.Length; j++)
                    {
                        if (mics[i].Moniker == regSelectedMics[j])
                        {
                            selectedMics.Add(mics[i]);
                            break;
                        }
                    }
                }
            }

            return((FilterInfo[])selectedMics.ToArray(typeof(FilterInfo)));
        }
        /// <summary>
        /// Populate form controls and compressor static values from the registry, while validating what was loaded.
        ///
        /// We assume that for each control whose value needs to be persisted there is a public static int
        /// field in the compressor class, the name of which is used as a key for finding validation data.
        /// Validation data may come in the form of an enum with int as the underlying data type, an
        /// int[] containing the accepted values, or an int[] containing min/max values. We look for them in
        /// that order, stopping when the first is found.
        ///
        /// Once validated we put the value into the corresponding ComboBox or TextBox.  If validation fails
        /// we get a default value from the compressor and use that instead.
        /// </summary>
        private void RestoreComboBoxValues()
        {
            // Loop over all the public statics in the compressor type.
            Type compressorType = typeof(OpusAudioCompressor);

            FieldInfo[] fields = compressorType.GetFields(BindingFlags.Public | BindingFlags.Static);
            foreach (FieldInfo field in fields)
            {
                if (field.IsLiteral || field.IsInitOnly)
                {
                    continue; //Ignore const and readonly
                }
                // Fetch the current value in case none is set in the registry.
                // On first use, this should be the default.
                object newValue = field.GetValue(null);

                // Read from registry
                object val = AVReg.ReadValue(AVReg.OpusCompressorKey, field.Name);
                if (val != null)
                {
                    newValue = val;
                    field.SetValue(null, newValue);
                }

                // Find the corresponding enum or array for validation
                Type  enumType;
                int[] valuesArray;
                // Check for enum first
                if ((enumType = findEnumType(field.Name)) != null)
                {
                    if (!enumType.IsEnumDefined(newValue))
                    {
                        //If the registry value is invalid, revert to default value
                        newValue = findDefaultValue(field.Name);
                        field.SetValue(null, newValue);
                    }

                    ComboBox cb = findComboBox(field.Name);
                    if (cb != null)
                    {
                        cb.SelectedItem = Enum.ToObject(enumType, newValue);
                    }
                }
                else if ((valuesArray = findValuesArray(field.Name)) != null)
                {
                    // If there's no matching enum, look for the corresponding array of int.
                    int  i         = (int)newValue;
                    bool validated = false;
                    foreach (int j in valuesArray)
                    {
                        if (i == j)
                        {
                            validated = true;
                            break;
                        }
                    }
                    if (!validated)
                    {
                        newValue = findDefaultValue(field.Name);
                        field.SetValue(null, newValue);
                    }

                    ComboBox cb = findComboBox(field.Name);
                    if (cb != null)
                    {
                        cb.SelectedItem = newValue;
                    }
                }
                else if ((valuesArray = findMinMaxArray(field.Name)) != null)
                {
                    // In this case the integer value is constrained by min and max, and the
                    // control is a TextBox.
                    if ((int)newValue < valuesArray[0] || (int)newValue > valuesArray[1])
                    {
                        newValue = findDefaultValue(field.Name);
                        field.SetValue(null, newValue);
                    }

                    TextBox tb = findTextBox(field.Name);
                    if (tb != null)
                    {
                        tb.Text = newValue.ToString();
                    }
                }
            }
        }
        /// <summary>
        /// Save compressor settings from the form back into the static properties and persist to the registry.
        /// </summary>
        protected override void SaveSettings()
        {
            // Compressor format
            OpusAudioCompressor.Frequency = (int)((CompressorFmt)this.cbCompressionFormat.SelectedItem).WFEX.SamplesPerSec;
            OpusAudioCompressor.Channels  = (int)((CompressorFmt)this.cbCompressionFormat.SelectedItem).WFEX.Channels;

            Type compressorType = typeof(OpusAudioCompressor);

            FieldInfo[] fields = compressorType.GetFields(BindingFlags.Public | BindingFlags.Static);
            foreach (FieldInfo field in fields)
            {
                if (field.IsLiteral || field.IsInitOnly)
                {
                    continue;
                }

                Type  enumType;
                int[] valuesArray;
                bool  validated    = false;
                int   checkedValue = 0;

                // Look for the enum type first
                if ((enumType = findEnumType(field.Name)) != null)
                {
                    object   saveValue;
                    ComboBox cb = findComboBox(field.Name);
                    if (cb == null)
                    {
                        continue;
                    }
                    if (enumTryParse(enumType, cb.SelectedValue.ToString(), out saveValue))
                    {
                        checkedValue = (int)saveValue;
                        validated    = true;
                    }
                }
                else if ((valuesArray = findValuesArray(field.Name)) != null)
                {
                    // Use a int[] of legal values
                    int      uncheckedValue = (int)field.GetValue(null);
                    ComboBox cb             = findComboBox(field.Name);
                    if ((cb == null) ||
                        ((cb != null) && (int.TryParse(cb.SelectedValue.ToString(), out uncheckedValue))))
                    {
                        foreach (int j in valuesArray)
                        {
                            if (uncheckedValue == j)
                            {
                                checkedValue = uncheckedValue;
                                validated    = true;
                                break;
                            }
                        }
                    }
                }
                else if ((valuesArray = findMinMaxArray(field.Name)) != null)
                {
                    // Use a int[] with min/max values.
                    TextBox tb = findTextBox(field.Name);
                    if (tb == null)
                    {
                        continue;
                    }
                    if (int.TryParse(tb.Text, out checkedValue))
                    {
                        if (checkedValue >= valuesArray[0] && checkedValue <= valuesArray[1])
                        {
                            validated = true;
                        }
                    }
                }

                if (!validated)
                {
                    checkedValue = (int)findDefaultValue(field.Name);
                }
                field.SetValue(null, checkedValue);
                AVReg.WriteValue(AVReg.OpusCompressorKey, field.Name, checkedValue);
            }
        }