Пример #1
0
        public bool EnumerateAudioSources()
        {
            try
            {
                WMEncoder Encoder = new WMEncoder();

                // Retrieve source and device plug-in info manager objects from WMEncoder.
                IWMEncSourcePluginInfoManager        SrcPlugMgr = Encoder.SourcePluginInfoManager;
                IWMEncDeviceControlPluginInfoManager DCPlugMgr  = Encoder.DeviceControlPluginInfoManager;

                // Loop through all the audio and video devices on the system.
                IWMEncPluginInfo PlugInfo;
                for (int i = 0; i < SrcPlugMgr.Count; i++)
                {
                    // Set the IWMEncPluginInfo object to the current plug-in.
                    PlugInfo = SrcPlugMgr.Item(i);

                    // Find the device plug-ins that support resources.
                    if (PlugInfo.SchemeType == "DEVICE" && PlugInfo.Resources == true)
                    {
                        // Loop through the resources in the current plug-in.
                        for (int j = 0; j < PlugInfo.Count; j++)
                        {
                            //if(frm_Rec.chkAudio.Checked==true)

                            {
                                // Add audio resources to the cboAudioSource combo box.
                                if (PlugInfo.MediaType == WMENC_SOURCE_TYPE.WMENC_AUDIO)
                                {
                                    m_sourceEnumDlg.audioSources.Items.Add(PlugInfo.Item(j));
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Video Recordong Module ===>Screen Capture.cs line==> 147", exp, "Error Enumeration Audio Resources: " + exp.Message.ToString(), true);
                //WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Error Stoping encoder: " + exp.Message.ToString());
                //Trace.WriteLine(exp.ToString()+"---"+exp.Message+"---"+exp.Source+exp.StackTrace+"---"+exp.TargetSite+"---"+exp.InnerException);
            }

            //DialogResult ret = m_sourceEnumDlg.ShowDialog();
            //if( ret == DialogResult.Cancel)
            //	return false;

            //m_szAudioSource = m_sourceEnumDlg.selectedItem;

            m_szAudioSource = config.Read("Driver");

            return(true);
        }
Пример #2
0
        /**
         * Get available sources of specified type.
         * @param type : Source type.
         * @return list of available sources. This sources can be selected by SetSource(...) method.
         */
        public static IList <string> GetSources(ESourceType type)
        {
            System.Collections.Generic.IList <string> sources = new System.Collections.Generic.List <string>();
            try
            {
                WMEncoderClass encoder = new WMEncoderClass();
                IWMEncSourcePluginInfoManager srcPlugMgr = encoder.SourcePluginInfoManager;
                IWMEncPluginInfo plugInfo;

                for (int i = 0; i < srcPlugMgr.Count; i++)
                {
                    plugInfo = srcPlugMgr.Item(i);
                    if (type == ESourceType.DesktopVideo &&
                        plugInfo.SchemeType == "ScreenCap" &&
                        plugInfo.MediaType == WMENC_SOURCE_TYPE.WMENC_VIDEO)
                    {
                        log.Debug(type + " source -->" + plugInfo.Name);
                        sources.Add(plugInfo.Name);
                    }
                    else
                    {
                        if (plugInfo.SchemeType == "DEVICE" && plugInfo.Resources == true)
                        {
                            for (int j = 0; j < plugInfo.Count; j++)
                            {
                                if (plugInfo.MediaType == WMENC_SOURCE_TYPE.WMENC_AUDIO &&
                                    type == ESourceType.DeviceAudio)
                                {
                                    log.Debug(type + " source(" + j + ") -->" + plugInfo.Item(j));
                                    sources.Add(plugInfo.Item(j));
                                }

                                if (plugInfo.MediaType == WMENC_SOURCE_TYPE.WMENC_VIDEO &&
                                    type == ESourceType.DeviceVideo)
                                {
                                    log.Debug(type + " source(" + j + ") -->" + plugInfo.Item(j));
                                    sources.Add(plugInfo.Item(j));
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.ErrorException("Exception retrieving sources", e);
                sources = null;
            }

            return(sources);
        }
Пример #3
0
        public frm_AudioConfig()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            btn_Previous.Enabled = false;
            btn_Finish.Enabled   = false;

            // Create a WMEncoder object.
            WMEncoder Encoder = new WMEncoder();



            // Retrieve source and device plug-in info manager objects from WMEncoder.
            IWMEncSourcePluginInfoManager        SrcPlugMgr = Encoder.SourcePluginInfoManager;
            IWMEncDeviceControlPluginInfoManager DCPlugMgr  = Encoder.DeviceControlPluginInfoManager;

            // Loop through all the audio and video devices on the system.
            for (int i = 0; i < SrcPlugMgr.Count; i++)
            {
                // Set the IWMEncPluginInfo object to the current plug-in.
                PlugInfo = SrcPlugMgr.Item(i);

                // Find the device plug-ins that support resources.
                if (PlugInfo.SchemeType == "DEVICE" && PlugInfo.Resources == true)
                {
                    // Loop through the resources in the current plug-in.
                    for (int j = 0; j < PlugInfo.Count; j++)
                    {
                        // Add audio resources to the cboAudioSource combo box.
                        if (PlugInfo.MediaType == WMENC_SOURCE_TYPE.WMENC_AUDIO)
                        {
                            cboAudioSource.Items.Add(PlugInfo.Item(j));
                        }
                    }
                }
            }

            cboAudioSource.SelectedIndex = 0;

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// 开始录制
        /// </summary>
        /// <param name="mediaInfo"></param>
        /// <param name="captureArea">捕获区域(录制的区域)</param>
        internal override void Start(MediaInfo mediaInfo, ScreenArea captureArea)
        {
            // 设置一些必要的变量
            IWMEncSourceGroupCollection sourceGroupCollection;
            IWMEncSourceGroup2          sourceGroup;
            IWMEncAudioSource           audioSource;
            IWMEncVideoSource2          vedioSource;

            //IWMEncProfile2 Pro;

            sourceGroupCollection = encoder.SourceGroupCollection;
            sourceGroup           = (IWMEncSourceGroup2)sourceGroupCollection.Add("SG_1");

            // 假如 是仅音频,或者是 音频视频 全有,则添加音频设备,并进行相关设置
            if (mediaInfo.AudioVedio == AudioVedioType.AudioOnly || mediaInfo.AudioVedio == AudioVedioType.Both)
            {
                audioSource = (IWMEncAudioSource)sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
                audioSource.SetInput("Default_Audio_Device", "DEVICE", "");
            }

            // 假如 是仅视频,或者是 音频视频 全有,则添加视频设备
            if (mediaInfo.AudioVedio == AudioVedioType.VedioOnly || mediaInfo.AudioVedio == AudioVedioType.Both)
            {
                vedioSource = (IWMEncVideoSource2)sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
                vedioSource.SetInput("ScreenCapture1", "ScreenCap", "");

                // 视频尺寸/显示器尺寸  缩放比
                Size  screenSize = SystemInformation.PrimaryMonitorSize;
                float scaleX     = (float)vedioSource.Height / (float)screenSize.Height;
                float scaleY     = (float)vedioSource.Width / (float)screenSize.Width;

                // 设置左边和上部剪裁区
                vedioSource.CroppingLeftMargin = (int)((float)captureArea.X * scaleY);
                vedioSource.CroppingTopMargin  = (int)((float)captureArea.Y * scaleX);

                // 设置右边和下部剪裁区
                int bottomMargin = screenSize.Height - captureArea.Height - captureArea.Y;
                int rightMargin  = screenSize.Width - captureArea.Weight - captureArea.X;
                vedioSource.CroppingRightMargin  = (int)((float)bottomMargin * scaleY);
                vedioSource.CroppingBottomMargin = (int)((float)rightMargin * scaleX);
            }

            // 设置压缩方式
            // 首先必须刷新一下信息
            IWMEncSourcePluginInfoManager sourcePluginInfoManager = encoder.SourcePluginInfoManager;

            sourcePluginInfoManager.Refresh();
            IWMEncProfileCollection wpfc = encoder.ProfileCollection;

            // 将压缩方式的名称添加进 profileNames 变量,将压缩方式对象本身添加到profiles 变量
            for (int i = 0; i < wpfc.Count; i++)
            {
                if (mediaInfo.ProfileName == wpfc.Item(i).Name)
                {
                    sourceGroup.set_Profile(wpfc.Item(i));
                    break;
                }
            }

            // 设置存放位置
            encoder.File.LocalFileName = mediaInfo.SavePath;

            // 启动
            encoder.Start();
        }
        public override Hashtable GetProfileInfos()
        {
            // 先清空
            profileInfos.Clear();

            // 声明必要变量
            IWMEncSourcePluginInfoManager sourceGroupCollection = encoder.SourcePluginInfoManager;
            IWMEncProfileCollection       profileCollection     = encoder.ProfileCollection;
            IWMEncProfile2 profile2 = new WMEncProfile2Class();

            // 刷新
            sourceGroupCollection.Refresh();

            // 将所有压缩方式的相关信息 依次存入 profileInfos(Hashtable)。
            for (int i = 0; i < profileCollection.Count; i++)
            {
                // 利用wp2获取压缩方式的相关信息
                profile2.LoadFromIWMProfile((IWMEncProfile)profileCollection.Item(i));

                // 获取压缩方式的相关描述
                StringBuilder profileInfo = new StringBuilder();
                profileInfo.AppendLine(profileCollection.Item(i).Description);
                for (int j = 0; j < profile2.AudienceCount; j++)
                {
                    IWMEncAudienceObj audienceObj = profile2.get_Audience(j);
                    // 假如此听众处于被选中状态
                    if (audienceObj.Selected)
                    {
                        object audioCodecName = null;
                        object videoCodecName = null;
                        try
                        {
                            // 得到音频编码名称
                            int audioCodecIndex = audienceObj.get_AudioCodec(0);
                            profile2.EnumAudioCodec(audioCodecIndex, out audioCodecName);

                            // 得到视频编码名称
                            int videoCodecIndex = audienceObj.get_VideoCodec(0);
                            profile2.EnumVideoCodec(videoCodecIndex, out videoCodecName);
                        }
                        catch
                        {
                        }

                        // 假如音频编码名称不为NULL
                        if (audioCodecName != null)
                        {
                            profileInfo.AppendLine("音频编码:" + audioCodecName.ToString());
                        }

                        // // 假如频编码名称不为NULL
                        if (videoCodecName != null)
                        {
                            profileInfo.AppendLine("视频编码:" + videoCodecName.ToString());
                            profileInfo.AppendLine("视频高度:" + Convert.ToString(audienceObj.get_VideoHeight(0)) + "\t视频宽度:" + Convert.ToString(audienceObj.get_VideoWidth(0)));
                        }
                    }
                }

                profileInfos.Add(profileCollection.Item(i).Name, profileInfo.ToString());
            }

            return(profileInfos);
        }