Skip to content

Commit

Permalink
Reconnect logic should be working, but I can't tell because VSFilter …
Browse files Browse the repository at this point in the history
…is fucking epic and manages to always insert itself into the graph except when using madVR.
  • Loading branch information
[email protected] committed May 16, 2012
1 parent 2a8d04a commit 9ecb4d1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
71 changes: 47 additions & 24 deletions source/dxsubfilter/dxsubfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool CDXSubFilter::CheckVideoSubtypeIs16Bit(const CMediaType* pMediaType)

HRESULT CDXSubFilter::CheckInputType(const CMediaType* mtIn)
{
// We only accept video and text
// We only accept video and text.
if (mtIn->majortype == MEDIATYPE_Video)
{
// Check to see if the video subtype is one of the supported subtypes
Expand Down Expand Up @@ -158,31 +158,12 @@ HRESULT CDXSubFilter::CheckTransform(const CMediaType* mtIn, const CMediaType* m
}
else
{
// We check to see if we're going from 10/16-bit input to 8-bit output
// We check to see if we're going from 10/16-bit input to 8-bit output. If so, we allow it
// and then during CompleteConnect, we will force upstream to reconnect with the final output
// format
if (CheckVideoSubtypeIs16Bit(mtIn) && CheckVideoSubtypeIs8Bit(mtOut))
{
// Force upstream to reconnect with the same proposed format as the output
if (SUCCEEDED(m_pInput->QueryAccept(mtOut)))
{
if (SUCCEEDED(ReconnectPin(m_pInput, mtOut)))
{
m_pInput->SetMediaType(mtOut);

// Update the fact that we've reconnected the input on a new format
m_InputVideoType = *mtOut;

return S_OK;
}
else
{
return VFW_E_TYPE_NOT_ACCEPTED;
}
}
else
{
// If upstream doesn't accept the output format, much sadness occurs :(
return VFW_E_TYPE_NOT_ACCEPTED;
}
return S_OK;
}
else
{
Expand All @@ -203,6 +184,47 @@ HRESULT CDXSubFilter::CheckTransform(const CMediaType* mtIn, const CMediaType* m
}
}

HRESULT CDXSubFilter::CompleteConnect(PIN_DIRECTION direction, IPin* pReceivePin)
{
if (direction == PINDIR_OUTPUT)
{
CMediaType mtOut = m_pOutput->CurrentMediaType();
if (mtOut != m_pInput->CurrentMediaType())
{
// Force upstream to reconnect with the same proposed format as the output
if (SUCCEEDED(m_pInput->QueryAccept(&mtOut)))
{
if (SUCCEEDED(ReconnectPin(m_pInput, &mtOut)))
{
m_pInput->SetMediaType(&mtOut);

// Update the fact that we've reconnected the input on a new format
m_InputVideoType = mtOut;

return S_OK;
}
else
{
return VFW_E_TYPE_NOT_ACCEPTED;
}
}
else
{
// If upstream doesn't accept the output format, much sadness occurs :(
return VFW_E_TYPE_NOT_ACCEPTED;
}
}
else
{
return S_OK;
}
}
else
{
return S_OK;
}
}

HRESULT CDXSubFilter::DecideBufferSize(IMemAllocator * pAllocator, ALLOCATOR_PROPERTIES *pProp)
{
// Our input and output formats should always match so we don't really need to do anything
Expand Down Expand Up @@ -276,6 +298,7 @@ HRESULT CDXSubFilter::GetMediaType(int iPosition, CMediaType *pMediaType)
else
{
// Subtract 1 from iPosition because iPosition == 0 is used for input format.
pMediaType->SetType(&MEDIATYPE_Video);
pMediaType->SetSubtype(&DXSUBFILTER_SUPPORTED_VIDEO_SUBTYPES_8BIT[iPosition-1]);
}
}
Expand Down
5 changes: 4 additions & 1 deletion source/dxsubfilter/dxsubfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace DXSubFilter
MEDIASUBTYPE_AYUV, // Packed 4:4:4
MEDIASUBTYPE_YUY2, // Packed 4:2:2
MEDIASUBTYPE_YV12, // Planar 4:2:0
MEDIASUBTYPE_NV12, // Planar/Packed 4:2:0
};

static const GUID DXSUBFILTER_SUPPORTED_VIDEO_SUBTYPES_16BIT[] = {
Expand Down Expand Up @@ -58,6 +57,10 @@ namespace DXSubFilter
// Check if we can support the transform from this input to this output
virtual HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);

// We override this so that we can perform additional checking related to 10/16-bit
// support
virtual HRESULT CompleteConnect(PIN_DIRECTION direction, IPin* pReceivePin);

// Call the SetProperties function with appropriate arguments
virtual HRESULT DecideBufferSize(
IMemAllocator * pAllocator,
Expand Down

0 comments on commit 9ecb4d1

Please sign in to comment.