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(0x2d,"PMT")]
    class Mpeg4TextDescriptor : TsDescriptor
    {
        public Mpeg4TextDescriptor(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, false);
            TextFormat = ms.ReadUInt8();
            if (TextFormat != 1)
                return;
            ushort textConfigLength = ms.ReadUInt16BE();
            if (ms.GetAvailableBytes() < textConfigLength)
                return;

            byte[] textConfig = ms.ReadBytes(textConfigLength);
            FormatSpecificTextConfig = new _3GPPSpecificTextConfig(textConfig);
        }

        public byte TextFormat { get; private set; }

        public _FormatSpecificTextConfig FormatSpecificTextConfig { get; private set; }

        public class _FormatSpecificTextConfig
        {

        }

        public class _3GPPSpecificTextConfig : _FormatSpecificTextConfig
        {
            public _3GPPSpecificTextConfig(byte[] buffer)
            {
                MemoryStream ms = new MemoryStream(buffer, false);
                //see ourdev_631444SHQH4Y.pdf, Page 21
                throw new NotFiniteNumberException(nameof(_3GPPSpecificTextConfig));
            }
        }
    }
}
