📄 formavwizard.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using LanMsg.AV;
namespace LanMsg
{
/// <summary>
/// AVWizardForm 的摘要说明。
/// </summary>
public class FormAVWizard : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl ts;
private System.Windows.Forms.TabPage pvideo;
private System.Windows.Forms.TabPage paudio;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnadvance;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Panel pnlpreview;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
LanMsg.AV.VideoCapturer vc;
LanMsg.AV.WaveIn wi;
LanMsg.AV.WaveOut wo;
WAVEFORMATEX wf;
LanMsg.AV.Mixer mixer;
LanMsg.AV.Mixer.MixerControlDetail indtl,outdtl;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button btnsave;
private System.Windows.Forms.Button btncancel;
private System.Windows.Forms.ComboBox cmbvideoDevice;
private System.Windows.Forms.ComboBox cmbintput;
private System.Windows.Forms.ComboBox cmboutput;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TrackBar trackBarInVolume;
private System.Windows.Forms.TrackBar trackBarOutVolume;
public FormAVWizard()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
VideoCapturer.VideoCaptureDeviceCollection vcs=VideoCapturer.GetDevices();
foreach(VideoCaptureDevice vd in vcs)
{
this.cmbvideoDevice.Items.Add( vd.Name );
}
if(vcs.Count>0)
this.cmbvideoDevice.SelectedIndex=0;
else
this.cmbvideoDevice.Text="没有找到视频输入设备";
AudioDevice.AudioDeviceCollection ads=AudioDevice.InputDevices();
foreach(AudioDevice ad in ads)
{
this.cmbintput.Items.Add((ad.Name));
this.cmboutput.Items.Add((ad.Name));
}
if(ads.Count>0)
{
this.cmbintput.SelectedIndex=0;
this.cmboutput.SelectedIndex=0;
}
else
{
this.cmbintput.Items.Add(("找不到音频输入设备"));
this.cmboutput.Items.Add(("找不到音频输出设备"));
}
mixer=new Mixer(this);
mixer.MixerControlChange+=new EventHandler(mixer_MixerControlChange);
this.outdtl=new LanMsg.AV.Mixer.MixerControlDetail(mixer,LanMsg.AV.Mixer.MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
this.trackBarOutVolume.Maximum=this.outdtl.Max;
this.trackBarOutVolume.Minimum=this.outdtl.Min;
this.trackBarOutVolume.Value=this.outdtl.Volume;
this.indtl=new LanMsg.AV.Mixer.MixerControlDetail(mixer,LanMsg.AV.Mixer.MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE);
this.trackBarInVolume.Maximum=this.indtl.Max;
this.trackBarInVolume.Minimum=this.indtl.Min;
this.trackBarInVolume.Value=this.indtl.Volume;
this.vc=new VideoCapturer(this.pnlpreview,this.cmbvideoDevice.SelectedIndex);
this.vc.ConnectDevice();
this.vc.SetPreviewRate(66);
LanMsg.AV.BITMAPINFO h=this.vc.BITMAPINFO;
h.bmiHeader.biBitCount=24;
h.bmiHeader.biWidth=160;
h.bmiHeader.biHeight=120;
this.vc.BITMAPINFO=h;
this.vc.Preview=true;
wf=new WAVEFORMATEX();
wf.cbSize=0;
wf.nChannels=1;
wf.nSamplesPerSec=8000;
wf.wBitsPerSample=16;
wf.nBlockAlign=2;
wf.nAvgBytesPerSec=16000;
wf.wFormatTag=1;//pcm
wo=new WaveOut(this.cmboutput.SelectedIndex,wf,1600,20);
wo.WaveOutError+=new WaveErrorEventHandler(wo_WaveInError);
this.wo.Start();
wi=new WaveIn(this.cmbintput.SelectedIndex,wf,1600,20);
wi.WaveInError+=new WaveErrorEventHandler(wo_WaveInError);
wi.WaveCaptured+=new WaveBufferEventHandler(wi_WaveCaptured);
this.wi.Start();
this.Activate();
}
private void InitialAll(object o)
{
}
private void wo_WaveInError(object sender, AVException e)
{
System.Diagnostics.Trace.WriteLine(e.Message);
}
private void wi_WaveCaptured(object sender, WAVEHDR hdr)
{
if(this.ts.SelectedTab==this.paudio)
{
byte[] data=new byte[hdr.dwBytesRecorded];
System.Runtime.InteropServices.Marshal.Copy(hdr.lpData,data,0,data.Length);
LanMsg.AV.UT.LowPassWave(this.wf,data,0,5000);
this.wo.Write(data);
Bitmap bm=new Bitmap(this.pictureBox1.Width,this.pictureBox1.Height);
Graphics g=Graphics.FromImage(bm);
Pen pen=new Pen(this.ForeColor);
int xi=(int)(this.pictureBox1.Width*16/data.Length),ys=(int)(this.pictureBox1.Height/2);
int h=this.pictureBox1.Height;
int x=-xi,y=ys,x2,y2;
if(xi<1)xi=1;
for(int i=0;i<data.Length;i+=16)
{
x2=x+xi;
y2=ys+(int)(System.BitConverter.ToInt16(data,i)/h);
g.DrawLine(pen,x,y,x2,y2);
x=x2;
y=y2;
}
g.Dispose();
this.pictureBox1.Image=bm;
}
}
private void SyncVolumn()
{
this.trackBarInVolume.Value=this.indtl.Volume;
this.trackBarOutVolume.Value=this.outdtl.Volume;
}
private void mixer_MixerControlChange(object sender, EventArgs e)
{
this.SyncVolumn();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
wi.Stop();
wo.Stop();
mixer.Close();
if(vc.Connected){vc.Close(); vc.Disconnect();}
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ts = new System.Windows.Forms.TabControl();
this.pvideo = new System.Windows.Forms.TabPage();
this.cmbvideoDevice = new System.Windows.Forms.ComboBox();
this.btnadvance = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.pnlpreview = new System.Windows.Forms.Panel();
this.paudio = new System.Windows.Forms.TabPage();
this.cmboutput = new System.Windows.Forms.ComboBox();
this.cmbintput = new System.Windows.Forms.ComboBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label4 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.trackBarInVolume = new System.Windows.Forms.TrackBar();
this.trackBarOutVolume = new System.Windows.Forms.TrackBar();
this.label5 = new System.Windows.Forms.Label();
this.btnsave = new System.Windows.Forms.Button();
this.btncancel = new System.Windows.Forms.Button();
this.ts.SuspendLayout();
this.pvideo.SuspendLayout();
this.paudio.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBarInVolume)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.trackBarOutVolume)).BeginInit();
this.SuspendLayout();
//
// ts
//
this.ts.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ts.Controls.Add(this.pvideo);
this.ts.Controls.Add(this.paudio);
this.ts.Location = new System.Drawing.Point(0, 0);
this.ts.Name = "ts";
this.ts.SelectedIndex = 0;
this.ts.Size = new System.Drawing.Size(360, 221);
this.ts.TabIndex = 0;
//
// pvideo
//
this.pvideo.Controls.Add(this.cmbvideoDevice);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -