Beispiel #1
0
        /// <summary>Возвращает удобное для чтения имя коннектора. </summary>
        private string getName(IPin pin)
        {
            string  s       = "Unknown pin";
            PinInfo pinInfo = new PinInfo();

            // Direction matches, so add pin name to listbox
            int hr = pin.QueryPinInfo(out pinInfo);

            if (hr == 0)
            {
                s = pinInfo.name + "";
            }
            else
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            //Структура PinInfo содержит ссылку на IBaseFilter, поэтому необходимо освободить ее, чтобы предотвратить утечку
            if (pinInfo.filter != null)
            {
                Marshal.ReleaseComObject(pinInfo.filter);
            }
            pinInfo.filter = null;
            return(s);
        }
        // --------------------------- Private methods ----------------------------

        /// <summary> Retrieve the friendly name of a connectorType. </summary>
        private string getName(IPin pin)
        {
            string  s       = "Unknown pin";
            PinInfo pinInfo = new PinInfo();

            // Direction matches, so add pin name to listbox
            int hr = pin.QueryPinInfo(out pinInfo);

            if (hr == 0)
            {
                s = pinInfo.name + "";
            }
            else
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            // The pininfo structure contains a reference to an IBaseFilter,
            // so you must release its reference to prevent resource a leak.
            if (pinInfo.filter != null)
            {
                Marshal.ReleaseComObject(pinInfo.filter);
            }
            pinInfo.filter = null;

            return(s);
        }
        /// <summary> Retrieve the friendly name of a connectorType. </summary>
        private string GetName(IPin pin)
        {
            string str = "Unknown pin";
            PinInfo pinInfo = new PinInfo();

            // Direction matches, so add pin name to listbox
            int errorCode = pin.QueryPinInfo(out pinInfo);
            if (errorCode == 0)
            {
                str = pinInfo.name ?? "";
            }
            else
            {
                Marshal.ThrowExceptionForHR(errorCode);
            }

            // The pininfo structure contains a reference to an IBaseFilter,
            // so you must release its reference to prevent resource a leak.
            if (pinInfo.filter != null)
            {
                Marshal.ReleaseComObject(pinInfo.filter);
            }
            pinInfo.filter = null;
            return str;
        }
Beispiel #4
0
        public static bool DisconnectPin(IGraphBuilder graphBuilder, IPin pin)
        {
            IPin    other;
            int     hr = pin.ConnectedTo(out other);
            bool    allDisconnected = true;
            PinInfo info;

            pin.QueryPinInfo(out info);
            DsUtils.FreePinInfo(info);

            if (hr == 0 && other != null)
            {
                other.QueryPinInfo(out info);
                if (!DisconnectAllPins(graphBuilder, info.filter))
                {
                    allDisconnected = false;
                }
                hr = pin.Disconnect();
                if (hr != 0)
                {
                    allDisconnected = false;
                }
                hr = other.Disconnect();
                if (hr != 0)
                {
                    allDisconnected = false;
                }
                DsUtils.FreePinInfo(info);
                Marshal.ReleaseComObject(other);
            }
            else
            {
            }
            return(allDisconnected);
        }
Beispiel #5
0
        public static string Name(IPin pin)
        {
            _PinInfo pi;

            pin.QueryPinInfo(out pi);
            return(pi.achName);
        }
Beispiel #6
0
        /// <summary>
        /// ピンの検索
        /// </summary>
        /// <param name="filter">フィルタ</param>
        /// <param name="name">ピン名称</param>
        /// <returns>
        ///		見つかった場合は、ピンの IPin インターフェースを返します。
        ///		見つからなかった場合は、 null を返します。
        ///	</returns>
        public static IPin FindPin(IBaseFilter filter, string name)
        {
            IEnumPins enumpins = null;
            IPin      pin      = null;

            try
            {
                filter.EnumPins(ref enumpins);

                int fetched = 0;
                while (enumpins.Next(1, ref pin, ref fetched) == 0)
                {
                    if (fetched == 0)
                    {
                        break;
                    }

                    var info = new PIN_INFO();

                    try
                    {
                        pin.QueryPinInfo(info);
                        if (info.achName == name)
                        {
                            return(pin);
                        }

                        if (pin != null)
                        {
                            Marshal.ReleaseComObject(pin);
                        }
                        pin = null;
                    }
                    finally
                    {
                        if (info.pFilter != null)
                        {
                            Marshal.ReleaseComObject(info.pFilter);
                        }
                    }
                }
            }
            catch
            {
                if (pin != null)
                {
                    Marshal.ReleaseComObject(pin);
                }
                throw;
            }
            finally
            {
                if (enumpins != null)
                {
                    Marshal.ReleaseComObject(enumpins);
                }
            }

            return(null);
        }
Beispiel #7
0
        /// <summary>
        /// Gets the filter that owns the specified pin.
        /// </summary>
        /// <param name="pin">pin to get owner of</param>
        /// <returns>Caller is responsible for freeing this filter</returns>
        public static IBaseFilter GetFilter(this IPin pin)
        {
            PinInfo info = default(PinInfo);
            int     hr   = pin.QueryPinInfo(out info);

            DsError.ThrowExceptionForHR(hr);
            return(info.filter);
        }
        private void logPins(IBaseFilter filter)
        {
            IEnumPins enumPins = null;

            IPin[] pins = new IPin[1];

            reply = filter.EnumPins(out enumPins);
            DsError.ThrowExceptionForHR(reply);

            if (enumPins == null)
            {
                return;
            }

            while (enumPins.Next(pins.Length, pins, IntPtr.Zero) == 0)
            {
                PinInfo pinInfo;

                reply = pins[0].QueryPinInfo(out pinInfo);
                DsError.ThrowExceptionForHR(reply);

                IPin connectedPin = null;
                reply = pins[0].ConnectedTo(out connectedPin);
                if (connectedPin != null)
                {
                    PinInfo connectedPinInfo;
                    reply = connectedPin.QueryPinInfo(out connectedPinInfo);
                    DsError.ThrowExceptionForHR(reply);

                    FilterInfo filterInfo;
                    reply = connectedPinInfo.filter.QueryFilterInfo(out filterInfo);
                    DsError.ThrowExceptionForHR(reply);

                    LogMessage("Pin: " + pinInfo.name + " Connected to: " + filterInfo.achName);
                    logMediaTypes(pins[0]);
                    if (filterInfo.pGraph != null)
                    {
                        Marshal.ReleaseComObject(filterInfo.pGraph);
                    }
                }
                else
                {
                    LogMessage("Pin: " + pinInfo.name + " not connected");
                    logMediaTypes(pins[0]);
                }

                Marshal.ReleaseComObject(pins[0]);
                if (connectedPin != null)
                {
                    Marshal.ReleaseComObject(connectedPin);
                }
            }

            Marshal.ReleaseComObject(enumPins);
        }
Beispiel #9
0
    private static IPin?EnumPins(IBaseFilter filter, Func <PIN_INFO, bool> func)
    {
        IEnumPins?pins = null;
        IPin?     ipin = null;

        try
        {
            filter.EnumPins(ref pins);

            int fetched = 0;
            while (pins?.Next(1, ref ipin, ref fetched) == 0)
            {
                if (fetched == 0)
                {
                    break;
                }

                var info = new PIN_INFO();
                try
                {
                    ipin?.QueryPinInfo(info);
                    var rc = func(info);
                    if (rc)
                    {
                        return(ipin);
                    }
                }
                finally
                {
                    if (info.pFilter != null)
                    {
                        Marshal.ReleaseComObject(info.pFilter);
                    }
                }
            }
        }
        catch
        {
            if (ipin != null)
            {
                Marshal.ReleaseComObject(ipin);
            }
            throw;
        }
        finally
        {
            if (pins != null)
            {
                Marshal.ReleaseComObject(pins);
            }
        }

        return(null);
    }
