Leaked source code of windows server 2003
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
8.6 KiB

  1. //==========================================================================;
  2. //
  3. // devimpl.h : additional infrastructure to support implementing IMSVidDevice
  4. // nicely from c++
  5. // Copyright (c) Microsoft Corporation 1999.
  6. //
  7. /////////////////////////////////////////////////////////////////////////////
  8. #pragma once
  9. #ifndef ANALOGTUNERIMPL_H
  10. #define ANALOGTUNERIMPL_H
  11. #include "tunerimpl.h"
  12. namespace MSVideoControl {
  13. template<class T,
  14. LPCGUID LibID,
  15. LPCGUID KSCategory,
  16. class MostDerivedInterface = IMSVidDevice>
  17. class DECLSPEC_NOVTABLE IMSVidAnalogTunerImpl : public IMSVidTunerImpl<T, LibID, KSCategory, MostDerivedInterface> {
  18. public:
  19. virtual ~IMSVidAnalogTunerImpl() {}
  20. virtual PQTVTuner GetTuner() = 0;
  21. virtual HRESULT DoTune(PQTuneRequest &pTR) {
  22. PQChannelTuneRequest ctr(pTR);
  23. if (!ctr) {
  24. return ImplReportError(__uuidof(T), IDS_INVALID_TR, __uuidof(IMSVidAnalogTuner), DISP_E_TYPEMISMATCH);
  25. }
  26. return NOERROR;
  27. }
  28. // IMSVidAnalogTuner
  29. STDMETHOD(get_Channel)(LONG * Channel)
  30. {
  31. if (!m_fInit) {
  32. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidAnalogTuner), CO_E_NOTINITIALIZED);
  33. }
  34. if (Channel == NULL)
  35. return E_POINTER;
  36. try {
  37. PQTVTuner pTV(GetTuner());
  38. if (!pTV) {
  39. return ImplReportError(__uuidof(T), IDS_INVALID_STATE, __uuidof(IMSVidAnalogTuner), HRESULT_FROM_WIN32(ERROR_INVALID_STATE));
  40. }
  41. long vsc, asc;
  42. return pTV->get_Channel(Channel, &vsc, &asc);
  43. } catch(...) {
  44. return E_UNEXPECTED;
  45. }
  46. }
  47. STDMETHOD(put_Channel)(LONG Channel)
  48. {
  49. if (!m_fInit) {
  50. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidAnalogTuner), CO_E_NOTINITIALIZED);
  51. }
  52. try {
  53. PQTVTuner pTV(GetTuner());
  54. if (!pTV) {
  55. return ImplReportError(__uuidof(T), IDS_INVALID_STATE, __uuidof(IMSVidAnalogTuner), HRESULT_FROM_WIN32(ERROR_INVALID_STATE));
  56. }
  57. return pTV->put_Channel(Channel, 0, 0);
  58. } catch(...) {
  59. return E_UNEXPECTED;
  60. }
  61. }
  62. STDMETHOD(get_VideoFrequency)(LONG * lcc)
  63. {
  64. if (!m_fInit) {
  65. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidAnalogTuner), CO_E_NOTINITIALIZED);
  66. }
  67. if (lcc == NULL)
  68. return E_POINTER;
  69. try {
  70. PQTVTuner pTV(GetTuner());
  71. if (!pTV) {
  72. return ImplReportError(__uuidof(T), IDS_INVALID_STATE, __uuidof(IMSVidAnalogTuner), HRESULT_FROM_WIN32(ERROR_INVALID_STATE));
  73. }
  74. return pTV->get_VideoFrequency(lcc);
  75. } catch(...) {
  76. return E_UNEXPECTED;
  77. }
  78. }
  79. STDMETHOD(get_AudioFrequency)(LONG * lcc)
  80. {
  81. if (!m_fInit) {
  82. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidAnalogTuner), CO_E_NOTINITIALIZED);
  83. }
  84. if (lcc == NULL)
  85. return E_POINTER;
  86. try {
  87. PQTVTuner pTV(GetTuner());
  88. if (!pTV) {
  89. return ImplReportError(__uuidof(T), IDS_INVALID_STATE, __uuidof(IMSVidAnalogTuner), HRESULT_FROM_WIN32(ERROR_INVALID_STATE));
  90. }
  91. return pTV->get_AudioFrequency(lcc);
  92. } catch(...) {
  93. return E_UNEXPECTED;
  94. }
  95. }
  96. STDMETHOD(get_CountryCode)(LONG * lcc)
  97. {
  98. if (!m_fInit) {
  99. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidAnalogTuner), CO_E_NOTINITIALIZED);
  100. }
  101. if (lcc == NULL)
  102. return E_POINTER;
  103. try {
  104. PQTVTuner pTV(GetTuner());
  105. if (!pTV) {
  106. return ImplReportError(__uuidof(T), IDS_INVALID_STATE, __uuidof(IMSVidAnalogTuner), HRESULT_FROM_WIN32(ERROR_INVALID_STATE));
  107. }
  108. return pTV->get_CountryCode(lcc);
  109. } catch(...) {
  110. return E_UNEXPECTED;
  111. }
  112. }
  113. STDMETHOD(put_CountryCode)(LONG lcc)
  114. {
  115. if (!m_fInit) {
  116. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidAnalogTuner), CO_E_NOTINITIALIZED);
  117. }
  118. try {
  119. PQTVTuner pTV(GetTuner());
  120. if (!pTV) {
  121. return HRESULT_FROM_WIN32(ERROR_INVALID_STATE);
  122. }
  123. return pTV->put_CountryCode(lcc);
  124. } catch(...) {
  125. return E_UNEXPECTED;
  126. }
  127. }
  128. STDMETHOD(get_SAP)(VARIANT_BOOL *pfSAP)
  129. {
  130. HRESULT hr = S_OK;
  131. if (!m_fInit) {
  132. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidAnalogTuner), CO_E_NOTINITIALIZED);
  133. }
  134. if (pfSAP == NULL)
  135. return E_POINTER;
  136. DSFilterList::iterator i;
  137. CComQIPtr<IAMTVAudio>spTVAudio;
  138. for(i = m_Filters.begin(); i != m_Filters.end(); ++i){
  139. spTVAudio = *i;
  140. if(spTVAudio){
  141. break;
  142. }
  143. }
  144. if(i == m_Filters.end()){
  145. return E_NOINTERFACE;
  146. }
  147. long dwMode = 0;
  148. #if 0
  149. hr = spTVAudio->GetHardwareSupportedTVAudioModes(&dwMode);
  150. if(FAILED(hr)){
  151. return hr;
  152. }
  153. hr = spTVAudio->GetAvailableTVAudioModes(&dwMode);
  154. if(FAILED(hr)){
  155. return hr;
  156. }
  157. #endif
  158. hr = spTVAudio->get_TVAudioMode(&dwMode);
  159. if(FAILED(hr)){
  160. return hr;
  161. }
  162. if(dwMode & AMTVAUDIO_MODE_LANG_B){
  163. *pfSAP = VARIANT_FALSE;
  164. }
  165. else{
  166. *pfSAP = VARIANT_TRUE;
  167. }
  168. return S_OK;
  169. }
  170. STDMETHOD(put_SAP)(VARIANT_BOOL fSAP)
  171. {
  172. HRESULT hr = S_OK;
  173. if (!m_fInit) {
  174. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidAnalogTuner), CO_E_NOTINITIALIZED);
  175. }
  176. DSFilterList::iterator i;
  177. CComQIPtr<IAMTVAudio>spTVAudio;
  178. for(i = m_Filters.begin(); i != m_Filters.end(); ++i){
  179. spTVAudio = *i;
  180. if(spTVAudio){
  181. break;
  182. }
  183. }
  184. if(i == m_Filters.end()){
  185. return E_NOINTERFACE;
  186. }
  187. long dwMode = 0;
  188. if(fSAP == VARIANT_TRUE){
  189. dwMode = AMTVAUDIO_MODE_LANG_B | AMTVAUDIO_MODE_MONO;
  190. hr = spTVAudio->put_TVAudioMode(dwMode);
  191. }
  192. else{
  193. dwMode = AMTVAUDIO_MODE_STEREO | AMTVAUDIO_MODE_LANG_A;
  194. hr = spTVAudio->put_TVAudioMode(dwMode);
  195. }
  196. if(FAILED(hr)){
  197. return hr;
  198. }
  199. return S_OK;
  200. }
  201. STDMETHOD(ChannelAvailable)(LONG nChannel, LONG * SignalStrength, VARIANT_BOOL * fSignalPresent)
  202. {
  203. if (!m_fInit) {
  204. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidAnalogTuner), CO_E_NOTINITIALIZED);
  205. }
  206. if (SignalStrength == NULL)
  207. return E_POINTER;
  208. if (fSignalPresent == NULL)
  209. return E_POINTER;
  210. CComQIPtr<IAMTuner> pTV(GetTuner());
  211. if (!pTV) {
  212. return ImplReportError(__uuidof(T), IDS_INVALID_STATE, __uuidof(IMSVidAnalogTuner), HRESULT_FROM_WIN32(ERROR_INVALID_STATE));
  213. }
  214. long curChannel = 0;
  215. HRESULT hr = get_Channel(&curChannel);
  216. if(nChannel != curChannel){
  217. return ImplReportError(__uuidof(T), IDS_INVALID_STATE, __uuidof(IMSVidAnalogTuner), HRESULT_FROM_WIN32(ERROR_INVALID_STATE));
  218. }
  219. hr = pTV->SignalPresent(SignalStrength);
  220. if(FAILED(hr)){
  221. return ImplReportError(__uuidof(T), IDS_INVALID_STATE, __uuidof(IMSVidAnalogTuner), HRESULT_FROM_WIN32(ERROR_INVALID_STATE));
  222. }
  223. if(hr == S_FALSE){
  224. *SignalStrength = 0;
  225. *fSignalPresent = VARIANT_FALSE;
  226. return S_OK;
  227. }
  228. CComQIPtr<IAMTVTuner> qiTV(GetTuner());
  229. if (!qiTV){
  230. return ImplReportError(__uuidof(T), IDS_INVALID_STATE, __uuidof(IMSVidAnalogTuner), HRESULT_FROM_WIN32(ERROR_INVALID_STATE));
  231. }
  232. long foundSignal;
  233. hr = qiTV->AutoTune(curChannel, &foundSignal);
  234. if(hr == S_FALSE){
  235. *SignalStrength = 0;
  236. *fSignalPresent = VARIANT_FALSE;
  237. return S_OK;
  238. }
  239. if(foundSignal){
  240. *fSignalPresent = VARIANT_TRUE;
  241. }
  242. else{
  243. *fSignalPresent = VARIANT_FALSE;
  244. }
  245. return S_OK;
  246. }
  247. #if 0
  248. STDMETHOD(MinMaxChannel)(LONG * lChannelMin, LONG * lChannelMax)
  249. {
  250. if (!m_fInit) {
  251. return ImplReportError(__uuidof(T), IDS_OBJ_NO_INIT, __uuidof(IMSVidAnalogTuner), CO_E_NOTINITIALIZED);
  252. }
  253. if (lChannelMin == NULL)
  254. return E_POINTER;
  255. if (lChannelMax == NULL)
  256. return E_POINTER;
  257. return E_NOTIMPL;
  258. }
  259. #endif
  260. };
  261. }; //namespace
  262. #endif
  263. // end of file - analogtunerimpl.h