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.

178 lines
6.1 KiB

  1. //==========================================================================;
  2. //
  3. // tunerimpl.h : additional infrastructure to support implementing IMSVidTuner
  4. // nicely from c++
  5. // Copyright (c) Microsoft Corporation 1999.
  6. //
  7. /////////////////////////////////////////////////////////////////////////////
  8. #pragma once
  9. #ifndef TUNERIMPL_H
  10. #define TUNERIMPL_H
  11. #include "videoinputimpl.h"
  12. #include "tune.h"
  13. #include <deviceeventimpl.h>
  14. namespace MSVideoControl {
  15. template<class T, LPCGUID LibID, LPCGUID KSCategory, class MostDerivedInterface = IMSVidTuner>
  16. class DECLSPEC_NOVTABLE IMSVidTunerImpl :
  17. public IMSVidVideoInputImpl<T, LibID, KSCategory, MostDerivedInterface> {
  18. public:
  19. TNTuningSpace m_TS;
  20. TNTuneRequest m_pCurrentTR;
  21. IMSVidTunerImpl() : m_TS(), m_pCurrentTR() {}
  22. virtual ~IMSVidTunerImpl() {}
  23. virtual HRESULT DoTune(TNTuneRequest& pTR) = 0;
  24. virtual HRESULT UpdateTR(TNTuneRequest& pTR) = 0;
  25. // IMSVidInputDevice
  26. STDMETHOD(IsViewable)(VARIANT* pv, VARIANT_BOOL *pfViewable)
  27. {
  28. if (!m_fInit) {
  29. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidTuner), CO_E_NOTINITIALIZED);
  30. }
  31. if (!pv) {
  32. return E_POINTER;
  33. }
  34. return E_NOTIMPL;
  35. }
  36. STDMETHOD(View)(VARIANT* pv) {
  37. if (!m_fInit) {
  38. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidTuner), CO_E_NOTINITIALIZED);
  39. }
  40. if (!pv) {
  41. return E_POINTER;
  42. }
  43. try {
  44. if (pv->vt != VT_DISPATCH && pv->vt != VT_UNKNOWN) {
  45. return ImplReportError(__uuidof(T), IDS_INVALID_CONTENT, __uuidof(IMSVidTuner), E_INVALIDARG);
  46. }
  47. PQTuneRequest tr((pv->vt == VT_UNKNOWN) ? pv->punkVal : pv->pdispVal);
  48. if (!tr) {
  49. return ImplReportError(__uuidof(T), IDS_INVALID_CONTENT, __uuidof(IMSVidTuner), E_INVALIDARG);
  50. }
  51. return put_Tune(tr);
  52. } catch(...) {
  53. return E_UNEXPECTED;
  54. }
  55. }
  56. // IMSVidTuner
  57. STDMETHOD(put_Tune)(ITuneRequest *pTR) {
  58. TRACELM(TRACE_DETAIL, "IMSVidTunerImpl<>::put_Tune()");
  59. if (!m_fInit) {
  60. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidTuner), CO_E_NOTINITIALIZED);
  61. }
  62. if (!pTR) {
  63. return E_POINTER;
  64. }
  65. try {
  66. TNTuneRequest req(pTR);
  67. ASSERT(req);
  68. if (m_TS) {
  69. // if this tuner has been initialized propertly it will have a tuning space
  70. // that it handles already specified. in that case, we should only
  71. // handle tune requests for our ts
  72. TNTuningSpace ts(req.TuningSpace());
  73. if (ts != m_TS) {
  74. return ImplReportError(__uuidof(T), IDS_INVALID_TS, __uuidof(IMSVidTuner), E_INVALIDARG);
  75. }
  76. } else {
  77. // undone: if dev init is correct this case should never occur
  78. // return E_UNEXPECTED;
  79. }
  80. HRESULT hr = DoTune(req);
  81. if (SUCCEEDED(hr)) {
  82. m_pCurrentTR = req;
  83. m_pCurrentTR.Clone();
  84. if (!m_TS) {
  85. // undone: this is bad. temporary hack until dev init is correct.
  86. m_TS = req.TuningSpace();
  87. m_TS.Clone();
  88. }
  89. }
  90. return hr;
  91. } catch(...) {
  92. return E_INVALIDARG;
  93. }
  94. }
  95. STDMETHOD(get_Tune)(ITuneRequest **ppTR) {
  96. if (!m_fInit) {
  97. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidTuner), CO_E_NOTINITIALIZED);
  98. }
  99. if (!ppTR) {
  100. return E_POINTER;
  101. }
  102. try {
  103. HRESULT hr = UpdateTR(m_pCurrentTR);
  104. if (FAILED(hr)) {
  105. return hr;
  106. }
  107. return m_pCurrentTR.CopyTo(ppTR);
  108. } catch(...) {
  109. return E_INVALIDARG;
  110. }
  111. }
  112. STDMETHOD(get_TuningSpace)(ITuningSpace **ppTS) {
  113. if (!m_fInit) {
  114. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidTuner), CO_E_NOTINITIALIZED);
  115. }
  116. if (ppTS == NULL)
  117. return E_POINTER;
  118. try {
  119. m_TS.CopyTo(ppTS);
  120. return NOERROR;
  121. } catch(...) {
  122. return E_UNEXPECTED;
  123. }
  124. }
  125. STDMETHOD(put_TuningSpace)(ITuningSpace* pTS) {
  126. return E_NOTIMPL;
  127. }
  128. };
  129. template <class T, const IID* piid = &IID_IMSVidTunerEvent, class CDV = CComDynamicUnkArray>
  130. class CProxy_Tuner : public CProxy_DeviceEvent<T, piid, CDV>
  131. {
  132. //Warning this class may be recreated by the wizard.
  133. public:
  134. VOID Fire_OnTuneChanged(IMSVidTuner *pTunerDev)
  135. {
  136. T* pT = static_cast<T*>(this);
  137. int nConnectionIndex;
  138. CComVariant* pvars = new CComVariant[1];
  139. int nConnections = m_vec.GetSize();
  140. for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
  141. {
  142. pT->Lock();
  143. CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
  144. pT->Unlock();
  145. IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
  146. if (pDispatch != NULL)
  147. {
  148. pvars[0] = pTunerDev;
  149. DISPPARAMS disp = { pvars, NULL, 1, 0 };
  150. pDispatch->Invoke(eventidOnTuneChanged, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  151. }
  152. }
  153. delete[] pvars;
  154. }
  155. };
  156. }; // namespace
  157. #endif
  158. // end of file - tunerimpl.h