1 /* 2 * Copyright (C) 2021 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 package android.media.audio.common; 18 19 import android.annotation.NonNull; 20 import android.media.AudioDescriptor; 21 import android.media.AudioDeviceAttributes; 22 import android.media.AudioFormat; 23 import android.media.AudioSystem; 24 import android.media.MediaFormat; 25 import android.os.Parcel; 26 27 import com.android.internal.annotations.VisibleForTesting; 28 29 import java.util.stream.Collectors; 30 31 /** 32 * This class provides utility functions for converting between 33 * the AIDL types defined in 'android.media.audio.common' and: 34 * - SDK (Java API) types from 'android.media'; 35 * - legacy native (system/audio.h) types. 36 * 37 * Methods that convert between AIDL and SDK types are called 38 * using the following pattern: 39 * 40 * aidl2api_AIDL-type-name_SDK-type-name 41 * api2aidl_SDK-type-name_AIDL-type-name 42 * 43 * Since the range of the SDK values is generally narrower than 44 * the range of AIDL values, when a match can't be found, the 45 * conversion function returns a corresponding 'INVALID' value. 46 * 47 * Methods that convert between AIDL and legacy types are called 48 * using the following pattern: 49 * 50 * aidl2legacy_AIDL-type-name_native-type-name 51 * legacy2aidl_native-type-name_AIDL-type-name 52 * 53 * In general, there is a 1:1 mapping between AIDL and framework 54 * types, and a failure to convert a value indicates a programming 55 * error. Thus, the conversion functions may throw an IllegalArgumentException. 56 * 57 * @hide 58 */ 59 @VisibleForTesting 60 public class AidlConversion { 61 /** Convert from AIDL AudioChannelLayout to legacy audio_channel_mask_t. */ aidl2legacy_AudioChannelLayout_audio_channel_mask_t( @onNull AudioChannelLayout aidl, boolean isInput)62 public static int /*audio_channel_mask_t*/ aidl2legacy_AudioChannelLayout_audio_channel_mask_t( 63 @NonNull AudioChannelLayout aidl, boolean isInput) { 64 Parcel out = Parcel.obtain(); 65 aidl.writeToParcel(out, 0); 66 out.setDataPosition(0); 67 try { 68 return aidl2legacy_AudioChannelLayout_Parcel_audio_channel_mask_t(out, isInput); 69 } finally { 70 out.recycle(); 71 } 72 } 73 74 /** Convert from legacy audio_channel_mask_t to AIDL AudioChannelLayout. */ legacy2aidl_audio_channel_mask_t_AudioChannelLayout( int legacy, boolean isInput)75 public static AudioChannelLayout legacy2aidl_audio_channel_mask_t_AudioChannelLayout( 76 int /*audio_channel_mask_t*/ legacy, boolean isInput) { 77 Parcel in = legacy2aidl_audio_channel_mask_t_AudioChannelLayout_Parcel(legacy, isInput); 78 if (in != null) { 79 try { 80 return AudioChannelLayout.CREATOR.createFromParcel(in); 81 } finally { 82 in.recycle(); 83 } 84 } 85 throw new IllegalArgumentException("Failed to convert legacy audio " 86 + (isInput ? "input" : "output") + " audio_channel_mask_t " + legacy + " value"); 87 } 88 89 /** Convert from AIDL AudioFormatDescription to legacy audio_format_t. */ aidl2legacy_AudioFormatDescription_audio_format_t( @onNull AudioFormatDescription aidl)90 public static int /*audio_format_t*/ aidl2legacy_AudioFormatDescription_audio_format_t( 91 @NonNull AudioFormatDescription aidl) { 92 Parcel out = Parcel.obtain(); 93 aidl.writeToParcel(out, 0); 94 out.setDataPosition(0); 95 try { 96 return aidl2legacy_AudioFormatDescription_Parcel_audio_format_t(out); 97 } finally { 98 out.recycle(); 99 } 100 } 101 102 /** Convert from legacy audio_format_t to AIDL AudioFormatDescription. */ legacy2aidl_audio_format_t_AudioFormatDescription( int legacy)103 public static @NonNull AudioFormatDescription legacy2aidl_audio_format_t_AudioFormatDescription( 104 int /*audio_format_t*/ legacy) { 105 Parcel in = legacy2aidl_audio_format_t_AudioFormatDescription_Parcel(legacy); 106 if (in != null) { 107 try { 108 return AudioFormatDescription.CREATOR.createFromParcel(in); 109 } finally { 110 in.recycle(); 111 } 112 } 113 throw new IllegalArgumentException( 114 "Failed to convert legacy audio_format_t value " + legacy); 115 } 116 117 /** Convert from AIDL AudioEncapsulationMode to legacy audio_encapsulation_mode_t. */ aidl2legacy_AudioEncapsulationMode_audio_encapsulation_mode_t( int aidl)118 public static native int aidl2legacy_AudioEncapsulationMode_audio_encapsulation_mode_t( 119 int /*AudioEncapsulationMode.* */ aidl); 120 121 /** Convert from legacy audio_encapsulation_mode_t to AIDL AudioEncapsulationMode. */ legacy2aidl_audio_encapsulation_mode_t_AudioEncapsulationMode( int legacy)122 public static native int legacy2aidl_audio_encapsulation_mode_t_AudioEncapsulationMode( 123 int /*audio_encapsulation_mode_t*/ legacy); 124 125 /** Convert from AIDL AudioStreamType to legacy audio_stream_type_t. */ aidl2legacy_AudioStreamType_audio_stream_type_t( int aidl)126 public static native int aidl2legacy_AudioStreamType_audio_stream_type_t( 127 int /*AudioStreamType.* */ aidl); 128 129 /** Convert from legacy audio_stream_type_t to AIDL AudioStreamType. */ legacy2aidl_audio_stream_type_t_AudioStreamType( int legacy)130 public static native int legacy2aidl_audio_stream_type_t_AudioStreamType( 131 int /*audio_stream_type_t*/ legacy); 132 133 /** Convert from AIDL AudioUsage to legacy audio_usage_t. */ aidl2legacy_AudioUsage_audio_usage_t(int aidl)134 public static native int aidl2legacy_AudioUsage_audio_usage_t(int /*AudioUsage.* */ aidl); 135 136 /** Convert from legacy audio_usage_t to AIDL AudioUsage. */ legacy2aidl_audio_usage_t_AudioUsage(int legacy)137 public static native int legacy2aidl_audio_usage_t_AudioUsage(int /*audio_usage_t*/ legacy); 138 139 /** Convert from a channel bit of AIDL AudioChannelLayout to SDK AudioFormat.CHANNEL_* bit. */ aidl2api_AudioChannelLayoutBit_AudioFormatChannel( int aidlBit, boolean isInput)140 private static int aidl2api_AudioChannelLayoutBit_AudioFormatChannel( 141 int aidlBit, boolean isInput) { 142 if (isInput) { 143 switch (aidlBit) { 144 case AudioChannelLayout.CHANNEL_FRONT_LEFT: 145 return AudioFormat.CHANNEL_IN_LEFT; 146 case AudioChannelLayout.CHANNEL_FRONT_RIGHT: 147 return AudioFormat.CHANNEL_IN_RIGHT; 148 case AudioChannelLayout.CHANNEL_FRONT_CENTER: 149 return AudioFormat.CHANNEL_IN_CENTER; 150 case AudioChannelLayout.CHANNEL_BACK_CENTER: 151 return AudioFormat.CHANNEL_IN_BACK; 152 // CHANNEL_IN_*_PROCESSED not supported 153 // CHANNEL_IN_PRESSURE not supported 154 // CHANNEL_IN_*_AXIS not supported 155 // CHANNEL_IN_VOICE_* not supported 156 case AudioChannelLayout.CHANNEL_BACK_LEFT: 157 return AudioFormat.CHANNEL_IN_BACK_LEFT; 158 case AudioChannelLayout.CHANNEL_BACK_RIGHT: 159 return AudioFormat.CHANNEL_IN_BACK_RIGHT; 160 case AudioChannelLayout.CHANNEL_LOW_FREQUENCY: 161 return AudioFormat.CHANNEL_IN_LOW_FREQUENCY; 162 case AudioChannelLayout.CHANNEL_TOP_SIDE_LEFT: 163 return AudioFormat.CHANNEL_IN_TOP_LEFT; 164 case AudioChannelLayout.CHANNEL_TOP_SIDE_RIGHT: 165 return AudioFormat.CHANNEL_IN_TOP_RIGHT; 166 default: 167 return AudioFormat.CHANNEL_INVALID; 168 } 169 } else { 170 switch (aidlBit) { 171 case AudioChannelLayout.CHANNEL_FRONT_LEFT: 172 return AudioFormat.CHANNEL_OUT_FRONT_LEFT; 173 case AudioChannelLayout.CHANNEL_FRONT_RIGHT: 174 return AudioFormat.CHANNEL_OUT_FRONT_RIGHT; 175 case AudioChannelLayout.CHANNEL_FRONT_CENTER: 176 return AudioFormat.CHANNEL_OUT_FRONT_CENTER; 177 case AudioChannelLayout.CHANNEL_LOW_FREQUENCY: 178 return AudioFormat.CHANNEL_OUT_LOW_FREQUENCY; 179 case AudioChannelLayout.CHANNEL_BACK_LEFT: 180 return AudioFormat.CHANNEL_OUT_BACK_LEFT; 181 case AudioChannelLayout.CHANNEL_BACK_RIGHT: 182 return AudioFormat.CHANNEL_OUT_BACK_RIGHT; 183 case AudioChannelLayout.CHANNEL_FRONT_LEFT_OF_CENTER: 184 return AudioFormat.CHANNEL_OUT_FRONT_LEFT_OF_CENTER; 185 case AudioChannelLayout.CHANNEL_FRONT_RIGHT_OF_CENTER: 186 return AudioFormat.CHANNEL_OUT_FRONT_RIGHT_OF_CENTER; 187 case AudioChannelLayout.CHANNEL_BACK_CENTER: 188 return AudioFormat.CHANNEL_OUT_BACK_CENTER; 189 case AudioChannelLayout.CHANNEL_SIDE_LEFT: 190 return AudioFormat.CHANNEL_OUT_SIDE_LEFT; 191 case AudioChannelLayout.CHANNEL_SIDE_RIGHT: 192 return AudioFormat.CHANNEL_OUT_SIDE_RIGHT; 193 case AudioChannelLayout.CHANNEL_TOP_CENTER: 194 return AudioFormat.CHANNEL_OUT_TOP_CENTER; 195 case AudioChannelLayout.CHANNEL_TOP_FRONT_LEFT: 196 return AudioFormat.CHANNEL_OUT_TOP_FRONT_LEFT; 197 case AudioChannelLayout.CHANNEL_TOP_FRONT_CENTER: 198 return AudioFormat.CHANNEL_OUT_TOP_FRONT_CENTER; 199 case AudioChannelLayout.CHANNEL_TOP_FRONT_RIGHT: 200 return AudioFormat.CHANNEL_OUT_TOP_FRONT_RIGHT; 201 case AudioChannelLayout.CHANNEL_TOP_BACK_LEFT: 202 return AudioFormat.CHANNEL_OUT_TOP_BACK_LEFT; 203 case AudioChannelLayout.CHANNEL_TOP_BACK_CENTER: 204 return AudioFormat.CHANNEL_OUT_TOP_BACK_CENTER; 205 case AudioChannelLayout.CHANNEL_TOP_BACK_RIGHT: 206 return AudioFormat.CHANNEL_OUT_TOP_BACK_RIGHT; 207 case AudioChannelLayout.CHANNEL_TOP_SIDE_LEFT: 208 return AudioFormat.CHANNEL_OUT_TOP_SIDE_LEFT; 209 case AudioChannelLayout.CHANNEL_TOP_SIDE_RIGHT: 210 return AudioFormat.CHANNEL_OUT_TOP_SIDE_RIGHT; 211 case AudioChannelLayout.CHANNEL_BOTTOM_FRONT_LEFT: 212 return AudioFormat.CHANNEL_OUT_BOTTOM_FRONT_LEFT; 213 case AudioChannelLayout.CHANNEL_BOTTOM_FRONT_CENTER: 214 return AudioFormat.CHANNEL_OUT_BOTTOM_FRONT_CENTER; 215 case AudioChannelLayout.CHANNEL_BOTTOM_FRONT_RIGHT: 216 return AudioFormat.CHANNEL_OUT_BOTTOM_FRONT_RIGHT; 217 case AudioChannelLayout.CHANNEL_LOW_FREQUENCY_2: 218 return AudioFormat.CHANNEL_OUT_LOW_FREQUENCY_2; 219 case AudioChannelLayout.CHANNEL_FRONT_WIDE_LEFT: 220 return AudioFormat.CHANNEL_OUT_FRONT_WIDE_LEFT; 221 case AudioChannelLayout.CHANNEL_FRONT_WIDE_RIGHT: 222 return AudioFormat.CHANNEL_OUT_FRONT_WIDE_RIGHT; 223 case AudioChannelLayout.CHANNEL_HAPTIC_A: 224 return AudioFormat.CHANNEL_OUT_HAPTIC_A; 225 case AudioChannelLayout.CHANNEL_HAPTIC_B: 226 return AudioFormat.CHANNEL_OUT_HAPTIC_B; 227 default: 228 return AudioFormat.CHANNEL_INVALID; 229 } 230 } 231 } 232 233 /** 234 * Convert from a channel bitmask of AIDL AudioChannelLayout to 235 * SDK AudioFormat.CHANNEL_* bitmask. 236 */ aidl2api_AudioChannelLayoutBitMask_AudioFormatChannelMask( int aidlBitMask, boolean isInput)237 private static int aidl2api_AudioChannelLayoutBitMask_AudioFormatChannelMask( 238 int aidlBitMask, boolean isInput) { 239 int apiMask = 0; 240 for (int bit = 1 << 31; bit != 0; bit >>>= 1) { 241 if ((aidlBitMask & bit) == bit) { 242 int apiBit = aidl2api_AudioChannelLayoutBit_AudioFormatChannel(bit, isInput); 243 if (apiBit != AudioFormat.CHANNEL_INVALID) { 244 apiMask |= apiBit; 245 aidlBitMask &= ~bit; 246 if (aidlBitMask == 0) { 247 return apiMask; 248 } 249 } else { 250 break; 251 } 252 } 253 } 254 return AudioFormat.CHANNEL_INVALID; 255 } 256 257 /** Convert from AIDL AudioChannelLayout to SDK AudioFormat.CHANNEL_*. */ aidl2api_AudioChannelLayout_AudioFormatChannelMask( @onNull AudioChannelLayout aidlMask, boolean isInput)258 public static int aidl2api_AudioChannelLayout_AudioFormatChannelMask( 259 @NonNull AudioChannelLayout aidlMask, boolean isInput) { 260 switch (aidlMask.getTag()) { 261 case AudioChannelLayout.none: 262 return isInput ? AudioFormat.CHANNEL_IN_DEFAULT : AudioFormat.CHANNEL_OUT_DEFAULT; 263 case AudioChannelLayout.invalid: 264 return AudioFormat.CHANNEL_INVALID; 265 case AudioChannelLayout.indexMask: 266 // Note that for a proper building of SDK AudioFormat one must 267 // call either 'setChannelMask' or 'setChannelIndexMask' depending 268 // on the variant of AudioChannelLayout. The integer representations 269 // of positional and indexed channel masks are indistinguishable in 270 // the SDK. 271 return aidlMask.getIndexMask(); 272 case AudioChannelLayout.layoutMask: 273 if (isInput) { 274 switch (aidlMask.getLayoutMask()) { 275 case AudioChannelLayout.LAYOUT_MONO: 276 return AudioFormat.CHANNEL_IN_MONO; 277 case AudioChannelLayout.LAYOUT_STEREO: 278 return AudioFormat.CHANNEL_IN_STEREO; 279 case AudioChannelLayout.LAYOUT_FRONT_BACK: 280 return AudioFormat.CHANNEL_IN_FRONT_BACK; 281 case AudioChannelLayout.LAYOUT_2POINT0POINT2: 282 return AudioFormat.CHANNEL_IN_2POINT0POINT2; 283 case AudioChannelLayout.LAYOUT_2POINT1POINT2: 284 return AudioFormat.CHANNEL_IN_2POINT1POINT2; 285 case AudioChannelLayout.LAYOUT_3POINT0POINT2: 286 return AudioFormat.CHANNEL_IN_3POINT0POINT2; 287 case AudioChannelLayout.LAYOUT_3POINT1POINT2: 288 return AudioFormat.CHANNEL_IN_3POINT1POINT2; 289 case AudioChannelLayout.LAYOUT_5POINT1: 290 return AudioFormat.CHANNEL_IN_5POINT1; 291 default: // fall through 292 } 293 } else { 294 switch (aidlMask.getLayoutMask()) { 295 case AudioChannelLayout.LAYOUT_MONO: 296 return AudioFormat.CHANNEL_OUT_MONO; 297 case AudioChannelLayout.LAYOUT_STEREO: 298 return AudioFormat.CHANNEL_OUT_STEREO; 299 case AudioChannelLayout.LAYOUT_2POINT1: 300 return AudioFormat.CHANNEL_OUT_FRONT_LEFT 301 | AudioFormat.CHANNEL_OUT_FRONT_RIGHT 302 | AudioFormat.CHANNEL_OUT_LOW_FREQUENCY; 303 case AudioChannelLayout.LAYOUT_TRI: 304 return AudioFormat.CHANNEL_OUT_FRONT_LEFT 305 | AudioFormat.CHANNEL_OUT_FRONT_RIGHT 306 | AudioFormat.CHANNEL_OUT_FRONT_CENTER; 307 case AudioChannelLayout.LAYOUT_TRI_BACK: 308 return AudioFormat.CHANNEL_OUT_FRONT_LEFT 309 | AudioFormat.CHANNEL_OUT_FRONT_RIGHT 310 | AudioFormat.CHANNEL_OUT_BACK_CENTER; 311 case AudioChannelLayout.LAYOUT_3POINT1: 312 return AudioFormat.CHANNEL_OUT_FRONT_LEFT 313 | AudioFormat.CHANNEL_OUT_FRONT_RIGHT 314 | AudioFormat.CHANNEL_OUT_FRONT_CENTER 315 | AudioFormat.CHANNEL_OUT_LOW_FREQUENCY; 316 case AudioChannelLayout.LAYOUT_2POINT0POINT2: 317 return AudioFormat.CHANNEL_OUT_FRONT_LEFT 318 | AudioFormat.CHANNEL_OUT_FRONT_RIGHT 319 | AudioFormat.CHANNEL_OUT_TOP_SIDE_LEFT 320 | AudioFormat.CHANNEL_OUT_TOP_SIDE_RIGHT; 321 case AudioChannelLayout.LAYOUT_2POINT1POINT2: 322 return AudioFormat.CHANNEL_OUT_FRONT_LEFT 323 | AudioFormat.CHANNEL_OUT_FRONT_RIGHT 324 | AudioFormat.CHANNEL_OUT_TOP_SIDE_LEFT 325 | AudioFormat.CHANNEL_OUT_TOP_SIDE_RIGHT 326 | AudioFormat.CHANNEL_OUT_LOW_FREQUENCY; 327 case AudioChannelLayout.LAYOUT_3POINT0POINT2: 328 return AudioFormat.CHANNEL_OUT_FRONT_LEFT 329 | AudioFormat.CHANNEL_OUT_FRONT_RIGHT 330 | AudioFormat.CHANNEL_OUT_FRONT_CENTER 331 | AudioFormat.CHANNEL_OUT_TOP_SIDE_LEFT 332 | AudioFormat.CHANNEL_OUT_TOP_SIDE_RIGHT; 333 case AudioChannelLayout.LAYOUT_3POINT1POINT2: 334 return AudioFormat.CHANNEL_OUT_FRONT_LEFT 335 | AudioFormat.CHANNEL_OUT_FRONT_RIGHT 336 | AudioFormat.CHANNEL_OUT_FRONT_CENTER 337 | AudioFormat.CHANNEL_OUT_TOP_SIDE_LEFT 338 | AudioFormat.CHANNEL_OUT_TOP_SIDE_RIGHT 339 | AudioFormat.CHANNEL_OUT_LOW_FREQUENCY; 340 case AudioChannelLayout.LAYOUT_QUAD: 341 return AudioFormat.CHANNEL_OUT_QUAD; 342 case AudioChannelLayout.LAYOUT_QUAD_SIDE: 343 return AudioFormat.CHANNEL_OUT_QUAD_SIDE; 344 case AudioChannelLayout.LAYOUT_SURROUND: 345 return AudioFormat.CHANNEL_OUT_SURROUND; 346 case AudioChannelLayout.LAYOUT_PENTA: 347 return AudioFormat.CHANNEL_OUT_QUAD 348 | AudioFormat.CHANNEL_OUT_FRONT_CENTER; 349 case AudioChannelLayout.LAYOUT_5POINT1: 350 return AudioFormat.CHANNEL_OUT_5POINT1; 351 case AudioChannelLayout.LAYOUT_5POINT1_SIDE: 352 return AudioFormat.CHANNEL_OUT_5POINT1_SIDE; 353 case AudioChannelLayout.LAYOUT_5POINT1POINT2: 354 return AudioFormat.CHANNEL_OUT_5POINT1POINT2; 355 case AudioChannelLayout.LAYOUT_5POINT1POINT4: 356 return AudioFormat.CHANNEL_OUT_5POINT1POINT4; 357 case AudioChannelLayout.LAYOUT_6POINT1: 358 return AudioFormat.CHANNEL_OUT_6POINT1; 359 case AudioChannelLayout.LAYOUT_7POINT1: 360 return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; 361 case AudioChannelLayout.LAYOUT_7POINT1POINT2: 362 return AudioFormat.CHANNEL_OUT_7POINT1POINT2; 363 case AudioChannelLayout.LAYOUT_7POINT1POINT4: 364 return AudioFormat.CHANNEL_OUT_7POINT1POINT4; 365 case AudioChannelLayout.LAYOUT_9POINT1POINT4: 366 return AudioFormat.CHANNEL_OUT_9POINT1POINT4; 367 case AudioChannelLayout.LAYOUT_9POINT1POINT6: 368 return AudioFormat.CHANNEL_OUT_9POINT1POINT6; 369 case AudioChannelLayout.LAYOUT_13POINT_360RA: 370 return AudioFormat.CHANNEL_OUT_13POINT_360RA; 371 case AudioChannelLayout.LAYOUT_22POINT2: 372 return AudioFormat.CHANNEL_OUT_22POINT2; 373 case AudioChannelLayout.LAYOUT_MONO_HAPTIC_A: 374 return AudioFormat.CHANNEL_OUT_MONO 375 | AudioFormat.CHANNEL_OUT_HAPTIC_A; 376 case AudioChannelLayout.LAYOUT_STEREO_HAPTIC_A: 377 return AudioFormat.CHANNEL_OUT_STEREO 378 | AudioFormat.CHANNEL_OUT_HAPTIC_A; 379 case AudioChannelLayout.LAYOUT_HAPTIC_AB: 380 return AudioFormat.CHANNEL_OUT_HAPTIC_A 381 | AudioFormat.CHANNEL_OUT_HAPTIC_B; 382 case AudioChannelLayout.LAYOUT_MONO_HAPTIC_AB: 383 return AudioFormat.CHANNEL_OUT_MONO 384 | AudioFormat.CHANNEL_OUT_HAPTIC_A 385 | AudioFormat.CHANNEL_OUT_HAPTIC_B; 386 case AudioChannelLayout.LAYOUT_STEREO_HAPTIC_AB: 387 return AudioFormat.CHANNEL_OUT_STEREO 388 | AudioFormat.CHANNEL_OUT_HAPTIC_A 389 | AudioFormat.CHANNEL_OUT_HAPTIC_B; 390 case AudioChannelLayout.LAYOUT_FRONT_BACK: 391 return AudioFormat.CHANNEL_OUT_FRONT_CENTER 392 | AudioFormat.CHANNEL_OUT_BACK_CENTER; 393 default: // fall through 394 } 395 } 396 // If a match for a predefined layout wasn't found, make a custom one from bits. 397 return aidl2api_AudioChannelLayoutBitMask_AudioFormatChannelMask( 398 aidlMask.getLayoutMask(), isInput); 399 case AudioChannelLayout.voiceMask: 400 if (isInput) { 401 switch (aidlMask.getVoiceMask()) { 402 // AudioFormat input masks match legacy native masks directly, 403 // thus we add AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO here. 404 case AudioChannelLayout.VOICE_UPLINK_MONO: 405 return AudioFormat.CHANNEL_IN_VOICE_UPLINK 406 | AudioFormat.CHANNEL_IN_MONO; 407 case AudioChannelLayout.VOICE_DNLINK_MONO: 408 return AudioFormat.CHANNEL_IN_VOICE_DNLINK 409 | AudioFormat.CHANNEL_IN_MONO; 410 case AudioChannelLayout.VOICE_CALL_MONO: 411 return AudioFormat.CHANNEL_IN_VOICE_UPLINK 412 | AudioFormat.CHANNEL_IN_VOICE_DNLINK 413 | AudioFormat.CHANNEL_IN_MONO; 414 } 415 } 416 return AudioFormat.CHANNEL_INVALID; 417 default: 418 return AudioFormat.CHANNEL_INVALID; 419 } 420 } 421 422 /** Convert from AIDL AudioConfig to SDK AudioFormat. */ aidl2api_AudioConfig_AudioFormat( @onNull AudioConfig aidl, boolean isInput)423 public static @NonNull AudioFormat aidl2api_AudioConfig_AudioFormat( 424 @NonNull AudioConfig aidl, boolean isInput) { 425 // Only information from the encapsulated AudioConfigBase is used. 426 return aidl2api_AudioConfigBase_AudioFormat(aidl.base, isInput); 427 } 428 429 /** Convert from AIDL AudioConfigBase to SDK AudioFormat. */ aidl2api_AudioConfigBase_AudioFormat( @onNull AudioConfigBase aidl, boolean isInput)430 public static @NonNull AudioFormat aidl2api_AudioConfigBase_AudioFormat( 431 @NonNull AudioConfigBase aidl, boolean isInput) { 432 AudioFormat.Builder apiBuilder = new AudioFormat.Builder(); 433 apiBuilder.setSampleRate(aidl.sampleRate); 434 if (aidl.channelMask.getTag() != AudioChannelLayout.indexMask) { 435 apiBuilder.setChannelMask(aidl2api_AudioChannelLayout_AudioFormatChannelMask( 436 aidl.channelMask, isInput)); 437 } else { 438 apiBuilder.setChannelIndexMask(aidl2api_AudioChannelLayout_AudioFormatChannelMask( 439 aidl.channelMask, isInput)); 440 } 441 apiBuilder.setEncoding(aidl2api_AudioFormat_AudioFormatEncoding(aidl.format)); 442 return apiBuilder.build(); 443 } 444 445 /** Convert from AIDL AudioFormat to SDK AudioFormat.ENCODING_*. */ aidl2api_AudioFormat_AudioFormatEncoding( @onNull AudioFormatDescription aidl)446 public static int aidl2api_AudioFormat_AudioFormatEncoding( 447 @NonNull AudioFormatDescription aidl) { 448 switch (aidl.type) { 449 case AudioFormatType.PCM: 450 switch (aidl.pcm) { 451 case PcmType.UINT_8_BIT: 452 return AudioFormat.ENCODING_PCM_8BIT; 453 case PcmType.INT_16_BIT: 454 return AudioFormat.ENCODING_PCM_16BIT; 455 case PcmType.INT_32_BIT: 456 return AudioFormat.ENCODING_PCM_32BIT; 457 case PcmType.FIXED_Q_8_24: 458 case PcmType.FLOAT_32_BIT: 459 return AudioFormat.ENCODING_PCM_FLOAT; 460 case PcmType.INT_24_BIT: 461 return AudioFormat.ENCODING_PCM_24BIT_PACKED; 462 default: 463 return AudioFormat.ENCODING_INVALID; 464 } 465 case AudioFormatType.NON_PCM: // same as DEFAULT 466 if (aidl.encoding != null && !aidl.encoding.isEmpty()) { 467 if (MediaFormat.MIMETYPE_AUDIO_AC3.equals(aidl.encoding)) { 468 return AudioFormat.ENCODING_AC3; 469 } else if (MediaFormat.MIMETYPE_AUDIO_EAC3.equals(aidl.encoding)) { 470 return AudioFormat.ENCODING_E_AC3; 471 } else if (MediaFormat.MIMETYPE_AUDIO_DTS.equals(aidl.encoding)) { 472 return AudioFormat.ENCODING_DTS; 473 } else if (MediaFormat.MIMETYPE_AUDIO_DTS_HD.equals(aidl.encoding)) { 474 return AudioFormat.ENCODING_DTS_HD; 475 } else if (MediaFormat.MIMETYPE_AUDIO_MPEG.equals(aidl.encoding)) { 476 return AudioFormat.ENCODING_MP3; 477 } else if (MediaFormat.MIMETYPE_AUDIO_AAC_LC.equals(aidl.encoding)) { 478 return AudioFormat.ENCODING_AAC_LC; 479 } else if (MediaFormat.MIMETYPE_AUDIO_AAC_HE_V1.equals(aidl.encoding)) { 480 return AudioFormat.ENCODING_AAC_HE_V1; 481 } else if (MediaFormat.MIMETYPE_AUDIO_AAC_HE_V2.equals(aidl.encoding)) { 482 return AudioFormat.ENCODING_AAC_HE_V2; 483 } else if (MediaFormat.MIMETYPE_AUDIO_IEC61937.equals(aidl.encoding) 484 && aidl.pcm == PcmType.INT_16_BIT) { 485 return AudioFormat.ENCODING_IEC61937; 486 } else if (MediaFormat.MIMETYPE_AUDIO_DOLBY_TRUEHD.equals( 487 aidl.encoding)) { 488 return AudioFormat.ENCODING_DOLBY_TRUEHD; 489 } else if (MediaFormat.MIMETYPE_AUDIO_AAC_ELD.equals(aidl.encoding)) { 490 return AudioFormat.ENCODING_AAC_ELD; 491 } else if (MediaFormat.MIMETYPE_AUDIO_AAC_XHE.equals(aidl.encoding)) { 492 return AudioFormat.ENCODING_AAC_XHE; 493 } else if (MediaFormat.MIMETYPE_AUDIO_AC4.equals(aidl.encoding)) { 494 return AudioFormat.ENCODING_AC4; 495 } else if (MediaFormat.MIMETYPE_AUDIO_EAC3_JOC.equals(aidl.encoding)) { 496 return AudioFormat.ENCODING_E_AC3_JOC; 497 } else if (MediaFormat.MIMETYPE_AUDIO_DOLBY_MAT.equals(aidl.encoding) 498 || aidl.encoding.startsWith( 499 MediaFormat.MIMETYPE_AUDIO_DOLBY_MAT + ".")) { 500 return AudioFormat.ENCODING_DOLBY_MAT; 501 } else if (MediaFormat.MIMETYPE_AUDIO_OPUS.equals(aidl.encoding)) { 502 return AudioFormat.ENCODING_OPUS; 503 } else if (MediaFormat.MIMETYPE_AUDIO_MPEGH_BL_L3.equals(aidl.encoding)) { 504 return AudioFormat.ENCODING_MPEGH_BL_L3; 505 } else if (MediaFormat.MIMETYPE_AUDIO_MPEGH_BL_L4.equals(aidl.encoding)) { 506 return AudioFormat.ENCODING_MPEGH_BL_L4; 507 } else if (MediaFormat.MIMETYPE_AUDIO_MPEGH_LC_L3.equals(aidl.encoding)) { 508 return AudioFormat.ENCODING_MPEGH_LC_L3; 509 } else if (MediaFormat.MIMETYPE_AUDIO_MPEGH_LC_L4.equals(aidl.encoding)) { 510 return AudioFormat.ENCODING_MPEGH_LC_L4; 511 } else if (MediaFormat.MIMETYPE_AUDIO_DTS_UHD.equals(aidl.encoding)) { 512 return AudioFormat.ENCODING_DTS_UHD_P1; 513 } else if (MediaFormat.MIMETYPE_AUDIO_DRA.equals(aidl.encoding)) { 514 return AudioFormat.ENCODING_DRA; 515 } else { 516 return AudioFormat.ENCODING_INVALID; 517 } 518 } else { 519 return AudioFormat.ENCODING_DEFAULT; 520 } 521 case AudioFormatType.SYS_RESERVED_INVALID: 522 default: 523 return AudioFormat.ENCODING_INVALID; 524 } 525 } 526 527 /** 528 * Convert from SDK AudioDeviceAttributes to AIDL AudioPort. 529 */ api2aidl_AudioDeviceAttributes_AudioPort( @onNull AudioDeviceAttributes attributes)530 public static AudioPort api2aidl_AudioDeviceAttributes_AudioPort( 531 @NonNull AudioDeviceAttributes attributes) { 532 AudioPort port = new AudioPort(); 533 port.name = attributes.getName(); 534 // TO DO: b/211611504 Convert attributes.getAudioProfiles() to AIDL as well. 535 port.profiles = new AudioProfile[]{}; 536 port.extraAudioDescriptors = attributes.getAudioDescriptors().stream() 537 .map(descriptor -> api2aidl_AudioDescriptor_ExtraAudioDescriptor(descriptor)) 538 .collect(Collectors.toList()).toArray(ExtraAudioDescriptor[]::new); 539 port.flags = new AudioIoFlags(); 540 port.gains = new AudioGain[]{}; 541 AudioPortDeviceExt deviceExt = new AudioPortDeviceExt(); 542 deviceExt.device = new AudioDevice(); 543 deviceExt.encodedFormats = new AudioFormatDescription[]{}; 544 deviceExt.device.type = 545 api2aidl_NativeType_AudioDeviceDescription(attributes.getInternalType()); 546 deviceExt.device.address = AudioDeviceAddress.id(attributes.getAddress()); 547 port.ext = AudioPortExt.device(deviceExt); 548 return port; 549 } 550 551 /** 552 * Convert from SDK AudioDescriptor to AIDL ExtraAudioDescriptor. 553 */ api2aidl_AudioDescriptor_ExtraAudioDescriptor( @onNull AudioDescriptor descriptor)554 public static ExtraAudioDescriptor api2aidl_AudioDescriptor_ExtraAudioDescriptor( 555 @NonNull AudioDescriptor descriptor) { 556 ExtraAudioDescriptor extraDescriptor = new ExtraAudioDescriptor(); 557 extraDescriptor.standard = 558 api2aidl_AudioDescriptorStandard_AudioStandard(descriptor.getStandard()); 559 extraDescriptor.audioDescriptor = descriptor.getDescriptor(); 560 extraDescriptor.encapsulationType = 561 api2aidl_AudioProfileEncapsulationType_AudioEncapsulationType( 562 descriptor.getEncapsulationType()); 563 return extraDescriptor; 564 } 565 566 /** 567 * Convert from SDK AudioDescriptor to AIDL ExtraAudioDescriptor. 568 */ aidl2api_ExtraAudioDescriptor_AudioDescriptor( @onNull ExtraAudioDescriptor extraDescriptor)569 public static @NonNull AudioDescriptor aidl2api_ExtraAudioDescriptor_AudioDescriptor( 570 @NonNull ExtraAudioDescriptor extraDescriptor) { 571 AudioDescriptor descriptor = new AudioDescriptor( 572 aidl2api_AudioStandard_AudioDescriptorStandard(extraDescriptor.standard), 573 aidl2api_AudioEncapsulationType_AudioProfileEncapsulationType( 574 extraDescriptor.encapsulationType), 575 extraDescriptor.audioDescriptor); 576 return descriptor; 577 } 578 579 /** 580 * Convert from SDK AudioDescriptor#mStandard to AIDL AudioStandard 581 */ 582 @AudioStandard api2aidl_AudioDescriptorStandard_AudioStandard( @udioDescriptor.AudioDescriptorStandard int standard)583 public static int api2aidl_AudioDescriptorStandard_AudioStandard( 584 @AudioDescriptor.AudioDescriptorStandard int standard) { 585 switch (standard) { 586 case AudioDescriptor.STANDARD_EDID: 587 return AudioStandard.EDID; 588 case AudioDescriptor.STANDARD_SADB: 589 return AudioStandard.SADB; 590 case AudioDescriptor.STANDARD_VSADB: 591 return AudioStandard.VSADB; 592 case AudioDescriptor.STANDARD_NONE: 593 default: 594 return AudioStandard.NONE; 595 } 596 } 597 598 /** 599 * Convert from AIDL AudioStandard to SDK AudioDescriptor#mStandard 600 */ 601 @AudioDescriptor.AudioDescriptorStandard aidl2api_AudioStandard_AudioDescriptorStandard(@udioStandard int standard)602 public static int aidl2api_AudioStandard_AudioDescriptorStandard(@AudioStandard int standard) { 603 switch (standard) { 604 case AudioStandard.EDID: 605 return AudioDescriptor.STANDARD_EDID; 606 case AudioStandard.SADB: 607 return AudioDescriptor.STANDARD_SADB; 608 case AudioStandard.VSADB: 609 return AudioDescriptor.STANDARD_VSADB; 610 case AudioStandard.NONE: 611 default: 612 return AudioDescriptor.STANDARD_NONE; 613 } 614 } 615 616 /** 617 * Convert from SDK AudioProfile.EncapsulationType to AIDL AudioEncapsulationType 618 */ 619 @AudioEncapsulationType api2aidl_AudioProfileEncapsulationType_AudioEncapsulationType( @ndroid.media.AudioProfile.EncapsulationType int type)620 public static int api2aidl_AudioProfileEncapsulationType_AudioEncapsulationType( 621 @android.media.AudioProfile.EncapsulationType int type) { 622 switch (type) { 623 case android.media.AudioProfile.AUDIO_ENCAPSULATION_TYPE_IEC61937: 624 return AudioEncapsulationType.IEC61937; 625 case android.media.AudioProfile.AUDIO_ENCAPSULATION_TYPE_PCM: 626 return AudioEncapsulationType.PCM; 627 case android.media.AudioProfile.AUDIO_ENCAPSULATION_TYPE_NONE: 628 default: 629 return AudioEncapsulationType.NONE; 630 } 631 } 632 633 /** 634 * Convert from AIDL AudioEncapsulationType to SDK AudioProfile.EncapsulationType 635 */ 636 @android.media.AudioProfile.EncapsulationType aidl2api_AudioEncapsulationType_AudioProfileEncapsulationType( @udioEncapsulationType int type)637 public static int aidl2api_AudioEncapsulationType_AudioProfileEncapsulationType( 638 @AudioEncapsulationType int type) { 639 switch (type) { 640 case AudioEncapsulationType.IEC61937: 641 return android.media.AudioProfile.AUDIO_ENCAPSULATION_TYPE_IEC61937; 642 case AudioEncapsulationType.PCM: 643 return android.media.AudioProfile.AUDIO_ENCAPSULATION_TYPE_PCM; 644 case AudioEncapsulationType.NONE: 645 default: 646 return android.media.AudioProfile.AUDIO_ENCAPSULATION_TYPE_NONE; 647 } 648 } 649 650 /** 651 * Convert from SDK native type to AIDL AudioDeviceDescription 652 */ api2aidl_NativeType_AudioDeviceDescription( int nativeType)653 public static AudioDeviceDescription api2aidl_NativeType_AudioDeviceDescription( 654 int nativeType) { 655 AudioDeviceDescription aidl = new AudioDeviceDescription(); 656 aidl.connection = ""; 657 switch (nativeType) { 658 case AudioSystem.DEVICE_OUT_EARPIECE: 659 aidl.type = AudioDeviceType.OUT_SPEAKER_EARPIECE; 660 break; 661 case AudioSystem.DEVICE_OUT_SPEAKER: 662 aidl.type = AudioDeviceType.OUT_SPEAKER; 663 break; 664 case AudioSystem.DEVICE_OUT_WIRED_HEADPHONE: 665 aidl.type = AudioDeviceType.OUT_HEADPHONE; 666 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 667 break; 668 case AudioSystem.DEVICE_OUT_BLUETOOTH_SCO: 669 aidl.type = AudioDeviceType.OUT_DEVICE; 670 aidl.connection = AudioDeviceDescription.CONNECTION_BT_SCO; 671 break; 672 case AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_CARKIT: 673 aidl.type = AudioDeviceType.OUT_CARKIT; 674 aidl.connection = AudioDeviceDescription.CONNECTION_BT_SCO; 675 break; 676 case AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES: 677 aidl.type = AudioDeviceType.OUT_HEADPHONE; 678 aidl.connection = AudioDeviceDescription.CONNECTION_BT_A2DP; 679 break; 680 case AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER: 681 aidl.type = AudioDeviceType.OUT_SPEAKER; 682 aidl.connection = AudioDeviceDescription.CONNECTION_BT_A2DP; 683 break; 684 case AudioSystem.DEVICE_OUT_TELEPHONY_TX: 685 aidl.type = AudioDeviceType.OUT_TELEPHONY_TX; 686 break; 687 case AudioSystem.DEVICE_OUT_AUX_LINE: 688 aidl.type = AudioDeviceType.OUT_LINE_AUX; 689 break; 690 case AudioSystem.DEVICE_OUT_SPEAKER_SAFE: 691 aidl.type = AudioDeviceType.OUT_SPEAKER_SAFE; 692 break; 693 case AudioSystem.DEVICE_OUT_HEARING_AID: 694 aidl.type = AudioDeviceType.OUT_HEARING_AID; 695 aidl.connection = AudioDeviceDescription.CONNECTION_WIRELESS; 696 break; 697 case AudioSystem.DEVICE_OUT_ECHO_CANCELLER: 698 aidl.type = AudioDeviceType.OUT_ECHO_CANCELLER; 699 break; 700 case AudioSystem.DEVICE_OUT_BLE_SPEAKER: 701 aidl.type = AudioDeviceType.OUT_SPEAKER; 702 aidl.connection = AudioDeviceDescription.CONNECTION_BT_LE; 703 break; 704 case AudioSystem.DEVICE_OUT_BLE_BROADCAST: 705 aidl.type = AudioDeviceType.OUT_BROADCAST; 706 aidl.connection = AudioDeviceDescription.CONNECTION_BT_LE; 707 break; 708 case AudioSystem.DEVICE_IN_BUILTIN_MIC: 709 aidl.type = AudioDeviceType.IN_MICROPHONE; 710 break; 711 case AudioSystem.DEVICE_IN_BACK_MIC: 712 aidl.type = AudioDeviceType.IN_MICROPHONE_BACK; 713 break; 714 case AudioSystem.DEVICE_IN_TELEPHONY_RX: 715 aidl.type = AudioDeviceType.IN_TELEPHONY_RX; 716 break; 717 case AudioSystem.DEVICE_IN_TV_TUNER: 718 aidl.type = AudioDeviceType.IN_TV_TUNER; 719 break; 720 case AudioSystem.DEVICE_IN_LOOPBACK: 721 aidl.type = AudioDeviceType.IN_LOOPBACK; 722 break; 723 case AudioSystem.DEVICE_IN_BLUETOOTH_BLE: 724 aidl.type = AudioDeviceType.IN_DEVICE; 725 aidl.connection = AudioDeviceDescription.CONNECTION_BT_LE; 726 break; 727 case AudioSystem.DEVICE_IN_ECHO_REFERENCE: 728 aidl.type = AudioDeviceType.IN_ECHO_REFERENCE; 729 break; 730 case AudioSystem.DEVICE_IN_WIRED_HEADSET: 731 aidl.type = AudioDeviceType.IN_HEADSET; 732 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 733 break; 734 case AudioSystem.DEVICE_OUT_WIRED_HEADSET: 735 aidl.type = AudioDeviceType.OUT_HEADSET; 736 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 737 break; 738 case AudioSystem.DEVICE_IN_BLUETOOTH_SCO_HEADSET: 739 aidl.type = AudioDeviceType.IN_HEADSET; 740 aidl.connection = AudioDeviceDescription.CONNECTION_BT_SCO; 741 break; 742 case AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_HEADSET: 743 aidl.type = AudioDeviceType.OUT_HEADSET; 744 aidl.connection = AudioDeviceDescription.CONNECTION_BT_SCO; 745 break; 746 case AudioSystem.DEVICE_IN_HDMI: 747 aidl.type = AudioDeviceType.IN_DEVICE; 748 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI; 749 break; 750 case AudioSystem.DEVICE_OUT_HDMI: 751 aidl.type = AudioDeviceType.OUT_DEVICE; 752 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI; 753 break; 754 case AudioSystem.DEVICE_IN_REMOTE_SUBMIX: 755 aidl.type = AudioDeviceType.IN_SUBMIX; 756 break; 757 case AudioSystem.DEVICE_OUT_REMOTE_SUBMIX: 758 aidl.type = AudioDeviceType.OUT_SUBMIX; 759 break; 760 case AudioSystem.DEVICE_IN_ANLG_DOCK_HEADSET: 761 aidl.type = AudioDeviceType.IN_DOCK; 762 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 763 break; 764 case AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET: 765 aidl.type = AudioDeviceType.OUT_DOCK; 766 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 767 break; 768 case AudioSystem.DEVICE_IN_DGTL_DOCK_HEADSET: 769 aidl.type = AudioDeviceType.IN_DOCK; 770 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 771 break; 772 case AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET: 773 aidl.type = AudioDeviceType.OUT_DOCK; 774 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 775 break; 776 case AudioSystem.DEVICE_IN_USB_ACCESSORY: 777 aidl.type = AudioDeviceType.IN_ACCESSORY; 778 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 779 break; 780 case AudioSystem.DEVICE_OUT_USB_ACCESSORY: 781 aidl.type = AudioDeviceType.OUT_ACCESSORY; 782 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 783 break; 784 case AudioSystem.DEVICE_IN_USB_DEVICE: 785 aidl.type = AudioDeviceType.IN_DEVICE; 786 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 787 break; 788 case AudioSystem.DEVICE_OUT_USB_DEVICE: 789 aidl.type = AudioDeviceType.OUT_DEVICE; 790 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 791 break; 792 case AudioSystem.DEVICE_IN_FM_TUNER: 793 aidl.type = AudioDeviceType.IN_FM_TUNER; 794 break; 795 case AudioSystem.DEVICE_OUT_FM: 796 aidl.type = AudioDeviceType.OUT_FM; 797 break; 798 case AudioSystem.DEVICE_IN_LINE: 799 aidl.type = AudioDeviceType.IN_DEVICE; 800 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 801 break; 802 case AudioSystem.DEVICE_OUT_LINE: 803 aidl.type = AudioDeviceType.OUT_DEVICE; 804 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 805 break; 806 case AudioSystem.DEVICE_IN_SPDIF: 807 aidl.type = AudioDeviceType.IN_DEVICE; 808 aidl.connection = AudioDeviceDescription.CONNECTION_SPDIF; 809 break; 810 case AudioSystem.DEVICE_OUT_SPDIF: 811 aidl.type = AudioDeviceType.OUT_DEVICE; 812 aidl.connection = AudioDeviceDescription.CONNECTION_SPDIF; 813 break; 814 case AudioSystem.DEVICE_IN_BLUETOOTH_A2DP: 815 aidl.type = AudioDeviceType.IN_DEVICE; 816 aidl.connection = AudioDeviceDescription.CONNECTION_BT_A2DP; 817 break; 818 case AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP: 819 aidl.type = AudioDeviceType.OUT_DEVICE; 820 aidl.connection = AudioDeviceDescription.CONNECTION_BT_A2DP; 821 break; 822 case AudioSystem.DEVICE_IN_IP: 823 aidl.type = AudioDeviceType.IN_DEVICE; 824 aidl.connection = AudioDeviceDescription.CONNECTION_IP_V4; 825 break; 826 case AudioSystem.DEVICE_OUT_IP: 827 aidl.type = AudioDeviceType.OUT_DEVICE; 828 aidl.connection = AudioDeviceDescription.CONNECTION_IP_V4; 829 break; 830 case AudioSystem.DEVICE_IN_BUS: 831 aidl.type = AudioDeviceType.IN_DEVICE; 832 aidl.connection = AudioDeviceDescription.CONNECTION_BUS; 833 break; 834 case AudioSystem.DEVICE_OUT_BUS: 835 aidl.type = AudioDeviceType.OUT_DEVICE; 836 aidl.connection = AudioDeviceDescription.CONNECTION_BUS; 837 break; 838 case AudioSystem.DEVICE_IN_PROXY: 839 aidl.type = AudioDeviceType.IN_AFE_PROXY; 840 break; 841 case AudioSystem.DEVICE_OUT_PROXY: 842 aidl.type = AudioDeviceType.OUT_AFE_PROXY; 843 break; 844 case AudioSystem.DEVICE_IN_USB_HEADSET: 845 aidl.type = AudioDeviceType.IN_HEADSET; 846 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 847 break; 848 case AudioSystem.DEVICE_OUT_USB_HEADSET: 849 aidl.type = AudioDeviceType.OUT_HEADSET; 850 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 851 break; 852 case AudioSystem.DEVICE_IN_HDMI_ARC: 853 aidl.type = AudioDeviceType.IN_DEVICE; 854 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI_ARC; 855 break; 856 case AudioSystem.DEVICE_OUT_HDMI_ARC: 857 aidl.type = AudioDeviceType.OUT_DEVICE; 858 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI_ARC; 859 break; 860 case AudioSystem.DEVICE_IN_HDMI_EARC: 861 aidl.type = AudioDeviceType.IN_DEVICE; 862 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI_EARC; 863 break; 864 case AudioSystem.DEVICE_OUT_HDMI_EARC: 865 aidl.type = AudioDeviceType.OUT_DEVICE; 866 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI_EARC; 867 break; 868 case AudioSystem.DEVICE_IN_BLE_HEADSET: 869 aidl.type = AudioDeviceType.IN_HEADSET; 870 aidl.connection = AudioDeviceDescription.CONNECTION_BT_LE; 871 break; 872 case AudioSystem.DEVICE_OUT_BLE_HEADSET: 873 aidl.type = AudioDeviceType.OUT_HEADSET; 874 aidl.connection = AudioDeviceDescription.CONNECTION_BT_LE; 875 break; 876 case AudioSystem.DEVICE_IN_DEFAULT: 877 aidl.type = AudioDeviceType.IN_DEFAULT; 878 break; 879 case AudioSystem.DEVICE_OUT_DEFAULT: 880 aidl.type = AudioDeviceType.OUT_DEFAULT; 881 break; 882 default: 883 aidl.type = AudioDeviceType.NONE; 884 } 885 return aidl; 886 } 887 aidl2legacy_AudioChannelLayout_Parcel_audio_channel_mask_t( Parcel aidl, boolean isInput)888 private static native int aidl2legacy_AudioChannelLayout_Parcel_audio_channel_mask_t( 889 Parcel aidl, boolean isInput); legacy2aidl_audio_channel_mask_t_AudioChannelLayout_Parcel( int legacy, boolean isInput)890 private static native Parcel legacy2aidl_audio_channel_mask_t_AudioChannelLayout_Parcel( 891 int legacy, boolean isInput); aidl2legacy_AudioFormatDescription_Parcel_audio_format_t( Parcel aidl)892 private static native int aidl2legacy_AudioFormatDescription_Parcel_audio_format_t( 893 Parcel aidl); legacy2aidl_audio_format_t_AudioFormatDescription_Parcel( int legacy)894 private static native Parcel legacy2aidl_audio_format_t_AudioFormatDescription_Parcel( 895 int legacy); 896 } 897