Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

324 lines
12 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: DShowUtl.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: OrenR
  10. *
  11. * DATE: 2000/10/25
  12. *
  13. * DESCRIPTION: Provides supporting DShow utility functions used to build
  14. * preview graph
  15. *
  16. *****************************************************************************/
  17. #ifndef _DSHOWUTL_H_
  18. #define _DSHOWUTL_H_
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CAccessLock
  21. //
  22. // locks a critical section, and unlocks it automatically
  23. // when the lock goes out of scope
  24. //
  25. class CAccessLock
  26. {
  27. public:
  28. CAccessLock(CRITICAL_SECTION *pCritSec)
  29. {
  30. m_pLock = pCritSec;
  31. EnterCriticalSection(m_pLock);
  32. };
  33. ~CAccessLock()
  34. {
  35. LeaveCriticalSection(m_pLock);
  36. };
  37. static HRESULT Init(CRITICAL_SECTION *pCritSec)
  38. {
  39. HRESULT hr = S_OK;
  40. __try
  41. {
  42. if (!InitializeCriticalSectionAndSpinCount(pCritSec, MINLONG))
  43. {
  44. hr = HRESULT_FROM_WIN32(::GetLastError());
  45. CHECK_S_OK2(hr, ("CAccessLock::Init, failed to create Critical "
  46. "section "));
  47. }
  48. }
  49. __except(EXCEPTION_EXECUTE_HANDLER)
  50. {
  51. hr = E_OUTOFMEMORY;
  52. }
  53. return hr;
  54. }
  55. static HRESULT Term(CRITICAL_SECTION *pCritSec)
  56. {
  57. DeleteCriticalSection(pCritSec);
  58. return S_OK;
  59. }
  60. protected:
  61. CRITICAL_SECTION *m_pLock;
  62. private:
  63. // make copy constructor and assignment operator inaccessible
  64. CAccessLock(const CAccessLock &refAutoLock);
  65. CAccessLock &operator=(const CAccessLock &refAutoLock);
  66. };
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CWiaVideoProperties
  69. class CWiaVideoProperties
  70. {
  71. public:
  72. #define PREFERRED_SETTING_MASK_MEDIASUBTYPE 0x00000001
  73. #define PREFERRED_SETTING_MASK_VIDEO_WIDTH_HEIGHT 0x00000002
  74. #define PREFERRED_SETTING_MASK_VIDEO_FRAMERATE 0x00000004
  75. ////////////////////////
  76. // PictureAttribute_t
  77. //
  78. // Contains all information
  79. // that can be obtained
  80. // via the IAMVideoProcAmp
  81. // interface
  82. //
  83. typedef struct tagPictureAttribute_t
  84. {
  85. BOOL bUsed; // TRUE if attribute is implemented, FALSE otherwise
  86. VideoProcAmpProperty Name;
  87. LONG lCurrentValue;
  88. VideoProcAmpFlags CurrentFlag;
  89. LONG lMinValue;
  90. LONG lMaxValue;
  91. LONG lDefaultValue;
  92. LONG lIncrement;
  93. VideoProcAmpFlags ValidFlags;
  94. } PictureAttribute_t;
  95. ////////////////////////
  96. // CameraAttribute_t
  97. //
  98. // Contains all information
  99. // that can be obtained
  100. // via the IAMCameraControl
  101. // interface
  102. //
  103. typedef struct tagCameraAttribute_t
  104. {
  105. BOOL bUsed; // TRUE if attribute is implemented, FALSE otherwise
  106. CameraControlProperty Name;
  107. LONG lCurrentValue;
  108. CameraControlFlags CurrentFlag;
  109. LONG lMinValue;
  110. LONG lMaxValue;
  111. LONG lDefaultValue;
  112. LONG lIncrement;
  113. CameraControlFlags ValidFlags;
  114. } CameraAttribute_t;
  115. CWiaVideoProperties(const TCHAR *pszOptionalWiaDeviceID) :
  116. pMediaType(NULL),
  117. pVideoInfoHeader(NULL),
  118. dwFrameRate(0),
  119. bPictureAttributesUsed(FALSE),
  120. bCameraAttributesUsed(FALSE),
  121. PreferredWidth(0),
  122. PreferredHeight(0),
  123. PreferredFrameRate(0),
  124. PreferredSettingsMask(0)
  125. {
  126. ZeroMemory(&Brightness, sizeof(Brightness));
  127. ZeroMemory(&Contrast, sizeof(Contrast));
  128. ZeroMemory(&Hue, sizeof(Hue));
  129. ZeroMemory(&Saturation, sizeof(Saturation));
  130. ZeroMemory(&Sharpness, sizeof(Sharpness));
  131. ZeroMemory(&Gamma, sizeof(Gamma));
  132. ZeroMemory(&ColorEnable, sizeof(ColorEnable));
  133. ZeroMemory(&WhiteBalance, sizeof(WhiteBalance));
  134. ZeroMemory(&BacklightCompensation, sizeof(BacklightCompensation));
  135. ZeroMemory(&Pan, sizeof(Pan));
  136. ZeroMemory(&Tilt, sizeof(Tilt));
  137. ZeroMemory(&Roll, sizeof(Roll));
  138. ZeroMemory(&Zoom, sizeof(Zoom));
  139. ZeroMemory(&Exposure, sizeof(Exposure));
  140. ZeroMemory(&Iris, sizeof(Iris));
  141. ZeroMemory(&Focus, sizeof(Focus));
  142. ZeroMemory(szWiaDeviceID, sizeof(szWiaDeviceID));
  143. ZeroMemory(&PreferredMediaSubType, sizeof(PreferredMediaSubType));
  144. if (pszOptionalWiaDeviceID)
  145. {
  146. _tcsncpy(szWiaDeviceID,
  147. pszOptionalWiaDeviceID,
  148. sizeof(szWiaDeviceID) / sizeof(TCHAR) - 1);
  149. }
  150. }
  151. virtual ~CWiaVideoProperties()
  152. {
  153. if (pMediaType)
  154. {
  155. DeleteMediaType(pMediaType);
  156. pMediaType = NULL;
  157. pVideoInfoHeader = NULL;
  158. dwFrameRate = 0;
  159. bPictureAttributesUsed = FALSE;
  160. bCameraAttributesUsed = FALSE;
  161. }
  162. }
  163. TCHAR szWiaDeviceID[MAX_PATH + 1];
  164. DWORD PreferredSettingsMask;
  165. GUID PreferredMediaSubType;
  166. LONG PreferredWidth;
  167. LONG PreferredHeight;
  168. LONG PreferredFrameRate;
  169. AM_MEDIA_TYPE *pMediaType;
  170. VIDEOINFOHEADER *pVideoInfoHeader;
  171. DWORD dwFrameRate;
  172. BOOL bPictureAttributesUsed;
  173. PictureAttribute_t Brightness;
  174. PictureAttribute_t Contrast;
  175. PictureAttribute_t Hue;
  176. PictureAttribute_t Saturation;
  177. PictureAttribute_t Sharpness;
  178. PictureAttribute_t Gamma;
  179. PictureAttribute_t ColorEnable;
  180. PictureAttribute_t WhiteBalance;
  181. PictureAttribute_t BacklightCompensation;
  182. BOOL bCameraAttributesUsed;
  183. CameraAttribute_t Pan;
  184. CameraAttribute_t Tilt;
  185. CameraAttribute_t Roll;
  186. CameraAttribute_t Zoom;
  187. CameraAttribute_t Exposure;
  188. CameraAttribute_t Iris;
  189. CameraAttribute_t Focus;
  190. };
  191. /////////////////////////////////////////////////////////////////////////////
  192. // CDShowUtil
  193. class CDShowUtil
  194. {
  195. public:
  196. static HRESULT SizeVideoToWindow(HWND hwnd,
  197. IVideoWindow *pVideoWindow,
  198. BOOL bStretchToFit);
  199. static HRESULT ShowVideo(BOOL bShow,
  200. IVideoWindow *pVideoWindow);
  201. static HRESULT SetVideoWindowParent(HWND hwndParent,
  202. IVideoWindow *pVideoWindow,
  203. LONG *plOldWindowStyle);
  204. static HRESULT FindDeviceByEnumPos(LONG lEnumPos,
  205. CSimpleString *pstrDShowDeviceID,
  206. CSimpleString *pstrFriendlyName,
  207. IMoniker **ppDeviceMoniker);
  208. static HRESULT FindDeviceByFriendlyName(const CSimpleString *pstrFriendlyName,
  209. LONG *plEnumPos,
  210. CSimpleString *pstrDShowDeviceID,
  211. IMoniker **ppDeviceMoniker);
  212. static HRESULT FindDeviceByWiaID(class CWiaLink *pWiaLink,
  213. const CSimpleString *pstrWiaDeviceID,
  214. CSimpleString *pstrFriendlyName,
  215. LONG *plEnumPos,
  216. CSimpleString *pstrDShowDeviceID,
  217. IMoniker **ppDeviceMoniker);
  218. static HRESULT CreateGraphBuilder(ICaptureGraphBuilder2 **ppCaptureGraphBuilder,
  219. IGraphBuilder **ppGraphBuilder);
  220. static HRESULT GetMonikerProperty(IMoniker *pMoniker,
  221. LPCWSTR pwszProperty,
  222. CSimpleString *pstrProperty);
  223. static HRESULT SetPreferredVideoFormat(IPin *pCapturePin,
  224. const GUID *pPreferredSubType,
  225. LONG lPreferredWidth,
  226. LONG lPreferredHeight,
  227. CWiaVideoProperties *pVideoProperties);
  228. static HRESULT SetFrameRate(IPin *pCapturePin,
  229. LONG lNewFrameRate,
  230. CWiaVideoProperties *pVideoProperties);
  231. static HRESULT GetFrameRate(IPin *pCapturePin,
  232. LONG *plFrameRate);
  233. static HRESULT GetPin(IBaseFilter *pFilter,
  234. PIN_DIRECTION PinDirection,
  235. IPin **ppPin);
  236. static HRESULT GetVideoProperties(IBaseFilter *pCaptureFilter,
  237. IPin *pCapturePin,
  238. CWiaVideoProperties *pVideoProperties);
  239. static HRESULT SetPictureAttribute(IBaseFilter *pCaptureFilter,
  240. CWiaVideoProperties::PictureAttribute_t *pPictureAttribute,
  241. LONG lNewValue,
  242. VideoProcAmpFlags lNewFlag);
  243. static HRESULT SetCameraAttribute(IBaseFilter *pCaptureFilter,
  244. CWiaVideoProperties::CameraAttribute_t *pCameraAttribute,
  245. LONG lNewValue,
  246. CameraControlFlags lNewFlag);
  247. static HRESULT TurnOffGraphClock(IGraphBuilder *pGraphBuilder);
  248. static void GUIDToString(const GUID &clsid,
  249. WCHAR *pwszGUID,
  250. ULONG ulNumChars);
  251. static void DumpCaptureMoniker(IMoniker *pCaptureDeviceMoniker);
  252. static void MyDumpVideoProperties(CWiaVideoProperties *pVideoProperties);
  253. static void MyDumpGraph(LPCTSTR Description,
  254. IGraphBuilder *pGraphBuilder);
  255. static void MyDumpFilter(IBaseFilter *pFilter);
  256. static void MyDumpAllPins(IBaseFilter *const pFilter);
  257. static void MyDumpPin(IPin *pPin);
  258. private:
  259. static HRESULT FindDeviceGeneric(UINT uiFindFlag,
  260. CSimpleString *pstrDShowDeviceID,
  261. LONG *plEnumPos,
  262. CSimpleString *pstrFriendlyName,
  263. IMoniker **ppDeviceMoniker);
  264. static HRESULT GetDeviceProperty(IPropertyBag *pPropertyBag,
  265. LPCWSTR pwszProperty,
  266. CSimpleString *pstrProperty);
  267. };
  268. #endif // _DSHOWUTL_H_