Added several TS and NAL convenience functions
This commit is contained in:
parent
45022f36c9
commit
ae448d6e8a
4 changed files with 74 additions and 0 deletions
50
lib/nal.cpp
50
lib/nal.cpp
|
@ -69,6 +69,56 @@ namespace nalu {
|
||||||
return dataSize;
|
return dataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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){
|
||||||
|
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
|
||||||
|
{
|
||||||
|
offset +=3;
|
||||||
|
}else if(((int)begin[1] == 1) && ((int)begin[2] ==0)){ //X10
|
||||||
|
offset +=2;
|
||||||
|
}else{
|
||||||
|
offset++; //[X00]? incr with 1 because the startcode could be one at 1byte offset.
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if(t != 0 )
|
||||||
|
{
|
||||||
|
offset += 3;
|
||||||
|
}else{
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// offset++;
|
||||||
|
}else{
|
||||||
|
packetPointer = begin;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
packetPointer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long fromAnnexB(const char * data, unsigned long dataSize, char *& result){
|
unsigned long fromAnnexB(const char * data, unsigned long dataSize, char *& result){
|
||||||
const char * lastCheck = data + dataSize - 3;
|
const char * lastCheck = data + dataSize - 3;
|
||||||
if (!result){
|
if (!result){
|
||||||
|
|
|
@ -16,4 +16,6 @@ namespace nalu {
|
||||||
|
|
||||||
unsigned long toAnnexB(const char * data, unsigned long dataSize, char *& result);
|
unsigned long toAnnexB(const char * data, unsigned long dataSize, char *& result);
|
||||||
unsigned long fromAnnexB(const char * data, unsigned long dataSize, char *& result);
|
unsigned long fromAnnexB(const char * data, unsigned long dataSize, char *& result);
|
||||||
|
void scanAnnexB(const char * data, uint32_t dataSize, const char *& packetPointer);
|
||||||
|
const char* nalEndPosition(const char * data, uint32_t dataSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,26 @@ namespace TS {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Packet::FromStream(std::istream & data)
|
||||||
|
{
|
||||||
|
long long int bPos = data.tellg();
|
||||||
|
if(!data.read (strBuf,188))
|
||||||
|
{
|
||||||
|
HIGH_MSG("failed to read 188 bytes");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strBuf[0] != 0x47)
|
||||||
|
{
|
||||||
|
HIGH_MSG("Failed to read a good packet on pos %lld", bPos);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = 188;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///This funtion fills a Packet from
|
///This funtion fills a Packet from
|
||||||
///a char array. It fills the content with
|
///a char array. It fills the content with
|
||||||
///the first 188 characters of a char array
|
///the first 188 characters of a char array
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "dtsc.h"
|
#include "dtsc.h"
|
||||||
#include "checksum.h"
|
#include "checksum.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
/// Holds all TS processing related code.
|
/// Holds all TS processing related code.
|
||||||
namespace TS {
|
namespace TS {
|
||||||
|
@ -26,6 +27,7 @@ namespace TS {
|
||||||
~Packet();
|
~Packet();
|
||||||
bool FromPointer(const char * data);
|
bool FromPointer(const char * data);
|
||||||
bool FromFile(FILE * data);
|
bool FromFile(FILE * data);
|
||||||
|
bool FromStream(std::istream & data);
|
||||||
|
|
||||||
//Base properties
|
//Base properties
|
||||||
void setPID(int NewPID);
|
void setPID(int NewPID);
|
||||||
|
|
Loading…
Add table
Reference in a new issue