前言

image.png
image.png
image.png
image.png
image.png
image.png
H:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\modules\video_capture\windows\help_functions_ds.cc
hr = pKs->Get(AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0,
&PinCategory, sizeof(GUID), &cbReturned);

代码分析

h:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\modules\video_capture\windows\video_capture_ds.cc

VideoCaptureDS::Init

  1. int32_t VideoCaptureDS::Init(const char* deviceUniqueIdUTF8) {
  2. ***
  3. _outputCapturePin = GetOutputPin(_captureFilter, PIN_CATEGORY_CAPTURE);
  4. if (!_outputCapturePin) {
  5. RTC_LOG(LS_INFO) << "Failed to get output capture pin";
  6. return -1;
  7. }
  8. ***
  9. }

—》H:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\modules\video_capture\windows\help_functions_ds.cc

GetOutputPin

  1. IPin* GetOutputPin(IBaseFilter* filter, REFGUID Category) {
  2. HRESULT hr;
  3. IPin* pin = NULL;
  4. IEnumPins* pPinEnum = NULL;
  5. filter->EnumPins(&pPinEnum);
  6. if (pPinEnum == NULL) {
  7. return NULL;
  8. }
  9. // get first unconnected pin
  10. hr = pPinEnum->Reset(); // set to first pin
  11. while (S_OK == pPinEnum->Next(1, &pin, NULL)) {
  12. PIN_DIRECTION pPinDir;
  13. pin->QueryDirection(&pPinDir);
  14. if (PINDIR_OUTPUT == pPinDir) // This is an output pin
  15. { // 我们就是要获取输出的pin,这里的GUID_NULL表示任意类型
  16. if (Category == GUID_NULL || PinMatchesCategory(pin, Category)) {
  17. pPinEnum->Release();
  18. return pin;
  19. }
  20. }
  21. pin->Release();
  22. pin = NULL;
  23. }
  24. pPinEnum->Release();
  25. return NULL;
  26. }

image.png
—》PinMatchesCategory(pin, Category)

PinMatchesCategory

  1. BOOL PinMatchesCategory(IPin* pPin, REFGUID Category) {
  2. BOOL bFound = FALSE;
  3. IKsPropertySet* pKs = NULL;
  4. // 获取该IKsPropertySet接口
  5. HRESULT hr = pPin->QueryInterface(IID_PPV_ARGS(&pKs));
  6. if (SUCCEEDED(hr)) {
  7. GUID PinCategory;
  8. DWORD cbReturned;
  9. hr = pKs->Get(AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0,
  10. &PinCategory, sizeof(GUID), &cbReturned);
  11. if (SUCCEEDED(hr) && (cbReturned == sizeof(GUID))) {
  12. // 如果PinCategory等于输入的Category,则说明已经找到了匹配的pin
  13. bFound = (PinCategory == Category);
  14. }
  15. pKs->Release();
  16. }
  17. return bFound;
  18. }

image.png

调用堆栈

image.png