NalReader::NalReader(const uint8_t* buf, int32_t size, bool asWhole) { m_begin = buf; m_next = buf; m_end = buf + size; m_asWhole = asWhole; if (!asWhole) { m_begin = searchStartCode(); } }
bool NalReader::read(const uint8_t*& nal, int32_t& size) { if (m_next == m_end) return false; const uint8_t* nalEnd; if (m_asWhole) { nalEnd = m_end; } else { nalEnd = searchStartCode(); } nal = m_begin; size = nalEnd - m_begin; m_begin = nalEnd; return true; }
bool Parser::convertToRbdu(uint8_t*& data, uint32_t& size) { uint8_t* pos; int32_t offset, i = 0; const uint8_t startCode[] = { 0x00, 0x00, 0x03 }; if (m_seqHdr.profile == PROFILE_ADVANCED) { while (1) { /*skip for ununsed bdu types*/ /*data and size are input and output parameters*/ offset = searchStartCode(data, size); if (offset >= 0) { data += (offset + 4); size -= (offset + 4); } if ((offset < 0) || (data[-1] == 0xD)) break; } if (offset < 0) { size = 0; return false; } } m_rbdu.clear(); /*extraction of rbdu from ebdu*/ while (1) { pos = std::search(data + i, data + size, startCode, startCode + 3); if (pos == data + size) { m_rbdu.insert(m_rbdu.end(), data + i, pos); break; } if (pos[3] <= 0x03) { m_rbdu.insert(m_rbdu.end(), data + i, pos + 2); } else { m_rbdu.insert(m_rbdu.end(), data + i, pos + 3); } i = pos - data + 3; } return (size > 0); }
const uint8_t* NalReader::searchNalStart() { if (!m_nalLengthSize) return searchStartCode(); if (m_end > m_begin + m_size + m_nalLengthSize) { m_begin += m_size; } else { m_begin = m_next = m_end; return m_begin; } uint32_t i, size; m_next = m_begin + m_nalLengthSize; for (i = 0, size = 0; i < m_nalLengthSize; i++) size = (size << 8) | m_begin[i]; m_size = m_nalLengthSize + size; return m_begin; }