simpleplayer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef SIMPLEPLAYER_H
  19. #define SIMPLEPLAYER_H
  20. #include "wmsdk.h"
  21. //
  22. // we preserve a list of "ready-to-free" list of wave headers for the
  23. // caller to unprepare and free
  24. //
  25. typedef struct WAVEHDR_LIST {
  26. LPWAVEHDR pwh;
  27. struct WAVEHDR_LIST *next;
  28. } WAVEHDR_LIST;
  29. #define SIMPLE_PLAYER_OPEN_EVENT _T( "45ab58e0-382e-4d1c-ac50-88a5f9601851" )
  30. #define SIMPLE_PLAYER_CLOSE_EVENT _T( "276095fa-a8e0-48e6-ac61-8b0002345607" )
  31. #define WMAPLAY_EVENT _T( "9e828a72-64f3-48f0-9de8-13dafd0cbd3a" )
  32. ///////////////////////////////////////////////////////////////////////////////
  33. class CSimplePlayer : public IWMReaderCallback
  34. {
  35. public:
  36. CSimplePlayer( HRESULT* phr );
  37. ~CSimplePlayer();
  38. virtual HRESULT Play( LPCWSTR pszUrl, DWORD dwSecDuration, HANDLE hCompletionEvent, HRESULT *phrCompletion );
  39. //
  40. // IUnknown Implemenation
  41. //
  42. public:
  43. virtual HRESULT STDMETHODCALLTYPE QueryInterface(
  44. REFIID riid,
  45. void **ppvObject );
  46. virtual ULONG STDMETHODCALLTYPE AddRef();
  47. virtual ULONG STDMETHODCALLTYPE Release();
  48. //
  49. // IWMReaderCallback Implemenation
  50. //
  51. public:
  52. virtual HRESULT STDMETHODCALLTYPE OnSample(
  53. /* [in] */ DWORD dwOutputNum,
  54. /* [in] */ QWORD cnsSampleTime,
  55. /* [in] */ QWORD cnsSampleDuration,
  56. /* [in] */ DWORD dwFlags,
  57. /* [in] */ INSSBuffer __RPC_FAR *pSample,
  58. /* [in] */ void __RPC_FAR *pvContext);
  59. virtual HRESULT STDMETHODCALLTYPE OnStatus(
  60. /* [in] */ WMT_STATUS Status,
  61. /* [in] */ HRESULT hr,
  62. /* [in] */ WMT_ATTR_DATATYPE dwType,
  63. /* [in] */ BYTE __RPC_FAR *pValue,
  64. /* [in] */ void __RPC_FAR *pvContext);
  65. //
  66. // Helper Methods
  67. //
  68. protected:
  69. HRESULT Close();
  70. void OnWaveOutMsg( UINT uMsg, DWORD dwParam1, DWORD dwParam2 );
  71. static void CALLBACK WaveProc(
  72. HWAVEOUT hwo,
  73. UINT uMsg,
  74. DWORD dwInstance,
  75. DWORD dwParam1,
  76. DWORD dwParam2 );
  77. HRESULT AddWaveHeader( LPWAVEHDR pwh );
  78. void RemoveWaveHeaders( void );
  79. CRITICAL_SECTION m_CriSec;
  80. WAVEHDR_LIST *m_whdrHead;
  81. LONG m_cRef;
  82. LONG m_cBuffersOutstanding;
  83. BOOL m_fEof;
  84. HANDLE m_hCompletionEvent;
  85. IWMReader *m_pReader;
  86. IWMHeaderInfo *m_pHeader;
  87. HWAVEOUT m_hwo;
  88. HRESULT *m_phrCompletion;
  89. HRESULT m_hrOpen;
  90. HANDLE m_hOpenEvent;
  91. HANDLE m_hCloseEvent;
  92. union
  93. {
  94. WAVEFORMATEX m_wfx;
  95. BYTE m_WfxBuf[1024];
  96. };
  97. LPWSTR m_pszUrl;
  98. };
  99. #endif // SIMPLEPLAYER_H