Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DShow.Net Problem With Opening Camera

DShow.Net Problem With Opening Camera

Scheduled Pinned Locked Moved C#
helpcsharpdata-structures
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BBatts
    wrote on last edited by
    #1

    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.

    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;
    
    S L 2 Replies Last reply
    0
    • B BBatts

      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.

      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;
      
      S Offline
      S Offline
      Simon_Whale
      wrote on last edited by
      #2

      What is the exception that it throws?

      Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

      B 1 Reply Last reply
      0
      • S Simon_Whale

        What is the exception that it throws?

        Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

        B Offline
        B Offline
        BBatts
        wrote on last edited by
        #3

        Thanks for replying. capGraph.RenderStreamdoesn't throw an exception, but it returns -2147024809

        S 1 Reply Last reply
        0
        • B BBatts

          Thanks for replying. capGraph.RenderStreamdoesn't throw an exception, but it returns -2147024809

          S Offline
          S Offline
          Simon_Whale
          wrote on last edited by
          #4

          http://stackoverflow.com/questions/13100698/unknown-error-on-renderstream[^] Can I suggest that you have a read of this

          Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

          B 1 Reply Last reply
          0
          • S Simon_Whale

            http://stackoverflow.com/questions/13100698/unknown-error-on-renderstream[^] Can I suggest that you have a read of this

            Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

            B Offline
            B Offline
            BBatts
            wrote on last edited by
            #5

            OK. It tells me parameter is incorrect. That's the exception thrown. Which leads to believe the one of my two IBaseFilters isn't being released. But I don't see where or how.

            1 Reply Last reply
            0
            • B BBatts

              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.

              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;
              
              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              if (grabberBase != null)

              Why's that there? It should not be disposed before the ReleaseComObject is called.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              B 1 Reply Last reply
              0
              • L Lost User

                if (grabberBase != null)

                Why's that there? It should not be disposed before the ReleaseComObject is called.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                B Offline
                B Offline
                BBatts
                wrote on last edited by
                #7

                I know it's unnecessary -- it's just an old habit. Certainly not what's causing my problem though.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups