Infognition forum
May 18, 2012, 10:20:25 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Last GraphEditPlus version: 1.4.0   Last Video Enhancer version: 1.9.7
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Error with generated C# code  (Read 808 times)
caseyd
Newbie
*

Karma: +0/-0
Posts: 9


View Profile
« on: December 16, 2011, 10:50:10 AM »

Any help is appreciated.....
Below is the output i get when running the code:

Pin not found
COM error: System.Runtime.InteropServices.COMException (0xFFFFFFFF): Exception from HRESULT: 0xFFFFFFFF
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at DirectShowLib.DsError.ThrowExceptionForHR(Int32 hr)
   at VideoSetupWindowed.Program.checkHR(Int32 hr, String msg) in c:\Documents and Settings\ST\My Documents\SharpDevelop Projects\VideoSetupWindowed\VideoSetupWindowed\Program.cs:line 114
   at VideoSetupWindowed.Program.GetPin(IBaseFilter filter, String pinname) in c:\Documents and Settings\ST\My Documents\SharpDevelop Projects\VideoSetupWindowed\VideoSetupWindowed\Program.cs:line 105
   at VideoSetupWindowed.Program.BuildGraph(IGraphBuilder pGraph) in c:\Documents and Settings\ST\My Documents\SharpDevelop Projects\VideoSetupWindowed\VideoSetupWindowed\Program.cs:line 145
   at VideoSetupWindowed.Program.Main(String[] args) in c:\Documents and Settings\ST\My Documents\SharpDevelop Projects\VideoSetupWindowed\VideoSetupWindowed\Program.cs:line 44
Logged
Dee Mon
Administrator
Hero Member
*****

Karma: +8/-0
Posts: 530



View Profile WWW
« Reply #1 on: December 16, 2011, 01:30:37 PM »

Obviously it means some pin not found. That's all that can be said based on your info.
If you provide more details on what you're trying to do in the code, you'll get a more detailed answer.

This topic looks very similar:
http://forum.infognition.com/index.php/topic,797.0.html

Logged
caseyd
Newbie
*

Karma: +0/-0
Posts: 9


View Profile
« Reply #2 on: December 16, 2011, 04:45:43 PM »

Sorry - you're right - here's the generated code I am using... does this help?

//Don't forget to add reference to DirectShowLib in your project.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;
using System.Runtime.InteropServices;
using DirectShowLib;

namespace graphcode
{
    class Program
    {
        static void checkHR(int hr, string msg)
        {
            if (hr < 0)
            {
                Console.WriteLine(msg);
                DsError.ThrowExceptionForHR(hr);
            }
        }

        static void BuildGraph(IGraphBuilder pGraph)
        {
            int hr = 0;

            //graph builder
            ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
            hr = pBuilder.SetFiltergraph(pGraph);
            checkHR(hr, "Can't SetFiltergraph");

            Guid CLSID_713xBDAAnalogTVTuner = new Guid("{266EEE40-6C63-11CF-8A03-00AA006ECB65}"); //kstvtune.ax
            Guid CLSID_713xBDAAnalogTVAudio = new Guid("{71F96462-78F3-11D0-A18C-00A0C9118956}"); //ksxbar.ax
            Guid CLSID_713xBDAAnalogXbar = new Guid("{71F96460-78F3-11D0-A18C-00A0C9118956}"); //ksxbar.ax
            Guid CLSID_713xBDAAnalogCapture = new Guid("{17CCA71B-ECD7-11D0-B908-00A0C9223196}"); //ksproxy.ax
            Guid CLSID_ArcSoftDeinterlace = new Guid("{6F07F8ED-C91F-4C9F-931F-37D108545CDB}"); //deinterlace.ax
            Guid CLSID_VCamRendererC = new Guid("{D7DE5DAC-B140-441A-87C1-568DFD91706E}"); //VCamFilters.ax

            //add 713x BDA Analog TV Tuner
            IBaseFilter p713xBDAAnalogTVTuner = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_713xBDAAnalogTVTuner));
            hr = pGraph.AddFilter(p713xBDAAnalogTVTuner, "713x BDA Analog TV Tuner");
            checkHR(hr, "Can't add 713x BDA Analog TV Tuner to graph");

