MediaPlaybackManager.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. *
  3. * Copyright (c) 2021 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #pragma once
  19. #include <app/clusters/media-playback-server/media-playback-server.h>
  20. #include <cstdint>
  21. #include <jni.h>
  22. enum MediaPlaybackRequestAttribute : uint8_t
  23. {
  24. MEDIA_PLAYBACK_ATTRIBUTE_PLAYBACK_STATE = 0,
  25. MEDIA_PLAYBACK_ATTRIBUTE_START_TIME = 1,
  26. MEDIA_PLAYBACK_ATTRIBUTE_DURATION = 2,
  27. MEDIA_PLAYBACK_ATTRIBUTE_SPEED = 3,
  28. MEDIA_PLAYBACK_ATTRIBUTE_SEEK_RANGE_END = 4,
  29. MEDIA_PLAYBACK_ATTRIBUTE_SEEK_RANGE_START = 5,
  30. MEDIA_PLAYBACK_ATTRIBUTE_COUNT,
  31. };
  32. enum MediaPlaybackRequest : uint8_t
  33. {
  34. MEDIA_PLAYBACK_REQUEST_PLAY = 0,
  35. MEDIA_PLAYBACK_REQUEST_PAUSE = 1,
  36. MEDIA_PLAYBACK_REQUEST_STOP = 2,
  37. MEDIA_PLAYBACK_REQUEST_START_OVER = 3,
  38. MEDIA_PLAYBACK_REQUEST_PREVIOUS = 4,
  39. MEDIA_PLAYBACK_REQUEST_NEXT = 5,
  40. MEDIA_PLAYBACK_REQUEST_REWIND = 6,
  41. MEDIA_PLAYBACK_REQUEST_FAST_FORWARD = 7,
  42. MEDIA_PLAYBACK_REQUEST_SKIP_FORWARD = 8,
  43. MEDIA_PLAYBACK_REQUEST_SKIP_BACKWARD = 9,
  44. MEDIA_PLAYBACK_REQUEST_SEEK = 10,
  45. };
  46. using chip::app::AttributeValueEncoder;
  47. using chip::app::CommandResponseHelper;
  48. using MediaPlaybackDelegate = chip::app::Clusters::MediaPlayback::Delegate;
  49. using PlaybackResponseType = chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type;
  50. class MediaPlaybackManager : public MediaPlaybackDelegate
  51. {
  52. public:
  53. static void NewManager(jint endpoint, jobject manager);
  54. void InitializeWithObjects(jobject managerObject);
  55. chip::app::Clusters::MediaPlayback::PlaybackStateEnum HandleGetCurrentState() override;
  56. uint64_t HandleGetStartTime() override;
  57. uint64_t HandleGetDuration() override;
  58. CHIP_ERROR HandleGetSampledPosition(AttributeValueEncoder & aEncoder) override;
  59. float HandleGetPlaybackSpeed() override;
  60. uint64_t HandleGetSeekRangeStart() override;
  61. uint64_t HandleGetSeekRangeEnd() override;
  62. void HandlePlay(CommandResponseHelper<PlaybackResponseType> & helper) override;
  63. void HandlePause(CommandResponseHelper<PlaybackResponseType> & helper) override;
  64. void HandleStop(CommandResponseHelper<PlaybackResponseType> & helper) override;
  65. void HandleFastForward(CommandResponseHelper<PlaybackResponseType> & helper) override;
  66. void HandlePrevious(CommandResponseHelper<PlaybackResponseType> & helper) override;
  67. void HandleRewind(CommandResponseHelper<PlaybackResponseType> & helper) override;
  68. void HandleSkipBackward(CommandResponseHelper<PlaybackResponseType> & helper,
  69. const uint64_t & deltaPositionMilliseconds) override;
  70. void HandleSkipForward(CommandResponseHelper<PlaybackResponseType> & helper,
  71. const uint64_t & deltaPositionMilliseconds) override;
  72. void HandleSeek(CommandResponseHelper<PlaybackResponseType> & helper, const uint64_t & positionMilliseconds) override;
  73. void HandleNext(CommandResponseHelper<PlaybackResponseType> & helper) override;
  74. void HandleStartOver(CommandResponseHelper<PlaybackResponseType> & helper) override;
  75. uint32_t GetFeatureMap(chip::EndpointId endpoint) override;
  76. private:
  77. jobject mMediaPlaybackManagerObject = nullptr;
  78. jmethodID mRequestMethod = nullptr;
  79. jmethodID mGetAttributeMethod = nullptr;
  80. jmethodID mGetPositionMethod = nullptr;
  81. uint64_t HandleMediaRequestGetAttribute(MediaPlaybackRequestAttribute attribute);
  82. long HandleMediaRequestGetLongAttribute(MediaPlaybackRequestAttribute attribute);
  83. chip::app::Clusters::MediaPlayback::Commands::PlaybackResponse::Type
  84. HandleMediaRequest(MediaPlaybackRequest mediaPlaybackRequest, uint64_t deltaPositionMilliseconds);
  85. // TODO: set this based upon meta data from app
  86. uint32_t mDynamicEndpointFeatureMap = 3;
  87. };