1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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
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
15 #include "webrtc/modules/video_capture/windows/help_functions_ds.h"
16
17 #include <cguid.h>
18
19 namespace webrtc
20 {
21 namespace videocapturemodule
22 {
23 // This returns minimum :), which will give max frame rate...
GetMaxOfFrameArray(LONGLONG * maxFps,long size)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
GetInputPin(IBaseFilter * filter)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
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
GetOutputPin(IBaseFilter * filter,REFGUID Category)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
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
PinMatchesCategory(IPin * pPin,REFGUID Category)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 }
118 } // namespace videocapturemodule
119 } // namespace webrtc
120