Troubles with GetStreamCaps

2005-07-16
2012-10-29
  • Ivanov Sergey

    Ivanov Sergey - 2005-07-16

    What should I pass instead "???"? And how can I get that value to pass?
    AMMediaType pMediaType = new AMMediaType();
    AudioStreamConfigCaps confCaps = new AudioStreamConfigCaps();
    hr = pStreamConfig.GetStreamCaps(i, out pMediaType, ???);
    DsError.ThrowExceptionForHR( hr );
    Thanks.

     
    • Eric

      Eric - 2005-07-16

      According to the Plateform SDK, the third parameter is a pointer (IntPtr in managed term). http://msdn.microsoft.com/library/en-us/directshow/htm/iamstreamconfiggetstreamcaps.asp?frame=true

      This pointer "point" on a VideoStreamConfigCaps or an AudioStreamConfigCaps structure. You can determine what kind of struct it is by checking the isize parameter returned by the GetNumberOfCapabilities method or check the mediatype returned by GetStreamCaps. Then you can use a Marshal.PtrToStructure to convert the IntPtr into a usable structure.

      All this is in the documentation. Please, read them...

       
    • snarfle

      snarfle - 2005-07-16

      Here is some (ugly) code:

              int hr;
              IntPtr pss;
              AMMediaType pmt;
              int iCount, iSize;
      
              hr = m_asc.GetNumberOfCapabilities(out iCount, out iSize);
              DsError.ThrowExceptionForHR(hr);
      
              pss = Marshal.AllocCoTaskMem(iCount * iSize);
              DsError.ThrowExceptionForHR(hr);
      
              if (iSize == Marshal.SizeOf(typeof(VideoStreamConfigCaps)))
              {
                  for (int x=0; x < iCount; x++)
                  {
                      hr = m_asc.GetStreamCaps(x, out pmt, pss);
                      DsError.ThrowExceptionForHR(hr);
      
                      VideoStreamConfigCaps vscc = (VideoStreamConfigCaps)Marshal.PtrToStructure(pss, typeof(VideoStreamConfigCaps));
                      pss = (IntPtr)(pss.ToInt64() + Marshal.SizeOf(typeof(VideoStreamConfigCaps)));
                  }
              }
              else if (iSize == Marshal.SizeOf(typeof(AudioStreamConfigCaps)))
              {
                  for (int x=0; x < iCount; x++)
                  {
                      hr = m_asc.GetStreamCaps(x, out pmt, pss);
                      DsError.ThrowExceptionForHR(hr);
      
                      AudioStreamConfigCaps vscc = (AudioStreamConfigCaps)Marshal.PtrToStructure(pss, typeof(AudioStreamConfigCaps));
                      pss = (IntPtr)(pss.ToInt64() + Marshal.SizeOf(typeof(AudioStreamConfigCaps)));
                  }
              }
              else
              {
                  Debug.Assert(false, "GetStreamCaps");
              }
      
              Marshal.FreeCoTaskMem(pss);
      
       
    • Ivanov Sergey

      Ivanov Sergey - 2005-07-16

      Sorry for disturbing you, I've read msdn articles already and tried the following code to get IntPtr for the third parameter:
      IntPtr p = IntPtr.Zero;
      Marshal.StructureToPtr(confCaps, p, true);
      But it fails with the exception "Value cannot be null". That is the reason of my question.

       
    • Ivanov Sergey

      Ivanov Sergey - 2005-07-16

      Thanks a lot. I've found an error, now I use GCHandle.Alloc instead of Marshal.StructureToPtr:
      GCHandle gch = System.Runtime.InteropServices.GCHandle.Alloc(confCaps);
      hr = pStreamConfig.GetStreamCaps(i, out pMediaType, (IntPtr)gch);
      DsError.ThrowExceptionForHR( hr );
      Now everything works great :)

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks