From: cocot Date: Sat, 14 Mar 2009 08:31:21 +0000 (+0900) Subject: implement BlureayOutput class in Utils X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;ds=sidebyside;h=8a771baf7488b145a6141e86c4e34bf791500ed9;p=tsremuxcpp%2Fdeveloping01.git implement BlureayOutput class in Utils --- diff --git a/src/Utils.cc b/src/Utils.cc old mode 100644 new mode 100755 index 2c530e0..db62f8f --- a/src/Utils.cc +++ b/src/Utils.cc @@ -2329,6 +2329,579 @@ void PmPacket::SetProgramDescriptorsData(pByte value) // 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()); + 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 Pids = new List(); + List StreamCodingInfos = new List(); + List AudioEntries = new List(); + List AudioAttributes = new List(); + List PgEntries = new List(); + List PgAttributes = new List(); + 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_castVIDEO_STREAM_VC1 + && type != repreinterpret_castVIDEO_STREAM_MPEG2 + && type != reinterpret_castVIDEO_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_castAUDIO_STREAM_AC3 + && type != reiterpret_castAUDIO_STREAM_AC3_PLUS + && type != reiterpret_castAUDIO_STREAM_AC3_TRUE_HD + && type != reiterpret_castAUDIO_STREAM_DTS + && type != reiterpret_castAUDIO_STREAM_DTS_HD + && type != reiterpret_castAUDIO_STREAM_DTS_HD_MASTER_AUDIO + && type != reiterpret_castAUDIO_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 table = new List(); + List temp = new List(); + 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((value >> 24) & 0xff); + ret[1] = reinterpret_cast((value >> 16) & 0xff); + ret[2] = reinterpret_cast((value >> 8) & 0xff); + ret[3] = reinterpret_cast(value & 0xff); + return ret; +} + +pByte BluRayOutput::Build_mlps(pByte PlayList, pByte PlayListMark) +{ + List 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 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 playItem = new List(); + List playTemp = new List(); + 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 marks = new List(); + List temp = new List(); + 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 clpi = new List(); + 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 clip = new List(); + List temp = new List(); + + 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 seq = new List(); + List temp = new List(); + + 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 info = new List(); + List temp = new List(); + 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 info = new List(); + 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 info = new List(); + 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 info = new List(); + 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 info = new List(); + 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 coarseloop = new List(); + List fineloop = new List(EpInfo.Length); + List EpMap = new List(); + + 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 diff --git a/src/Utils.h b/src/Utils.h old mode 100644 new mode 100755 index 5bf27ee..47021ba --- a/src/Utils.h +++ b/src/Utils.h @@ -1,12 +1,13 @@ #ifndef TSREMUXCPP_UTILS_H_ #define TSREMUXCPP_UTILS_H_ -#include +#include +#include #include #include #include #include -// #include "BlueMux.h" +#include #include "tsremuxcpp_define.h" namespace TsRemux { @@ -143,6 +144,13 @@ class StreamInfo { class BluRayOutput { public: + static readonly byte index_bdmv[]; + static readonly byte MovieObject_bdmv[]; + static readonly byte PlayList_00000_mpls[]; + static readonly byte AppInfoPlayList[]; + static readonly byte PgStreamAttributes[]; + static readonly byte ClipInfo_0000_clpi[]; + static readonly byte TsTypeInfoBlock[]; BluRayOutput(std::string path, TimeSpan chapterLen); void Author(EpElement* EpInfo, StreamInfo* sis, UInt32 numOfSourcePackets); pByte BuildPlayList(byte* PlayItems); @@ -171,6 +179,8 @@ class BluRayOutput { byte* PgEntries, byte* PgAttributes); pByte UintToByteArraryNetwork(UInt32 value); pByte Build_mlps(byte* PlayList, byte* PlayListMark); + std::string path; + TimeSpan chapterLen; }; class Descriptor { diff --git a/src/tsremuxcpp_define.h b/src/tsremuxcpp_define.h index 4c2dc81..3023b2c 100644 --- a/src/tsremuxcpp_define.h +++ b/src/tsremuxcpp_define.h @@ -1,10 +1,11 @@ #ifndef TSREMUXCPP_DEFINE_H_ #define TSREMUXCPP_DEFINE_H_ +#include #include #include #include -#include +#include #define readonly const @@ -16,9 +17,7 @@ namespace TsRemux { typedef signed int Int32; typedef unsigned long long UInt64; typedef signed long long Int64; - typedef time_t TimeSpan; + typedef boost::posix_time::time_duration TimeSpan; typedef boost::shared_array pByte; -// typedef std::vector Bytes; -// typedef std::vector::iterator Iter; } // namespace #endif TSREMUXCPP_DEFINE_H_