STDMETHODIMP CBasePin::Connect( IPin * pReceivePin, const AM_MEDIA_TYPE *pmt // optional media type ) { CheckPointer(pReceivePin,E_POINTER); ValidateReadPtr(pReceivePin,sizeof(IPin)); CComAutoLock cObjectLock(m_pLock); DisplayPinInfo(pReceivePin); /* See if we are already connected */ if (m_Connected) { DbgLog((LOG_TRACE, CONNECT_TRACE_LEVEL, TEXT("Already connected"))); return VFW_E_ALREADY_CONNECTED; } /* See if the filter is active */ if (!IsStopped() && !m_bCanReconnectWhenActive) { return VFW_E_NOT_STOPPED; } // Find a mutually agreeable media type - // Pass in the template media type. If this is partially specified, // each of the enumerated media types will need to be checked against // it. If it is non-null and fully specified, we will just try to connect // with this. const CMediaType * ptype = (CMediaType*)pmt; HRESULT hr = AgreeMediaType(pReceivePin, ptype); if (FAILED(hr)) { DbgLog((LOG_TRACE, CONNECT_TRACE_LEVEL, TEXT("Failed to agree type"))); // Since the procedure is already returning an error code, there // is nothing else this function can do to report the error. EXECUTE_ASSERT( SUCCEEDED( BreakConnect() ) ); return hr; } DbgLog((LOG_TRACE, CONNECT_TRACE_LEVEL, TEXT("Connection succeeded"))); return NOERROR; }
ErrorCode BasePinImpl::Connect(IPin *pReceivePin, MediaType* pmt) { ASSERT(pReceivePin != NULL); if (pReceivePin == NULL) throw -1;//return E_INVALIDARG; ASSERT(m_connectedTo == NULL); if (m_connectedTo != NULL) return MEDIA_E_ALREADY_CONNECTED; if (m_dir != PINDIR_OUTPUT) return Error; ErrorCode hr; hr = AgreeMediaType(pReceivePin, pmt); return hr; }