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.

239 lines
6.4 KiB

  1. //==========================================================================;
  2. // MSVidClosedCaptioning.h : Declaration of the CMSVidClosedCaptioning
  3. // copyright (c) Microsoft Corp. 1998-1999.
  4. /////////////////////////////////////////////////////////////////////////////
  5. #pragma once
  6. #ifndef __MSVidClosedCaptioning_H_
  7. #define __MSVidClosedCaptioning_H_
  8. #include <algorithm>
  9. #include <tchar.h>
  10. #include "segimpl.h"
  11. #include "CC2impl.h"
  12. #include <objectwithsiteimplsec.h>
  13. #include "seg.h"
  14. typedef CComQIPtr<ITuner> PQMSVidClosedCaptioning;
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMSVidClosedCaptioning
  17. class ATL_NO_VTABLE __declspec(uuid("7F9CB14D-48E4-43b6-9346-1AEBC39C64D3")) CClosedCaptioning :
  18. public CComObjectRootEx<CComSingleThreadModel>,
  19. public CComCoClass<CClosedCaptioning, &__uuidof(CClosedCaptioning)>,
  20. public ISupportErrorInfo,
  21. public IConnectionPointContainerImpl<CClosedCaptioning>,
  22. public IObjectWithSiteImplSec<CClosedCaptioning>,
  23. public IMSVidGraphSegmentImpl<CClosedCaptioning, MSVidSEG_XFORM, &GUID_NULL>,
  24. public IMSVidClosedCaptioningImpl2<CClosedCaptioning, &LIBID_MSVidCtlLib, &GUID_NULL, IMSVidClosedCaptioning2>
  25. {
  26. public:
  27. typedef IMSVidClosedCaptioningImpl2<CClosedCaptioning, &LIBID_MSVidCtlLib, &GUID_NULL, IMSVidClosedCaptioning2> ccimplbase;
  28. CClosedCaptioning() : m_iL21(-1) {
  29. }
  30. REGISTER_AUTOMATION_OBJECT(IDS_PROJNAME,
  31. IDS_REG_CLOSEDCAPTIONING_PROGID,
  32. IDS_REG_CLOSEDCAPTIONING_DESC,
  33. LIBID_MSVidCtlLib,
  34. __uuidof(CClosedCaptioning));
  35. DECLARE_PROTECT_FINAL_CONSTRUCT()
  36. BEGIN_COM_MAP(CClosedCaptioning)
  37. COM_INTERFACE_ENTRY(IMSVidGraphSegment)
  38. COM_INTERFACE_ENTRY(IMSVidClosedCaptioning)
  39. COM_INTERFACE_ENTRY(IMSVidClosedCaptioning2)
  40. COM_INTERFACE_ENTRY(IDispatch)
  41. COM_INTERFACE_ENTRY(IObjectWithSite)
  42. COM_INTERFACE_ENTRY(IMSVidFeature)
  43. COM_INTERFACE_ENTRY(IMSVidDevice)
  44. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  45. COM_INTERFACE_ENTRY(IConnectionPointContainer)
  46. COM_INTERFACE_ENTRY(IPersist)
  47. END_COM_MAP()
  48. BEGIN_CATEGORY_MAP(CClosedCaptioning)
  49. IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
  50. IMPLEMENTED_CATEGORY(CATID_SafeForInitializing)
  51. IMPLEMENTED_CATEGORY(CATID_PersistsToPropertyBag)
  52. END_CATEGORY_MAP()
  53. BEGIN_CONNECTION_POINT_MAP(CClosedCaptioning)
  54. END_CONNECTION_POINT_MAP()
  55. // ISupportsErrorInfo
  56. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  57. public:
  58. int m_iL21;
  59. HRESULT Unload(void) {
  60. IMSVidGraphSegmentImpl<CClosedCaptioning, MSVidSEG_XFORM, &GUID_NULL>::Unload();
  61. m_iL21 = -1;
  62. return NOERROR;
  63. }
  64. HRESULT SetFilterState() {
  65. if (m_iL21 < 0) {
  66. return NOERROR;
  67. }
  68. PQLine21Decoder pl21(m_Filters[m_iL21]);
  69. if (!pl21) {
  70. return NOERROR;
  71. }
  72. return pl21->SetServiceState(m_fCCEnable ? AM_L21_CCSTATE_On : AM_L21_CCSTATE_Off);
  73. }
  74. // IMSVidGraphSegment
  75. STDMETHOD(Build)() {
  76. return NOERROR;
  77. }
  78. STDMETHOD(PreRun)() {
  79. return NOERROR;
  80. }
  81. STDMETHOD(Decompose)(){
  82. // The Line21 Decoder was not being disconnected from the vmr
  83. // This code disconnects all of the filters in this segment
  84. if(m_pGraph){
  85. for (DSFilterList::iterator i = m_Filters.begin(); i != m_Filters.end(); ++i) {
  86. m_pGraph.DisconnectFilter(*i, false, false);
  87. }
  88. }
  89. return S_OK;
  90. }
  91. STDMETHOD(PostRun)() {
  92. return SetFilterState();
  93. }
  94. STDMETHOD(put_Container)(IMSVidGraphSegmentContainer *pCtl)
  95. {
  96. if (!m_fInit) {
  97. return CO_E_NOTINITIALIZED;
  98. }
  99. try {
  100. if (!pCtl) {
  101. return Unload();
  102. }
  103. if (m_pContainer) {
  104. if (!m_pContainer.IsEqualObject(VWSegmentContainer(pCtl))) {
  105. return Error(IDS_OBJ_ALREADY_INIT, __uuidof(IMSVidClosedCaptioning2), CO_E_ALREADYINITIALIZED);
  106. } else {
  107. return NO_ERROR;
  108. }
  109. }
  110. // DON'T addref the container. we're guaranteed nested lifetimes
  111. // and an addref creates circular refcounts so we never unload.
  112. m_pContainer.p = pCtl;
  113. m_pGraph = m_pContainer.GetGraph();
  114. // bring in the right network provider
  115. PQLine21Decoder l21(CLSID_Line21Decoder2, NULL, CLSCTX_INPROC_SERVER);
  116. if (!l21) {
  117. TRACELM(TRACE_ERROR, "CMSVidClosedCaptioning::put_Container() can't load line 21 decoder");
  118. return E_FAIL;
  119. }
  120. DSFilter f(l21);
  121. if (!f) {
  122. return E_UNEXPECTED;
  123. }
  124. CString csName(_T("Line 21 Decoder"));
  125. HRESULT hr = m_pGraph.AddFilter(f, csName);
  126. if (FAILED(hr)) {
  127. return hr;
  128. }
  129. m_Filters.push_back(f);
  130. m_iL21 = m_Filters.size() - 1;
  131. return NOERROR;
  132. } catch (ComException &e) {
  133. return e;
  134. } catch(...) {
  135. return E_UNEXPECTED;
  136. }
  137. return NOERROR;
  138. }
  139. STDMETHOD(put_Enable)(VARIANT_BOOL fEnable) {
  140. HRESULT hr = ccimplbase::put_Enable(fEnable);
  141. if (FAILED(hr)) {
  142. return hr;
  143. }
  144. return SetFilterState();
  145. }
  146. // IMSVidDevice
  147. STDMETHOD(get_Name)(BSTR * Name)
  148. {
  149. if (!m_fInit) {
  150. return CO_E_NOTINITIALIZED;
  151. }
  152. try {
  153. return GetName(((m_iL21 > -1) ? (m_Filters[m_iL21]) : DSFilter()), m_pDev, CComBSTR(_T("Line 21 Decoder"))).CopyTo(Name);
  154. } catch(...) {
  155. return E_POINTER;
  156. }
  157. }
  158. STDMETHOD(put_Service)(MSVidCCService ccServ) {
  159. if (m_iL21 < 0) {
  160. return Error(IDS_INVALID_STATE, __uuidof(IMSVidClosedCaptioning2), CO_E_NOTINITIALIZED);
  161. }
  162. PQLine21Decoder pl21(m_Filters[m_iL21]);
  163. if (!pl21) {
  164. return E_UNEXPECTED;
  165. }
  166. AM_LINE21_CCSERVICE amServ = static_cast<AM_LINE21_CCSERVICE>(ccServ);
  167. HRESULT hr = pl21->SetCurrentService(amServ);
  168. if(FAILED(hr)){
  169. return hr;
  170. }
  171. return S_OK;
  172. }
  173. STDMETHOD(get_Service)(MSVidCCService *ccServ) {
  174. if (!ccServ) {
  175. return E_POINTER;
  176. }
  177. PQLine21Decoder pl21(m_Filters[m_iL21]);
  178. if (!pl21) {
  179. return E_UNEXPECTED;
  180. }
  181. AM_LINE21_CCSERVICE amServ;
  182. HRESULT hr = pl21->GetCurrentService(&amServ);
  183. if(FAILED(hr)){
  184. return hr;
  185. }
  186. *ccServ = static_cast<MSVidCCService>(amServ);
  187. return S_OK;
  188. }
  189. };
  190. STDMETHODIMP CClosedCaptioning::InterfaceSupportsErrorInfo(REFIID riid)
  191. {
  192. static const IID* arr[] =
  193. {
  194. &IID_IMSVidClosedCaptioning2
  195. };
  196. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  197. {
  198. if (InlineIsEqualGUID(*arr[i],riid))
  199. return S_OK;
  200. }
  201. return S_FALSE;
  202. }
  203. #endif //__MSVidClosedCaptioning_H_