0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 };
-StreamInfo::StreamInfo(byte* data, int index)throw(std::invalid_argument)
+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;
+}
+
+StreamInfo::StreamInfo(pByte data, int index)throw(std::invalid_argument)
{
if (NULL == data) {
throw std::invalid_argument("stream data is NULL");
}
- if (std::strlen(data) + index < 5) {
+ if (std::strlen(data.get()) + index < 5) {
throw std::invalid_argument("stream data too short");
}
throw std::invalid_argument("descriptors data too long");
}
- if (5 + descLength > std::strlen(data) - index) {
+ if (5 + descLength > std::strlen(data.get()) - index) {
throw std::invalid_argument("stream data too short");
}
- mData = new byte[5 + descLength];
- for (int i = 0; i < sizeof(mData); i++) {
- mData[i] = data[i + index];
+ mData.clear();
+ for(int i = 0; i < (5 + descLength); i++)
+ {
+ mData.push_back(data[i + index]);
}
SetVideoFormat(VF_Reserved);
StreamInfo::StreamInfo(ElementaryStreamTypes streamType, ushort elementaryPid)
{
- mData = new byte[5];
- StreamType = streamType;
- ElementaryPID = elementaryPid;
+ mData.clear();
+ SetElementaryStreamTypes(streamType);
+ SetElementaryPID(elementaryPid);
// reserved and descriptors length
- mData[3] = 0xf0;
- mData[4] = 0x00;
+ mData.push_back(0x00);
+ mData.push_back(0x00);
+ mData.push_back(0x00);
+ mData.push_back(0xf0);
+ mData.push_back(0x00);
}
-byte* StreamInfo::GetByteData(void)
+pByte StreamInfo::GetByteData(void)
{
- return mData;
+ return Utility::ToArray(mData);
}
ElementaryStreamTypes StreamInfo::GetElementaryStreamTypes(void)
{
- return (ElementaryStreamTypes)mData[0];
+ return (ElementaryStreamTypes)mData.at(0);
}
void StreamInfo::SetElementaryStreamTypes(ElementaryStreamTypes stream_type)
}
ushort StreamInfo::GetElementaryPID(void)
{
- return (ushort)(((mData[1] & 0x1f) << 8) + mData[2]);
+ return (ushort)(((mData.at(1) & 0x1f) << 8) + mData.at(2));
}
-void StreamInfo::GetElementaryPID(ushort pid)
+void StreamInfo::SetElementaryPID(ushort pid)
{
mData[1] = (byte)(((pid >> 8) & 0x1f) | 0xe0);
mData[2] = (byte)(pid & 0xff);
}
-byte* StreamInfo::GetElementaryDescriptors(void)
+pByte StreamInfo::GetElementaryDescriptors(void)
{
- if (std::strlen(mData) == 5) return NULL;
- byte* descriptors = new byte[std::strlen(mData) - 5];
- for (int i = 0; i < sizeof(descriptors); i++)
+ if(mData.size() == 5) return (pByte)NULL;
+ pByte descriptors = pByte(new byte[mData.size() - 5]);
+ for (int i = 0; i < (mData.size() - 5); i++)
{
descriptors[i] = mData[i + 5];
}
return descriptors;
}
-void StreamInfo::SetElementaryDescriptors(byte* value)
+void StreamInfo::SetElementaryDescriptors(pByte value)
throw(std::invalid_argument)
{
if(NULL == value || 0 == sizeof(value))
{
- if(std::strlen(mData) > 5)
+ if(mData.size() > 5)
{
// need to remove existing descriptors
- byte* data = new byte[5];
- data[0] = mData[0];
- data[1] = mData[1];
- data[2] = mData[2];
- data[3] = 0xf0;
- data[4] = 0x00;
- mData = data;
+ Bytes data;
+ data.push_back(mData.at(0));
+ data.push_back(mData.at(1));
+ data.push_back(mData.at(2));
+ data.push_back(0xf0);
+ data.push_back(0x00);
+ mData.swap(data);
}
else
{
}
else
{
- if(std::strlen(value) > 180) {
+ if(sizeof(value) > 180) {
throw std::invalid_argument("descriptors data too long");
}
- byte* data = new byte[5 + std::strlen(value)];
- data[0] = mData[0];
- data[1] = mData[1];
- data[2] = mData[2];
- data[3] = (byte)(0xf0 | (byte)((std::strlen(value) >> 8) & 0x0f));
- data[4] = (byte)(std::strlen(value) & 0xff);
- for (int i = 0; i < std::strlen(value); i++)
+ Bytes data;
+ data.push_back(mData.at(0));
+ data.push_back(mData.at(1));
+ data.push_back(mData.at(2));
+ data.push_back(
+ (byte)(0xf0 | (byte)((std::strlen(value.get()) >> 8) & 0x0f)));
+ data.push_back(std::strlen(value.get()) & 0xff);
+ for (int i = 0; i < std::strlen(value.get()); i++)
{
- data[5 + i] = value[i];
+ data.push_back(value[i]);
}
- mData = data;
+ mData.swap(data);
}
}
TsPacket::TsPacket(void)
{
// initialize the packet as a NULL packet
- mData = new byte[Constants::TS_SIZE];
+ mData.clear();
mData[0] = Constants::SYNC_BYTE; // sync byte
mData[1] = 0x1f; // PID = 0x1FFF
mData[2] = 0xff; // PID == 0x1FFF
return (byte)(mData[4] + 1 + mData[mData[4] + 5]);
}
-byte* TsPacket::GetData(void)
+pByte TsPacket::GetData(void)
{
- return mData;
+ return Utility::ToArray(mData);
}
-void TsPacket::SetData(byte* data, int startIndex)throw(std::invalid_argument)
+void TsPacket::SetData(pByte data, int startIndex)throw(std::invalid_argument)
{
if (NULL == data)
throw std::invalid_argument("NULL packet");
- else if (Constants::TS_SIZE > std::strlen(data) - startIndex)
+ else if (Constants::TS_SIZE > std::strlen(data.get()) - startIndex)
throw std::invalid_argument("small packet");
else if (Constants::SYNC_BYTE != data[0 + startIndex])
throw std::invalid_argument("sync byte missing");
return false;
}
-byte* TsPacket::Payload(void)
+pByte TsPacket::Payload(void)
{
int offset = 4;
if ((mData[3] & 0x20) > 0)
// adaptation field present
offset += (1 + mData[4]);
if (offset >= Constants::TS_SIZE)
- return NULL;
+ return (pByte)NULL;
}
if ((mData[3] & 0x10) > 0)
{
// payload present
- byte* ret = new byte[Constants::TS_SIZE - offset];
+ pByte ret = pByte(new byte[Constants::TS_SIZE - offset]);
for (int i = 0; i < sizeof(ret); i++)
ret[i] = mData[i + offset];
+ ret[Constants::TS_SIZE - offset] = '\0';
return ret;
}
- return NULL;
+ return (pByte)NULL;
}
void TsPacket::IncrementContinuityCounter(void)
mData[12] = 0x0;
}
-TsTable::TsTable(byte* data)
+TsTable::TsTable(pByte data)
{
SetData(data, 0);
}
-void TsTable::AddData(byte* data, int offset, int len)
+void TsTable::AddData(pByte data, int offset, int len)
{
- byte* newData = NULL;
- newData = new byte[std::strlen(mData)+(len-offset)+1];
- std::strncpy(&newData[0], &mData[0], std::strlen(mData));
- std::strncat(&newData[0], &data[0], (len-offset));
- mData = &newData[0];
+ for(int i = 0; i < len; i++)
+ {
+ mData.push_back(data[offset + i]);
+ }
}
bool TsTable::Complete(void)
{
- int currentLen = strlen(mData) - (GetPointerSize() + 8);
+ int currentLen = mData.size() - (GetPointerSize() + 8);
if (GetLength() > currentLen)
return false;
return true;
byte TsTable::GetTableId(void)
{
- return mData[5 + GetPointerSize()];
+ return mData.at(5 + GetPointerSize());
}
void TsTable::SetTableId(byte value)
ushort TsTable::GetNumberId(void)
{
- return (ushort)((mData[8 + GetPointerSize()] << 8)
- + mData[9 + GetPointerSize()]);
+ return (ushort)((mData.at(8 + GetPointerSize()) << 8)
+ + mData.at(9 + GetPointerSize()));
}
void TsTable::SetNumberId(ushort value)
ushort TsTable::GetLength(void)
{
- return (ushort)(((mData[6 + GetPointerSize()] & 0x0f) << 8)
- + mData[7 + GetPointerSize()]);
+ return (ushort)(((mData.at(6 + GetPointerSize()) & 0x0f) << 8)
+ + mData.at(7 + GetPointerSize()));
}
void TsTable::SetLength(ushort value)
void TsTable::RefreshCrc(void)
{
uint crc = Constants::ComputeCrc(
- mData, GetLength() - 1, 5 + GetPointerSize());
+ Utility::ToArray(mData), GetLength() - 1, 5 + GetPointerSize());
mData[GetLength() + 4 + GetPointerSize()]
= (byte)((crc >> 24) & 0xff);
mData[GetLength() + 5 + GetPointerSize()]
}
}
-
-
-
-Descriptor::Descriptor(byte* data, int startIndex)throw(std::invalid_argument)
+Descriptor::Descriptor(pByte data, int startIndex)throw(std::invalid_argument)
{
- if (strlen(data) < 2)
+ if (strlen(data.get()) < 2)
throw std::invalid_argument("Invalid descriptor");
- if (startIndex + 2 + data[startIndex + 1] > strlen(data))
+ if (startIndex + 2 + data[startIndex + 1] > strlen(data.get()))
throw std::invalid_argument("Invalid descriptor");
- mData = new byte[2 + data[startIndex + 1]];
- for (int i = 0; i < strlen(mData); i++)
- mData[i] = data[i + startIndex];
+ mData.clear();
+ for (int i = 0; i < (2 + data[startIndex + 1]); i++)
+ mData.push_back(data[i + startIndex]);
}
byte Descriptor::GetTag(void)
{
- return mData[0];
+ return mData.at(0);
}
byte Descriptor::GetLength(void)
{
- return mData[1];
+ return mData.at(1);
}
-byte* Descriptor::GetData(void)
+pByte Descriptor::GetData(void)
{
- return mData;
+ return Utility::ToArray(mData);
}
PcrPacket::PcrPacket(Int64 pcr, byte counter, ushort pid)
mData[i] = 0xff;
}
-PesPacket::PesPacket(byte* buff, int offset, int length, ushort pid)
+PesPacket::PesPacket(pByte buff, int offset, int length, ushort pid)
{
mData.assign(0,length);
SetPID(pid);
mPriority = value;
}
-byte* PesPacket::GetData(void)
+pByte PesPacket::GetData(void)
{
- byte* buff = new byte[mData.size()+1];
+ pByte buff = pByte(new byte[mData.size()+1]);
for(int i = 0; i < mData.size();i++)
buff[i] = mData.at(i);
buff[mData.size()] = '\0';
return buff;
}
-byte* PesPacket::GetPayload(void)
+pByte PesPacket::GetPayload(void)
{
- PesHeader* ph = GetHeader();
+ boost::shared_ptr<PesHeader> ph = GetHeader();
if(ph == NULL) return GetData();
- byte* buff = new byte[mData.size()-(9 + ph->HeaderLength)+1];
+ pByte buff = pByte(new byte[mData.size()-(9 + ph->HeaderLength)+1]);
for(int i=(9 + ph->HeaderLength); i < mData.size(); i++)
buff[i] = mData.at(i);
buff[mData.size()-(9 + ph->HeaderLength)] = '\0';
byte PesPacket::GetByte(int i)
{
- return mData[i];
+ return mData.at(i);
}
void PesPacket::SetByte(byte value)
}
}
-/*
-PesHeader* PesPacket::GetHeader(void)
+boost::shared_ptr<PesHeader> PesPacket::GetHeader(void)
{
try
{
- PesHeader* ph = new PesHeader(data.ToArray());
+ boost::shared_ptr<PesHeader> ph
+ = boost::shared_ptr<PesHeader>(
+ new PesHeader(Utility::ToArray(mData)));
return ph;
}
- catch (...)
+ catch(...)
{
// no valid header (yet)
- return NULL;
+ return (boost::shared_ptr<PesHeader>)NULL;
}
}
-*/
-void PesPacket::AddData(std::vector<byte> moredata)
+void PesPacket::AddData(pByte moredata)
{
for(std::vector<byte>::iterator it = mData.begin();
it != mData.end();
}
}
-void PesPacket::AddData(byte* buff, int offset, int length)
+void PesPacket::AddData(pByte buff, int offset, int length)
{
for (int i = offset; i < length + offset; i++)
mData.push_back(buff[i]);