1
0

WMCallback.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #include "Main.h"
  2. #include "WMCallback.h"
  3. #include <algorithm>
  4. #include "WMHandler.h"
  5. #include "util.h"
  6. #include <cassert>
  7. #define CAST_TO(x) if (riid== IID_##x) { *ppvObject=static_cast<x *>(this); AddRef(); return S_OK; }
  8. #define CAST_TO_VIA(x,y) if (riid== IID_##x) { *ppvObject=static_cast<y *>(this); AddRef(); return S_OK; }
  9. HRESULT WMCallback::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject )
  10. {
  11. CAST_TO(IWMReaderCallback);
  12. CAST_TO_VIA(IUnknown, IWMReaderCallback);
  13. CAST_TO(IWMReaderCallbackAdvanced);
  14. #ifdef _DEBUG
  15. CAST_TO(IWMCredentialCallback);
  16. #endif
  17. *ppvObject = NULL;
  18. return E_NOINTERFACE;
  19. }
  20. ULONG WMCallback::AddRef()
  21. {
  22. return InterlockedIncrement(&refCount);
  23. }
  24. ULONG WMCallback::Release()
  25. {
  26. if (InterlockedDecrement(&refCount) == 0)
  27. {
  28. delete this;
  29. return 0;
  30. }
  31. return refCount;
  32. }
  33. HRESULT WMCallback::OnStatus(WMT_STATUS Status, HRESULT hr, WMT_ATTR_DATATYPE dwType,
  34. BYTE __RPC_FAR *pValue, void __RPC_FAR *pvContext)
  35. {
  36. if (!handler)
  37. return S_OK;
  38. switch (Status)
  39. {
  40. WMTCASE(WMT_INIT_PLAYLIST_BURN)
  41. handler->InitPlaylistBurn();
  42. break;
  43. WMTCASE(WMT_NO_RIGHTS)
  44. handler->NoRights((wchar_t *)pValue);
  45. break;
  46. WMTCASE(WMT_NO_RIGHTS_EX)
  47. handler->NoRightsEx((WM_GET_LICENSE_DATA *&)pValue);
  48. break;
  49. WMTCASE(WMT_NEEDS_INDIVIDUALIZATION)
  50. handler->Individualize();
  51. break;
  52. WMTCASE(WMT_END_OF_STREAMING)
  53. break;
  54. WMTCASE(WMT_LICENSEURL_SIGNATURE_STATE)
  55. handler->SignatureState((WMT_DRMLA_TRUST *&)pValue);
  56. break;
  57. WMTCASE(WMT_ACQUIRE_LICENSE)
  58. WMT_SHOW_HR_CODE(hr)
  59. switch (hr)
  60. {
  61. case NS_S_DRM_LICENSE_ACQUIRED:
  62. handler->LicenseAcquired();
  63. break;
  64. case NS_S_DRM_MONITOR_CANCELLED:
  65. handler->MonitorCancelled();
  66. break;
  67. case NS_S_DRM_ACQUIRE_CANCELLED:
  68. handler->SilentCancelled();
  69. break;
  70. default:
  71. handler->AcquireLicense((WM_GET_LICENSE_DATA *&)pValue);
  72. }
  73. break;
  74. WMTCASE(WMT_INDIVIDUALIZE)
  75. handler->IndividualizeStatus((WM_INDIVIDUALIZE_STATUS *)pValue);
  76. break;
  77. //the file has been opened
  78. WMTCASE(WMT_OPENED)
  79. if (SUCCEEDED(hr))
  80. handler->Opened();
  81. else
  82. {
  83. switch (hr)
  84. {
  85. WMTCASE(NS_E_DRM_APPCERT_REVOKED)
  86. WMTCASE(NS_E_DRM_LICENSE_APP_NOTALLOWED)
  87. handler->DRMExpired();
  88. WMTCASE(NS_E_LICENSE_REQUIRED)
  89. handler->LicenseRequired();
  90. break;
  91. WMTCASE(NS_E_DRM_NEEDS_INDIVIDUALIZATION)
  92. handler->NeedsIndividualization();
  93. break;
  94. WMTCASE(E_ACCESSDENIED)
  95. handler->AccessDenied();
  96. break;
  97. default:
  98. WMT_SHOW_HR_CODE(hr);
  99. handler->Error();
  100. return S_OK;
  101. }
  102. handler->OpenCalled();
  103. }
  104. break;
  105. // Playback of the opened file has begun.
  106. WMTCASE( WMT_STARTED)
  107. if (SUCCEEDED(hr))
  108. handler->Started();
  109. else
  110. {
  111. switch (hr)
  112. {
  113. WMTCASE(E_ABORT)
  114. //handler->OpenFailed();
  115. break;
  116. WMTCASE(NS_E_DRM_REOPEN_CONTENT)
  117. handler->Error();
  118. break;
  119. default:
  120. WMT_SHOW_HR_CODE(hr);
  121. handler->Error();
  122. break;
  123. }
  124. }
  125. break;
  126. WMTCASE( WMT_NEW_METADATA)
  127. if (SUCCEEDED(hr))
  128. handler->NewMetadata();
  129. break;
  130. // The previously playing reader has stopped.
  131. WMTCASE( WMT_STOPPED)
  132. if (SUCCEEDED(hr))
  133. handler->Stopped();
  134. else
  135. {
  136. WMT_SHOW_HR_CODE(hr);
  137. handler->Error();
  138. }
  139. break;
  140. // The previously playing reader has stopped.
  141. WMTCASE( WMT_CLOSED)
  142. if (SUCCEEDED(hr))
  143. handler->Closed();
  144. else
  145. {
  146. WMT_SHOW_HR_CODE(hr);
  147. handler->Error();
  148. }
  149. break;
  150. WMTCASE(WMT_ERROR)
  151. WMT_SHOW_HR_CODE(hr);
  152. //handler->Error();
  153. break;
  154. WMTCASE( WMT_BUFFERING_START)
  155. if (SUCCEEDED(hr))
  156. handler->BufferingStarted();
  157. break;
  158. WMTCASE( WMT_BUFFERING_STOP)
  159. if (SUCCEEDED(hr))
  160. handler->BufferingStopped();
  161. break;
  162. WMTCASE( WMT_EOF)
  163. WMT_SHOW_HR_CODE(hr);
  164. handler->EndOfFile();
  165. break;
  166. WMTCASE( WMT_LOCATING)
  167. handler->Locating();
  168. break;
  169. WMTCASE( WMT_CONNECTING)
  170. handler->Connecting();
  171. break;
  172. WMTCASE( WMT_PREROLL_READY)
  173. break;
  174. WMTCASE( WMT_PREROLL_COMPLETE)
  175. break;
  176. WMTCASE(WMT_NEW_SOURCEFLAGS)
  177. break;
  178. WMTCASE(WMT_MISSING_CODEC)
  179. WMT_SHOW_HR_CODE(hr);
  180. #ifdef DEBUG
  181. std::cerr << dwType << std::endl;
  182. std::wcerr << GuidString(*(GUID *)pValue) << std::endl;
  183. #endif
  184. break;
  185. default:
  186. #ifdef DEBUG
  187. std::cerr << "unknown message = " << Status << std::endl;
  188. #endif
  189. break;
  190. };
  191. return S_OK;
  192. }
  193. HRESULT WMCallback::OnStreamSelection(WORD wStreamCount, WORD *pStreamNumbers, WMT_STREAM_SELECTION *pSelections, void *pvContext)
  194. {
  195. #ifdef DEBUG
  196. std::cerr << "OnStreamSelection" << std::endl;
  197. #endif
  198. return E_NOTIMPL;
  199. }
  200. HRESULT WMCallback::OnOutputPropsChanged(DWORD dwOutputNum, WM_MEDIA_TYPE *pMediaType, void *pvContext)
  201. {
  202. #ifdef DEBUG
  203. std::cerr << "OnOutputPropsChanged" << std::endl;
  204. #endif
  205. return E_NOTIMPL;
  206. }
  207. HRESULT WMCallback::AllocateForStream(WORD wStreamNum, DWORD cbBuffer, INSSBuffer **ppBuffer, void *pvContext)
  208. {
  209. return E_NOTIMPL;
  210. }
  211. HRESULT WMCallback::AllocateForOutput(DWORD dwOutputNum, DWORD cbBuffer, INSSBuffer **ppBuffer, void *pvContext)
  212. {
  213. return E_NOTIMPL;
  214. }
  215. HRESULT WMCallback::OnStreamSample(WORD wStreamNum, QWORD cnsSampleTime, QWORD cnsSampleDuration, DWORD dwFlags, INSSBuffer *pSample, void *pvContext)
  216. {
  217. return E_NOTIMPL;
  218. }
  219. // 0x5A, 0xA5, 0x00, 0x03, 0x74, 0x00, 0x01, 0x01, 0x77,
  220. //------------------------------------------------------------------------------
  221. // Name: CWAPlugin::OnSample()
  222. // Desc: IWMReaderCallback method to process samples.
  223. //------------------------------------------------------------------------------
  224. HRESULT WMCallback::OnSample(DWORD dwOutputNum, QWORD cnsSampleTime,
  225. QWORD cnsSampleDuration, DWORD dwFlags,
  226. INSSBuffer __RPC_FAR *pSample, void __RPC_FAR *pvContext)
  227. {
  228. if (!handler)
  229. return S_OK;
  230. handler->SampleReceived(cnsSampleTime, cnsSampleDuration, dwOutputNum, dwFlags, pSample);
  231. return S_OK;
  232. }
  233. HRESULT WMCallback::OnTime(QWORD cnsCurrentTime, void *pvContext)
  234. {
  235. if (!handler)
  236. return S_OK;
  237. handler->TimeReached(cnsCurrentTime);
  238. return S_OK;
  239. }
  240. HRESULT WMCallback::AcquireCredentials(WCHAR* pwszRealm, WCHAR* pwszSite,
  241. WCHAR* pwszUser, DWORD cchUser,
  242. WCHAR* pwszPassword, DWORD cchPassword,
  243. HRESULT hrStatus, DWORD* pdwFlags)
  244. {
  245. #ifdef _DEBUG
  246. std::cout << "WMCallback::AcquireCredentials" << std::endl;
  247. std::wcout << pwszRealm << std::endl;
  248. std::wcout << pwszSite << std::endl;
  249. std::wcout << HRErrorCode(hrStatus) << std::endl;
  250. return S_OK;
  251. #endif
  252. return E_NOTIMPL;
  253. }