1 #ifndef TSREMUXCPP_UTILS_H_
2 #define TSREMUXCPP_UTILS_H_
7 // #include "BlueMux.h"
8 #include "tsremuxcpp_define.h"
30 enum ElementaryStreamTypes {
32 VIDEO_STREAM_MPEG1 = 0x01,
33 VIDEO_STREAM_MPEG2 = 0x02,
34 AUDIO_STREAM_MPEG1 = 0x03, // all layers including mp3
35 AUDIO_STREAM_MPEG2 = 0x04,
36 VIDEO_STREAM_H264 = 0x1b,
37 AUDIO_STREAM_LPCM = 0x80,
38 AUDIO_STREAM_AC3 = 0x81,
39 AUDIO_STREAM_DTS = 0x82,
40 AUDIO_STREAM_AC3_TRUE_HD = 0x83,
41 AUDIO_STREAM_AC3_PLUS = 0x84,
42 AUDIO_STREAM_DTS_HD = 0x85,
43 AUDIO_STREAM_DTS_HD_MASTER_AUDIO = 0x86,
44 PRESENTATION_GRAPHICS_STREAM = 0x90,
45 INTERACTIVE_GRAPHICS_STREAM = 0x91,
46 SUBTITLE_STREAM = 0x92,
47 SECONDARY_AUDIO_AC3_PLUS = 0xa1,
48 SECONDARY_AUDIO_DTS_HD = 0xa2,
49 VIDEO_STREAM_VC1 = 0xea
79 enum AudioPresentationType {
87 enum SamplingFrequency {
98 signed long long pts_;
100 EpElement(signed long long pts, unsigned long spn);
105 StreamInfo(byte* data, int index)throw(std::invalid_argument);
106 VideoFormat GetVideoFormat(void);
107 void SetVideoFormat(VideoFormat videoformat);
108 AspectRatio GetAspectRatio(void);
109 void SetAspectRatio(AspectRatio aspectratio);
110 FrameRate GetFrameRate(void);
111 void SetFrameRate(FrameRate frameRate);
112 AudioPresentationType GetAudioPresentationType(void);
113 void SetAudioPresentationType(AudioPresentationType audioPresentationTyp);
114 SamplingFrequency GetSamplingFrequency(void);
115 void SetSamplingFrequency(SamplingFrequency samplingFrequency);
116 StreamInfo(ElementaryStreamTypes streamType, ushort elementaryPid);
117 byte* GetByteData(void);
118 ElementaryStreamTypes GetElementaryStreamTypes(void);
119 void SetElementaryStreamTypes(ElementaryStreamTypes stream_type);
120 ushort GetElementaryPID(void);
121 void GetElementaryPID(ushort pid);
122 byte* GetElementaryDescriptors(void);
123 void SetElementaryDescriptors(byte* value)throw(std::invalid_argument);
126 VideoFormat mVideoFormat;
127 AspectRatio mAspectRatio;
128 FrameRate mFrameRate;
129 AudioPresentationType mAudioPresentationType;
130 SamplingFrequency mSamplingFrequency;
131 ElementaryStreamTypes StreamType;
132 ushort ElementaryPID;
133 byte* ElementaryDescriptors;
138 BluRayOutput(std::string path, TimeSpan chapterLen);
139 void Author(EpElement* EpInfo, StreamInfo* sis, UInt32 numOfSourcePackets);
140 byte* BuildPlayList(byte* PlayItems);
141 byte* BuildFirstPlayItem(byte stc_id, UInt32 start,
142 UInt32 end, byte* StnTable);
143 byte* BuildFirstPlayMarks(UInt32 start, UInt32 end, UInt32 interval);
144 byte* Build_clpi(byte* ClipInfo, byte* SequenceInfo,
145 byte* ProgramInfo, byte* CPI);
146 byte* BuildClipInfo(UInt32 numOfSourcePackets, EpElement* EpInfo);
147 byte* BuildSequenceInfo(UInt32 start, UInt32 end);
148 byte* BuildProgramInfo(ushort pids, byte* StreamCodingInfos);
149 byte* BuildVideoStreamCodingInfo(ElementaryStreamTypes type,
150 VideoFormat format, FrameRate rate, AspectRatio ratio);
151 byte* BuildAudioStreamCodingInfo(ElementaryStreamTypes type,
152 AudioPresentationType format, SamplingFrequency rate);
153 byte* BuildPgStreamCodingInfo(void);
154 byte* BuildCpi(byte* EpMap);
155 byte* BuildEpMap(EpElement* EpInfo);
157 byte* BuildStreamEntry(ushort pid);
158 byte* BuildVideoStreamAttributes(byte type, VideoFormat vf, FrameRate fr);
159 byte* BuildAudioStreamAttributes(byte type, AudioPresentationType vf,
160 SamplingFrequency fr);
161 byte* BuildStnTable(byte* VideoEntry, byte* VideoAttributes,
162 byte* AudioEntries, byte* AudioAttributes,
163 byte* PgEntries, byte* PgAttributes);
164 byte* UintToByteArraryNetwork(UInt32 value);
165 byte* Build_mlps(byte* PlayList, byte* PlayListMark);
170 Descriptor(byte* data, int startIndex);
173 class DTCP_Descriptor : Descriptor {
175 DTCP_Descriptor(byte* data, int startIndex);
180 static const int TS_PAYLOAD_SIZE;
181 static const int TS_SIZE;
182 static const int STRIDE_SIZE;
183 static const int DISK_BUFFER;
184 static const byte SYNC_BYTE;
185 static const byte PAT_PID;
186 static const byte SIT_PID;
187 static const byte PAT_TABLE_ID;
188 static const byte PMT_TABLE_ID;
189 static const byte DTCP_DESCRIPTOR_TAG;
190 static const byte PACK_ID;
191 static const byte SYS_ID;
192 static const byte MAP_ID;
193 static const byte DIR_ID;
194 static const byte PAD_ID;
197 static const ushort DEFAULT_PMT_PID;
198 static const ushort DEFAULT_VIDEO_PID;
199 static const ushort MAX_VIDEO_PID;
200 static const ushort DEFAULT_AUDIO_PID;
201 static const ushort MAX_AUDIO_PID;
202 static const ushort DEFAULT_PCR_PID;
203 static const ushort DEFAULT_SUBTITLE_PID;
204 static const ushort DEFAULT_PRESENTATION_GRAPHICS_PID;
205 static const ushort DEFAULT_INTERACTIVE_GRAPHICS_PID;
206 static const ushort DEFAULT_PROGRAM_NUMBER;
207 static const int MAX_BUFFER_COUNT;
208 static const int MIN_BUFFER_COUNT;
209 static const Int64 AUDIO_DELAY;
210 static const UInt32 MKVCLUSTER_START;
211 static const UInt32 MKVFILE_START;
212 static const UInt32 MKVSEGMENT_START;
213 static const UInt32 MKVTRACKINFO_START;
214 static const byte MKVTIMECODE_START;
217 static const byte PES_VIDEO;
218 static const byte PES_AUDIO_MPEG;
219 static const byte PES_PRIVATE1;
220 static const byte PES_PADDING;
221 static const byte PES_PRIVATE2;
222 static const byte PES_VIDEO_VC1;
223 static const byte PES_PRIVATE_AC3;
224 static const byte PES_PRIVATE_AC3_PLUS;
225 static const byte PES_PRIVATE_DTS_HD;
226 static const byte PES_PRIVATE_LPCM;
227 static const byte PES_PRIVATE_AC3_TRUE_HD;
228 static const UInt32 VC1_SEQ_SC;
229 static const UInt32 VC1_END_OF_STREAM;
230 static const ushort AC3_SYNC;
231 static const UInt32 H264_PREFIX;
232 static const UInt32 H264_END_OF_STREAM;
233 static const UInt32 DTS_SYNC;
234 static const UInt32 DTS_EXT_SYNC;
235 static const UInt32 MLP_SYNC;
236 static const UInt32 MPEG2_SEQ_CODE;
237 static const UInt32 MPEG2_SEQ_EXT;
238 static const UInt32 MPEG2_SEQ_END;
241 static const Int64 MPEG2TS_CLOCK_RATE;
242 static const Int64 MAX_MPEG2TS_CLOCK;
243 static const Int64 MAX_BLURAY_CLOCK;
244 static const Int64 MAX_FIREWIRE_CLOCK;
245 static const Int64 MAX_PTS_CLOCK;
246 static const Int64 PTS_CLOCK_RATE;
247 static const int MAX_OFFSET;
248 static const int MAX_COUNT;
251 static readonly byte hdmv_registration_descriptor[];
252 static readonly byte copy_control_descriptor[];
253 static readonly byte vc1_descriptor[];
254 static readonly byte ac3_registration_descriptor[];
255 static readonly byte DefaultSitTableOne[];
256 static readonly uint crc_table[];
257 static uint ComputeCrc(byte* data);
258 static uint ComputeCrc(byte* data, int length);
259 static uint ComputeCrc(byte* data, int length, int startIndex);
264 ProgramInfo(byte* data, int index);
265 ProgramInfo(ushort programNumber, ushort programPid);
266 ushort ProgramNumber;
276 bool GetPriority(void);
277 void SetPriority(bool priority);
279 void SetPID(ushort pid);
280 byte GetPointerSize(void);
282 void SetData(byte* data, int startIndex)throw(std::invalid_argument);
284 Int64 GetPcr(void)throw(std::out_of_range);
286 void IncrementContinuityCounter(void);
287 byte GetContinuityCounter(void);
288 void SetContinuityCounter(byte value)throw(std::out_of_range);
289 bool HasPesHeader(void);
297 class PcrPacket : TsPacket {
299 PcrPacket(Int64 pcr, byte counter, ushort pid);
302 class TsTable : TsPacket {
306 void AddData(byte* data, int offset, int len);
308 byte GetTableId(void);
309 void SetTableId(byte value);
310 ushort GetNumberId(void);
311 void SetNumberId(ushort value);
312 ushort GetLength(void);
313 void SetLength(ushort value);
315 void RefreshCrc(void);
318 class PatPacket : TsTable {
321 PatPacket(byte* data);
322 ushort TransportStreamId;
323 ProgramInfo* Programs;
325 ushort ProgramInfoLength;
328 class SitPacket : TsTable {
331 SitPacket(byte* data);
334 class PmPacket : TsTable {
337 PmPacket(byte* data);
338 DTCP_Descriptor DtcpInfo;
339 byte* ProgramDescriptorsData;
340 StreamInfo* ElementaryStreams;
341 ushort ProgramNumber;
344 ushort ProgramDescriptorsLength;
345 ushort StreamInfoLength;
350 PesHeader(byte* data);
353 void SetByte(byte dat);
355 int TotalHeaderLength;
369 PesPacket(byte* buff, int offset, int length, ushort pid);
372 byte* GetPayload(void);
374 void SetByte(byte dat);
377 PesHeader GetHeader(void);
378 void AddData(std::list<byte> moredata);
379 void AddData(byte* buff, int offset, int length);
384 std::list<byte> data;
389 class VC1SequenceInfo {
391 VC1SequenceInfo(byte* data, int offset);
393 VideoFormat GetVideoFormati(void);
394 void SetVideoFormat(VideoFormat videoformat);
395 AspectRatio GetAspectRatio(void);
396 void SetAspectRatio(AspectRatio aspectratio);
397 FrameRate GetFrameRate(void);
398 void SetFrameRate(FrameRate frameRate);
408 bool FrameRateIndicatorFlag;
409 AspectRatio mAspectRatio;
410 VideoFormat mVideoFormat;
411 FrameRate mFrameRate;
416 H264Info(byte* data, int offset);
417 byte* ElementaryDescriptors;
418 VideoFormat GetVideoFormati(void);
419 void SetVideoFormat(VideoFormat videoformat);
420 AspectRatio GetAspectRatio(void);
421 void SetAspectRatio(AspectRatio aspectratio);
422 FrameRate GetFrameRate(void);
423 void SetFrameRate(FrameRate frameRate);
424 AudioPresentationType GetAudioPresentationType(void);
425 void SetAudioPresentationType(AudioPresentationType audioPresentationTyp);
426 SamplingFrequency GetsamplingFrequency(void);
427 void SetSamplingFrequency(SamplingFrequency samplingFrequency);
429 UInt32 GetNextExpGolomb();
430 void ScalingListSkip(int skip);
433 byte* HdmvVideoRegistrationDescriptor;
434 VideoFormat mVideoFormat;
435 AspectRatio mAspectRatio;
436 FrameRate mFrameRate;
437 AudioPresentationType mAudioPresentationType;
438 SamplingFrequency mSamplingFrequency;
448 class ElementaryParse {
450 ElementaryParse(void);
451 virtual VideoFormat GetVideoFormati(void);
452 virtual void SetVideoFormat(VideoFormat videoformat);
453 virtual AspectRatio GetAspectRatio(void);
454 virtual void SetAspectRatio(AspectRatio aspectratio);
455 virtual FrameRate GetFrameRate(void);
456 virtual void SetFrameRate(FrameRate frameRate);
457 virtual AudioPresentationType GetAudioPresentationType(void);
458 virtual void SetAudioPresentationType(
459 AudioPresentationType audioPresentationTyp);
460 virtual SamplingFrequency GetsamplingFrequency(void);
461 virtual void SetSamplingFrequency(SamplingFrequency samplingFrequency);
462 virtual byte* GetElementaryDescriptors(void);
464 byte GetNextBit(void);
468 VideoFormat mVideoFormat;
469 FrameRate mFrameRate;
470 AspectRatio mAspectRatio;
471 SamplingFrequency mSamplingFrequency;
472 AudioPresentationType mAudioPresentationType;
473 byte* ElementaryDescriptors;
476 class AC3Info : ElementaryParse {
480 bool IndependentStream;
481 Ac3SyntaxType SyntaxType;
482 AC3Info(byte* data, int offset);
483 VideoFormat GetVideoFormati(void);
484 void SetVideoFormat(VideoFormat videoformat);
485 AspectRatio GetAspectRatio(void);
486 void SetAspectRatio(AspectRatio aspectratio);
487 FrameRate GetFrameRate(void);
488 void SetFrameRate(FrameRate frameRate);
489 AudioPresentationType GetAudioPresentationType(void);
490 void SetAudioPresentationType(AudioPresentationType audioPresentationTyp);
491 SamplingFrequency GetsamplingFrequency(void);
492 void SetSamplingFrequency(SamplingFrequency samplingFrequency);
493 byte* GetElementaryDescriptors(void);
495 static readonly int* len48k;
496 static readonly int* len44k;
497 static readonly int* len32k;
503 class DtsInfo : ElementaryParse {
505 DtsInfo(byte* data, int offset);
506 VideoFormat GetVideoFormati(void);
507 void SetVideoFormat(VideoFormat videoformat);
508 AspectRatio GetAspectRatio(void);
509 void SetAspectRatio(AspectRatio aspectratio);
510 FrameRate GetFrameRate(void);
511 void SetFrameRate(FrameRate frameRate);
512 AudioPresentationType GetAudioPresentationType(void);
513 void SetAudioPresentationType( AudioPresentationType audioPresentationTyp);
514 SamplingFrequency GetsamplingFrequency(void);
515 void SetSamplingFrequency(SamplingFrequency samplingFrequency);
516 byte* GetElementaryDescriptors(void);
525 class MlpInfo : ElementaryParse {
527 MlpInfo(byte* data, int offset);
528 VideoFormat GetVideoFormati(void);
529 void SetVideoFormat(VideoFormat videoformat);
530 AspectRatio GetAspectRatio(void);
531 void SetAspectRatio(AspectRatio aspectratio);
532 FrameRate GetFrameRate(void);
533 void SetFrameRate(FrameRate frameRate);
534 AudioPresentationType GetAudioPresentationType(void);
535 void SetAudioPresentationType(AudioPresentationType audioPresentationTyp);
536 SamplingFrequency GetsamplingFrequency(void);
537 void SetSamplingFrequency(SamplingFrequency samplingFrequency);
538 byte* GetElementaryDescriptors(void);
540 byte* AC3AudioDescriptor;
544 class Mpeg2Info : ElementaryParse {
546 Mpeg2Info(byte* data, int offset);
547 VideoFormat GetVideoFormati(void);
548 void SetVideoFormat(VideoFormat videoformat);
549 AspectRatio GetAspectRatio(void);
550 void SetAspectRatio(AspectRatio aspectratio);
551 FrameRate GetFrameRate(void);
552 void SetFrameRate(FrameRate frameRate);
553 AudioPresentationType GetAudioPresentationType(void);
554 void SetAudioPresentationType(AudioPresentationType audioPresentationTyp);
555 SamplingFrequency GetsamplingFrequency(void);
556 void SetSamplingFrequency(SamplingFrequency samplingFrequency);
557 byte* GetElementaryDescriptors(void);
559 byte* Mpeg2VideoRegistrationDescriptor;
568 #endif TSREMUXCPP_UTILS_H_