PlayerState.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef PLAYERSTATE_H
  2. #define PLAYERSTATE_H
  3. #include <vector>
  4. #include <memory>
  5. #include <string>
  6. #include "ProtoHelper.h"
  7. #include "Utils.h"
  8. #include "TimeProvider.h"
  9. #include "ConstantParameters.h"
  10. #include "CspotAssert.h"
  11. #include "TrackReference.h"
  12. #include "ConfigJSON.h"
  13. enum class PlaybackState {
  14. Playing,
  15. Stopped,
  16. Loading,
  17. Paused
  18. };
  19. class PlayerState
  20. {
  21. private:
  22. uint32_t seqNum = 0;
  23. uint8_t capabilityIndex = 0;
  24. std::vector<uint8_t> frameData;
  25. std::shared_ptr<TimeProvider> timeProvider;
  26. std::shared_ptr<ConfigJSON> config;
  27. void addCapability(CapabilityType typ, int intValue = -1, std::vector<std::string> stringsValue = std::vector<std::string>());
  28. public:
  29. Frame innerFrame = Frame();
  30. Frame remoteFrame = Frame();
  31. /**
  32. * @brief Player state represents the current state of player.
  33. *
  34. * Responsible for keeping track of player's state. Doesn't control the playback itself.
  35. *
  36. * @param timeProvider synced time provider
  37. */
  38. PlayerState(std::shared_ptr<TimeProvider> timeProvider);
  39. /**
  40. * @brief Updates state according to current playback state.
  41. *
  42. * @param state playback state
  43. */
  44. void setPlaybackState(const PlaybackState state);
  45. /**
  46. * @brief Sets player activity
  47. *
  48. * @param isActive activity status
  49. */
  50. void setActive(bool isActive);
  51. /**
  52. * @brief Simple getter
  53. *
  54. * @return true player is active
  55. * @return false player is inactive
  56. */
  57. bool isActive();
  58. /**
  59. * @brief Updates local track position.
  60. *
  61. * @param position position in milliseconds
  62. */
  63. void updatePositionMs(uint32_t position);
  64. /**
  65. * @brief Sets local volume on internal state.
  66. *
  67. * @param volume volume between 0 and UINT16 max
  68. */
  69. void setVolume(uint32_t volume);
  70. /**
  71. * @brief Enables queue shuffling.
  72. *
  73. * Sets shuffle parameter on local frame, and in case shuffling is enabled,
  74. * it will randomize the entire local queue.
  75. *
  76. * @param shuffle whenever should shuffle
  77. */
  78. void setShuffle(bool shuffle);
  79. /**
  80. * @brief Enables repeat
  81. *
  82. * @param repeat should repeat param
  83. */
  84. void setRepeat(bool repeat);
  85. /**
  86. * @brief Updates local track queue from remote data.
  87. */
  88. void updateTracks();
  89. /**
  90. * @brief Changes playback to next queued track.
  91. *
  92. * Will go back to first track if current track is last track in queue.
  93. * In that case, it will pause if repeat is disabled.
  94. */
  95. bool nextTrack();
  96. /**
  97. * @brief Changes playback to previous queued track.
  98. *
  99. * Will stop if current track is the first track in queue and repeat is disabled.
  100. * If repeat is enabled, it will loop back to the last track in queue.
  101. */
  102. void prevTrack();
  103. /**
  104. * @brief Gets the current track reference.
  105. *
  106. * @return std::shared_ptr<TrackReference> pointer to track reference
  107. */
  108. std::shared_ptr<TrackReference> getCurrentTrack();
  109. /**
  110. * @brief Encodes current frame into binary data via protobuf.
  111. *
  112. * @param typ message type to include in frame type
  113. * @return std::vector<uint8_t> binary frame data
  114. */
  115. std::vector<uint8_t> encodeCurrentFrame(MessageType typ);
  116. };
  117. #endif