📄 av.cs
字号:
using System;
using System.Drawing;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using gowk.multimedia;
using System.Runtime.InteropServices;
using System.Net.Sockets;
using System.Net;
namespace gowk.multimedia
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class AV:System.IDisposable
{
#region 成员
Mixer mixer;
Mixer.MixerControlDetail dt, dt2;
DrawDib dd;
AVChanel chanel;
VideoCapturer vc;
//int v_Width; int v_Height;
WaveIn wi;
WaveOut wo; WAVEFORMATEX wf;
PictureBox local, remote;
String mb_title;
bool noencode;
bool nodecode;
public bool RemotePreView;
//*
COMPVARS pp;
COMPVARS p2;
BITMAPINFOHEADER bmi;
BITMAPINFO bi;
BITMAPINFOHEADER bmi2;
BITMAPINFO bi2;
//*/
public ProgressBar PlayBackVolumeControl;
#endregion
#region 构造函数
public AV(PictureBox local,PictureBox remote)
{
this.local=local;
this.remote=remote;
RemotePreView = false;
noencode = false;
nodecode = false;
/*
if (width <= 0 || height <= 0)
{
this.v_Width = 176;
this.v_Height = 144;
}
else
{
this.v_Width = width;
this.v_Height = height;
}
* */
mb_title = "ZX Messenger AVPhone";
}
#endregion
#region IDisposable 成员
public void Dispose()
{
Debug.Print("AV Disposing.......................................");
if(this.vc!=null)
{
//dpp.Close();
//cpp.Close();
this.vc.Preview=false;
this.vc.Stop();
this.vc.Disconnect();
this.vc.Close();
}
if(this.wi!=null)
{
//this.wi.Reset();
this.wi.Stop();
}
if(this.dd!=null)
{
this.dd.Close();
}
if(this.wo!=null)
{
//this.wo.Reset();
this.wo.Stop();
//this.wo.Dispose();
}
if(this.mixer!=null)
{
this.mixer.Close();
}
if (this.chanel != null)
{
try
{
//this.chanel.Disconnect();
this.chanel.Close();
}
catch (System.Exception ex)
{
//MessageBox.Show(ex.Message);
Debug.Print("Dispose Error: " + ex.Message);
}
}
}
#endregion
#region initial
/* public void InitializeAV()
{
this.IniAudio();
this.IniVideo();
}*/
public void Initial()
{
this.IniChanel();
this.IniAudio();
this.IniVideo();
}
#region audio
public void IniAudio()
{
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(0,wf,4000,20);
wo.WaveOutError+=new WaveErrorEventHandler(wo_WaveInError);
wi=new WaveIn(0,wf,4000,20);
wi.WaveInError+=new WaveErrorEventHandler(wo_WaveInError);
wi.WaveCaptured+=new WaveBufferEventHandler(wi_WaveCaptured);
this.wo.Start();
this.wi.Start();
this.mixer=new Mixer(this.local);
dt=new Mixer.MixerControlDetail(this.mixer,Mixer.MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
dt2=new Mixer.MixerControlDetail(this.mixer,0x00001000+3);
}
#endregion
#region video
public void IniVideoCapture()
{
//*
pp = new COMPVARS();
pp.cbSize = Marshal.SizeOf(pp);
pp.dwFlags = 1;
pp.fccHandler = FOURCC.IntelIYUV ;
pp.fccType = FOURCC.ICTYPE_VIDEO; //这个是固定的
pp.lDataRate = 120; //数据率30k/s
pp.lKey = 15;
pp.lQ = 1000;
//pp.lQ = 0;
p2 = pp;
bmi = new BITMAPINFOHEADER();
bmi.biCompression = (int)BI.BI_RGB;
bmi.biWidth = 176;
bmi.biHeight = 144;
bmi.biPlanes = 1;
bmi.biBitCount = 24;
bmi.biXPelsPerMeter = 0;
bmi.biYPelsPerMeter = 0;
bmi.biClrUsed = 0;
bmi.biClrImportant = 0;
bmi.biSizeImage = 57600;
bmi.biSize = Marshal.SizeOf(bmi);
bi = new BITMAPINFO();
bi.bmiHeader = bmi;
bmi2 = new BITMAPINFOHEADER();
bmi2.biCompression = FOURCC.IntelIYUV;
bmi2.biWidth = 176;
bmi2.biHeight = 144;
bmi2.biPlanes = 1;
bmi2.biBitCount = 24;
bmi2.biXPelsPerMeter = 0;
bmi2.biYPelsPerMeter = 0;
bmi2.biClrUsed = 0;
bmi2.biClrImportant = 0;
bmi2.biSize = 40;
bmi2.biSizeImage = 76032;
bi2 = new BITMAPINFO();
bi2.bmiHeader = bmi2;
//*/
this.vc=new VideoCapturer(this.local,0);
this.vc.ConnectDevice();
this.vc.SetPreviewRate(66);
this.vc.Preview=true;
gowk.multimedia.CaptureParms cp=this.vc.CaptureParms;
cp.fAbortLeftMouse=cp.fAbortRightMouse=false;
cp.fYield=true ;
this.vc.CaptureParms=cp;
gowk.multimedia.BITMAPINFO h=this.vc.BITMAPINFO;
h.bmiHeader.biBitCount=24;
h.bmiHeader.biWidth=176 ;
h.bmiHeader.biHeight=144;
h.bmiHeader.biSizeImage = 76032;
this.vc.BITMAPINFO=h;
this.vc.VideoCaptured+=new VideoCaptureEventHandler(vc_VideoCaptured);
//this.vc.CaptureWithOutFile();
}
public void IniVideoRender()
{
BITMAPINFOHEADER bmi=new BITMAPINFOHEADER();
bmi.biCompression =(int) BI.BI_RGB;
bmi.biWidth = 176;
bmi.biHeight = 144 ;
bmi.biPlanes = 1;
bmi.biBitCount = 24;
bmi.biXPelsPerMeter = 0;
bmi.biYPelsPerMeter = 0;
bmi.biClrUsed = 0;
bmi.biClrImportant = 0;
bmi.biSizeImage=76032;
bmi.biSize=Marshal.SizeOf(bmi);
dd = new DrawDib(176, 144);//(this.v_Width ,this.v_Height );
dd.Control=this.remote;
dd.BITMAPINFOHEADER=bmi;
dd.Open();
}
public int GetVideoWidth()
{
if (this.vc != null)
{
return vc.BITMAPINFO.bmiHeader.biWidth;
}
else
{
return 0;
}
}
public int GetVideoHeight()
{
if (this.vc != null)
{
return vc.BITMAPINFO.bmiHeader.biHeight ;
}
else
{
return 0;
}
}
public void IniVideo()
{
// this.IniVideoCompress();
this.IniVideoRender();
this.IniVideoCapture();
}
#endregion
#region
public void IniChanel()
{
chanel=new AVChanel();
this.chanel.AudioData+=new AVChanel.AVChanelEventHandler(chanel_AudioData);
this.chanel.VideoData+=new AVChanel.AVChanelEventHandler(chanel_VideoData);
this.chanel.Open();
}
#endregion
#endregion
#region 实现函数和过程
public void Start(string ip,int p)
{
//if (!RemotePreView)
//{
this.chanel.Connect(ip, p);
//}
}
public AVChanel Chanel
{
get{return this.chanel;}
}
//SetWindowPos(hCapWnd, 0, 25, 25, bmi.bmiHeader.biWidth,bmi.bmiHeader.biHeight,0);
private void chanel_AudioData(object sender, AVChanel.AVChanelEventArgs e)
{
if(this.wo!=null)this.wo.Write(e.Data);
}
private void chanel_VideoData(object sender, AVChanel.AVChanelEventArgs e)
{
// byte[] decompressdata=this.dp.Process(e.Data);
if (this.dd != null)
{
this.dd.Draw(e.Data);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -