问题描述
大家好,最近一直在做一个网络视频的项目,所以找了Gowk的代码经过分析和试验,Gowk网络语音视频代码可以实现,但是总觉得有点不太稳定现在遇到一个问题,困扰了我很久,希望各位能够帮助解决,我把最后的一百分贡献出来了就是当我拥有1个以上的视频设备的时候,假设一个设备为A,另外一个为B但程序枚举设备时,只显示MicrosoftWDMImageCapture(Win32),点击“属性”按钮的时候,也就是执行publicintShowVideoSource(){returnSendMessageClass.SendMessage(m_hwnd,WM_CAP_DLG_VIDEOSOURCE,0,0);}这个方法的时候,弹出一个属性框在里面可以看到A,B的名称,并可以进行选择因为默认是先显示A设备,如果我想用B设备,还必须弹出属性窗口后,选择B设备后才可以,很麻烦我想做的就是,我不想弹出属性框进行AB设备的选择,因为属性框是系统弹出的,我不能控制怎么样才能在代码里实现,我想选那个设备,就选那个设备呢,谢谢大家了代码太长贴出主要部分publicdelegatevoidVideoCaptureEventHandler(objectsender,VIDEOHDRhdr);publicdelegatevoidVideoErrorEventHandler(objectsender,stringdesc);publicclassVideoCapturer{capVideoStreamCallbackm_streamCallBack;capErrorCallbackm_errorCallBack;CaptureParmsm_parms;BITMAPINFOm_BITMAPINFO;IntPtrm_hwnd;boolm_IsCapturing;boolm_HasPreview;boolm_Connected;privateintindex;publiceventVideoCaptureEventHandlerVideoCaptured;publiceventVideoErrorEventHandlerVideoError;//intm_NumberFramesPerSecond=66;publicVideoCapturer(Controlcontrol,intindex){this.index=index;m_hwnd=capCreateCaptureWindow("",WS_VISIBLE|WS_CHILD,0,0,160,120,control.Handle,0);if(m_hwnd==IntPtr.Zero)thrownewMultimediaException();m_parms=newCaptureParms();m_streamCallBack=newcapVideoStreamCallback(this.streamCallBack);m_errorCallBack=newcapErrorCallback(this.capErrorCallback);SendMessage(m_hwnd,WM_CAP_SET_CALLBACK_ERRORA,0,m_errorCallBack);SendMessage(m_hwnd,WM_CAP_SET_CALLBACK_VIDEOSTREAM,0,m_streamCallBack);}publicintShowVideoDisplay(){returnSendMessageClass.SendMessage(m_hwnd,WM_CAP_DLG_VIDEODISPLAY,0,0);}publicintShowVideoCompression(){returnSendMessageClass.SendMessage(m_hwnd,WM_CAP_DLG_VIDEOCOMPRESSION,0,0);}publicintShowVideoFormat(){returnSendMessageClass.SendMessage(m_hwnd,WM_CAP_DLG_VIDEOFORMAT,0,0);}publicintShowVideoSource(){returnSendMessageClass.SendMessage(m_hwnd,WM_CAP_DLG_VIDEOSOURCE,0,0);}publicintConnectDevice(){returnSendMessageClass.SendMessage(m_hwnd,WM_CAP_DRIVER_CONNECT,this.index,0);}publicintSetPreviewRate(intrate){returnSendMessageClass.SendMessage(m_hwnd,WM_CAP_SET_PREVIEWRATE,rate,0);}publicboolPreview{get{returnthis.m_HasPreview;}set{intret=SendMessageClass.SendMessage(m_hwnd,WM_CAP_SET_PREVIEW,value,0);if(ret==1)this.m_HasPreview=value;}}publicintCaptureWithOutFile(){//Debug.Assert(this.Connected);intret=SendMessageClass.SendMessage(m_hwnd,WM_CAP_SEQUENCE_NOFILE,0,0);returnret;}publicvoidDisconnect(){SendMessageClass.SendMessage(m_hwnd,WM_CAP_DRIVER_DISCONNECT,0,0);}publicvoidClose(){SendMessageClass.SendMessage(m_hwnd,0x10,0,0);}publicintStop(){intret=SendMessageClass.SendMessage(m_hwnd,WM_CAP_STOP,0,0);returnret;}publicintAbort(){intret=SendMessageClass.SendMessage(m_hwnd,WM_CAP_ABORT,0,0);returnret;}publicintSavePicture(stringfile){returnSendMessage(m_hwnd,WM_CAP_FILE_SAVEDIBW,0,file);}publicCaptureParmsCaptureParms{get{SendMessage(m_hwnd,WM_CAP_GET_SEQUENCE_SETUP,Marshal.SizeOf(m_parms),refm_parms);returnthis.m_parms;}set{m_parms=value;SendMessage(m_hwnd,WM_CAP_SET_SEQUENCE_SETUP,Marshal.SizeOf(m_parms),refm_parms);}}publicBITMAPINFOBITMAPINFO{get{SendMessage(m_hwnd,WM_CAP_GET_VIDEOFORMAT,Marshal.SizeOf(m_BITMAPINFO),refm_BITMAPINFO);returnthis.m_BITMAPINFO;}set{this.m_BITMAPINFO=value;SendMessage(m_hwnd,WM_CAP_SET_VIDEOFORMAT,Marshal.SizeOf(m_BITMAPINFO),refm_BITMAPINFO);}}publicintSetScale(boolvalue){returnSendMessageClass.SendMessage(m_hwnd,WM_CAP_SET_SCALE,value,0);}publicCAPSTATUSCAPSTATUS{get{CAPSTATUSstatus=newCAPSTATUS();SendMessage(m_hwnd,WM_CAP_GET_STATUS,Marshal.SizeOf(CAPSTATUS),refstatus);returnstatus;}}publicboolConnected{get{returnthis.m_Connected;}}publicIntPtrHandler{get{returnthis.Handler;}}publicboolIsCapturing{get{returnthis.m_IsCapturing;}}/*publicintNumberFramesPerSecond{get{returnthis.m_NumberFramesPerSecond;}set{Debug.Assert(value>0&&value<10000);}}*/privateintstreamCallBack(IntPtrhWnd,refVIDEOHDRlpVHdr){if(this.VideoCaptured!=null)this.VideoCaptured(this,lpVHdr);return0;}privateintcapErrorCallback(IntPtrhWnd,intnID,stringlpsz){this.m_IsCapturing=false;this.m_HasPreview=false;if(this.m_Connected){this.Disconnect();this.m_Connected=false;}if(this.VideoError!=null)this.VideoError(this,lpsz);return0;}publicclassVideoCaptureDeviceCollection:System.Collections.ArrayList{}publicstaticVideoCaptureDeviceCollectionGetDevices(){VideoCaptureDeviceCollectionc=newVideoCaptureDeviceCollection();for(inti=0;i<10;i++){StringBuildername,version;name=newStringBuilder(128);version=newStringBuilder(128);if(capGetDriverDescription(i,name,128,version,128)){c.Add(newVideoCaptureDevice(i,name.ToString(),version.ToString()));}}returnc;}
解决方案
解决方案二:
用C#麻烦,用C++吧
解决方案三:
唉,用了C#2年多,总感觉C#弱弱的,疯掉了,我也想用C++,可我现在就会C#希望有高人指点一下这个问题啊
解决方案四:
:)-
解决方案五:
jf,
解决方案六:
我没分了,最后一百分了,拜托大家了,没人知道么?在线等
解决方案七:
好像不好搞,至少没搞过这方面的东东!不好意思了,帮你顶西呕!
解决方案八:
这个问题是不是不好弄啊,大家不要详细的告诉我,只需要告诉我应该改那个参数就可以了比如我试过,publicintConnectDevice(){returnSendMessageClass.SendMessage(m_hwnd,WM_CAP_DRIVER_CONNECT,this.index,0);}把这方法的最后一个参数改为1publicintConnectDevice(){returnSendMessageClass.SendMessage(m_hwnd,WM_CAP_DRIVER_CONNECT,this.index,1);}也没用,估计还是没有改对地方希望高手指点,不需要详细过程,就需要告诉我应该改什么地方就好了
解决方案九:
虽然不知道怎么样,但还是帮你顶一下,呵呵...
解决方案十:
楼主代码很强,那么长,愣是没有一个注释
解决方案十一:
没摄相头了,没试过。帮顶。
解决方案十二:
呵呵,没有人知道么?伤心了
解决方案十三:
顶!!支持楼主!!共同学习,共同进步!
解决方案十四:
引用9楼wisdomqq的回复:
楼主代码很强,那么长,愣是没有一个注释
帮顶
解决方案十五:
<C#开发经验技巧宝曲>VFW开发里有介绍,去看一下这本书
解决方案:
该回复于2008-05-05 16:53:22被版主删除
解决方案:
晕,解释一下,呵呵,这不是我的代码哦,是Gowk的,我写的程序基本是一句代码,一句注释,良好的编成习惯,对开发也有很大的帮助,没有注释,是因为我还没有完全理解Gowk的代码,所以没加呵呵,唉,这个那么难么?都没人会,看来得另想办法了