Infognition forum
February 11, 2012, 06:27:15 AM *
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: NEW - Generated code cannot connect filters  (Read 2193 times)
WayneVanRooyen
Newbie
*

Karma: +0/-0
Posts: 2


View Profile
« on: March 19, 2009, 06:52:27 PM »

I have recently purchased graphedit, and i am having the same problem with the pins not being found, i have tried both methods direct connect and renderstream and it always goes to the hr exception.
This is very frustrating as the graph builds and runs fine in graphedit
Logged
Dee Mon
Administrator
Hero Member
*****

Karma: +8/-0
Posts: 517



View Profile WWW
« Reply #1 on: March 20, 2009, 12:13:07 AM »

I guess you've seen recommendations from similar topics here. Can't add anything to them.
What kind of error your code returns?
Logged
WayneVanRooyen
Newbie
*

Karma: +0/-0
Posts: 2


View Profile
« Reply #2 on: March 20, 2009, 05:25:12 PM »

Hi been through all the recommendations but nothing fixed the problem.
The problem is that it searches for a min named analog audio but the get pins does not find any and returns 0.
I have also tried to put a sleep in case it takes a while to build the capture device.
And its not my code it a direct copy and paste from your generate code that fails on the first get pin.

//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_TridVidTvTuner0001 = new Guid("{266EEE40-6C63-11CF-8A03-00AA006ECB65}"); //kstvtune.ax
            Guid CLSID_TridVidTvAudio0002 = new Guid("{71F96462-78F3-11D0-A18C-00A0C9118956}"); //ksxbar.ax
            Guid CLSID_TridVidCrossbar = new Guid("{71F96460-78F3-11D0-A18C-00A0C9118956}"); //ksxbar.ax
            Guid CLSID_SigmaTelAudioTopology = new Guid("{17CCA71B-ECD7-11D0-B908-00A0C9223196}"); //ksproxy.ax
            Guid CLSID_VideoRenderer = new Guid("{B87BEB7B-8D29-423F-AE4D-6582C10175AC}"); //quartz.dll

            //add TridVid TvTuner 0001
            IBaseFilter pTridVidTvTuner0001 = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_TridVidTvTuner0001));
            hr = pGraph.AddFilter(pTridVidTvTuner0001, "TridVid TvTuner 0001");
            checkHR(hr, "Can't add TridVid TvTuner 0001 to graph");

            //add TridVid TvAudio 0002
            IBaseFilter pTridVidTvAudio0002 = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_TridVidTvAudio0002));
            hr = pGraph.AddFilter(pTridVidTvAudio0002, "TridVid TvAudio 0002");
            checkHR(hr, "Can't add TridVid TvAudio 0002 to graph");

            //connect TridVid TvTuner 0001 and TridVid TvAudio 0002
            hr = pGraph.ConnectDirect(GetPin(pTridVidTvTuner0001, "Analog Audio"), GetPin(pTridVidTvAudio0002, "TVAudio In"), null);
            checkHR(hr, "Can't connect TridVid TvTuner 0001 and TridVid TvAudio 0002");

            //add TridVid Crossbar
            IBaseFilter pTridVidCrossbar = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_TridVidCrossbar));
            hr = pGraph.AddFilter(pTridVidCrossbar, "TridVid Crossbar");
            checkHR(hr, "Can't add TridVid Crossbar to graph");

            //connect TridVid TvTuner 0001 and TridVid Crossbar
            hr = pGraph.ConnectDirect(GetPin(pTridVidTvTuner0001, "Analog Video"), GetPin(pTridVidCrossbar, "0: Video Tuner In"), null);
            checkHR(hr, "Can't connect TridVid TvTuner 0001 and TridVid Crossbar");

            //connect TridVid TvAudio 0002 and TridVid Crossbar
            hr = pGraph.ConnectDirect(GetPin(pTridVidTvAudio0002, "TVAudio Out"), GetPin(pTridVidCrossbar, "3: Audio Tuner In"), null);
            checkHR(hr, "Can't connect TridVid TvAudio 0002 and TridVid Crossbar");

            //add SigmaTel Audio Topology
            IBaseFilter pSigmaTelAudioTopology = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_SigmaTelAudioTopology));
            hr = pGraph.AddFilter(pSigmaTelAudioTopology, "SigmaTel Audio Topology");
            checkHR(hr, "Can't add SigmaTel Audio Topology to graph");

            //connect TridVid Crossbar and SigmaTel Audio Topology
            hr = pGraph.ConnectDirect(GetPin(pTridVidCrossbar, "0: Video Decoder Out"), GetPin(pSigmaTelAudioTopology, "Analog Video In"), null);
            checkHR(hr, "Can't connect TridVid Crossbar and SigmaTel Audio Topology");

            //connect TridVid Crossbar and SigmaTel Audio Topology
            hr = pGraph.ConnectDirect(GetPin(pTridVidCrossbar, "1: Audio Decoder Out"), GetPin(pSigmaTelAudioTopology, "Analog Audio In"), null);
            checkHR(hr, "Can't connect TridVid Crossbar and SigmaTel Audio Topology");

            //add Video Renderer
            IBaseFilter pVideoRenderer = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_VideoRenderer));
            hr = pGraph.AddFilter(pVideoRenderer, "Video Renderer");
            checkHR(hr, "Can't add Video Renderer to graph");

            //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");

            //connect SigmaTel Audio Topology and Video Renderer
            hr = pGraph.ConnectDirect(GetPin(pSigmaTelAudioTopology, "Capture"), GetPin(pVideoRenderer, "VMR Input0"), null);
            checkHR(hr, "Can't connect SigmaTel Audio Topology and Video Renderer");

            //connect SigmaTel Audio Topology and Default DirectSound Device
            hr = pGraph.ConnectDirect(GetPin(pSigmaTelAudioTopology, "Audio"), GetPin(pDefaultDirectSoundDevice, "Audio Input pin (rendered)"), null);
            checkHR(hr, "Can't connect SigmaTel Audio Topology and Default DirectSound Device");

        }

        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;
                int n = 0;
                while (!stop)
                {
                    System.Threading.Thread.Sleep(500);
                    Console.Write(".");
                    EventCode ev;
                    IntPtr p1, p2;
                    if (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);
                    }
                    // stop after 10 seconds
                    n++;
                    if (n > 20)
                    {
                        Console.WriteLine("stopping..");
                        mediaControl.Stop();
                        stop = true;
                    }
                }
            }
            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(hr,"");
            return null;
        }

    }
}
« Last Edit: March 20, 2009, 05:26:43 PM by WayneVanRooyen » Logged
Dee Mon
Administrator
Hero Member
*****

