PlayerState.h 3.3 KB

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