scanAnnexB speed optimize
This commit is contained in:
parent
9be07e5ecb
commit
cba764d8eb
1 changed files with 17 additions and 14 deletions
27
lib/nal.cpp
27
lib/nal.cpp
|
@ -79,21 +79,24 @@ namespace nalu {
|
||||||
|
|
||||||
///Scan data for Annex B start code. Returns pointer to it when found, null otherwise.
|
///Scan data for Annex B start code. Returns pointer to it when found, null otherwise.
|
||||||
const char * scanAnnexB(const char * data, uint32_t dataSize){
|
const char * scanAnnexB(const char * data, uint32_t dataSize){
|
||||||
int offset = 0;
|
char * offset = (char*)data;
|
||||||
while(offset+2 < dataSize){
|
const char * maxData = data + dataSize - 2;
|
||||||
const char * begin = data + offset;
|
while(offset < maxData){
|
||||||
bool t = (begin[2] == 1 && !begin[0] && !begin[1]);
|
if (offset[2] > 1){
|
||||||
if(!t){
|
//We have no zero in the third byte, so we need to skip at least 3 bytes forward
|
||||||
if (begin[2]){//skip three bytes if the last one isn't zero
|
|
||||||
offset += 3;
|
offset += 3;
|
||||||
}else if (begin[1]){//skip two bytes if the second one isn't zero
|
continue;
|
||||||
offset +=2;
|
|
||||||
}else{//All other cases, skip one byte
|
|
||||||
offset++;
|
|
||||||
}
|
}
|
||||||
}else{
|
if (!offset[2]){
|
||||||
return begin;
|
//We skip forward 1 or 2 bytes depending on contents of the second byte
|
||||||
|
offset += (offset[1]?2:1);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!offset[0] && !offset[1]){
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
//We have no zero in the third byte, so we need to skip at least 3 bytes forward
|
||||||
|
offset += 3;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue