OSDN Git Service

implement H264Info class in Utils
authorcocot <cocot@users.sourceforge.jp>
Sat, 7 Mar 2009 12:44:36 +0000 (21:44 +0900)
committercocot <cocot@users.sourceforge.jp>
Sat, 7 Mar 2009 12:44:36 +0000 (21:44 +0900)
src/Utils.cc
src/Utils.h

index d50c717..625f4d4 100644 (file)
@@ -2022,11 +2022,199 @@ bool Mpeg2Info::GetProgressive(void)
 }
 */
 
+// implement class H264Info : ElementaryParse
+H264Info::H264Info(pByte data, int offset)
+{
+    UInt32 marker = 0xffffffff;
+    for (; offset < sizeof(data.get()); offset++)
+    {
+        marker = marker << 8;
+        marker &= 0xffffff00;
+        marker += data[offset];
+        if ((marker & 0xffffff9f) == Constants::H264_PREFIX)
+        {
+                    break;
+        }
+    }
+    offset++;
+    if (offset < sizeof(data.get()))
+    {
+        // sequence parameter set
+        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();
+}
+
+UInt32 H264Info::GetNextExpGolomb(void)
+{
+    int leadingZeroBits = -1;
+    byte b = 0;
+    for (; b == 0; leadingZeroBits++)
+        b = GetNextBit();
+    UInt32 codeNum = (UInt32)(1 << leadingZeroBits);
+    codeNum -= 1;
+    UInt32 part2 = 0;
+    for (; leadingZeroBits > 0; leadingZeroBits-- )
+    {
+        b = GetNextBit();
+        part2 = part2 << 1;
+        part2 |= b;
+    }
+    codeNum += part2;
+    return codeNum;
+}
+
+void H264Info::ScalingListSkip(int skip)
+{
+    int lastScale = 8;
+    int nextScale = 8;
+    for (int i = 0; i < skip; i++)
+    {
+        if (nextScale != 0)
+        {
+            int deltaScale = (int)GetNextExpGolomb();
+            nextScale = (lastScale + deltaScale) % 256;
+        }
+    }
+}
+
+UInt32 H264Info::GetWidth(void)
+{
+    indicator = 24;
+    GetNextExpGolomb();
+    if (mData[0] == 100 || mData[0] == 110 || mData[0] == 122 || mData[0] == 144)
+    {
+        UInt32 chroma = GetNextExpGolomb();
+        if (chroma == 3)
+        GetNextBit();
+        GetNextExpGolomb();
+        GetNextExpGolomb();
+        GetNextBit();
+        if (GetNextBit() == 1)
+        {
+            for (int i = 0; i < 6; i++)
+            {
+                if (GetNextBit() == 1)
+                {
+                    ScalingListSkip(16);
+                }
+            }
+            for (int i = 6; i < 8; i++)
+            {
+                if (GetNextBit() == 1)
+                {
+                    ScalingListSkip(64);
+                }
+            }
+        }
+    }
+    GetNextExpGolomb();
+    UInt32 pic = GetNextExpGolomb();
+    if (pic == 0)
+        GetNextExpGolomb();     
+    else if (pic == 1)
+    {
+        GetNextBit();
+        GetNextExpGolomb();
+        GetNextExpGolomb();
+        UInt32 numFrame = GetNextExpGolomb();
+        for (int i = 0; i < numFrame; i++)
+            GetNextExpGolomb();
+    }
+    GetNextExpGolomb();
+    GetNextBit();
+    UInt32 wid = GetNextExpGolomb();
+    wid++;
+    wid <<= 4;
+    return wid;
+}
+
+UInt32 H264Info::GetHeigth(void)
+{
+    UInt32 width = GetWidth();
+    UInt32 height = GetNextExpGolomb();
+    height++;
+    height <<= 4;
+    return height;
+}
+
+pByte H264Info::GetHdmvVideoRegistrationDescriptor(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] = 0x1b;
+    data[8] = (byte)((((byte)GetVideoFormat()) << 4) | ((byte)GetFrameRate()));
+    data[9] = (byte)((((byte)GetAspectRatio()) << 4) | 0x0f);
+    return data;
+}
+
+VideoFormat H264Info::GetVideoFormat(void)
+{
+    UInt32 h = GetHeigth();
+    if (h == 1080 || h == 1088)
+        return p1080;
+    else if (h == 720)
+        return p720;
+    else if (h == 576)
+        return p576;
+    else if (h == 480)
+        return p480;
+    else if (h == 540 || h == 544)
+        return i1080;
+    else if (h == 288)
+        return i576;
+    else if (h == 240)
+        return i480;
+    else
+        return VF_Reserved;
+}
+
+AspectRatio H264Info::GetAspectRatio(void)
+{
+    if (GetVideoFormat() == i480 || GetVideoFormat() == i576)
+        return a4_3;
+    return a16_9;
+}
+
+FrameRate H264Info::GetFrameRate(void)
+{
+    if (GetVideoFormat() == p720)
+        return f59_94;
+    else if (GetVideoFormat() == p1080 || GetVideoFormat() == p480)
+        return f23_976;
+    else if (GetVideoFormat() == p576 || GetVideoFormat() == i576)
+        return f25;
+    else
+        return f29_97;
+}
+
+pByte H264Info::GetElementaryDescriptors(void)
+{
+    return GetHdmvVideoRegistrationDescriptor();
+}
+
+AudioPresentationType H264Info::GetAudioPresentationType(void)
+{
+    return AP_Reserved;
+}
+
+SamplingFrequency H264Info::GetSamplingFrequency(void)
+{
+    return SF_Reserved;
+}
 
 // implement class BluRayOutput
 // implement class SitPacket : TsTable
 // implement class PmPacket : TsTable
-// implement class H264Info : ElementaryParse
 
 
 } // namespace
index e541d39..aafb4f4 100644 (file)
@@ -469,28 +469,17 @@ class ElementaryParse {
 class H264Info : ElementaryParse {
  public:
   H264Info(pByte data, int offset);
-  pByte ElementaryDescriptors;
-  VideoFormat GetVideoFormati(void);
-  void SetVideoFormat(VideoFormat videoformat);
+  pByte GetElementaryDescriptors(void);
+  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);
- private:
   UInt32 GetNextExpGolomb();
   void ScalingListSkip(int skip);
-  UInt32 Width;
-  UInt32 Heigth;
-  pByte HdmvVideoRegistrationDescriptor;
-  VideoFormat mVideoFormat;
-  AspectRatio mAspectRatio;
-  FrameRate   mFrameRate;
-  AudioPresentationType mAudioPresentationType;
-  SamplingFrequency mSamplingFrequency;
+  UInt32 GetWidth(void);
+  UInt32 GetHeigth(void);
+  pByte GetHdmvVideoRegistrationDescriptor(void);
 };
 
 class AC3Info : ElementaryParse {