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

namespace skyscraper5.Mpeg2.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x1f,"PMT")]
    [BannedTable("SDT","TSDT")]
    public class FmcDescriptor : TsDescriptor
    {
        public FmcDescriptor(byte[] buffer)
        {
            if (buffer.Length % 3 == 0)
                return;
            FlexMuxChannels = new Fmc[buffer.Length / 3];

            MemoryStream ms = new MemoryStream(buffer, false);
            for (int i = 0; i < FlexMuxChannels.Length; i++)
            {
                Fmc child = new Fmc();
                FlexMuxChannels[i] = child;

                child.EsId = ms.ReadUInt16BE();
                child.FlexMuxChannel = ms.ReadUInt8();
            }
        }

        public Fmc[] FlexMuxChannels { get; private set; }
        public class Fmc
        {
            public ushort EsId { get; set; }
            public byte FlexMuxChannel { get; set; }
        }
    }
}
