void ABST::setQualityEntry(std::string & newEntry, uint32_t no) { int countLoc = 29 + getStringLen(29) + 1 + 1; for (unsigned int i = 0; i < getServerEntryCount(); i++) { countLoc += getStringLen(countLoc) + 1; } int tempLoc = countLoc + 1; //attempt to reach the wanted position unsigned int i; for (i = 0; i < getInt8(countLoc) && i < no; ++i) { tempLoc += getStringLen(tempLoc) + 1; } //we are now either at the end, or at the right position //let's reserve any unreserved space... if (no + 1 > getInt8(countLoc)) { int amount = no + 1 - getInt8(countLoc); if (!reserve(payloadOffset + tempLoc, 0, amount)) { return; }; memset(data + payloadOffset + tempLoc, 0, amount); setInt8(no + 1, countLoc); //set new qualityEntryCount tempLoc += no - i; } //now, tempLoc is at position for string number no, and we have at least 1 byte reserved. setString(newEntry, tempLoc); }
uint32_t ABST::getQualityEntryCount() { int countLoc = 29 + getStringLen(29) + 1 + 1; for (unsigned int i = 0; i < getServerEntryCount(); i++) { countLoc += getStringLen(countLoc) + 1; } return getInt8(countLoc); }
void ABST::setSegmentRunTable(ASRT & newSegment, uint32_t no) { uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1; for (unsigned int i = 0; i < getServerEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc++; for (unsigned int i = 0; i < getQualityEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc += getStringLen(tempLoc) + 1; //DrmData tempLoc += getStringLen(tempLoc) + 1; //MetaData int countLoc = tempLoc; tempLoc++; //skip segmentRuntableCount //attempt to reach the wanted position unsigned int i; for (i = 0; i < getInt8(countLoc) && i < no; ++i) { tempLoc += getBoxLen(tempLoc); } //we are now either at the end, or at the right position //let's reserve any unreserved space... if (no + 1 > getInt8(countLoc)) { int amount = no + 1 - getInt8(countLoc); if (!reserve(payloadOffset + tempLoc, 0, amount * 8)) { return; }; //set empty erro boxes as contents for (int j = 0; j < amount; ++j) { memcpy(data + payloadOffset + tempLoc + j * 8, "\000\000\000\010erro", 8); } setInt8(no + 1, countLoc); //set new count tempLoc += (no - i) * 8; } //now, tempLoc is at position for string number no, and we have at least an erro box reserved. setBox(newSegment, tempLoc); }
AFRT & ABST::getFragmentRunTable(uint32_t no) { static Box result; if (no >= getFragmentRunTableCount()) { static Box res; return (AFRT &)res; } uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1; for (unsigned int i = 0; i < getServerEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc++; for (unsigned int i = 0; i < getQualityEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc += getStringLen(tempLoc) + 1; //DrmData tempLoc += getStringLen(tempLoc) + 1; //MetaData for (unsigned int i = getInt8(tempLoc++); i != 0; --i) { tempLoc += getBoxLen(tempLoc); } tempLoc++; for (unsigned int i = 0; i < no; i++) { tempLoc += getBoxLen(tempLoc); } return (AFRT &)getBox(tempLoc); }
///\return Empty string if no > serverEntryCount(), serverEntry[no] otherwise. const char * ABST::getServerEntry(uint32_t no) { if (no + 1 > getServerEntryCount()) { return ""; } int tempLoc = 29 + getStringLen(29) + 1 + 1; //position of first entry for (unsigned int i = 0; i < no; i++) { tempLoc += getStringLen(tempLoc) + 1; } return getString(tempLoc); }
char * ABST::getDrmData() { uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1; for (unsigned int i = 0; i < getServerEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc++; for (unsigned int i = 0; i < getQualityEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } return getString(tempLoc); }
void ABST::setDrmData(std::string newDrm) { uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1; for (unsigned int i = 0; i < getServerEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc++; for (unsigned int i = 0; i < getQualityEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } setString(newDrm, tempLoc); }
uint32_t ABST::getSegmentRunTableCount() { uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1; for (unsigned int i = 0; i < getServerEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc++; for (unsigned int i = 0; i < getQualityEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc += getStringLen(tempLoc) + 1; //DrmData tempLoc += getStringLen(tempLoc) + 1; //MetaData return getInt8(tempLoc); }
const char * ABST::getQualityEntry(uint32_t no) { if (no > getQualityEntryCount()) { return ""; } int tempLoc = 29 + getStringLen(29) + 1 + 1; //position of serverentries; for (unsigned int i = 0; i < getServerEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc += 1; //first qualityentry for (unsigned int i = 0; i < no; i++) { tempLoc += getStringLen(tempLoc) + 1; } return getString(tempLoc); }
/// Sets the NULL-terminated string at the given index. /// Will attempt to resize if the string doesn't fit. /// Fails silently if resizing failed. void Box::setString(char * newData, size_t size, size_t index) { index += payloadOffset; if (index >= boxedSize()) { if (!reserve(index, 0, 1)) { return; } data[index] = 0; } if (getStringLen(index) != size) { if (!reserve(index, getStringLen(index) + 1, size + 1)) { return; } } memcpy(data + index, newData, size + 1); }
uint32_t ASRT::getSegmentRunEntryCount() { int tempLoc = 5; //position of qualityentry count; for (unsigned int i = 0; i < getQualityEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } return getInt32(tempLoc); }
char *String2Utf8(Object *string) { int len = getStringLen(string); unsigned short *unicode = getStringChars(string); char *utf8 = (char*)sysMalloc(utf8CharLen(unicode, len) + 1); return unicode2Utf8(unicode, len, utf8); }
afrt_runtable AFRT::getFragmentRun(uint32_t no) { afrt_runtable res; if (no > getFragmentRunCount()) { return res; } int tempLoc = 9; for (unsigned int i = 0; i < getQualityEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc += 4; for (unsigned int i = 0; i < no; i++) { if (getInt32(tempLoc + 12) == 0) { tempLoc += 17; } else { tempLoc += 16; } } res.firstFragment = getInt32(tempLoc); res.firstTimestamp = getInt64(tempLoc + 4); res.duration = getInt32(tempLoc + 12); if (res.duration) { res.discontinuity = getInt8(tempLoc + 16); } else { res.discontinuity = 0; } return res; }
void AFRT::setFragmentRun(afrt_runtable newRun, uint32_t no) { int tempLoc = 9; for (unsigned int i = 0; i < getQualityEntryCount(); ++i) { tempLoc += getStringLen(tempLoc) + 1; } int countLoc = tempLoc; unsigned int count = getInt32(countLoc); tempLoc += 4; for (unsigned int i = 0; i < no; i++) { if (i + 1 > count) { setInt32(0, tempLoc); setInt64(0, tempLoc + 4); setInt32(1, tempLoc + 12); } if (getInt32(tempLoc + 12) == 0) { tempLoc += 17; } else { tempLoc += 16; } } setInt32(newRun.firstFragment, tempLoc); setInt64(newRun.firstTimestamp, tempLoc + 4); setInt32(newRun.duration, tempLoc + 12); if (newRun.duration == 0) { setInt8(newRun.discontinuity, tempLoc + 16); } if (count < no + 1) { setInt32(no + 1, countLoc); } }
uint32_t AFRT::getFragmentRunCount() { int tempLoc = 9; for (unsigned int i = 0; i < getQualityEntryCount(); ++i) { tempLoc += getStringLen(tempLoc) + 1; } return getInt32(tempLoc); }
const char * ASRT::getQualityEntry(uint32_t no) { if (no > getQualityEntryCount()) { return ""; } int tempLoc = 5; //position of qualityentry count; for (unsigned int i = 0; i < no; i++) { tempLoc += getStringLen(tempLoc) + 1; } return getString(tempLoc); }
void ASRT::setSegmentRun(uint32_t firstSegment, uint32_t fragmentsPerSegment, uint32_t no) { int tempLoc = 5; //position of qualityentry count; for (unsigned int i = 0; i < getQualityEntryCount(); i++) { tempLoc += getStringLen(tempLoc) + 1; } int countLoc = tempLoc; tempLoc += 4 + no * 8; if (no + 1 > getInt32(countLoc)) { setInt32(no + 1, countLoc); //set new qualityEntryCount } setInt32(firstSegment, tempLoc); setInt32(fragmentsPerSegment, tempLoc + 4); }
void refactorString(struct bucketString *pStr) { struct bucket *pResult; struct bucket *pBkt; int i, j; /* Exit if string is empty, or only one bucket exists */ if (pStr == NULL) return; if (pStr->pBkt == NULL) { pStr->pLast = NULL; return; } if (pStr->pBkt->pNext == NULL) { if (isBucketNonEmpty(pStr->pBkt)==0) { /* Dump bucket */ clearString(pStr); return; } else { /* Already have only one valid bucket */ pStr->pLast = pStr->pBkt; return; } } /* Attempt to create new bucket */ pResult = newBucket(getStringLen(pStr)); if (pResult == NULL) { /* Failed to create bucket. Clear string (probably empty) */ clearString(pStr); return; } /* Copy over data from existing buckets */ i = 0; for (pBkt = pStr->pBkt; pBkt != NULL; pBkt = pBkt->pNext) { /* Skip empty buckets */ if (isBucketNonEmpty(pBkt) == 0) continue; /* Copy buffers. i accumulates continuously */ for (j = 0; j < pBkt->size; i++, j++) { pResult->pBuf[i] = pBkt->pBuf[j]; } } /* Remove old buckets and reassign to new bucket */ clearString(pStr); pStr->pBkt = pResult; pStr->pLast = pResult; }
asrt_runtable ASRT::getSegmentRun(uint32_t no) { asrt_runtable res; if (no >= getSegmentRunEntryCount()) { return res; } int tempLoc = 5; //position of qualityentry count; for (unsigned int i = 0; i < getQualityEntryCount(); ++i) { tempLoc += getStringLen(tempLoc) + 1; } tempLoc += 4 + 8 * no; res.firstSegment = getInt32(tempLoc); res.fragmentsPerSegment = getInt32(tempLoc + 4); return res; }
int getStringUtf8Len(Object *string) { return utf8CharLen(getStringChars(string), getStringLen(string)); }
uint32_t ABST::getServerEntryCount() { int countLoc = 29 + getStringLen(29) + 1; return getInt8(countLoc); }