Home | History | Annotate | Download | only in descriptors
      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  * Audio20.pdf - 4.9.2 Class-Specific AS Interface Descriptor
     22  * 16 bytes
     23  */
     24 public final class Usb20ASGeneral extends UsbACInterface {
     25     private static final String TAG = "Usb20ASGeneral";
     26 
     27     // Audio20.pdf - Table 4-27
     28     private byte mTerminalLink; // 3:1 The Terminal ID of the Terminal to which
     29                                 // this interface is connected.
     30     private byte mControls;     // 4:1 see audio20.pdf Table 4-27
     31     private byte mFormatType;   // 5:1 Constant identifying the Format Type the
     32                                 // AudioStreaming interface is using.
     33     private int mFormats;       // 6:4 The Audio Data Format(s) that can be
     34                                 // used to communicate with this interface.
     35                                 // See the USB Audio Data Formats
     36                                 // document for further details.
     37     private byte mNumChannels;  // 10:1 Number of physical channels in the AS
     38                                 // Interface audio channel cluster.
     39     private int mChannelConfig; // 11:4 Describes the spatial location of the
     40                                 // physical channels.
     41     private byte mChannelNames; // 15:1 Index of a string descriptor, describing the
     42                                 // name of the first physical channel.
     43 
     44     public Usb20ASGeneral(int length, byte type, byte subtype, int subclass) {
     45         super(length, type, subtype, subclass);
     46     }
     47 
     48     public byte getTerminalLink() {
     49         return mTerminalLink;
     50     }
     51 
     52     public byte getControls() {
     53         return mControls;
     54     }
     55 
     56     public byte getFormatType() {
     57         return mFormatType;
     58     }
     59 
     60     public int getFormats() {
     61         return mFormats;
     62     }
     63 
     64     public byte getNumChannels() {
     65         return mNumChannels;
     66     }
     67 
     68     public int getChannelConfig() {
     69         return mChannelConfig;
     70     }
     71 
     72     public byte getChannelNames() {
     73         return mChannelNames;
     74     }
     75 
     76     @Override
     77     public int parseRawDescriptors(ByteStream stream) {
     78 
     79         mTerminalLink = stream.getByte();
     80         mControls = stream.getByte();
     81         mFormatType = stream.getByte();
     82         mFormats = stream.unpackUsbInt();
     83         mNumChannels = stream.getByte();
     84         mChannelConfig = stream.unpackUsbInt();
     85         mChannelNames = stream.getByte();
     86 
     87         return mLength;
     88     }
     89 
     90     @Override
     91     public void report(ReportCanvas canvas) {
     92         super.report(canvas);
     93 
     94         canvas.openList();
     95         canvas.writeListItem("Terminal Link: " + getTerminalLink());
     96         canvas.writeListItem("Controls: " + ReportCanvas.getHexString(getControls()));
     97         canvas.writeListItem("Format Type: " + ReportCanvas.getHexString(getFormatType()));
     98         canvas.writeListItem("Formats: " + ReportCanvas.getHexString(getFormats()));
     99         canvas.writeListItem("Num Channels: " + getNumChannels());
    100         canvas.writeListItem("Channel Config: " + ReportCanvas.getHexString(getChannelConfig()));
    101         canvas.writeListItem("Channel Names String ID: " + getChannelNames());
    102         canvas.closeList();
    103     }
    104 }
    105