1 /* 2 * Copyright (c) 2022-2025 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_AVCONTROL_COMMAND_H 17 #define OHOS_AVCONTROL_COMMAND_H 18 19 #include <cinttypes> 20 #include <functional> 21 #include <string> 22 #include <variant> 23 24 #include "parcel.h" 25 26 namespace OHOS::AVSession { 27 class AVControlCommand : public Parcelable { 28 public: 29 enum { 30 SESSION_CMD_INVALID = -1, 31 SESSION_CMD_PLAY = 0, 32 SESSION_CMD_PAUSE = 1, 33 SESSION_CMD_STOP = 2, 34 SESSION_CMD_PLAY_NEXT = 3, 35 SESSION_CMD_PLAY_PREVIOUS = 4, 36 SESSION_CMD_FAST_FORWARD = 5, 37 SESSION_CMD_REWIND = 6, 38 SESSION_CMD_SEEK = 7, 39 SESSION_CMD_SET_SPEED = 8, 40 SESSION_CMD_SET_LOOP_MODE = 9, 41 SESSION_CMD_TOGGLE_FAVORITE = 10, 42 SESSION_CMD_PLAY_FROM_ASSETID = 11, 43 SESSION_CMD_AVCALL_ANSWER = 12, 44 SESSION_CMD_AVCALL_HANG_UP = 13, 45 SESSION_CMD_AVCALL_TOGGLE_CALL_MUTE = 14, 46 SESSION_CMD_MEDIA_KEY_SUPPORT = 15, 47 SESSION_CMD_SET_TARGET_LOOP_MODE = 16, 48 SESSION_CMD_PLAY_WITH_ASSETID = 17, 49 SESSION_CMD_MAX 50 }; 51 52 AVControlCommand(); 53 ~AVControlCommand() override; 54 55 static AVControlCommand* Unmarshalling(Parcel& data); 56 bool Marshalling(Parcel& parcel) const override; 57 58 bool IsValid() const; 59 60 int32_t SetCommand(int32_t cmd); 61 int32_t GetCommand() const; 62 63 int32_t SetSpeed(double speed); 64 int32_t GetSpeed(double& speed) const; 65 66 int32_t SetForwardTime(int64_t forwardTime); 67 int32_t GetForwardTime(int64_t& forwardTime) const; 68 69 int32_t SetRewindTime(int64_t rewindTime); 70 int32_t GetRewindTime(int64_t& rewindTime) const; 71 72 int32_t SetSeekTime(int64_t time); 73 int32_t GetSeekTime(int64_t& time) const; 74 75 int32_t SetLoopMode(int32_t mode); 76 int32_t GetLoopMode(int32_t& mode) const; 77 78 int32_t SetTargetLoopMode(int32_t targetMode); 79 int32_t GetTargetLoopMode(int32_t& targetMode) const; 80 81 int32_t SetAssetId(const std::string& assetId); 82 int32_t GetAssetId(std::string& assetId) const; 83 84 int32_t SetPlayFromAssetId(int64_t playFromAssetId); 85 int32_t GetPlayFromAssetId(int64_t& playFromAssetId) const; 86 87 int32_t SetPlayWithAssetId(const std::string& playWithAssetId); 88 int32_t GetPlayWithAssetId(std::string& playWithAssetId) const; 89 90 const static inline std::vector<int32_t> localCapability { 91 SESSION_CMD_PLAY, 92 SESSION_CMD_PAUSE, 93 SESSION_CMD_STOP, 94 SESSION_CMD_PLAY_NEXT, 95 SESSION_CMD_PLAY_PREVIOUS, 96 SESSION_CMD_FAST_FORWARD, 97 SESSION_CMD_REWIND, 98 SESSION_CMD_SEEK, 99 SESSION_CMD_SET_SPEED, 100 SESSION_CMD_SET_LOOP_MODE, 101 SESSION_CMD_TOGGLE_FAVORITE, 102 SESSION_CMD_PLAY_FROM_ASSETID, 103 SESSION_CMD_PLAY_WITH_ASSETID, 104 SESSION_CMD_AVCALL_ANSWER, 105 SESSION_CMD_AVCALL_HANG_UP, 106 SESSION_CMD_AVCALL_TOGGLE_CALL_MUTE, 107 SESSION_CMD_MEDIA_KEY_SUPPORT, 108 SESSION_CMD_SET_TARGET_LOOP_MODE, 109 }; 110 111 private: 112 int32_t cmd_ = SESSION_CMD_INVALID; 113 std::variant<int32_t, double, int64_t, bool, std::string> param_; 114 }; 115 } 116 #endif // OHOS_AVCONTROL_COMMAND_H