Beispiel #10
0
        /// <summary>
        /// ピン一覧の取得
        /// </summary>
        /// <param name="filter">対象のフィルタ</param>
        /// <returns>
        ///		取得したピン情報のコレクションを返します。
        /// </returns>
        public static List <CxPinInfo> GetPinList(IBaseFilter filter)
        {
            var       result   = new List <CxPinInfo>();
            IEnumPins enumpins = null;

            try
            {
                filter.EnumPins(ref enumpins);

                while (true)
                {
                    IPin pin     = null;
                    int  fetched = 0;
                    if (enumpins.Next(1, ref pin, ref fetched) < 0)
                    {
                        break;
                    }
                    if (fetched == 0)
                    {
                        break;
                    }

                    var info = new PIN_INFO();

                    try
                    {
                        pin.QueryPinInfo(info);
                        var dpi = new CxPinInfo(info.achName, info.dir);
                        result.Add(dpi);
                    }
                    finally
                    {
                        if (info.pFilter != null)
                        {
                            Marshal.ReleaseComObject(info.pFilter);
                        }
                        if (pin != null)
                        {
                            Marshal.ReleaseComObject(pin);
                        }
                        pin = null;
                    }
                }
            }
            finally
            {
                if (enumpins != null)
                {
                    Marshal.ReleaseComObject(enumpins);
                }
            }

            return(result);
        }
Beispiel #11
0
        public DSInputPin(IPin pin) : base()
        {
            _pin = pin;

            // get the name of the IPin
            PinInfo pi;

            _pin.QueryPinInfo(out pi);
            Name = pi.name;
            DsUtils.FreePinInfo(pi);
        }
Beispiel #12
0
        protected void removeDownstream(IBaseFilter filter, bool removeFirstFilter)
        {
            // Get a pin enumerator off the filter
            IEnumPins pinEnum;
            int       hr = filter.EnumPins(out pinEnum);

            pinEnum.Reset();
            if ((hr == 0) && (pinEnum != null))
            {
                // Loop through each pin
                IPin[] pins = new IPin[1];
                int    f;
                do
                {
                    // Get the next pin
                    hr = pinEnum.Next(1, pins, out f);
                    if ((hr == 0) && (pins[0] != null))
                    {
                        // Get the pin it is connected to
                        IPin pinTo = null;
                        pins[0].ConnectedTo(out pinTo);
                        if (pinTo != null)
                        {
                            // Is this an input pin?
                            PinInfo info = new PinInfo();
                            hr = pinTo.QueryPinInfo(out info);
                            if ((hr == 0) && (info.dir == (PinDirection.Input)))
                            {
                                // Recurse down this branch
                                removeDownstream(info.filter, true);

                                // Disconnect
                                graphBuilder.Disconnect(pinTo);
                                graphBuilder.Disconnect(pins[0]);

                                // Remove this filter
                                // but don't remove the video or audio compressors
                                if ((info.filter != videoCompressorFilter) &&
                                    (info.filter != audioCompressorFilter))
                                {
                                    graphBuilder.RemoveFilter(info.filter);
                                }
                            }
                            Marshal.ReleaseComObject(info.filter);
                            Marshal.ReleaseComObject(pinTo);
                        }
                        Marshal.ReleaseComObject(pins[0]);
                    }
                }while (hr == 0);

                Marshal.ReleaseComObject(pinEnum);
                pinEnum = null;
            }
        }
