From: cocot Date: Sun, 1 Mar 2009 01:31:45 +0000 (+0900) Subject: implement VC1SequenceInfo class in Utils X-Git-Url: http://git.osdn.net/view?p=tsremuxcpp%2Fdeveloping01.git;a=commitdiff_plain;h=8f9f97bdff443fbb1893b5d518b0135456ec5c8e implement VC1SequenceInfo class in Utils --- diff --git a/src/Utils.cc b/src/Utils.cc index 72623d3..b33edde 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -975,13 +975,216 @@ pByte PesHeader::GetData(void) return Utility::ToArray(mData); } +VC1SequenceInfo::VC1SequenceInfo(pByte data, int offset) +{ + UInt32 marker = 0xffffffff; + for(; offset < sizeof(reinterpret_cast(data.get())); offset++) + { + marker = marker << 8; + marker &= 0xffffff00; + marker += data[offset]; + if(marker == Constants::VC1_SEQ_SC) + break; + } + offset++; + mData.clear(); + if(offset < sizeof(reinterpret_cast(data.get()))) + { + // sequence header + for(int i = 0; + offset < sizeof(reinterpret_cast(data.get())); + i++, offset++) + { + mData.push_back(data[offset]); + } + } +} + +int VC1SequenceInfo::GetHeight(void) +{ + if(!mData.empty()&& mData.size() > 4) + return ((((mData.at(3) & 0x0f) << 8) + mData.at(4)) << 1) + 2; + else + return -1; +} + +int VC1SequenceInfo::GetWidth(void) +{ + if(!mData.empty() && mData.size() > 3) + return (((mData.at(2) << 4) + ((mData.at(3) & 0xf0) >> 4)) << 1) + 2; + else + return -1; +} + +bool VC1SequenceInfo::Valid(void) +{ + return !mData.empty(); +} + +bool VC1SequenceInfo::Interlaced(void) +{ + if(!mData.empty() && mData.size() > 5) + return ((mData.at(5) & 0x40) > 0); + return false; +} + +bool VC1SequenceInfo::DisplayExt(void) +{ + if(!mData.empty() && mData.size() > 5) + return ((mData.at(5) & 0x02) > 0); + return false; +} + +bool VC1SequenceInfo::AspectFlag(void) +{ + if(DisplayExt() && mData.size() > 9) + return ((mData.at(9) & 0x10) > 0); + return false; +} + +byte VC1SequenceInfo::GetVc1AspectRatio(void) +{ + if(AspectFlag() && mData.size() > 9) + return (byte)(mData.at(9) & 0x0f); + return 0; +} + +bool VC1SequenceInfo::FrameFlag(void) +{ + if(AspectFlag()) + { + if(GetVc1AspectRatio() == 15 && mData.size() > 12) + return ((mData.at(12) & 0x80) > 0); + else if(GetVc1AspectRatio() != 15 && mData.size() > 10) + return ((mData.at(10) & 0x80) > 0); + else + return false; + } + else if(mData.size() > 9) + return ((mData.at(9) & 0x08) > 0); + else + return false; +} + +bool VC1SequenceInfo::FrameRateIndicatorFlag(void) +{ + if(FrameFlag()) + { + if(AspectFlag()) + { + if (GetVc1AspectRatio() == 15 && mData.size() > 12) + return ((mData.at(12) & 0x40) > 0); + else if (GetVc1AspectRatio() != 15 && mData.size() > 10) + return ((mData.at(10) & 0x40) > 0); + else + return false; + } + else if (mData.size() > 9) + return ((mData.at(9) & 0x04) > 0); + else + return false; + } + else + return false; +} + +AspectRatio VC1SequenceInfo::GetAspectRatio(void) +{ + if(GetVc1AspectRatio() == 1) + { + if(GetWidth() == 1920 && GetHeight() == 1080) + return a16_9; + if(GetWidth() == 1280 && GetHeight() == 720) + return a16_9; + if(GetWidth() == 640 && GetHeight() == 480) + return a4_3; + } + if(GetVc1AspectRatio() >= 2 && GetVc1AspectRatio() <= 5) + return a4_3; + if(GetVc1AspectRatio() >= 6 && GetVc1AspectRatio() <= 9) + return a16_9; + if(GetVc1AspectRatio() >= 10 && GetVc1AspectRatio() <= 11) + return a4_3; + if(GetVc1AspectRatio() >= 12 && GetVc1AspectRatio() <= 13) + return a16_9; + return AR_Reserved; +} + +VideoFormat VC1SequenceInfo::GetVideoFormat(void) +{ + if (GetHeight() == 480 && Interlaced() == true) + return i480; + else if (GetHeight() == 480 && Interlaced() == false) + return p480; + else if (GetHeight() == 576 && Interlaced() == true) + return i576; + else if (GetHeight() == 576 && Interlaced() == false) + return p576; + else if (GetHeight() == 720 && Interlaced() == false) + return p720; + else if (GetHeight() == 1080 && Interlaced() == true) + return i1080; + else if (GetHeight() == 1080 && Interlaced() == false) + return p1080; + return VF_Reserved; +} + +FrameRate VC1SequenceInfo::GetFrameRate(void) +{ + if(false == FrameFlag()) + return FR_Reserved; + if(false == FrameRateIndicatorFlag()) + { + byte FrameRateNr = 0; + byte FrameRateDr = 0; + if(AspectFlag()) + { + if(GetVc1AspectRatio() == 15 && mData.size() > 13) + { + FrameRateNr = (byte)(((mData.at(12) & 0x3f) << 2) + + ((mData.at(13) & 0xc0) >> 6)); + FrameRateDr = (byte)((mData.at(13) & 0x3c) >> 2); + } + else if(GetVc1AspectRatio() != 15 && mData.size() > 11) + { + FrameRateNr = (byte)(((mData.at(10) & 0x3f) << 2) + + ((mData.at(11) & 0xc0) >> 6)); + FrameRateDr = (byte)((mData.at(11) & 0x3c) >> 2); + } + } + else if(mData.size() > 11) + { + FrameRateNr = (byte)(((mData.at(9) & 0x03) << 6) + + ((mData.at(10) & 0xfc) >> 2)); + FrameRateDr = (byte)(((mData.at(10) & 0x03) << 2) + + ((mData[11] & 0xc0) >> 6)); + } + + if(FrameRateNr == 1 && FrameRateDr == 2) + return f23_976; + else if(FrameRateNr == 1 && FrameRateDr == 1) + return f24; + else if(FrameRateNr == 2 && FrameRateDr == 1) + return f25; + else if(FrameRateNr == 3 && FrameRateDr == 2) + return f29_97; + else if(FrameRateNr == 4 && FrameRateDr == 1) + return f50; + else if(FrameRateNr == 5 && FrameRateDr == 2) + return f59_94; + } + return FR_Reserved; +} + + + + // implement class BluRayOutput // implement class DTCP_Descriptor : Descriptor // implement class PatPacket : TsTable // implement class SitPacket : TsTable // implement class PmPacket : TsTable -// implement class VC1SequenceInfo -// implement class H264Info +// implement class H264Info : ElementaryParse // implement class AC3Info : ElementaryParse // implement class DtsInfo : ElementaryParse // implement class MlpInfo : ElementaryParse diff --git a/src/Utils.h b/src/Utils.h index 93605c6..6b116d6 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -405,53 +405,20 @@ class PesPacket { class VC1SequenceInfo { public: VC1SequenceInfo(pByte data, int offset); - bool Valid; - VideoFormat GetVideoFormati(void); - void SetVideoFormat(VideoFormat videoformat); + int GetHeight(void); + int GetWidth(void); + bool Valid(void); + bool Interlaced(void); + bool DisplayExt(void); + bool AspectFlag(void); + byte GetVc1AspectRatio(void); + bool FrameFlag(void); + bool FrameRateIndicatorFlag(void); AspectRatio GetAspectRatio(void); - void SetAspectRatio(AspectRatio aspectratio); + VideoFormat GetVideoFormat(void); FrameRate GetFrameRate(void); - void SetFrameRate(FrameRate frameRate); private: Bytes mData; - int Height; - int Width; - bool Interlaced; - bool DisplayExt; - bool AspectFlag; - byte Vc1AspectRatio; - bool FrameFlag; - bool FrameRateIndicatorFlag; - AspectRatio mAspectRatio; - VideoFormat mVideoFormat; - FrameRate mFrameRate; -}; - -class H264Info { - public: - H264Info(pByte data, int offset); - Bytes ElementaryDescriptors; - VideoFormat GetVideoFormati(void); - void SetVideoFormat(VideoFormat videoformat); - 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); - private: - UInt32 GetNextExpGolomb(); - void ScalingListSkip(int skip); - UInt32 Width; - UInt32 Heigth; - Bytes HdmvVideoRegistrationDescriptor; - VideoFormat mVideoFormat; - AspectRatio mAspectRatio; - FrameRate mFrameRate; - AudioPresentationType mAudioPresentationType; - SamplingFrequency mSamplingFrequency; }; enum Ac3SyntaxType { @@ -489,6 +456,33 @@ class ElementaryParse { Bytes ElementaryDescriptors; }; +class H264Info : ElementaryParse { + public: + H264Info(pByte data, int offset); + Bytes ElementaryDescriptors; + VideoFormat GetVideoFormati(void); + void SetVideoFormat(VideoFormat videoformat); + 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); + private: + UInt32 GetNextExpGolomb(); + void ScalingListSkip(int skip); + UInt32 Width; + UInt32 Heigth; + Bytes HdmvVideoRegistrationDescriptor; + VideoFormat mVideoFormat; + AspectRatio mAspectRatio; + FrameRate mFrameRate; + AudioPresentationType mAudioPresentationType; + SamplingFrequency mSamplingFrequency; +}; + class AC3Info : ElementaryParse { public: int MaxFrameLength;