From: cocot Date: Sat, 7 Mar 2009 10:16:20 +0000 (+0900) Subject: implement DtsInfo class in Utils X-Git-Url: http://git.osdn.net/view?p=tsremuxcpp%2Fdeveloping01.git;a=commitdiff_plain;h=b894ce3c22169c6e449a116771a098efdc2c886a implement DtsInfo class in Utils --- diff --git a/src/Utils.cc b/src/Utils.cc index e0c3edf..d50c717 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -1626,13 +1626,407 @@ VideoFormat AC3Info::GetVideoFormat(void) return VF_Reserved; } +// implement class DtsInfo : ElementaryParse +DtsInfo::DtsInfo(pByte data, int offset) +{ + UInt32 marker = 0xffffffff; + for(; offset < sizeof(data.get()); offset++) + { + marker = (UInt32)marker << 8; + marker &= 0xffffff00; + marker += data[offset]; + if(marker == Constants::DTS_SYNC) + break; + } + offset++; + if(offset < sizeof(data.get())) + { + // sequence header + mData = pByte(new byte[sizeof(data.get()) - offset]); + for(int i = 0; offset < sizeof(data.get()); i++, offset++) + mData[i] = data[offset]; + } + else + mData.reset(); +} + +ushort DtsInfo::GetFrameSize(void) +{ + indicator = 14; + ushort ret = 0; + for (int i = 0; i < 14; i++) + { + ret <<= 1; + ret |= GetNextBit(); + } + ret++; + return ret; +} + +byte DtsInfo::GetAmode(void) +{ + indicator = 28; + byte ret = 0; + for (int i = 0; i < 6; i++) + { + ret <<= 1; + ret |= GetNextBit(); + } + return ret; +} + +/* +byte DtsInfo::GetSamplingFrequency(void) +{ + indicator = 34; + byte ret = 0; + for (int i = 0; i < 4; i++) + { + ret <<= 1; + ret |= GetNextBit(); + } + return ret; +} +*/ + +bool DtsInfo::GetExtAudio(void) +{ + indicator = 51; + if (1 == GetNextBit()) + return true; + return false; +} + +byte DtsInfo::GetExtAudioId(void) +{ + if (false == GetExtAudio()) + return 0xff; + indicator = 48; + byte ret = 0; + for (int i = 0; i < 3; i++) + { + ret <<= 1; + ret |= GetNextBit(); + } + return ret; +} + +AudioPresentationType DtsInfo::GetAudioPresentationType(void) +{ + switch (GetAmode()) + { + case 0x00: + return mono; + case 0x01: + case 0x02: + case 0x03: + case 0x04: + return stereo; + default: + return multi; + } +} + +SamplingFrequency DtsInfo::GetSamplingFrequency(void) +{ + switch (mSamplingFrequency) + { + case 0xd: + return kHz48; + } + return SF_Reserved; +} + +pByte DtsInfo::GetElementaryDescriptors(void) +{ + // DTS registration descriptor + pByte regdesc = pByte(new byte[6]); + regdesc[0] = 0x05; + regdesc[1] = 0x04; + regdesc[2] = 0x44; + regdesc[3] = 0x54; + regdesc[4] = 0x53; + if(sizeof(mData.get()) < 0x400) + regdesc[5] = 0x31; + else if(sizeof(mData.get()) < 0x800) + regdesc[5] = 0x32; + else + regdesc[5] = 0x33; + return regdesc; +} + +AspectRatio DtsInfo::GetAspectRatio(void) +{ + return AR_Reserved; +} + +FrameRate DtsInfo::GetFrameRate(void) +{ + return FR_Reserved; +} + +VideoFormat DtsInfo::GetVideoFormat(void) +{ + return VF_Reserved; +} + +/* +// implement class Mpeg2Info : ElementaryParse +Mpeg2Info::Mpeg2Info(void) +{ + private class Mpeg2Ext : ElementaryParse + { + public Mpeg2Ext(byte[] data, int offset) + : base() + { + UInt32 marker = 0xffffffff; + for (; offset < data.Length - 1; offset++) + { + marker = (UInt32)marker << 8; + marker &= 0xffffff00; + marker += data[offset]; + if (marker == Constants.MPEG2_SEQ_EXT) + { + if((data[offset + 1] & 0xf0) == 0x10) + break; + } + } + offset++; + if (offset < data.Length) + { + // sequence header + mData = new byte[data.Length - offset]; + for (int i = 0; offset < data.Length; i++, offset++) + mData[i] = data[offset]; + } + else + mData = null; + } + + public override AspectRatio AspectRatio + { + get { throw new Exception("The method or operation is not implemented."); } + } + public override AudioPresentationType AudioPresentationType + { + get { throw new Exception("The method or operation is not implemented."); } + } + public override byte[] ElementaryDescriptors + { + get { throw new Exception("The method or operation is not implemented."); } + } + public override FrameRate FrameRate + { + get { throw new Exception("The method or operation is not implemented."); } + } + public override SamplingFrequency SamplingFrequency + { + get { throw new Exception("The method or operation is not implemented."); } + } + public override VideoFormat VideoFormat + { + get { throw new Exception("The method or operation is not implemented."); } + } + public bool Progressive + { + get + { + indicator = 12; + if (GetNextBit() == 1) + return true; + return false; + } +} + +Mpeg2Info::Mpeg2Info(pByte data, int offset) +{ + UInt32 marker = 0xffffffff; + int oldOffset = offset; + for (; offset < sizeof(data.get()); offset++) + { + marker = (UInt32)marker << 8; + marker &= 0xffffff00; + marker += data[offset]; + if (marker == Constants::MPEG2_SEQ_CODE) + break; + } + offset++; + if(offset < sizeof(data.get())) + { + // sequence header + mData = pByte(new byte[sizeof(data.get()) - offset]); + for(int i = 0; offset < sizeof(data.get()); i++, offset++) + mData[i] = data[offset]; + mpgext = new Mpeg2Ext(data, oldOffset); + } + else + mData.reset(); +} + +Mpeg2Info::~Mpeg2Info(void) +{ + delete mpgext; +} + +AspectRatio Mpeg2Info::GetAspectRatio(void) +{ + switch (GetAspect()) + { + case 0x01: + if (GetVertical() == 1080 || GetVertical() == 1088 || GetVertical() == 720) + return a16_9; + else + return a4_3; + case 0x02: + return a4_3; + case 0x03: + return a16_9; + default: + return AR_Reserved; + } +} + +FrameRate Mpeg2Info::GetFrameRate(void) +{ + switch (GetFrameRateCode()) + { + case 0x01: + return f23_976; + case 0x02: + return f24; + case 0x03: + return f25; + case 0x04: + return f29_97; + case 0x06: + return f50; + case 0x07: + return f59_94; + default: + return FR_Reserved; + } +} + +VideoFormat Mpeg2Info::GetVideoFormat(void) +{ + if (GetVertical() == 1080 || GetVertical() == 1088) + { + if(GetProgressive()) + return p1080; + else + return i1080; + } + else if (GetVertical() == 576) + { + if (GetProgressive()) + return p576; + else + return i576; + } + else if (GetVertical() == 720) + return p720; + else if (GetVertical() == 480) + { + if (GetProgressive()) + return p480; + else + return i480; + } + return VF_Reserved; +} + +pByte Mpeg2Info::GetElementaryDescriptors(void) +{ + return GetMpeg2VideoRegistrationDescriptor(); +} + +AudioPresentationType Mpeg2Info::GetAudioPresentationType(void) +{ + return AP_Reserved; +} + +SamplingFrequency Mpeg2Info::GetSamplingFrequency(void) +{ + return SF_Reserved; +} + +pByte Mpeg2Info::GetMpeg2VideoRegistrationDescriptor(void) +{ + pByte data = pByte(new byte[10]); + data[0] = 0x05; + data[1] = 0x08; + data[2] = 0x48; + data[3] = 0x44; + data[4] = 0x4d; + data[5] = 0x56; + data[6] = 0xff; + data[7] = 0x02; + data[8] = (byte)((((byte)GetVideoFormat()) << 4) | ((byte)GetFrameRate())); + data[9] = (byte)((((byte)GetAspectRatio()) << 4) | 0x0f); + return data; +} + +ushort Mpeg2Info::GetHorizontal(void) +{ + indicator = 0; + ushort ret = 0; + for (int i = 0; i < 12; i++) + { + ret <<= 1; + ret |= GetNextBit(); + } + return ret; +} + +ushort Mpeg2Info::GetVertical(void) +{ + indicator = 12; + ushort ret = 0; + for (int i = 0; i < 12; i++) + { + ret <<= 1; + ret |= GetNextBit(); + } + return ret; +} + +byte Mpeg2Info::GetAspect(void) +{ + indicator = 24; + byte ret = 0; + for (int i = 0; i < 4; i++) + { + ret <<= 1; + ret |= GetNextBit(); + } + return ret; +} + +byte Mpeg2Info::GetFrameRateCode(void) +{ + indicator = 28; + byte ret = 0; + for (int i = 0; i < 4; i++) + { + ret <<= 1; + ret |= GetNextBit(); + } + return ret; +} + +bool Mpeg2Info::GetProgressive(void) +{ + if (mpgext.mValid() && mpgext.GetProgressive()) + return true; + return false; +} +*/ + // implement class BluRayOutput // implement class SitPacket : TsTable // implement class PmPacket : TsTable // implement class H264Info : ElementaryParse -// implement class DtsInfo : ElementaryParse -// implement class Mpeg2Info : ElementaryParse } // namespace diff --git a/src/Utils.h b/src/Utils.h index 21bce7d..e541d39 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -450,7 +450,7 @@ class ElementaryParse { virtual AudioPresentationType GetAudioPresentationType(void); virtual void SetAudioPresentationType( AudioPresentationType audioPresentationTyp); - virtual SamplingFrequency GetsamplingFrequency(void); + virtual SamplingFrequency GetSamplingFrequency(void); virtual void SetSamplingFrequency(SamplingFrequency samplingFrequency); virtual pByte GetElementaryDescriptors(void); protected: @@ -478,7 +478,7 @@ class H264Info : ElementaryParse { void SetFrameRate(FrameRate frameRate); AudioPresentationType GetAudioPresentationType(void); void SetAudioPresentationType(AudioPresentationType audioPresentationTyp); - SamplingFrequency GetsamplingFrequency(void); + SamplingFrequency GetSamplingFrequency(void); void SetSamplingFrequency(SamplingFrequency samplingFrequency); private: UInt32 GetNextExpGolomb(); @@ -520,24 +520,18 @@ class AC3Info : ElementaryParse { class DtsInfo : ElementaryParse { public: + bool GetExtAudio(void); DtsInfo(pByte data, int offset); - VideoFormat GetVideoFormati(void); - void SetVideoFormat(VideoFormat videoformat); + VideoFormat GetVideoFormat(void); AspectRatio GetAspectRatio(void); - void SetAspectRatio(AspectRatio aspectratio); FrameRate GetFrameRate(void); - void SetFrameRate(FrameRate frameRate); AudioPresentationType GetAudioPresentationType(void); - void SetAudioPresentationType( AudioPresentationType audioPresentationTyp); - SamplingFrequency GetsamplingFrequency(void); - void SetSamplingFrequency(SamplingFrequency samplingFrequency); + SamplingFrequency GetSamplingFrequency(void); pByte GetElementaryDescriptors(void); - ushort FrameSize; - byte ExtAudioId; - private: - byte Amode; - byte SampleFreq; - bool ExtAudio; + ushort GetFrameSize(void); + byte GetExtAudioId(void); + byte GetAmode(void); + byte GetGetSamplingFrequency(void); }; class MlpInfo : ElementaryParse { @@ -555,25 +549,34 @@ class MlpInfo : ElementaryParse { class Mpeg2Info : ElementaryParse { public: + Mpeg2Info(void); Mpeg2Info(pByte data, int offset); - VideoFormat GetVideoFormati(void); - void SetVideoFormat(VideoFormat videoformat); + VideoFormat GetVideoFormat(void); AspectRatio GetAspectRatio(void); - void SetAspectRatio(AspectRatio aspectratio); FrameRate GetFrameRate(void); - void SetFrameRate(FrameRate frameRate); AudioPresentationType GetAudioPresentationType(void); - void SetAudioPresentationType(AudioPresentationType audioPresentationTyp); SamplingFrequency GetSamplingFrequency(void); - void SetSamplingFrequency(SamplingFrequency samplingFrequency); pByte GetElementaryDescriptors(void); + pByte GetMpeg2VideoRegistrationDescriptor(void); + ushort GetHorizontal(void); + ushort GetVertical(void); + byte GetAspect(void); + byte GetFrameRateCode(void); + bool GetProgressive(void); private: - pByte Mpeg2VideoRegistrationDescriptor; - ushort Horizontal; - ushort Vertical; - byte Aspect; - byte FrameRateCode; - bool Progressive; + class Mpeg2Ext :ElementaryParse { + public: + Mpeg2Ext(void); + Mpeg2Ext(pByte data, int offset); + AspectRatio GetAspectRatio(void); + AudioPresentationType GetAudioPresentationType(void); + pByte GetElementaryDescriptors(void); + FrameRate GetFrameRate(void); + SamplingFrequency GetSamplingFrequency(void); + VideoFormat GetVideoFormat(void); + bool GetProgressive(void); + }; + Mpeg2Ext mpgext; }; } //namespace