Esempio n. 1
0
        private void DoSetup2()
        {
            Guid g    = new Guid("{42150CD9-CA9A-4EA5-9939-30EE037F6E74}");
            Type type = Type.GetTypeFromCLSID(g);

            m_ica = Activator.CreateInstance(type) as ICodecAPI;
        }
Esempio n. 2
0
        private void SetAudioDecoderOutputToPCMStereo(IBaseFilter audiodecoder)
        {
            // Set audio decoder to output 2 channel PCM  // wm/asf writer doesn't support multi-channel audio
            int       hr;
            Guid      AVDecCommonOutputFormat = new Guid(0x3c790028, 0xc0ce, 0x4256, 0xb1, 0xa2, 0x1b, 0x0f, 0xc8, 0xb1, 0xdc, 0xdc);
            ICodecAPI audioConfig             = audiodecoder as ICodecAPI;

            if (audioConfig != null)
            {
                object pValue = 0;

                hr = audioConfig.GetValue(AVDecCommonOutputFormat, out pValue);
                DsError.ThrowExceptionForHR(hr);

                hr = audioConfig.IsModifiable(AVDecCommonOutputFormat);

                if (hr == 0)
                {
                    Guid AVDecAudioOutputFormat_PCM_Stereo_Auto = new Guid(0x696e1d35, 0x548f, 0x4036, 0x82, 0x5f, 0x70, 0x26, 0xc6, 0x00, 0x11, 0xbd);
                    pValue = AVDecAudioOutputFormat_PCM_Stereo_Auto.ToString("B");
                    hr     = audioConfig.SetValue(AVDecCommonOutputFormat, ref pValue);
                    DsError.ThrowExceptionForHR(hr);
                }
            }
        }
