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_FRONT_LEFT 359 | AudioFormat.CHANNEL_OUT_FRONT_RIGHT 360 | AudioFormat.CHANNEL_OUT_FRONT_CENTER 361 | AudioFormat.CHANNEL_OUT_LOW_FREQUENCY 362 | AudioFormat.CHANNEL_OUT_BACK_LEFT 363 | AudioFormat.CHANNEL_OUT_BACK_RIGHT 364 | AudioFormat.CHANNEL_OUT_BACK_CENTER; 365 case AudioChannelLayout.LAYOUT_7POINT1: 366 return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; 367 case AudioChannelLayout.LAYOUT_7POINT1POINT2: 368 return AudioFormat.CHANNEL_OUT_7POINT1POINT2; 369 case AudioChannelLayout.LAYOUT_7POINT1POINT4: 370 return AudioFormat.CHANNEL_OUT_7POINT1POINT4; 371 case AudioChannelLayout.LAYOUT_9POINT1POINT4: 372 return AudioFormat.CHANNEL_OUT_9POINT1POINT4; 373 case AudioChannelLayout.LAYOUT_9POINT1POINT6: 374 return AudioFormat.CHANNEL_OUT_9POINT1POINT6; 375 case AudioChannelLayout.LAYOUT_13POINT_360RA: 376 return AudioFormat.CHANNEL_OUT_13POINT_360RA; 377 case AudioChannelLayout.LAYOUT_22POINT2: 378 return AudioFormat.CHANNEL_OUT_22POINT2; 379 case AudioChannelLayout.LAYOUT_MONO_HAPTIC_A: 380 return AudioFormat.CHANNEL_OUT_MONO 381 | AudioFormat.CHANNEL_OUT_HAPTIC_A; 382 case AudioChannelLayout.LAYOUT_STEREO_HAPTIC_A: 383 return AudioFormat.CHANNEL_OUT_STEREO 384 | AudioFormat.CHANNEL_OUT_HAPTIC_A; 385 case AudioChannelLayout.LAYOUT_HAPTIC_AB: 386 return AudioFormat.CHANNEL_OUT_HAPTIC_A 387 | AudioFormat.CHANNEL_OUT_HAPTIC_B; 388 case AudioChannelLayout.LAYOUT_MONO_HAPTIC_AB: 389 return AudioFormat.CHANNEL_OUT_MONO 390 | AudioFormat.CHANNEL_OUT_HAPTIC_A 391 | AudioFormat.CHANNEL_OUT_HAPTIC_B; 392 case AudioChannelLayout.LAYOUT_STEREO_HAPTIC_AB: 393 return AudioFormat.CHANNEL_OUT_STEREO 394 | AudioFormat.CHANNEL_OUT_HAPTIC_A 395 | AudioFormat.CHANNEL_OUT_HAPTIC_B; 396 case AudioChannelLayout.LAYOUT_FRONT_BACK: 397 return AudioFormat.CHANNEL_OUT_FRONT_CENTER 398 | AudioFormat.CHANNEL_OUT_BACK_CENTER; 399 default: // fall through 400 } 401 } 402 // If a match for a predefined layout wasn't found, make a custom one from bits. 403 return aidl2api_AudioChannelLayoutBitMask_AudioFormatChannelMask( 404 aidlMask.getLayoutMask(), isInput); 405 case AudioChannelLayout.voiceMask: 406 if (isInput) { 407 switch (aidlMask.getVoiceMask()) { 408 // AudioFormat input masks match legacy native masks directly, 409 // thus we add AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO here. 410 case AudioChannelLayout.VOICE_UPLINK_MONO: 411 return AudioFormat.CHANNEL_IN_VOICE_UPLINK 412 | AudioFormat.CHANNEL_IN_MONO; 413 case AudioChannelLayout.VOICE_DNLINK_MONO: 414 return AudioFormat.CHANNEL_IN_VOICE_DNLINK 415 | AudioFormat.CHANNEL_IN_MONO; 416 case AudioChannelLayout.VOICE_CALL_MONO: 417 return AudioFormat.CHANNEL_IN_VOICE_UPLINK 418 | AudioFormat.CHANNEL_IN_VOICE_DNLINK 419 | AudioFormat.CHANNEL_IN_MONO; 420 } 421 } 422 return AudioFormat.CHANNEL_INVALID; 423 default: 424 return AudioFormat.CHANNEL_INVALID; 425 } 426 } 427 428 /** Convert from AIDL AudioConfig to SDK AudioFormat. */ aidl2api_AudioConfig_AudioFormat( @onNull AudioConfig aidl, boolean isInput)429 public static @NonNull AudioFormat aidl2api_AudioConfig_AudioFormat( 430 @NonNull AudioConfig aidl, boolean isInput) { 431 // Only information from the encapsulated AudioConfigBase is used. 432 return aidl2api_AudioConfigBase_AudioFormat(aidl.base, isInput); 433 } 434 435 /** Convert from AIDL AudioConfigBase to SDK AudioFormat. */ aidl2api_AudioConfigBase_AudioFormat( @onNull AudioConfigBase aidl, boolean isInput)436 public static @NonNull AudioFormat aidl2api_AudioConfigBase_AudioFormat( 437 @NonNull AudioConfigBase aidl, boolean isInput) { 438 AudioFormat.Builder apiBuilder = new AudioFormat.Builder(); 439 apiBuilder.setSampleRate(aidl.sampleRate); 440 if (aidl.channelMask.getTag() != AudioChannelLayout.indexMask) { 441 apiBuilder.setChannelMask(aidl2api_AudioChannelLayout_AudioFormatChannelMask( 442 aidl.channelMask, isInput)); 443 } else { 444 apiBuilder.setChannelIndexMask(aidl2api_AudioChannelLayout_AudioFormatChannelMask( 445 aidl.channelMask, isInput)); 446 } 447 apiBuilder.setEncoding(aidl2api_AudioFormat_AudioFormatEncoding(aidl.format)); 448 return apiBuilder.build(); 449 } 450 451 /** Convert from AIDL AudioFormat to SDK AudioFormat.ENCODING_*. */ aidl2api_AudioFormat_AudioFormatEncoding( @onNull AudioFormatDescription aidl)452 public static int aidl2api_AudioFormat_AudioFormatEncoding( 453 @NonNull AudioFormatDescription aidl) { 454 switch (aidl.type) { 455 case AudioFormatType.PCM: 456 switch (aidl.pcm) { 457 case PcmType.UINT_8_BIT: 458 return AudioFormat.ENCODING_PCM_8BIT; 459 case PcmType.INT_16_BIT: 460 return AudioFormat.ENCODING_PCM_16BIT; 461 case PcmType.INT_32_BIT: 462 return AudioFormat.ENCODING_PCM_32BIT; 463 case PcmType.FIXED_Q_8_24: 464 case PcmType.FLOAT_32_BIT: 465 return AudioFormat.ENCODING_PCM_FLOAT; 466 case PcmType.INT_24_BIT: 467 return AudioFormat.ENCODING_PCM_24BIT_PACKED; 468 default: 469 return AudioFormat.ENCODING_INVALID; 470 } 471 case AudioFormatType.NON_PCM: // same as DEFAULT 472 if (aidl.encoding != null && !aidl.encoding.isEmpty()) { 473 if (MediaFormat.MIMETYPE_AUDIO_AC3.equals(aidl.encoding)) { 474 return AudioFormat.ENCODING_AC3; 475 } else if (MediaFormat.MIMETYPE_AUDIO_EAC3.equals(aidl.encoding)) { 476 return AudioFormat.ENCODING_E_AC3; 477 } else if (MediaFormat.MIMETYPE_AUDIO_DTS.equals(aidl.encoding)) { 478 return AudioFormat.ENCODING_DTS; 479 } else if (MediaFormat.MIMETYPE_AUDIO_DTS_HD.equals(aidl.encoding)) { 480 return AudioFormat.ENCODING_DTS_HD; 481 } else if (MediaFormat.MIMETYPE_AUDIO_MPEG.equals(aidl.encoding)) { 482 return AudioFormat.ENCODING_MP3; 483 } else if (MediaFormat.MIMETYPE_AUDIO_AAC_LC.equals(aidl.encoding)) { 484 return AudioFormat.ENCODING_AAC_LC; 485 } else if (MediaFormat.MIMETYPE_AUDIO_AAC_HE_V1.equals(aidl.encoding)) { 486 return AudioFormat.ENCODING_AAC_HE_V1; 487 } else if (MediaFormat.MIMETYPE_AUDIO_AAC_HE_V2.equals(aidl.encoding)) { 488 return AudioFormat.ENCODING_AAC_HE_V2; 489 } else if (MediaFormat.MIMETYPE_AUDIO_IEC61937.equals(aidl.encoding) 490 && aidl.pcm == PcmType.INT_16_BIT) { 491 return AudioFormat.ENCODING_IEC61937; 492 } else if (MediaFormat.MIMETYPE_AUDIO_DOLBY_TRUEHD.equals( 493 aidl.encoding)) { 494 return AudioFormat.ENCODING_DOLBY_TRUEHD; 495 } else if (MediaFormat.MIMETYPE_AUDIO_AAC_ELD.equals(aidl.encoding)) { 496 return AudioFormat.ENCODING_AAC_ELD; 497 } else if (MediaFormat.MIMETYPE_AUDIO_AAC_XHE.equals(aidl.encoding)) { 498 return AudioFormat.ENCODING_AAC_XHE; 499 } else if (MediaFormat.MIMETYPE_AUDIO_AC4.equals(aidl.encoding)) { 500 return AudioFormat.ENCODING_AC4; 501 } else if (MediaFormat.MIMETYPE_AUDIO_EAC3_JOC.equals(aidl.encoding)) { 502 return AudioFormat.ENCODING_E_AC3_JOC; 503 } else if (MediaFormat.MIMETYPE_AUDIO_DOLBY_MAT.equals(aidl.encoding) 504 || aidl.encoding.startsWith( 505 MediaFormat.MIMETYPE_AUDIO_DOLBY_MAT + ".")) { 506 return AudioFormat.ENCODING_DOLBY_MAT; 507 } else if (MediaFormat.MIMETYPE_AUDIO_OPUS.equals(aidl.encoding)) { 508 return AudioFormat.ENCODING_OPUS; 509 } else if (MediaFormat.MIMETYPE_AUDIO_MPEGH_BL_L3.equals(aidl.encoding)) { 510 return AudioFormat.ENCODING_MPEGH_BL_L3; 511 } else if (MediaFormat.MIMETYPE_AUDIO_MPEGH_BL_L4.equals(aidl.encoding)) { 512 return AudioFormat.ENCODING_MPEGH_BL_L4; 513 } else if (MediaFormat.MIMETYPE_AUDIO_MPEGH_LC_L3.equals(aidl.encoding)) { 514 return AudioFormat.ENCODING_MPEGH_LC_L3; 515 } else if (MediaFormat.MIMETYPE_AUDIO_MPEGH_LC_L4.equals(aidl.encoding)) { 516 return AudioFormat.ENCODING_MPEGH_LC_L4; 517 } else if (MediaFormat.MIMETYPE_AUDIO_DTS_UHD.equals(aidl.encoding)) { 518 return AudioFormat.ENCODING_DTS_UHD; 519 } else if (MediaFormat.MIMETYPE_AUDIO_DRA.equals(aidl.encoding)) { 520 return AudioFormat.ENCODING_DRA; 521 } else { 522 return AudioFormat.ENCODING_INVALID; 523 } 524 } else { 525 return AudioFormat.ENCODING_DEFAULT; 526 } 527 case AudioFormatType.SYS_RESERVED_INVALID: 528 default: 529 return AudioFormat.ENCODING_INVALID; 530 } 531 } 532 533 /** 534 * Convert from SDK AudioDeviceAttributes to AIDL AudioPort. 535 */ api2aidl_AudioDeviceAttributes_AudioPort( @onNull AudioDeviceAttributes attributes)536 public static AudioPort api2aidl_AudioDeviceAttributes_AudioPort( 537 @NonNull AudioDeviceAttributes attributes) { 538 AudioPort port = new AudioPort(); 539 port.name = attributes.getName(); 540 // TO DO: b/211611504 Convert attributes.getAudioProfiles() to AIDL as well. 541 port.profiles = new AudioProfile[]{}; 542 port.extraAudioDescriptors = attributes.getAudioDescriptors().stream() 543 .map(descriptor -> api2aidl_AudioDescriptor_ExtraAudioDescriptor(descriptor)) 544 .collect(Collectors.toList()).toArray(ExtraAudioDescriptor[]::new); 545 port.flags = new AudioIoFlags(); 546 port.gains = new AudioGain[]{}; 547 AudioPortDeviceExt deviceExt = new AudioPortDeviceExt(); 548 deviceExt.device = new AudioDevice(); 549 deviceExt.encodedFormats = new AudioFormatDescription[]{}; 550 deviceExt.device.type = 551 api2aidl_NativeType_AudioDeviceDescription(attributes.getInternalType()); 552 deviceExt.device.address = AudioDeviceAddress.id(attributes.getAddress()); 553 port.ext = AudioPortExt.device(deviceExt); 554 return port; 555 } 556 557 /** 558 * Convert from SDK AudioDescriptor to AIDL ExtraAudioDescriptor. 559 */ api2aidl_AudioDescriptor_ExtraAudioDescriptor( @onNull AudioDescriptor descriptor)560 public static ExtraAudioDescriptor api2aidl_AudioDescriptor_ExtraAudioDescriptor( 561 @NonNull AudioDescriptor descriptor) { 562 ExtraAudioDescriptor extraDescriptor = new ExtraAudioDescriptor(); 563 extraDescriptor.standard = 564 api2aidl_AudioDescriptorStandard_AudioStandard(descriptor.getStandard()); 565 extraDescriptor.audioDescriptor = descriptor.getDescriptor(); 566 extraDescriptor.encapsulationType = 567 api2aidl_AudioProfileEncapsulationType_AudioEncapsulationType( 568 descriptor.getEncapsulationType()); 569 return extraDescriptor; 570 } 571 572 /** 573 * Convert from SDK AudioDescriptor to AIDL ExtraAudioDescriptor. 574 */ aidl2api_ExtraAudioDescriptor_AudioDescriptor( @onNull ExtraAudioDescriptor extraDescriptor)575 public static @NonNull AudioDescriptor aidl2api_ExtraAudioDescriptor_AudioDescriptor( 576 @NonNull ExtraAudioDescriptor extraDescriptor) { 577 AudioDescriptor descriptor = new AudioDescriptor( 578 aidl2api_AudioStandard_AudioDescriptorStandard(extraDescriptor.standard), 579 aidl2api_AudioEncapsulationType_AudioProfileEncapsulationType( 580 extraDescriptor.encapsulationType), 581 extraDescriptor.audioDescriptor); 582 return descriptor; 583 } 584 585 /** 586 * Convert from SDK AudioDescriptor#mStandard to AIDL AudioStandard 587 */ 588 @AudioStandard api2aidl_AudioDescriptorStandard_AudioStandard( @udioDescriptor.AudioDescriptorStandard int standard)589 public static int api2aidl_AudioDescriptorStandard_AudioStandard( 590 @AudioDescriptor.AudioDescriptorStandard int standard) { 591 switch (standard) { 592 case AudioDescriptor.STANDARD_EDID: 593 return AudioStandard.EDID; 594 case AudioDescriptor.STANDARD_NONE: 595 default: 596 return AudioStandard.NONE; 597 } 598 } 599 600 /** 601 * Convert from AIDL AudioStandard to SDK AudioDescriptor#mStandard 602 */ 603 @AudioDescriptor.AudioDescriptorStandard aidl2api_AudioStandard_AudioDescriptorStandard(@udioStandard int standard)604 public static int aidl2api_AudioStandard_AudioDescriptorStandard(@AudioStandard int standard) { 605 switch (standard) { 606 case AudioStandard.EDID: 607 return AudioDescriptor.STANDARD_EDID; 608 case AudioStandard.NONE: 609 default: 610 return AudioDescriptor.STANDARD_NONE; 611 } 612 } 613 614 /** 615 * Convert from SDK AudioProfile.EncapsulationType to AIDL AudioEncapsulationType 616 */ 617 @AudioEncapsulationType api2aidl_AudioProfileEncapsulationType_AudioEncapsulationType( @ndroid.media.AudioProfile.EncapsulationType int type)618 public static int api2aidl_AudioProfileEncapsulationType_AudioEncapsulationType( 619 @android.media.AudioProfile.EncapsulationType int type) { 620 switch (type) { 621 case android.media.AudioProfile.AUDIO_ENCAPSULATION_TYPE_IEC61937: 622 return AudioEncapsulationType.IEC61937; 623 case android.media.AudioProfile.AUDIO_ENCAPSULATION_TYPE_NONE: 624 default: 625 return AudioEncapsulationType.NONE; 626 } 627 } 628 629 /** 630 * Convert from AIDL AudioEncapsulationType to SDK AudioProfile.EncapsulationType 631 */ 632 @android.media.AudioProfile.EncapsulationType aidl2api_AudioEncapsulationType_AudioProfileEncapsulationType( @udioEncapsulationType int type)633 public static int aidl2api_AudioEncapsulationType_AudioProfileEncapsulationType( 634 @AudioEncapsulationType int type) { 635 switch (type) { 636 case AudioEncapsulationType.IEC61937: 637 return android.media.AudioProfile.AUDIO_ENCAPSULATION_TYPE_IEC61937; 638 case AudioEncapsulationType.NONE: 639 default: 640 return android.media.AudioProfile.AUDIO_ENCAPSULATION_TYPE_NONE; 641 } 642 } 643 644 /** 645 * Convert from SDK native type to AIDL AudioDeviceDescription 646 */ api2aidl_NativeType_AudioDeviceDescription( int nativeType)647 public static AudioDeviceDescription api2aidl_NativeType_AudioDeviceDescription( 648 int nativeType) { 649 AudioDeviceDescription aidl = new AudioDeviceDescription(); 650 aidl.connection = ""; 651 switch (nativeType) { 652 case AudioSystem.DEVICE_OUT_EARPIECE: 653 aidl.type = AudioDeviceType.OUT_SPEAKER_EARPIECE; 654 break; 655 case AudioSystem.DEVICE_OUT_SPEAKER: 656 aidl.type = AudioDeviceType.OUT_SPEAKER; 657 break; 658 case AudioSystem.DEVICE_OUT_WIRED_HEADPHONE: 659 aidl.type = AudioDeviceType.OUT_HEADPHONE; 660 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 661 break; 662 case AudioSystem.DEVICE_OUT_BLUETOOTH_SCO: 663 aidl.type = AudioDeviceType.OUT_DEVICE; 664 aidl.connection = AudioDeviceDescription.CONNECTION_BT_SCO; 665 break; 666 case AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_CARKIT: 667 aidl.type = AudioDeviceType.OUT_CARKIT; 668 aidl.connection = AudioDeviceDescription.CONNECTION_BT_SCO; 669 break; 670 case AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES: 671 aidl.type = AudioDeviceType.OUT_HEADPHONE; 672 aidl.connection = AudioDeviceDescription.CONNECTION_BT_A2DP; 673 break; 674 case AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER: 675 aidl.type = AudioDeviceType.OUT_SPEAKER; 676 aidl.connection = AudioDeviceDescription.CONNECTION_BT_A2DP; 677 break; 678 case AudioSystem.DEVICE_OUT_TELEPHONY_TX: 679 aidl.type = AudioDeviceType.OUT_TELEPHONY_TX; 680 break; 681 case AudioSystem.DEVICE_OUT_AUX_LINE: 682 aidl.type = AudioDeviceType.OUT_LINE_AUX; 683 break; 684 case AudioSystem.DEVICE_OUT_SPEAKER_SAFE: 685 aidl.type = AudioDeviceType.OUT_SPEAKER_SAFE; 686 break; 687 case AudioSystem.DEVICE_OUT_HEARING_AID: 688 aidl.type = AudioDeviceType.OUT_HEARING_AID; 689 aidl.connection = AudioDeviceDescription.CONNECTION_WIRELESS; 690 break; 691 case AudioSystem.DEVICE_OUT_ECHO_CANCELLER: 692 aidl.type = AudioDeviceType.OUT_ECHO_CANCELLER; 693 break; 694 case AudioSystem.DEVICE_OUT_BLE_SPEAKER: 695 aidl.type = AudioDeviceType.OUT_SPEAKER; 696 aidl.connection = AudioDeviceDescription.CONNECTION_BT_LE; 697 break; 698 case AudioSystem.DEVICE_OUT_BLE_BROADCAST: 699 aidl.type = AudioDeviceType.OUT_BROADCAST; 700 aidl.connection = AudioDeviceDescription.CONNECTION_BT_LE; 701 break; 702 case AudioSystem.DEVICE_IN_BUILTIN_MIC: 703 aidl.type = AudioDeviceType.IN_MICROPHONE; 704 break; 705 case AudioSystem.DEVICE_IN_BACK_MIC: 706 aidl.type = AudioDeviceType.IN_MICROPHONE_BACK; 707 break; 708 case AudioSystem.DEVICE_IN_TELEPHONY_RX: 709 aidl.type = AudioDeviceType.IN_TELEPHONY_RX; 710 break; 711 case AudioSystem.DEVICE_IN_TV_TUNER: 712 aidl.type = AudioDeviceType.IN_TV_TUNER; 713 break; 714 case AudioSystem.DEVICE_IN_LOOPBACK: 715 aidl.type = AudioDeviceType.IN_LOOPBACK; 716 break; 717 case AudioSystem.DEVICE_IN_BLUETOOTH_BLE: 718 aidl.type = AudioDeviceType.IN_DEVICE; 719 aidl.connection = AudioDeviceDescription.CONNECTION_BT_LE; 720 break; 721 case AudioSystem.DEVICE_IN_ECHO_REFERENCE: 722 aidl.type = AudioDeviceType.IN_ECHO_REFERENCE; 723 break; 724 case AudioSystem.DEVICE_IN_WIRED_HEADSET: 725 aidl.type = AudioDeviceType.IN_HEADSET; 726 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 727 break; 728 case AudioSystem.DEVICE_OUT_WIRED_HEADSET: 729 aidl.type = AudioDeviceType.OUT_HEADSET; 730 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 731 break; 732 case AudioSystem.DEVICE_IN_BLUETOOTH_SCO_HEADSET: 733 aidl.type = AudioDeviceType.IN_HEADSET; 734 aidl.connection = AudioDeviceDescription.CONNECTION_BT_SCO; 735 break; 736 case AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_HEADSET: 737 aidl.type = AudioDeviceType.OUT_HEADSET; 738 aidl.connection = AudioDeviceDescription.CONNECTION_BT_SCO; 739 break; 740 case AudioSystem.DEVICE_IN_HDMI: 741 aidl.type = AudioDeviceType.IN_DEVICE; 742 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI; 743 break; 744 case AudioSystem.DEVICE_OUT_HDMI: 745 aidl.type = AudioDeviceType.OUT_DEVICE; 746 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI; 747 break; 748 case AudioSystem.DEVICE_IN_REMOTE_SUBMIX: 749 aidl.type = AudioDeviceType.IN_SUBMIX; 750 break; 751 case AudioSystem.DEVICE_OUT_REMOTE_SUBMIX: 752 aidl.type = AudioDeviceType.OUT_SUBMIX; 753 break; 754 case AudioSystem.DEVICE_IN_ANLG_DOCK_HEADSET: 755 aidl.type = AudioDeviceType.IN_DOCK; 756 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 757 break; 758 case AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET: 759 aidl.type = AudioDeviceType.OUT_DOCK; 760 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 761 break; 762 case AudioSystem.DEVICE_IN_DGTL_DOCK_HEADSET: 763 aidl.type = AudioDeviceType.IN_DOCK; 764 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 765 break; 766 case AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET: 767 aidl.type = AudioDeviceType.OUT_DOCK; 768 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 769 break; 770 case AudioSystem.DEVICE_IN_USB_ACCESSORY: 771 aidl.type = AudioDeviceType.IN_ACCESSORY; 772 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 773 break; 774 case AudioSystem.DEVICE_OUT_USB_ACCESSORY: 775 aidl.type = AudioDeviceType.OUT_ACCESSORY; 776 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 777 break; 778 case AudioSystem.DEVICE_IN_USB_DEVICE: 779 aidl.type = AudioDeviceType.IN_DEVICE; 780 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 781 break; 782 case AudioSystem.DEVICE_OUT_USB_DEVICE: 783 aidl.type = AudioDeviceType.OUT_DEVICE; 784 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 785 break; 786 case AudioSystem.DEVICE_IN_FM_TUNER: 787 aidl.type = AudioDeviceType.IN_FM_TUNER; 788 break; 789 case AudioSystem.DEVICE_OUT_FM: 790 aidl.type = AudioDeviceType.OUT_FM; 791 break; 792 case AudioSystem.DEVICE_IN_LINE: 793 aidl.type = AudioDeviceType.IN_DEVICE; 794 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 795 break; 796 case AudioSystem.DEVICE_OUT_LINE: 797 aidl.type = AudioDeviceType.OUT_DEVICE; 798 aidl.connection = AudioDeviceDescription.CONNECTION_ANALOG; 799 break; 800 case AudioSystem.DEVICE_IN_SPDIF: 801 aidl.type = AudioDeviceType.IN_DEVICE; 802 aidl.connection = AudioDeviceDescription.CONNECTION_SPDIF; 803 break; 804 case AudioSystem.DEVICE_OUT_SPDIF: 805 aidl.type = AudioDeviceType.OUT_DEVICE; 806 aidl.connection = AudioDeviceDescription.CONNECTION_SPDIF; 807 break; 808 case AudioSystem.DEVICE_IN_BLUETOOTH_A2DP: 809 aidl.type = AudioDeviceType.IN_DEVICE; 810 aidl.connection = AudioDeviceDescription.CONNECTION_BT_A2DP; 811 break; 812 case AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP: 813 aidl.type = AudioDeviceType.OUT_DEVICE; 814 aidl.connection = AudioDeviceDescription.CONNECTION_BT_A2DP; 815 break; 816 case AudioSystem.DEVICE_IN_IP: 817 aidl.type = AudioDeviceType.IN_DEVICE; 818 aidl.connection = AudioDeviceDescription.CONNECTION_IP_V4; 819 break; 820 case AudioSystem.DEVICE_OUT_IP: 821 aidl.type = AudioDeviceType.OUT_DEVICE; 822 aidl.connection = AudioDeviceDescription.CONNECTION_IP_V4; 823 break; 824 case AudioSystem.DEVICE_IN_BUS: 825 aidl.type = AudioDeviceType.IN_DEVICE; 826 aidl.connection = AudioDeviceDescription.CONNECTION_BUS; 827 break; 828 case AudioSystem.DEVICE_OUT_BUS: 829 aidl.type = AudioDeviceType.OUT_DEVICE; 830 aidl.connection = AudioDeviceDescription.CONNECTION_BUS; 831 break; 832 case AudioSystem.DEVICE_IN_PROXY: 833 aidl.type = AudioDeviceType.IN_AFE_PROXY; 834 break; 835 case AudioSystem.DEVICE_OUT_PROXY: 836 aidl.type = AudioDeviceType.OUT_AFE_PROXY; 837 break; 838 case AudioSystem.DEVICE_IN_USB_HEADSET: 839 aidl.type = AudioDeviceType.IN_HEADSET; 840 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 841 break; 842 case AudioSystem.DEVICE_OUT_USB_HEADSET: 843 aidl.type = AudioDeviceType.OUT_HEADSET; 844 aidl.connection = AudioDeviceDescription.CONNECTION_USB; 845 break; 846 case AudioSystem.DEVICE_IN_HDMI_ARC: 847 aidl.type = AudioDeviceType.IN_DEVICE; 848 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI_ARC; 849 break; 850 case AudioSystem.DEVICE_OUT_HDMI_ARC: 851 aidl.type = AudioDeviceType.OUT_DEVICE; 852 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI_ARC; 853 break; 854 case AudioSystem.DEVICE_IN_HDMI_EARC: 855 aidl.type = AudioDeviceType.IN_DEVICE; 856 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI_EARC; 857 break; 858 case AudioSystem.DEVICE_OUT_HDMI_EARC: 859 aidl.type = AudioDeviceType.OUT_DEVICE; 860 aidl.connection = AudioDeviceDescription.CONNECTION_HDMI_EARC; 861 break; 862 case AudioSystem.DEVICE_IN_BLE_HEADSET: 863 aidl.type = AudioDeviceType.IN_HEADSET; 864 aidl.connection = AudioDeviceDescription.CONNECTION_BT_LE; 865 break; 866 case AudioSystem.DEVICE_OUT_BLE_HEADSET: 867 aidl.type = AudioDeviceType.OUT_HEADSET; 868 aidl.connection = AudioDeviceDescription.CONNECTION_BT_LE; 869 break; 870 case AudioSystem.DEVICE_IN_DEFAULT: 871 aidl.type = AudioDeviceType.IN_DEFAULT; 872 break; 873 case AudioSystem.DEVICE_OUT_DEFAULT: 874 aidl.type = AudioDeviceType.OUT_DEFAULT; 875 break; 876 default: 877 aidl.type = AudioDeviceType.NONE; 878 } 879 return aidl; 880 } 881 aidl2legacy_AudioChannelLayout_Parcel_audio_channel_mask_t( Parcel aidl, boolean isInput)882 private static native int aidl2legacy_AudioChannelLayout_Parcel_audio_channel_mask_t( 883 Parcel aidl, boolean isInput); legacy2aidl_audio_channel_mask_t_AudioChannelLayout_Parcel( int legacy, boolean isInput)884 private static native Parcel legacy2aidl_audio_channel_mask_t_AudioChannelLayout_Parcel( 885 int legacy, boolean isInput); aidl2legacy_AudioFormatDescription_Parcel_audio_format_t( Parcel aidl)886 private static native int aidl2legacy_AudioFormatDescription_Parcel_audio_format_t( 887 Parcel aidl); legacy2aidl_audio_format_t_AudioFormatDescription_Parcel( int legacy)888 private static native Parcel legacy2aidl_audio_format_t_AudioFormatDescription_Parcel( 889 int legacy); 890 } 891