Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
AnswerRe: How do i load a XML data to a Combobox? Pin
Wayne Gaylard20-Feb-14 22:37
professionalWayne Gaylard20-Feb-14 22:37 
QuestionThreading and system.diagnostics Pin
Syed Ata-Ur-Rehman20-Feb-14 9:56
Syed Ata-Ur-Rehman20-Feb-14 9:56 
AnswerRe: Threading and system.diagnostics Pin
Dave Kreskowiak20-Feb-14 13:15
mveDave Kreskowiak20-Feb-14 13:15 
AnswerRe: Threading and system.diagnostics Pin
Bernhard Hiller20-Feb-14 22:12
Bernhard Hiller20-Feb-14 22:12 
QuestionDll libraries Pin
Blubbo20-Feb-14 3:37
Blubbo20-Feb-14 3:37 
AnswerRe: Dll libraries Pin
Alan N20-Feb-14 6:53
Alan N20-Feb-14 6:53 
AnswerRe: Dll libraries Pin
Richard MacCutchan20-Feb-14 6:55
mveRichard MacCutchan20-Feb-14 6:55 
QuestionDShow.Net Problem With Opening Camera Pin
BBatts20-Feb-14 2:59
BBatts20-Feb-14 2:59 
Hello. I'm streaming a webcam using DirectShow. I can open the camera fine on a windows form once. But, If I close the camera and then try to reopen it my code fails on the RenderStream line. Once I restart my application everything is fine again. I'm quite certain I'm freeing everything up, but i'm stumped. Any help would be GREATLY appreciated.

C#
Guid cat = PinCategory.Capture;
       Guid med = MediaType.Video;

       private IBaseFilter sourceBase;
       private IGraphBuilder graph;
       private ICaptureGraphBuilder2 capGraph;
       private ISampleGrabber sg;
       private IMediaControl mc;
       private IBaseFilter grabberBase;
       private VideoInfoHeader videoInfoHeader;

       private const int WM_GRAPHNOTIFY = 0x00008001;
       private const int WS_CHILD = 0x40000000;
       private const int WS_CLIPCHILDREN = 0x02000000;
       private const int WS_CLIPSIBLINGS = 0x04000000;

       private int frameWidth = 320;
       private int frameHeight = 240;

   public bool Start(string SystemID)
       {
           using (DsDevice camDevice = GetDeviceFromMon(SystemID))
           {
               if (camDevice != null)
               {
                   object comObj = null;
                   Guid gbf = typeof(IBaseFilter).GUID;
                   Guid clsid = Clsid.CaptureGraphBuilder2;
                   Guid riid = typeof(ICaptureGraphBuilder2).GUID;

                   AMMediaType media = new AMMediaType();
                   media.majorType = MediaType.Video;
                   media.subType = MediaSubType.RGB24;
                   media.formatType = FormatType.VideoInfo;

                   //Create Source
                   camDevice.Mon.BindToObject(null, null, ref gbf, out comObj);
                   sourceBase = (IBaseFilter)comObj; comObj = null;

                   //Create Graph
                   comObj = Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.FilterGraph));
                   graph = (IGraphBuilder)comObj; comObj = null;

                   //Create Capture Graph
                   comObj = DsBugWO.CreateDsInstance(ref clsid, ref riid);
                   capGraph = (ICaptureGraphBuilder2)comObj; comObj = null;

                   //Create Grabber
                   comObj = Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.SampleGrabber));
                   sg = (ISampleGrabber)comObj; comObj = null;

                   mc = (IMediaControl)graph;
                   grabberBase = (IBaseFilter)sg;

                   //Set Graphs/Filters
                   capGraph.SetFiltergraph(graph);
                   graph.AddFilter(sourceBase, "Ds.NET Video Capture Device");
                   sg.SetMediaType(media);
                   graph.AddFilter(grabberBase, "Ds.NET Grabber");

                   //Renter My Stream
                   if (capGraph.RenderStream(ref cat, ref med, sourceBase, null, grabberBase) >= 0)
                   {
                       media = new AMMediaType();
                       if (sg.GetConnectedMediaType(media) >= 0)
                       {
                           if ((media.formatType == FormatType.VideoInfo) && (media.formatPtr != IntPtr.Zero))
                           {
                               videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader));
                               frameWidth = videoInfoHeader.BmiHeader.Width;
                               frameHeight = videoInfoHeader.BmiHeader.Height;

                               Marshal.FreeCoTaskMem(media.formatPtr); media.formatPtr = IntPtr.Zero;

                               sg.SetBufferSamples(false);
                               sg.SetOneShot(false);
                               sg.SetCallback(this, 1);

                               mc.Run();
                           }
                       }
                   }
               }
           }

           return false;
       }

       public void Stop()
       {
           if (mc != null)
           {
               mc.StopWhenReady();
               mc = null;
           }

           if (sg != null)
           {
               sg.SetCallback(null, 0);
               Marshal.ReleaseComObject(sg); sg = null;
           }

           if (grabberBase != null)
               Marshal.ReleaseComObject(grabberBase); grabberBase = null;

           if (capGraph != null)
               Marshal.ReleaseComObject(capGraph); capGraph = null;

           if (graph != null)
               Marshal.ReleaseComObject(graph); graph = null;

           if (sourceBase != null)
               Marshal.ReleaseComObject(sourceBase); sourceBase = null;

           videoInfoHeader = null;
       }

