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.IO;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.Dvb.Descriptors.Extension
{
	[SkyscraperPlugin]
	[ExtensionDescriptor(0x15,"PMT")]
    class Ac4Descriptor : Dvb.ExtensionDescriptor
    {
        public Ac4Descriptor(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, false);
            byte flags = ms.ReadUInt8();
            bool ac4ConfigFlag = (flags & 0x80) != 0;
            bool ac4TocFlag = (flags & 0x40) != 0;
            if (ac4ConfigFlag)
            {
                flags = ms.ReadUInt8();
                Ac4DialogEnhancementEnabled = (flags & 0x80) != 0;
                Ac4ChannelMode = (flags & 0x60) >> 5;
            }

            if (ac4TocFlag)
            {
                byte ac4TocLen = ms.ReadUInt8();
                Ac4Dsi = ms.ReadBytes(ac4TocLen);
            }
        }

        public byte[] Ac4Dsi { get; private set; }

        public int Ac4ChannelMode { get; private set; }

        public bool Ac4DialogEnhancementEnabled { get; private set; }
    }
}
