libepg.ts.packet.RESERVED_PROGRAM_ID.java Source code

Java tutorial

Introduction

Here is the source code for libepg.ts.packet.RESERVED_PROGRAM_ID.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package libepg.ts.packet;

import enumsupport.reverselookupmapfactory.DeduplicatdeNumberSetFactory;
import enumsupport.reverselookupmapfactory.ReverseLookUpMapFactory;
import java.text.MessageFormat;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import org.apache.commons.lang3.Range;

/**
 * TS???PID???????????? 0x0000=PAT 0x0001=CAT 0x00020x000F=
 * 0x0010=NIT 0x00110x1FFE=PAT?CAT?NIT?????????? 0x1FFF=
 *
 * (?????????PAT???????????)<br>
 * 0x0,0x1,0x10,0x11,0x12,0x14,0x23,0x24,0x27,0x28,0x29,0x100,0x110,0x111,0x130,0x137,0x138,0x140,0x160,0x161,0x162,0x163,0x164,0x165,0x1f0,0x1ff,0x238,<br>
 * 0x3f0,0x480,0x481,0x4f0,0x580,0x581,0x583,0x587,0x589,0x58a,0x58b,0x5a6,0x5f4,0x5ff,0x781,0x900,0x901,0x902,0xaef,0xb93,0xe52,0x1380,0x161a,0x1c61,<br>
 * 0x1c63,0x1d76,0x1df0,0x1f22,0x1f86,0x1fc8,0x1ffd<br>
 * ???????enum?????????<br>
 * <br>
 */
public enum RESERVED_PROGRAM_ID {

    /**
     * PAT(Program Association Table) MPEG-2
     * TS???????????????MPEG-2 TS <br>
     * PMT?PID????<br>
     * PAT?PID?0????<br>
     */
    PAT("PAT", 0x0), UNDEFINED("", 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe,
            0xf), CAT("CAT", 0x1),
    /**
     * ?NITNIT ?????ISO/IEC 13818-1(22)???????
     * ??ISO/IEC 13818-1(22)???NIT ????????? ?????????NIT
     * ??????? MPEG-2 ?PSI ????TLV ??????????2 ?
     * ????????? 1) TLV ?TLV-NIT TLV-NIT ??NIT
     * ????????????? 2) AMT AMT
     * ???????IP ?? ???
     */
    NIT("?", 0x10),
    /**
     * SDTService Description Table<br>
     * ??????????????????????id=0x42<br>
     *
     * BAT(SDT??ID?????????)<br>
     * ????????????????????(?????)id=?<br>
     */
    SDT_OR_BAT("????", 0x11),
    /**
     * ????????????? (?=0x12 =0x26,0x27)
     */
    EIT_GR_ST("", 0x12, 0x26, 0x27),
    /**
     * null
     */
    NULL_PACKET("null", 0x1FFF);

    /**
     * ??
     */
    private static final Map<Integer, RESERVED_PROGRAM_ID> rev;

    private static final Function<RESERVED_PROGRAM_ID, Set<Integer>> func1 = (RESERVED_PROGRAM_ID t) -> t.getPids();
    //???
    private static final ReverseLookUpMapFactory<Integer, Set<Integer>, RESERVED_PROGRAM_ID> revmapf = new ReverseLookUpMapFactory<>(
            func1);

    static {
        for (RESERVED_PROGRAM_ID pid : RESERVED_PROGRAM_ID.values()) {
            revmapf.put(pid);
        }
        rev = revmapf.getUnmodifiableMap();
    }

    ;

    /**
     * ID??????
     *
     * @param pid ID
     * @return ID????null
     */
    public static synchronized RESERVED_PROGRAM_ID reverseLookUp(int pid) {
        return rev.get(pid);
    }

    private final String pidName;
    private final Set<Integer> pids;

    private RESERVED_PROGRAM_ID(String pidName, Integer pid, Integer... pids) {

        this.pidName = pidName;
        if ((this.pidName == null) || ("".equals(this.pidName))) {
            throw new IllegalArgumentException("???????????");
        }
        Range<Integer> r = Range.between(0x0000, 0x1FFF);

        DeduplicatdeNumberSetFactory<Integer> setf = new DeduplicatdeNumberSetFactory<>();

        this.pids = setf.makeSet(r, pid, pids);

    }

    /**
     * ??????PID???????
     *
     * @param pid PID
     * @return ?????true
     */
    public synchronized boolean contains(int pid) {
        return this.pids.contains(pid);
    }

    public String getPidName() {
        return pidName;
    }

    /**
     * @return ??????pid?
     */
    public Set<Integer> getPids() {
        return pids;
    }

    @Override
    public synchronized String toString() {
        StringBuilder s = new StringBuilder();
        for (int i : this.pids) {
            s.append("[");
            s.append(Integer.toHexString(i));
            s.append("]");
        }
        String set = s.toString();
        MessageFormat msg = new MessageFormat("{0}(pidName={1},PIDs={2})");
        Object[] parameters = { super.toString(), this.getPidName(), set };
        return msg.format(parameters);
    }
}