Source code of Windows XP (NT5)
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.

175 lines
5.8 KiB

  1. //==========================================================================;
  2. //
  3. // Composition.h : Declaration of the custom composition class for gluing analog capture to ovmixer
  4. // Copyright (c) Microsoft Corporation 1999.
  5. //
  6. /////////////////////////////////////////////////////////////////////////////
  7. #ifndef ANA2XDS_H
  8. #define ANA2XDS_H
  9. #pragma once
  10. #include <winerror.h>
  11. #include <algorithm>
  12. #include <compimpl.h>
  13. #include <seg.h>
  14. #include "resource.h" // main symbols
  15. #include <objectwithsiteimplsec.h>
  16. #include "dsextend.h"
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CAna2XDSComp
  19. class ATL_NO_VTABLE __declspec(uuid("3540D440-5B1D-49cb-821A-E84B8CF065A7")) CAna2XDSComp :
  20. public CComObjectRootEx<CComSingleThreadModel>,
  21. public CComCoClass<CAna2XDSComp, &__uuidof(CAna2XDSComp)>,
  22. public IObjectWithSiteImplSec<CAna2XDSComp>,
  23. public IMSVidCompositionSegmentImpl<CAna2XDSComp>
  24. {
  25. public:
  26. CAna2XDSComp() {}
  27. virtual ~CAna2XDSComp() {}
  28. REGISTER_NONAUTOMATION_OBJECT(IDS_PROJNAME,
  29. IDS_REG_ANA2XDSCOMP_DESC,
  30. LIBID_MSVidCtlLib,
  31. __uuidof(CAna2XDSComp));
  32. DECLARE_PROTECT_FINAL_CONSTRUCT()
  33. BEGIN_COM_MAP(CAna2XDSComp)
  34. COM_INTERFACE_ENTRY(IMSVidCompositionSegment)
  35. COM_INTERFACE_ENTRY(IMSVidGraphSegment)
  36. COM_INTERFACE_ENTRY(IObjectWithSite)
  37. COM_INTERFACE_ENTRY(IPersist)
  38. END_COM_MAP()
  39. public:
  40. PQCreateDevEnum m_pSystemEnum;
  41. //////////////
  42. // IMSVidGraphSegment
  43. // IMSVidCompositionSegment
  44. STDMETHOD(Compose)(IMSVidGraphSegment * upstream, IMSVidGraphSegment * downstream)
  45. {
  46. TRACELM(TRACE_ERROR, "CVidCtl::Ana2XDS() Compose");
  47. if (m_fComposed) {
  48. return NOERROR;
  49. }
  50. ASSERT(m_pGraph);
  51. try {
  52. #if 0
  53. VWGraphSegment up(upstream);
  54. ASSERT(up.Graph() == m_pGraph);
  55. VWGraphSegment down(downstream);
  56. ASSERT(down.Graph() == m_pGraph);
  57. if (up.begin() == up.end()) {
  58. TRACELM(TRACE_ERROR, "CAna2XDSComp::Compose() can't compose empty up segment");
  59. return E_INVALIDARG;
  60. }
  61. if (down.begin() == down.end()) {
  62. TRACELM(TRACE_ERROR, "CAna2XDSComp::Compose() can't compose empty down segment");
  63. return E_INVALIDARG;
  64. }
  65. VWGraphSegment::iterator iCap;
  66. for(iCap = up.begin(); iCap != up.end(); ++iCap){
  67. if(IsAnalogVideoCapture(*iCap)){
  68. break;
  69. }
  70. }
  71. if (iCap == up.end()) {
  72. TRACELM(TRACE_ERROR, "CAna2XDSComp::Compose() upstream segment has no capture filter");
  73. return E_FAIL;
  74. }
  75. ASSERT((*iCap).GetGraph() == m_pGraph);
  76. DSFilter::iterator iVbi;
  77. for(iVbi = (*iCap).begin(); iVbi != (*iCap).end(); ++iVbi){
  78. if((*iVbi).HasCategory(PIN_CATEGORY_VBI)){
  79. break;
  80. }
  81. }
  82. if(iVbi == (*iCap).end()){
  83. TRACELM(TRACE_ERROR, "CAna2XDSComp::Compose() capture filter has no vbi");
  84. return E_FAIL;
  85. }
  86. HRESULT hr = S_OK;
  87. DSFilterList intermediates;
  88. for(VWGraphSegment::iterator pXDS = down.begin(); pXDS != down.end(); ++pXDS){
  89. hr = (*iVbi).IntelligentConnect((*pXDS), intermediates);
  90. if(FAILED(hr)){
  91. continue;
  92. }
  93. else{
  94. break;
  95. }
  96. }
  97. if(FAILED(hr)){
  98. TRACELM(TRACE_ERROR, "CAna2XDSComp::Compose() can't connect vbi to xds");
  99. return hr;
  100. }
  101. m_Filters.insert(m_Filters.end(), intermediates.begin(), intermediates.end());
  102. return NOERROR;
  103. #else
  104. VWGraphSegment up(upstream);
  105. ASSERT(up.Graph() == m_pGraph);
  106. VWGraphSegment down(downstream);
  107. ASSERT(down.Graph() == m_pGraph);
  108. if (upstream == downstream) {
  109. return Error(IDS_CANT_COMPOSE_WITH_SELF, __uuidof(IMSVidCompositionSegment), E_INVALIDARG);
  110. }
  111. if (up.begin() == up.end()) {
  112. TRACELM(TRACE_ERROR, "CComposition::Compose() can't compose empty up segment");
  113. return NOERROR;
  114. }
  115. if (down.begin() == down.end()) {
  116. TRACELM(TRACE_ERROR, "CComposition::Compose() can't compose empty down segment");
  117. // this is not an error, for example, CA is an empty segment.
  118. return NOERROR;
  119. }
  120. // do the list backwards
  121. DSFilterList upF;
  122. for(VWGraphSegment::iterator upStart = up.begin(); upStart != up.end(); ++upStart){
  123. upF.push_back(*upStart);
  124. }
  125. for (DSFilterList::reverse_iterator iStart = upF.rbegin(); iStart != upF.rend(); ++iStart) {
  126. ASSERT((*iStart).GetGraph() == m_pGraph);
  127. for (VWGraphSegment::iterator iStop = down.begin(); iStop != down.end(); ++iStop) {
  128. ASSERT((*iStop).GetGraph() == m_pGraph);
  129. DSFilter pStart(*iStart);
  130. DSFilter pStop(*iStop);
  131. // HRESULT hr = m_pGraph.Connect(pStart, pStop, m_Filters);
  132. HRESULT hr = m_pGraph.Connect(pStop, pStart, m_Filters, 0, UPSTREAM);
  133. if (SUCCEEDED(hr)) {
  134. m_Segments.push_back(up);
  135. m_Segments.push_back(down);
  136. m_pDown = m_Segments.end();
  137. --m_pDown;
  138. m_pUp = m_pDown;
  139. --m_pUp;
  140. m_fComposed = true;
  141. return NOERROR;
  142. }
  143. }
  144. }
  145. TRACELM(TRACE_ERROR, "CComposition::Compose() compose didn't connect anything");
  146. return Error(IDS_CANT_COMPOSE, __uuidof(IMSVidCompositionSegment), E_FAIL);
  147. #endif
  148. } catch (ComException &e) {
  149. return e;
  150. } catch (...) {
  151. return E_UNEXPECTED;
  152. }
  153. }
  154. };
  155. #endif // Ana2XDS_H
  156. // end of file - Ana2XDS.h