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 }
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); }
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); } } }
public void SetValue(Guid api, IntPtr value) => _api.SetValue(api, value);
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; } } }
/// <summary> /// Sets the value for the give GUID /// </summary> /// <param name="guid">GUID</param> /// <param name="newBitRateModeO">Bit Rate Mode object</param> /// <returns>HR result</returns> protected override int SetValue(Guid guid, ref object newBitRateModeO) { return(_codecAPI.SetValue(guid, ref newBitRateModeO)); }