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

namespace skyscraper5.src.Mpeg2.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x2e, "PMT")]
	public class _0x2E_Mpeg4AudioExtensionDescriptor : TsDescriptor
	{
		public _0x2E_Mpeg4AudioExtensionDescriptor(byte[] buffer)
		{
			MemoryStream ms = new MemoryStream(buffer, false);
			byte firstByte = ms.ReadUInt8();
			bool ascFlag = (firstByte & 0x80) != 0;
			int numOfLoops = (firstByte & 0x0f);
			AudioProfileLevelIndication = ms.ReadBytes(numOfLoops);
			if (ascFlag)
			{
				byte ascSize = ms.ReadUInt8();
				AudioSpecificConfig = ms.ReadBytes(ascSize);
			}
			Valid = true;
		}

		/// <summary>
		/// encoded as specified for the audioprofileLevelIndication field in 1.5.2.1 in ISO/IEC 14496-3
		/// </summary>
		public byte[] AudioProfileLevelIndication { get; }
	
		/// <summary>
		/// The audioSpecificConfig() of the associated ISO/IEC 14496-3 audio stream, as specified in 1.6.2.1 in ISO/IEC 14496-3.
		/// </summary>
		public byte[] AudioSpecificConfig { get; }
	}
}
