package net.northking.cctp.upperComputer.driver.agent.command;


import net.northking.cctp.upperComputer.driver.agent.command.data.MediaCodecInfo;
import net.northking.cctp.upperComputer.driver.agent.command.protocol.AbstractProtocolCommand;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;


public class MediaCodecListCommand extends AbstractProtocolCommand<ArrayList<MediaCodecInfo>> {

    private static MediaCodecListCommand instance = null;

    public static MediaCodecListCommand getInstance() {
        if (instance == null) {
            instance = new MediaCodecListCommand();
        }
        return instance;
    }

    @Override
    public int getCommandId() {
        return 47;
    }

    @Override
    public void doSend(DataOutput output) throws IOException {

    }

    @Override
    public ArrayList<MediaCodecInfo> buildReceive(DataInput input) throws IOException {
        int count = input.readInt();
        ArrayList list = new ArrayList<MediaCodecInfo>(count);
        for (int i = 0; i < count; i++) {
            MediaCodecInfo info = new MediaCodecInfo();
            info.setName(readText(input));
            info.setCanonicalName(readText(input));
            info.setAlias(input.readBoolean());
            info.setVendor(input.readBoolean());
            info.setSoftwareOnly(input.readBoolean());
            info.setHardwareAccelerated(input.readBoolean());
            info.setEncoder(input.readBoolean());
            int supportedTypesCount = input.readInt();
            ArrayList supportedTypes = new ArrayList<String>(supportedTypesCount);
            for (int j = 0; j < supportedTypesCount; j++) {
                supportedTypes.add(readText(input));
            }
            info.setSupportedTypes(supportedTypes);
            list.add(info);
        }
        return list;
    }
}