Esempio n. 3
0
        protected void SetMPEG2Parameters()
        {
#if COMMENT
            int hr;
            MPEG2AudioConfig config = SourceConfig.MPEG2Audio;

            if (Profile == null)
            {
                AppLogger.Message("SetMPEG2Parameters called, but Profile is not set");
                return;
            }

            IntPtr nativeVariant = Marshal.AllocCoTaskMem(64);

            ICodecAPI codecAPI_MP3 = GetCodecAPI_MP3();

            Marshal.GetNativeVariantForObject(config.DSP, nativeVariant);
            hr = codecAPI_MP3.SetValue(CodecAPIParam.DSP, nativeVariant);
            DsError.ThrowExceptionForHR(hr);

            Marshal.GetNativeVariantForObject(config.Mic, nativeVariant);
            hr = codecAPI_MP3.SetValue(CodecAPIParam.Mic, nativeVariant);
            DsError.ThrowExceptionForHR(hr);

            Marshal.GetNativeVariantForObject(config.BitRateKbps, nativeVariant);
            hr = codecAPI_MP3.SetValue(CodecAPIParam.AudioBitRate, nativeVariant);
            DsError.ThrowExceptionForHR(hr);

            hr = Marshal.ReleaseComObject(codecAPI_MP3);
            DsError.ThrowExceptionForHR(hr);

            Marshal.FreeCoTaskMem(nativeVariant);
#endif
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the ICodecAPI interface for whichever pin is in use for the current codec
        /// </summary>
        /// <returns>a reference to the ICodecAPI on the current pin</returns>
        private ICodecAPI GetCodecAPI()
        {
            string pinName;

            if (_currentVideoSettings.CodecType == VideoCodecType.H264)
            {
                pinName = "H264";
            }
            else
            {
                throw new NotImplementedException("GetCodecAPI not implemented for codectype " + _currentVideoSettings.CodecType.ToString());
            }
            IPin pin = DsFindPin.ByName(_captureFilter, pinName);

            if (pin == null)
            {
                throw new Exception(pinName + " pin not found on MangoCapture filter.");
            }
            ICodecAPI codecAPI = (ICodecAPI)pin;

            if (codecAPI == null)
            {
                throw new Exception("ICodecAPI interface not found on pin " + pinName);
            }
            return(codecAPI);
        }
Esempio n. 5
0
        protected void SetDSP_and_Camera(StreamSourceInfo sourceConfig)
        {
            int hr;

            IntPtr nativeVariant = Marshal.AllocCoTaskMem(64);

            ICodecAPI codecAPI_H264 = GetCodecAPI();

            if (sourceConfig.DeviceAddress == null)
            {
                throw new SourceConfigException("DeviceAddress may not be null!");
            }

            AppLogger.Message(String.Format("MangoDVR SetDSP_and_Camera Channel={0} Input={1}", sourceConfig.DeviceAddress.Channel, sourceConfig.DeviceAddress.Input));
            Marshal.GetNativeVariantForObject(sourceConfig.DeviceAddress.Channel, nativeVariant);
            hr = codecAPI_H264.SetValue(CodecAPIParam.DSP, nativeVariant);
            DsError.ThrowExceptionForHR(hr);

            Marshal.GetNativeVariantForObject(sourceConfig.DeviceAddress.Input, nativeVariant);
            hr = codecAPI_H264.SetValue(CodecAPIParam.Cam, nativeVariant);
            DsError.ThrowExceptionForHR(hr);

            hr = Marshal.ReleaseComObject(codecAPI_H264);
            DsError.ThrowExceptionForHR(hr);

            Marshal.FreeCoTaskMem(nativeVariant);
        }
        /// <summary>
        /// Creates the object that implements the IQuality interface
        /// </summary>
        public static IQuality createQualityControl(Configuration configuration, IBaseFilter filterVideoEncoder,
                                                    IBaseFilter filterCapture, IBaseFilter filterMultiplexer,
                                                    IBaseFilter filterVideoCompressor)
        {
            ICodecAPI codecAPI = checkCodecAPI(filterVideoEncoder, filterCapture, filterMultiplexer, filterVideoCompressor);

            if (codecAPI != null)
            {
                return(new CodecAPIControl(configuration, codecAPI));
            }

            IVideoEncoder videoEncoder = checkVideoEncoder(filterVideoEncoder, filterCapture, filterMultiplexer,
                                                           filterVideoCompressor);

            if (videoEncoder != null)
            {
                return(new VideoEncoderControl(configuration, videoEncoder));
            }

#pragma warning disable 618,612
            IEncoderAPI encoderAPI = checkEncoderAPI(filterVideoEncoder, filterCapture, filterMultiplexer,
                                                     filterVideoCompressor);
            if (encoderAPI != null)
            {
                return(new EncoderAPIControl(configuration, encoderAPI));
            }
#pragma warning restore 618,612

            return(null);
        }
        private static ICodecAPI checkCodecAPI(IBaseFilter filterVideoEncoder, IBaseFilter filterCapture,
                                               IBaseFilter filterMultiplexer, IBaseFilter filterVideoCompressor)
        {
            ICodecAPI videoEncoder = null;

            if (filterVideoEncoder != null)
            {
                videoEncoder = filterVideoEncoder as ICodecAPI;
            }

            if (videoEncoder == null && filterCapture != null)
            {
                videoEncoder = filterCapture as ICodecAPI;
            }

            if (videoEncoder == null && filterMultiplexer != null)
            {
                videoEncoder = filterMultiplexer as ICodecAPI;
            }

            if (videoEncoder == null && filterVideoCompressor != null)
            {
                videoEncoder = filterVideoCompressor as ICodecAPI;
            }

            return(videoEncoder);
        }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CodecAPIControl"/> class.
 /// </summary>
 /// <param name="configuration">The encoder settings to use.</param>
 /// <param name="codecAPI">The ICodecAPI interface to the filter that must be used to control the quality.</param>
 public CodecAPIControl(Configuration configuration, ICodecAPI codecAPI)
   : base(configuration)
 {
   _codecAPI = codecAPI;
   Log.Log.WriteFile("analog: ICodecAPI supported by: " + FilterGraphTools.GetFilterName(_codecAPI as IBaseFilter) +
                     "; Checking capabilities ");
   CheckCapabilities();
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CodecAPIControl"/> class.
 /// </summary>
 /// <param name="configuration">The encoder settings to use.</param>
 /// <param name="codecAPI">The ICodecAPI interface to the filter that must be used to control the quality.</param>
 public CodecAPIControl(Configuration configuration, ICodecAPI codecAPI)
     : base(configuration)
 {
     _codecAPI = codecAPI;
     Log.Log.WriteFile("analog: ICodecAPI supported by: " + FilterGraphTools.GetFilterName(_codecAPI as IBaseFilter) +
                       "; Checking capabilities ");
     CheckCapabilities();
 }
Esempio n. 10
0
        private void DoSetup()
        {
            DsDevice [] capDevices = DsDevice.GetDevicesOfCat(FilterCategory.LegacyAmFilterCategory);

            foreach (DsDevice dev in capDevices)
            {
                string s;

                dev.Mon.GetDisplayName(null, null, out s);

                try
                {
                    m_ica = Marshal.BindToMoniker(s) as ICodecAPI;
                    if (dev.Name == "Microsoft MPEG-1/DD Audio Decoder")
                    {
                        break;
                    }
                }
                catch { }
            }
        }
Esempio n. 11
0
 public CodecApi(object api)
     : base(api)
 {
     _api = (ICodecAPI)api;
 }
Esempio n. 12
0
        public override void ChangeProfile(Profile newProfile)
        {
            try
            {
                int hr;

                if (newProfile.Video == null)
                {
                    AppLogger.Message("Mango.ChangeProfile called but newProfile.Video == null");
                }
                IntPtr    nativeVariant = Marshal.AllocCoTaskMem(64);
                ICodecAPI codecAPI      = GetCodecAPI();
                if (_captureFilter != null)
                {
                    //detect codec change
                    if (newProfile.Video.CodecType != _currentVideoSettings.CodecType)
                    {
                        throw new ServerGraphRebuildException("codec switch");
                    }

                    //detect resolution change
                    if (newProfile.Video.ImageSize != _currentVideoSettings.ImageSize)
                    {
                        AppLogger.Message(String.Format("ImageSize changing from {0} to {1}",
                                                        _currentVideoSettings.ImageSize,
                                                        newProfile.Video.ImageSize));

                        if (State == ServerGraphState.Running)
                        {
                            throw new ServerGraphRebuildException("ImageSize change");
                        }

                        Marshal.GetNativeVariantForObject(newProfile.Video.ImageSize, nativeVariant);
                        hr = codecAPI.SetValue(CodecAPIParam.ImageSize, nativeVariant);
                        DsError.ThrowExceptionForHR(hr);
                        _currentVideoSettings.ImageSize = newProfile.Video.ImageSize;
                    }

                    //set key frame rate
                    if (newProfile.Video.KeyFrameRate != _currentVideoSettings.KeyFrameRate)
                    {
                        Marshal.GetNativeVariantForObject(newProfile.Video.KeyFrameRate, nativeVariant);
                        hr = codecAPI.SetValue(CodecAPIParam.KeyFrameRate, nativeVariant);
                        DsError.ThrowExceptionForHR(hr);
                        _currentVideoSettings.KeyFrameRate = newProfile.Video.KeyFrameRate;
                    }

                    //set frame rate
                    if ((newProfile.Video.FrameRate != _currentVideoSettings.FrameRate) || (newProfile.Video.FrameRateUnits != _currentVideoSettings.FrameRateUnits))
                    {
                        int nFrames;
                        if (newProfile.Video.FrameRateUnits == VideoFrameRateUnits.FramesPerSecond)
                        {
                            nFrames = 30 / newProfile.Video.FrameRate;
                        }
                        else if (newProfile.Video.FrameRateUnits == VideoFrameRateUnits.FramesPerMinute)
                        {
                            nFrames = 1800 / newProfile.Video.FrameRate;
                        }
                        else
                        {
                            throw new UnsupportedFrameRateUnitsException(newProfile.Video.FrameRateUnits);
                        }
                        if (nFrames < 1)
                        {
                            throw new UnsupportedFrameRateUnitsException(newProfile.Video.FrameRateUnits);
                        }
                        Marshal.GetNativeVariantForObject(nFrames, nativeVariant);
                        hr = codecAPI.SetValue(CodecAPIParam.FrameRate, nativeVariant);
                        DsError.ThrowExceptionForHR(hr);
                        _currentVideoSettings.FrameRate      = newProfile.Video.FrameRate;
                        _currentVideoSettings.FrameRateUnits = newProfile.Video.FrameRateUnits;
                    }

                    //set constatnt bit rate
                    if (newProfile.Video.ConstantBitRate != _currentVideoSettings.ConstantBitRate)
                    {
                        Marshal.GetNativeVariantForObject(newProfile.Video.ConstantBitRate, nativeVariant);
                        hr = codecAPI.SetValue(PropSetID.ENCAPIPARAM_BitRate, nativeVariant);
                        DsError.ThrowExceptionForHR(hr);
                        _currentVideoSettings.ConstantBitRate = newProfile.Video.ConstantBitRate;
                    }
                }
                Marshal.FreeCoTaskMem(nativeVariant);
                hr = Marshal.ReleaseComObject(codecAPI);
                DsError.ThrowExceptionForHR(hr);
                base.ChangeProfile(newProfile);
            }
            catch (COMException ex)
            {
                if ((ex.ErrorCode == DsResults.MXE_E_Timeout) ||
                    (ex.ErrorCode == DsResults.MXE_E_Fail))
                {
                    throw new ServerGraphRebuildException("Failure from MX card! " + ex.ErrorCode.ToString("X"));
                }
                else
                {
                    throw ex;
                }
            }
        }