OSDN Git Service

implement AC3Info class in Utils
authorcocot <cocot@users.sourceforge.jp>
Wed, 4 Mar 2009 12:15:52 +0000 (21:15 +0900)
committercocot <cocot@users.sourceforge.jp>
Wed, 4 Mar 2009 12:15:52 +0000 (21:15 +0900)
src/Utils.cc
src/Utils.h

index 3503d8e..e0c3edf 100644 (file)
@@ -1422,11 +1422,215 @@ byte MlpInfo::GetSampleRateCode(void)
     return 0x00;
 }
 
+// implement class AC3Info : ElementaryParse
+readonly int AC3Info::len48k[] = {
+             128,  128,  160,  160,  192,  192,  224,  224,
+             256,  256,  320,  320,  384,  384,  448,  448,
+             512,  512,  640,  640,  768,  768,  896,  896,
+            1024, 1024, 1280, 1280, 1536, 1536, 1792, 1792,
+            2048, 2048, 2304, 2304, 2560, 2560 };
+
+readonly int AC3Info::len44k[] = {
+             138,  140,  174,  176,  208,  210,  242,  244,
+             278,  280,  348,  350,  416,  418,  486,  488,
+             556,  558,  696,  698,  834,  836,  974,  976,
+            1114, 1116, 1392, 1394, 1670, 1672, 1950, 1952,
+            2228, 2230, 2506, 2508, 2786, 2788 };
+
+readonly int AC3Info::len32k[] = { 
+             192,  192,  240,  240,  288,  288,  336,  336,
+             384,  384,  480,  480,  576,  576,  672,  672,
+             768,  768,  960,  960, 1152, 1152, 1344, 1344,
+            1536, 1536, 1920, 1920, 2304, 2304, 2688, 2688,
+            3072, 3072, 3456, 3456, 3840, 3840 };
+
+int AC3Info::GetMaxFrameLength(void)
+{
+    return len32k[sizeof(len32k) - 1];
+}
+
+int AC3Info::GetFrameLength(void)
+{
+    if(GetSyntaxType() == Standard
+    || GetSyntaxType() == Alternative)
+    {
+        byte index = (byte)(mData[2] & 0x3f);
+        if (index < 38)
+        {
+            switch (GetSampleRateCode())
+            {
+            case 00:
+                return len48k[mData[2] & 0x3f];
+            case 01:
+                return len44k[mData[2] & 0x3f];
+            case 02:
+                return len32k[mData[2] & 0x3f];
+            }
+        }
+    }
+    else if (GetSyntaxType() == Enhanced)
+        return (((mData[0] & 0x03) << 8) + mData[1] + 1) << 1;
+    return 0;
+}
+
+bool AC3Info::Valid(void)
+{
+    return mValid && GetSyntaxType() != Invalid;
+}
+
+byte AC3Info::GetSampleRateCode(void)
+{
+    if (sizeof(mData.get()) > 2)
+        return (byte)(mData[2] >> 6);
+    return 0x03;
+}
+
+byte AC3Info::GetBsid(void)
+{
+    if (sizeof(mData.get()) > 3)
+        return (byte)(mData[3] >> 3);
+    return 0;
+}
+
+byte AC3Info::GetBsmod(void)
+{
+    if (sizeof(mData.get()) > 3
+    && (GetSyntaxType() == Standard
+    || GetSyntaxType() == Alternative))
+        return (byte)(mData[3] & 0x07);
+    return 0;
+}
+
+byte AC3Info::GetAcmod(void)
+{
+    if (sizeof(mData.get()) > 4
+    && (GetSyntaxType() == Standard
+    || GetSyntaxType() == Alternative))
+        return (byte)(mData[4] >> 5);
+    else if (sizeof(mData.get()) > 2
+    && GetSyntaxType() == Enhanced)
+        return (byte)((mData[2] >> 1) & 0x07);
+    return 0x07;
+}
+
+bool AC3Info::IsIndependentStream(void)
+{
+    if (Enhanced != GetSyntaxType())
+        return true;
+    byte res = (byte)(mData[0] >> 6);
+    if (res != 1)
+        return true;
+    return false;
+}
+
+Ac3SyntaxType AC3Info::GetSyntaxType(void)
+{
+    switch (GetBsid())
+    {
+    case (byte)Standard:
+        return Standard;
+    case (byte)Alternative:
+        return Alternative;
+    case (byte)Enhanced:
+        return Enhanced;
+    }
+    return Invalid;
+}
+
+pByte AC3Info::GetAC3AudioDescriptor(void)
+{
+    std::vector<byte> desc;
+    desc.push_back(0x81);
+    desc.push_back((byte)(desc.size() - 2));
+    desc.push_back((byte)((GetSampleRateCode() << 5) | GetBsid()));
+    desc.push_back(200);
+    desc.push_back((byte)((GetBsmod() << 5) | (GetAcmod() << 1) | 1));
+    return Utility::ToArray(desc);
+}
+
+AC3Info::AC3Info(pByte data, int offset)
+{
+    ushort marker = 0xffff;
+    for (; offset < sizeof(data.get()); offset++)
+    {
+        marker = (ushort)(marker << 8);
+        marker &= 0xff00;
+        marker += data[offset];
+        if (marker == Constants::AC3_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();
+}
+
+AudioPresentationType AC3Info::GetAudioPresentationType(void)
+{
+    switch (GetAcmod())
+    {
+    case 0x00:
+        return stereo;
+    case 0x01:
+        return mono;
+    case 0x02:
+        return stereo;
+    default:
+        return multi;
+    }
+}
+
+SamplingFrequency AC3Info::GetSamplingFrequency(void)
+{
+    switch (GetSampleRateCode())
+    {
+    case 0x00:
+        return kHz48;
+    }
+    return SF_Reserved;
+}
+
+pByte AC3Info::GetElementaryDescriptors(void)
+{
+    std::vector<byte> descriptors;
+    for(int i = 0; i < sizeof(Constants::ac3_registration_descriptor); i++)
+    {
+        descriptors.push_back(Constants::ac3_registration_descriptor[i]);
+    }
+    pByte ac3ad = GetAC3AudioDescriptor();
+    for(int j = 0; j < sizeof(ac3ad.get()); j++)
+    {
+        descriptors.push_back(ac3ad[j]);
+    }
+    return Utility::ToArray(descriptors);
+}
+
+AspectRatio AC3Info::GetAspectRatio(void)
+{
+    return AR_Reserved;
+}
+
+FrameRate AC3Info::GetFrameRate(void)
+{
+    return FR_Reserved;
+}
+
+VideoFormat AC3Info::GetVideoFormat(void)
+{
+    return VF_Reserved;
+}
+
+
 // implement class BluRayOutput
 // implement class SitPacket : TsTable
 // implement class PmPacket : TsTable
 // implement class H264Info : ElementaryParse
-// implement class AC3Info : ElementaryParse
 // implement class DtsInfo : ElementaryParse
 // implement class Mpeg2Info : ElementaryParse
 
index 1f411c4..21bce7d 100644 (file)
@@ -441,7 +441,7 @@ enum Ac3SyntaxType {
 class ElementaryParse {
  public:
   ElementaryParse(void);
-  virtual VideoFormat GetVideoFormati(void);
+  virtual VideoFormat GetVideoFormat(void);
   virtual void SetVideoFormat(VideoFormat videoformat);
   virtual AspectRatio GetAspectRatio(void);
   virtual void SetAspectRatio(AspectRatio aspectratio);
@@ -495,29 +495,27 @@ class H264Info : ElementaryParse {
 
 class AC3Info : ElementaryParse {
  public:
-  int MaxFrameLength;
-  int FrameLength;
-  bool IndependentStream;
-  Ac3SyntaxType SyntaxType;
+  int GetMaxFrameLength(void);
+  int GetFrameLength(void);
+  Ac3SyntaxType GetSyntaxType(void);
+  byte GetBsid(void);
+  byte GetBsmod(void);
+  byte GetAcmod(void);
+  bool IsIndependentStream(void);
   AC3Info(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);
+  pByte AC3Info::GetAC3AudioDescriptor(void);
+  byte GetSampleRateCode(void);
+  bool Valid(void);
  private:
-  static readonly int* len48k;
-  static readonly int* len44k;
-  static readonly int* len32k;
-  byte Bsid;
-  byte Bsmod;
-  byte Acmod;
+  static readonly int len48k[];
+  static readonly int len44k[];
+  static readonly int len32k[];
 };
 
 class DtsInfo : ElementaryParse {