            //add 713x BDA Analog TV Audio
            IBaseFilter p713xBDAAnalogTVAudio = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_713xBDAAnalogTVAudio));
            hr = pGraph.AddFilter(p713xBDAAnalogTVAudio, "713x BDA Analog TV Audio");
            checkHR(hr, "Can't add 713x BDA Analog TV Audio to graph");

            //connect 713x BDA Analog TV Tuner and 713x BDA Analog TV Audio
            hr = pGraph.ConnectDirect(GetPin(p713xBDAAnalogTVTuner, "Analog Audio"), GetPin(p713xBDAAnalogTVAudio, "TVAudio In"), null);
            checkHR(hr, "Can't connect 713x BDA Analog TV Tuner and 713x BDA Analog TV Audio");

            //add 713x BDA Analog Xbar
            IBaseFilter p713xBDAAnalogXbar = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_713xBDAAnalogXbar));
            hr = pGraph.AddFilter(p713xBDAAnalogXbar, "713x BDA Analog Xbar");
            checkHR(hr, "Can't add 713x BDA Analog Xbar to graph");

            //connect 713x BDA Analog TV Audio and 713x BDA Analog Xbar
            hr = pGraph.ConnectDirect(GetPin(p713xBDAAnalogTVAudio, "TVAudio Out"), GetPin(p713xBDAAnalogXbar, "3: Audio Tuner In"), null);
            checkHR(hr, "Can't connect 713x BDA Analog TV Audio and 713x BDA Analog Xbar");

            //add 713x BDA Analog Capture
            IBaseFilter p713xBDAAnalogCapture = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_713xBDAAnalogCapture));
            hr = pGraph.AddFilter(p713xBDAAnalogCapture, "713x BDA Analog Capture");
            checkHR(hr, "Can't add 713x BDA Analog Capture to graph");

            //connect 713x BDA Analog Xbar and 713x BDA Analog Capture
            hr = pGraph.ConnectDirect(GetPin(p713xBDAAnalogXbar, "0: Video Decoder Out"), GetPin(p713xBDAAnalogCapture, "Analog Video In"), null);
            checkHR(hr, "Can't connect 713x BDA Analog Xbar and 713x BDA Analog Capture");

            //connect 713x BDA Analog Xbar and 713x BDA Analog Capture
            hr = pGraph.ConnectDirect(GetPin(p713xBDAAnalogXbar, "1: Audio Decoder Out"), GetPin(p713xBDAAnalogCapture, "Analog Audioinput"), null);
            checkHR(hr, "Can't connect 713x BDA Analog Xbar and 713x BDA Analog Capture");

            //add Default DirectSound Device
            IBaseFilter pDefaultDirectSoundDevice = (IBaseFilter) new DSoundRender();
            hr = pGraph.AddFilter(pDefaultDirectSoundDevice, "Default DirectSound Device");
            checkHR(hr, "Can't add Default DirectSound Device to graph");

            //add ArcSoft Deinterlace
            IBaseFilter pArcSoftDeinterlace = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_ArcSoftDeinterlace));
            hr = pGraph.AddFilter(pArcSoftDeinterlace, "ArcSoft Deinterlace");
            checkHR(hr, "Can't add ArcSoft Deinterlace to graph");

            //connect 713x BDA Analog Capture and ArcSoft Deinterlace
            hr = pGraph.ConnectDirect(GetPin(p713xBDAAnalogCapture, "Capture"), GetPin(pArcSoftDeinterlace, "XForm In"), null);
            checkHR(hr, "Can't connect 713x BDA Analog Capture and ArcSoft Deinterlace");

            //connect 713x BDA Analog Capture and Default DirectSound Device
            hr = pGraph.ConnectDirect(GetPin(p713xBDAAnalogCapture, "Audio"), GetPin(pDefaultDirectSoundDevice, "Audio Input pin (rendered)"), null);
            checkHR(hr, "Can't connect 713x BDA Analog Capture and Default DirectSound Device");

            //add VCam Renderer (C)
            IBaseFilter pVCamRendererC = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_VCamRendererC));
            hr = pGraph.AddFilter(pVCamRendererC, "VCam Renderer (C)");
            checkHR(hr, "Can't add VCam Renderer (C) to graph");

            //connect ArcSoft Deinterlace and VCam Renderer (C)
            hr = pGraph.ConnectDirect(GetPin(pArcSoftDeinterlace, "XForm Out"), GetPin(pVCamRendererC, "In"), null);
            checkHR(hr, "Can't connect ArcSoft Deinterlace and VCam Renderer (C)");

        }

        static void Main(string[] args)
        {
            try
            {
                IGraphBuilder graph = (IGraphBuilder)new FilterGraph();
                Console.WriteLine("Building graph...");
                BuildGraph(graph);
                Console.WriteLine("Running...");
                IMediaControl mediaControl = (IMediaControl)graph;
                IMediaEvent mediaEvent = (IMediaEvent)graph;
                int hr = mediaControl.Run();
                checkHR(hr, "Can't run the graph");
                bool stop = false;
                while (!stop)
                {
                    System.Threading.Thread.Sleep(500);
                    Console.Write(".");
                    EventCode ev;
                    IntPtr p1, p2;
                    System.Windows.Forms.Application.DoEvents();
                    while (mediaEvent.GetEvent(out ev, out p1, out p2, 0) == 0)
                    {
                        if (ev == EventCode.Complete || ev == EventCode.UserAbort)
                        {
                            Console.WriteLine("Done!");
                            stop = true;
                        }
                        else
                        if (ev == EventCode.ErrorAbort)
                        {
                            Console.WriteLine("An error occured: HRESULT={0:X}", p1);
                            mediaControl.Stop();
                            stop = true;
                        }
                        mediaEvent.FreeEventParams(ev, p1, p2);
                    }
                }
            }
            catch (COMException ex)
            {
                Console.WriteLine("COM error: " + ex.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.ToString());
            }
        }
        static IPin GetPin(IBaseFilter filter, string pinname)
        {
            IEnumPins epins;
            int hr = filter.EnumPins(out epins);
            checkHR(hr, "Can't enumerate pins");
            IntPtr fetched = Marshal.AllocCoTaskMem(4);
            IPin[] pins = new IPin[1];
            while (epins.Next(1, pins, fetched) == 0)
            {
                PinInfo pinfo;
                pins[0].QueryPinInfo(out pinfo);
                bool found = (pinfo.name == pinname);
                DsUtils.FreePinInfo(pinfo);
                if (found)
                    return pins[0];
            }
            checkHR(-1, "Pin not found");
            return null;
        }

    }
}
Logged
caseyd
Newbie
*

