Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IAMStreamConfig::GetStreamCaps get wrong SubType when enum twice because CPushPinDesktop::GetMediaType has a bug #162

Open
yinkaisheng opened this issue Feb 1, 2023 · 3 comments

Comments

@yinkaisheng
Copy link

yinkaisheng commented Feb 1, 2023

the following code outputs:

Camera capability 0, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kRGB32, rateControl:0
Camera capability 1, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kRGB32, rateControl:0
Camera capability 2, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kRGB32, rateControl:0
Camera capability 3, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kRGB32, rateControl:0
Camera capability 4, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kRGB32, rateControl:0
Camera capability 5, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kRGB32, rateControl:0
Camera capability 6, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kI420, rateControl:0

----

Camera capability 0, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kI420, rateControl:0
Camera capability 1, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kI420, rateControl:0
Camera capability 2, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kI420, rateControl:0
Camera capability 3, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kI420, rateControl:0
Camera capability 4, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kI420, rateControl:0
Camera capability 5, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kI420, rateControl:0
Camera capability 6, VideoInfo1, size:2560 x 1440, fps:30, video sub type:kI420, rateControl:0
ComPtr<IAMStreamConfig> streamConfig;
hr = outputPin->QueryInterface(IID_IAMStreamConfig, (void**)&streamConfig);

AM_MEDIA_TYPE* pmt = nullptr;
VIDEO_STREAM_CONFIG_CAPS caps;
int count = 0;
int size = 0;
hr = streamConfig->GetNumberOfCapabilities(&count, &size);

int enumTimes = 2;
for (int n = 0; n < enumTimes; ++n)
{
    for (int index = 0; index < count; ++index)
    {
        hr = streamConfig->GetStreamCaps(index, &pmt, reinterpret_cast<BYTE*>(&caps));
        //print pmt properties;
    }
    printf("\n----\n");
}	

In CPushPinDesktop::GetMediaType, pmt->Subtype() is always I420 (!=GUID_NULL) after enumerating once, pmt->SetSubType is never called when enumerating the second time.

HRESULT CPushPinDesktop::GetMediaType(int iPosition, CMediaType *pmt) // AM_MEDIA_TYPE basically == CMediaType
{
    //...
    if (*pmt->Subtype() == GUID_NULL) {
      const GUID SubTypeGUID = GetBitmapSubtype(&pvi->bmiHeader);
      pmt->SetSubtype(&SubTypeGUID);
    }
}

if I change the code to the following, then IAMStreamConfig::GetStreamCaps will get correct result when enumerating twice.

HRESULT CPushPinDesktop::GetMediaType(int iPosition, CMediaType *pmt) // AM_MEDIA_TYPE basically == CMediaType
{
    //...
    if (iPosition < 6) {
      const GUID SubTypeGUID = GetBitmapSubtype(&pvi->bmiHeader);
      pmt->SetSubtype(&SubTypeGUID);
    }
}
@rdp
Copy link
Owner

rdp commented Feb 2, 2023 via email

@yinkaisheng
Copy link
Author

Yes, when app calls streamConfig->GetStreamCaps with index 0,... 6, CPushPinDesktop::GetStreamCaps will be called.
m_mt's Subtype is set and is not GUID_NULL anymore, SubType is I420 when the last index is 6.
If app calls streamConfig->GetStreamCaps with index 0,... 6 again, pmt->SetSubtype is never called because *pmt->Subtype() != GUID_NULL, the SubType in pmt that app gets is always I420。

HRESULT STDMETHODCALLTYPE CPushPinDesktop::GetStreamCaps(int iIndex, AM_MEDIA_TYPE **pmt, BYTE *pSCC)
{
    CAutoLock cAutoLock(m_pFilter->pStateLock());
    HRESULT hr = GetMediaType(iIndex, &m_mt); // setup then re-use m_mt ... why not?
    ...
    *pmt = CreateMediaType(&m_mt);
}
HRESULT CPushPinDesktop::GetMediaType(int iPosition, CMediaType *pmt) // AM_MEDIA_TYPE basically == CMediaType
{
//...
    if (*pmt->Subtype() == GUID_NULL) {
      const GUID SubTypeGUID = GetBitmapSubtype(&pvi->bmiHeader);
      pmt->SetSubtype(&SubTypeGUID);
    }
}

@rdp
Copy link
Owner

rdp commented May 24, 2023

Check it, see if it works for you...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants