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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "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 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 19 | namespace webrtc { |
| 20 | namespace videocapturemodule { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | // This returns minimum :), which will give max frame rate... |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 22 | LONGLONG GetMaxOfFrameArray(LONGLONG* maxFps, long size) { |
| 23 | LONGLONG maxFPS = maxFps[0]; |
| 24 | for (int i = 0; i < size; i++) { |
| 25 | if (maxFPS > maxFps[i]) |
| 26 | maxFPS = maxFps[i]; |
| 27 | } |
| 28 | return maxFPS; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 31 | IPin* GetInputPin(IBaseFilter* filter) { |
| 32 | HRESULT hr; |
| 33 | IPin* pin = NULL; |
| 34 | IEnumPins* pPinEnum = NULL; |
| 35 | filter->EnumPins(&pPinEnum); |
| 36 | if (pPinEnum == NULL) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | return NULL; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // get first unconnected pin |
| 41 | hr = pPinEnum->Reset(); // set to first pin |
| 42 | |
| 43 | while (S_OK == pPinEnum->Next(1, &pin, NULL)) { |
| 44 | PIN_DIRECTION pPinDir; |
| 45 | pin->QueryDirection(&pPinDir); |
| 46 | if (PINDIR_INPUT == pPinDir) // This is an input pin |
| 47 | { |
| 48 | IPin* tempPin = NULL; |
| 49 | if (S_OK != pin->ConnectedTo(&tempPin)) // The pint is not connected |
| 50 | { |
| 51 | pPinEnum->Release(); |
| 52 | return pin; |
| 53 | } |
| 54 | } |
| 55 | pin->Release(); |
| 56 | } |
| 57 | pPinEnum->Release(); |
| 58 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 61 | IPin* GetOutputPin(IBaseFilter* filter, REFGUID Category) { |
| 62 | HRESULT hr; |
| 63 | IPin* pin = NULL; |
| 64 | IEnumPins* pPinEnum = NULL; |
| 65 | filter->EnumPins(&pPinEnum); |
| 66 | if (pPinEnum == NULL) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | return NULL; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 68 | } |
| 69 | // get first unconnected pin |
| 70 | hr = pPinEnum->Reset(); // set to first pin |
| 71 | while (S_OK == pPinEnum->Next(1, &pin, NULL)) { |
| 72 | PIN_DIRECTION pPinDir; |
| 73 | pin->QueryDirection(&pPinDir); |
| 74 | if (PINDIR_OUTPUT == pPinDir) // This is an output pin |
| 75 | { |
| 76 | if (Category == GUID_NULL || PinMatchesCategory(pin, Category)) { |
| 77 | pPinEnum->Release(); |
| 78 | return pin; |
| 79 | } |
| 80 | } |
| 81 | pin->Release(); |
| 82 | pin = NULL; |
| 83 | } |
| 84 | pPinEnum->Release(); |
| 85 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 88 | BOOL PinMatchesCategory(IPin* pPin, REFGUID Category) { |
| 89 | BOOL bFound = FALSE; |
| 90 | IKsPropertySet* pKs = NULL; |
| 91 | HRESULT hr = pPin->QueryInterface(IID_PPV_ARGS(&pKs)); |
| 92 | if (SUCCEEDED(hr)) { |
| 93 | GUID PinCategory; |
| 94 | DWORD cbReturned; |
| 95 | hr = pKs->Get(AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0, |
| 96 | &PinCategory, sizeof(GUID), &cbReturned); |
| 97 | if (SUCCEEDED(hr) && (cbReturned == sizeof(GUID))) { |
| 98 | bFound = (PinCategory == Category); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 100 | pKs->Release(); |
| 101 | } |
| 102 | return bFound; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | } |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 104 | } // namespace videocapturemodule |
| 105 | } // namespace webrtc |