Beispiel #13
0
        private void RenderNetDemux()
        {
            int hr;

            IEnumPins enumPins;

            IPin[] pins = new IPin[1];

            hr = _netDmx.EnumPins(out enumPins);
            DsError.ThrowExceptionForHR(hr);
            try
            {
                while (enumPins.Next(pins.Length, pins, IntPtr.Zero) == 0)
                {
                    try
                    {
                        PinInfo pinInfo;
                        IPin    upstreamPin = pins[0];
                        hr = upstreamPin.QueryPinInfo(out pinInfo);
                        DsError.ThrowExceptionForHR(hr);
                        if (pinInfo.dir == PinDirection.Output)
                        {
                            IEnumMediaTypes enumMediaTypes;
                            hr = upstreamPin.EnumMediaTypes(out enumMediaTypes);
                            DsError.ThrowExceptionForHR(hr);
                            AMMediaType[] mediaTypes = new AMMediaType[1];

                            if (enumMediaTypes.Next(1, mediaTypes, IntPtr.Zero) == 0)
                            {
                                AMMediaType mediaType = mediaTypes[0];
                                if (mediaType.majorType == MediaType.Video)
                                {
                                    hr = _captureGraphBuilder.RenderStream(null, null, upstreamPin, _videoDecoder, _videoRender);
                                }
                                else
                                {
                                    AddAudioVolumeFilter();
                                    AddAudioRenderer();
                                    ConnectToAudio(upstreamPin, true);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(pins[0]);
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(enumPins);
            }
        }
Beispiel #14
0
        public void TestQueryPinInfo()
        {
            IPin    testPin = GetSmartTeeInputPin();
            PinInfo pinInfo;
            int     hr = testPin.QueryPinInfo(out pinInfo);

            Marshal.ThrowExceptionForHR(hr);


            Assert.IsNotNull(pinInfo);
            Assert.IsNotNull(pinInfo.name);
            Console.WriteLine(pinInfo.name);
        }
Beispiel #15
0
        /// <summary>
        /// QueryConnect checks if two Pins can be connected.
        /// </summary>
        /// <param name="pin">Pin 1</param>
        /// <param name="other">Pin 2</param>
        /// <returns>True if they accept connection</returns>
        static bool QueryConnect(IPin pin, IPin other)
        {
            IEnumMediaTypes enumTypes;
            int             hr = pin.EnumMediaTypes(out enumTypes);

            if (hr != 0 || enumTypes == null)
            {
                return(false);
            }

            int    count      = 0;
            IntPtr ptrFetched = Marshal.AllocCoTaskMem(4);

            try
            {
                for (; ;)
                {
                    AMMediaType[] types = new AMMediaType[1];
                    hr = enumTypes.Next(1, types, ptrFetched);
                    if (hr != 0 || Marshal.ReadInt32(ptrFetched) == 0)
                    {
                        break;
                    }

                    count++;
                    try
                    {
                        if (other.QueryAccept(types[0]) == 0)
                        {
                            return(true);
                        }
                    }
                    finally
                    {
                        FilterGraphTools.FreeAMMediaType(types[0]);
                    }
                }
                PinInfo info;
                PinInfo infoOther;
                pin.QueryPinInfo(out info);
                other.QueryPinInfo(out infoOther);
                ServiceRegistration.Get <ILogger>().Info("Pins {0} and {1} do not accept each other. Tested {2} media types", info.name, infoOther.name, count);
                FilterGraphTools.FreePinInfo(info);
                FilterGraphTools.FreePinInfo(infoOther);
                return(false);
            }
            finally
            {
                Marshal.FreeCoTaskMem(ptrFetched);
            }
        }
Beispiel #16
0
        public static void FixFlippedVideo(IAMVideoControl videoControl, IPin pPin)
        {
            VideoControlFlags pCapsFlags;

            int hr = videoControl.GetCaps(pPin, out pCapsFlags);

            DsError.ThrowExceptionForHR(hr);

            if ((pCapsFlags & VideoControlFlags.FlipVertical) > 0)
            {
                hr = videoControl.GetMode(pPin, out pCapsFlags);
                DsError.ThrowExceptionForHR(hr);

                hr = videoControl.SetMode(pPin, pCapsFlags & ~VideoControlFlags.FlipVertical);
                DsError.ThrowExceptionForHR(hr);

                PinInfo pinInfo;
                hr = pPin.QueryPinInfo(out pinInfo);
                DsError.ThrowExceptionForHR(hr);

                Trace.WriteLine("Fixing 'FlipVertical' video for pin " + pinInfo.name);
            }

            if ((pCapsFlags & VideoControlFlags.FlipHorizontal) > 0)
            {
                hr = videoControl.GetMode(pPin, out pCapsFlags);
                DsError.ThrowExceptionForHR(hr);

                hr = videoControl.SetMode(pPin, pCapsFlags | VideoControlFlags.FlipHorizontal);
                DsError.ThrowExceptionForHR(hr);

                PinInfo pinInfo;
                hr = pPin.QueryPinInfo(out pinInfo);
                DsError.ThrowExceptionForHR(hr);

                Trace.WriteLine("Fixing 'FlipHorizontal' video for pin " + pinInfo.name);
            }
        }
Beispiel #17
0
        public Pin(PinDirection dir, Filter f, IPin _ipin, int _num) //x,y in pixels inside filter rect
        {
            direction = dir;
            filter    = f;
            num       = _num;
            rect      = new Rectangle(0, 0, 10, 10);
            ipin      = _ipin;
            PinInfo pinfo;

            ipin.QueryPinInfo(out pinfo);
            name     = pinfo.name;
            uniqname = f.Name + "." + pinfo.name;
            DsUtils.FreePinInfo(pinfo);
        }
Beispiel #18
0
        public static void FixFlippedVideo(IAMVideoControl videoControl, IPin pPin)
        {
            VideoControlFlags pCapsFlags;

            int hr = videoControl.GetCaps(pPin, out pCapsFlags);
            DsError.ThrowExceptionForHR(hr);

            if ((pCapsFlags & VideoControlFlags.FlipVertical) > 0)
            {
                hr = videoControl.GetMode(pPin, out pCapsFlags);
                DsError.ThrowExceptionForHR(hr);

                hr = videoControl.SetMode(pPin, pCapsFlags & ~VideoControlFlags.FlipVertical);
                DsError.ThrowExceptionForHR(hr);

                PinInfo pinInfo;
                hr = pPin.QueryPinInfo(out pinInfo);
                DsError.ThrowExceptionForHR(hr);

                Trace.WriteLine("Fixing 'FlipVertical' video for pin " + pinInfo.name);
            }

            if ((pCapsFlags & VideoControlFlags.FlipHorizontal) > 0)
            {
                hr = videoControl.GetMode(pPin, out pCapsFlags);
                DsError.ThrowExceptionForHR(hr);

                hr = videoControl.SetMode(pPin, pCapsFlags | VideoControlFlags.FlipHorizontal);
                DsError.ThrowExceptionForHR(hr);

                PinInfo pinInfo;
                hr = pPin.QueryPinInfo(out pinInfo);
                DsError.ThrowExceptionForHR(hr);

                Trace.WriteLine("Fixing 'FlipHorizontal' video for pin " + pinInfo.name);
            }
        }
Beispiel #19
0
        public static string DumpPinInfo(IPin pin)
        {
            StringBuilder sb = new StringBuilder();
            int           hr;

            sb.AppendLine(">>>>> Pin Info");

            {
                PinInfo pi;
                hr = pin.QueryPinInfo(out pi);
                if (0 == hr)
                {
                    sb.AppendLine(string.Format("PinInfo  name: {0}  direction: {1}", pi.name, pi.dir.ToString()));
                }
                else
                {
                    sb.AppendLine("PinInfo: " + GetErrorText(hr));
                }
            }

            // Pins info
            {
                IEnumMediaTypes enumMediaTypes = null;
                AMMediaType[]   mediaTypes     = new AMMediaType[1] {
                    null
                };

                try
                {
                    hr = pin.EnumMediaTypes(out enumMediaTypes);
                    DsError.ThrowExceptionForHR(hr);

                    while (enumMediaTypes.Next(1, mediaTypes, IntPtr.Zero) == 0)
                    {
                        sb.AppendLine(DumpAMMediaTypeInfo(mediaTypes[0]));
                        DsUtils.FreeAMMediaType(mediaTypes[0]);
                        mediaTypes[0] = null;
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(enumMediaTypes);
                }
            }

            sb.AppendLine("<<<<< Pin Info");

            return(sb.ToString());
        }
        private void logMediaTypes(IPin pin)
        {
            IEnumMediaTypes mediaTypes = null;

            AMMediaType[] mediaType = new AMMediaType[1];

            AMMediaType connectedMediaType = new AMMediaType();

            reply = pin.ConnectionMediaType(connectedMediaType);

            reply = pin.EnumMediaTypes(out mediaTypes);
            if (reply != 0)
            {
                LogMessage("Media types cannot be determined at this time (not connected yet?)");
                return;
            }

            while (mediaTypes.Next(mediaType.Length, mediaType, IntPtr.Zero) == 0)
            {
                foreach (AMMediaType currentMediaType in mediaType)
                {
                    PinInfo pinInfo;
                    reply = pin.QueryPinInfo(out pinInfo);
                    DsError.ThrowExceptionForHR(reply);

                    string majorType = TranslateMediaMajorType(currentMediaType.majorType);
                    string subType   = TranslateMediaSubType(currentMediaType.subType);

                    string connectedComment;

                    if (currentMediaType.majorType == connectedMediaType.majorType && currentMediaType.subType == connectedMediaType.subType)
                    {
                        connectedComment = "** Connected **";
                    }
                    else
                    {
                        connectedComment = string.Empty;
                    }

                    LogMessage("Media type: " +
                               majorType + " ; " +
                               subType + " " +
                               currentMediaType.fixedSizeSamples + " " +
                               currentMediaType.sampleSize + " " +
                               connectedComment);
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// ピン名称の取得
        /// </summary>
        /// <param name="Pin">ピン</param>
        /// <returns>
        ///		ピン名称を返します。
        ///	</returns>
        public static string GetPinName(IPin Pin)
        {
            var info = new PIN_INFO();

            try
            {
                Pin.QueryPinInfo(info);
                return(info.achName);
            }
            finally
            {
                if (info.pFilter != null)
                {
                    Marshal.ReleaseComObject(info.pFilter);
                }
            }
        }
Beispiel #22
0
        private void RenderNetDemux()
        {
            int hr;

            IEnumPins enumPins;

            IPin[] pins = new IPin[1];

            hr = _netDmx.EnumPins(out enumPins);
            DsError.ThrowExceptionForHR(hr);
            try
            {
                while (enumPins.Next(pins.Length, pins, IntPtr.Zero) == 0)
                {
                    try
                    {
                        PinInfo pinInfo;
                        IPin    upstreamPin = pins[0];
                        hr = upstreamPin.QueryPinInfo(out pinInfo);
                        DsError.ThrowExceptionForHR(hr);
                        Console.WriteLine("rendering pin {0}", pinInfo.name);
                        if (pinInfo.dir == PinDirection.Output)
                        {
                            if (pinInfo.name == "Output 01")
                            {
                                //  FilterGraphTools.ConnectFilters(_graphBuilder, _netDmx, pinInfo.name, _textOverlayFilter, "XForm In", true);
                                FilterGraphTools.RenderPin(_graphBuilder, _netDmx, pinInfo.name);
//                                FilterGraphTools.RenderPin(_graphBuilder, _textOverlayFilter, "XForm Out");
                            }
                            else
                            {
                                FilterGraphTools.RenderPin(_graphBuilder, _netDmx, pinInfo.name);
                            }
                        }
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(pins[0]);
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(enumPins);
            }
        }
		/// <summary> Retrieve the friendly name of a connectorType. </summary>
		private string getName(IPin pin)
		{
			string s = "Unknown pin";
			PinInfo pinInfo = new PinInfo();

			// Direction matches, so add pin name to listbox
			int hr = pin.QueryPinInfo(out pinInfo);
			Marshal.ThrowExceptionForHR(hr);
			s = pinInfo.name + "";

			// The pininfo structure contains a reference to an IBaseFilter,
			// so you must release its reference to prevent resource a leak.
			if (pinInfo.filter != null)
				Marshal.ReleaseComObject(pinInfo.filter); 
			pinInfo.filter = null;

			return (s);
		}
Beispiel #24
0
        public DSOutputPin(IPin pin)
            : base()
        {
            // store the IPin
            _pin = pin;

            // we're only using the UI to work with a DirectShow graph
            // so we never pass data, and don't allow pin multi-connect
            AllowMultiConnect = false;
            PassByClone       = PassPinDataAsClone.Never;

            // get the name of the IPin
            PinInfo pi;

            _pin.QueryPinInfo(out pi);
            Name = pi.name;
            DsUtils.FreePinInfo(pi);
        }
        /// <summary>
        /// Disconnects a single Pin.
        /// </summary>
        /// <param name="graphBuilder">IGraphBuilder</param>
        /// <param name="pin">Pin to disconnect</param>
        /// <returns>True if successful</returns>
        bool DisconnectPin(IGraphBuilder graphBuilder, IPin pin)
        {
            IntPtr other_ptr;
            int    hr = pin.ConnectedTo(out other_ptr);
            bool   allDisconnected = true;

            if (hr == 0 && other_ptr != IntPtr.Zero)
            {
                IPin    other = Marshal.GetObjectForIUnknown(other_ptr) as IPin;
                PinInfo info;
                pin.QueryPinInfo(out info);
                ServiceRegistration.Get <ILogger>().Info("Disconnecting pin {0}", info.name);
                FilterGraphTools.FreePinInfo(info);

                other.QueryPinInfo(out info);
                if (!DisconnectAllPins(graphBuilder, info.filter))
                {
                    allDisconnected = false;
                }

                FilterGraphTools.FreePinInfo(info);

                hr = pin.Disconnect();
                if (hr != 0)
                {
                    allDisconnected = false;
                    ServiceRegistration.Get <ILogger>().Error("Error disconnecting: {0:x}", hr);
                }
                hr = other.Disconnect();
                if (hr != 0)
                {
                    allDisconnected = false;
                    ServiceRegistration.Get <ILogger>().Error("Error disconnecting other: {0:x}", hr);
                }
                Marshal.ReleaseComObject(other);
            }
            else
            {
                ServiceRegistration.Get <ILogger>().Info("  Not connected");
            }
            return(allDisconnected);
        }
Beispiel #26
0
 private string getName(IPin pin)
 {
     string str = "Unknown pin";
     PinInfo pInfo = new PinInfo();
     int errorCode = pin.QueryPinInfo(out pInfo);
     if (errorCode == 0)
     {
         str = pInfo.name ?? "";
     }
     else
     {
         Marshal.ThrowExceptionForHR(errorCode);
     }
     if (pInfo.filter != null)
     {
         Marshal.ReleaseComObject(pInfo.filter);
     }
     pInfo.filter = null;
     return str;
 }
Beispiel #27
0
        /// <summary>
        /// Helper method to obtain a little information about who
        /// we just connected to.
        /// </summary>
        public void ResolveConnectedFilter()
        {
            if (_ConnectedPin == null)
            {
                return;
            }

            PinInfo pi;

            _ConnectedPin.QueryPinInfo(out pi);
            FilterInfo fi;

            pi.filter.QueryFilterInfo(out fi);
            _ConnectedFilter     = pi.filter;
            _ConnectedFilterName = fi.achName;

            pi.filter.GetClassID(out _ConnectedFilterClassID);

            Debug.WriteLine(_ConnectedFilterClassID + " " + _ConnectedFilterName, "ResolveConnectedFilter");
        }
Beispiel #28
0
        protected void removeDownstream(IBaseFilter filter, bool removeFirstFilter)
        {
            IEnumPins pins;
            int       num = filter.EnumPins(out pins);

            pins.Reset();
            if ((num == 0) && (pins != null))
            {
                IPin[] ppPins = new IPin[1];
                do
                {
                    int num2;
                    num = pins.Next(1, ppPins, out num2);
                    if ((num == 0) && (ppPins[0] != null))
                    {
                        IPin ppPin = null;
                        ppPins[0].ConnectedTo(out ppPin);
                        if (ppPin != null)
                        {
                            PinInfo pInfo = new PinInfo();
                            num = ppPin.QueryPinInfo(out pInfo);
                            if ((num == 0) && (pInfo.dir == PinDirection.Input))
                            {
                                this.removeDownstream(pInfo.filter, true);
                                this.graphBuilder.Disconnect(ppPin);
                                this.graphBuilder.Disconnect(ppPins[0]);
                                if ((pInfo.filter != this.videoCompressorFilter) && (pInfo.filter != this.audioCompressorFilter))
                                {
                                    this.graphBuilder.RemoveFilter(pInfo.filter);
                                }
                            }
                            Marshal.ReleaseComObject(pInfo.filter);
                            Marshal.ReleaseComObject(ppPin);
                        }
                        Marshal.ReleaseComObject(ppPins[0]);
                    }
                }while (num == 0);
                Marshal.ReleaseComObject(pins);
                pins = null;
            }
        }
Beispiel #29
0
        // Token: 0x06000193 RID: 403 RVA: 0x00011B14 File Offset: 0x0000FD14
        protected void removeDownstream(IBaseFilter filter, bool removeFirstFilter)
        {
            IEnumPins enumPins;
            int       num = filter.EnumPins(out enumPins);

            enumPins.Reset();
            if (num == 0 && enumPins != null)
            {
                IPin[] array = new IPin[1];
                do
                {
                    int num2;
                    num = enumPins.Next(1, array, out num2);
                    if (num == 0 && array[0] != null)
                    {
                        IPin pin = null;
                        array[0].ConnectedTo(out pin);
                        if (pin != null)
                        {
                            PinInfo pinInfo = default(PinInfo);
                            num = pin.QueryPinInfo(out pinInfo);
                            if (num == 0 && pinInfo.dir == PinDirection.Input)
                            {
                                this.removeDownstream(pinInfo.filter, true);
                                this.graphBuilder.Disconnect(pin);
                                this.graphBuilder.Disconnect(array[0]);
                                if (pinInfo.filter == this.videoCompressorFilter && pinInfo.filter == this.audioCompressorFilter)
                                {
                                    this.graphBuilder.RemoveFilter(pinInfo.filter);
                                }
                            }
                            Marshal.ReleaseComObject(pinInfo.filter);
                            Marshal.ReleaseComObject(pin);
                        }
                        Marshal.ReleaseComObject(array[0]);
                    }
                }while (num == 0);
                Marshal.ReleaseComObject(enumPins);
                enumPins = null;
            }
        }
Beispiel #30
0
        private string getName(IPin pin)
        {
            string  str       = "Unknown pin";
            PinInfo pInfo     = new PinInfo();
            int     errorCode = pin.QueryPinInfo(out pInfo);

            if (errorCode == 0)
            {
                str = pInfo.name ?? "";
            }
            else
            {
                Marshal.ThrowExceptionForHR(errorCode);
            }
            if (pInfo.filter != null)
            {
                Marshal.ReleaseComObject(pInfo.filter);
            }
            pInfo.filter = null;
            return(str);
        }
Beispiel #31
0
        protected IPin GetUnconnectedPin(IBaseFilter filter, PinDirection direction)
        {
            IPin      destPin = null;
            IEnumPins iEnum;
            var       pins = new IPin[1];

            var hr = filter.EnumPins(out iEnum);

            Marshal.ThrowExceptionForHR(hr);

            var fetched = Marshal.AllocCoTaskMem(4);

            hr = iEnum.Next(1, pins, fetched);
            Marshal.ThrowExceptionForHR(hr);

            while (Marshal.ReadInt32(fetched) == 1)
            {
                PinDirection pinDir;
                IPin         pPin;
                destPin = pins[0];

                hr = destPin.QueryDirection(out pinDir);
                Marshal.ThrowExceptionForHR(hr);

                PinInfo info;
                destPin.QueryPinInfo(out info);
                //var name = info.name;
                destPin.ConnectedTo(out pPin);

                if (pPin == null && pinDir == direction)
                {
                    break;
                }

                hr = iEnum.Next(1, pins, fetched);
                Marshal.ThrowExceptionForHR(hr);
            }
            Marshal.FreeCoTaskMem(fetched);
            return(destPin);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GenPixBDA"/> class.
        /// </summary>
        /// <param name="tunerFilter">The tuner filter.</param>
        public GenPixBDA(IBaseFilter tunerFilter)
        {
            //check the filter name
            FilterInfo tInfo;

            tunerFilter.QueryFilterInfo(out tInfo);
            Log.Log.Debug("GenPix tuner filter name: {0}", tInfo.achName);
            //check the pin name
            IPin    pin = DsFindPin.ByDirection(tunerFilter, PinDirection.Output, 0);
            PinInfo pInfo;

            pin.QueryPinInfo(out pInfo);
            Log.Log.Debug("GenPix tuner filter pin name: {0}", pInfo.name);
            if (pin != null)
            {
                _propertySet = pin as IKsPropertySet;
                if (_propertySet != null)
                {
                    KSPropertySupport supported;
                    _propertySet.QuerySupported(BdaTunerExtentionProperties, (int)BdaTunerExtension.KSPROPERTY_BDA_DISEQC,
                                                out supported);
                    if ((supported & KSPropertySupport.Set) != 0)
                    {
                        Log.Log.Debug("GenPix BDA: DVB-S card found!");
                        _isGenPix        = true;
                        _ptrDiseqc       = Marshal.AllocCoTaskMem(1024);
                        _ptrTempInstance = Marshal.AllocCoTaskMem(1024);
                    }
                    else
                    {
                        Log.Log.Debug("GenPix BDA: DVB-S card NOT found!");
                        _isGenPix = false;
                    }
                }
            }
            else
            {
                Log.Log.Info("GenPix BDA: tuner pin not found!");
            }
        }
        /// <summary>
        /// QueryConnect checks if two Pins can be connected.
        /// </summary>
        /// <param name="pin">Pin 1</param>
        /// <param name="other">Pin 2</param>
        /// <returns>True if they accept connection</returns>
        static bool QueryConnect(IPin pin, IPin other)
        {
            var pin1     = new DSPin(pin);
            var pinOther = new DSPin(other);

            foreach (var mediaType in pin1.MediaTypes)
            {
                if (pinOther.IsAccepted(mediaType))
                {
                    return(true);
                }
            }

            PinInfo info;
            PinInfo infoOther;

            pin.QueryPinInfo(out info);
            other.QueryPinInfo(out infoOther);
            ServiceRegistration.Get <ILogger>().Info("Pins {0} and {1} do not accept each other. Tested {2} media types", info.name, infoOther.name, pin1.MediaTypes.Count);
            FilterGraphTools.FreePinInfo(info);
            FilterGraphTools.FreePinInfo(infoOther);
            return(false);
        }
Beispiel #34
0
        /// <summary>
        /// Constructs a DetailPinInfo for the specified pin
        /// </summary>
        /// <param name="pin">IPin interface to get info about</param>
        public DetailPinInfo(IPin pin)
        {
            PinInfo pinInfo = new PinInfo();
            int     hr      = pin.QueryPinInfo(out pinInfo);

            DsError.ThrowExceptionForHR(hr);

            IEnumMediaTypes enumMediaTypes;

            hr = pin.EnumMediaTypes(out enumMediaTypes);
            DsError.ThrowExceptionForHR(hr);

            AMMediaType[] curMediaType = new AMMediaType[1];

            IntPtr fetched2 = Marshal.AllocCoTaskMem(4);

            try
            {
                if (enumMediaTypes.Next(1, curMediaType, fetched2) == 0)
                {
                    if (Marshal.ReadInt32(fetched2) != 1)
                    {
                        throw new Exception("Cannot enumerate media types for pin!");
                    }
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(fetched2);
            }

            this.Pin  = pin;
            this.Info = pinInfo;
            this.Type = curMediaType[0];

            BaseDSGraph.Release(enumMediaTypes);
        }
    /// <summary>
    /// Logs the pin info.
    /// </summary>
    /// <param name="pin">The pin.</param>
    /// <returns></returns>
    public static string LogPinInfo(IPin pin)
    {
      if (pin == null)
        return " pin==null ";
      PinInfo pinInfo;
      IPin connectedToPin;
      if (pin.ConnectedTo(out connectedToPin) != 0)
        connectedToPin = null;

      bool connected = connectedToPin != null;
      if (connected)
        Release.ComObject(connectedToPin);

      int hr = pin.QueryPinInfo(out pinInfo);
      if (hr == 0)
      {
        if (pinInfo.filter != null)
          Release.ComObject(pinInfo.filter);
      }
      return String.Format("name:{0} [{3}/{4}] Direction:{1} Connected:{2}", pinInfo.name, pinInfo.dir, connected,
                           getRefCount(pin), getRefCountCOM(pin));
    }
 /// <summary>
 /// Gets the pin name.
 /// </summary>
 /// <param name="pin">The pin.</param>
 /// <returns>PinName</returns>
 public static string GetPinName(IPin pin)
 {
   if (pin == null)
     return "";
   PinInfo pinInfo;
   int hr = pin.QueryPinInfo(out pinInfo);
   if (hr == 0)
   {
     if (pinInfo.filter != null)
       Release.ComObject(pinInfo.filter);
   }
   return String.Format(pinInfo.name);
 }
Beispiel #37
0
        private static IPin PrintInfoAndReturnPin(IBaseFilter filter, IPin pin, PinDirection direction, Guid mediaType, Guid pinCategory, string debugInfo)
        {
            if (Settings.Default.VideoGraphDebugMode)
            {
                FilterInfo fInfo;
                int hr = filter.QueryFilterInfo(out fInfo);
                DsError.ThrowExceptionForHR(hr);

                string vendorInfo = null;
                hr = filter.QueryVendorInfo(out vendorInfo);
                if ((uint)hr != 0x80004001) /* Not Implemented*/
                    DsError.ThrowExceptionForHR(hr);

                string mediaTypeStr = "N/A";
                if (mediaType == MediaType.AnalogVideo)
                    mediaTypeStr = "AnalogVideo";
                else if (mediaType == MediaType.Video)
                    mediaTypeStr = "Video";
                else if (mediaType == MediaType.Null)
                    mediaTypeStr = "Null";

                string categoryStr = "N/A";
                if (pinCategory == PinCategory.Capture)
                    categoryStr = "Capture";
                else if (pinCategory == PinCategory.Preview)
                    categoryStr = "Preview";
                else if (pinCategory == PinCategory.AnalogVideoIn)
                    categoryStr = "AnalogVideoIn";
                else if (pinCategory == PinCategory.CC)
                    categoryStr = "CC";

                PinInfo pinInfo;
                hr = pin.QueryPinInfo(out pinInfo);
                DsError.ThrowExceptionForHR(hr);

                Trace.WriteLine(string.Format("Using {0} pin '{1}' of media type '{2}' and category '{3}' {4} ({5}::{6})",
                    direction == PinDirection.Input ? "input" : "output",
                    pinInfo.name,
                    mediaTypeStr,
                    categoryStr,
                    debugInfo,
                    vendorInfo, fInfo.achName));
            }

            return pin;
        }
Beispiel #38
0
    protected void RebuildMediaType(IPin pPin)
    {
      if (pPin != null)
      {
        //Detection if the Video Stream is VC-1 on output pin of the splitter
        IEnumMediaTypes enumMediaTypesAudioVideo;
        int hr = pPin.EnumMediaTypes(out enumMediaTypesAudioVideo);
        AMMediaType[] mediaTypes = new AMMediaType[1];
        int typesFetched;
        PinInfo pinInfo;
        pPin.QueryPinInfo(out pinInfo);

        while (0 == enumMediaTypesAudioVideo.Next(1, mediaTypes, out typesFetched))
        {
          if (typesFetched == 0)
            break;

          if (mediaTypes[0].majorType == MediaType.Video && !pinInfo.name.ToLowerInvariant().Contains("sub"))
          {
            if (mediaTypes[0].subType == MediaSubType.VC1)
            {
              Log.Info("VideoPlayer9: found VC-1 video out pin");
              vc1Codec = true;
            }
            if (mediaTypes[0].subType == MediaSubType.H264 || mediaTypes[0].subType == MediaSubType.AVC1)
            {
              Log.Info("VideoPlayer9: found H264 video out pin");
              h264Codec = true;
            }
            if (mediaTypes[0].subType == MediaSubType.XVID || mediaTypes[0].subType == MediaSubType.xvid ||
                mediaTypes[0].subType == MediaSubType.dx50 || mediaTypes[0].subType == MediaSubType.DX50 ||
                mediaTypes[0].subType == MediaSubType.divx || mediaTypes[0].subType == MediaSubType.DIVX)
            {
              Log.Info("VideoPlayer9: found XVID video out pin");
              xvidCodec = true;
            }
            MediatypeVideo = true;
          }
          else if (mediaTypes[0].majorType == MediaType.Audio)
          {
            //Detection if the Audio Stream is AAC on output pin of the splitter
            if (mediaTypes[0].subType == MediaSubType.LATMAAC || mediaTypes[0].subType == MediaSubType.AAC)
            {
              Log.Info("VideoPlayer9: found AAC Audio out pin");
              aacCodec = true;
            }
            if (mediaTypes[0].subType == MediaSubType.LATMAACLAF)
            {
              Log.Info("VideoPlayer9: found AAC LAVF Audio out pin");
              aacCodecLav = true;
            }
            MediatypeAudio = true;
          }
          else if (mediaTypes[0].majorType == MediaType.Subtitle)
          {
            MediatypeSubtitle = true;
          }
        }
        DirectShowUtil.ReleaseComObject(enumMediaTypesAudioVideo);
        enumMediaTypesAudioVideo = null;
      }
    }
 public static bool QueryConnect(IPin pin, IPin other)
 {
   IEnumMediaTypes enumTypes;
   int hr = pin.EnumMediaTypes(out enumTypes);
   if (hr != 0 || enumTypes == null)
   {
     return false;
   }
   int count = 0;
   for (;;)
   {
     AMMediaType[] types = new AMMediaType[1];
     int fetched;
     hr = enumTypes.Next(1, types, out fetched);
     if (hr != 0 || fetched == 0)
     {
       break;
     }
     count++;
     if (other.QueryAccept(types[0]) == 0)
     {
       return true;
     }
   }
   PinInfo info;
   PinInfo infoOther;
   pin.QueryPinInfo(out info);
   DsUtils.FreePinInfo(info);
   other.QueryPinInfo(out infoOther);
   DsUtils.FreePinInfo(infoOther);
   Log.Info("Pins {0} and {1} do not accept each other. Tested {2} media types", info.name, infoOther.name, count);
   return false;
 }
        public int Connect(IPin pReceivePin, AMMediaType pmt)
        {
            Monitor.Enter(this);
            int hr = S_OK;
            pin = null;
            pintype = null;
            allocator = null;
            string id = "Unnamed pin";
            pReceivePin.QueryId(out id);
            PinInfo pi = new PinInfo();
            hr = pReceivePin.QueryPinInfo(out pi);
            if (hr == S_OK)
            {
                FilterInfo fi = new FilterInfo();
                hr = pi.filter.QueryFilterInfo(out fi);
                if (hr == S_OK)
                {
                    id += (" (" + fi.achName);
                }
                Guid guid;
                hr = pi.filter.GetClassID(out guid);
                if (hr == S_OK)
                {
                    id += (", " + guid.ToString());
                }
                id += ")";
            }
            try
            {
                AMMediaType amt = null;
                if (pmt != null)
                {
                    amt = pmt;
                }
                else
            #if false
                {
                    IEnumMediaTypes ie;
                    hr = pReceivePin.EnumMediaTypes(out ie);
                    int fetched;
                    int alloc = Marshal.SizeOf(typeof(AMMediaType));
                    IntPtr mtypePtr = Marshal.AllocCoTaskMem(alloc);
                    while (ie.Next(1, mtypePtr, out fetched) == S_OK)
                    {
                        amt = new AMMediaType();
                        Marshal.PtrToStructure(mtypePtr, amt);
                        hr = pReceivePin.QueryAccept(amt);
                        if (hr == S_OK)
                        {
                            break;
                        }
                        DsUtils.FreeAMMediaType(amt);
                        amt = null;
                    }
                    if (fetched == 0)
                    {
                        amt = null;
                    }
                    Marshal.FreeCoTaskMem(mtypePtr);
                }
                if (amt == null)
            #endif
                {
                    amt = mediatype;
                }
                hr = pReceivePin.QueryAccept(amt);
                if (hr == S_FALSE)
                {
                    log.InfoFormat("No media type for pin '{0}'", id);
                    Monitor.Exit(this);
                    return VFW_E_NO_ACCEPTABLE_TYPES;
                }

                hr = pReceivePin.ReceiveConnection(this, amt);
                if (hr == VFW_E_TYPE_NOT_ACCEPTED)
                {
                    log.InfoFormat("No connection to pin '{0}'", id);
                    Monitor.Exit(this);
                    return VFW_E_NO_ACCEPTABLE_TYPES;
                }
                DsError.ThrowExceptionForHR(hr);

                pin = pReceivePin;
                pintype = amt;
            }
            catch (Exception e)
            {
                LogUtil.ExceptionLog.ErrorFormat("Caught exception in connect ({0}): {1}{2}", id, e.Message, e.StackTrace);
                pin = null;
                pintype = null;
                allocator = null;
                Monitor.Exit(this);
                return VFW_E_NO_TRANSPORT;
            }
            Monitor.Exit(this);
            log.InfoFormat("Connected to pin '{0}'", id);
            return S_OK;
        }
    public static bool TryConnect(IGraphBuilder graphBuilder, string filtername, IPin outputPin, bool TryNewFilters)
    {
      int hr;
      Log.Info("----------------TryConnect-------------");
      PinInfo outputInfo;
      outputPin.QueryPinInfo(out outputInfo);
      DsUtils.FreePinInfo(outputInfo);
      //ListMediaTypes(outputPin);
      ArrayList currentfilters = GetFilters(graphBuilder);
      foreach (IBaseFilter filter in currentfilters)
      {
        if (TryConnect(graphBuilder, filtername, outputPin, filter))
        {
          ReleaseFilters(currentfilters);
          return true;
        }
      }
      ReleaseFilters(currentfilters);
      //not found, try new filter from registry
      if (TryNewFilters)
      {
        Log.Info("No preloaded filter could be connected. Trying to load new one from registry");
        IEnumMediaTypes enumTypes;
        hr = outputPin.EnumMediaTypes(out enumTypes);
        if (hr != 0)
        {
          Log.Debug("Failed: {0:x}", hr);
          return false;
        }
        Log.Debug("Got enum");
        ArrayList major = new ArrayList();
        ArrayList sub = new ArrayList();

        Log.Debug("Getting corresponding filters");
        for (;;)
        {
          AMMediaType[] mediaTypes = new AMMediaType[1];
          int typesFetched;
          hr = enumTypes.Next(1, mediaTypes, out typesFetched);
          if (hr != 0 || typesFetched == 0)
          {
            break;
          }
          major.Add(mediaTypes[0].majorType);
          sub.Add(mediaTypes[0].subType);
        }
        ReleaseComObject(enumTypes);
        Log.Debug("Found {0} media types", major.Count);
        Guid[] majorTypes = (Guid[])major.ToArray(typeof (Guid));
        Guid[] subTypes = (Guid[])sub.ToArray(typeof (Guid));
        Log.Debug("Loading filters");
        ArrayList filters = FilterHelper.GetFilters(majorTypes, subTypes, (Merit)0x00400000);
        Log.Debug("Loaded {0} filters", filters.Count);
        foreach (string name in filters)
        {
          if (!CheckFilterIsLoaded(graphBuilder, name))
          {
            Log.Debug("Loading filter: {0}", name);
            IBaseFilter f = AddFilterToGraph(graphBuilder, name);
            if (f != null)
            {
              if (TryConnect(graphBuilder, filtername, outputPin, f))
              {
                ReleaseComObject(f);
                return true;
              }
              else
              {
                graphBuilder.RemoveFilter(f);
                ReleaseComObject(f);
              }
            }
          }
          else
          {
            Log.Debug("Ignoring filter {0}. Already in graph.", name);
          }
        }
      }
      Log.Debug("TryConnect failed.");
      return outputInfo.name.StartsWith("~");
    }
        public static bool DisconnectPin(IGraphBuilder graphBuilder, IPin pin)
        {
            IPin other;
            int hr = pin.ConnectedTo(out other);
            bool allDisconnected = true;
            PinInfo info;
            pin.QueryPinInfo(out info);
            DsUtils.FreePinInfo(info);

            if (hr == 0 && other != null)
            {
                other.QueryPinInfo(out info);
                if (!DisconnectAllPins(graphBuilder, info.filter))
                {
                    allDisconnected = false;
                }
                hr = pin.Disconnect();
                if (hr != 0)
                {
                    allDisconnected = false;

                }
                hr = other.Disconnect();
                if (hr != 0)
                {
                    allDisconnected = false;

                }
                DsUtils.FreePinInfo(info);
                Marshal.ReleaseComObject(other);
            }
            else
            {

            }
            return allDisconnected;
        }
Beispiel #43
0
    /// <summary>
    /// QueryConnect checks if two Pins can be connected.
    /// </summary>
    /// <param name="pin">Pin 1</param>
    /// <param name="other">Pin 2</param>
    /// <returns>True if they accept connection</returns>
    static bool QueryConnect(IPin pin, IPin other)
    {
      var pin1 = new DSPin(pin);
      var pinOther = new DSPin(other);

      foreach (var mediaType in pin1.MediaTypes)
      {
        if (pinOther.IsAccepted(mediaType))
          return true;
      }

      PinInfo info;
      PinInfo infoOther;
      pin.QueryPinInfo(out info);
      other.QueryPinInfo(out infoOther);
      ServiceRegistration.Get<ILogger>().Info("Pins {0} and {1} do not accept each other. Tested {2} media types", info.name, infoOther.name, pin1.MediaTypes.Count);
      FilterGraphTools.FreePinInfo(info);
      FilterGraphTools.FreePinInfo(infoOther);
      return false;
    }
Beispiel #44
0
    /// <summary>
    /// Disconnects a single Pin.
    /// </summary>
    /// <param name="graphBuilder">IGraphBuilder</param>
    /// <param name="pin">Pin to disconnect</param>
    /// <returns>True if successful</returns>
    bool DisconnectPin(IGraphBuilder graphBuilder, IPin pin)
    {
      IntPtr other_ptr;
      int hr = pin.ConnectedTo(out other_ptr);
      bool allDisconnected = true;
      if (hr == 0 && other_ptr != IntPtr.Zero)
      {
        IPin other = Marshal.GetObjectForIUnknown(other_ptr) as IPin;
        PinInfo info;
        pin.QueryPinInfo(out info);
        ServiceRegistration.Get<ILogger>().Info("Disconnecting pin {0}", info.name);
        FilterGraphTools.FreePinInfo(info);

        other.QueryPinInfo(out info);
        if (!DisconnectAllPins(graphBuilder, info.filter))
          allDisconnected = false;

        FilterGraphTools.FreePinInfo(info);

        hr = pin.Disconnect();
        if (hr != 0)
        {
          allDisconnected = false;
          ServiceRegistration.Get<ILogger>().Error("Error disconnecting: {0:x}", hr);
        }
        hr = other.Disconnect();
        if (hr != 0)
        {
          allDisconnected = false;
          ServiceRegistration.Get<ILogger>().Error("Error disconnecting other: {0:x}", hr);
        }
        Marshal.ReleaseComObject(other);
      }
      else
      {
        ServiceRegistration.Get<ILogger>().Info("  Not connected");
      }
      return allDisconnected;
    }
        public static IBaseFilter GetFilterFromPin(IPin pin)
        {
            PinInfo pi = default(PinInfo);
            IBaseFilter filter;
            int hr;

            //try
            //{
            hr = pin.QueryPinInfo(out pi);
            DsError.ThrowExceptionForHR(hr);

            filter = pi.filter;
            return filter;
            //}
            //finally
            //{
            //    DsUtils.FreePinInfo(pi);
            //}
        }
Beispiel #46
0
 public static string Name(IPin pin)
 {
     _PinInfo pi;
     pin.QueryPinInfo(out pi);
     return pi.achName;
 }
    /// <summary>
    /// QueryConnect checks if two Pins can be connected.
    /// </summary>
    /// <param name="pin">Pin 1</param>
    /// <param name="other">Pin 2</param>
    /// <returns>True if they accept connection</returns>
    static bool QueryConnect(IPin pin, IPin other)
    {
      IEnumMediaTypes enumTypes;
      int hr = pin.EnumMediaTypes(out enumTypes);
      if (hr != 0 || enumTypes == null)
        return false;

      int count = 0;
      IntPtr ptrFetched = Marshal.AllocCoTaskMem(4);
      try
      {
        for (; ; )
        {
          AMMediaType[] types = new AMMediaType[1];
          hr = enumTypes.Next(1, types, ptrFetched);
          if (hr != 0 || Marshal.ReadInt32(ptrFetched) == 0)
            break;

          count++;
          try
          {
            if (other.QueryAccept(types[0]) == 0)
              return true;
          }
          finally
          {
            FilterGraphTools.FreeAMMediaType(types[0]);
          }
        }
        PinInfo info;
        PinInfo infoOther;
        pin.QueryPinInfo(out info);
        other.QueryPinInfo(out infoOther);
        ServiceRegistration.Get<ILogger>().Info("Pins {0} and {1} do not accept each other. Tested {2} media types", info.name, infoOther.name, count);
        FilterGraphTools.FreePinInfo(info);
        FilterGraphTools.FreePinInfo(infoOther);
        return false;
      }
      finally
      {
        Marshal.FreeCoTaskMem(ptrFetched);
      }
    }
Beispiel #48
0
        private void logMediaTypes(IPin pin)
        {
            IEnumMediaTypes mediaTypes = null;
            AMMediaType[] mediaType = new AMMediaType[1];

            AMMediaType connectedMediaType = new AMMediaType();
            reply = pin.ConnectionMediaType(connectedMediaType);

            reply = pin.EnumMediaTypes(out mediaTypes);
            if (reply != 0)
            {
                LogMessage("Media types cannot be determined at this time (not connected yet?)");
                return;
            }

            while (mediaTypes.Next(mediaType.Length, mediaType, IntPtr.Zero) == 0)
            {
                foreach (AMMediaType currentMediaType in mediaType)
                {
                    PinInfo pinInfo;
                    reply = pin.QueryPinInfo(out pinInfo);
                    DsError.ThrowExceptionForHR(reply);

                    string majorType = TranslateMediaMajorType(currentMediaType.majorType);
                    string subType = TranslateMediaSubType(currentMediaType.subType);

                    string connectedComment;

                    if (currentMediaType.majorType == connectedMediaType.majorType && currentMediaType.subType == connectedMediaType.subType)
                        connectedComment = "** Connected **";
                    else
                        connectedComment = string.Empty;

                    LogMessage("Media type: " +
                        majorType + " ; " +
                        subType + " " +
                        currentMediaType.fixedSizeSamples + " " +
                        currentMediaType.sampleSize + " " +
                        connectedComment);
                }
            }
        }
 public static bool DisconnectPin(IGraphBuilder graphBuilder, IPin pin)
 {
   IPin other;
   int hr = pin.ConnectedTo(out other);
   bool allDisconnected = true;
   PinInfo info;
   pin.QueryPinInfo(out info);
   DsUtils.FreePinInfo(info);
   Log.Info("Disconnecting pin {0}", info.name);
   if (hr == 0 && other != null)
   {
     other.QueryPinInfo(out info);
     if (!DisconnectAllPins(graphBuilder, info.filter))
     {
       allDisconnected = false;
     }
     hr = pin.Disconnect();
     if (hr != 0)
     {
       allDisconnected = false;
       Log.Error("Error disconnecting: {0:x}", hr);
     }
     hr = other.Disconnect();
     if (hr != 0)
     {
       allDisconnected = false;
       Log.Error("Error disconnecting other: {0:x}", hr);
     }
     DsUtils.FreePinInfo(info);
     ReleaseComObject(other);
   }
   else
   {
     Log.Info("  Not connected");
   }
   return allDisconnected;
 }
    private static bool TryConnect(IGraphBuilder graphBuilder, string filtername, IPin outputPin, IBaseFilter to)
    {
      bool ret = false;
      int hr;
      FilterInfo info;
      PinInfo outputInfo;

      to.QueryFilterInfo(out info);
      ReleaseComObject(info.pGraph);

      outputPin.QueryPinInfo(out outputInfo);
      DsUtils.FreePinInfo(outputInfo);

      if (info.achName.Equals(filtername))
      {
        return false; //do not connect to self
      }
      Log.Debug("Testing filter: {0}", info.achName);

      IEnumPins enumPins;
      IPin[] pins = new IPin[1];
      to.EnumPins(out enumPins);
      do
      {
        int pinsFetched;
        hr = enumPins.Next(1, pins, out pinsFetched);
        if (hr != 0 || pinsFetched == 0)
        {
          break;
        }
        PinDirection direction;
        pins[0].QueryDirection(out direction);
        if (direction == PinDirection.Input && !HasConnection(pins[0])) // && TestMediaTypes(outputPin, pins[0]))
        {
          PinInfo pinInfo;
          pins[0].QueryPinInfo(out pinInfo);
          DsUtils.FreePinInfo(pinInfo);
          Log.Debug("Testing compatibility to {0}",
                    pinInfo.name);
          //ListMediaTypes(pins[0]);
          //hr =  outputPin.Connect(pins[0], null);
          hr = graphBuilder.ConnectDirect(outputPin, pins[0], null);
          if (hr == 0)
          {
            Log.Debug("Connection succeeded");
            if (RenderOutputPins(graphBuilder, to))
            {
              Log.Info("Successfully rendered pin {0}:{1} to {2}:{3}.",
                       filtername, outputInfo.name, info.achName, pinInfo.name);
              ret = true;
              ReleaseComObject(pins[0]);
              break;
            }
            else
            {
              Log.Debug("Rendering got stuck. Trying next filter, and disconnecting {0}!", outputInfo.name);
              outputPin.Disconnect();
              pins[0].Disconnect();
            }
          }
          else
          {
            Log.Debug("Could not connect, filters are not compatible: {0:x}", hr);
          }
        }
        ReleaseComObject(pins[0]);
      } while (true);
      ReleaseComObject(enumPins);
      if (!ret)
      {
        Log.Debug("Dead end. Could not successfully connect pin {0} to filter {1}!", outputInfo.name, info.achName);
      }
      return ret;
    }