1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_AVCAST_CONTROLLER_ITEM_H 17 #define OHOS_AVCAST_CONTROLLER_ITEM_H 18 19 #include "i_avcast_controller_proxy.h" 20 #include "avcast_controller_callback_proxy.h" 21 #include "avcast_controller_stub.h" 22 #include "avcast_control_command.h" 23 24 namespace OHOS::AVSession { 25 class AVCastControllerItem : public AVCastControllerStub, public IAVCastControllerProxyListener, 26 public std::enable_shared_from_this<IAVCastControllerProxyListener> { 27 public: 28 AVCastControllerItem(); 29 30 ~AVCastControllerItem(); 31 32 void Init(std::shared_ptr<IAVCastControllerProxy> castControllerProxy, 33 const std::function<void(int32_t, std::vector<int32_t>&)>& validCommandsChangecallback); 34 35 void OnCastPlaybackStateChange(const AVPlaybackState& state) override; 36 37 void OnMediaItemChange(const AVQueueItem& avQueueItem) override; 38 39 void OnPlayNext() override; 40 41 void OnPlayPrevious() override; 42 43 void OnSeekDone(const int32_t seekNumber) override; 44 45 void OnVideoSizeChange(const int32_t width, const int32_t height) override; 46 47 void OnPlayerError(const int32_t errorCode, const std::string& errorMsg) override; 48 49 void OnEndOfStream(const int32_t isLooping) override; 50 51 void OnPlayRequest(const AVQueueItem& avQueueItem) override; 52 53 void OnKeyRequest(const std::string& assetId, const std::vector<uint8_t>& keyRequestData) override; 54 55 void OnValidCommandChange(const std::vector<int32_t> &cmds) override; 56 57 int32_t SendControlCommand(const AVCastControlCommand& cmd) override; 58 59 int32_t Start(const AVQueueItem& avQueueItem) override; 60 61 int32_t Prepare(const AVQueueItem& avQueueItem) override; 62 63 int32_t GetDuration(int32_t& duration) override; 64 65 int32_t GetCastAVPlaybackState(AVPlaybackState& avPlaybackState) override; 66 67 int32_t GetCurrentItem(AVQueueItem& currentItem) override; 68 69 int32_t GetValidCommands(std::vector<int32_t>& cmds) override; 70 71 int32_t SetDisplaySurface(std::string& surfaceId) override; 72 73 int32_t SetCastPlaybackFilter(const AVPlaybackState::PlaybackStateMaskType& filter) override; 74 75 int32_t ProcessMediaKeyResponse(const std::string& assetId, const std::vector<uint8_t>& response) override; 76 77 bool RegisterControllerListener(std::shared_ptr<IAVCastControllerProxy> castControllerProxy); 78 79 int32_t AddAvailableCommand(const int32_t cmd) override; 80 81 int32_t RemoveAvailableCommand(const int32_t cmd) override; 82 83 int32_t HandleCastValidCommandChange(const std::vector<int32_t> &cmds); 84 85 void SetSessionTag(const std::string& tag); 86 87 int32_t Destroy() override; 88 89 protected: 90 int32_t RegisterCallbackInner(const sptr<IRemoteObject>& callback) override; 91 92 private: 93 std::shared_ptr<IAVCastControllerProxy> castControllerProxy_; 94 sptr<IAVCastControllerCallback> callback_; 95 std::recursive_mutex itemCallbackLock_; 96 AVPlaybackState::PlaybackStateMaskType castPlaybackMask_; 97 AVQueueItem currentAVQueueItem_; 98 std::vector<int32_t> supportedCastCmds_; 99 std::function<void(int32_t, std::vector<int32_t>&)> validCommandsChangecallback_; 100 int32_t removeCmdStep_ = 1000; 101 int32_t currentState_ = AVPlaybackState::PLAYBACK_STATE_INITIAL; 102 std::string sessionTag_; 103 bool isSessionCallbackAvailable_ = true; 104 std::mutex callbackToSessionLock_; 105 }; 106 } // namespace OHOS::AVSession 107 #endif // OHOS_AVCAST_CONTROLLER_ITEM_H 108