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.

522 lines
11 KiB

  1. // File: ichnlvid.cpp
  2. #include "precomp.h"
  3. #include "ichnlvid.h"
  4. typedef struct
  5. {
  6. DWORD *pdwCapDevIDs;
  7. LPTSTR pszCapDevNames;
  8. DWORD dwNumCapDev;
  9. } ENUM_CAP_DEV;
  10. static HRESULT OnNotifyStateChanged(IUnknown *pChannelNotify, PVOID pv, REFIID riid);
  11. static HRESULT OnNotifyPropertyChanged(IUnknown *pChannelNotify, PVOID pv, REFIID riid);
  12. static const IID * g_apiidCP[] =
  13. {
  14. {&IID_INmChannelNotify},
  15. {&IID_INmChannelVideoNotify}
  16. };
  17. CNmChannelVideo * CNmChannelVideo::m_pPreviewChannel = NULL;
  18. CNmChannelVideo::CNmChannelVideo(BOOL fIncoming) :
  19. CConnectionPointContainer(g_apiidCP, ARRAY_ELEMENTS(g_apiidCP)),
  20. m_VideoPump(!fIncoming /* fLocal */),
  21. m_cMembers (0),
  22. m_fIncoming(fIncoming),
  23. m_pMediaChannel(NULL),
  24. m_pCommChannel(NULL),
  25. m_MediaFormat(INVALID_MEDIA_FORMAT)
  26. {
  27. if (NULL != g_pH323UI)
  28. {
  29. IH323CallControl * pH323CallControl = g_pH323UI->GetH323CallControl();
  30. IMediaChannelBuilder * pMCProvider = g_pH323UI->GetStreamProvider();
  31. IVideoDevice *pVideoDevice=NULL;
  32. ASSERT((NULL != pH323CallControl) && (NULL != pMCProvider));
  33. pMCProvider->CreateMediaChannel(MCF_VIDEO | (fIncoming ? MCF_RECV : MCF_SEND), &m_pMediaChannel);
  34. if (m_pMediaChannel)
  35. {
  36. pMCProvider->QueryInterface(IID_IVideoDevice, (void**)&pVideoDevice);
  37. m_VideoPump.Initialize(pH323CallControl, m_pMediaChannel, pVideoDevice, (DWORD_PTR)this, FrameReadyCallback);
  38. pVideoDevice->Release();
  39. }
  40. pMCProvider->Release();
  41. }
  42. DbgMsg(iZONE_OBJECTS, "Obj: %08X created CNmChannelVideo", this);
  43. }
  44. CNmChannelVideo::~CNmChannelVideo()
  45. {
  46. if (!m_fIncoming)
  47. {
  48. // make sure we're no longer capturing
  49. m_VideoPump.EnableXfer(FALSE);
  50. }
  51. if (this == m_pPreviewChannel)
  52. {
  53. m_pPreviewChannel = NULL;
  54. }
  55. if (NULL != m_pCommChannel)
  56. {
  57. m_pCommChannel->Release();
  58. }
  59. if (NULL != m_pMediaChannel)
  60. {
  61. m_pMediaChannel->Release();
  62. }
  63. DbgMsg(iZONE_OBJECTS, "Obj: %08X destroyed CNmChannelVideo", this);
  64. }
  65. VOID CNmChannelVideo::CommChannelOpened(ICommChannel *pCommChannel)
  66. {
  67. ASSERT(NULL == m_pCommChannel);
  68. m_pCommChannel = pCommChannel;
  69. m_pCommChannel->AddRef();
  70. }
  71. VOID CNmChannelVideo::CommChannelActive(ICommChannel *pCommChannel)
  72. {
  73. ASSERT(m_pCommChannel == pCommChannel);
  74. m_VideoPump.OnChannelOpened(pCommChannel);
  75. OnStateChange();
  76. }
  77. VOID CNmChannelVideo::CommChannelClosed()
  78. {
  79. if (NULL != m_pCommChannel)
  80. {
  81. m_pCommChannel->Release();
  82. m_pCommChannel = NULL;
  83. m_VideoPump.OnChannelClosed();
  84. OnStateChange();
  85. }
  86. }
  87. CNmChannelVideo * CNmChannelVideo::CreateChannel(BOOL fIncoming)
  88. {
  89. if (fIncoming)
  90. {
  91. return new CNmChannelVideo(TRUE /* fIncoming */);
  92. }
  93. else
  94. {
  95. if (NULL != m_pPreviewChannel)
  96. {
  97. m_pPreviewChannel->AddRef();
  98. }
  99. return m_pPreviewChannel;
  100. }
  101. }
  102. CNmChannelVideo * CNmChannelVideo::CreatePreviewChannel()
  103. {
  104. ASSERT(NULL == m_pPreviewChannel);
  105. m_pPreviewChannel = new CNmChannelVideo(FALSE /* fIncoming */);
  106. if (NULL != m_pPreviewChannel)
  107. {
  108. if (!m_pPreviewChannel->IsCaptureAvailable())
  109. {
  110. delete m_pPreviewChannel;
  111. m_pPreviewChannel = NULL;
  112. }
  113. }
  114. return m_pPreviewChannel;
  115. }
  116. VOID CNmChannelVideo::OnMemberAdded(CNmMember *pMember)
  117. {
  118. // Don't add to the channel if we already belong.
  119. if (0 != (pMember->GetNmchCaps() & NMCH_VIDEO))
  120. {
  121. return;
  122. }
  123. ++m_cMembers;
  124. pMember->AddNmchCaps(NMCH_VIDEO);
  125. CConfObject *pco = ::GetConfObject();
  126. pco->OnMemberUpdated(pMember);
  127. NotifySink((INmMember *) pMember, OnNotifyChannelMemberAdded);
  128. }
  129. VOID CNmChannelVideo::OnMemberRemoved(CNmMember *pMember)
  130. {
  131. // If member does not belong to this channel, don't remove it.
  132. if (0 == (pMember->GetNmchCaps() & NMCH_VIDEO))
  133. {
  134. return;
  135. }
  136. --m_cMembers;
  137. pMember->RemoveNmchCaps(NMCH_VIDEO);
  138. CConfObject *pco = ::GetConfObject();
  139. pco->OnMemberUpdated(pMember);
  140. NotifySink((INmMember *) pMember, OnNotifyChannelMemberRemoved);
  141. }
  142. VOID CNmChannelVideo::OnMemberUpdated(CNmMember *pMember)
  143. {
  144. NotifySink((INmMember *) pMember, OnNotifyChannelMemberUpdated);
  145. }
  146. VOID CNmChannelVideo::OnStateChange()
  147. {
  148. NM_VIDEO_STATE state;
  149. GetState(&state);
  150. NotifySink((PVOID) state, OnNotifyStateChanged);
  151. }
  152. VOID CNmChannelVideo::OnFrameAvailable()
  153. {
  154. NotifySink((PVOID) NM_VIDPROP_FRAME, OnNotifyPropertyChanged);
  155. }
  156. VOID CNmChannelVideo::Open()
  157. {
  158. ASSERT(m_MediaFormat != INVALID_MEDIA_FORMAT);
  159. m_VideoPump.Open(m_MediaFormat);
  160. }
  161. VOID CNmChannelVideo::Close()
  162. {
  163. m_VideoPump.Close();
  164. }
  165. STDMETHODIMP_(ULONG) CNmChannelVideo::AddRef(void)
  166. {
  167. return RefCount::AddRef();
  168. }
  169. STDMETHODIMP_(ULONG) CNmChannelVideo::Release(void)
  170. {
  171. return RefCount::Release();
  172. }
  173. STDMETHODIMP CNmChannelVideo::QueryInterface(REFIID riid, PVOID *ppv)
  174. {
  175. HRESULT hr = S_OK;
  176. if ((riid == IID_INmChannelVideo) || (riid == IID_INmChannel) || (riid == IID_IUnknown))
  177. {
  178. *ppv = (INmChannel *)this;
  179. DbgMsgApi("CNmChannelVideo::QueryInterface()");
  180. }
  181. else if (riid == IID_IConnectionPointContainer)
  182. {
  183. *ppv = (IConnectionPointContainer *) this;
  184. DbgMsgApi("CNmChannelVideo::QueryInterface(): Returning IConnectionPointContainer.");
  185. }
  186. else
  187. {
  188. hr = E_NOINTERFACE;
  189. *ppv = NULL;
  190. DbgMsgApi("CNmChannelVideo::QueryInterface(): Called on unknown interface.");
  191. }
  192. if (S_OK == hr)
  193. {
  194. AddRef();
  195. }
  196. return hr;
  197. }
  198. STDMETHODIMP CNmChannelVideo::IsSameAs(INmChannel *pChannel)
  199. {
  200. return (((INmChannel *) this) == pChannel) ? S_OK : S_FALSE;
  201. }
  202. STDMETHODIMP CNmChannelVideo::IsActive()
  203. {
  204. return (NULL != m_pCommChannel) ? S_OK : S_FALSE;
  205. }
  206. STDMETHODIMP CNmChannelVideo::SetActive(BOOL fActive)
  207. {
  208. return E_FAIL;
  209. }
  210. STDMETHODIMP CNmChannelVideo::GetConference(INmConference **ppConference)
  211. {
  212. return ::GetConference(ppConference);
  213. }
  214. STDMETHODIMP CNmChannelVideo::GetInterface(IID *piid)
  215. {
  216. HRESULT hr = E_POINTER;
  217. if (NULL != piid)
  218. {
  219. *piid = IID_INmChannelVideo;
  220. hr = S_OK;
  221. }
  222. return hr;
  223. }
  224. STDMETHODIMP CNmChannelVideo::GetNmch(ULONG *puCh)
  225. {
  226. HRESULT hr = E_POINTER;
  227. if (NULL != puCh)
  228. {
  229. *puCh = NMCH_VIDEO;
  230. hr = S_OK;
  231. }
  232. return hr;
  233. }
  234. STDMETHODIMP CNmChannelVideo::EnumMember(IEnumNmMember **ppEnum)
  235. {
  236. HRESULT hr = E_POINTER;
  237. if (NULL != ppEnum)
  238. {
  239. int cMembers = 0;
  240. COBLIST MemberList;
  241. COBLIST* pPartList = ::GetMemberList();
  242. if (NULL != pPartList)
  243. {
  244. POSITION pos = pPartList->GetHeadPosition();
  245. while (pos)
  246. {
  247. CNmMember * pMember = (CNmMember *) pPartList->GetNext(pos);
  248. ASSERT(NULL != pMember);
  249. if (NMCH_AUDIO & pMember->GetNmchCaps())
  250. {
  251. MemberList.AddTail(pMember);
  252. pMember->AddRef();
  253. cMembers++;
  254. }
  255. }
  256. }
  257. *ppEnum = new CEnumNmMember(&MemberList, cMembers);
  258. while (!MemberList.IsEmpty())
  259. {
  260. INmMember *pMember = (INmMember *) (CNmMember *) MemberList.RemoveHead();
  261. pMember->Release();
  262. }
  263. hr = (NULL != *ppEnum)? S_OK : E_OUTOFMEMORY;
  264. }
  265. return hr;
  266. }
  267. STDMETHODIMP CNmChannelVideo::GetMemberCount(ULONG * puCount)
  268. {
  269. HRESULT hr = E_POINTER;
  270. if (NULL != puCount)
  271. {
  272. *puCount = m_cMembers;
  273. hr = S_OK;
  274. }
  275. return hr;
  276. }
  277. STDMETHODIMP CNmChannelVideo::IsIncoming(void)
  278. {
  279. return m_fIncoming ? S_OK : S_FALSE;
  280. }
  281. STDMETHODIMP CNmChannelVideo::GetState(NM_VIDEO_STATE *puState)
  282. {
  283. HRESULT hr = E_POINTER;
  284. if (NULL != puState)
  285. {
  286. *puState = m_VideoPump.GetState();
  287. hr = S_OK;
  288. }
  289. return hr;
  290. }
  291. STDMETHODIMP CNmChannelVideo::GetProperty(NM_VIDPROP uID, ULONG_PTR *puValue)
  292. {
  293. HRESULT hr = S_OK;
  294. switch (uID)
  295. {
  296. case NM_VIDPROP_PAUSE:
  297. *puValue = m_VideoPump.IsPaused();
  298. break;
  299. case NM_VIDPROP_IMAGE_PREFERRED_SIZE:
  300. *puValue = m_VideoPump.GetFrameSize();
  301. break;
  302. case NM_VIDPROP_IMAGE_QUALITY:
  303. if (m_fIncoming)
  304. {
  305. *puValue = m_VideoPump.GetReceiveQuality();
  306. }
  307. break;
  308. case NM_VIDPROP_CAMERA_DIALOG:
  309. *puValue = 0;
  310. if (m_VideoPump.HasSourceDialog())
  311. {
  312. *puValue |= NM_VIDEO_SOURCE_DIALOG;
  313. }
  314. if (m_VideoPump.HasFormatDialog())
  315. {
  316. *puValue |= NM_VIDEO_FORMAT_DIALOG;
  317. }
  318. break;
  319. case NM_VIDPROP_IMAGE_SIZES:
  320. // get all the sizes, not just a size for one video format
  321. *puValue = m_VideoPump.GetFrameSizes(INVALID_MEDIA_FORMAT);
  322. break;
  323. case NM_VIDPROP_FRAME:
  324. {
  325. FRAMECONTEXT *pfc = (FRAMECONTEXT*) puValue;
  326. hr = m_VideoPump.GetFrame(pfc);
  327. break;
  328. }
  329. case NM_VIDPROP_NUM_CAPTURE_DEVS:
  330. *puValue = m_VideoPump.GetNumCapDev();
  331. break;
  332. case NM_VIDPROP_CAPTURE_DEV_ID:
  333. *puValue = m_VideoPump.GetCurrCapDevID();
  334. break;
  335. case NM_VIDPROP_MAX_CAPTURE_NAME:
  336. *puValue = m_VideoPump.GetMaxCapDevNameLen();
  337. break;
  338. case NM_VIDPROP_CAPTURE_LIST:
  339. {
  340. ENUM_CAP_DEV *pEnumCapDev = (ENUM_CAP_DEV *)puValue;
  341. if(m_VideoPump.EnumCapDev(pEnumCapDev->pdwCapDevIDs,
  342. pEnumCapDev->pszCapDevNames,
  343. pEnumCapDev->dwNumCapDev))
  344. {
  345. hr = E_FAIL;
  346. }
  347. break;
  348. }
  349. default:
  350. hr = E_INVALIDARG;
  351. break;
  352. }
  353. return hr;
  354. }
  355. STDMETHODIMP CNmChannelVideo::SetProperty(NM_VIDPROP uID, ULONG_PTR uValue)
  356. {
  357. HRESULT hr = S_OK;
  358. switch (uID)
  359. {
  360. case NM_VIDPROP_PAUSE:
  361. m_VideoPump.Pause(uValue);
  362. OnStateChange();
  363. break;
  364. case NM_VIDPROP_IMAGE_PREFERRED_SIZE:
  365. switch(uValue)
  366. {
  367. case NM_VIDEO_SMALL:
  368. case NM_VIDEO_MEDIUM:
  369. case NM_VIDEO_LARGE:
  370. m_VideoPump.SetFrameSize(uValue);
  371. break;
  372. default:
  373. hr = E_INVALIDARG;
  374. break;
  375. }
  376. break;
  377. case NM_VIDPROP_IMAGE_QUALITY:
  378. if /* ((uValue >= NM_VIDEO_MIN_QUALITY) || Always True */ ((uValue <= NM_VIDEO_MAX_QUALITY))
  379. {
  380. if (m_fIncoming)
  381. {
  382. m_VideoPump.SetReceiveQuality(uValue);
  383. }
  384. }
  385. else
  386. {
  387. hr = E_INVALIDARG;
  388. }
  389. break;
  390. case NM_VIDPROP_CAMERA_DIALOG:
  391. switch(uValue)
  392. {
  393. case NM_VIDEO_SOURCE_DIALOG:
  394. m_VideoPump.ShowSourceDialog();
  395. break;
  396. case NM_VIDEO_FORMAT_DIALOG:
  397. m_VideoPump.ShowFormatDialog();
  398. break;
  399. default:
  400. hr = E_INVALIDARG;
  401. break;
  402. }
  403. break;
  404. case NM_VIDPROP_SUSPEND_CAPTURE:
  405. m_VideoPump.SuspendCapture(uValue);
  406. break;
  407. case NM_VIDPROP_FRAME:
  408. hr = m_VideoPump.ReleaseFrame((FRAMECONTEXT *)uValue);
  409. break;
  410. case NM_VIDPROP_CAPTURE_DEV_ID:
  411. m_VideoPump.SetCurrCapDevID(uValue);
  412. break;
  413. default:
  414. hr = E_INVALIDARG;
  415. break;
  416. }
  417. return hr;
  418. }
  419. VOID __stdcall CNmChannelVideo::FrameReadyCallback(DWORD_PTR dwMyThis)
  420. {
  421. CNmChannelVideo *pChannel = (CNmChannelVideo *)dwMyThis;
  422. if (NULL != pChannel)
  423. {
  424. pChannel->OnFrameAvailable();
  425. }
  426. }
  427. /* O N N O T I F Y S T A T E C H A N G E D */
  428. /*-------------------------------------------------------------------------
  429. %%Function: OnNotifyStateChanged
  430. -------------------------------------------------------------------------*/
  431. HRESULT OnNotifyStateChanged(IUnknown *pChannelNotify, PVOID pv, REFIID riid)
  432. {
  433. ASSERT(NULL != pChannelNotify);
  434. if (IID_INmChannelVideoNotify == riid)
  435. {
  436. ((INmChannelVideoNotify*)pChannelNotify)->StateChanged((NM_VIDEO_STATE) (DWORD)((DWORD_PTR)pv));
  437. }
  438. return S_OK;
  439. }
  440. /* O N N O T I F Y P R O P E R T Y C H A N G E D */
  441. /*-------------------------------------------------------------------------
  442. %%Function: OnNotifyPropertyChanged
  443. -------------------------------------------------------------------------*/
  444. HRESULT OnNotifyPropertyChanged(IUnknown *pChannelNotify, PVOID pv, REFIID riid)
  445. {
  446. ASSERT(NULL != pChannelNotify);
  447. if (IID_INmChannelVideoNotify == riid)
  448. {
  449. ((INmChannelVideoNotify*)pChannelNotify)->PropertyChanged((DWORD)((DWORD_PTR)pv));
  450. }
  451. return S_OK;
  452. }
  453.