void DirectShowPlayerService::doReleaseAudioOutput(QMutexLocker *locker) { m_pendingTasks |= m_executedTasks & (Play | Pause); if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) { control->Stop(); control->Release(); } IBaseFilter *decoder = getConnected(m_audioOutput, PINDIR_INPUT); if (!decoder) { decoder = m_audioOutput; decoder->AddRef(); } // {DCFBDCF6-0DC2-45f5-9AB2-7C330EA09C29} static const GUID iid_IFilterChain = { 0xDCFBDCF6, 0x0DC2, 0x45f5, {0x9A, 0xB2, 0x7C, 0x33, 0x0E, 0xA0, 0x9C, 0x29} }; if (IFilterChain *chain = com_cast<IFilterChain>(m_graph, iid_IFilterChain)) { chain->RemoveChain(decoder, m_audioOutput); chain->Release(); } else { m_graph->RemoveFilter(m_audioOutput); } decoder->Release(); m_executedTasks &= ~SetAudioOutput; m_loop->wake(); }
HRESULT FindSourceFilter(IFilterGraph* filterGraph,IBaseFilter*& result) { HRESULT hr; IEnumFilters *enumFilters; hr = filterGraph->EnumFilters(&enumFilters); if (FAILED(hr)) { ErrorPrint("Get enum filters error",hr); return hr; } ComReleaser enumFilterReleaser(enumFilters); IBaseFilter* filter; while (S_OK == enumFilters->Next(1, &filter, NULL)) { ComReleaser filterReleaser(filter); IEnumPins *enumPins; hr = filter->EnumPins(&enumPins); if (FAILED(hr)) { ErrorPrint("Get enum pins error",hr); return hr; } ComReleaser enumPinsReleaser(enumPins); IPin* pin; bool isSourceFilter = true; while (S_OK == enumPins->Next(1, &pin, NULL)) { ComReleaser pinReleaser(pin); PIN_INFO pinInfo; hr = pin->QueryPinInfo(&pinInfo); if (FAILED(hr)) { ErrorPrint("Get pin info error",hr); continue; } if (pinInfo.dir == PINDIR_INPUT) //认为没有输入pin的就是source filter,这其实是有些问题的,特别是当捕获(如声卡的音频)的filter有时候有很多输入PIN { isSourceFilter = false; break; } } if (isSourceFilter) { filter->AddRef(); //存在一个资源管理的释放类,必须增加一个引用,否则会被释放掉 result = filter; return S_OK; } } return E_FAIL; }
void CALLBACK OpenConfiguration(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) { HRESULT hr = S_OK; CUnknown *pInstance = CreateInstance<CLAVAudio>(nullptr, &hr); IBaseFilter *pFilter = nullptr; pInstance->NonDelegatingQueryInterface(IID_IBaseFilter, (void **)&pFilter); if (pFilter) { pFilter->AddRef(); CBaseDSPropPage::ShowPropPageDialog(pFilter); } delete pInstance; }
void DirectShowPlayerService::doReleaseVideoOutput(QMutexLocker *locker) { m_pendingTasks |= m_executedTasks & (Play | Pause); if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) { control->Stop(); control->Release(); } IBaseFilter *intermediate = 0; if (!SUCCEEDED(m_graph->FindFilterByName(L"Color Space Converter", &intermediate))) { intermediate = m_videoOutput; intermediate->AddRef(); } IBaseFilter *decoder = getConnected(intermediate, PINDIR_INPUT); if (!decoder) { decoder = intermediate; decoder->AddRef(); } // {DCFBDCF6-0DC2-45f5-9AB2-7C330EA09C29} static const GUID iid_IFilterChain = { 0xDCFBDCF6, 0x0DC2, 0x45f5, {0x9A, 0xB2, 0x7C, 0x33, 0x0E, 0xA0, 0x9C, 0x29} }; if (IFilterChain *chain = com_cast<IFilterChain>(m_graph, iid_IFilterChain)) { chain->RemoveChain(decoder, m_videoOutput); chain->Release(); } else { m_graph->RemoveFilter(m_videoOutput); } intermediate->Release(); decoder->Release(); m_executedTasks &= ~SetVideoOutput; m_loop->wake(); }
HRESULT WINAPI CreateWaveOutRenderer(LPUNKNOWN unk, IBaseFilter** out) { if (!out) return E_POINTER; HRESULT hr = S_OK; IBaseFilter* punk = new CWaveOutRenderer(unk, &hr); if(punk == NULL) return E_OUTOFMEMORY; punk->AddRef(); *out = punk; return hr; }
STDAPI OpenConfiguration() { HRESULT hr = S_OK; CUnknown *pInstance = CreateInstance<CLAVSplitter>(NULL, &hr); IBaseFilter *pFilter = NULL; pInstance->NonDelegatingQueryInterface(IID_IBaseFilter, (void **)&pFilter); if (pFilter) { pFilter->AddRef(); CBaseDSPropPage::ShowPropPageDialog(pFilter); } delete pInstance; return 0; }
STDMETHODIMP CapturePin::QueryPinInfo(PIN_INFO *pInfo) { PrintFunc(L"CapturePin::QueryPinInfo"); pInfo->pFilter = filter; if (filter) { IBaseFilter *ptr = filter; ptr->AddRef(); } if (captureInfo.expectedMajorType == MEDIATYPE_Video) memcpy(pInfo->achName, VIDEO_PIN_NAME, sizeof(VIDEO_PIN_NAME)); else memcpy(pInfo->achName, AUDIO_PIN_NAME, sizeof(AUDIO_PIN_NAME)); pInfo->dir = PINDIR_INPUT; return NOERROR; }
HRESULT RenderSubPicture() { if (!m_pDeMux) return E_POINTER; // Render from the output of the DVD Nav & then from the output of the decoder filter IPin* subpicSource = FindPinByName(m_pDeMux, "SubPicture", PINDIR_OUTPUT); if (!subpicSource) return E_FAIL; HRESULT hr; // Check if the video rendering filter has an extra input pin. If it doesn't then // this'll end up adding another renderer to the graph which causes an ActiveMovieWindow // to display. We abort rendering of the subpicture in this case. /* if (!m_pVideoRenderer) { IBaseFilter* pCurrVRend = FindVideoRendererFilter(m_pGraph); if (!pCurrVRend) return E_FAIL; IPin* testPin = FindUnconnectedPin(m_pVideoRenderer, PINDIR_INPUT); if (!testPin) { slog(("Aborting subpicture rendering because there's no more input pins on video renderer.\r\n")); return E_FAIL; } testPin->Release(); } else { IPin* testPin = FindUnconnectedPin(m_pVideoRenderer, PINDIR_INPUT); if (!testPin) { slog(("Aborting subpicture rendering because there's no more input pins on video renderer.\r\n")); return E_FAIL; } testPin->Release(); } */ // Get the decoder filter, since it may not be specified IBaseFilter* pVideoDecoder = NULL; IBaseFilter* pVideoRenderer = NULL; if (m_pVideoDecoder) { pVideoDecoder = m_pVideoDecoder; pVideoDecoder->AddRef(); } else { IPin* vSrc = GetSourceVideoPin(); IPin* vNext = NULL; vSrc->ConnectedTo(&vNext); vSrc->Release(); PIN_INFO pInfo; hr = vNext->QueryPinInfo(&pInfo); pVideoDecoder = pInfo.pFilter; vNext->Release(); } // We added this back for Vista to get DVD subpictures to show up. But this won't end up doing anything // if we can't find another input pin on the renderer. BOOL renderDVDSubpic = TRUE; if (renderDVDSubpic) { if (m_pVideoRenderer) { pVideoRenderer = m_pVideoRenderer; pVideoRenderer->AddRef(); } else { IPin* vSrc = FindUnconnectedPin(pVideoDecoder, PINDIR_OUTPUT, TRUE); IPin* vNext = NULL; vSrc->ConnectedTo(&vNext); vSrc->Release(); PIN_INFO pInfo; hr = vNext->QueryPinInfo(&pInfo); pVideoRenderer = pInfo.pFilter; vNext->Release(); } } IPin* subpicDestPin = FindUnconnectedPin(pVideoDecoder, PINDIR_INPUT); if (!subpicDestPin) { pVideoDecoder->Release(); return E_FAIL; } hr = m_pGraph->Connect(subpicSource, subpicDestPin); SAFE_RELEASE(subpicDestPin); SAFE_RELEASE(subpicSource); /* * NOTE: 7/27/04 - On my system, the video wouldn't play at all on DVDs if I connected * up the subpicture stream. But the subpicture worked fine when I didn't connect it. * For now I'm going to leave it that way and then just connect up the CC instead. */ if (renderDVDSubpic && SUCCEEDED(hr)) { IPin* decoderSubpicOut = FindDecoderSubpictureOutputPin(pVideoDecoder); if (decoderSubpicOut) { IPin* renderSubpicIn = FindUnconnectedPin(pVideoRenderer, PINDIR_INPUT); if (renderSubpicIn) { hr = m_pGraph->Connect(decoderSubpicOut, renderSubpicIn); SAFE_RELEASE(renderSubpicIn); } // hr = m_pGraph->Render(decoderSubpicOut); SAFE_RELEASE(decoderSubpicOut); } } if (pVideoRenderer) pVideoRenderer->Release(); pVideoDecoder->Release(); return hr; }