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 #ifndef AUDIO_INTERRUPT_INFO_H 16 #define AUDIO_INTERRUPT_INFO_H 17 18 #include <parcel.h> 19 #include <audio_stream_info.h> 20 #include <audio_source_type.h> 21 22 namespace OHOS { 23 namespace AudioStandard { 24 enum ActionTarget { 25 CURRENT = 0, 26 INCOMING, 27 BOTH 28 }; 29 30 enum AudioFocuState { 31 ACTIVE = 0, 32 DUCK, 33 PAUSE, 34 STOP 35 }; 36 37 enum InterruptMode { 38 SHARE_MODE = 0, 39 INDEPENDENT_MODE = 1 40 }; 41 42 /** 43 * Enumerates the audio interrupt request type. 44 */ 45 enum InterruptRequestType { 46 INTERRUPT_REQUEST_TYPE_DEFAULT = 0, 47 }; 48 49 /** 50 * Enumerates audio interrupt request result type. 51 */ 52 enum InterruptRequestResultType { 53 INTERRUPT_REQUEST_GRANT = 0, 54 INTERRUPT_REQUEST_REJECT = 1 55 }; 56 57 enum InterruptType { 58 INTERRUPT_TYPE_BEGIN = 1, 59 INTERRUPT_TYPE_END = 2, 60 }; 61 62 enum InterruptHint { 63 INTERRUPT_HINT_NONE = 0, 64 INTERRUPT_HINT_RESUME, 65 INTERRUPT_HINT_PAUSE, 66 INTERRUPT_HINT_STOP, 67 INTERRUPT_HINT_DUCK, 68 INTERRUPT_HINT_UNDUCK 69 }; 70 71 enum InterruptForceType { 72 /** 73 * Force type, system change audio state. 74 */ 75 INTERRUPT_FORCE = 0, 76 /** 77 * Share type, application change audio state. 78 */ 79 INTERRUPT_SHARE 80 }; 81 82 struct InterruptEvent { 83 /** 84 * Interrupt event type, begin or end 85 */ 86 InterruptType eventType; 87 /** 88 * Interrupt force type, force or share 89 */ 90 InterruptForceType forceType; 91 /** 92 * Interrupt hint type. In force type, the audio state already changed, 93 * but in share mode, only provide a hint for application to decide. 94 */ 95 InterruptHint hintType; 96 }; 97 98 // Used internally only by AudioFramework 99 struct InterruptEventInternal { 100 InterruptType eventType; 101 InterruptForceType forceType; 102 InterruptHint hintType; 103 float duckVolume; 104 }; 105 106 enum AudioInterruptChangeType { 107 ACTIVATE_AUDIO_INTERRUPT = 0, 108 DEACTIVATE_AUDIO_INTERRUPT = 1, 109 }; 110 111 // Below APIs are added to handle compilation error in call manager 112 // Once call manager adapt to new interrupt APIs, this will be removed 113 enum InterruptActionType { 114 TYPE_ACTIVATED = 0, 115 TYPE_INTERRUPT = 1 116 }; 117 118 struct InterruptAction { 119 InterruptActionType actionType; 120 InterruptType interruptType; 121 InterruptHint interruptHint; 122 bool activated; 123 }; 124 125 struct AudioFocusEntry { 126 InterruptForceType forceType; 127 InterruptHint hintType; 128 ActionTarget actionOn; 129 bool isReject; 130 }; 131 132 struct AudioFocusType { 133 AudioStreamType streamType; 134 SourceType sourceType; 135 bool isPlay; 136 bool operator==(const AudioFocusType &value) const 137 { 138 return streamType == value.streamType && sourceType == value.sourceType && isPlay == value.isPlay; 139 } 140 141 bool operator<(const AudioFocusType &value) const 142 { 143 return streamType < value.streamType || (streamType == value.streamType && sourceType < value.sourceType); 144 } 145 146 bool operator>(const AudioFocusType &value) const 147 { 148 return streamType > value.streamType || (streamType == value.streamType && sourceType > value.sourceType); 149 } 150 }; 151 152 class AudioInterrupt : public Parcelable { 153 public: 154 StreamUsage streamUsage; 155 ContentType contentType; 156 AudioFocusType audioFocusType; 157 uint32_t sessionID; 158 bool pauseWhenDucked = false; 159 int32_t pid { -1 }; 160 InterruptMode mode { SHARE_MODE }; 161 bool parallelPlayFlag {false}; 162 163 AudioInterrupt() = default; AudioInterrupt(StreamUsage streamUsage_,ContentType contentType_,AudioFocusType audioFocusType_,uint32_t sessionID_)164 AudioInterrupt(StreamUsage streamUsage_, ContentType contentType_, AudioFocusType audioFocusType_, 165 uint32_t sessionID_) : streamUsage(streamUsage_), contentType(contentType_), audioFocusType(audioFocusType_), 166 sessionID(sessionID_) {} 167 ~AudioInterrupt() = default; Marshalling(Parcel & parcel)168 bool Marshalling(Parcel &parcel) const override 169 { 170 return parcel.WriteInt32(static_cast<int32_t>(streamUsage)) 171 && parcel.WriteInt32(static_cast<int32_t>(contentType)) 172 && parcel.WriteInt32(static_cast<int32_t>(audioFocusType.streamType)) 173 && parcel.WriteInt32(static_cast<int32_t>(audioFocusType.sourceType)) 174 && parcel.WriteBool(audioFocusType.isPlay) 175 && parcel.WriteUint32(sessionID) 176 && parcel.WriteBool(pauseWhenDucked) 177 && parcel.WriteInt32(pid) 178 && parcel.WriteInt32(static_cast<int32_t>(mode)) 179 && parcel.WriteBool(parallelPlayFlag); 180 } Unmarshalling(Parcel & parcel)181 void Unmarshalling(Parcel &parcel) 182 { 183 streamUsage = static_cast<StreamUsage>(parcel.ReadInt32()); 184 contentType = static_cast<ContentType>(parcel.ReadInt32()); 185 audioFocusType.streamType = static_cast<AudioStreamType>(parcel.ReadInt32()); 186 audioFocusType.sourceType = static_cast<SourceType>(parcel.ReadInt32()); 187 audioFocusType.isPlay = parcel.ReadBool(); 188 sessionID = parcel.ReadUint32(); 189 pauseWhenDucked = parcel.ReadBool(); 190 pid = parcel.ReadInt32(); 191 mode = static_cast<InterruptMode>(parcel.ReadInt32()); 192 parallelPlayFlag = parcel.ReadBool(); 193 } 194 }; 195 } // namespace AudioStandard 196 } // namespace OHOS 197 #endif // AUDIO_INTERRUPT_INFO_H