blob: ab85da948883591d612451413fd5e2182f26d3ae [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
andrew@webrtc.orge713fd02012-04-10 07:13:46 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org81878772012-11-20 13:35:33 +000011#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 Bonadei92ea95e2017-09-15 06:47:31 +020015#include "modules/video_capture/windows/help_functions_ds.h"
tommi@webrtc.org81878772012-11-20 13:35:33 +000016
17#include <cguid.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000018
Yves Gerey665174f2018-06-19 15:03:05 +020019namespace webrtc {
20namespace videocapturemodule {
niklase@google.com470e71d2011-07-07 08:21:25 +000021// This returns minimum :), which will give max frame rate...
Yves Gerey665174f2018-06-19 15:03:05 +020022LONGLONG 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.com470e71d2011-07-07 08:21:25 +000029}
30
Yves Gerey665174f2018-06-19 15:03:05 +020031IPin* GetInputPin(IBaseFilter* filter) {
32 HRESULT hr;
33 IPin* pin = NULL;
34 IEnumPins* pPinEnum = NULL;
35 filter->EnumPins(&pPinEnum);
36 if (pPinEnum == NULL) {
niklase@google.com470e71d2011-07-07 08:21:25 +000037 return NULL;
Yves Gerey665174f2018-06-19 15:03:05 +020038 }
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.com470e71d2011-07-07 08:21:25 +000059}
60
Yves Gerey665174f2018-06-19 15:03:05 +020061IPin* 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.com470e71d2011-07-07 08:21:25 +000067 return NULL;
Yves Gerey665174f2018-06-19 15:03:05 +020068 }
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.com470e71d2011-07-07 08:21:25 +000086}
87
Yves Gerey665174f2018-06-19 15:03:05 +020088BOOL 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.com470e71d2011-07-07 08:21:25 +000099 }
Yves Gerey665174f2018-06-19 15:03:05 +0200100 pKs->Release();
101 }
102 return bFound;
niklase@google.com470e71d2011-07-07 08:21:25 +0000103}
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000104} // namespace videocapturemodule
105} // namespace webrtc