rtsnd.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. #ifndef RTSND_H
  19. #define RTSND_H
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Headers.
  22. //////////////////////////////////////////////////////////////////////////////
  23. #include "dispatch.h"
  24. #include "Image.h"
  25. #include "mix.h"
  26. //////////////////////////////////////////////////////////////////////////////
  27. // Macros.
  28. //////////////////////////////////////////////////////////////////////////////
  29. // This value can be from 0 to 64K - 1.
  30. // The overhead per channel is sizeof(SND_RT_HDR) bytes.
  31. #define MAX_SND_CHANNELS 50
  32. #define MAXBUFS 60
  33. //////////////////////////////////////////////////////////////////////////////
  34. // Typedefs.
  35. //////////////////////////////////////////////////////////////////////////////
  36. class CRtSnd
  37. {
  38. public: // Construction/Destruction.
  39. // Default constructor.
  40. CRtSnd();
  41. // Destructor.
  42. ~CRtSnd();
  43. public: // Methods.
  44. // Sets the dispatcher.
  45. void SetDispatcher(CDispatch* pdispatch);
  46. protected: // Internal methods.
  47. // Sets variables w/o regard to current values.
  48. void Set();
  49. // Resets variables. Performs deallocation if necessary.
  50. void Reset();
  51. // Use handler for RtSnd buffers.
  52. // Returns RET_FREE if done with data on return, RET_DONTFREE otherwise.
  53. short Use( UCHAR* puc, long lSize, USHORT usType, UCHAR ucFlags,
  54. long lTime);
  55. // Static entry point for above.
  56. static short UseStatic( UCHAR* puc, long lSize, USHORT usType,
  57. UCHAR ucFlags, long lTime, long l_pRtSnd);
  58. // Callback for mixer.
  59. // Returns new buffer to play or NULL if none.
  60. static void* MixCall(USHORT usMsg, void* pData, ULONG* pulBufSize,
  61. ULONG ul_psndhdr);
  62. // Keeps the mixer channel open and starts the mixing in the beginning
  63. // and whenever a break up occurs due to streaming for all active
  64. // channels.
  65. static void CritiCall(ULONG);
  66. public: // Internal typedefs.
  67. typedef struct
  68. {
  69. UCHAR* puc; // Data.
  70. long lSize; // Amount of data in bytes.
  71. long lTime; // Time for chunk to be played.
  72. short sLast; // TRUE if the last buffer, FALSE otherwise.
  73. } SNDBUF, *PSNDBUF;
  74. typedef struct
  75. {
  76. // Header info from stream.
  77. long lSamplesPerSec; // Sample rate.
  78. short sBitsPerSample; // Number of bits that constitute a sample.
  79. short sNumChannels; // Number of channels: 1 == mono, 2 == stereo.
  80. long lLead; // Amount of time data is received of ahead
  81. // of being used.
  82. // Header info for our use.
  83. CMix mix; // Mixer channel.
  84. CQueue<SNDBUF, MAXBUFS> qsndbufs; // Queue of SNDBUFs for this channel.
  85. USHORT usStatus; // Status of current channel.
  86. CDispatch* pdispatch;
  87. } SND_RT_HDR, *PSND_RT_HDR;
  88. public: // Members.
  89. protected: // Members.
  90. SND_RT_HDR m_asndhdrs[MAX_SND_CHANNELS];// Info for each channel.
  91. USHORT m_usState; // The current state of this CRtSnd.
  92. CDispatch* m_pdispatch; // The dispatcher for this CRtSnd.
  93. static CList<SND_RT_HDR> ms_listSndhdrs; // List of active channels.
  94. };
  95. #endif // RTSND_H
  96. //////////////////////////////////////////////////////////////////////////////
  97. // EOF
  98. //////////////////////////////////////////////////////////////////////////////