180922886Sopenharmony_ci/* 280922886Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480922886Sopenharmony_ci * you may not use this file except in compliance with the License. 580922886Sopenharmony_ci * You may obtain a copy of the License at 680922886Sopenharmony_ci * 780922886Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880922886Sopenharmony_ci * 980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280922886Sopenharmony_ci * See the License for the specific language governing permissions and 1380922886Sopenharmony_ci * limitations under the License. 1480922886Sopenharmony_ci */ 1580922886Sopenharmony_ci 1680922886Sopenharmony_ci#ifndef OHOS_AVCAST_CONTROLLER_ITEM_H 1780922886Sopenharmony_ci#define OHOS_AVCAST_CONTROLLER_ITEM_H 1880922886Sopenharmony_ci 1980922886Sopenharmony_ci#include "i_avcast_controller_proxy.h" 2080922886Sopenharmony_ci#include "avcast_controller_callback_proxy.h" 2180922886Sopenharmony_ci#include "avcast_controller_stub.h" 2280922886Sopenharmony_ci#include "avcast_control_command.h" 2380922886Sopenharmony_ci 2480922886Sopenharmony_cinamespace OHOS::AVSession { 2580922886Sopenharmony_ciclass AVCastControllerItem : public AVCastControllerStub, public IAVCastControllerProxyListener, 2680922886Sopenharmony_ci public std::enable_shared_from_this<IAVCastControllerProxyListener> { 2780922886Sopenharmony_cipublic: 2880922886Sopenharmony_ci AVCastControllerItem(); 2980922886Sopenharmony_ci 3080922886Sopenharmony_ci ~AVCastControllerItem(); 3180922886Sopenharmony_ci 3280922886Sopenharmony_ci void Init(std::shared_ptr<IAVCastControllerProxy> castControllerProxy, 3380922886Sopenharmony_ci const std::function<void(int32_t, std::vector<int32_t>&)>& validCommandsChangecallback); 3480922886Sopenharmony_ci 3580922886Sopenharmony_ci void OnCastPlaybackStateChange(const AVPlaybackState& state) override; 3680922886Sopenharmony_ci 3780922886Sopenharmony_ci void OnMediaItemChange(const AVQueueItem& avQueueItem) override; 3880922886Sopenharmony_ci 3980922886Sopenharmony_ci void OnPlayNext() override; 4080922886Sopenharmony_ci 4180922886Sopenharmony_ci void OnPlayPrevious() override; 4280922886Sopenharmony_ci 4380922886Sopenharmony_ci void OnSeekDone(const int32_t seekNumber) override; 4480922886Sopenharmony_ci 4580922886Sopenharmony_ci void OnVideoSizeChange(const int32_t width, const int32_t height) override; 4680922886Sopenharmony_ci 4780922886Sopenharmony_ci void OnPlayerError(const int32_t errorCode, const std::string& errorMsg) override; 4880922886Sopenharmony_ci 4980922886Sopenharmony_ci void OnEndOfStream(const int32_t isLooping) override; 5080922886Sopenharmony_ci 5180922886Sopenharmony_ci void OnPlayRequest(const AVQueueItem& avQueueItem) override; 5280922886Sopenharmony_ci 5380922886Sopenharmony_ci void OnKeyRequest(const std::string& assetId, const std::vector<uint8_t>& keyRequestData) override; 5480922886Sopenharmony_ci 5580922886Sopenharmony_ci void OnValidCommandChange(const std::vector<int32_t> &cmds) override; 5680922886Sopenharmony_ci 5780922886Sopenharmony_ci int32_t SendControlCommand(const AVCastControlCommand& cmd) override; 5880922886Sopenharmony_ci 5980922886Sopenharmony_ci int32_t Start(const AVQueueItem& avQueueItem) override; 6080922886Sopenharmony_ci 6180922886Sopenharmony_ci int32_t Prepare(const AVQueueItem& avQueueItem) override; 6280922886Sopenharmony_ci 6380922886Sopenharmony_ci int32_t GetDuration(int32_t& duration) override; 6480922886Sopenharmony_ci 6580922886Sopenharmony_ci int32_t GetCastAVPlaybackState(AVPlaybackState& avPlaybackState) override; 6680922886Sopenharmony_ci 6780922886Sopenharmony_ci int32_t GetCurrentItem(AVQueueItem& currentItem) override; 6880922886Sopenharmony_ci 6980922886Sopenharmony_ci int32_t GetValidCommands(std::vector<int32_t>& cmds) override; 7080922886Sopenharmony_ci 7180922886Sopenharmony_ci int32_t SetDisplaySurface(std::string& surfaceId) override; 7280922886Sopenharmony_ci 7380922886Sopenharmony_ci int32_t SetCastPlaybackFilter(const AVPlaybackState::PlaybackStateMaskType& filter) override; 7480922886Sopenharmony_ci 7580922886Sopenharmony_ci int32_t ProcessMediaKeyResponse(const std::string& assetId, const std::vector<uint8_t>& response) override; 7680922886Sopenharmony_ci 7780922886Sopenharmony_ci bool RegisterControllerListener(std::shared_ptr<IAVCastControllerProxy> castControllerProxy); 7880922886Sopenharmony_ci 7980922886Sopenharmony_ci int32_t AddAvailableCommand(const int32_t cmd) override; 8080922886Sopenharmony_ci 8180922886Sopenharmony_ci int32_t RemoveAvailableCommand(const int32_t cmd) override; 8280922886Sopenharmony_ci 8380922886Sopenharmony_ci int32_t HandleCastValidCommandChange(const std::vector<int32_t> &cmds); 8480922886Sopenharmony_ci 8580922886Sopenharmony_ci void SetSessionTag(const std::string tag); 8680922886Sopenharmony_ci 8780922886Sopenharmony_ci int32_t Destroy() override; 8880922886Sopenharmony_ci 8980922886Sopenharmony_ciprotected: 9080922886Sopenharmony_ci int32_t RegisterCallbackInner(const sptr<IRemoteObject>& callback) override; 9180922886Sopenharmony_ci 9280922886Sopenharmony_ciprivate: 9380922886Sopenharmony_ci std::shared_ptr<IAVCastControllerProxy> castControllerProxy_; 9480922886Sopenharmony_ci sptr<IAVCastControllerCallback> callback_; 9580922886Sopenharmony_ci AVPlaybackState::PlaybackStateMaskType castPlaybackMask_; 9680922886Sopenharmony_ci std::function<void(int32_t, std::vector<int32_t>&)> validCommandsChangecallback_; 9780922886Sopenharmony_ci int32_t removeCmdStep_ = 1000; 9880922886Sopenharmony_ci int32_t currentState_ = AVPlaybackState::PLAYBACK_STATE_INITIAL; 9980922886Sopenharmony_ci std::string sessionTag_; 10080922886Sopenharmony_ci bool isSessionCallbackAvailable_ = true; 10180922886Sopenharmony_ci std::recursive_mutex castControllerLock_; 10280922886Sopenharmony_ci std::recursive_mutex castControllerCallbackLock_; 10380922886Sopenharmony_ci std::mutex callbackToSessionLock_; 10480922886Sopenharmony_ci}; 10580922886Sopenharmony_ci} // namespace OHOS::AVSession 10680922886Sopenharmony_ci#endif // OHOS_AVCAST_CONTROLLER_ITEM_H 107