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.

277 lines
11 KiB

  1. //==========================================================================;
  2. //
  3. // Composition.h : Declaration of the custom composition class for gluing ANAlog capture to sbe SINk
  4. // Copyright (c) Microsoft Corporation 1999.
  5. //
  6. /////////////////////////////////////////////////////////////////////////////
  7. #ifndef ANASIN_H
  8. #define ANASIN_H
  9. #pragma once
  10. #include "stdafx.h"
  11. #include <uuids.h>
  12. #include "bdamedia.h"
  13. #include "MSVidTVTuner.h"
  14. #include "MSVidSBESink.h"
  15. #include "encdec.h"
  16. #include "resource.h" // main symbols
  17. #include <objectwithsiteimplsec.h>
  18. #include <winerror.h>
  19. #include <algorithm>
  20. #include <compimpl.h>
  21. #include <seg.h>
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CAnaSinComp
  24. class ATL_NO_VTABLE __declspec(uuid("9F50E8B1-9530-4ddc-825E-1AF81D47AED6")) CAnaSinComp :
  25. public CComObjectRootEx<CComSingleThreadModel>,
  26. public CComCoClass<CAnaSinComp, &__uuidof(CAnaSinComp)>,
  27. public IObjectWithSiteImplSec<CAnaSinComp>,
  28. public IMSVidCompositionSegmentImpl<CAnaSinComp>
  29. {
  30. public:
  31. CAnaSinComp() {}
  32. virtual ~CAnaSinComp() {}
  33. REGISTER_NONAUTOMATION_OBJECT(IDS_PROJNAME,
  34. IDS_REG_ANASINCOMP_DESC,
  35. LIBID_MSVidCtlLib,
  36. __uuidof(CAnaSinComp));
  37. DECLARE_PROTECT_FINAL_CONSTRUCT()
  38. BEGIN_COM_MAP(CAnaSinComp)
  39. COM_INTERFACE_ENTRY(IMSVidCompositionSegment)
  40. COM_INTERFACE_ENTRY(IMSVidGraphSegment)
  41. COM_INTERFACE_ENTRY(IObjectWithSite)
  42. COM_INTERFACE_ENTRY(IPersist)
  43. END_COM_MAP()
  44. // IMSVidComposition
  45. public:
  46. // IMSVidGraphSegment
  47. // IMSVidCompositionSegment
  48. STDMETHOD(Compose)(IMSVidGraphSegment * upstream, IMSVidGraphSegment * downstream)
  49. {
  50. if (m_fComposed) {
  51. return NOERROR;
  52. }
  53. ASSERT(m_pGraph);
  54. try {
  55. TRACELM(TRACE_DETAIL, "CAnaSinComp::Compose()");
  56. VWGraphSegment up(upstream);
  57. ASSERT(up.Graph() == m_pGraph);
  58. VWGraphSegment down(downstream);
  59. ASSERT(down.Graph() == m_pGraph);
  60. if (up.begin() == up.end()) {
  61. TRACELM(TRACE_ERROR, "CAnaSinComp::Compose() can't compose empty up segment");
  62. return E_INVALIDARG;
  63. }
  64. if (down.begin() == down.end()) {
  65. TRACELM(TRACE_ERROR, "CAnaSinComp::Compose() can't compose empty down segment");
  66. return E_INVALIDARG;
  67. }
  68. #if 0
  69. VWGraphSegment::iterator iOv = std::find_if(down.begin(),
  70. down.end(),
  71. arity1_pointer(&IsVideoRenderer));
  72. #endif
  73. CMSVidStreamBufferSink* ds = (CMSVidStreamBufferSink*)downstream;
  74. DSFilter pSink(ds->m_Filters[0]);
  75. CComQIPtr<IMSVidAnalogTuner> qiITV(upstream);
  76. CMSVidTVTuner* qiTV;
  77. qiTV = static_cast<CMSVidTVTuner*>(qiITV.p);
  78. DSPin pVidPin;
  79. DSPin pAudPin;
  80. #if 0
  81. if(!!qiTV && qiTV->m_iDeMux > 0){
  82. CString csName;
  83. // render demux out to vr
  84. DSFilter pDeMux = qiTV->m_Filters[qiTV->m_iDeMux];
  85. DSFilter::iterator iVidPin;
  86. DSMediaType mtVideo(MEDIATYPE_Video, MEDIASUBTYPE_MPEG2_VIDEO, FORMAT_MPEG2Video);
  87. DSMediaType mtAudio(MEDIATYPE_Audio, MEDIASUBTYPE_MPEG1Payload, FORMAT_WaveFormatEx);
  88. for (iVidPin = pDeMux.begin(); iVidPin != pDeMux.end(); ++iVidPin) {
  89. DSPin::iterator j;
  90. for(j = (*iVidPin).begin(); j != (*iVidPin).end(); ++j){
  91. DSMediaType pinType(*j);
  92. if (pinType == mtVideo){
  93. CComPtr<IUnknown> spMpeg2Analyze(CLSID_Mpeg2VideoStreamAnalyzer, NULL, CLSCTX_INPROC_SERVER);
  94. if (!spMpeg2Analyze) {
  95. //TRACELSM(TRACE_ERROR, (dbgDump << "CMSVidStreamBufferSink::Build() can't load Stream Buffer Sink");
  96. return ImplReportError(__uuidof(IMSVidStreamBufferSink), IDS_CANT_CREATE_FILTER, __uuidof(IStreamBufferSink), E_UNEXPECTED);
  97. }
  98. DSFilter vr(spMpeg2Analyze);
  99. if (!vr) {
  100. ASSERT(false);
  101. return ImplReportError(__uuidof(IMSVidStreamBufferSink), IDS_CANT_CREATE_FILTER, __uuidof(IBaseFilter), E_UNEXPECTED);
  102. }
  103. m_Filters.push_back(vr);
  104. csName = _T("Mpeg2 Analysis");
  105. m_pGraph.AddFilter(vr, csName);
  106. DSFilter::iterator a;
  107. for(a = vr.begin(); a != vr.end(); ++a){
  108. HRESULT hr = (*a).Connect(*iVidPin);
  109. if(FAILED(hr)){
  110. continue;
  111. }
  112. else{
  113. break;
  114. }
  115. }
  116. if(a == vr.end()){
  117. return E_FAIL;
  118. }
  119. for(a = vr.begin(); a != vr.end(); ++a){
  120. if((*a).GetDirection() == PINDIR_OUTPUT){
  121. pVidPin = (*a);
  122. }
  123. }
  124. if(!pVidPin){
  125. return E_FAIL;
  126. }
  127. }
  128. if(pinType == mtAudio){
  129. pAudPin = (*iVidPin);
  130. }
  131. }
  132. if(!!pVidPin && !!pAudPin){
  133. break;
  134. }
  135. }
  136. if(!pVidPin || !pAudPin){
  137. TRACELM(TRACE_DETAIL, "CAnaSinComp::Compose() can't find video and/or audio pin on demux");
  138. return E_UNEXPECTED;
  139. }
  140. DSFilterList intermediates;
  141. CComBSTR encString(L"{C4C4C4F1-0049-4E2B-98FB-9537F6CE516D}");
  142. GUID2 encdecGuid (encString);
  143. HRESULT hr = S_OK;
  144. // Create and add to graph the Video Tagger Filter
  145. CComPtr<IUnknown> spEncTagV(encdecGuid, NULL, CLSCTX_INPROC_SERVER);
  146. if (!spEncTagV) {
  147. TRACELM(TRACE_ERROR, "CMSVidStreamBufferSink::Build() can't load Tagger filter");
  148. return ImplReportError(__uuidof(IMSVidStreamBufferSink), IDS_CANT_CREATE_FILTER, __uuidof(IStreamBufferSink), E_UNEXPECTED);
  149. }
  150. DSFilter vrV(spEncTagV);
  151. if (!vrV) {
  152. ASSERT(false);
  153. return ImplReportError(__uuidof(IMSVidStreamBufferSink), IDS_CANT_CREATE_FILTER, __uuidof(IBaseFilter), E_UNEXPECTED);
  154. }
  155. m_Filters.push_back(vrV);
  156. csName = _T("Video Encoder Tagger Filter");
  157. m_pGraph.AddFilter(vrV, csName);
  158. // Connect video pin to Tagger
  159. hr = pVidPin.IntelligentConnect(vrV, intermediates);
  160. if(FAILED(hr)){
  161. TRACELM(TRACE_DETAIL, "CAnaSinComp::Compose() can't connect audio pin to Audio Tagger");
  162. return E_UNEXPECTED;
  163. }
  164. // Connect Tagger to Sink
  165. DSFilter::iterator fil, vP;
  166. hr = E_FAIL;
  167. for(vP = vrV.begin(); vP != vrV.end(); ++ vP){
  168. if((*vP).GetDirection() == PINDIR_OUTPUT){
  169. break;
  170. }
  171. }
  172. if(vP == vrV.end()){
  173. return E_UNEXPECTED;
  174. }
  175. for(fil = pSink.begin(); fil != pSink.end() && FAILED(hr); ++fil){
  176. hr = (*vP).Connect((*fil));
  177. }
  178. if(FAILED(hr)){
  179. TRACELM(TRACE_DETAIL, "CAnaSinComp::Compose() can't connect Video Tagger to Sink");
  180. return E_UNEXPECTED;
  181. }
  182. // Create and add to graph the Audio Tagger Filter
  183. CComPtr<IUnknown> spEncTagA(encdecGuid, NULL, CLSCTX_INPROC_SERVER);
  184. if (!spEncTagA) {
  185. TRACELM(TRACE_ERROR, "CMSVidStreamBufferSink::Build() can't load Tagger filter");
  186. return ImplReportError(__uuidof(IMSVidStreamBufferSink), IDS_CANT_CREATE_FILTER, __uuidof(IStreamBufferSink), E_UNEXPECTED);
  187. }
  188. DSFilter vrA(spEncTagA);
  189. if (!vrA) {
  190. ASSERT(false);
  191. return ImplReportError(__uuidof(IMSVidStreamBufferSink), IDS_CANT_CREATE_FILTER, __uuidof(IBaseFilter), E_UNEXPECTED);
  192. }
  193. m_Filters.push_back(vrA);
  194. csName = _T("Audio Encoder Tagger Filter");
  195. m_pGraph.AddFilter(vrA, csName);
  196. // Connect audio pin to the Tagger
  197. hr = pAudPin.IntelligentConnect(vrA, intermediates);
  198. if(FAILED(hr)){
  199. TRACELM(TRACE_DETAIL, "CAnaSinComp::Compose() can't connect audio pin to Audio Tagger");
  200. return E_UNEXPECTED;
  201. }
  202. // Connect Tagger to Sink
  203. hr = E_FAIL;
  204. for(vP = vrA.begin(); vP != vrA.end(); ++ vP){
  205. if((*vP).GetDirection() == PINDIR_OUTPUT){
  206. break;
  207. }
  208. }
  209. if(vP == vrA.end()){
  210. return E_UNEXPECTED;
  211. }
  212. for(fil = pSink.begin(); fil != pSink.end() && FAILED(hr); ++fil){
  213. hr = (*vP).Connect((*fil));
  214. }
  215. if(FAILED(hr)){
  216. TRACELM(TRACE_DETAIL, "CAnaSinComp::Compose() can't connect Video Tagger to Sink");
  217. return E_UNEXPECTED;
  218. }
  219. /*
  220. hr = m_pGraph.Connect(vrA, pSink, intermediates);
  221. if(FAILED(hr)){
  222. TRACELM(TRACE_DETAIL, "CAnaSinComp::Compose() can't connect Audio Tagger to Sink");
  223. return E_UNEXPECTED;
  224. }
  225. */
  226. ASSERT(intermediates.begin() == intermediates.end());
  227. m_Filters.insert(m_Filters.end(), intermediates.begin(), intermediates.end());
  228. }
  229. else{
  230. #endif
  231. return S_OK;
  232. #if 0
  233. }
  234. #endif
  235. TRACELM(TRACE_DETAIL, "CAnaSinComp::Compose() SUCCEEDED");
  236. m_fComposed = true;
  237. return NOERROR;
  238. } catch (ComException &e) {
  239. HRESULT hr = e;
  240. TRACELSM(TRACE_ERROR, (dbgDump << "CAnaSinComp::Compose() exception = " << hexdump(hr)), "");
  241. return e;
  242. } catch (...) {
  243. TRACELM(TRACE_ERROR, "CAnaSinComp::Compose() exception ... ");
  244. return E_UNEXPECTED;
  245. }
  246. }
  247. };
  248. #endif // AnaSin_H
  249. // end of file - AnaSin.h