Esempio n. 1
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;
                }
            }
        }
Esempio n. 2
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>
        /// 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;
                }
            }
        }
Esempio n. 5
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());
                    }
                }
            }
        }
Esempio n. 6
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;
                }
            }
        }
        /// <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);
        }
        /// <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();
                    }
                }
            }
        }