0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 };
-// pByte Utility::ToArray(const Bytes vector)
-// {
-// pByte array = pByte(new byte[vector.size()]);
-// for(int i = 0; i < vector.size(); i++)
-// {
-// array[i] = vector.at(i);
-// }
-// return array;
-// }
+pByte Utility::ToArray(const std::vector<byte> vctr)
+{
+ pByte array = pByte(new byte[vctr.size()]);
+ for(int i = 0; i < vctr.size(); i++)
+ {
+ array[i] = vctr.at(i);
+ }
+ return array;
+}
+const int DATA_HEADER = 5;
StreamInfo::StreamInfo(pByte data, int index)throw(std::invalid_argument)
{
if(!data)
throw std::invalid_argument("stream data is NULL");
- if(sizeof(data.get()) + index < 5)
+ if(sizeof(data.get()) + index < DATA_HEADER)
throw std::invalid_argument("stream data too short");
uint descLength = (data[3 + index] & 0x0f) << 8 + data[4 + index];
throw std::invalid_argument("stream data too short");
}
- mData = pByte(new byte[5 + descLength]);
+ mData = pByte(new byte[DATA_HEADER + descLength]);
for(int i = 0; i < sizeof(mData.get()); i++)
{
mData[i] = data[i + index];
StreamInfo::StreamInfo(ElementaryStreamTypes streamType, ushort elementaryPid)
{
- mData = pByte(new byte[5]);
+ mData = pByte(new byte[DATA_HEADER]);
SetElementaryStreamTypes(streamType);
SetElementaryPID(elementaryPid);
// reserved and descriptors length
pByte StreamInfo::GetElementaryDescriptors(void)
{
pByte descriptors;
- if(sizeof(mData.get()) == 5)
+ if(sizeof(mData.get()) == DATA_HEADER)
{
descriptors.reset();
}
else
{
- descriptors = pByte(new byte[sizeof(mData.get()) - 5]);
- for (int i = 0; i < (sizeof(mData.get()) - 5); i++)
+ descriptors = pByte(new byte[sizeof(mData.get()) - DATA_HEADER]);
+ for (int i = 0; i < (sizeof(mData.get()) - DATA_HEADER); i++)
{
- descriptors[i] = mData[i + 5];
+ descriptors[i] = mData[i + DATA_HEADER];
}
}
return descriptors;
{
if(!value || 0 == sizeof(value.get()))
{
- if(sizeof(mData.get()) > 5)
+ if(sizeof(mData.get()) > DATA_HEADER)
{
// need to remove existing descriptors
- pByte data = pByte(new byte[5]);
+ pByte data = pByte(new byte[DATA_HEADER]);
data[0] = mData[0];
data[1] = mData[1];
data[2] = mData[2];
throw std::invalid_argument("descriptors data too long");
}
- pByte data = pByte(new byte[5 + sizeof(value.get())]);
+ pByte data = pByte(new byte[DATA_HEADER + sizeof(value.get())]);
data[0] = mData[0];
data[1] = mData[1];
data[2] = mData[2];
data[4] = (byte)(sizeof(value.get()) & 0xff);
for (int i = 0; i < sizeof(value.get()); i++)
{
- data[5 + i] = value[i];
+ data[DATA_HEADER + i] = value[i];
}
mData = data;
}
{
if ((mData[3] & 0x20) == 0) // No adaptation field present
return mData[4];
- return (byte)(mData[4] + 1 + mData[mData[4] + 5]);
+ return (byte)(mData[4] + 1 + mData[mData[4] + DATA_HEADER]);
}
pByte TsPacket::GetData(void)
{
if ((mData[3] & 0x20) > 0 // Adaptation field present
&& (mData[4] > 0) // length > 0
- && (mData[5] & 0x10) > 0) // and a PCR
+ && (mData[DATA_HEADER] & 0x10) > 0) // and a PCR
return true;
return false;
}
byte TsTable::GetTableId(void)
{
- return mData[5 + GetPointerSize()];
+ return mData[DATA_HEADER + GetPointerSize()];
}
void TsTable::SetTableId(byte value)
{
- mData[5 + GetPointerSize()] = value;
+ mData[DATA_HEADER + GetPointerSize()] = value;
}
ushort TsTable::GetNumberId(void)
void TsTable::RefreshCrc(void)
{
uint crc = Constants::ComputeCrc(
- mData, GetLength() - 1, 5 + GetPointerSize());
+ mData, GetLength() - 1, DATA_HEADER + GetPointerSize());
mData[GetLength() + 4 + GetPointerSize()]
= (byte)((crc >> 24) & 0xff);
- mData[GetLength() + 5 + GetPointerSize()]
+ mData[GetLength() + DATA_HEADER + GetPointerSize()]
= (byte)((crc >> 16) & 0xff);
mData[GetLength() + 6 + GetPointerSize()]
= (byte)((crc >> 8) & 0xff);
mData[3] &= 0x0f; // adaptation field only, no payload
mData[3] |= 0x20; // adaptation field only, no payload
mData[4] = 183; // length
- mData[5] = 0x10; // only PCR present
+ mData[DATA_HEADER] = 0x10; // only PCR present
Int64 tsClockValue = pcr / 300;
Int64 tsOffsetValue = pcr % 300;
mData[6] = (byte)((tsClockValue & 0x1fe000000LL) >> 25);
bool PesPacket::GetComplete(void)
{
if(sizeof(mData.get()) < 6) return false;
- ushort len = (ushort)((mData[4] << 8) + mData[5]);
+ ushort len = (ushort)((mData[4] << 8) + mData[DATA_HEADER]);
if(len == 0) return false;
if(sizeof(mData.get()) != len + 6) return false;
return true;
if (sizeof(mData.get()) > (0xffff - 6))
len = 0;
mData[4] = (byte)((len >> 8) & 0xff);
- mData[5] = (byte)(len & 0xff);
+ mData[DATA_HEADER] = (byte)(len & 0xff);
}
}
if (data[0] != 0x00 || data[1] != 0x00 || data[2] != 0x01)
throw std::invalid_argument("Invalid PES prefix");
int hlen = 9 + data[8];
- int plen = 6 + (data[4] << 8) + data[5];
+ int plen = 6 + (data[4] << 8) + data[DATA_HEADER];
if (plen != 6 && hlen > plen)
throw new std::invalid_argument("Invalid PES header/packet length");
if (sizeof(data.get()) < hlen)
ushort PesHeader::GetPacketLength(void)
{
- return (ushort)((mData[4] << 8) + mData[5]);
+ return (ushort)((mData[4] << 8) + mData[DATA_HEADER]);
}
bool PesHeader::HasPts(void)
bool VC1SequenceInfo::Interlaced(void)
{
- if(!mData && sizeof(mData.get()) > 5)
- return ((mData[5] & 0x40) > 0);
+ if(!mData && sizeof(mData.get()) > DATA_HEADER)
+ return ((mData[DATA_HEADER] & 0x40) > 0);
return false;
}
bool VC1SequenceInfo::DisplayExt(void)
{
- if(!mData && sizeof(mData.get()) > 5)
- return ((mData[5] & 0x02) > 0);
+ if(!mData && sizeof(mData.get()) > DATA_HEADER)
+ return ((mData[DATA_HEADER] & 0x02) > 0);
return false;
}
return ((mData[5] & 0x3) > 0);
}
+MlpInfo::MlpInfo(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::MLP_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();
+}
+
+AspectRatio MlpInfo::GetAspectRatio(void)
+{
+ return AR_Reserved;
+}
+FrameRate MlpInfo::GetFrameRate(void)
+{
+ return FR_Reserved;
+}
+
+VideoFormat MlpInfo::GetVideoFormat(void)
+{
+ return VF_Reserved;
+}
+
+pByte MlpInfo::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 ad = GetAC3AudioDescriptor();
+ for(int i = 0; i < sizeof(ad.get()); i++)
+ {
+ descriptors.push_back(ad[i]);
+ }
+ return Utility::ToArray(descriptors);
+}
+
+AudioPresentationType MlpInfo::GetAudioPresentationType(void)
+{
+ return multi;
+}
+
+SamplingFrequency MlpInfo::GetSamplingFrequency(void)
+{
+ switch (GetSampleRateCode())
+ {
+ case 0:
+ return kHz48;
+ case 1:
+ return kHz96;
+ case 2:
+ return kHz192;
+ case 8: // 44.1kHz
+ case 9: // 88.2kHz
+ case 10: // 176.4kHz
+ default:
+ return SF_Reserved;
+ }
+}
+
+pByte MlpInfo::GetAC3AudioDescriptor(void)
+{
+ std::vector<byte> desc;
+ desc.push_back(0x81);
+ desc.push_back(0x00);
+ desc.push_back((byte)((GetSampleRateCode() << 5) | 0x08));
+ desc.push_back(200);
+ desc.push_back((byte)(0x0f));
+ desc[1] = (byte)(desc.size() - 2);
+ return Utility::ToArray(desc);
+}
+
+byte MlpInfo::GetSampleRateCode(void)
+{
+ if (sizeof(mData.get()) > 0)
+ return (byte)(mData[0] >> 4);
+ return 0x00;
+}
// implement class BluRayOutput
// implement class SitPacket : TsTable
// implement class H264Info : ElementaryParse
// implement class AC3Info : ElementaryParse
// implement class DtsInfo : ElementaryParse
-// implement class MlpInfo : ElementaryParse
// implement class Mpeg2Info : ElementaryParse
EpElement(signed long long pts, unsigned long spn);
};
-//class Utility {
-// public:
-// static pByte ToArray(pByte vector);
-//};
+class Utility {
+ public:
+ static pByte ToArray(std::vector<byte> vector);
+};
class StreamInfo {
public:
+ static const int DATA_HEADER;
StreamInfo(pByte data, int index)throw(std::invalid_argument);
StreamInfo(ElementaryStreamTypes streamType, ushort elementaryPid);
VideoFormat GetVideoFormat(void);
class MlpInfo : ElementaryParse {
public:
MlpInfo(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);
- private:
- pByte AC3AudioDescriptor;
- byte SampleRateCode;
+ pByte GetAC3AudioDescriptor(void);
+ byte GetSampleRateCode(void);
};
class Mpeg2Info : ElementaryParse {
void SetFrameRate(FrameRate frameRate);
AudioPresentationType GetAudioPresentationType(void);
void SetAudioPresentationType(AudioPresentationType audioPresentationTyp);
- SamplingFrequency GetsamplingFrequency(void);
+ SamplingFrequency GetSamplingFrequency(void);
void SetSamplingFrequency(SamplingFrequency samplingFrequency);
pByte GetElementaryDescriptors(void);
private: