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.

177 lines
5.3 KiB

  1. //==========================================================================;
  2. // MSVidXDS.cpp : Declaration of the CMSVidXDS
  3. // copyright (c) Microsoft Corp. 1998-1999.
  4. /////////////////////////////////////////////////////////////////////////////
  5. #include "stdafx.h"
  6. #ifndef TUNING_MODEL_ONLY
  7. #include "msvidXDS.h"
  8. #include <winerror.h>
  9. #include <algorithm>
  10. #include "segimpl.h"
  11. #include "devices.h"
  12. #include <compimpl.h>
  13. #include <seg.h>
  14. #include <objectwithsiteimplsec.h>
  15. #include "resource.h" // main symbols
  16. DEFINE_EXTERN_OBJECT_ENTRY(CLSID_MSVidXDS, CXDS)
  17. HRESULT CXDS::Unload(void) {
  18. IMSVidGraphSegmentImpl<CXDS, MSVidSEG_XFORM, &GUID_NULL>::Unload();
  19. m_iIPSink = -1;
  20. return NOERROR;
  21. }
  22. // IMSVidGraphSegment
  23. STDMETHODIMP CXDS::Build() {
  24. return NOERROR;
  25. }
  26. STDMETHODIMP CXDS::PreRun() {
  27. return NOERROR;
  28. }
  29. STDMETHODIMP CXDS::put_Container(IMSVidGraphSegmentContainer *pCtl){
  30. if (!m_fInit) {
  31. return CO_E_NOTINITIALIZED;
  32. }
  33. try {
  34. if (!pCtl) {
  35. return Unload();
  36. }
  37. if (m_pContainer) {
  38. if (!m_pContainer.IsEqualObject(VWSegmentContainer(pCtl))) {
  39. return Error(IDS_OBJ_ALREADY_INIT, __uuidof(IMSVidXDS), CO_E_ALREADYINITIALIZED);
  40. } else {
  41. return NO_ERROR;
  42. }
  43. }
  44. // DON'T addref the container. we're guaranteed nested lifetimes
  45. // and an addref creates circular refcounts so we never unload.
  46. m_pContainer.p = pCtl;
  47. m_pGraph = m_pContainer.GetGraph();
  48. if (!m_pSystemEnum) {
  49. HRESULT hr = m_pSystemEnum.CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER);
  50. if (FAILED(hr)) {
  51. return E_UNEXPECTED;
  52. }
  53. }
  54. PQVidCtl pqCtl;
  55. HRESULT hr = m_pContainer->QueryInterface(IID_IMSVidCtl, reinterpret_cast<void**>(&pqCtl));
  56. if(FAILED(hr)){
  57. return hr;
  58. }
  59. PQFeatures activeFeat;
  60. hr = pqCtl->get_FeaturesActive(&activeFeat);
  61. if(FAILED(hr)){
  62. return hr;
  63. }
  64. CFeatures* pC = static_cast<CFeatures *>(activeFeat.p);
  65. DeviceCollection::iterator i;
  66. // Check to see if data services is active, if it is not find and load the cc codec
  67. for(i = pC->m_Devices.begin(); i != pC->m_Devices.end(); ++i){
  68. if(VWGraphSegment(*i).ClassID() == CLSID_MSVidDataServices){
  69. break;
  70. }
  71. }
  72. DSFilter ccDec;
  73. DSPin ccDecPin;
  74. if(i == pC->m_Devices.end()){
  75. DSDevices codeclist(m_pSystemEnum, KSCATEGORY_VBICODEC);
  76. DSMediaType mtL21(MEDIATYPE_AUXLine21Data, MEDIASUBTYPE_Line21_BytePair);
  77. for(DSDevices::iterator n = codeclist.begin(); n != codeclist.end() && !ccDec; ++n){
  78. DSFilter codecFilter = m_pGraph.AddMoniker((*n));
  79. for(DSFilter::iterator codecPin = codecFilter.begin(); codecPin != codecFilter.end(); ++codecPin){
  80. if((*codecPin).GetDirection() == PINDIR_OUTPUT){
  81. for(DSPin::iterator codecMediaType = (*codecPin).begin(); codecMediaType != (*codecPin).end(); ++codecMediaType){
  82. if((*codecMediaType) == mtL21){
  83. ccDec = codecFilter;
  84. m_Filters.push_back(ccDec);
  85. ccDecPin = *codecPin;
  86. }
  87. }
  88. }
  89. }
  90. if(!ccDec){
  91. m_pGraph.RemoveFilter(codecFilter);
  92. }
  93. }
  94. }
  95. if(!ccDec){
  96. return E_UNEXPECTED;
  97. }
  98. CComBSTR xdsString(L"{C4C4C4F3-0049-4E2B-98FB-9537F6CE516D}");
  99. GUID2 xdsGuid(xdsString);
  100. // bring in xds filter
  101. CComPtr<IUnknown> fXDS(xdsGuid, NULL, CLSCTX_INPROC_SERVER);
  102. if (!fXDS) {
  103. TRACELM(TRACE_ERROR, "CMSVidClosedCaptioning::put_Container() can't load line 21 decoder");
  104. return E_FAIL;
  105. }
  106. DSFilter xdsFilter(fXDS);
  107. if (!xdsFilter) {
  108. return E_UNEXPECTED;
  109. }
  110. CString csName(_T("XDS Decoder"));
  111. hr = m_pGraph.AddFilter(xdsFilter, csName);
  112. if (FAILED(hr)) {
  113. return hr;
  114. }
  115. m_Filters.push_back(xdsFilter);
  116. DSFilterList intermediates;
  117. hr = m_pGraph.Connect(ccDec, xdsFilter, intermediates);
  118. if(FAILED(hr)){
  119. return hr;
  120. }
  121. m_Filters.insert(m_Filters.end(), intermediates.begin(), intermediates.end());
  122. return NOERROR;
  123. } catch (ComException &e) {
  124. return e;
  125. } catch(...) {
  126. return E_UNEXPECTED;
  127. }
  128. return NOERROR;
  129. }
  130. // IMSVidDevice
  131. STDMETHODIMP CXDS::get_Name(BSTR * Name){
  132. if (!m_fInit) {
  133. return CO_E_NOTINITIALIZED;
  134. }
  135. try {
  136. return CComBSTR("XDS Segment").CopyTo(Name);
  137. } catch(...) {
  138. return E_POINTER;
  139. }
  140. }
  141. STDMETHODIMP CXDS::InterfaceSupportsErrorInfo(REFIID riid){
  142. static const IID* arr[] =
  143. {
  144. &IID_IMSVidXDS
  145. };
  146. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++){
  147. if (InlineIsEqualGUID(*arr[i],riid))
  148. return S_OK;
  149. }
  150. return S_FALSE;
  151. }
  152. #endif // TUNING_MODEL_ONLY