Merge branch 'development' into LTS_development
This commit is contained in:
commit
a2b83e0cd3
9 changed files with 675 additions and 687 deletions
|
@ -37,6 +37,9 @@ static const char * DBG_LVL_LIST[] = {"NONE", "FAIL", "ERROR", "WARN", "INFO", "
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
static inline void show_stackframe(){}
|
||||
#else
|
||||
#include <execinfo.h>
|
||||
static inline void show_stackframe() {
|
||||
void *trace[16];
|
||||
|
@ -52,6 +55,7 @@ static inline void show_stackframe() {
|
|||
DEBUG_MSG(0, "Backtrace[%d]: %s", i, messages[i]+p);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
|
|
37
lib/mp4.cpp
37
lib/mp4.cpp
|
@ -67,13 +67,25 @@ namespace MP4 {
|
|||
}
|
||||
}
|
||||
|
||||
void Box::copyFrom(const Box & rs){
|
||||
clear();
|
||||
if (data) {
|
||||
free(data);
|
||||
data = 0;
|
||||
}
|
||||
data = (char*)malloc(rs.data_size);
|
||||
memcpy(data, rs.data, rs.data_size);
|
||||
data_size = rs.data_size;
|
||||
managed = true;
|
||||
payloadOffset = rs.payloadOffset;
|
||||
}
|
||||
/// Returns the values at byte positions 4 through 7.
|
||||
std::string Box::getType() {
|
||||
return std::string(data + 4, 4);
|
||||
}
|
||||
|
||||
/// Returns true if the given 4-byte boxtype is equal to the values at byte positions 4 through 7.
|
||||
bool Box::isType(const char * boxType) {
|
||||
bool Box::isType(const char * boxType) const {
|
||||
return !memcmp(boxType, data + 4, 4);
|
||||
}
|
||||
|
||||
|
@ -790,6 +802,29 @@ namespace MP4 {
|
|||
return getBox(tempLoc);
|
||||
}
|
||||
|
||||
Box containerBox::getChild(const char * boxName){
|
||||
uint32_t count = getContentCount();
|
||||
for (uint32_t i = 0; i < count; i++){
|
||||
Box & thisChild = getContent(i);
|
||||
if (thisChild.isType(boxName)){
|
||||
return Box(thisChild.asBox(), false);
|
||||
}
|
||||
}
|
||||
return Box((char*)"\000\000\000\010erro", false);
|
||||
}
|
||||
|
||||
std::deque<Box> containerBox::getChildren(const char * boxName){
|
||||
std::deque<Box> res;
|
||||
uint32_t count = getContentCount();
|
||||
for (uint32_t i = 0; i < count; i++){
|
||||
Box & thisChild = getContent(i);
|
||||
if (thisChild.isType(boxName)){
|
||||
res.push_back(Box(thisChild.asBox(), false));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string containerBox::toPrettyString(uint32_t indent) {
|
||||
std::stringstream r;
|
||||
r << std::string(indent, ' ') << "[" << getType() << "] Container Box (" << boxedSize() << ")" << std::endl;
|
||||
|
|
26
lib/mp4.h
26
lib/mp4.h
|
@ -26,10 +26,16 @@ namespace MP4 {
|
|||
Box(const Box & rs);
|
||||
Box & operator = (const Box & rs);
|
||||
~Box();
|
||||
operator bool() const {
|
||||
return data && data_size >= 8 && !isType("erro");
|
||||
}
|
||||
void copyFrom(const Box & rs);
|
||||
|
||||
std::string getType();
|
||||
bool isType(const char * boxType);
|
||||
bool isType(const char * boxType) const;
|
||||
bool read(FILE * newData);
|
||||
bool read(std::string & newData);
|
||||
|
||||
uint64_t boxedSize();
|
||||
uint64_t payloadSize();
|
||||
char * asBox();
|
||||
|
@ -84,6 +90,24 @@ namespace MP4 {
|
|||
void setContent(Box & newContent, uint32_t no);
|
||||
Box & getContent(uint32_t no, bool unsafe = false);
|
||||
std::string toPrettyString(uint32_t indent = 0);
|
||||
Box getChild(const char * boxName);
|
||||
template <typename T>
|
||||
T getChild(){
|
||||
T a;
|
||||
MP4::Box r = getChild(a.getType().c_str());
|
||||
return (T&)r;
|
||||
}
|
||||
std::deque<Box> getChildren(const char * boxName);
|
||||
template <typename T>
|
||||
std::deque<T> getChildren(){
|
||||
T a;
|
||||
std::deque<Box> tmpRes = getChildren(a.getType().c_str());
|
||||
std::deque<T> res;
|
||||
for (std::deque<Box>::iterator it = tmpRes.begin(); it != tmpRes.end(); it++){
|
||||
res.push_back((T&)*it);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
class containerFullBox: public fullBox {
|
||||
|
|
|
@ -581,6 +581,26 @@ namespace MP4 {
|
|||
return payload() + 8;
|
||||
}
|
||||
|
||||
std::string AVCC::hexSPS(){
|
||||
std::stringstream res;
|
||||
char * data = getSPS();
|
||||
uint32_t len = getSPSLen();
|
||||
for (int i = 0; i < len; i++){
|
||||
res << std::hex << std::setw(2) << std::setfill('0') << (int)data[i];
|
||||
}
|
||||
return res.str();
|
||||
}
|
||||
|
||||
std::string AVCC::hexPPS(){
|
||||
std::stringstream res;
|
||||
char * data = getPPS();
|
||||
uint32_t len = getPPSLen();
|
||||
for (int i = 0; i < len; i++){
|
||||
res << std::hex << std::setw(2) << std::setfill('0') << (int)data[i];
|
||||
}
|
||||
return res.str();
|
||||
}
|
||||
|
||||
void AVCC::setPPSNumber(uint32_t newPPSNumber) {
|
||||
int offset = 8 + getSPSLen();
|
||||
setInt8(newPPSNumber, offset);
|
||||
|
@ -617,9 +637,9 @@ namespace MP4 {
|
|||
r << std::string(indent + 1, ' ') << "Compatible Profiles: " << getCompatibleProfiles() << std::endl;
|
||||
r << std::string(indent + 1, ' ') << "Level: " << getLevel() << std::endl;
|
||||
r << std::string(indent + 1, ' ') << "SPS Number: " << getSPSNumber() << std::endl;
|
||||
r << std::string(indent + 2, ' ') << getSPSLen() << " of SPS data" << std::endl;
|
||||
r << std::string(indent + 2, ' ') << getSPSLen() << " of SPS data: " << hexSPS() << std::endl;
|
||||
r << std::string(indent + 1, ' ') << "PPS Number: " << getPPSNumber() << std::endl;
|
||||
r << std::string(indent + 2, ' ') << getPPSLen() << " of PPS data" << std::endl;
|
||||
r << std::string(indent + 2, ' ') << getPPSLen() << " of PPS data: " << hexPPS() << std::endl;
|
||||
return r.str();
|
||||
}
|
||||
|
||||
|
@ -634,7 +654,7 @@ namespace MP4 {
|
|||
|
||||
void AVCC::setPayload(std::string newPayload) {
|
||||
if (!reserve(0, payloadSize(), newPayload.size())) {
|
||||
DEBUG_MSG(DLVL_ERROR, "Cannot allocate enough memory for payload");
|
||||
ERROR_MSG("Cannot allocate enough memory for payload");
|
||||
return;
|
||||
}
|
||||
memcpy((char *)payload(), (char *)newPayload.c_str(), newPayload.size());
|
||||
|
@ -842,7 +862,7 @@ namespace MP4 {
|
|||
|
||||
void HVCC::setPayload(std::string newPayload) {
|
||||
if (!reserve(0, payloadSize(), newPayload.size())) {
|
||||
DEBUG_MSG(DLVL_ERROR, "Cannot allocate enough memory for payload");
|
||||
ERROR_MSG("Cannot allocate enough memory for payload");
|
||||
return;
|
||||
}
|
||||
memcpy((char *)payload(), (char *)newPayload.c_str(), newPayload.size());
|
||||
|
@ -1478,7 +1498,7 @@ namespace MP4 {
|
|||
return r.str();
|
||||
}
|
||||
|
||||
HDLR::HDLR(std::string & type, std::string name) {
|
||||
HDLR::HDLR(const std::string & type, const std::string & name) {
|
||||
memcpy(data + 4, "hdlr", 4);
|
||||
//reserve an entire box, except for the string part at the end
|
||||
if (!reserve(0, 8, 32)) {
|
||||
|
@ -2571,9 +2591,7 @@ namespace MP4 {
|
|||
for (unsigned int i = 0; i < getEntryCount(); i++) {
|
||||
static STTSEntry temp;
|
||||
temp = getSTTSEntry(i);
|
||||
r << std::string(indent + 1, ' ') << "Entry[" << i << "]:" << std::endl;
|
||||
r << std::string(indent + 2, ' ') << "SampleCount: " << temp.sampleCount << std::endl;
|
||||
r << std::string(indent + 2, ' ') << "SampleDelta: " << temp.sampleDelta << std::endl;
|
||||
r << std::string(indent + 1, ' ') << "Entry[" << i << "]: " << temp.sampleCount << " sample(s) of " << temp.sampleDelta << "ms each" << std::endl;
|
||||
}
|
||||
return r.str();
|
||||
|
||||
|
|
|
@ -113,11 +113,13 @@ namespace MP4 {
|
|||
void setSPS(std::string newSPS);
|
||||
uint32_t getSPSLen();
|
||||
char * getSPS();
|
||||
std::string hexSPS();
|
||||
void setPPSNumber(uint32_t newPPSNumber);
|
||||
uint32_t getPPSNumber();
|
||||
void setPPS(std::string newPPS);
|
||||
uint32_t getPPSLen();
|
||||
char * getPPS();
|
||||
std::string hexPPS();
|
||||
std::string asAnnexB();
|
||||
void setPayload(std::string newPayload);
|
||||
std::string toPrettyString(uint32_t indent = 0);
|
||||
|
@ -333,7 +335,7 @@ namespace MP4 {
|
|||
|
||||
class HDLR: public Box {
|
||||
public:
|
||||
HDLR(std::string & type, std::string name);
|
||||
HDLR(const std::string & type = "", const std::string & name = "");
|
||||
void setHandlerType(const char * newHandlerType);
|
||||
std::string getHandlerType();
|
||||
void setName(std::string newName);
|
||||
|
@ -472,7 +474,7 @@ namespace MP4 {
|
|||
|
||||
class TKHD: public fullBox {
|
||||
public:
|
||||
TKHD(uint32_t trackId, uint64_t duration, uint32_t width, uint32_t height);
|
||||
TKHD(uint32_t trackId = 0, uint64_t duration = 0, uint32_t width = 0, uint32_t height = 0);
|
||||
TKHD(DTSC::Track & track, bool fragmented);
|
||||
|
||||
void setCreationTime(uint64_t newCreationTime);
|
||||
|
@ -506,7 +508,7 @@ namespace MP4 {
|
|||
|
||||
class MDHD: public fullBox {
|
||||
public:
|
||||
MDHD(uint64_t duration);
|
||||
MDHD(uint64_t duration = 0);
|
||||
void setCreationTime(uint64_t newCreationTime);
|
||||
uint64_t getCreationTime();
|
||||
void setModificationTime(uint64_t newModificationTime);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue