// implement class BluRayOutput
+readonly byte BluRayOutput::index_bdmv[] = {
+ 0x49, 0x4e, 0x44, 0x58, 0x30, 0x31, 0x30, 0x30, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x78,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x26, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
+ 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x92, 0x00, 0x00, 0x00, 0x18,
+ 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x01, 0x7e,
+ 0x49, 0x44, 0x45, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x62, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x36, 0x10, 0x13, 0x00, 0x01,
+ 0x54, 0x52, 0x20, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x2e, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x06, 0xff, 0xff, 0x42, 0x20, 0x07, 0x08, 0x08, 0x00, 0x54, 0x53, 0x00, 0x90, 0x0a, 0x54,
+ 0x52, 0x20, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x2e, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
+ 0x00, 0x00, 0x00, 0x01, 0x30, 0x30, 0x30, 0x30, 0x30, 0x01, 0x00, 0x00, 0x00, 0x00 };
+
+readonly byte BluRayOutput::MovieObject_bdmv[] = {
+ 0x4d, 0x4f, 0x42, 0x4a, 0x30, 0x31, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xea, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x03, 0x80, 0x00, 0x00, 0x04, 0x50, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
+ 0x00, 0x00, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x82,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x21, 0x81, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x0a, 0x00, 0x00, 0x00, 0x03, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
+ 0xff, 0xff, 0x48, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x22, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x0a, 0x00, 0x00, 0x00, 0x04, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x48, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x21, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x21, 0x81, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x05, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+ 0x00, 0x01, 0x50, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xff, 0xff, 0x50, 0x40,
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x21, 0x81, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+readonly byte BluRayOutput::PlayList_00000_mpls[] = { 0x4d, 0x50, 0x4c, 0x53, 0x30, 0x31, 0x30, 0x30 };
+
+readonly byte BluRayOutput::AppInfoPlayList[] = {
+ 0x00, 0x00, 0x00, 0x0e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00 };
+
+readonly byte BluRayOutput::PgStreamAttributes[] = { 0x05, 0x90, 0x65, 0x6e, 0x67, 0x00 };
+
+readonly byte BluRayOutput::ClipInfo_0000_clpi[] = { 0x48, 0x44, 0x4d, 0x56, 0x30, 0x31, 0x30, 0x30 };
+
+readonly byte BluRayOutput::TsTypeInfoBlock[] = {
+ 0x00, 0x1e, 0x80, 0x48, 0x44, 0x4d, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+BluRayOutput::BluRayOutput(std::string arg_path, TimeSpan arg_chapterLen)
+{
+ path = arg_path;
+ chapterLen = arg_chapterLen;
+ boost::filesystem::path full_path(boost::filesystem::initial_path<boost::filesystem::path>());
+ if(boost::filesystem::exists(full_path))
+ boost::filesystem::remove(full_path);
+ boost::filesystem::create_directory(full_path);
+ boost::filesystem::create_directory(full_path / "BDMV");
+ boost::filesystem::create_directory(full_path / "BDMV" / "AUXDATA");
+ boost::filesystem::create_directory(full_path / "BDMV" / "BACKUP");
+ boost::filesystem::create_directory(full_path / "BDMV" / "BACKUP" / "BDJO");
+ boost::filesystem::create_directory(full_path / "BDMV" / "BACKUP" / "CLIPINF");
+ boost::filesystem::create_directory(full_path / "BDMV" / "BACKUP" / "PLAYLIST");
+ boost::filesystem::create_directory(full_path / "BDMV" / "BDJO");
+ boost::filesystem::create_directory(full_path / "BDMV" / "CLIPINF");
+ boost::filesystem::create_directory(full_path / "BDMV" / "JAR");
+ boost::filesystem::create_directory(full_path / "BDMV" / "META");
+ boost::filesystem::create_directory(full_path / "BDMV" / "PLAYLIST");
+ boost::filesystem::create_directory(full_path / "BDMV" / "STREAM");
+ boost::filesystem::create_directory(full_path / "CERTIFICATE");
+ boost::filesystem::create_directory(full_path / "CERTIFICATE" / "BACKUP");
+
+ boost::filesystem::ofstream file_index_bdmv(full_path / "BDMV/index.bdmv");
+ file_index_bdmv << index_bdmv;
+ boost::filesystem::ofstream file_index_bdmv_backup(full_path / "BDMV/BACKUP/index.bdmv");
+ file_index_bdmv_backup << index_bdmv;
+
+ boost::filesystem::ofstream file_movieobject_bdmv(full_path / "BDMV/MovieObject.bdmv");
+ file_movieobject_bdmv << MovieObject_bdmv;
+ boost::filesystem::ofstream file_movieobject_bdmv_backup(full_path / "BDMV/BACKUP/MovieObject.bdmv");
+ file_movieobject_bdmv_backup << MovieObject_bdmv;
+}
+
+/** not modefied
+void BluRayOutput::Author(EpElement* EpInfo, StreamInfo* sis, UInt32 numOfSourcePackets)
+{
+ List<ushort> Pids = new List<ushort>();
+ List<byte[]> StreamCodingInfos = new List<byte[]>();
+ List<byte[]> AudioEntries = new List<byte[]>();
+ List<byte[]> AudioAttributes = new List<byte[]>();
+ List<byte[]> PgEntries = new List<byte[]>();
+ List<byte[]> PgAttributes = new List<byte[]>();
+ byte[] VideoEntry = null;
+ byte[] VideoAttribute = null;
+ ElementaryStreamTypes VideoType = ElementaryStreamTypes.INVALID;
+ foreach(StreamInfo si in sis)
+ {
+ switch (si.StreamType)
+ {
+ case ElementaryStreamTypes.AUDIO_STREAM_AC3:
+ case ElementaryStreamTypes.AUDIO_STREAM_AC3_PLUS:
+ case ElementaryStreamTypes.AUDIO_STREAM_AC3_TRUE_HD:
+ case ElementaryStreamTypes.AUDIO_STREAM_DTS:
+ case ElementaryStreamTypes.AUDIO_STREAM_DTS_HD:
+ case ElementaryStreamTypes.AUDIO_STREAM_DTS_HD_MASTER_AUDIO:
+ case ElementaryStreamTypes.AUDIO_STREAM_LPCM:
+ case ElementaryStreamTypes.AUDIO_STREAM_MPEG1:
+ case ElementaryStreamTypes.AUDIO_STREAM_MPEG2:
+ byte[] AudioEntry = BuildStreamEntry(si.ElementaryPID);
+ byte[] AudioAttribute = BuildAudioStreamAttributes((byte)si.StreamType,si.AudioPresentationType,si.SamplingFrequency);
+ AudioEntries.Add(AudioEntry);
+ AudioAttributes.Add(AudioAttribute);
+ byte[] AudioCodingInfo = BuildAudioStreamCodingInfo(si.StreamType, si.AudioPresentationType, si.SamplingFrequency);
+ Pids.Add(si.ElementaryPID);
+ StreamCodingInfos.Add(AudioCodingInfo);
+ break;
+ case ElementaryStreamTypes.VIDEO_STREAM_H264:
+ case ElementaryStreamTypes.VIDEO_STREAM_MPEG1:
+ case ElementaryStreamTypes.VIDEO_STREAM_MPEG2:
+ case ElementaryStreamTypes.VIDEO_STREAM_VC1:
+ VideoType = si.StreamType;
+ VideoEntry = BuildStreamEntry(si.ElementaryPID);
+ VideoAttribute = BuildVideoStreamAttributes((byte)si.StreamType,si.VideoFormat,si.FrameRate);
+ byte[] VideoCodingInfo = BuildVideoStreamCodingInfo(si.StreamType, si.VideoFormat, si.FrameRate, si.AspectRatio);
+ Pids.Add(si.ElementaryPID);
+ StreamCodingInfos.Add(VideoCodingInfo);
+ break;
+ case ElementaryStreamTypes.PRESENTATION_GRAPHICS_STREAM:
+ byte[] PgEntry = BuildStreamEntry(si.ElementaryPID);
+ PgEntries.Add(PgEntry);
+ PgAttributes.Add(PgStreamAttributes);
+ byte[] PgCodingInfo = BuildPgStreamCodingInfo();
+ Pids.Add(si.ElementaryPID);
+ StreamCodingInfos.Add(PgCodingInfo);
+ break;
+ }
+ }
+ byte[][] PlayItems = new byte[1][];
+ UInt32 Start = (UInt32)((EpInfo[0].PTS >> 1) & 0xffffffff);
+ UInt32 End = (UInt32)((EpInfo[EpInfo.Length - 1].PTS >> 1) & 0xffffffff);
+ UInt32 Interval = ((UInt32)(chapterLen.TotalMinutes)) * 2700000;
+ byte[] StnTable = BuildStnTable(VideoEntry, VideoAttribute, AudioEntries.ToArray(), AudioAttributes.ToArray(), PgEntries.ToArray(), PgAttributes.ToArray());
+ PlayItems[0] = BuildFirstPlayItem(0, Start, End, StnTable);
+ byte[] PlayList = BuildPlayList(PlayItems);
+ byte[] PlayListMark = BuildFirstPlayMarks(Start, End, Interval);
+ byte[] mlps = Build_mlps(PlayList, PlayListMark);
+ File.WriteAllBytes(Path.Combine(path, @"BDMV\PLAYLIST\00000.mpls"), mlps);
+ File.Copy(Path.Combine(path, @"BDMV\PLAYLIST\00000.mpls"), Path.Combine(path, @"BDMV\BACKUP\PLAYLIST\00000.mpls"),true);
+
+ byte[] ClipInfo = BuildClipInfo(numOfSourcePackets,EpInfo);
+ byte[] SequenceInfo = BuildSequenceInfo(Start, End);
+ byte[] ProgramInf = BuildProgramInfo(Pids.ToArray(), StreamCodingInfos.ToArray());
+ byte[] EpMap = BuildEpMap(EpInfo);
+ byte[] CPI = BuildCpi(EpMap);
+ byte[] clpi = Build_clpi(ClipInfo, SequenceInfo, ProgramInf, CPI);
+ File.WriteAllBytes(Path.Combine(path, @"BDMV\CLIPINF\00001.clpi"), clpi);
+ File.Copy(Path.Combine(path, @"BDMV\CLIPINF\00001.clpi"), Path.Combine(path, @"BDMV\BACKUP\CLIPINF\00001.clpi"),true);
+}
+**/
+
+pByte BluRayOutput::BuildStreamEntry(ushort pid)
+{
+ pByte StreamEntry = pByte(new byte[10] {
+ 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
+ StreamEntry[2] = (byte)((pid >> 8) & 0xff);
+ StreamEntry[3] = (byte)(pid & 0xff);
+ return StreamEntry;
+}
+
+pByte BluRayOutput::BuildVideoStreamAttributes(byte type, VideoFormat vf, FrameRate fr)
+ throw(std::invalid_argument)
+{
+ if (type != reinterpret_cast<byte>VIDEO_STREAM_VC1
+ && type != repreinterpret_cast<byte>VIDEO_STREAM_MPEG2
+ && type != reinterpret_cast<byte>VIDEO_STREAM_H264)
+ throw std::invalid_argument("Video stream of type is not supported by Blu Ray");
+ pByte attributes = pByte(new byte[6]);
+ attributes[0] = 0x05;
+ attributes[1] = type;
+ attributes[2] = (byte)((((byte)vf) << 4) & 0xf0);
+ attributes[2] |= (byte)(((byte)fr) & 0x0f);
+ attributes[3] = attributes[4] = attributes[5] = 0;
+ return attributes;
+}
+
+pByte BluRayOutput::BuildAudioStreamAttributes(byte type, AudioPresentationType vf, SamplingFrequency fr)
+ throw(std::invalid_argument)
+{
+ if (type != reinterpret_cast<byte>AUDIO_STREAM_AC3
+ && type != reiterpret_cast<byte>AUDIO_STREAM_AC3_PLUS
+ && type != reiterpret_cast<byte>AUDIO_STREAM_AC3_TRUE_HD
+ && type != reiterpret_cast<byte>AUDIO_STREAM_DTS
+ && type != reiterpret_cast<byte>AUDIO_STREAM_DTS_HD
+ && type != reiterpret_cast<byte>AUDIO_STREAM_DTS_HD_MASTER_AUDIO
+ && type != reiterpret_cast<byte>AUDIO_STREAM_LPCM)
+ throw std::invalid_argument("Audio stream of type is not supported by Blu Ray");
+ pByte attributes = pByte(new byte[6]);
+ attributes[0] = 0x05;
+ attributes[1] = type;
+ attributes[2] = (byte)((((byte)vf) << 4) & 0xf0);
+ attributes[2] |= (byte)(((byte)fr) & 0x0f);
+ attributes[3] = 0x65;
+ attributes[4] = 0x6e;
+ attributes[5] = 0x67;
+ return attributes;
+}
+
+/** not modefied
+pByte BluRayOutput::BuildStnTable(pByte VideoEntry, pByte VideoAttributes, byte[][] AudioEntries, byte[][] AudioAttributes, byte[][] PgEntries, byte[][] PgAttributes)
+{
+ List<byte> table = new List<byte>();
+ List<byte> temp = new List<byte>();
+ table.Add(0x00);
+ table.Add(0x00);
+ table.Add(0x01);
+ if (AudioEntries.Length > 0)
+ table.Add((byte)AudioEntries.Length);
+ else
+ table.Add(0x00);
+ if (PgEntries.Length > 0)
+ table.Add((byte)PgEntries.Length);
+ else
+ table.Add(0x00);
+ for (int i = 0; i < 9; i++)
+ table.Add(0x00);
+ table.AddRange(VideoEntry);
+ table.AddRange(VideoAttributes);
+ for (int i = 0; i < AudioEntries.Length; i++)
+ {
+ table.AddRange(AudioEntries[i]);
+ table.AddRange(AudioAttributes[i]);
+ }
+ for (int i = 0; i < PgEntries.Length; i++)
+ {
+ table.AddRange(PgEntries[i]);
+ table.AddRange(PgAttributes[i]);
+ }
+ UInt32 len = (UInt32)table.Count;
+ temp.Add((byte)((len >> 8) & 0xff));
+ temp.Add((byte)(len & 0xff));
+ temp.AddRange(table);
+ return temp.ToArray();
+}
+
+pByte BluRayOutput:: UintToByteArraryNetwork(UInt32 value)
+{
+ pByte ret = pByte(new byte[4]);
+ ret[0] = reinterpret_cast<byte>((value >> 24) & 0xff);
+ ret[1] = reinterpret_cast<byte>((value >> 16) & 0xff);
+ ret[2] = reinterpret_cast<byte>((value >> 8) & 0xff);
+ ret[3] = reinterpret_cast<byte>(value & 0xff);
+ return ret;
+}
+
+pByte BluRayOutput::Build_mlps(pByte PlayList, pByte PlayListMark)
+{
+ List<byte> mlps;
+ mlps.AddRange(PlayList_00000_mpls);
+ UInt32 temp = (UInt32)AppInfoPlayList.Length;
+ temp += 40;
+ mlps.AddRange(UintToByteArraryNetwork(temp));
+ temp += (UInt32)PlayList.Length;
+ mlps.AddRange(UintToByteArraryNetwork(temp));
+ for (int i = 0; i < 24; i++)
+ mlps.Add(0x00);
+ mlps.AddRange(AppInfoPlayList);
+ mlps.AddRange(PlayList);
+ mlps.AddRange(PlayListMark);
+ return mlps.ToArray();
+}
+
+pByte BluRayOutput::BuildPlayList(byte[][] PlayItems)
+{
+ std::List<byte> playList;
+ UInt32 playItemNum = sizeof(PlayItems);
+ playItemNum <<= 16;
+ playItemNum &= 0xffff0000;
+ UInt32 len = sizeof(PlayItems) + 6;
+ playList.AddRange(UintToByteArraryNetwork(len));
+ playList.push_back(0x00);
+ playList.push_back(0x00);
+ playList.AddRange(UintToByteArraryNetwork(playItemNum));
+ for (int i = 0; i < PlayItems.Length; i++)
+ playList.AddRange(PlayItems[i]);
+ return playList.ToArray();
+}
+
+byte[] BuildFirstPlayItem(byte stc_id, UInt32 start, UInt32 end, byte[] StnTable)
+{
+ List<byte> playItem = new List<byte>();
+ List<byte> playTemp = new List<byte>();
+ for (int i = 0; i < 4; i++)
+ playItem.Add(0x30);
+ playItem.Add(0x31);
+ playItem.Add(0x4d);
+ playItem.Add(0x32);
+ playItem.Add(0x54);
+ playItem.Add(0x53);
+ playItem.Add(0x00);
+ playItem.Add(0x01);
+ playItem.Add(stc_id);
+ playItem.AddRange(UintToByteArraryNetwork(start));
+ playItem.AddRange(UintToByteArraryNetwork(end));
+ for (int i = 0; i < 12; i++)
+ playItem.Add(0x00);
+ playItem.AddRange(StnTable);
+ UInt32 len = (UInt32)playItem.Count;
+ playTemp.Add((byte)((len >> 8) & 0xff));
+ playTemp.Add((byte)(len & 0xff));
+ playTemp.AddRange(playItem);
+ return playTemp.ToArray();
+}
+
+byte[] BuildFirstPlayMarks(UInt32 start, UInt32 end, UInt32 interval)
+{
+ List<byte> marks = new List<byte>();
+ List<byte> temp = new List<byte>();
+ UInt32 num = 0;
+ for (UInt32 i = start; i < end; i += interval, num++)
+ {
+ marks.Add(0x00);
+ marks.Add(0x01);
+ marks.Add(0x00);
+ marks.Add(0x00);
+ UInt32 time = i;
+ marks.AddRange(UintToByteArraryNetwork(time));
+ marks.Add(0xff);
+ marks.Add(0xff);
+ time = 0;
+ marks.AddRange(UintToByteArraryNetwork(time));
+ }
+ UInt32 len = (UInt32)marks.Count;
+ len += 2;
+ temp.AddRange(UintToByteArraryNetwork(len));
+ temp.Add((byte)((num >> 8) & 0xff));
+ temp.Add((byte)(num & 0xff));
+ temp.AddRange(marks);
+ return temp.ToArray();
+}
+
+byte[] Build_clpi(byte[] ClipInfo, byte[] SequenceInfo, byte[] ProgramInfo, byte[] CPI)
+{
+ List<byte> clpi = new List<byte>();
+ clpi.AddRange(ClipInfo_0000_clpi);
+ UInt32 len = 40;
+ len += (UInt32)ClipInfo.Length;
+ clpi.AddRange(UintToByteArraryNetwork(len));
+ len += (UInt32)SequenceInfo.Length;
+ clpi.AddRange(UintToByteArraryNetwork(len));
+ len += (UInt32)ProgramInfo.Length;
+ clpi.AddRange(UintToByteArraryNetwork(len));
+ len += (UInt32)CPI.Length;
+ clpi.AddRange(UintToByteArraryNetwork(len));
+ for (int i = 0; i < 16; i++)
+ clpi.Add(0x00);
+ clpi.AddRange(ClipInfo);
+ clpi.AddRange(SequenceInfo);
+ clpi.AddRange(ProgramInfo);
+ clpi.AddRange(CPI);
+ clpi.AddRange(UintToByteArraryNetwork(0x00000000));
+ return clpi.ToArray();
+}
+
+byte[] BuildClipInfo(UInt32 numOfSourcePackets, EpElement[] EpInfo)
+{
+ List<byte> clip = new List<byte>();
+ List<byte> temp = new List<byte>();
+
+ clip.Add(0x00);
+ clip.Add(0x00);
+ clip.Add(0x01);
+ clip.Add(0x01);
+ clip.Add(0x00);
+ clip.Add(0x00);
+ clip.Add(0x00);
+ clip.Add(0x00);
+ Int64 rate = EpInfo[EpInfo.Length - 1].SPN - EpInfo[0].SPN;
+ rate *= 192;
+ rate /= ((EpInfo[EpInfo.Length - 1].PTS - EpInfo[0].PTS) / 90000);
+ clip.AddRange(UintToByteArraryNetwork((UInt32)rate));
+ clip.AddRange(UintToByteArraryNetwork(numOfSourcePackets));
+ for (int i = 0; i < 128; i++)
+ clip.Add(0x00);
+ clip.AddRange(TsTypeInfoBlock);
+ UInt32 len = (UInt32)clip.Count;
+ temp.AddRange(UintToByteArraryNetwork(len));
+ temp.AddRange(clip);
+ return temp.ToArray();
+}
+
+byte[] BuildSequenceInfo(UInt32 start, UInt32 end)
+{
+ List<byte> seq = new List<byte>();
+ List<byte> temp = new List<byte>();
+
+ seq.Add(0x00);
+ seq.Add(0x01);
+ seq.Add(0x00);
+ seq.Add(0x00);
+ seq.Add(0x00);
+ seq.Add(0x00);
+ seq.Add(0x01);
+ seq.Add(0x00);
+ seq.Add((byte)((Constants.DEFAULT_PCR_PID >> 8) & 0xff));
+ seq.Add((byte)(Constants.DEFAULT_PCR_PID & 0xff));
+ seq.Add(0x00);
+ seq.Add(0x00);
+ seq.Add(0x00);
+ seq.Add(0x00);
+ seq.AddRange(UintToByteArraryNetwork(start));
+ seq.AddRange(UintToByteArraryNetwork(end));
+ UInt32 len = (UInt32)seq.Count;
+ temp.AddRange(UintToByteArraryNetwork(len));
+ temp.AddRange(seq);
+ return temp.ToArray();
+}
+
+byte[] BuildProgramInfo(ushort[] pids, byte[][] StreamCodingInfos)
+{
+ List<byte> info = new List<byte>();
+ List<byte> temp = new List<byte>();
+ info.Add(0x00);
+ info.Add(0x01);
+ info.Add(0x00);
+ info.Add(0x00);
+ info.Add(0x00);
+ info.Add(0x00);
+ info.Add((byte)((Constants.DEFAULT_PMT_PID >> 8) & 0xff));
+ info.Add((byte)(Constants.DEFAULT_PMT_PID & 0xff));
+ info.Add((byte)pids.Length);
+ info.Add(0x00);
+ for (int i = 0; i < pids.Length; i++)
+ {
+ info.Add((byte)((pids[i] >> 8) & 0xff));
+ info.Add((byte)(pids[i] & 0xff));
+ info.AddRange(StreamCodingInfos[i]);
+ }
+
+ UInt32 len = (UInt32)info.Count;
+ temp.AddRange(UintToByteArraryNetwork(len));
+ temp.AddRange(info);
+ return temp.ToArray();
+}
+
+byte[] BuildVideoStreamCodingInfo(ElementaryStreamTypes type, VideoFormat format, FrameRate rate, AspectRatio ratio)
+{
+ List<byte> info = new List<byte>();
+ info.Add(0x15);
+ info.Add((byte)type);
+ info.Add((byte)((((byte)format) << 4) | (byte)rate));
+ info.Add((byte)(((byte)(ratio)) << 4));
+ for(int i = 0; i < 18; i++)
+ info.Add(0x00);
+ return info.ToArray();
+}
+
+byte[] BuildAudioStreamCodingInfo(ElementaryStreamTypes type, AudioPresentationType format, SamplingFrequency rate)
+{
+ List<byte> info = new List<byte>();
+ info.Add(0x15);
+ info.Add((byte)type);
+ info.Add((byte)((((byte)format) << 4) | (byte)rate));
+ info.Add(0x65);
+ info.Add(0x6e);
+ info.Add(0x67);
+ for (int i = 0; i < 16; i++)
+ info.Add(0x00);
+ return info.ToArray();
+}
+
+byte[] BuildPgStreamCodingInfo()
+{
+ List<byte> info = new List<byte>();
+ info.Add(0x15);
+ info.Add(0x90);
+ info.Add(0x65);
+ info.Add(0x6e);
+ info.Add(0x67);
+ for (int i = 0; i < 17; i++)
+ info.Add(0x00);
+ return info.ToArray();
+}
+
+byte[] BuildCpi(byte[] EpMap)
+{
+ List<byte> info = new List<byte>();
+ UInt32 len = (UInt32)EpMap.Length + 2;
+ info.AddRange(UintToByteArraryNetwork(len));
+ info.Add(0x00);
+ info.Add(0x01);
+ info.AddRange(EpMap);
+ return info.ToArray();
+}
+
+byte[] BuildEpMap(EpElement[] EpInfo)
+{
+ UInt32 lastepfine = 0x7ff;
+ UInt32 lastspnfine = 0x1ffff;
+ UInt32 numofcoarse = 0;
+ List<byte> coarseloop = new List<byte>();
+ List<byte> fineloop = new List<byte>(EpInfo.Length);
+ List<byte> EpMap = new List<byte>();
+
+ for (int i = 0; i < EpInfo.Length; i++)
+ {
+ UInt32 epfine = (UInt32)((EpInfo[i].PTS >> 9) % 0x800);
+ UInt32 epcoarse = (UInt32)((EpInfo[i].PTS >> 19) % 0x4000);
+ UInt32 spnfine = EpInfo[i].SPN % 0x20000;
+ if (lastepfine > epfine || lastspnfine > spnfine)
+ {
+ UInt32 reftofine = (UInt32)i;
+ reftofine <<= 14;
+ reftofine |= epcoarse;
+ coarseloop.AddRange(UintToByteArraryNetwork(reftofine));
+ coarseloop.AddRange(UintToByteArraryNetwork(EpInfo[i].SPN));
+ numofcoarse++;
+ }
+ UInt32 value = 0x1000;
+ value |= (epfine << 17);
+ value |= spnfine;
+ fineloop.AddRange(UintToByteArraryNetwork(value));
+ lastepfine = epfine;
+ lastspnfine = spnfine;
+ }
+
+ EpMap.Add(0x00);
+ EpMap.Add(0x01);
+ EpMap.Add((byte)((Constants.DEFAULT_VIDEO_PID >> 8) & 0xff));
+ EpMap.Add((byte)(Constants.DEFAULT_VIDEO_PID & 0xff));
+ EpMap.Add(0x00);
+ byte btemp = 4;
+ btemp |= (byte)((numofcoarse >> 14) & 0xff);
+ EpMap.Add(btemp);
+ btemp = (byte)((numofcoarse >> 6) & 0xff);
+ EpMap.Add(btemp);
+ btemp = (byte)((numofcoarse & 0x3f) << 2);
+ btemp |= (byte)((EpInfo.Length >> 16) & 0x03);
+ EpMap.Add(btemp);
+ btemp = (byte)((EpInfo.Length >> 8) & 0xff);
+ EpMap.Add(btemp);
+ btemp = (byte)(EpInfo.Length& 0xff);
+ EpMap.Add(btemp);
+ UInt32 count = 4 + (UInt32)EpMap.Count;
+ EpMap.AddRange(UintToByteArraryNetwork(count));
+ UInt32 start = 4 + (UInt32)coarseloop.Count;
+ EpMap.AddRange(UintToByteArraryNetwork(start));
+ EpMap.AddRange(coarseloop);
+ EpMap.AddRange(fineloop);
+ return EpMap.ToArray();
+ }
+}
+**/
+
+
} // namespace