📄 av.cs
字号:
private void vc_VideoCaptured(object sender, VIDEOHDR hdr)
{
if(this.chanel==null || !this.chanel.Connected)return;
try
{
byte[] data=new byte[hdr.dwBytesUsed];
Marshal.Copy(hdr.lpData, data, 0, hdr.dwBytesUsed);
if (RemotePreView)
{
ICDecompressor dpp;
ICCompressor cpp;
//byte[] bs=this.icm.Process(data);
//ide.Process(bs);
dpp = new ICDecompressor(pp, bi2, FOURCC.IntelIYUV);
dpp.Open();
cpp = new ICCompressor(pp, bi, FOURCC.IntelIYUV);
cpp.Open();
byte[] compresseddata = cpp.Process(data);
byte[] decompressdata = null;
if (compresseddata != null)
{
if (compresseddata.Length > 1000)
decompressdata = dpp.Process(compresseddata);
}
if (decompressdata != null)
{
this.dd.Draw(decompressdata);
}
//this.dd.Draw(data);
//Application.DoEvents();
if (!cpp.HASIntelCodec)
{
noencode = true;
}
else
{
noencode = false;
}
if (!dpp.HASIntelCodec)
{
nodecode = true;
}
else
{
nodecode = false;
}
cpp.Close();
dpp.Close();
//GC.Collect();
Application.DoEvents();
Debug.Print("previewing..............................");
}
if (!RemotePreView)
{
if (this.chanel != null && this.chanel.Connected)
{
this.chanel.SendVideo(data);
Debug.Print("this is not preview now!!!!!!!!!");
}
}
}
catch(System.Exception ex)
{
// MessageBox.Show(ex.Message);
// throw;
gowk.utility.Diagnostics.Debug.Write(ex);
System.Diagnostics.Trace.WriteLine(ex.Message+":"+ex.StackTrace);
}
}
private void wi_WaveCaptured(object sender, WAVEHDR hdr)
{
/* byte[] dd=new byte[hdr.dwBytesRecorded];
System.Runtime.InteropServices.Marshal.Copy(hdr.lpData,dd,0,dd.Length);
UT.HighPassWave(this.wi.WAVEFORMATEX,dd,dd.Length,200000);
UT.LowPassWave(this.wi.WAVEFORMATEX,dd,dd.Length,3000);
this.wo.Write(dd);*/
// byte[] dd=new byte[hdr.dwBytesRecorded];
// System.Runtime.InteropServices.Marshal.Copy(hdr.lpData,dd,0,dd.Length);
// this.wo.Write(dd);
/* if(this.PlayBackVolumeControl!=null)
{
byte[] ddd=new byte[hdr.dwBytesRecorded];
System.Runtime.InteropServices.Marshal.Copy(hdr.lpData,ddd,0,ddd.Length);
for(int i=0;i<hdr.dwBytesRecorded;i+=160)
{
byte[] b=new byte[]{ddd[i+1],ddd[i]};
int v=System.BitConverter.ToInt16(b,0)+32768;
this.PlayBackVolumeControl.Value=v;
System.Diagnostics.Trace.WriteLine(v.ToString());
}
}*/
if (!RemotePreView)
{
if (this.chanel == null || !this.chanel.Connected) return;
byte[] data = new byte[hdr.dwBytesRecorded];
System.Runtime.InteropServices.Marshal.Copy(hdr.lpData, data, 0, data.Length);
// UT.HighPassWave(this.wi.WAVEFORMATEX,data,data.Length,200000);
UT.LowPassWave(this.wi.WAVEFORMATEX, data, data.Length, 2500);
this.chanel.SendAudio(data);
}
// this.chanel.Test(data);
// for(int i=0;i<data.Length;i+=300)
// {
// this.progressBar1.Value=System.BitConverter.ToUInt16(data,i);
// }
// this.wo.Write(data);
// this.wo.Write(data);
// if(this.PlayBackVolumeControl==null)return;
/* lock(this.PlayBackVolumeControl)
{
for(int i=0;i<data.Length;i+=160)
{
int v=System.BitConverter.ToUInt16(data,i);
v=v-32768;
this.PlayBackVolumeControl.Value=32767-(int)System.Math.Abs(v);
}
}*/
/* if(this.cansent)
{
byte[] dst=new byte[(int)(data.Length/16)];
System.Diagnostics.Trace.WriteLine(dst.Length);
// this.g729.Encode(data,dst);
this.sock.Send(dst);
System.Diagnostics.Trace.WriteLine("sent a audio packet");
}*/
// this.wo.Write(this.chanel.de(this.chanel.en(data)));
}
private void wo_WaveInError(object sender, MultimediaException e)
{
System.Diagnostics.Trace.WriteLine(e.Message);
}
public int LocalPort
{
get{return this.chanel.LocalPort;}
}
public AVChanel AVChanel
{
get{return this.chanel;}
}
public void ShowSource()
{
if (vc.CAPDRIVERCAPS.fHasDlgVideoSource != 0)
{
vc.ShowVideoSource();
}
else
{
MessageBox.Show("设备不支持该设置!", mb_title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
public void ShowFormat()
{
if (vc.CAPDRIVERCAPS.fHasDlgVideoFormat != 0)
{
vc.ShowVideoFormat();
}
else
{
MessageBox.Show("设备不支持该设置!", mb_title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
public bool SaveToPicture(string Path)
{
if (this.vc.SavePicture(Path) != 0)
{
return true;
}
else
{
return false;
}
}
public bool SaveRemoteToPicture(string Path)
{
//晕!微软居然开这种玩笑....
IntPtr hdc = GetDC(remote.Handle);
IntPtr hdcsrc = CreateCompatibleDC(hdc);
IntPtr objptr;
try
{
if (hdcsrc != IntPtr.Zero)
{
IntPtr hbitmap = CreateCompatibleBitmap(hdc, remote.Size.Width, remote.Size.Height);
if (hbitmap != IntPtr.Zero)
{
objptr = SelectObject(hdcsrc, hbitmap);
int blt=BitBlt(hdcsrc, 0, 0, 176, 144, hdc, 0, 0, SRCCOPY);
if (blt != 0)
{
Bitmap bmsave = Bitmap.FromHbitmap(hbitmap);
bmsave.Save(Path, System.Drawing.Imaging.ImageFormat.Bmp);
DeleteObject(objptr);
DeleteDC(hdcsrc);
Application.DoEvents();
bmsave.Dispose();
return true;
}
DeleteObject(objptr);
DeleteDC(hdcsrc);
return false;
}
}
}
catch (Exception ex)
{
Debug.Print("\r\n" + ex.Message);
return false ;
}
DeleteDC(hdcsrc);
Debug.Print("API 错误!!!!!");
return false;
}
#endregion
#region 属性
public BITMAPINFO vc_BITMAPINFO
{
get
{
return vc.BITMAPINFO;
}
set
{
vc.BITMAPINFO = value;
}
}
public bool HasDecoder
{
get
{
return nodecode;
}
}
public bool HasEncoder
{
get
{
return noencode;
}
}
public bool HasCam
{
get
{
return vc.HasCam;
}
}
#endregion
#region API声明
private static readonly int SRCCOPY = 13369376;
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern int DeleteDC(
IntPtr hdc // handle to DC
);
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
private static extern IntPtr GetDC(
IntPtr hWnd // handle to window
);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern IntPtr SelectObject(
IntPtr hdc, // handle to DC
IntPtr hgdiobj // handle to object
);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern int DeleteObject(
IntPtr hObject // handle to graphic object
);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern IntPtr CreateCompatibleDC(
IntPtr hdc // handle to DC
);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern IntPtr CreateCompatibleBitmap(
IntPtr hdc, // handle to DC
int nWidth, // width of bitmap, in pixels
int nHeight // height of bitmap, in pixels
);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern int BitBlt(
IntPtr hdcDest, // 目标设备的句柄
int nXDest, // 目标对象的左上角的X坐标
int nYDest, // 目标对象的左上角的X坐标
int nWidth, // 目标对象的矩形的宽度
int nHeight, // 目标对象的矩形的长度
IntPtr hdcSrc, // 源设备的句柄
int nXSrc, // 源对象的左上角的X坐标
int nYSrc, // 源对象的左上角的X坐标
System.Int32 dwRop // 光栅的操作值
);
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -