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 int32_t SendControlCommand(const AVCastControlCommand& cmd) override; 54 55 int32_t Start(const AVQueueItem& avQueueItem) override; 56 57 int32_t Prepare(const AVQueueItem& avQueueItem) override; 58 59 int32_t GetDuration(int32_t& duration) override; 60 61 int32_t GetCastAVPlaybackState(AVPlaybackState& avPlaybackState) override; 62 63 int32_t GetCurrentItem(AVQueueItem& currentItem) override; 64 65 int32_t GetValidCommands(std::vector<int32_t>& cmds) override; 66 67 int32_t SetDisplaySurface(std::string& surfaceId) override; 68 69 int32_t SetCastPlaybackFilter(const AVPlaybackState::PlaybackStateMaskType& filter) override; 70 71 bool RegisterControllerListener(std::shared_ptr<IAVCastControllerProxy> castControllerProxy); 72 73 int32_t AddAvailableCommand(const int32_t cmd) override; 74 75 int32_t RemoveAvailableCommand(const int32_t cmd) override; 76 77 int32_t Destroy() override; 78 79 protected: 80 int32_t RegisterCallbackInner(const sptr<IRemoteObject>& callback) override; 81 82 private: 83 std::shared_ptr<IAVCastControllerProxy> castControllerProxy_; 84 sptr<IAVCastControllerCallback> callback_; 85 std::recursive_mutex itemCallbackLock_; 86 AVPlaybackState::PlaybackStateMaskType castPlaybackMask_; 87 AVQueueItem currentAVQueueItem_; 88 std::vector<int32_t> supportedCastCmds_; 89 std::function<void(int32_t, std::vector<int32_t>&)> validCommandsChangecallback_; 90 int32_t removeCmdStep_ = 1000; 91 }; 92 } // namespace OHOS::AVSession 93 #endif // OHOS_AVCAST_CONTROLLER_ITEM_H 94