Karma: +8/-0
Posts: 517



View Profile WWW
« Reply #3 on: March 21, 2009, 09:53:11 PM »

In your case the problem might be in tuner filter creation.
Try creating it not by CLSID, but by DisplayName. Use this code:
Code:
public static IBaseFilter CreateFilter(string displayName)
        {
            int hr = 0;
            IBaseFilter filter = null;
            IBindCtx bindCtx = null;
            IMoniker moniker = null;

            try
            {
                hr = CreateBindCtx(0, out bindCtx);
                Marshal.ThrowExceptionForHR(hr);

                int eaten;
                hr = MkParseDisplayName(bindCtx, displayName, out eaten, out moniker);
                Marshal.ThrowExceptionForHR(hr);

                Guid guid = typeof(IBaseFilter).GUID;
                object obj;
                moniker.BindToObject(bindCtx, null, ref guid, out obj);
                filter = (IBaseFilter)obj;
            }
            finally
            {
                if (bindCtx != null) Marshal.ReleaseComObject(bindCtx);
                if (moniker != null) Marshal.ReleaseComObject(moniker);
            }

            return filter;
        }

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

        [DllImport("ole32.dll")]
        public static extern int MkParseDisplayName(IBindCtx pcb, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out int pchEaten, out IMoniker ppmk);

Actual DisplayName you can copy from properties window when you click the tuner in filters list.
And if you need to be sure your code works correctly on different machines, you should enumerate capture sources, find your tuner there and insert it by its moniker.
« Last Edit: March 21, 2009, 09:54:47 PM by Dee Mon » Logged
caseyd
Newbie
*

Karma: +0/-0
Posts: 9


View Profile
« Reply #4 on: December 16, 2011, 10:59:00 PM »

Is there a workaround for this if the tuner shows no display name in the properties?
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!