-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
#include "H264Parser.h" | ||
#include <cstring> | ||
|
||
using namespace xop; | ||
|
||
Nal H264Parser::findNal(const uint8_t *data, uint32_t size) | ||
{ | ||
Nal nal(nullptr, nullptr); | ||
|
||
if(size < 5) | ||
{ | ||
return nal; | ||
} | ||
|
||
nal.second = const_cast<uint8_t*>(data) + (size-1); | ||
|
||
//uint32_t startCode = 0; | ||
uint32_t pos = 0; | ||
uint8_t prefix[3] = {0}; | ||
memcpy(prefix, data, 3); | ||
size -= 3; | ||
data += 2; | ||
|
||
while(size--) | ||
{ | ||
if ((prefix[pos % 3] == 0) && (prefix[(pos + 1) % 3] == 0) && (prefix[(pos + 2) % 3] == 1)) | ||
{ | ||
if(nal.first == nullptr) // 00 00 01 | ||
{ | ||
nal.first = const_cast<uint8_t*>(data) + 1; | ||
//startCode = 3; | ||
} | ||
else if(data > nal.first + 3) | ||
{ | ||
nal.second = const_cast<uint8_t*>(data) - 3; | ||
break; | ||
} | ||
} | ||
else if ((prefix[pos % 3] == 0) && (prefix[(pos + 1) % 3] == 0) && (prefix[(pos + 2) % 3] == 0)) | ||
{ | ||
if (*(data+1) == 0x01) // 00 00 00 01 | ||
{ | ||
if(nal.first == nullptr) | ||
{ | ||
if(size >= 1) | ||
{ | ||
nal.first = const_cast<uint8_t*>(data) + 2; | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
//startCode = 4; | ||
} | ||
else //if(startCode == 4) | ||
{ | ||
nal.second = const_cast<uint8_t*>(data) - 3; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
prefix[(pos++) % 3] = *(++data); | ||
} | ||
|
||
if(nal.first == nullptr) | ||
nal.second = nullptr; | ||
|
||
return nal; | ||
} | ||
|
||
|
||
#include "H264Parser.h" | ||
#include <cstring> | ||
|
||
using namespace xop; | ||
|
||
Nal H264Parser::findNal(const uint8_t *data, uint32_t size) | ||
{ | ||
Nal nal(nullptr, nullptr); | ||
|
||
if(size < 5) | ||
{ | ||
return nal; | ||
} | ||
|
||
nal.second = const_cast<uint8_t*>(data) + (size-1); | ||
|
||
//uint32_t startCode = 0; | ||
uint32_t pos = 0; | ||
uint8_t prefix[3] = {0}; | ||
memcpy(prefix, data, 3); | ||
size -= 3; | ||
data += 2; | ||
|
||
while(size--) | ||
{ | ||
if ((prefix[pos % 3] == 0) && (prefix[(pos + 1) % 3] == 0) && (prefix[(pos + 2) % 3] == 1)) | ||
{ | ||
if(nal.first == nullptr) // 00 00 01 | ||
{ | ||
nal.first = const_cast<uint8_t*>(data) + 1; | ||
//startCode = 3; | ||
} | ||
else if(data > nal.first + 3) | ||
{ | ||
nal.second = const_cast<uint8_t*>(data) - 3; | ||
break; | ||
} | ||
} | ||
else if ((prefix[pos % 3] == 0) && (prefix[(pos + 1) % 3] == 0) && (prefix[(pos + 2) % 3] == 0)) | ||
{ | ||
if (*(data+1) == 0x01) // 00 00 00 01 | ||
{ | ||
if(nal.first == nullptr) | ||
{ | ||
if(size >= 1) | ||
{ | ||
nal.first = const_cast<uint8_t*>(data) + 2; | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
//startCode = 4; | ||
} | ||
else //if(startCode == 4) | ||
{ | ||
nal.second = const_cast<uint8_t*>(data) - 3; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
prefix[(pos++) % 3] = *(++data); | ||
} | ||
|
||
if(nal.first == nullptr) | ||
nal.second = nullptr; | ||
|
||
return nal; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
#ifndef XOP_H264_PARSER_H | ||
#define XOP_H264_PARSER_H | ||
|
||
#include <cstdint> | ||
#include <utility> | ||
|
||
namespace xop | ||
{ | ||
|
||
typedef std::pair<uint8_t*, uint8_t*> Nal; // <nal begin, nal end> | ||
|
||
class H264Parser | ||
{ | ||
public: | ||
static Nal findNal(const uint8_t *data, uint32_t size); | ||
|
||
private: | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif | ||
|
||
#ifndef XOP_H264_PARSER_H | ||
#define XOP_H264_PARSER_H | ||
|
||
#include <cstdint> | ||
#include <utility> | ||
|
||
namespace xop | ||
{ | ||
|
||
typedef std::pair<uint8_t*, uint8_t*> Nal; // <nal begin, nal end> | ||
|
||
class H264Parser | ||
{ | ||
public: | ||
static Nal findNal(const uint8_t *data, uint32_t size); | ||
|
||
private: | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters