int IPin.Connect(IPin pReceivePin, AMMediaType pmt)
            {
                IEnumMediaTypes emt;

                if (connectedPin != null)
                {
                    return(DsResults.E_AlreadyConnected);
                }
                if (pReceivePin == null)
                {
                    return(E_POINTER);
                }
                if (pReceivePin.EnumMediaTypes(out emt) == S_OK)
                {
                    var mediaTypes = new AMMediaType[1];

                    while (emt.Next(1, mediaTypes, IntPtr.Zero) == S_OK)
                    {
                        if (mediaTypes[0].majorType == MediaType.Stream && pReceivePin.ReceiveConnection(this, mediaTypes[0]) == S_OK)
                        {
                            emt          = null;
                            connectedPin = pReceivePin;
                            return(S_OK);
                        }
                    }
                    emt = null;
                }
                if (pmt != null && pmt.majorType != MediaType.Null && pmt.majorType != MediaType.Stream)
                {
                    return(DsResults.E_TypeNotAccepted);
                }
                if (pReceivePin.ReceiveConnection(this, mediaType) == S_OK)
                {
                    connectedPin = pReceivePin;
                    return(S_OK);
                }
                return(DsResults.E_NoAcceptableTypes);
            }
            int IPin.Connect(IPin pReceivePin, AMMediaType pmt)
            {
                IEnumMediaTypes emt;

                if (connectedPin != null)
                    return DsResults.E_AlreadyConnected;
                if (pReceivePin == null)
                    return E_POINTER;
                if (pReceivePin.EnumMediaTypes(out emt) == S_OK)
                {
                    var mediaTypes = new AMMediaType[1];

                    while (emt.Next(1, mediaTypes, IntPtr.Zero) == S_OK)
                        if (mediaTypes[0].majorType == MediaType.Stream && pReceivePin.ReceiveConnection(this, mediaTypes[0]) == S_OK)
                        {
                            emt = null;
                            connectedPin = pReceivePin;
                            return S_OK;
                        }
                    emt = null;
                }
                if (pmt != null && pmt.majorType != MediaType.Null && pmt.majorType != MediaType.Stream)
                    return DsResults.E_TypeNotAccepted;
                if (pReceivePin.ReceiveConnection(this, mediaType) == S_OK)
                {
                    connectedPin = pReceivePin;
                    return S_OK;
                }
                return DsResults.E_NoAcceptableTypes;
            }
Beispiel #3
0
 public void Connect(IPin receivePin)
 {
     ConnectedTo = receivePin;
     receivePin.ReceiveConnection(this);
 }
        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;
        }