PlaybackState.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include <stdint.h> // for uint8_t, uint32_t
  3. #include <memory> // for shared_ptr
  4. #include <string> // for string
  5. #include <vector> // for vector
  6. #include "TrackReference.h"
  7. #include "protobuf/spirc.pb.h" // for Frame, TrackRef, CapabilityType, Mess...
  8. namespace cspot {
  9. struct Context;
  10. class PlaybackState {
  11. private:
  12. std::shared_ptr<cspot::Context> ctx;
  13. uint32_t seqNum = 0;
  14. uint8_t capabilityIndex = 0;
  15. std::vector<uint8_t> frameData;
  16. void addCapability(
  17. CapabilityType typ, int intValue = -1,
  18. std::vector<std::string> stringsValue = std::vector<std::string>());
  19. public:
  20. Frame innerFrame;
  21. Frame remoteFrame;
  22. std::vector<TrackReference> remoteTracks;
  23. enum class State { Playing, Stopped, Loading, Paused };
  24. /**
  25. * @brief Player state represents the current state of player.
  26. *
  27. * Responsible for keeping track of player's state. Doesn't control the playback itself.
  28. *
  29. * @param timeProvider synced time provider
  30. */
  31. PlaybackState(std::shared_ptr<cspot::Context> ctx);
  32. ~PlaybackState();
  33. /**
  34. * @brief Updates state according to current playback state.
  35. *
  36. * @param state playback state
  37. */
  38. void setPlaybackState(const PlaybackState::State state);
  39. /**
  40. * @brief Sets player activity
  41. *
  42. * @param isActive activity status
  43. */
  44. void setActive(bool isActive);
  45. /**
  46. * @brief Simple getter
  47. *
  48. * @return true player is active
  49. * @return false player is inactive
  50. */
  51. bool isActive();
  52. /**
  53. * @brief Updates local track position.
  54. *
  55. * @param position position in milliseconds
  56. */
  57. void updatePositionMs(uint32_t position);
  58. /**
  59. * @brief Sets local volume on internal state.
  60. *
  61. * @param volume volume between 0 and UINT16 max
  62. */
  63. void setVolume(uint32_t volume);
  64. /**
  65. * @brief Updates local track queue from remote data.
  66. */
  67. void syncWithRemote();
  68. /**
  69. * @brief Encodes current frame into binary data via protobuf.
  70. *
  71. * @param typ message type to include in frame type
  72. * @return std::vector<uint8_t> binary frame data
  73. */
  74. std::vector<uint8_t> encodeCurrentFrame(MessageType typ);
  75. bool decodeRemoteFrame(std::vector<uint8_t>& data);
  76. };
  77. } // namespace cspot