1 /* 2 * Copyright 2017 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 com.mobileer.oboetester; 18 19 import android.content.res.Resources; 20 21 import java.util.ArrayList; 22 import java.util.HashMap; 23 import java.util.List; 24 25 /** 26 * Container for the properties of a Stream. 27 * 28 * This can be used to build a stream, or as a base class for a Stream, 29 * or as a way to report the properties of a Stream. 30 */ 31 32 public class StreamConfiguration { 33 public static final int UNSPECIFIED = 0; 34 35 // These must match order in Spinner and in native code and in AAudio.h 36 public static final int NATIVE_API_UNSPECIFIED = 0; 37 public static final int NATIVE_API_OPENSLES = 1; 38 public static final int NATIVE_API_AAUDIO = 2; 39 40 public static final int SHARING_MODE_EXCLUSIVE = 0; // must match AAUDIO 41 public static final int SHARING_MODE_SHARED = 1; // must match AAUDIO 42 43 public static final int AUDIO_FORMAT_PCM_16 = 1; // must match AAUDIO 44 public static final int AUDIO_FORMAT_PCM_FLOAT = 2; // must match AAUDIO 45 public static final int AUDIO_FORMAT_PCM_24 = 3; // must match AAUDIO 46 public static final int AUDIO_FORMAT_PCM_32 = 4; // must match AAUDIO 47 48 public static final int DIRECTION_OUTPUT = 0; // must match AAUDIO 49 public static final int DIRECTION_INPUT = 1; // must match AAUDIO 50 51 public static final int SESSION_ID_NONE = -1; // must match AAUDIO 52 public static final int SESSION_ID_ALLOCATE = 0; // must match AAUDIO 53 54 public static final int PERFORMANCE_MODE_NONE = 10; // must match AAUDIO 55 public static final int PERFORMANCE_MODE_POWER_SAVING = 11; // must match AAUDIO 56 public static final int PERFORMANCE_MODE_LOW_LATENCY = 12; // must match AAUDIO 57 58 public static final int RATE_CONVERSION_QUALITY_NONE = 0; // must match Oboe 59 public static final int RATE_CONVERSION_QUALITY_FASTEST = 1; // must match Oboe 60 public static final int RATE_CONVERSION_QUALITY_LOW = 2; // must match Oboe 61 public static final int RATE_CONVERSION_QUALITY_MEDIUM = 3; // must match Oboe 62 public static final int RATE_CONVERSION_QUALITY_HIGH = 4; // must match Oboe 63 public static final int RATE_CONVERSION_QUALITY_BEST = 5; // must match Oboe 64 65 public static final int STREAM_STATE_STARTING = 3; // must match Oboe 66 public static final int STREAM_STATE_STARTED = 4; // must match Oboe 67 68 public static final int INPUT_PRESET_GENERIC = 1; // must match Oboe 69 public static final int INPUT_PRESET_CAMCORDER = 5; // must match Oboe 70 public static final int INPUT_PRESET_VOICE_RECOGNITION = 6; // must match Oboe 71 public static final int INPUT_PRESET_VOICE_COMMUNICATION = 7; // must match Oboe 72 public static final int INPUT_PRESET_UNPROCESSED = 9; // must match Oboe 73 public static final int INPUT_PRESET_VOICE_PERFORMANCE = 10; // must match Oboe 74 75 public static final int ERROR_DISCONNECTED = -899; // must match Oboe 76 77 public static final int USAGE_MEDIA = 1; 78 public static final int USAGE_VOICE_COMMUNICATION = 2; 79 public static final int USAGE_VOICE_COMMUNICATION_SIGNALLING = 3; 80 public static final int USAGE_ALARM = 4; 81 public static final int USAGE_NOTIFICATION = 5; 82 public static final int USAGE_NOTIFICATION_RINGTONE = 6; 83 public static final int USAGE_NOTIFICATION_EVENT = 10; 84 public static final int USAGE_ASSISTANCE_ACCESSIBILITY = 11; 85 public static final int USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12; 86 public static final int USAGE_ASSISTANCE_SONIFICATION = 13; 87 public static final int USAGE_GAME = 14; 88 public static final int USAGE_ASSISTANT = 16; 89 90 public static final int CONTENT_TYPE_SPEECH = 1; 91 public static final int CONTENT_TYPE_MUSIC = 2; 92 public static final int CONTENT_TYPE_MOVIE = 3; 93 public static final int CONTENT_TYPE_SONIFICATION = 4; 94 95 public static final int CHANNEL_FRONT_LEFT = 1 << 0; 96 public static final int CHANNEL_FRONT_RIGHT = 1 << 1; 97 public static final int CHANNEL_FRONT_CENTER = 1 << 2; 98 public static final int CHANNEL_LOW_FREQUENCY = 1 << 3; 99 public static final int CHANNEL_BACK_LEFT = 1 << 4; 100 public static final int CHANNEL_BACK_RIGHT = 1 << 5; 101 public static final int CHANNEL_FRONT_LEFT_OF_CENTER = 1 << 6; 102 public static final int CHANNEL_FRONT_RIGHT_OF_CENTER = 1 << 7; 103 public static final int CHANNEL_BACK_CENTER = 1 << 8; 104 public static final int CHANNEL_SIDE_LEFT = 1 << 9; 105 public static final int CHANNEL_SIDE_RIGHT = 1 << 10; 106 public static final int CHANNEL_TOP_CENTER = 1 << 11; 107 public static final int CHANNEL_TOP_FRONT_LEFT = 1 << 12; 108 public static final int CHANNEL_TOP_FRONT_CENTER = 1 << 13; 109 public static final int CHANNEL_TOP_FRONT_RIGHT = 1 << 14; 110 public static final int CHANNEL_TOP_BACK_LEFT = 1 << 15; 111 public static final int CHANNEL_TOP_BACK_CENTER = 1 << 16; 112 public static final int CHANNEL_TOP_BACK_RIGHT = 1 << 17; 113 public static final int CHANNEL_TOP_SIDE_LEFT = 1 << 18; 114 public static final int CHANNEL_TOP_SIDE_RIGHT = 1 << 19; 115 public static final int CHANNEL_BOTTOM_FRONT_LEFT = 1 << 20; 116 public static final int CHANNEL_BOTTOM_FRONT_CENTER = 1 << 21; 117 public static final int CHANNEL_BOTTOM_FRONT_RIGHT = 1 << 22; 118 public static final int CHANNEL_LOW_FREQUENCY_2 = 1 << 23; 119 public static final int CHANNEL_FRONT_WIDE_LEFT = 1 << 24; 120 public static final int CHANNEL_FRONT_WIDE_RIGHT = 1 << 25; 121 122 public static final int CHANNEL_MONO = CHANNEL_FRONT_LEFT; 123 public static final int CHANNEL_STEREO = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT; 124 public static final int CHANNEL_2POINT1 = CHANNEL_FRONT_LEFT | 125 CHANNEL_FRONT_RIGHT | 126 CHANNEL_LOW_FREQUENCY; 127 public static final int CHANNEL_TRI = CHANNEL_FRONT_LEFT | 128 CHANNEL_FRONT_RIGHT | 129 CHANNEL_FRONT_CENTER; 130 public static final int CHANNEL_TRI_BACK = CHANNEL_FRONT_LEFT | 131 CHANNEL_FRONT_RIGHT | 132 CHANNEL_BACK_CENTER; 133 public static final int CHANNEL_3POINT1 = CHANNEL_FRONT_LEFT | 134 CHANNEL_FRONT_RIGHT | 135 CHANNEL_FRONT_CENTER | 136 CHANNEL_LOW_FREQUENCY; 137 public static final int CHANNEL_2POINT0POINT2 = CHANNEL_FRONT_LEFT | 138 CHANNEL_FRONT_RIGHT | 139 CHANNEL_TOP_SIDE_LEFT | 140 CHANNEL_TOP_SIDE_RIGHT; 141 public static final int CHANNEL_2POINT1POINT2 = CHANNEL_2POINT0POINT2 | CHANNEL_LOW_FREQUENCY; 142 public static final int CHANNEL_3POINT0POINT2 = CHANNEL_FRONT_LEFT | 143 CHANNEL_FRONT_RIGHT | 144 CHANNEL_FRONT_CENTER | 145 CHANNEL_TOP_SIDE_LEFT | 146 CHANNEL_TOP_SIDE_RIGHT; 147 public static final int CHANNEL_3POINT1POINT2 = CHANNEL_3POINT0POINT2 | CHANNEL_LOW_FREQUENCY; 148 public static final int CHANNEL_QUAD = CHANNEL_FRONT_LEFT | 149 CHANNEL_FRONT_RIGHT | 150 CHANNEL_BACK_LEFT | 151 CHANNEL_BACK_RIGHT; 152 public static final int CHANNEL_QUAD_SIDE = CHANNEL_FRONT_LEFT | 153 CHANNEL_FRONT_RIGHT | 154 CHANNEL_SIDE_LEFT | 155 CHANNEL_SIDE_RIGHT; 156 public static final int CHANNEL_SURROUND = CHANNEL_FRONT_LEFT | 157 CHANNEL_FRONT_RIGHT | 158 CHANNEL_FRONT_CENTER | 159 CHANNEL_BACK_CENTER; 160 public static final int CHANNEL_PENTA = CHANNEL_QUAD | CHANNEL_FRONT_CENTER; 161 // aka 5POINT1_BACK 162 public static final int CHANNEL_5POINT1 = CHANNEL_FRONT_LEFT | 163 CHANNEL_FRONT_RIGHT | 164 CHANNEL_FRONT_CENTER | 165 CHANNEL_LOW_FREQUENCY | 166 CHANNEL_BACK_LEFT | 167 CHANNEL_BACK_RIGHT; 168 public static final int CHANNEL_5POINT1_SIDE = CHANNEL_FRONT_LEFT | 169 CHANNEL_FRONT_RIGHT | 170 CHANNEL_FRONT_CENTER | 171 CHANNEL_LOW_FREQUENCY | 172 CHANNEL_SIDE_LEFT | 173 CHANNEL_SIDE_RIGHT; 174 public static final int CHANNEL_6POINT1 = CHANNEL_FRONT_LEFT | 175 CHANNEL_FRONT_RIGHT | 176 CHANNEL_FRONT_CENTER | 177 CHANNEL_LOW_FREQUENCY | 178 CHANNEL_BACK_LEFT | 179 CHANNEL_BACK_RIGHT | 180 CHANNEL_BACK_CENTER; 181 public static final int CHANNEL_7POINT1 = CHANNEL_5POINT1 | 182 CHANNEL_SIDE_LEFT | 183 CHANNEL_SIDE_RIGHT; 184 public static final int CHANNEL_5POINT1POINT2 = CHANNEL_5POINT1 | 185 CHANNEL_TOP_SIDE_LEFT | 186 CHANNEL_TOP_SIDE_RIGHT; 187 public static final int CHANNEL_5POINT1POINT4 = CHANNEL_5POINT1 | 188 CHANNEL_TOP_FRONT_LEFT | 189 CHANNEL_TOP_FRONT_RIGHT | 190 CHANNEL_TOP_BACK_LEFT | 191 CHANNEL_TOP_BACK_RIGHT; 192 public static final int CHANNEL_7POINT1POINT2 = CHANNEL_7POINT1 | 193 CHANNEL_TOP_SIDE_LEFT | 194 CHANNEL_TOP_SIDE_RIGHT; 195 public static final int CHANNEL_7POINT1POINT4 = CHANNEL_7POINT1 | 196 CHANNEL_TOP_FRONT_LEFT | 197 CHANNEL_TOP_FRONT_RIGHT | 198 CHANNEL_TOP_BACK_LEFT | 199 CHANNEL_TOP_BACK_RIGHT; 200 public static final int CHANNEL_9POINT1POINT4 = CHANNEL_7POINT1POINT4 | 201 CHANNEL_FRONT_WIDE_LEFT | 202 CHANNEL_FRONT_WIDE_RIGHT; 203 public static final int CHANNEL_9POINT1POINT6 = CHANNEL_9POINT1POINT4 | 204 CHANNEL_TOP_SIDE_LEFT | 205 CHANNEL_TOP_SIDE_RIGHT; 206 public static final int CHANNEL_FRONT_BACK = CHANNEL_FRONT_CENTER | CHANNEL_BACK_CENTER; 207 208 public static final int[] usages = { 209 USAGE_MEDIA, 210 USAGE_VOICE_COMMUNICATION, 211 USAGE_VOICE_COMMUNICATION_SIGNALLING, 212 USAGE_ALARM, 213 USAGE_NOTIFICATION, 214 USAGE_NOTIFICATION_RINGTONE, 215 USAGE_NOTIFICATION_EVENT, 216 USAGE_ASSISTANCE_ACCESSIBILITY, 217 USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, 218 USAGE_ASSISTANCE_SONIFICATION, 219 USAGE_GAME, 220 USAGE_ASSISTANT}; 221 222 public static final int[] contentTypes = { 223 CONTENT_TYPE_SPEECH, 224 CONTENT_TYPE_MUSIC, 225 CONTENT_TYPE_MOVIE, 226 CONTENT_TYPE_SONIFICATION}; 227 228 public static final int[] channelMasks = { 229 CHANNEL_MONO, 230 CHANNEL_STEREO, 231 CHANNEL_2POINT1, 232 CHANNEL_TRI, 233 CHANNEL_TRI_BACK, 234 CHANNEL_3POINT1, 235 CHANNEL_2POINT0POINT2, 236 CHANNEL_2POINT1POINT2, 237 CHANNEL_3POINT0POINT2, 238 CHANNEL_3POINT1POINT2, 239 CHANNEL_QUAD, 240 CHANNEL_QUAD_SIDE, 241 CHANNEL_SURROUND, 242 CHANNEL_PENTA, 243 CHANNEL_5POINT1, 244 CHANNEL_5POINT1_SIDE, 245 CHANNEL_6POINT1, 246 CHANNEL_7POINT1, 247 CHANNEL_5POINT1POINT2, 248 CHANNEL_5POINT1POINT4, 249 CHANNEL_7POINT1POINT2, 250 CHANNEL_7POINT1POINT4, 251 CHANNEL_9POINT1POINT4, 252 CHANNEL_9POINT1POINT6, 253 CHANNEL_FRONT_BACK 254 }; 255 256 private static HashMap<String,Integer> mUsageStringToIntegerMap; 257 private static HashMap<String,Integer> mContentTypeStringToIntegerMap; 258 private static HashMap<String,Integer> mChannelMaskStringToIntegerMap; 259 private static List<String> mChannelMaskStrings = new ArrayList<>(); 260 261 private int mNativeApi; 262 private int mBufferCapacityInFrames; 263 private int mChannelCount; 264 private int mDeviceId; 265 private int mSessionId; 266 private int mDirection; // does not get reset 267 private int mFormat; 268 private int mSampleRate; 269 private int mSharingMode; 270 private int mPerformanceMode; 271 private boolean mFormatConversionAllowed; 272 private boolean mChannelConversionAllowed; 273 private int mRateConversionQuality; 274 private int mInputPreset; 275 private int mUsage; 276 private int mContentType; 277 private int mFramesPerBurst; 278 private boolean mMMap; 279 private int mChannelMask; 280 StreamConfiguration()281 public StreamConfiguration() { 282 reset(); 283 } 284 285 static { 286 // Build map for Usage string-to-int conversion. 287 mUsageStringToIntegerMap = new HashMap<String,Integer>(); convertUsageToText(UNSPECIFIED)288 mUsageStringToIntegerMap.put(convertUsageToText(UNSPECIFIED), UNSPECIFIED); 289 for (int usage : usages) { convertUsageToText(usage)290 mUsageStringToIntegerMap.put(convertUsageToText(usage), usage); 291 } 292 293 // Build map for Content Type string-to-int conversion. 294 mContentTypeStringToIntegerMap = new HashMap<String,Integer>(); convertContentTypeToText(UNSPECIFIED)295 mContentTypeStringToIntegerMap.put(convertContentTypeToText(UNSPECIFIED), UNSPECIFIED); 296 for (int contentType : contentTypes) { convertContentTypeToText(contentType)297 mContentTypeStringToIntegerMap.put(convertContentTypeToText(contentType), contentType); 298 } 299 300 // Build map for Channel Mask string-to-int conversion. 301 mChannelMaskStringToIntegerMap = new HashMap<String, Integer>(); 302 String channelMaskStr = convertChannelMaskToText(UNSPECIFIED); mChannelMaskStringToIntegerMap.put(channelMaskStr, UNSPECIFIED)303 mChannelMaskStringToIntegerMap.put(channelMaskStr, UNSPECIFIED); 304 mChannelMaskStrings.add(channelMaskStr); 305 for (int channelMask : channelMasks) { 306 channelMaskStr = convertChannelMaskToText(channelMask); mChannelMaskStringToIntegerMap.put(channelMaskStr, channelMask)307 mChannelMaskStringToIntegerMap.put(channelMaskStr, channelMask); 308 mChannelMaskStrings.add(channelMaskStr); 309 } 310 } 311 reset()312 public void reset() { 313 mNativeApi = NATIVE_API_UNSPECIFIED; 314 mBufferCapacityInFrames = UNSPECIFIED; 315 mChannelCount = UNSPECIFIED; 316 mChannelMask = UNSPECIFIED; 317 mDeviceId = UNSPECIFIED; 318 mSessionId = -1; 319 mFormat = AUDIO_FORMAT_PCM_FLOAT; 320 mSampleRate = UNSPECIFIED; 321 mSharingMode = SHARING_MODE_EXCLUSIVE; 322 mPerformanceMode = PERFORMANCE_MODE_LOW_LATENCY; 323 mInputPreset = INPUT_PRESET_VOICE_RECOGNITION; 324 mUsage = UNSPECIFIED; 325 mContentType = UNSPECIFIED; 326 mFormatConversionAllowed = false; 327 mChannelConversionAllowed = false; 328 mRateConversionQuality = RATE_CONVERSION_QUALITY_NONE; 329 mMMap = NativeEngine.isMMapSupported(); 330 } 331 getFramesPerBurst()332 public int getFramesPerBurst() { 333 return mFramesPerBurst; 334 } 335 setFramesPerBurst(int framesPerBurst)336 public void setFramesPerBurst(int framesPerBurst) { 337 this.mFramesPerBurst = framesPerBurst; 338 } 339 getBufferCapacityInFrames()340 public int getBufferCapacityInFrames() { 341 return mBufferCapacityInFrames; 342 } 343 setBufferCapacityInFrames(int bufferCapacityInFrames)344 public void setBufferCapacityInFrames(int bufferCapacityInFrames) { 345 this.mBufferCapacityInFrames = bufferCapacityInFrames; 346 } 347 getFormat()348 public int getFormat() { 349 return mFormat; 350 } 351 setFormat(int format)352 public void setFormat(int format) { 353 this.mFormat = format; 354 } 355 getDirection()356 public int getDirection() { 357 return mDirection; 358 } 359 setDirection(int direction)360 public void setDirection(int direction) { 361 this.mDirection = direction; 362 } 363 getPerformanceMode()364 public int getPerformanceMode() { 365 return mPerformanceMode; 366 } 367 setPerformanceMode(int performanceMode)368 public void setPerformanceMode(int performanceMode) { 369 this.mPerformanceMode = performanceMode; 370 } 371 convertPerformanceModeToText(int performanceMode)372 static String convertPerformanceModeToText(int performanceMode) { 373 switch(performanceMode) { 374 case PERFORMANCE_MODE_NONE: 375 return "NO"; 376 case PERFORMANCE_MODE_POWER_SAVING: 377 return "PS"; 378 case PERFORMANCE_MODE_LOW_LATENCY: 379 return "LL"; 380 default: 381 return "??"; 382 } 383 } 384 getInputPreset()385 public int getInputPreset() { return mInputPreset; } setInputPreset(int inputPreset)386 public void setInputPreset(int inputPreset) { 387 this.mInputPreset = inputPreset; 388 } 389 getUsage()390 public int getUsage() { return mUsage; } setUsage(int usage)391 public void setUsage(int usage) { 392 this.mUsage = usage; 393 } 394 getContentType()395 public int getContentType() { return mContentType; } setContentType(int contentType)396 public void setContentType(int contentType) { 397 this.mContentType = contentType; 398 } 399 convertUsageToText(int usage)400 static String convertUsageToText(int usage) { 401 switch(usage) { 402 case UNSPECIFIED: 403 return "Unspecified"; 404 case USAGE_MEDIA: 405 return "Media"; 406 case USAGE_VOICE_COMMUNICATION: 407 return "VoiceComm"; 408 case USAGE_VOICE_COMMUNICATION_SIGNALLING: 409 return "VoiceCommSig"; 410 case USAGE_ALARM: 411 return "Alarm"; 412 case USAGE_NOTIFICATION: 413 return "Notification"; 414 case USAGE_NOTIFICATION_RINGTONE: 415 return "Ringtone"; 416 case USAGE_NOTIFICATION_EVENT: 417 return "Event"; 418 case USAGE_ASSISTANCE_ACCESSIBILITY: 419 return "Accessability"; 420 case USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: 421 return "Navigation"; 422 case USAGE_ASSISTANCE_SONIFICATION: 423 return "Sonification"; 424 case USAGE_GAME: 425 return "Game"; 426 case USAGE_ASSISTANT: 427 return "Assistant"; 428 default: 429 return "?=" + usage; 430 } 431 } 432 convertTextToUsage(String text)433 public static int convertTextToUsage(String text) { 434 return mUsageStringToIntegerMap.get(text); 435 } 436 convertContentTypeToText(int contentType)437 static String convertContentTypeToText(int contentType) { 438 switch(contentType) { 439 case UNSPECIFIED: 440 return "Unspecified"; 441 case CONTENT_TYPE_SPEECH: 442 return "Speech"; 443 case CONTENT_TYPE_MUSIC: 444 return "Music"; 445 case CONTENT_TYPE_MOVIE: 446 return "Movie"; 447 case CONTENT_TYPE_SONIFICATION: 448 return "Sonification"; 449 default: 450 return "?=" + contentType; 451 } 452 } 453 convertTextToContentType(String text)454 public static int convertTextToContentType(String text) { 455 return mContentTypeStringToIntegerMap.get(text); 456 } 457 getSharingMode()458 public int getSharingMode() { 459 return mSharingMode; 460 } 461 setSharingMode(int sharingMode)462 public void setSharingMode(int sharingMode) { 463 this.mSharingMode = sharingMode; 464 } 465 convertSharingModeToText(int sharingMode)466 static String convertSharingModeToText(int sharingMode) { 467 switch(sharingMode) { 468 case SHARING_MODE_SHARED: 469 return "SH"; 470 case SHARING_MODE_EXCLUSIVE: 471 return "EX"; 472 default: 473 return "??"; 474 } 475 } 476 convertFormatToText(int format)477 public static String convertFormatToText(int format) { 478 switch(format) { 479 case UNSPECIFIED: 480 return "Unspecified"; 481 case AUDIO_FORMAT_PCM_16: 482 return "I16"; 483 case AUDIO_FORMAT_PCM_24: 484 return "I24"; 485 case AUDIO_FORMAT_PCM_32: 486 return "I32"; 487 case AUDIO_FORMAT_PCM_FLOAT: 488 return "Float"; 489 default: 490 return "Invalid"; 491 } 492 } 493 convertNativeApiToText(int api)494 public static String convertNativeApiToText(int api) { 495 switch(api) { 496 case NATIVE_API_UNSPECIFIED: 497 return "Unspec"; 498 case NATIVE_API_AAUDIO: 499 return "AAudio"; 500 case NATIVE_API_OPENSLES: 501 return "OpenSL"; 502 default: 503 return "Invalid"; 504 } 505 } 506 convertChannelMaskToText(int channelMask)507 public static String convertChannelMaskToText(int channelMask) { 508 switch (channelMask) { 509 case UNSPECIFIED: 510 return "Unspecified"; 511 case CHANNEL_MONO: 512 return "Mono"; 513 case CHANNEL_STEREO: 514 return "Stereo"; 515 case CHANNEL_2POINT1: 516 return "2.1"; 517 case CHANNEL_TRI: 518 return "Tri"; 519 case CHANNEL_TRI_BACK: 520 return "TriBack"; 521 case CHANNEL_3POINT1: 522 return "3.1"; 523 case CHANNEL_2POINT0POINT2: 524 return "2.0.2"; 525 case CHANNEL_2POINT1POINT2: 526 return "2.1.2"; 527 case CHANNEL_3POINT0POINT2: 528 return "3.0.2"; 529 case CHANNEL_3POINT1POINT2: 530 return "3.1.2"; 531 case CHANNEL_QUAD: 532 return "Quad"; 533 case CHANNEL_QUAD_SIDE: 534 return "QuadSide"; 535 case CHANNEL_SURROUND: 536 return "Surround"; 537 case CHANNEL_PENTA: 538 return "Penta"; 539 case CHANNEL_5POINT1: 540 return "5.1"; 541 case CHANNEL_5POINT1_SIDE: 542 return "5.1Side"; 543 case CHANNEL_6POINT1: 544 return "6.1"; 545 case CHANNEL_7POINT1: 546 return "7.1"; 547 case CHANNEL_5POINT1POINT2: 548 return "5.1.2"; 549 case CHANNEL_5POINT1POINT4: 550 return "5.1.4"; 551 case CHANNEL_7POINT1POINT2: 552 return "7.1.2"; 553 case CHANNEL_7POINT1POINT4: 554 return "7.1.4"; 555 case CHANNEL_9POINT1POINT4: 556 return "9.1.4"; 557 case CHANNEL_9POINT1POINT6: 558 return "9.1.6"; 559 case CHANNEL_FRONT_BACK: 560 return "FrontBack"; 561 default: 562 return "?=" + Integer.toHexString(channelMask); 563 } 564 } 565 convertTextToChannelMask(String text)566 public static int convertTextToChannelMask(String text) { 567 return mChannelMaskStringToIntegerMap.get(text); 568 } 569 570 dump()571 public String dump() { 572 String prefix = (getDirection() == DIRECTION_INPUT) ? "in" : "out"; 573 StringBuffer message = new StringBuffer(); 574 message.append(String.format("%s.channels = %d\n", prefix, mChannelCount)); 575 message.append(String.format("%s.perf = %s\n", prefix, 576 convertPerformanceModeToText(mPerformanceMode).toLowerCase())); 577 if (getDirection() == DIRECTION_INPUT) { 578 message.append(String.format("%s.preset = %s\n", prefix, 579 convertInputPresetToText(mInputPreset).toLowerCase())); 580 } else { 581 message.append(String.format("%s.preset = %s\n", prefix, 582 convertUsageToText(mUsage).toLowerCase())); 583 message.append(String.format("%s.contentType = %s\n", prefix, 584 convertContentTypeToText(mContentType).toLowerCase())); 585 } 586 message.append(String.format("%s.sharing = %s\n", prefix, 587 convertSharingModeToText(mSharingMode).toLowerCase())); 588 message.append(String.format("%s.api = %s\n", prefix, 589 convertNativeApiToText(getNativeApi()).toLowerCase())); 590 message.append(String.format("%s.rate = %d\n", prefix, mSampleRate)); 591 message.append(String.format("%s.device = %d\n", prefix, mDeviceId)); 592 message.append(String.format("%s.mmap = %s\n", prefix, isMMap() ? "yes" : "no")); 593 message.append(String.format("%s.rate.conversion.quality = %d\n", prefix, mRateConversionQuality)); 594 return message.toString(); 595 } 596 597 // text must match menu values 598 public static final String NAME_INPUT_PRESET_GENERIC = "Generic"; 599 public static final String NAME_INPUT_PRESET_CAMCORDER = "Camcorder"; 600 public static final String NAME_INPUT_PRESET_VOICE_RECOGNITION = "VoiceRec"; 601 public static final String NAME_INPUT_PRESET_VOICE_COMMUNICATION = "VoiceComm"; 602 public static final String NAME_INPUT_PRESET_UNPROCESSED = "Unprocessed"; 603 public static final String NAME_INPUT_PRESET_VOICE_PERFORMANCE = "Performance"; 604 convertInputPresetToText(int inputPreset)605 public static String convertInputPresetToText(int inputPreset) { 606 switch(inputPreset) { 607 case INPUT_PRESET_GENERIC: 608 return NAME_INPUT_PRESET_GENERIC; 609 case INPUT_PRESET_CAMCORDER: 610 return NAME_INPUT_PRESET_CAMCORDER; 611 case INPUT_PRESET_VOICE_RECOGNITION: 612 return NAME_INPUT_PRESET_VOICE_RECOGNITION; 613 case INPUT_PRESET_VOICE_COMMUNICATION: 614 return NAME_INPUT_PRESET_VOICE_COMMUNICATION; 615 case INPUT_PRESET_UNPROCESSED: 616 return NAME_INPUT_PRESET_UNPROCESSED; 617 case INPUT_PRESET_VOICE_PERFORMANCE: 618 return NAME_INPUT_PRESET_VOICE_PERFORMANCE; 619 default: 620 return "Invalid"; 621 } 622 } 623 matchInputPreset(String text, int preset)624 private static boolean matchInputPreset(String text, int preset) { 625 return convertInputPresetToText(preset).toLowerCase().equals(text); 626 } 627 628 /** 629 * Case insensitive. 630 * @param text 631 * @return inputPreset, eg. INPUT_PRESET_CAMCORDER 632 */ convertTextToInputPreset(String text)633 public static int convertTextToInputPreset(String text) { 634 text = text.toLowerCase(); 635 if (matchInputPreset(text, INPUT_PRESET_GENERIC)) { 636 return INPUT_PRESET_GENERIC; 637 } else if (matchInputPreset(text, INPUT_PRESET_CAMCORDER)) { 638 return INPUT_PRESET_CAMCORDER; 639 } else if (matchInputPreset(text, INPUT_PRESET_VOICE_RECOGNITION)) { 640 return INPUT_PRESET_VOICE_RECOGNITION; 641 } else if (matchInputPreset(text, INPUT_PRESET_VOICE_COMMUNICATION)) { 642 return INPUT_PRESET_VOICE_COMMUNICATION; 643 } else if (matchInputPreset(text, INPUT_PRESET_UNPROCESSED)) { 644 return INPUT_PRESET_UNPROCESSED; 645 } else if (matchInputPreset(text, INPUT_PRESET_VOICE_PERFORMANCE)) { 646 return INPUT_PRESET_VOICE_PERFORMANCE; 647 } 648 return -1; 649 } 650 getChannelCount()651 public int getChannelCount() { 652 return mChannelCount; 653 } 654 setChannelCount(int channelCount)655 public void setChannelCount(int channelCount) { 656 this.mChannelCount = channelCount; 657 } 658 getSampleRate()659 public int getSampleRate() { 660 return mSampleRate; 661 } 662 setSampleRate(int sampleRate)663 public void setSampleRate(int sampleRate) { 664 this.mSampleRate = sampleRate; 665 } 666 getDeviceId()667 public int getDeviceId() { 668 return mDeviceId; 669 } 670 setDeviceId(int deviceId)671 public void setDeviceId(int deviceId) { 672 this.mDeviceId = deviceId; 673 } 674 getSessionId()675 public int getSessionId() { 676 return mSessionId; 677 } 678 setSessionId(int sessionId)679 public void setSessionId(int sessionId) { 680 mSessionId = sessionId; 681 } 682 isMMap()683 public boolean isMMap() { 684 return mMMap; 685 } 686 setMMap(boolean b)687 public void setMMap(boolean b) { mMMap = b; } 688 getNativeApi()689 public int getNativeApi() { 690 return mNativeApi; 691 } 692 setNativeApi(int nativeApi)693 public void setNativeApi(int nativeApi) { 694 mNativeApi = nativeApi; 695 } 696 setChannelConversionAllowed(boolean b)697 public void setChannelConversionAllowed(boolean b) { mChannelConversionAllowed = b; } 698 getChannelConversionAllowed()699 public boolean getChannelConversionAllowed() { 700 return mChannelConversionAllowed; 701 } 702 setFormatConversionAllowed(boolean b)703 public void setFormatConversionAllowed(boolean b) { 704 mFormatConversionAllowed = b; 705 } 706 getFormatConversionAllowed()707 public boolean getFormatConversionAllowed() { 708 return mFormatConversionAllowed; 709 } 710 setRateConversionQuality(int quality)711 public void setRateConversionQuality(int quality) { mRateConversionQuality = quality; } 712 getRateConversionQuality()713 public int getRateConversionQuality() { 714 return mRateConversionQuality; 715 } 716 getChannelMask()717 public int getChannelMask() { 718 return mChannelMask; 719 } 720 setChannelMask(int channelMask)721 public void setChannelMask(int channelMask) { 722 this.mChannelMask = channelMask; 723 } 724 getAllChannelMasks()725 public static List<String> getAllChannelMasks() { 726 return mChannelMaskStrings; 727 } 728 729 } 730