Improved NAL unit and keyframe handling

This commit is contained in:
Thulinma 2017-05-15 17:11:24 +02:00
parent e5470f035e
commit 288cc5d3ce
4 changed files with 21 additions and 39 deletions

View file

@ -69,54 +69,33 @@ namespace nalu {
return dataSize;
}
///Scans data for the last non-zero byte, returning a pointer to it.
const char* nalEndPosition(const char * data, uint32_t dataSize){
while(dataSize > 0 && memcmp(data+dataSize-1, "\000",1) == 0 ){
dataSize--;
}
return data+dataSize;
}
///scan data stream for startcode. return pointer to location when found, NULL otherwise
void scanAnnexB(const char * data, uint32_t dataSize, const char *& packetPointer){
///Scan data for Annex B start code. Returns pointer to it when found, null otherwise.
const char * scanAnnexB(const char * data, uint32_t dataSize){
int offset = 0;
while(offset+2 < dataSize){
const char * begin = data + offset;
// int t = ((((int*)begin)[0]) >> 8) & 0x00FFFFFF;
int t = (int)((begin[0] << 8)|((begin[1]) << 8)|(begin[2]));
//int t = (int)((begin[0]|begin[1]) << 1)|(begin[2]);
//search for startcode
//if(memcmp(begin, "\000\000\001",3) != 0){
if(t != 1){
//if((t & 0x0000FF != 0 ))
if((int)begin[2] != 0 ) //XX1
{
if (begin[2]){//skip three bytes if the last one isn't zero
offset +=3;
}else if(((int)begin[1] == 1) && ((int)begin[2] ==0)){ //X10
}else if (begin[1]){//skip two bytes if the second one isn't zero
offset +=2;
}else{
offset++; //[X00]? incr with 1 because the startcode could be one at 1byte offset.
}
/*
if(t != 0 )
{
offset += 3;
}else{
}else{//All other cases, skip one byte
offset++;
}
*/
// offset++;
}else{
packetPointer = begin;
return;
return begin;
}
}
packetPointer = NULL;
return 0;
}
unsigned long fromAnnexB(const char * data, unsigned long dataSize, char *& result){