Пример #1
0
STDMETHODIMP
BasePin::ReceiveConnection(IPin * aPin,
                             const AM_MEDIA_TYPE *aMediaType)
{
  if (!aPin)
    return E_POINTER;

  if (!aMediaType)
    E_POINTER;

  CriticalSectionAutoEnter monitor(*mLock);

  if (IsConnected())
    return VFW_E_ALREADY_CONNECTED;

  if (!IsStopped())
    return VFW_E_NOT_STOPPED;

  HRESULT hr = CheckConnect(aPin);
  if (FAILED(hr)) {
    BreakConnect();
    return hr;
  }

  // See if subclass supports the specified media type.
  const MediaType* mediaType = reinterpret_cast<const MediaType*>(aMediaType);
  hr = CheckMediaType(mediaType);
  if (FAILED(hr)) {
    BreakConnect();
    return hr;
  }

  // Supported, set it.
  hr = SetMediaType(mediaType);
  if (FAILED(hr))
    return hr;

  // Complete the connection.
  mConnectedPin = aPin;
  // Give the subclass one last chance to refuse the connection.
  hr = CompleteConnect(aPin);
  if (FAILED(hr)) {
    // Subclass refused connection, fail...
    mConnectedPin = NULL;
    BreakConnect();
    return hr;
  }

  // It's all good, we're connected.
  return S_OK;
}
Пример #2
0
// требует установки diCurr
bool    LoadConnect(uchar  ibCanal)
{
  if (fConnect == 1)
  {
    if ((diLast.ibPort == 0xFF) || (diLast.ibPhone == 0xFF))
    {
      KeyBreakConnect();
      return(0);
    }
    else if (BreakConnect() == 1)
    {
      if (NeedDisconnect() == 1)
      {
        diNext = diCurr; diCurr = diLast;
        bool fAlt = SafeDisconnect();
        diCurr = diNext;

        if (fAlt == 0) { ShowLo(szNoDisconnect); InitConnect(); return(0); }
      }

      ibDig = ibCanal;
      if (SafeConnect() == 0) { ShowLo(szNoConnect);  InitConnect(); return(0); }
    }
    else ibDig = ibCanal;
  }
  else
  {
    ibDig = ibCanal;
    if (SafeConnect() == 0) { ShowLo(szNoConnect);  InitConnect(); return(0); }
  }

  return(1);
}
Пример #3
0
STDMETHODIMP
CBasePin::DisconnectInternal()
{
	ASSERT(CritCheckIn(m_pLock));

	if (m_Connected) {
		HRESULT hr = BreakConnect();
		if( FAILED( hr ) ) {


			// There is usually a bug in the program if BreakConnect() fails.
			DbgBreak( "WARNING: BreakConnect() failed in CBasePin::Disconnect()." );
			return hr;
		}

		m_Connected->Release();
		m_Connected = NULL;


		return S_OK;
	} else {
		// no connection - not an error


		return S_FALSE;
	}
}
Пример #4
0
// Attempt to connect this pin to |aPin| using given media type.
HRESULT
BasePin::AttemptConnection(IPin* aPin,
                             const MediaType* aMediaType)
{
  CriticalSectionAutoEnter monitor(*mLock);

  // Ensure we can connect to the other pin. Gives subclasses a chance
  // to prevent connection.
  HRESULT hr = CheckConnect(aPin);
  if (FAILED(hr)) {
    BreakConnect();
    return hr;
  }

  // Ensure we can connect with this media type. This gives subclasses a
  // chance to abort the connection.
  hr = CheckMediaType(aMediaType);
  if (FAILED(hr))
    return hr;

  hr = SetMediaType(aMediaType);
  if (FAILED(hr))
    return hr;

  // Ask the other pin if it will accept a connection with our media type.
  hr = aPin->ReceiveConnection(static_cast<IPin*>(this), aMediaType);
  if (FAILED(hr))
    return hr;

  // Looks good so far, give subclass one final chance to refuse connection...
  mConnectedPin = aPin;
  hr = CompleteConnect(aPin);

  if (FAILED(hr)) {
    // Subclass refused the connection, inform the other pin that we're
    // disconnecting, and break the connection.
    aPin->Disconnect();
    BreakConnect();
    mConnectedPin = NULL;
    mMediaType.Clear();
    return VFW_E_TYPE_NOT_ACCEPTED;
  }

  // Otherwise, we're all good!
  return S_OK;
}
Пример #5
0
ErrorCode BasePinImpl::ReceiveConnection(IPin *pConnector, MediaType* pMediaType)
{
	if (pConnector == NULL)
	{
		ASSERT(0);
		//return E_INVALIDARG;
		throw -1;
	}

	if (m_dir != PINDIR_INPUT)
	{
		ASSERT(0);
		return Error;
	}

	ErrorCode hr;

	hr = CheckConnect(pConnector);
	if (hr < 0)
	{
		BreakConnect();
		return hr;
	}

	hr = CheckMediaType(pMediaType);
	if (hr < 0)
	{
		BreakConnect();
		return hr;
	}

	// Is the order of these last two correct?

	SetMediaType(pMediaType);

	hr = CompleteConnect(pConnector);
	if (hr < 0)
	{
		// BreakConnect(); ??
		return hr;
	}

	return 0;
}
Пример #6
0
ErrorCode BasePinImpl::AttemptConnection(IPin *pReceivePin, MediaType* mt)
{
	ErrorCode hr;

	//CheckConnect( Why Is this called here, it will be called multiple times if it's here?

	hr = CheckConnect(pReceivePin);
	if (hr < 0)
	{
		BreakConnect();
		return hr;
	}

	hr = CheckMediaType(mt);
	if (hr < 0)
	{
		BreakConnect();
		return hr;
	}

	hr = pReceivePin->ReceiveConnection(this, mt);
	if (hr < 0) return hr;

	hr = SetMediaType(mt);	// ?? Have this here??
	if (hr < 0)
	{
		BreakConnect();
		return hr;
	}

	hr = CompleteConnect(pReceivePin);
	if (hr < 0)
	{
		Disconnect();
		return hr;
	}

	return 0;
}
Пример #7
0
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;
}
Пример #8
0
STDMETHODIMP
BasePin::Disconnect()
{
  CriticalSectionAutoEnter monitor(*mLock);

  // Can't disconnect a non-stopped filter.
  if (!IsStopped())
    return VFW_E_NOT_STOPPED;

  if (!IsConnected())
     return S_FALSE;

  HRESULT hr = BreakConnect();
  mConnectedPin = NULL;
  return hr;
}
Пример #9
0
ErrorCode BasePinImpl::Disconnect()
{
	BreakConnect();
	m_connectedTo = NULL;
	return 0;
}
Пример #10
0
STDMETHODIMP
CBasePin::ReceiveConnection(
							IPin * pConnector,      // this is the pin who we will connect to
							const AM_MEDIA_TYPE *pmt    // this is the media type we will exchange
							)
{
	CheckPointer(pConnector,E_POINTER);
	CheckPointer(pmt,E_POINTER);
	ValidateReadPtr(pConnector,sizeof(IPin));
	ValidateReadPtr(pmt,sizeof(AM_MEDIA_TYPE));
	CComAutoLock cObjectLock(m_pLock);

#ifdef _DEBUG
	PIN_INFO PinInfo;

	if(!FAILED(pConnector->QueryPinInfo(&PinInfo)))
	{

		CEasyString PinName=PinInfo.achName;



		PrintSystemLog(0,"RecvPin:%s",(LPCTSTR)PinName);


		if(PinInfo.pFilter)
		{

			FILTER_INFO FilterInfo;
			if (!FAILED(PinInfo.pFilter->QueryFilterInfo(&FilterInfo)))
			{

				CLSID ClassID;

				PinInfo.pFilter->GetClassID(&ClassID);

				CEasyString FilterName=FilterInfo.achName;

				PrintSystemLog(0,"RecvPinFilter:%s",(LPCTSTR)FilterName);


				// The FILTER_INFO structure holds a pointer to the Filter Graph
				// Manager, with a reference count that must be released.
				if (FilterInfo.pGraph != NULL)
				{
					FilterInfo.pGraph->Release();
				}
			}

			PinInfo.pFilter->Release();
		}

		//MessageBox(NULL, (LPCTSTR)PinName, TEXT("Filter Name"), MB_OK);
	}

#endif

	/* Are we already connected */
	if (m_Connected) {
		return VFW_E_ALREADY_CONNECTED;
	}

	/* See if the filter is active */
	if (!IsStopped() && !m_bCanReconnectWhenActive) {
		return VFW_E_NOT_STOPPED;
	}

	HRESULT hr = CheckConnect(pConnector);
	if (FAILED(hr)) {
		// 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;
	}

	/* Ask derived class if this media type is ok */

	CMediaType * pcmt = (CMediaType*) pmt;
	hr = CheckMediaType(pcmt);
	if (hr != NOERROR) {
		// no -we don't support this media 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 a specific media type error if there is one
		// or map a general failure code to something more helpful
		// (in particular S_FALSE gets changed to an error code)
		if (SUCCEEDED(hr) ||
			(hr == E_FAIL) ||
			(hr == E_INVALIDARG)) {
				hr = VFW_E_TYPE_NOT_ACCEPTED;
		}


		return hr;
	}

	/* Complete the connection */

	m_Connected = pConnector;
	m_Connected->AddRef();
	hr = SetMediaType(pcmt);
	if (SUCCEEDED(hr)) {
		hr = CompleteConnect(pConnector);
		if (SUCCEEDED(hr)) {


			return NOERROR;
		}
	}

	DbgLog((LOG_TRACE, CONNECT_TRACE_LEVEL, TEXT("Failed to set the media type or failed to complete the connection.")));
	m_Connected->Release();
	m_Connected = NULL;

	// 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;
}
Пример #11
0
// given a specific media type, attempt a connection (includes
// checking that the type is acceptable to this pin)
HRESULT
CBasePin::AttemptConnection(
							IPin* pReceivePin,      // connect to this pin
							const CMediaType* pmt   // using this type
							)
{
	// The caller should hold the filter lock becasue this function
	// uses m_Connected.  The caller should also hold the filter lock
	// because this function calls SetMediaType(), IsStopped() and
	// CompleteConnect().
	ASSERT(CritCheckIn(m_pLock));

	// Check that the connection is valid  -- need to do this for every
	// connect attempt since BreakConnect will undo it.
	HRESULT hr = CheckConnect(pReceivePin);
	if (FAILED(hr)) {
		DbgLog((LOG_TRACE, CONNECT_TRACE_LEVEL, TEXT("CheckConnect failed")));

		// 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;
	}

	DisplayTypeInfo(pReceivePin, pmt);

	/* Check we will accept this media type */

	hr = CheckMediaType(pmt);
	if (hr == NOERROR) {

		/*  Make ourselves look connected otherwise ReceiveConnection
		may not be able to complete the connection
		*/
		m_Connected = pReceivePin;
		m_Connected->AddRef();
		hr = SetMediaType(pmt);
		if (SUCCEEDED(hr)) {
			/* See if the other pin will accept this type */

			hr = pReceivePin->ReceiveConnection((IPin *)this, pmt);
			if (SUCCEEDED(hr)) {
				/* Complete the connection */

				hr = CompleteConnect(pReceivePin);
				if (SUCCEEDED(hr)) {
					return hr;
				} else {
					DbgLog((LOG_TRACE,
						CONNECT_TRACE_LEVEL,
						TEXT("Failed to complete connection")));
					pReceivePin->Disconnect();
				}
			}
		}
	} else {
		// we cannot use this media type

		// return a specific media type error if there is one
		// or map a general failure code to something more helpful
		// (in particular S_FALSE gets changed to an error code)
		if (SUCCEEDED(hr) ||
			(hr == E_FAIL) ||
			(hr == E_INVALIDARG)) {
				hr = VFW_E_TYPE_NOT_ACCEPTED;
		}
	}

	// BreakConnect and release any connection here in case CheckMediaType
	// failed, or if we set anything up during a call back during
	// ReceiveConnection.

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

	/*  If failed then undo our state */
	if (m_Connected) {
		m_Connected->Release();
		m_Connected = NULL;
	}

	return hr;
}