📄 dabmot.cpp
字号:
/* The first occurrence of a Data Group type 3 containing
header information is referred as the beginning of the
object transmission. Set new transport ID */
MOTObjectRaw.iTransportID = iTransportID;
/* Init flag for header ok */
MOTObjectRaw.Header.bOK = TRUE;
/* Add new segment data */
MOTObjectRaw.Header.Add(vecbiNewData, iSegmentSize,
iSegmentNum);
}
else
{
/* Check transport ID */
if (MOTObjectRaw.iTransportID != iTransportID)
MOTObjectRaw.Header.Reset();
else
{
/* Sometimes a packet is transmitted more than once,
only use packets which are not already received
correctly */
if (MOTObjectRaw.Header.iDataSegNum != iSegmentNum)
{
/* Check segment number */
if (MOTObjectRaw.Header.iDataSegNum + 1 !=
iSegmentNum)
{
/* A packet is missing, reset Header */
MOTObjectRaw.Header.Reset();
}
else
{
/* Add data */
MOTObjectRaw.Header.Add(vecbiNewData,
iSegmentSize, iSegmentNum);
}
}
}
}
/* Test if last flag is active */
if (biLastFlag == TRUE)
{
if (MOTObjectRaw.Header.bOK == TRUE)
{
/* This was the last segment and all segments were ok.
Mark header as ready */
MOTObjectRaw.Header.bReady = TRUE;
}
}
}
else if (iDataGroupType == 4)
{
/* Body data segments are transferred in Data Group type 4 */
/* Body ----------------------------------------------------- */
if (iSegmentNum == 0)
{
/* The first segment was received, reset body */
MOTObjectRaw.Body.Reset();
/* Check transport ID */
if (MOTObjectRaw.iTransportID == iTransportID)
{
/* Init flag for body ok */
MOTObjectRaw.Body.bOK = TRUE;
/* Add data */
MOTObjectRaw.Body.Add(vecbiNewData, iSegmentSize,
iSegmentNum);
}
}
else
{
/* Check transport ID */
if (MOTObjectRaw.iTransportID != iTransportID)
MOTObjectRaw.Body.Reset();
else
{
/* Sometimes a packet is transmitted more than once,
only use packets which are not already received
correctly */
if (MOTObjectRaw.Body.iDataSegNum != iSegmentNum)
{
/* Check segment number */
if (MOTObjectRaw.Body.iDataSegNum + 1 !=
iSegmentNum)
{
/* A packet is missing, reset Header */
MOTObjectRaw.Body.Reset();
}
else
{
/* Add data */
MOTObjectRaw.Body.Add(vecbiNewData,
iSegmentSize, iSegmentNum);
}
}
}
}
/* Test if last flag is active */
if (biLastFlag == TRUE)
{
if (MOTObjectRaw.Body.bOK == TRUE)
{
/* This was the last segment and all segments were ok.
Mark body as ready */
MOTObjectRaw.Body.bReady = TRUE;
}
}
}
/* Use MOT object ----------------------------------------------- */
/* Test if MOT object is ready */
if ((MOTObjectRaw.Header.bReady == TRUE) &&
(MOTObjectRaw.Body.bReady == TRUE))
{
DecodeObject(MOTObjectRaw);
/* Set flag that new object was successfully decoded */
bMOTObjectReady = TRUE;
/* Reset raw MOT object */
MOTObjectRaw.Header.Reset();
MOTObjectRaw.Body.Reset();
}
}
}
/* Return status of MOT object decoding */
return bMOTObjectReady;
}
void CMOTDABDec::DecodeObject(CMOTObjectRaw& MOTObjectRaw)
{
int i;
int iDaSiBytes;
unsigned char ucParamId;
unsigned char ucDatafield;
/* Header --------------------------------------------------------------- */
/* ETSI EN 301 234 */
MOTObjectRaw.Header.vecbiData.ResetBitAccess();
/* HeaderSize and BodySize */
const int iBodySize = (int) MOTObjectRaw.Header.vecbiData.Separate(28);
const int iHeaderSize = (int) MOTObjectRaw.Header.vecbiData.Separate(13);
/* 7 bytes for header core */
int iSizeRec = iHeaderSize - 7;
/* Content type and content sup-type */
const int iContentType = (int) MOTObjectRaw.Header.vecbiData.Separate(6);
const int iContentSubType =
(int) MOTObjectRaw.Header.vecbiData.Separate(9);
/* Use all header extension data blocks */
while (iSizeRec > 0)
{
/* PLI (Parameter Length Indicator) */
int iPLI = (int) MOTObjectRaw.Header.vecbiData.Separate(2);
switch(iPLI)
{
case 0:
/* Total parameter length = 1 byte; no DataField
available */
ucParamId = (unsigned char)
MOTObjectRaw.Header.vecbiData.Separate(6);
/* TODO: Use "ucParamId" */
iSizeRec -= 1; /* 6 + 2 (PLI) bits */
break;
case 1:
/* Total parameter length = 2 bytes, length of DataField
is 1 byte */
ucParamId = (unsigned char)
MOTObjectRaw.Header.vecbiData.Separate(6);
ucDatafield = (unsigned char)
MOTObjectRaw.Header.vecbiData.Separate(8);
/* TODO: Use information in data field */
iSizeRec -= 2; /* 6 + 8 + 2 (PLI) bits */
break;
case 2:
/* Total parameter length = 5 bytes; length of DataField
is 4 bytes */
ucParamId = (unsigned char)
MOTObjectRaw.Header.vecbiData.Separate(6);
for (i = 0; i < 4; i++)
{
ucDatafield = (unsigned char)
MOTObjectRaw.Header.vecbiData.Separate(8);
/* TODO: Use information in data field */
}
iSizeRec -= 5; /* 6 + 4 * 8 + 2 (PLI) bits */
break;
case 3:
/* Total parameter length depends on the DataFieldLength
indicator (the maximum parameter length is
32770 bytes) */
ucParamId = (unsigned char)
MOTObjectRaw.Header.vecbiData.Separate(6);
iSizeRec -= 1; /* 2 (PLI) + 6 bits */
/* Ext (ExtensionFlag): This 1-bit field specifies the
length of the DataFieldLength Indicator and is coded
as follows:
- 0: the total parameter length is derived from the
next 7 bits;
- 1: the total parameter length is derived from the
next 15 bits */
unsigned char ucExt = (unsigned char)
MOTObjectRaw.Header.vecbiData.Separate(1);
int iDataFieldLen = 0;
/* Get data field length */
if (ucExt == 0)
{
iDataFieldLen = (int)
MOTObjectRaw.Header.vecbiData.Separate(7);
iSizeRec -= 1;
}
else
{
iDataFieldLen = (int)
MOTObjectRaw.Header.vecbiData.Separate(15);
iSizeRec -= 2;
}
/* Store data in vector */
CVector<char> veccNewData(iDataFieldLen);
for (i = 0; i < iDataFieldLen; i++)
{
veccNewData[i] = (char)
MOTObjectRaw.Header.vecbiData.Separate(8);
}
/* Decode label (P.10 Label) */
if ((ucParamId == 12) && (iDataFieldLen > 0))
{
/* Only use "0 0 0 0 complete EBU Latin based repertoire"
character set */
if (veccNewData[0] == 0)
{
/* Copy name of object (first byte is character set
indicator) */
MOTObject.strName = "";
for(i = 1; i < iDataFieldLen; i++)
MOTObject.strName.append(&veccNewData[i], 1);
}
}
break;
}
}
/* Body ----------------------------------------------------------------- */
/* We only use images */
if (iContentType == 2 /* image */)
{
/* Check range of content sub type */
if (iContentSubType < 4)
{
/* Set up MOT picture ------------------------------------------- */
/* Reset bit access to extract data from body */
MOTObjectRaw.Body.vecbiData.ResetBitAccess();
/* Data size in bytes */
iDaSiBytes =
MOTObjectRaw.Body.vecbiData.Size() / SIZEOF__BYTE;
/* Copy data */
MOTObject.vecbRawData.Init(iDaSiBytes);
for (int i = 0; i < iDaSiBytes; i++)
{
MOTObject.vecbRawData[i] = (_BYTE) MOTObjectRaw.Body.
vecbiData.Separate(SIZEOF__BYTE);
}
/* Set format */
switch (iContentSubType)
{
case 0: /* gif */
MOTObject.strFormat = "gif";
break;
case 1: /* jfif */
MOTObject.strFormat = "jpeg";
break;
case 2: /* bmp */
MOTObject.strFormat = "bmp";
break;
case 3: /* png */
MOTObject.strFormat = "png";
break;
default:
MOTObject.strFormat = "";
break;
}
}
}
}
void CMOTObjectRaw::CDataUnit::Add(CVector<_BINARY>& vecbiNewData,
const int iSegmentSize,
const int iSegNum)
{
/* Add new data (bit-wise copying) */
const int iOldDataSize = vecbiData.Size();
const int iNewEnlSize = iSegmentSize * SIZEOF__BYTE;
vecbiData.Enlarge(iNewEnlSize);
/* Read useful bits. We have to use the "Separate()" function since we have
to start adding at the current bit position of "vecbiNewData" */
for (int i = 0; i < iNewEnlSize; i++)
{
vecbiData[iOldDataSize + i] =
(_BINARY) vecbiNewData.Separate(1);
}
/* Set new segment number */
iDataSegNum = iSegNum;
}
void CMOTObjectRaw::CDataUnit::Reset()
{
vecbiData.Init(0);
bOK = FALSE;
bReady = FALSE;
iDataSegNum = -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -