PlayerModel.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #if !defined(PLAYERMODEL_HPP)
  2. #define PLAYERMODEL_HPP
  3. //______________________________________________________________________________
  4. //
  5. // PlayerModel.hpp
  6. //
  7. #include <string>
  8. #include <exception>
  9. #include <iosfwd>
  10. namespace on2vp
  11. {
  12. //--------------------------------------
  13. class PlayerModel
  14. {
  15. friend std::ostream& operator<<(std::ostream& os, const PlayerModel& pm);
  16. public:
  17. class Exception : public std::exception
  18. {
  19. public:
  20. Exception(const std::string& strText);
  21. ~Exception() throw();
  22. const char* what() const throw();
  23. private:
  24. std::string m_strText;
  25. };
  26. // Any changes made to AspectRatio need to be reflected in XSAspectRatio defined in On2XS.h and On2XS.bas
  27. enum AspectRatio
  28. {
  29. AR_Null,
  30. AR_PC,
  31. AR_NTSC,
  32. AR_PAL
  33. };
  34. enum
  35. {
  36. Auto = -2,
  37. Null = -1
  38. };
  39. PlayerModel(long lRateNum = 0, long lRateDenom = 0);
  40. PlayerModel(const PlayerModel& pm);
  41. ~PlayerModel();
  42. PlayerModel& operator=(const PlayerModel& pm);
  43. long bitrate() const;
  44. long bufferMax() const;
  45. long prebufferMax() const;
  46. bool bufferPad() const;
  47. long bufferRequired() const;
  48. long prebufferRequired() const;
  49. long rebufferRequired() const;
  50. AspectRatio sourceAspectRatio() const;
  51. int frameWidth() const;
  52. int frameHeight() const;
  53. void bitrate(long lBitrate);
  54. void bufferMax(long lBufferMax);
  55. void prebufferMax(long lPrebufferMax);
  56. void bufferPad(bool bBufferPad);
  57. void bufferRequired(long lBufferRequired);
  58. void prebufferRequired(long lPrebufferRequired);
  59. void rebufferRequired(long lRebufferRequired);
  60. void frameSize(AspectRatio arSource, int iFrameWidth, int iFrameHeight);
  61. void rate(long lRateNum, long lRateDenom);
  62. void initialize(int iWidthOrig, int iHeightOrig);
  63. void finalize();
  64. void updateBuffer(long lBytesOut, long nSamples, bool bKeyFrame);
  65. long bufferPadding(long lBytesOut, long nSamples);
  66. private:
  67. void initializeInternal();
  68. void updateBuffer0(long lBytesOut, long nSamples, bool bKeyFrame);
  69. void updateBuffer1(long lBytesOut, long nSamples, bool bKeyFrame); // Given bitrate, calculate buffer and prebuffer required
  70. void updateBuffer2(long lBytesOut, long nSamples, bool bKeyFrame); // Given buffer and prebuffer size, calculate bitrate
  71. long m_lBitrate;
  72. long m_lBufferMax;
  73. long m_lPrebufferMax;
  74. bool m_bBufferPad;
  75. long m_lBufferRequired;
  76. long m_lPrebufferRequired;
  77. long m_lRebufferRequired;
  78. AspectRatio m_arSource;
  79. int m_iFrameWidth;
  80. int m_iFrameHeight;
  81. long m_lRateNum;
  82. long m_lRateDenom;
  83. double m_dBytesIn;
  84. double m_dBufferFilled; // Used to calculate buffer required and prebuffer required
  85. double m_dBufferFilled2; // Used to calculate rebuffer required
  86. bool m_bInitialized;
  87. bool m_bInitializedInternal;
  88. bool m_bFinalized;
  89. void (PlayerModel::*m_updateBuffer)(long lBytesOut, long nSamples, bool bKeyFrame);
  90. };
  91. } // namespace on2vp
  92. #endif // PLAYERMODEL_HPP