Ich habe 4 DirectShow-Filter im Diagramm:
- Aufnahmefilter für eine Webcam, die nur VIH1 ausgibt
- Aufnahmefilter für ein Capture Board (CB), das sowohl VIH1 als auch VIH2 ausgibt
- SampleGrabber2
- VMR9
Hier ist der relevante Medientyp-Aushandlungscode. Wie kann ich eine nahtlose Aushandlung durchführen und diese Verbindungsabbrüche verhindern? Ich gehe davon aus, dass dies etwas mit der Allokatorverhandlung zu tun hat, aber bisher hatte ich kein Glück, das Problem zu beheben.
Code: Select all
HRESULT CSG2InPin::CheckMediaType(const CMediaType* pmt)
{
if (!pmt) return E_POINTER;
if (IsConnected()) {
const CMediaType& cur = CurrentMediaType();
return (*pmt == cur) ? S_OK : VFW_E_TYPE_NOT_ACCEPTED;
}
// One-time probe: does the peer enumerate a VIH2 we would accept?
if (!m_peerHasVIH2Checked && m_spPeer) {
m_peerHasVIH2Checked = true;
CComPtr spEnum;
if (SUCCEEDED(m_spPeer->EnumMediaTypes(&spEnum)) && spEnum) {
AM_MEDIA_TYPE* pTry = nullptr;
while (spEnum->Next(1, &pTry, nullptr) == S_OK) {
CMediaType mt(*pTry);
if (mt.majortype == MEDIATYPE_Video &&
mt.formattype == FORMAT_VideoInfo2 &&
SUCCEEDED(m_pTransformFilter->CheckInputType(&mt))) {
m_peerHasVIH2 = true;
break;
}
}
}
}
// If the peer can do VIH2 and we’re currently being offered VIH1, decline it
// so the search advances to VIH2.
if (pmt->majortype == MEDIATYPE_Video &&
pmt->formattype == FORMAT_VideoInfo &&
m_peerHasVIH2) {
return VFW_E_TYPE_NOT_ACCEPTED; // “Prefer VIH2 if available”
}
// Otherwise, defer to the filter’s policy
return m_pTransformFilter->CheckInputType(pmt);
}
...
HRESULT CSampleGrabber2::CheckInputType(const CMediaType* mtIn)
{
if ((mtIn->majortype != MEDIATYPE_Video) ||
(mtIn->formattype != FORMAT_VideoInfo) &&
(mtIn->formattype != FORMAT_VideoInfo2))
{
return VFW_E_TYPE_NOT_ACCEPTED;
}
currentFormat = (mtIn->formattype == FORMAT_VideoInfo2) ? VIH2 : VIH;
return S_OK;
}
Mobile version