using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.Dvb.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x7a,"PMT")]
    class EnhancedAc3Descriptor : TsDescriptor
    {
        public EnhancedAc3Descriptor(byte[] buffer)
        {
            int ptr = 0;
            byte flags = buffer[ptr++];
            bool componentTypeFlags = (flags & 0x80) != 0;
            bool bsidFlag = (flags & 0x40) != 0;
            bool mainIdFlag = (flags & 0x20) != 0;
            bool asvcFlag = (flags & 0x10) != 0;
            MixInfoExists = (flags & 0x08) != 0;
            bool substream1Flag = (flags & 0x04) != 0;
            bool substream2Flag = (flags & 0x02) != 0;
            bool substream3Flag = (flags & 0x01) != 0;
            if (componentTypeFlags)
                ComponentType = buffer[ptr++];
            if (bsidFlag)
                BSID = buffer[ptr++];
            if (mainIdFlag)
                MainId = buffer[ptr++];
            if (asvcFlag)
                ASVC = buffer[ptr++];
            if (substream1Flag)
                Substream1 = buffer[ptr++];
            if (substream2Flag)
                Substream2 = buffer[ptr++];
            if (substream3Flag)
                Substream3 = buffer[ptr++];
        }

        public byte? Substream3 { get; private set; }

        public byte? Substream2 { get; private set; }

        public byte? Substream1 { get; private set; }

        public bool MixInfoExists { get; private set; }

        public byte? ASVC { get; private set; }

        public byte? MainId { get; private set; }

        public byte? BSID { get; private set; }

        public byte? ComponentType { get; private set; }
    }
}
