Usb10ACMixerUnit.java revision 558ff9d3f5f0a70d745b72d1d2d84f4e91850b8b
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 */
16package com.android.server.usb.descriptors;
17
18import com.android.server.usb.descriptors.report.ReportCanvas;
19
20/**
21 * @hide
22 * An audio class-specific Mixer Interface.
23 * see audio10.pdf section 4.3.2.3
24 */
25public final class Usb10ACMixerUnit extends UsbACMixerUnit {
26    private static final String TAG = "Usb10ACMixerUnit";
27
28    private int mChannelConfig; // Spatial location of output channels
29    private byte mChanNameID;   // First channel name string descriptor ID
30    private byte[] mControls;   // bitmasks of which controls are present for each channel
31    private byte mNameID;       // string descriptor ID of mixer name
32
33    public Usb10ACMixerUnit(int length, byte type, byte subtype, int subClass) {
34        super(length, type, subtype, subClass);
35    }
36
37    public int getChannelConfig() {
38        return mChannelConfig;
39    }
40
41    public byte getChanNameID() {
42        return mChanNameID;
43    }
44
45    public byte[] getControls() {
46        return mControls;
47    }
48
49    public byte getNameID() {
50        return mNameID;
51    }
52
53    @Override
54    public int parseRawDescriptors(ByteStream stream) {
55        super.parseRawDescriptors(stream);
56
57        mChannelConfig = stream.unpackUsbShort();
58        mChanNameID = stream.getByte();
59
60        int controlArraySize = calcControlArraySize(mNumInputs, mNumOutputs);
61        mControls = new byte[controlArraySize];
62        for (int index = 0; index < controlArraySize; index++) {
63            mControls[index] = stream.getByte();
64        }
65
66        mNameID = stream.getByte();
67
68        return mLength;
69    }
70
71    @Override
72    public void report(ReportCanvas canvas) {
73        super.report(canvas);
74
75        canvas.writeParagraph("Mixer Unit", false);
76        canvas.openList();
77
78        canvas.writeListItem("Unit ID: " + ReportCanvas.getHexString(getUnitID()));
79        byte numInputs = getNumInputs();
80        byte[] inputIDs = getInputIDs();
81        canvas.openListItem();
82        canvas.write("Num Inputs: " + numInputs + " [");
83        for (int input = 0; input < numInputs; input++) {
84            canvas.write("" + ReportCanvas.getHexString(inputIDs[input]));
85            if (input < numInputs - 1) {
86                canvas.write(" ");
87            }
88        }
89        canvas.write("]");
90        canvas.closeListItem();
91
92        canvas.writeListItem("Num Outputs: " + getNumOutputs());
93        canvas.writeListItem("Channel Config: " + ReportCanvas.getHexString(getChannelConfig()));
94
95        byte[] controls = getControls();
96        canvas.openListItem();
97        canvas.write("Controls: " + controls.length + " [");
98        for (int ctrl = 0; ctrl < controls.length; ctrl++) {
99            canvas.write("" + controls[ctrl]);
100            if (ctrl < controls.length - 1) {
101                canvas.write(" ");
102            }
103        }
104        canvas.write("]");
105        canvas.closeListItem();
106        canvas.closeList();
107    }
108}
109