Merge branch 'development' into LTS_development

This commit is contained in:
Thulinma 2017-07-27 18:57:50 +02:00
commit e608ef69fd
4 changed files with 52 additions and 30 deletions

View file

@ -120,8 +120,8 @@ namespace DTSC {
void genericFill(long long packTime, long long packOffset, long long packTrack, const char * packData, long long packDataSize, uint64_t packBytePos, bool isKeyframe);
void getString(const char * identifier, char *& result, unsigned int & len) const;
void getString(const char * identifier, std::string & result) const;
void getInt(const char * identifier, int & result) const;
int getInt(const char * identifier) const;
void getInt(const char * identifier, uint64_t & result) const;
uint64_t getInt(const char * identifier) const;
void getFlag(const char * identifier, bool & result) const;
bool getFlag(const char * identifier) const;
bool hasMember(const char * identifier) const;

View file

@ -415,15 +415,15 @@ namespace DTSC {
///\brief Retrieves a single parameter as an integer
///\param identifier The name of the parameter
///\param result The result is stored in this integer
void Packet::getInt(const char * identifier, int & result) const {
void Packet::getInt(const char * identifier, uint64_t & result) const {
result = getScan().getMember(identifier).asInt();
}
///\brief Retrieves a single parameter as an integer
///\param identifier The name of the parameter
///\result The requested parameter as an integer
int Packet::getInt(const char * identifier) const {
int result;
uint64_t Packet::getInt(const char * identifier) const {
uint64_t result;
getInt(identifier, result);
return result;
}
@ -432,7 +432,7 @@ namespace DTSC {
///\param identifier The name of the parameter
///\param result The result is stored in this boolean
void Packet::getFlag(const char * identifier, bool & result) const {
int result_;
uint64_t result_;
getInt(identifier, result_);
result = (bool)result_;
}

View file

@ -79,21 +79,24 @@ namespace nalu {
///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;
bool t = (begin[2] == 1 && !begin[0] && !begin[1]);
if(!t){
if (begin[2]){//skip three bytes if the last one isn't zero
offset +=3;
}else if (begin[1]){//skip two bytes if the second one isn't zero
offset +=2;
}else{//All other cases, skip one byte
offset++;
char * offset = (char*)data;
const char * maxData = data + dataSize - 2;
while(offset < maxData){
if (offset[2] > 1){
//We have no zero in the third byte, so we need to skip at least 3 bytes forward
offset += 3;
continue;
}
}else{
return begin;
if (!offset[2]){
//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;
}

View file

@ -1,6 +1,7 @@
/// \file ts_packet.cpp
/// Holds all code for the TS namespace.
#include "util.h"
#include <sstream>
#include <iomanip>
#include <string.h>
@ -35,18 +36,36 @@ namespace TS {
/// It fills the content with the next 188 bytes int he file.
/// \param Data The data to be read into the packet.
/// \return true if it was possible to read in a full packet, false otherwise.
bool Packet::FromFile(FILE * data) {
long long int bPos = ftell(data);
bool Packet::FromFile(FILE * data){
uint64_t bPos = Util::ftell(data);
uint16_t retries = 0;
while (retries < 256){
if (!fread((void *)strBuf, 188, 1, data)) {
if (!feof(data)){
FAIL_MSG("Could not read 188 bytes from file! %s", strerror(errno));
}
return false;
}
if (strBuf[0] != 0x47){
HIGH_MSG("Failed to read a good packet on pos %lld", bPos);
if (strBuf[0] == 0x47){
pos=188;
return true;
}
for (uint8_t i = 1; i < 188; ++i){
if (strBuf[i] == 0x47){
INFO_MSG("Shifting %u bytes", i);
memmove((void*)strBuf, (void*)(strBuf+i), 188-i);
if (!fread((void *)strBuf, i, 1, data)) {
return false;
}
pos=188;
return true;
}
}
INFO_MSG("Skipping invalid TS packet...");
}
FAIL_MSG("Failed to read a good packet @ %lld bytes", bPos);
return false;
}
bool Packet::FromStream(std::istream & data)
{