Karma: +0/-0
Posts: 9


View Profile
« Reply #3 on: December 16, 2011, 04:50:36 PM »

In debug, it looks like it's the DirectShowLib.IBaseFilter that's the culprit pin
Logged
caseyd
Newbie
*

Karma: +0/-0
Posts: 9


View Profile
« Reply #4 on: December 16, 2011, 05:26:42 PM »

The post you referenced says I need to re-write some of the generated code...... I purchased this prog to generate code so that I wouldn't need to write this code.....
If I DO need to re-write the code, can you give me an example of one of the repairs I must do?
Logged
Dee Mon
Administrator
Hero Member
*****

Karma: +8/-0
Posts: 530



View Profile WWW
« Reply #5 on: December 17, 2011, 11:43:52 AM »

Here's a function that creates a filter by its name. You need to provide the name as string and GUID of that filter's category which you can look up in the filters list in GraphEditPlus.

Code:
        public static IBaseFilter CreateFilterByName(string filterName, Guid category)
        {
            int hr = 0;
            DsDevice[] devices = DsDevice.GetDevicesOfCat(category);
            foreach(DsDevice dev in devices)
                if (dev.Name == filterName)
                {
                    IBaseFilter filter = null;
                    IBindCtx bindCtx = null;
                    try
                    {
                        hr = CreateBindCtx(0, out bindCtx);
                        DsError.ThrowExceptionForHR(hr);
                        Guid guid = typeof(IBaseFilter).GUID;
                        object obj;
                        dev.Mon.BindToObject(bindCtx, null, ref guid, out obj);
                        filter = (IBaseFilter)obj;
                    }
                    finally
                    {
                        if (bindCtx != null) Marshal.ReleaseComObject(bindCtx);
                    }
                    return filter;
                }
            return null;
        }

