1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 3DSource implementation */ 18 19 #include "sles_allinclusive.h" 20 21 22 static SLresult I3DSource_SetHeadRelative(SL3DSourceItf self, SLboolean headRelative) 23 { 24 SL_ENTER_INTERFACE 25 26 I3DSource *this = (I3DSource *) self; 27 interface_lock_poke(this); 28 this->mHeadRelative = SL_BOOLEAN_FALSE != headRelative; // normalize 29 interface_unlock_poke(this); 30 result = SL_RESULT_SUCCESS; 31 32 SL_LEAVE_INTERFACE 33 } 34 35 36 static SLresult I3DSource_GetHeadRelative(SL3DSourceItf self, SLboolean *pHeadRelative) 37 { 38 SL_ENTER_INTERFACE 39 40 if (NULL == pHeadRelative) { 41 result = SL_RESULT_PARAMETER_INVALID; 42 } else { 43 I3DSource *this = (I3DSource *) self; 44 interface_lock_peek(this); 45 SLboolean headRelative = this->mHeadRelative; 46 interface_unlock_peek(this); 47 *pHeadRelative = headRelative; 48 result = SL_RESULT_SUCCESS; 49 } 50 51 SL_LEAVE_INTERFACE 52 } 53 54 55 static SLresult I3DSource_SetRolloffDistances(SL3DSourceItf self, 56 SLmillimeter minDistance, SLmillimeter maxDistance) 57 { 58 SL_ENTER_INTERFACE 59 60 if (!((0 < minDistance) && (minDistance <= SL_MILLIMETER_MAX) && 61 (minDistance <= maxDistance) && (maxDistance <= SL_MILLIMETER_MAX))) { 62 result = SL_RESULT_PARAMETER_INVALID; 63 } else { 64 I3DSource *this = (I3DSource *) self; 65 interface_lock_exclusive(this); 66 this->mMinDistance = minDistance; 67 this->mMaxDistance = maxDistance; 68 interface_unlock_exclusive(this); 69 result = SL_RESULT_SUCCESS; 70 } 71 72 SL_LEAVE_INTERFACE 73 } 74 75 76 static SLresult I3DSource_GetRolloffDistances(SL3DSourceItf self, 77 SLmillimeter *pMinDistance, SLmillimeter *pMaxDistance) 78 { 79 SL_ENTER_INTERFACE 80 81 if (NULL == pMinDistance || NULL == pMaxDistance) { 82 result = SL_RESULT_PARAMETER_INVALID; 83 } else { 84 I3DSource *this = (I3DSource *) self; interface_lock_shared(this); 85 SLmillimeter minDistance = this->mMinDistance; 86 SLmillimeter maxDistance = this->mMaxDistance; 87 interface_unlock_shared(this); 88 *pMinDistance = minDistance; 89 *pMaxDistance = maxDistance; 90 result = SL_RESULT_SUCCESS; 91 } 92 93 SL_LEAVE_INTERFACE 94 } 95 96 97 static SLresult I3DSource_SetRolloffMaxDistanceMute(SL3DSourceItf self, SLboolean mute) 98 { 99 SL_ENTER_INTERFACE 100 101 I3DSource *this = (I3DSource *) self; 102 interface_lock_poke(this); 103 this->mRolloffMaxDistanceMute = SL_BOOLEAN_FALSE != mute; // normalize 104 interface_unlock_poke(this); 105 result = SL_RESULT_SUCCESS; 106 107 SL_LEAVE_INTERFACE 108 } 109 110 111 static SLresult I3DSource_GetRolloffMaxDistanceMute(SL3DSourceItf self, SLboolean *pMute) 112 { 113 SL_ENTER_INTERFACE 114 115 if (NULL == pMute) { 116 result = SL_RESULT_PARAMETER_INVALID; 117 } else { 118 I3DSource *this = (I3DSource *) self; 119 interface_lock_peek(this); 120 SLboolean mute = this->mRolloffMaxDistanceMute; 121 interface_unlock_peek(this); 122 *pMute = mute; 123 result = SL_RESULT_SUCCESS; 124 } 125 126 SL_LEAVE_INTERFACE 127 } 128 129 130 static SLresult I3DSource_SetRolloffFactor(SL3DSourceItf self, SLpermille rolloffFactor) 131 { 132 SL_ENTER_INTERFACE 133 134 if (!((0 <= rolloffFactor) && (rolloffFactor <= 10000))) { 135 result = SL_RESULT_PARAMETER_INVALID; 136 } else { 137 I3DSource *this = (I3DSource *) self; 138 interface_lock_poke(this); 139 this->mRolloffFactor = rolloffFactor; 140 interface_unlock_poke(this); 141 result = SL_RESULT_SUCCESS; 142 } 143 144 SL_LEAVE_INTERFACE 145 } 146 147 148 static SLresult I3DSource_GetRolloffFactor(SL3DSourceItf self, SLpermille *pRolloffFactor) 149 { 150 SL_ENTER_INTERFACE 151 152 I3DSource *this = (I3DSource *) self; 153 interface_lock_peek(this); 154 SLpermille rolloffFactor = this->mRolloffFactor; 155 interface_unlock_peek(this); 156 *pRolloffFactor = rolloffFactor; 157 result = SL_RESULT_SUCCESS; 158 159 SL_LEAVE_INTERFACE 160 } 161 162 163 static SLresult I3DSource_SetRoomRolloffFactor(SL3DSourceItf self, SLpermille roomRolloffFactor) 164 { 165 SL_ENTER_INTERFACE 166 167 if (!((0 <= roomRolloffFactor) && (roomRolloffFactor <= 10000))) { 168 result = SL_RESULT_PARAMETER_INVALID; 169 } else { 170 I3DSource *this = (I3DSource *) self; 171 interface_lock_poke(this); 172 this->mRoomRolloffFactor = roomRolloffFactor; 173 interface_unlock_poke(this); 174 result = SL_RESULT_SUCCESS; 175 } 176 177 SL_LEAVE_INTERFACE 178 } 179 180 181 static SLresult I3DSource_GetRoomRolloffFactor(SL3DSourceItf self, SLpermille *pRoomRolloffFactor) 182 { 183 SL_ENTER_INTERFACE 184 185 I3DSource *this = (I3DSource *) self; 186 interface_lock_peek(this); 187 SLpermille roomRolloffFactor = this->mRoomRolloffFactor; 188 interface_unlock_peek(this); 189 *pRoomRolloffFactor = roomRolloffFactor; 190 result = SL_RESULT_SUCCESS; 191 192 SL_LEAVE_INTERFACE 193 } 194 195 196 static SLresult I3DSource_SetRolloffModel(SL3DSourceItf self, SLuint8 model) 197 { 198 SL_ENTER_INTERFACE 199 200 switch (model) { 201 case SL_ROLLOFFMODEL_LINEAR: 202 case SL_ROLLOFFMODEL_EXPONENTIAL: 203 { 204 I3DSource *this = (I3DSource *) self; 205 interface_lock_poke(this); 206 this->mDistanceModel = model; 207 interface_unlock_poke(this); 208 result = SL_RESULT_SUCCESS; 209 } 210 break; 211 default: 212 result = SL_RESULT_PARAMETER_INVALID; 213 break; 214 } 215 216 SL_LEAVE_INTERFACE 217 } 218 219 220 static SLresult I3DSource_GetRolloffModel(SL3DSourceItf self, SLuint8 *pModel) 221 { 222 SL_ENTER_INTERFACE 223 224 I3DSource *this = (I3DSource *) self; 225 interface_lock_peek(this); 226 SLuint8 model = this->mDistanceModel; 227 interface_unlock_peek(this); 228 *pModel = model; 229 result = SL_RESULT_SUCCESS; 230 231 SL_LEAVE_INTERFACE 232 } 233 234 235 static SLresult I3DSource_SetCone(SL3DSourceItf self, SLmillidegree innerAngle, 236 SLmillidegree outerAngle, SLmillibel outerLevel) 237 { 238 SL_ENTER_INTERFACE 239 240 if (!((0 <= innerAngle) && (innerAngle <= 360000) && 241 (0 <= outerAngle) && (outerAngle <= 360000) && 242 (SL_MILLIBEL_MIN <= outerLevel) && (outerLevel <= 0))) { 243 result = SL_RESULT_PARAMETER_INVALID; 244 } else { 245 I3DSource *this = (I3DSource *) self; 246 interface_lock_exclusive(this); 247 this->mConeInnerAngle = innerAngle; 248 this->mConeOuterAngle = outerAngle; 249 this->mConeOuterLevel = outerLevel; 250 interface_unlock_exclusive(this); 251 result = SL_RESULT_SUCCESS; 252 } 253 254 SL_LEAVE_INTERFACE 255 } 256 257 258 static SLresult I3DSource_GetCone(SL3DSourceItf self, SLmillidegree *pInnerAngle, 259 SLmillidegree *pOuterAngle, SLmillibel *pOuterLevel) 260 { 261 SL_ENTER_INTERFACE 262 263 if (NULL == pInnerAngle || NULL == pOuterAngle || NULL == pOuterLevel) { 264 result = SL_RESULT_PARAMETER_INVALID; 265 } else { 266 I3DSource *this = (I3DSource *) self; 267 interface_lock_shared(this); 268 SLmillidegree innerAngle = this->mConeInnerAngle; 269 SLmillidegree outerAngle = this->mConeOuterAngle; 270 SLmillibel outerLevel = this->mConeOuterLevel; 271 interface_unlock_shared(this); 272 *pInnerAngle = innerAngle; 273 *pOuterAngle = outerAngle; 274 *pOuterLevel = outerLevel; 275 result = SL_RESULT_SUCCESS; 276 } 277 278 SL_LEAVE_INTERFACE 279 } 280 281 282 static const struct SL3DSourceItf_ I3DSource_Itf = { 283 I3DSource_SetHeadRelative, 284 I3DSource_GetHeadRelative, 285 I3DSource_SetRolloffDistances, 286 I3DSource_GetRolloffDistances, 287 I3DSource_SetRolloffMaxDistanceMute, 288 I3DSource_GetRolloffMaxDistanceMute, 289 I3DSource_SetRolloffFactor, 290 I3DSource_GetRolloffFactor, 291 I3DSource_SetRoomRolloffFactor, 292 I3DSource_GetRoomRolloffFactor, 293 I3DSource_SetRolloffModel, 294 I3DSource_GetRolloffModel, 295 I3DSource_SetCone, 296 I3DSource_GetCone 297 }; 298 299 void I3DSource_init(void *self) 300 { 301 I3DSource *this = (I3DSource *) self; 302 this->mItf = &I3DSource_Itf; 303 this->mHeadRelative = SL_BOOLEAN_FALSE; 304 this->mRolloffMaxDistanceMute = SL_BOOLEAN_FALSE; 305 this->mMaxDistance = SL_MILLIMETER_MAX; 306 this->mMinDistance = 1000; 307 this->mConeInnerAngle = 360000; 308 this->mConeOuterAngle = 360000; 309 this->mConeOuterLevel = 0; 310 this->mRolloffFactor = 1000; 311 this->mRoomRolloffFactor = 0; 312 this->mDistanceModel = SL_ROLLOFFMODEL_EXPONENTIAL; 313 } 314