Ejemplo n.º 1
0
        public void TestQueryId()
        {
            IPin   testPin = GetSmartTeeInputPin();
            string idStr;
            int    hr = testPin.QueryId(out idStr);

            Marshal.ThrowExceptionForHR(hr);

            Assert.IsNotNull(idStr);
        }
Ejemplo n.º 2
0
        public static void SetFilterFormat(AMMediaType streamFormat, IBaseFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            int hr;

            IEnumPins pinsEnum = null;

            try
            {
                hr = filter.EnumPins(out pinsEnum);
                DsError.ThrowExceptionForHR(hr);

                if (pinsEnum == null)
                {
                    throw new SplicerException(Resources.ErrorPinsEnumeratorIsNull);
                }

                var pins = new IPin[1];

                while (true)
                {
                    try
                    {
                        int    fetched   = 0;
                        IntPtr pcFetched = Marshal.AllocCoTaskMem(4);
                        try
                        {
                            hr = pinsEnum.Next(pins.Length, pins, pcFetched);
                            DsError.ThrowExceptionForHR(hr);
                            fetched = Marshal.ReadInt32(pcFetched);
                        }
                        finally
                        {
                            Marshal.FreeCoTaskMem(pcFetched);
                        }

                        if (fetched == 1)
                        {
                            // we have something
                            IPin pin = pins[0];

                            string queryId;
                            hr = pin.QueryId(out queryId);
                            DsError.ThrowExceptionForHR(hr);

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

                            if (pinInfo.dir != PinDirection.Output)
                            {
                                continue;
                            }
                            var streamConfig = (IAMStreamConfig)pin;

                            hr = streamConfig.SetFormat(streamFormat);
                            DsError.ThrowExceptionForHR(hr);
                        }
                        else
                        {
                            break;
                        }
                    }
                    finally
                    {
                        if (pins[0] != null)
                        {
                            Marshal.ReleaseComObject(pins[0]);
                        }
                        pins[0] = null;
                    }
                }
            }
            finally
            {
                if (pinsEnum != null)
                {
                    Marshal.ReleaseComObject(pinsEnum);
                }
            }
        }
Ejemplo n.º 3
0
        public static IList <PinQueryInfo> EnumeratePins(IBaseFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }
            int hr = 0;

            var pinsInfo = new List <PinQueryInfo>();

            IEnumPins pinsEnum = null;

            try
            {
                hr = filter.EnumPins(out pinsEnum);
                DsError.ThrowExceptionForHR(hr);

                if (pinsEnum == null)
                {
                    throw new InvalidOperationException("pinsEnum is null");
                }

                var pins = new IPin[1];

                while (true)
                {
                    try
                    {
                        int fetched = 0;

                        IntPtr pcFetched = Marshal.AllocCoTaskMem(4);

                        try
                        {
                            hr = pinsEnum.Next(pins.Length, pins, pcFetched);
                            DsError.ThrowExceptionForHR(hr);
                            fetched = Marshal.ReadInt32(pcFetched);
                        }
                        finally
                        {
                            Marshal.FreeCoTaskMem(pcFetched);
                        }

                        if (fetched == 1)
                        {
                            // we have something
                            IPin pin = pins[0];

                            string queryId;
                            hr = pin.QueryId(out queryId);
                            DsError.ThrowExceptionForHR(hr);

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

                            pinsInfo.Add(new PinQueryInfo(pinInfo.dir, pinInfo.name, queryId));
                        }
                        else
                        {
                            break;
                        }
                    }
                    finally
                    {
                        if (pins[0] != null)
                        {
                            Marshal.ReleaseComObject(pins[0]);
                        }
                        pins[0] = null;
                    }
                }
            }
            finally
            {
                if (pinsEnum != null)
                {
                    Marshal.ReleaseComObject(pinsEnum);
                }
            }

            return(pinsInfo);
        }
Ejemplo n.º 4
0
        public static IEnumerator <WavFormatInfo> EnumerateFormatsForDirection(IBaseFilter filter, PinDirection direction)
        {
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }
            int hr;

            IEnumPins pinsEnum = null;

            try
            {
                hr = filter.EnumPins(out pinsEnum);
                DsError.ThrowExceptionForHR(hr);

                if (pinsEnum == null)
                {
                    throw new InvalidOperationException("pinsEnum is null");
                }

                IPin[] pins = new IPin[1];

                while (true)
                {
                    try
                    {
                        int pcFetched;
                        hr = pinsEnum.Next(pins.Length, pins, out pcFetched);
                        DsError.ThrowExceptionForHR(hr);

                        if (pcFetched == 1)
                        {
                            // we have something
                            IPin pin = pins[0];

                            string queryId;
                            hr = pin.QueryId(out queryId);
                            DsError.ThrowExceptionForHR(hr);

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

                            if (pinInfo.dir != direction)
                            {
                                continue;
                            }

                            IEnumMediaTypes mediaTypesEnum = null;

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

                                AMMediaType[] mediaTypes = new AMMediaType[1];

                                int mtFetched;

                                while (true)
                                {
                                    hr = mediaTypesEnum.Next(1, mediaTypes, out mtFetched);
                                    DsError.ThrowExceptionForHR(hr);
                                    if (mtFetched == 1)
                                    {
                                        if (mediaTypes[0].formatType == FormatType.WaveEx)
                                        {
                                            yield return(new WavFormatInfo(mediaTypes[0]));
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            finally
                            {
                                if (mediaTypesEnum != null)
                                {
                                    Marshal.ReleaseComObject(mediaTypesEnum);
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    finally
                    {
                        if (pins[0] != null)
                        {
                            Marshal.ReleaseComObject(pins[0]);
                        }
                        pins[0] = null;
                    }
                }
            }
            finally
            {
                if (pinsEnum != null)
                {
                    Marshal.ReleaseComObject(pinsEnum);
                }
            }
        }
        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;
        }