1 /* 2 * Copyright (c) 2022 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_AVCONTROLLER_ITEM_H 17 #define OHOS_AVCONTROLLER_ITEM_H 18 19 #include <string> 20 21 #include "avsession_item.h" 22 #include "avcontroller_callback_proxy.h" 23 #include "avsession_controller_stub.h" 24 #include "audio_info.h" 25 26 namespace OHOS::AVSession { 27 class AVControllerItem : public AVSessionControllerStub { 28 public: 29 AVControllerItem(pid_t pid, const sptr<AVSessionItem>& session); 30 31 ~AVControllerItem() override; 32 33 int32_t GetAVPlaybackState(AVPlaybackState& state) override; 34 35 int32_t GetAVMetaData(AVMetaData& data) override; 36 37 int32_t SendAVKeyEvent(const MMI::KeyEvent& keyEvent) override; 38 39 int32_t GetLaunchAbility(AbilityRuntime::WantAgent::WantAgent& ability) override; 40 41 int32_t GetValidCommands(std::vector<int32_t>& cmds) override; 42 43 int32_t IsSessionActive(bool& isActive) override; 44 45 int32_t SendControlCommand(const AVControlCommand& cmd) override; 46 47 int32_t SetMetaFilter(const AVMetaData::MetaMaskType& filter) override; 48 49 int32_t SetPlaybackFilter(const AVPlaybackState::PlaybackStateMaskType& filter) override; 50 51 int32_t Destroy() override; 52 53 std::string GetSessionId() override; 54 55 void HandleSessionDestroy(); 56 57 void HandlePlaybackStateChange(const AVPlaybackState& state); 58 59 void HandleMetaDataChange(const AVMetaData& data); 60 61 void HandleActiveStateChange(bool isActive); 62 63 void HandleValidCommandChange(const std::vector<int32_t>& cmds); 64 65 void HandleOutputDeviceChange(const OutputDeviceInfo& outputDeviceInfo); 66 67 pid_t GetPid() const; 68 69 bool HasSession(const std::string& sessionId); 70 71 void SetServiceCallbackForRelease(const std::function<void(AVControllerItem&)>& callback); 72 73 protected: 74 int32_t RegisterCallbackInner(const sptr<IRemoteObject>& callback) override; 75 76 private: 77 pid_t pid_; 78 std::string sessionId_; 79 sptr<AVSessionItem> session_; 80 sptr<IAVControllerCallback> callback_; 81 AVMetaData::MetaMaskType metaMask_; 82 AVPlaybackState::PlaybackStateMaskType playbackMask_; 83 std::function<void(AVControllerItem&)> serviceCallback_; 84 }; 85 } // namespace OHOS::AVSession 86 #endif // OHOS_AVCONTROLLER_ITEM_H