Jump to content
  • Advertisement
Sign in to follow this  

[DirectShow] Overriding CBasePin::ReceiveConnection to handle dynamic format changes

This topic is 2891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on an in-place transform filter (CTransInPlaceFilter) and have hit a snag. I have a DVD MPEG-2 decoder which connects at 720x480 then changes to the (correct) 720x576 some time afterwards. The default implementation of CBasePin::ReceiveConnection returns VFW_E_ALREADY_CONNECTED if the pin is already connected, which means that the attempt to change format fails and the video plays back at 720x480. This naturally degrades image quality and also causes rendering issues with DVD menus (compare to the intended appearance).

I have overridden the GetPin method to return my own pin which derives from CTransInPlaceInputPin and overridden its ReceiveConnection method. In doing so I have tried to do what MSDN says I should be doing, but I'm not entirely sure what I'm supposed to be doing. The below code appears to work, but I'm inherently distrustful of code that works first time and without me fully understanding what it's doing.

STDMETHODIMP CNameOfMyInputPin::ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt) {
CheckPointer(pConnector, E_POINTER);
CheckPointer(pmt, E_POINTER);

if (!m_Connected) {
return __super::ReceiveConnection(pConnector, pmt);
} else {


// Fetch my output pin.
IPin* outputPin = m_pFilter->GetPin(1);

// Get the downstream input pin it is connected to.
IPin* downstreamInputPin;
hr = outputPin->ConnectedTo(&downstreamInputPin);
if (hr != S_OK) return hr;

// Call ReceiveConnection on the downstream pin.
hr = downstreamInputPin->ReceiveConnection(this, pmt);
if (hr != S_OK) return hr;

// Call NotifyAllocator on the downstream pin.
IMemInputPin* memoryInputPin;
if (downstreamInputPin->QueryInterface<IMemInputPin>(&memoryInputPin) == S_OK) {
IMemAllocator* allocator;
if (memoryInputPin->GetAllocator(&allocator) == S_OK) {
memoryInputPin->NotifyAllocator(allocator, FALSE);

return hr;

I'd greatly appreciate any feedback!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!