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;
19import com.android.server.usb.descriptors.report.UsbStrings;
20
21/**
22 * @hide
23 * An audio class-specific General interface.
24 * see audio10.pdf section 4.5.2
25 */
26public final class Usb10ASGeneral extends UsbACInterface {
27    private static final String TAG = "Usb10ASGeneral";
28
29    // audio10.pdf - section 4.5.2
30    private byte mTerminalLink; // 3:1 The Terminal ID of the Terminal to which the endpoint
31                                // of this interface is connected.
32    private byte mDelay;        // 4:1 Delay introduced by the data path (see Section 3.4,
33                                // “Inter Channel Synchronization”). Expressed in number of frames.
34    private int mFormatTag;     // 5:2 The Audio Data Format that has to be used to communicate
35                                // with this interface.
36
37    public Usb10ASGeneral(int length, byte type, byte subtype, int subclass) {
38        super(length, type, subtype, subclass);
39    }
40
41    public byte getTerminalLink() {
42        return mTerminalLink;
43    }
44
45    public byte getDelay() {
46        return mDelay;
47    }
48
49    public int getFormatTag() {
50        return mFormatTag;
51    }
52
53    @Override
54    public int parseRawDescriptors(ByteStream stream) {
55        mTerminalLink = stream.getByte();
56        mDelay = stream.getByte();
57        mFormatTag = stream.unpackUsbShort();
58
59        return mLength;
60    }
61
62    @Override
63    public void report(ReportCanvas canvas) {
64        super.report(canvas);
65
66        canvas.openList();
67        canvas.writeListItem("Delay: " + mDelay);
68        canvas.writeListItem("Terminal Link: " + mTerminalLink);
69        canvas.writeListItem("Format: " + UsbStrings.getAudioFormatName(mFormatTag) + " - "
70                + ReportCanvas.getHexString(mFormatTag));
71        canvas.closeList();
72    }
73}
74