[DllImport("ole32.dll")]
public static extern int CreateBindCtx(int reserved, out IBindCtx ppbc);
Logged
caseyd
Newbie
*

Karma: +0/-0
Posts: 9


View Profile
« Reply #6 on: December 18, 2011, 02:34:12 AM »

I've added the code snippet from above and changed this line:


IBaseFilter p713xBDAAnalogTVAudio = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_713xBDAAnalogTVAudio));

to:

IBaseFilter p713xBDAAnalogTVAudio =  (IBaseFilter)CreateFilterByName("713x BDA Analog TV Audio", CLSID_713xBDAAnalogTVAudio);

Obviously this is incorrect, because now I get his error...

Building graph...
Can't add 713x BDA Analog TV Audio to graph
COM error: System.Runtime.InteropServices.COMException (0x80004003): Invalid pointer

   at DirectShowLib.DsError.ThrowExceptionForHR(Int32 hr)
   at VideoSetupWindowed.Program.checkHR(Int32 hr, String msg) in c:\Documents and Settings\ST\My Documents\SharpDevelop Projects\VideoSetupWindowed\VideoSetupWindowed\Program.cs:line 128
   at VideoSetupWindowed.Program.BuildGraph(IGraphBuilder pGraph) in c:\Documents and Settings\ST\My Documents\SharpDevelop Projects\VideoSetupWindowed\VideoSetupWindowed\Program.cs:line 169
   at VideoSetupWindowed.Program.Main(String[] args) in c:\Documents and Settings\ST\My Documents\SharpDevelop Projects\VideoSetupWindowed\VideoSetupWindowed\Program.cs:line 50
Logged
Dee Mon
Administrator
Hero Member
*****

Karma: +8/-0
Posts: 530



View Profile WWW
« Reply #7 on: December 18, 2011, 08:55:34 AM »

Yep, look at the second argument.
CreateFilterByName(string filterName, Guid category)
and my words above:
"You need to provide the name as string and GUID of that filter's category."

You won't go far in DirectShow without understanding the basics.
Every filter belongs to some category. You may see the category name here:


Every category has its CLSID. You can find it by looking at category of all categories and clicking the category you're interested in:
« Last Edit: December 18, 2011, 09:05:45 AM by Dee Mon » Logged
caseyd
Newbie
*

Karma: +0/-0
Posts: 9


View Profile
« Reply #8 on: December 20, 2011, 08:29:50 AM »

Ok - I finally got it to run using the CreateFilter method and sending displayname,...

now, my issue is that the settings on the property pages aren't staying the way it is in the graph settings...

For instance - after I quit GraphBuilderPlus, then reboot, and run my C# project, the input on the video card is set back to default...

Have any ideas?
Logged
Dee Mon
Administrator
Hero Member
*****

Karma: +8/-0
Posts: 530



View Profile WWW
« Reply #9 on: December 20, 2011, 03:13:36 PM »

If the settings in question are video mode/format, then most probably that filter's pin exposes IAMStreamConfig interface which you can use in your program to list available formats and select the one you need. In GraphEditPlus you can check it by right clicking the pin, if IAMStreamConfig is supported you'll see corresponding commands in the context menu.

If it's something else then there is a harder but more general way - using IPersistStream to save and load settings. If the filter supports this interface, of course.
Logged
caseyd
Newbie
*

Karma: +0/-0
Posts: 9


View Profile
« Reply #10 on: December 20, 2011, 05:59:33 PM »

Thanks - got it by scanning interfaces. I got the graph to set the pins on IAMCrossbar object derived using IBaseFilter pointer...

Now, my application is having trouble quitting, and I believe it is due to filter/resources not being released....
what i'm getting is a message telling me the requested resource is in use when I exit my app and run a second time ...

I don't see anything in the generated code, but how do I release the filters or suspend/stop the process on exit?
« Last Edit: December 20, 2011, 06:52:57 PM by caseyd » Logged
Dee Mon
Administrator
Hero Member
*****

Karma: +8/-0
Posts: 530



View Profile WWW
« Reply #11 on: December 20, 2011, 08:19:37 PM »

First stop your graph, for each filter in your graph:
Code:
graphBuilder.RemoveFilter(filter);
Marshal.ReleaseComObject(filter);
and then
Marshal.ReleaseComObject(graphBuilder);
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!