niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | e713fd0 | 2012-04-10 07:13:46 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
tommi@webrtc.org | 8187877 | 2012-11-20 13:35:33 +0000 | [diff] [blame] | 11 | #include <initguid.h> // Must come before the help_functions_ds.h include so |
| 12 | // that DEFINE_GUID() entries will be defined in this |
| 13 | // object file. |
| 14 | |
pbos@webrtc.org | a9b74ad | 2013-07-12 10:03:52 +0000 | [diff] [blame] | 15 | #include "webrtc/modules/video_capture/windows/help_functions_ds.h" |
tommi@webrtc.org | 8187877 | 2012-11-20 13:35:33 +0000 | [diff] [blame] | 16 | |
| 17 | #include <cguid.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc |
| 20 | { |
| 21 | namespace videocapturemodule |
| 22 | { |
| 23 | // This returns minimum :), which will give max frame rate... |
| 24 | LONGLONG GetMaxOfFrameArray(LONGLONG *maxFps, long size) |
| 25 | { |
| 26 | LONGLONG maxFPS = maxFps[0]; |
| 27 | for (int i = 0; i < size; i++) |
| 28 | { |
| 29 | if (maxFPS > maxFps[i]) |
| 30 | maxFPS = maxFps[i]; |
| 31 | } |
| 32 | return maxFPS; |
| 33 | } |
| 34 | |
| 35 | IPin* GetInputPin(IBaseFilter* filter) |
| 36 | { |
| 37 | HRESULT hr; |
| 38 | IPin* pin = NULL; |
| 39 | IEnumPins* pPinEnum = NULL; |
| 40 | filter->EnumPins(&pPinEnum); |
| 41 | if (pPinEnum == NULL) |
| 42 | { |
| 43 | return NULL; |
| 44 | } |
| 45 | |
| 46 | // get first unconnected pin |
| 47 | hr = pPinEnum->Reset(); // set to first pin |
| 48 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | while (S_OK == pPinEnum->Next(1, &pin, NULL)) |
| 50 | { |
| 51 | PIN_DIRECTION pPinDir; |
| 52 | pin->QueryDirection(&pPinDir); |
| 53 | if (PINDIR_INPUT == pPinDir) // This is an input pin |
| 54 | { |
| 55 | IPin* tempPin = NULL; |
| 56 | if (S_OK != pin->ConnectedTo(&tempPin)) // The pint is not connected |
| 57 | { |
| 58 | pPinEnum->Release(); |
| 59 | return pin; |
| 60 | } |
| 61 | } |
| 62 | pin->Release(); |
| 63 | } |
| 64 | pPinEnum->Release(); |
| 65 | return NULL; |
| 66 | } |
| 67 | |
| 68 | IPin* GetOutputPin(IBaseFilter* filter, REFGUID Category) |
| 69 | { |
| 70 | HRESULT hr; |
| 71 | IPin* pin = NULL; |
| 72 | IEnumPins* pPinEnum = NULL; |
| 73 | filter->EnumPins(&pPinEnum); |
| 74 | if (pPinEnum == NULL) |
| 75 | { |
| 76 | return NULL; |
| 77 | } |
| 78 | // get first unconnected pin |
| 79 | hr = pPinEnum->Reset(); // set to first pin |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | while (S_OK == pPinEnum->Next(1, &pin, NULL)) |
| 81 | { |
| 82 | PIN_DIRECTION pPinDir; |
| 83 | pin->QueryDirection(&pPinDir); |
| 84 | if (PINDIR_OUTPUT == pPinDir) // This is an output pin |
| 85 | { |
| 86 | if (Category == GUID_NULL || PinMatchesCategory(pin, Category)) |
| 87 | { |
| 88 | pPinEnum->Release(); |
| 89 | return pin; |
| 90 | } |
| 91 | } |
| 92 | pin->Release(); |
| 93 | pin = NULL; |
| 94 | } |
| 95 | pPinEnum->Release(); |
| 96 | return NULL; |
| 97 | } |
| 98 | |
| 99 | BOOL PinMatchesCategory(IPin *pPin, REFGUID Category) |
| 100 | { |
| 101 | BOOL bFound = FALSE; |
| 102 | IKsPropertySet *pKs = NULL; |
| 103 | HRESULT hr = pPin->QueryInterface(IID_PPV_ARGS(&pKs)); |
| 104 | if (SUCCEEDED(hr)) |
| 105 | { |
| 106 | GUID PinCategory; |
| 107 | DWORD cbReturned; |
| 108 | hr = pKs->Get(AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0, &PinCategory, |
| 109 | sizeof(GUID), &cbReturned); |
| 110 | if (SUCCEEDED(hr) && (cbReturned == sizeof(GUID))) |
| 111 | { |
| 112 | bFound = (PinCategory == Category); |
| 113 | } |
| 114 | pKs->Release(); |
| 115 | } |
| 116 | return bFound; |
| 117 | } |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 118 | } // namespace videocapturemodule |
| 119 | } // namespace webrtc |