Merge branch 'development' into LTS_development
This commit is contained in:
commit
e608ef69fd
4 changed files with 52 additions and 30 deletions
|
@ -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 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, char *& result, unsigned int & len) const;
|
||||||
void getString(const char * identifier, std::string & result) const;
|
void getString(const char * identifier, std::string & result) const;
|
||||||
void getInt(const char * identifier, int & result) const;
|
void getInt(const char * identifier, uint64_t & result) const;
|
||||||
int getInt(const char * identifier) const;
|
uint64_t getInt(const char * identifier) const;
|
||||||
void getFlag(const char * identifier, bool & result) const;
|
void getFlag(const char * identifier, bool & result) const;
|
||||||
bool getFlag(const char * identifier) const;
|
bool getFlag(const char * identifier) const;
|
||||||
bool hasMember(const char * identifier) const;
|
bool hasMember(const char * identifier) const;
|
||||||
|
|
|
@ -415,15 +415,15 @@ namespace DTSC {
|
||||||
///\brief Retrieves a single parameter as an integer
|
///\brief Retrieves a single parameter as an integer
|
||||||
///\param identifier The name of the parameter
|
///\param identifier The name of the parameter
|
||||||
///\param result The result is stored in this integer
|
///\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();
|
result = getScan().getMember(identifier).asInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
///\brief Retrieves a single parameter as an integer
|
///\brief Retrieves a single parameter as an integer
|
||||||
///\param identifier The name of the parameter
|
///\param identifier The name of the parameter
|
||||||
///\result The requested parameter as an integer
|
///\result The requested parameter as an integer
|
||||||
int Packet::getInt(const char * identifier) const {
|
uint64_t Packet::getInt(const char * identifier) const {
|
||||||
int result;
|
uint64_t result;
|
||||||
getInt(identifier, result);
|
getInt(identifier, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -432,7 +432,7 @@ namespace DTSC {
|
||||||
///\param identifier The name of the parameter
|
///\param identifier The name of the parameter
|
||||||
///\param result The result is stored in this boolean
|
///\param result The result is stored in this boolean
|
||||||
void Packet::getFlag(const char * identifier, bool & result) const {
|
void Packet::getFlag(const char * identifier, bool & result) const {
|
||||||
int result_;
|
uint64_t result_;
|
||||||
getInt(identifier, result_);
|
getInt(identifier, result_);
|
||||||
result = (bool)result_;
|
result = (bool)result_;
|
||||||
}
|
}
|
||||||
|
|
31
lib/nal.cpp
31
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;
|
continue;
|
||||||
}else if (begin[1]){//skip two bytes if the second one isn't zero
|
|
||||||
offset +=2;
|
|
||||||
}else{//All other cases, skip one byte
|
|
||||||
offset++;
|
|
||||||
}
|
|
||||||
}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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/// \file ts_packet.cpp
|
/// \file ts_packet.cpp
|
||||||
/// Holds all code for the TS namespace.
|
/// Holds all code for the TS namespace.
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -35,17 +36,35 @@ namespace TS {
|
||||||
/// It fills the content with the next 188 bytes int he file.
|
/// It fills the content with the next 188 bytes int he file.
|
||||||
/// \param Data The data to be read into the packet.
|
/// \param Data The data to be read into the packet.
|
||||||
/// \return true if it was possible to read in a full packet, false otherwise.
|
/// \return true if it was possible to read in a full packet, false otherwise.
|
||||||
bool Packet::FromFile(FILE * data) {
|
bool Packet::FromFile(FILE * data){
|
||||||
long long int bPos = ftell(data);
|
uint64_t bPos = Util::ftell(data);
|
||||||
if (!fread((void *)strBuf, 188, 1, data)) {
|
uint16_t retries = 0;
|
||||||
return false;
|
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){
|
||||||
|
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...");
|
||||||
}
|
}
|
||||||
if (strBuf[0] != 0x47){
|
FAIL_MSG("Failed to read a good packet @ %lld bytes", bPos);
|
||||||
HIGH_MSG("Failed to read a good packet on pos %lld", bPos);
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
pos=188;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Packet::FromStream(std::istream & data)
|
bool Packet::FromStream(std::istream & data)
|
||||||
|
|
Loading…
Add table
Reference in a new issue