// Path: library/src/main/java/com/jwoolston/android/uvc/interfaces/VideoClassInterface.java
// public abstract class VideoClassInterface extends UvcInterface {
// 
//     VideoClassInterface(UsbInterface usbInterface, byte[] descriptor) {
//         super(usbInterface, descriptor);
//     }
// 
//     public static enum VC_INF_SUBTYPE {
//         VC_DESCRIPTOR_UNDEFINED(0x00),
//         VC_HEADER(0x01),
//         VC_INPUT_TERMINAL(0x02),
//         VC_OUTPUT_TERMINAL(0x03),
//         VC_SELECTOR_UNIT(0x04),
//         VC_PROCESSING_UNIT(0x05),
//         VC_EXTENSION_UNIT(0x06),
//         VC_ENCODING_UNIT(0x07);
// 
//         public final byte subtype;
// 
//         private VC_INF_SUBTYPE(int subtype) {
//             this.subtype = (byte) (subtype & 0xFF);
//         }
// 
//         public static VC_INF_SUBTYPE getSubtype(byte subtype) {
//             for (VC_INF_SUBTYPE s : VC_INF_SUBTYPE.values()) {
//                 if (s.subtype == subtype) {
//                     return s;
//                 }
//             }
//             return null;
//         }
//     }
// }


import com.jwoolston.android.uvc.interfaces.VideoClassInterface;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import timber.log.Timber;
package com.jwoolston.android.uvc.interfaces.units;


/**
 * The Encoding Unit controls attributes of the encoder that encodes the video being streamed through it. It has a
 * single input and multiple output pins. It provides support for the following features which can be used before or
 * after streaming has started.
 *
 * <br>-Select Layer
 * <br>-Video Resolution
 * <br>-Profile and Toolset
 * <br>-Minimum Frame Interval
 * <br>-Slice Mode
 * <br>-Rate Control Mode
 * <br>-Average Bitrate Control
 * <br>-CPB Size Control
 * <br>-Peak Bit Rate
 * <br>-Quantization Parameter
 * <br>-Synchronization and Long Term Reference Frame
 * <br>-Long Term Reference Buffers
 * <br>-Long Term Picture
 * <br>-Valid Long Term Pictures
 * <br>-LevelIDC
 * <br>-SEI Message
 * <br>-QP Range
 * <br>-Priority ID
 * <br>-Start or Stop Layer
 * <br>-Error Resiliency
 *
 * Support for the Encoding Unit control is optional and only applicable to devices with onboard video encoders. The
 * Select Layer control also allows control of individual streams for devices that support simulcast transport of
 * more than one stream. Individual payloads may specialize the behavior of each of these controls to align with the
 * feature set defined by the associated encoder, e.g. H.264. This specialized behavior is defined in the associated
 * payload specification.
 *
 * @author Jared Woolston (Jared.Woolston@gmail.com)
 * @see <a href=http://www.usb.org/developers/docs/devclass_docs/USB_Video_Class_1_5.zip>UVC 1.5 Class
 * Specification §2.3.6</a>
 */
public class VideoEncodingUnit extends VideoUnit {

    private static final int LENGTH = 13;

    private static final int bSourceID         = 4;
    private static final int iEncoding         = 5;
    private static final int bmControls        = 7;
    private static final int bmControlsRuntime = 10;

    private final int mSourceID;
    private final int mIndexEncoding;

    private final Set<CONTROL> mControlSet;
    private final Set<CONTROL> mRuntimeControlSet;

    public static boolean isVideoEncodingUnit(byte[] descriptor) {
        return (descriptor.length >= LENGTH
// Path: library/src/main/java/com/jwoolston/android/uvc/interfaces/VideoClassInterface.java
// public abstract class VideoClassInterface extends UvcInterface {
// 
//     VideoClassInterface(UsbInterface usbInterface, byte[] descriptor) {
//         super(usbInterface, descriptor);
//     }
// 
//     public static enum VC_INF_SUBTYPE {
//         VC_DESCRIPTOR_UNDEFINED(0x00),
//         VC_HEADER(0x01),
//         VC_INPUT_TERMINAL(0x02),
//         VC_OUTPUT_TERMINAL(0x03),
//         VC_SELECTOR_UNIT(0x04),
//         VC_PROCESSING_UNIT(0x05),
//         VC_EXTENSION_UNIT(0x06),
//         VC_ENCODING_UNIT(0x07);
// 
//         public final byte subtype;
// 
//         private VC_INF_SUBTYPE(int subtype) {
//             this.subtype = (byte) (subtype & 0xFF);
//         }
// 
//         public static VC_INF_SUBTYPE getSubtype(byte subtype) {
//             for (VC_INF_SUBTYPE s : VC_INF_SUBTYPE.values()) {
//                 if (s.subtype == subtype) {
//                     return s;
//                 }
//             }
//             return null;
//         }
//     }
// }


// Path: library/src/main/java/com/jwoolston/android/uvc/interfaces/units/VideoEncodingUnit.java
import com.jwoolston.android.uvc.interfaces.VideoClassInterface;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import timber.log.Timber;

package com.jwoolston.android.uvc.interfaces.units;


/**
 * The Encoding Unit controls attributes of the encoder that encodes the video being streamed through it. It has a
 * single input and multiple output pins. It provides support for the following features which can be used before or
 * after streaming has started.
 *
 * <br>-Select Layer
 * <br>-Video Resolution
 * <br>-Profile and Toolset
 * <br>-Minimum Frame Interval
 * <br>-Slice Mode
 * <br>-Rate Control Mode
 * <br>-Average Bitrate Control
 * <br>-CPB Size Control
 * <br>-Peak Bit Rate
 * <br>-Quantization Parameter
 * <br>-Synchronization and Long Term Reference Frame
 * <br>-Long Term Reference Buffers
 * <br>-Long Term Picture
 * <br>-Valid Long Term Pictures
 * <br>-LevelIDC
 * <br>-SEI Message
 * <br>-QP Range
 * <br>-Priority ID
 * <br>-Start or Stop Layer
 * <br>-Error Resiliency
 *
 * Support for the Encoding Unit control is optional and only applicable to devices with onboard video encoders. The
 * Select Layer control also allows control of individual streams for devices that support simulcast transport of
 * more than one stream. Individual payloads may specialize the behavior of each of these controls to align with the
 * feature set defined by the associated encoder, e.g. H.264. This specialized behavior is defined in the associated
 * payload specification.
 *
 * @author Jared Woolston (Jared.Woolston@gmail.com)
 * @see <a href=http://www.usb.org/developers/docs/devclass_docs/USB_Video_Class_1_5.zip>UVC 1.5 Class
 * Specification §2.3.6</a>
 */
public class VideoEncodingUnit extends VideoUnit {

    private static final int LENGTH = 13;

    private static final int bSourceID         = 4;
    private static final int iEncoding         = 5;
    private static final int bmControls        = 7;
    private static final int bmControlsRuntime = 10;

    private final int mSourceID;
    private final int mIndexEncoding;

    private final Set<CONTROL> mControlSet;
    private final Set<CONTROL> mRuntimeControlSet;

    public static boolean isVideoEncodingUnit(byte[] descriptor) {
        return (descriptor.length >= LENGTH
                & descriptor[bDescriptorSubtype] == VideoClassInterface.VC_INF_SUBTYPE.VC_ENCODING_UNIT.subtype);