AnswerRe: DShow.Net Problem With Opening Camera Pin
Simon_Whale20-Feb-14 3:30
Simon_Whale20-Feb-14 3:30 
GeneralRe: DShow.Net Problem With Opening Camera Pin
BBatts20-Feb-14 3:56
BBatts20-Feb-14 3:56 
GeneralRe: DShow.Net Problem With Opening Camera Pin
Simon_Whale20-Feb-14 4:06
Simon_Whale20-Feb-14 4:06 
GeneralRe: DShow.Net Problem With Opening Camera Pin
BBatts20-Feb-14 4:25
BBatts20-Feb-14 4:25 
AnswerRe: DShow.Net Problem With Opening Camera Pin
Eddy Vluggen20-Feb-14 8:06
professionalEddy Vluggen20-Feb-14 8:06 
GeneralRe: DShow.Net Problem With Opening Camera Pin
BBatts20-Feb-14 8:08
BBatts20-Feb-14 8:08 
QuestionJoystick Driver Project Pin
uddajay20-Feb-14 2:51
uddajay20-Feb-14 2:51 
AnswerRe: Joystick Driver Project Pin
Richard MacCutchan20-Feb-14 2:55
mveRichard MacCutchan20-Feb-14 2:55 
AnswerRe: Joystick Driver Project Pin
Dave Kreskowiak20-Feb-14 3:32
mveDave Kreskowiak20-Feb-14 3:32 
QuestionHow to read view permission groups from DFS link objects? Pin
RolandZ19-Feb-14 23:15
RolandZ19-Feb-14 23:15 
Questionpublished c# application cannot start Pin
emma.sun.sts19-Feb-14 20:04
emma.sun.sts19-Feb-14 20:04 
AnswerRe: published c# application cannot start Pin
OriginalGriff19-Feb-14 21:06
mveOriginalGriff19-Feb-14 21:06 
GeneralRe: published c# application cannot start Pin
emma.sun.sts23-Feb-14 13:58
emma.sun.sts23-Feb-14 13:58 
AnswerRe: published c# application cannot start Pin
Richard Deeming20-Feb-14 1:53
mveRichard Deeming20-Feb-14 1:53 
GeneralRe: published c# application cannot start Pin
emma.sun.sts23-Feb-14 14:00
emma.sun.sts23-Feb-14 14:00 
QuestionHow to make POS payments to bank? Pin
Member 1059798819-Feb-14 15:13
Member 1059798819-Feb-14 15:13 
AnswerRe: How to make POS payments to bank? Pin
Dave Kreskowiak19-Feb-14 16:40
mveDave Kreskowiak19-Feb-14 16:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.