1 /* 2 * Copyright (C) 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 package com.android.server.usb.descriptors; 17 18 import com.android.server.usb.descriptors.report.ReportCanvas; 19 20 /** 21 * @hide 22 * An audio class-specific Format I interface. 23 * see Frmts10.pdf section 2.2 24 */ 25 public final class Usb10ASFormatI extends UsbASFormat { 26 private static final String TAG = "Usb10ASFormatI"; 27 28 private byte mNumChannels; // 4:1 29 private byte mSubframeSize; // 5:1 frame size in bytes 30 private byte mBitResolution; // 6:1 sample size in bits 31 private byte mSampleFreqType; // 7:1 32 private int[] mSampleRates; // if mSamFreqType == 0, there will be 2 values: the 33 // min & max rates otherwise mSamFreqType rates. 34 // All 3-byte values. All rates in Hz 35 36 public Usb10ASFormatI(int length, byte type, byte subtype, byte formatType, int subclass) { 37 super(length, type, subtype, formatType, subclass); 38 } 39 40 public byte getNumChannels() { 41 return mNumChannels; 42 } 43 44 public byte getSubframeSize() { 45 return mSubframeSize; 46 } 47 48 public byte getBitResolution() { 49 return mBitResolution; 50 } 51 52 public byte getSampleFreqType() { 53 return mSampleFreqType; 54 } 55 56 @Override 57 public int[] getSampleRates() { 58 return mSampleRates; 59 } 60 61 @Override 62 public int[] getBitDepths() { 63 int[] depths = {mBitResolution}; 64 return depths; 65 } 66 67 @Override 68 public int[] getChannelCounts() { 69 int[] counts = {mNumChannels}; 70 return counts; 71 } 72 73 @Override 74 public int parseRawDescriptors(ByteStream stream) { 75 mNumChannels = stream.getByte(); 76 mSubframeSize = stream.getByte(); 77 mBitResolution = stream.getByte(); 78 mSampleFreqType = stream.getByte(); 79 if (mSampleFreqType == 0) { 80 mSampleRates = new int[2]; 81 mSampleRates[0] = stream.unpackUsbTriple(); 82 mSampleRates[1] = stream.unpackUsbTriple(); 83 } else { 84 mSampleRates = new int[mSampleFreqType]; 85 for (int index = 0; index < mSampleFreqType; index++) { 86 mSampleRates[index] = stream.unpackUsbTriple(); 87 } 88 } 89 90 return mLength; 91 } 92 93 @Override 94 public void report(ReportCanvas canvas) { 95 super.report(canvas); 96 97 canvas.openList(); 98 canvas.writeListItem("" + getNumChannels() + " Channels."); 99 canvas.writeListItem("Subframe Size: " + getSubframeSize()); 100 canvas.writeListItem("Bit Resolution: " + getBitResolution()); 101 byte sampleFreqType = getSampleFreqType(); 102 int[] sampleRates = getSampleRates(); 103 canvas.writeListItem("Sample Freq Type: " + sampleFreqType); 104 canvas.openList(); 105 if (sampleFreqType == 0) { 106 canvas.writeListItem("min: " + sampleRates[0]); 107 canvas.writeListItem("max: " + sampleRates[1]); 108 } else { 109 for (int index = 0; index < sampleFreqType; index++) { 110 canvas.writeListItem("" + sampleRates[index]); 111 } 112 } 113 canvas.closeList(); 114 canvas.closeList(); 115 } 116 } 117