MP4 lib signedness fixes.

This commit is contained in:
Thulinma 2013-03-04 22:02:10 +01:00
parent 23def8aa86
commit ddb681fb8c
2 changed files with 273 additions and 273 deletions

View file

@ -4,7 +4,7 @@
#include "mp4.h" #include "mp4.h"
#include "json.h" #include "json.h"
#define Int64 long long int #define Int64 uint64_t
/// Contains all MP4 format related code. /// Contains all MP4 format related code.
namespace MP4 { namespace MP4 {
@ -50,7 +50,7 @@ namespace MP4 {
} }
if (newData.size() > 4){ if (newData.size() > 4){
payloadOffset = 8; payloadOffset = 8;
long long int size = ntohl(((int*)newData.c_str())[0]); uint64_t size = ntohl(((int*)newData.c_str())[0]);
if (size == 1){ if (size == 1){
if (newData.size() > 16){ if (newData.size() > 16){
size = 0 + ntohl(((int*)newData.c_str())[2]); size = 0 + ntohl(((int*)newData.c_str())[2]);
@ -77,16 +77,16 @@ namespace MP4 {
} }
/// Returns the total boxed size of this box, including the header. /// Returns the total boxed size of this box, including the header.
long long int Box::boxedSize(){ uint64_t Box::boxedSize(){
if (payloadOffset == 16){ if (payloadOffset == 16){
return ((long long int)ntohl(((int*)data)[2]) << 32) + ntohl(((int*)data)[3]); return ((uint64_t)ntohl(((int*)data)[2]) << 32) + ntohl(((int*)data)[3]);
} }
return ntohl(((int*)data)[0]); return ntohl(((int*)data)[0]);
} }
/// Retruns the size of the payload of thix box, excluding the header. /// Retruns the size of the payload of thix box, excluding the header.
/// This value is defined as boxedSize() - 8. /// This value is defined as boxedSize() - 8.
long long int Box::payloadSize(){ uint64_t Box::payloadSize(){
return boxedSize() - payloadOffset; return boxedSize() - payloadOffset;
} }
@ -217,7 +217,7 @@ namespace MP4 {
/// Sets the 24 bits integer at the given index. /// Sets the 24 bits integer at the given index.
/// Attempts to resize the data pointer if the index is out of range. /// Attempts to resize the data pointer if the index is out of range.
/// Fails silently if resizing failed. /// Fails silently if resizing failed.
void Box::setInt24(long newData, size_t index){ void Box::setInt24(uint32_t newData, size_t index){
index += payloadOffset; index += payloadOffset;
if (index + 2 >= boxedSize()){ if (index + 2 >= boxedSize()){
if ( !reserve(index, 0, 3)){ if ( !reserve(index, 0, 3)){
@ -232,7 +232,7 @@ namespace MP4 {
/// Gets the 24 bits integer at the given index. /// Gets the 24 bits integer at the given index.
/// Attempts to resize the data pointer if the index is out of range. /// Attempts to resize the data pointer if the index is out of range.
/// Returns zero if resizing failed. /// Returns zero if resizing failed.
long Box::getInt24(size_t index){ uint32_t Box::getInt24(size_t index){
index += payloadOffset; index += payloadOffset;
if (index + 2 >= boxedSize()){ if (index + 2 >= boxedSize()){
if ( !reserve(index, 0, 3)){ if ( !reserve(index, 0, 3)){
@ -240,7 +240,7 @@ namespace MP4 {
} }
setInt24(0, index - payloadOffset); setInt24(0, index - payloadOffset);
} }
long result = data[index]; uint32_t result = data[index];
result <<= 8; result <<= 8;
result += data[index + 1]; result += data[index + 1];
result <<= 8; result <<= 8;
@ -251,7 +251,7 @@ namespace MP4 {
/// Sets the 32 bits integer at the given index. /// Sets the 32 bits integer at the given index.
/// Attempts to resize the data pointer if the index is out of range. /// Attempts to resize the data pointer if the index is out of range.
/// Fails silently if resizing failed. /// Fails silently if resizing failed.
void Box::setInt32(long newData, size_t index){ void Box::setInt32(uint32_t newData, size_t index){
index += payloadOffset; index += payloadOffset;
if (index + 3 >= boxedSize()){ if (index + 3 >= boxedSize()){
if ( !reserve(index, 0, 4)){ if ( !reserve(index, 0, 4)){
@ -265,7 +265,7 @@ namespace MP4 {
/// Gets the 32 bits integer at the given index. /// Gets the 32 bits integer at the given index.
/// Attempts to resize the data pointer if the index is out of range. /// Attempts to resize the data pointer if the index is out of range.
/// Returns zero if resizing failed. /// Returns zero if resizing failed.
long Box::getInt32(size_t index){ uint32_t Box::getInt32(size_t index){
index += payloadOffset; index += payloadOffset;
if (index + 3 >= boxedSize()){ if (index + 3 >= boxedSize()){
if ( !reserve(index, 0, 4)){ if ( !reserve(index, 0, 4)){
@ -273,7 +273,7 @@ namespace MP4 {
} }
setInt32(0, index - payloadOffset); setInt32(0, index - payloadOffset);
} }
long result; uint32_t result;
memcpy((char*) &result, data + index, 4); memcpy((char*) &result, data + index, 4);
return ntohl(result); return ntohl(result);
} }
@ -463,19 +463,19 @@ namespace MP4 {
return getInt8(0); return getInt8(0);
} }
void ABST::setFlags(long newFlags){ void ABST::setFlags(uint32_t newFlags){
setInt24(newFlags, 1); setInt24(newFlags, 1);
} }
long ABST::getFlags(){ uint32_t ABST::getFlags(){
return getInt24(1); return getInt24(1);
} }
void ABST::setBootstrapinfoVersion(long newVersion){ void ABST::setBootstrapinfoVersion(uint32_t newVersion){
setInt32(newVersion, 4); setInt32(newVersion, 4);
} }
long ABST::getBootstrapinfoVersion(){ uint32_t ABST::getBootstrapinfoVersion(){
return getInt32(4); return getInt32(4);
} }
@ -507,11 +507,11 @@ namespace MP4 {
return (getInt8(8) & 0x08); return (getInt8(8) & 0x08);
} }
void ABST::setTimeScale(long newScale){ void ABST::setTimeScale(uint32_t newScale){
setInt32(newScale, 9); setInt32(newScale, 9);
} }
long ABST::getTimeScale(){ uint32_t ABST::getTimeScale(){
return getInt32(9); return getInt32(9);
} }
@ -539,12 +539,12 @@ namespace MP4 {
return getString(29); return getString(29);
} }
long ABST::getServerEntryCount(){ uint32_t ABST::getServerEntryCount(){
int countLoc = 29 + getStringLen(29) + 1; int countLoc = 29 + getStringLen(29) + 1;
return getInt8(countLoc); return getInt8(countLoc);
} }
void ABST::setServerEntry(std::string & newEntry, long no){ void ABST::setServerEntry(std::string & newEntry, uint32_t no){
int countLoc = 29 + getStringLen(29) + 1; int countLoc = 29 + getStringLen(29) + 1;
int tempLoc = countLoc + 1; int tempLoc = countLoc + 1;
//attempt to reach the wanted position //attempt to reach the wanted position
@ -568,7 +568,7 @@ namespace MP4 {
} }
///\return Empty string if no > serverEntryCount(), serverEntry[no] otherwise. ///\return Empty string if no > serverEntryCount(), serverEntry[no] otherwise.
const char* ABST::getServerEntry(long no){ const char* ABST::getServerEntry(uint32_t no){
if (no + 1 > getServerEntryCount()){ if (no + 1 > getServerEntryCount()){
return ""; return "";
} }
@ -579,7 +579,7 @@ namespace MP4 {
return getString(tempLoc); return getString(tempLoc);
} }
long ABST::getQualityEntryCount(){ uint32_t ABST::getQualityEntryCount(){
int countLoc = 29 + getStringLen(29) + 1 + 1; int countLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
countLoc += getStringLen(countLoc) + 1; countLoc += getStringLen(countLoc) + 1;
@ -587,7 +587,7 @@ namespace MP4 {
return getInt8(countLoc); return getInt8(countLoc);
} }
void ABST::setQualityEntry(std::string & newEntry, long no){ void ABST::setQualityEntry(std::string & newEntry, uint32_t no){
int countLoc = 29 + getStringLen(29) + 1 + 1; int countLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
countLoc += getStringLen(countLoc) + 1; countLoc += getStringLen(countLoc) + 1;
@ -613,7 +613,7 @@ namespace MP4 {
setString(newEntry, tempLoc); setString(newEntry, tempLoc);
} }
const char* ABST::getQualityEntry(long no){ const char* ABST::getQualityEntry(uint32_t no){
if (no > getQualityEntryCount()){ if (no > getQualityEntryCount()){
return ""; return "";
} }
@ -629,7 +629,7 @@ namespace MP4 {
} }
void ABST::setDrmData(std::string newDrm){ void ABST::setDrmData(std::string newDrm){
long tempLoc = 29 + getStringLen(29) + 1 + 1; uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
} }
@ -641,7 +641,7 @@ namespace MP4 {
} }
char* ABST::getDrmData(){ char* ABST::getDrmData(){
long tempLoc = 29 + getStringLen(29) + 1 + 1; uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
} }
@ -653,7 +653,7 @@ namespace MP4 {
} }
void ABST::setMetaData(std::string newMetaData){ void ABST::setMetaData(std::string newMetaData){
long tempLoc = 29 + getStringLen(29) + 1 + 1; uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
} }
@ -666,7 +666,7 @@ namespace MP4 {
} }
char* ABST::getMetaData(){ char* ABST::getMetaData(){
long tempLoc = 29 + getStringLen(29) + 1 + 1; uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
} }
@ -678,8 +678,8 @@ namespace MP4 {
return getString(tempLoc); return getString(tempLoc);
} }
long ABST::getSegmentRunTableCount(){ uint32_t ABST::getSegmentRunTableCount(){
long tempLoc = 29 + getStringLen(29) + 1 + 1; uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
} }
@ -692,8 +692,8 @@ namespace MP4 {
return getInt8(tempLoc); return getInt8(tempLoc);
} }
void ABST::setSegmentRunTable(ASRT & newSegment, long no){ void ABST::setSegmentRunTable(ASRT & newSegment, uint32_t no){
long tempLoc = 29 + getStringLen(29) + 1 + 1; uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
} }
@ -728,13 +728,13 @@ namespace MP4 {
setBox(newSegment, tempLoc); setBox(newSegment, tempLoc);
} }
ASRT & ABST::getSegmentRunTable(long no){ ASRT & ABST::getSegmentRunTable(uint32_t no){
static Box result; static Box result;
if (no > getSegmentRunTableCount()){ if (no > getSegmentRunTableCount()){
static Box res; static Box res;
return (ASRT&)res; return (ASRT&)res;
} }
long tempLoc = 29 + getStringLen(29) + 1 + 1; uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
} }
@ -752,8 +752,8 @@ namespace MP4 {
return (ASRT&)getBox(tempLoc); return (ASRT&)getBox(tempLoc);
} }
long ABST::getFragmentRunTableCount(){ uint32_t ABST::getFragmentRunTableCount(){
long tempLoc = 29 + getStringLen(29) + 1 + 1; uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
} }
@ -769,8 +769,8 @@ namespace MP4 {
return getInt8(tempLoc); return getInt8(tempLoc);
} }
void ABST::setFragmentRunTable(AFRT & newFragment, long no){ void ABST::setFragmentRunTable(AFRT & newFragment, uint32_t no){
long tempLoc = 29 + getStringLen(29) + 1 + 1; uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
} }
@ -808,13 +808,13 @@ namespace MP4 {
setBox(newFragment, tempLoc); setBox(newFragment, tempLoc);
} }
AFRT & ABST::getFragmentRunTable(long no){ AFRT & ABST::getFragmentRunTable(uint32_t no){
static Box result; static Box result;
if (no >= getFragmentRunTableCount()){ if (no >= getFragmentRunTableCount()){
static Box res; static Box res;
return (AFRT&)res; return (AFRT&)res;
} }
long tempLoc = 29 + getStringLen(29) + 1 + 1; uint32_t tempLoc = 29 + getStringLen(29) + 1 + 1;
for (int i = 0; i < getServerEntryCount(); i++){ for (int i = 0; i < getServerEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
} }
@ -835,7 +835,7 @@ namespace MP4 {
return (AFRT&)getBox(tempLoc); return (AFRT&)getBox(tempLoc);
} }
std::string ABST::toPrettyString(long indent){ std::string ABST::toPrettyString(uint32_t indent){
std::stringstream r; std::stringstream r;
r << std::string(indent, ' ') << "[abst] Bootstrap Info (" << boxedSize() << ")" << std::endl; r << std::string(indent, ' ') << "[abst] Bootstrap Info (" << boxedSize() << ")" << std::endl;
r << std::string(indent + 1, ' ') << "Version " << (int)getVersion() << std::endl; r << std::string(indent + 1, ' ') << "Version " << (int)getVersion() << std::endl;
@ -887,31 +887,31 @@ namespace MP4 {
setInt8(newVersion, 0); setInt8(newVersion, 0);
} }
long AFRT::getVersion(){ uint32_t AFRT::getVersion(){
return getInt8(0); return getInt8(0);
} }
void AFRT::setUpdate(long newUpdate){ void AFRT::setUpdate(uint32_t newUpdate){
setInt24(newUpdate, 1); setInt24(newUpdate, 1);
} }
long AFRT::getUpdate(){ uint32_t AFRT::getUpdate(){
return getInt24(1); return getInt24(1);
} }
void AFRT::setTimeScale(long newScale){ void AFRT::setTimeScale(uint32_t newScale){
setInt32(newScale, 4); setInt32(newScale, 4);
} }
long AFRT::getTimeScale(){ uint32_t AFRT::getTimeScale(){
return getInt32(4); return getInt32(4);
} }
long AFRT::getQualityEntryCount(){ uint32_t AFRT::getQualityEntryCount(){
return getInt8(8); return getInt8(8);
} }
void AFRT::setQualityEntry(std::string & newEntry, long no){ void AFRT::setQualityEntry(std::string & newEntry, uint32_t no){
int countLoc = 8; int countLoc = 8;
int tempLoc = countLoc + 1; int tempLoc = countLoc + 1;
//attempt to reach the wanted position //attempt to reach the wanted position
@ -934,7 +934,7 @@ namespace MP4 {
setString(newEntry, tempLoc); setString(newEntry, tempLoc);
} }
const char* AFRT::getQualityEntry(long no){ const char* AFRT::getQualityEntry(uint32_t no){
if (no + 1 > getQualityEntryCount()){ if (no + 1 > getQualityEntryCount()){
return ""; return "";
} }
@ -945,7 +945,7 @@ namespace MP4 {
return getString(tempLoc); return getString(tempLoc);
} }
long AFRT::getFragmentRunCount(){ uint32_t AFRT::getFragmentRunCount(){
int tempLoc = 9; int tempLoc = 9;
for (int i = 0; i < getQualityEntryCount(); ++i){ for (int i = 0; i < getQualityEntryCount(); ++i){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
@ -953,7 +953,7 @@ namespace MP4 {
return getInt32(tempLoc); return getInt32(tempLoc);
} }
void AFRT::setFragmentRun(afrt_runtable newRun, long no){ void AFRT::setFragmentRun(afrt_runtable newRun, uint32_t no){
int tempLoc = 9; int tempLoc = 9;
for (int i = 0; i < getQualityEntryCount(); ++i){ for (int i = 0; i < getQualityEntryCount(); ++i){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
@ -983,7 +983,7 @@ namespace MP4 {
} }
} }
afrt_runtable AFRT::getFragmentRun(long no){ afrt_runtable AFRT::getFragmentRun(uint32_t no){
afrt_runtable res; afrt_runtable res;
if (no > getFragmentRunCount()){ if (no > getFragmentRunCount()){
return res; return res;
@ -1050,23 +1050,23 @@ namespace MP4 {
setInt8(newVersion, 0); setInt8(newVersion, 0);
} }
long ASRT::getVersion(){ uint32_t ASRT::getVersion(){
return getInt8(0); return getInt8(0);
} }
void ASRT::setUpdate(long newUpdate){ void ASRT::setUpdate(uint32_t newUpdate){
setInt24(newUpdate, 1); setInt24(newUpdate, 1);
} }
long ASRT::getUpdate(){ uint32_t ASRT::getUpdate(){
return getInt24(1); return getInt24(1);
} }
long ASRT::getQualityEntryCount(){ uint32_t ASRT::getQualityEntryCount(){
return getInt8(4); return getInt8(4);
} }
void ASRT::setQualityEntry(std::string & newEntry, long no){ void ASRT::setQualityEntry(std::string & newEntry, uint32_t no){
int countLoc = 4; int countLoc = 4;
int tempLoc = countLoc + 1; int tempLoc = countLoc + 1;
//attempt to reach the wanted position //attempt to reach the wanted position
@ -1089,7 +1089,7 @@ namespace MP4 {
setString(newEntry, tempLoc); setString(newEntry, tempLoc);
} }
const char* ASRT::getQualityEntry(long no){ const char* ASRT::getQualityEntry(uint32_t no){
if (no > getQualityEntryCount()){ if (no > getQualityEntryCount()){
return ""; return "";
} }
@ -1100,7 +1100,7 @@ namespace MP4 {
return getString(tempLoc); return getString(tempLoc);
} }
long ASRT::getSegmentRunEntryCount(){ uint32_t ASRT::getSegmentRunEntryCount(){
int tempLoc = 5; //position of qualityentry count; int tempLoc = 5; //position of qualityentry count;
for (int i = 0; i < getQualityEntryCount(); i++){ for (int i = 0; i < getQualityEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
@ -1108,7 +1108,7 @@ namespace MP4 {
return getInt32(tempLoc); return getInt32(tempLoc);
} }
void ASRT::setSegmentRun(long firstSegment, long fragmentsPerSegment, long no){ void ASRT::setSegmentRun(uint32_t firstSegment, uint32_t fragmentsPerSegment, uint32_t no){
int tempLoc = 5; //position of qualityentry count; int tempLoc = 5; //position of qualityentry count;
for (int i = 0; i < getQualityEntryCount(); i++){ for (int i = 0; i < getQualityEntryCount(); i++){
tempLoc += getStringLen(tempLoc) + 1; tempLoc += getStringLen(tempLoc) + 1;
@ -1122,7 +1122,7 @@ namespace MP4 {
setInt32(fragmentsPerSegment, tempLoc + 4); setInt32(fragmentsPerSegment, tempLoc + 4);
} }
asrt_runtable ASRT::getSegmentRun(long no){ asrt_runtable ASRT::getSegmentRun(uint32_t no){
asrt_runtable res; asrt_runtable res;
if (no >= getSegmentRunEntryCount()){ if (no >= getSegmentRunEntryCount()){
return res; return res;
@ -1164,11 +1164,11 @@ namespace MP4 {
setInt32(0, 0); setInt32(0, 0);
} }
void MFHD::setSequenceNumber(long newSequenceNumber){ void MFHD::setSequenceNumber(uint32_t newSequenceNumber){
setInt32(newSequenceNumber, 4); setInt32(newSequenceNumber, 4);
} }
long MFHD::getSequenceNumber(){ uint32_t MFHD::getSequenceNumber(){
return getInt32(4); return getInt32(4);
} }
@ -1183,7 +1183,7 @@ namespace MP4 {
memcpy(data + 4, "moof", 4); memcpy(data + 4, "moof", 4);
} }
long MOOF::getContentCount(){ uint32_t MOOF::getContentCount(){
int res = 0; int res = 0;
int tempLoc = 0; int tempLoc = 0;
while (tempLoc < boxedSize() - 8){ while (tempLoc < boxedSize() - 8){
@ -1193,7 +1193,7 @@ namespace MP4 {
return res; return res;
} }
void MOOF::setContent(Box & newContent, long no){ void MOOF::setContent(Box & newContent, uint32_t no){
int tempLoc = 0; int tempLoc = 0;
int contentCount = getContentCount(); int contentCount = getContentCount();
for (int i = 0; i < no; i++){ for (int i = 0; i < no; i++){
@ -1211,7 +1211,7 @@ namespace MP4 {
setBox(newContent, tempLoc); setBox(newContent, tempLoc);
} }
Box & MOOF::getContent(long no){ Box & MOOF::getContent(uint32_t no){
static Box ret = Box((char*)"\000\000\000\010erro", false); static Box ret = Box((char*)"\000\000\000\010erro", false);
if (no > getContentCount()){ if (no > getContentCount()){
return ret; return ret;
@ -1243,7 +1243,7 @@ namespace MP4 {
memcpy(data + 4, "traf", 4); memcpy(data + 4, "traf", 4);
} }
long TRAF::getContentCount(){ uint32_t TRAF::getContentCount(){
int res = 0; int res = 0;
int tempLoc = 0; int tempLoc = 0;
while (tempLoc < boxedSize() - 8){ while (tempLoc < boxedSize() - 8){
@ -1253,7 +1253,7 @@ namespace MP4 {
return res; return res;
} }
void TRAF::setContent(Box & newContent, long no){ void TRAF::setContent(Box & newContent, uint32_t no){
int tempLoc = 0; int tempLoc = 0;
int contentCount = getContentCount(); int contentCount = getContentCount();
for (int i = 0; i < no; i++){ for (int i = 0; i < no; i++){
@ -1271,7 +1271,7 @@ namespace MP4 {
setBox(newContent, tempLoc); setBox(newContent, tempLoc);
} }
Box & TRAF::getContent(long no){ Box & TRAF::getContent(uint32_t no){
static Box ret = Box((char*)"\000\000\000\010erro", false); static Box ret = Box((char*)"\000\000\000\010erro", false);
if (no > getContentCount()){ if (no > getContentCount()){
return ret; return ret;
@ -1303,21 +1303,21 @@ namespace MP4 {
memcpy(data + 4, "trun", 4); memcpy(data + 4, "trun", 4);
} }
void TRUN::setFlags(long newFlags){ void TRUN::setFlags(uint32_t newFlags){
setInt24(newFlags, 1); setInt24(newFlags, 1);
} }
long TRUN::getFlags(){ uint32_t TRUN::getFlags(){
return getInt24(1); return getInt24(1);
} }
void TRUN::setDataOffset(long newOffset){ void TRUN::setDataOffset(uint32_t newOffset){
if (getFlags() & trundataOffset){ if (getFlags() & trundataOffset){
setInt32(newOffset, 8); setInt32(newOffset, 8);
} }
} }
long TRUN::getDataOffset(){ uint32_t TRUN::getDataOffset(){
if (getFlags() & trundataOffset){ if (getFlags() & trundataOffset){
return getInt32(8); return getInt32(8);
}else{ }else{
@ -1325,7 +1325,7 @@ namespace MP4 {
} }
} }
void TRUN::setFirstSampleFlags(long newSampleFlags){ void TRUN::setFirstSampleFlags(uint32_t newSampleFlags){
if ( !(getFlags() & trunfirstSampleFlags)){ if ( !(getFlags() & trunfirstSampleFlags)){
return; return;
} }
@ -1336,7 +1336,7 @@ namespace MP4 {
} }
} }
long TRUN::getFirstSampleFlags(){ uint32_t TRUN::getFirstSampleFlags(){
if ( !(getFlags() & trunfirstSampleFlags)){ if ( !(getFlags() & trunfirstSampleFlags)){
return 0; return 0;
} }
@ -1347,13 +1347,13 @@ namespace MP4 {
} }
} }
long TRUN::getSampleInformationCount(){ uint32_t TRUN::getSampleInformationCount(){
return getInt32(4); return getInt32(4);
} }
void TRUN::setSampleInformation(trunSampleInformation newSample, long no){ void TRUN::setSampleInformation(trunSampleInformation newSample, uint32_t no){
long flags = getFlags(); uint32_t flags = getFlags();
long sampInfoSize = 0; uint32_t sampInfoSize = 0;
if (flags & trunsampleDuration){ if (flags & trunsampleDuration){
sampInfoSize += 4; sampInfoSize += 4;
} }
@ -1366,14 +1366,14 @@ namespace MP4 {
if (flags & trunsampleOffsets){ if (flags & trunsampleOffsets){
sampInfoSize += 4; sampInfoSize += 4;
} }
long offset = 8; uint32_t offset = 8;
if (flags & trundataOffset){ if (flags & trundataOffset){
offset += 4; offset += 4;
} }
if (flags & trunfirstSampleFlags){ if (flags & trunfirstSampleFlags){
offset += 4; offset += 4;
} }
long innerOffset = 0; uint32_t innerOffset = 0;
if (flags & trunsampleDuration){ if (flags & trunsampleDuration){
setInt32(newSample.sampleDuration, offset + no * sampInfoSize + innerOffset); setInt32(newSample.sampleDuration, offset + no * sampInfoSize + innerOffset);
innerOffset += 4; innerOffset += 4;
@ -1395,7 +1395,7 @@ namespace MP4 {
} }
} }
trunSampleInformation TRUN::getSampleInformation(long no){ trunSampleInformation TRUN::getSampleInformation(uint32_t no){
trunSampleInformation ret; trunSampleInformation ret;
ret.sampleDuration = 0; ret.sampleDuration = 0;
ret.sampleSize = 0; ret.sampleSize = 0;
@ -1404,8 +1404,8 @@ namespace MP4 {
if (getSampleInformationCount() < no + 1){ if (getSampleInformationCount() < no + 1){
return ret; return ret;
} }
long flags = getFlags(); uint32_t flags = getFlags();
long sampInfoSize = 0; uint32_t sampInfoSize = 0;
if (flags & trunsampleDuration){ if (flags & trunsampleDuration){
sampInfoSize += 4; sampInfoSize += 4;
} }
@ -1418,14 +1418,14 @@ namespace MP4 {
if (flags & trunsampleOffsets){ if (flags & trunsampleOffsets){
sampInfoSize += 4; sampInfoSize += 4;
} }
long offset = 8; uint32_t offset = 8;
if (flags & trundataOffset){ if (flags & trundataOffset){
offset += 4; offset += 4;
} }
if (flags & trunfirstSampleFlags){ if (flags & trunfirstSampleFlags){
offset += 4; offset += 4;
} }
long innerOffset = 0; uint32_t innerOffset = 0;
if (flags & trunsampleDuration){ if (flags & trunsampleDuration){
ret.sampleDuration = getInt32(offset + no * sampInfoSize + innerOffset); ret.sampleDuration = getInt32(offset + no * sampInfoSize + innerOffset);
innerOffset += 4; innerOffset += 4;
@ -1445,12 +1445,12 @@ namespace MP4 {
return ret; return ret;
} }
std::string TRUN::toPrettyString(long indent){ std::string TRUN::toPrettyString(uint32_t indent){
std::stringstream r; std::stringstream r;
r << std::string(indent, ' ') << "[trun] Track Fragment Run (" << boxedSize() << ")" << std::endl; r << std::string(indent, ' ') << "[trun] Track Fragment Run (" << boxedSize() << ")" << std::endl;
r << std::string(indent + 1, ' ') << "Version " << (int)getInt8(0) << std::endl; r << std::string(indent + 1, ' ') << "Version " << (int)getInt8(0) << std::endl;
long flags = getFlags(); uint32_t flags = getFlags();
r << std::string(indent + 1, ' ') << "Flags"; r << std::string(indent + 1, ' ') << "Flags";
if (flags & trundataOffset){ if (flags & trundataOffset){
r << " dataOffset"; r << " dataOffset";
@ -1500,7 +1500,7 @@ namespace MP4 {
return r.str(); return r.str();
} }
std::string prettySampleFlags(long flag){ std::string prettySampleFlags(uint32_t flag){
std::stringstream r; std::stringstream r;
if (flag & noIPicture){ if (flag & noIPicture){
r << " noIPicture"; r << " noIPicture";
@ -1532,29 +1532,29 @@ namespace MP4 {
memcpy(data + 4, "tfhd", 4); memcpy(data + 4, "tfhd", 4);
} }
void TFHD::setFlags(long newFlags){ void TFHD::setFlags(uint32_t newFlags){
setInt24(newFlags, 1); setInt24(newFlags, 1);
} }
long TFHD::getFlags(){ uint32_t TFHD::getFlags(){
return getInt24(1); return getInt24(1);
} }
void TFHD::setTrackID(long newID){ void TFHD::setTrackID(uint32_t newID){
setInt32(newID, 4); setInt32(newID, 4);
} }
long TFHD::getTrackID(){ uint32_t TFHD::getTrackID(){
return getInt32(4); return getInt32(4);
} }
void TFHD::setBaseDataOffset(long long newOffset){ void TFHD::setBaseDataOffset(uint64_t newOffset){
if (getFlags() & tfhdBaseOffset){ if (getFlags() & tfhdBaseOffset){
setInt64(newOffset, 8); setInt64(newOffset, 8);
} }
} }
long long TFHD::getBaseDataOffset(){ uint64_t TFHD::getBaseDataOffset(){
if (getFlags() & tfhdBaseOffset){ if (getFlags() & tfhdBaseOffset){
return getInt64(8); return getInt64(8);
}else{ }else{
@ -1562,7 +1562,7 @@ namespace MP4 {
} }
} }
void TFHD::setSampleDescriptionIndex(long newIndex){ void TFHD::setSampleDescriptionIndex(uint32_t newIndex){
if ( !(getFlags() & tfhdSampleDesc)){ if ( !(getFlags() & tfhdSampleDesc)){
return; return;
} }
@ -1573,7 +1573,7 @@ namespace MP4 {
setInt32(newIndex, offset); setInt32(newIndex, offset);
} }
long TFHD::getSampleDescriptionIndex(){ uint32_t TFHD::getSampleDescriptionIndex(){
if ( !(getFlags() & tfhdSampleDesc)){ if ( !(getFlags() & tfhdSampleDesc)){
return 0; return 0;
} }
@ -1584,7 +1584,7 @@ namespace MP4 {
return getInt32(offset); return getInt32(offset);
} }
void TFHD::setDefaultSampleDuration(long newDuration){ void TFHD::setDefaultSampleDuration(uint32_t newDuration){
if ( !(getFlags() & tfhdSampleDura)){ if ( !(getFlags() & tfhdSampleDura)){
return; return;
} }
@ -1598,7 +1598,7 @@ namespace MP4 {
setInt32(newDuration, offset); setInt32(newDuration, offset);
} }
long TFHD::getDefaultSampleDuration(){ uint32_t TFHD::getDefaultSampleDuration(){
if ( !(getFlags() & tfhdSampleDura)){ if ( !(getFlags() & tfhdSampleDura)){
return 0; return 0;
} }
@ -1612,7 +1612,7 @@ namespace MP4 {
return getInt32(offset); return getInt32(offset);
} }
void TFHD::setDefaultSampleSize(long newSize){ void TFHD::setDefaultSampleSize(uint32_t newSize){
if ( !(getFlags() & tfhdSampleSize)){ if ( !(getFlags() & tfhdSampleSize)){
return; return;
} }
@ -1629,7 +1629,7 @@ namespace MP4 {
setInt32(newSize, offset); setInt32(newSize, offset);
} }
long TFHD::getDefaultSampleSize(){ uint32_t TFHD::getDefaultSampleSize(){
if ( !(getFlags() & tfhdSampleSize)){ if ( !(getFlags() & tfhdSampleSize)){
return 0; return 0;
} }
@ -1646,7 +1646,7 @@ namespace MP4 {
return getInt32(offset); return getInt32(offset);
} }
void TFHD::setDefaultSampleFlags(long newFlags){ void TFHD::setDefaultSampleFlags(uint32_t newFlags){
if ( !(getFlags() & tfhdSampleFlag)){ if ( !(getFlags() & tfhdSampleFlag)){
return; return;
} }
@ -1666,7 +1666,7 @@ namespace MP4 {
setInt32(newFlags, offset); setInt32(newFlags, offset);
} }
long TFHD::getDefaultSampleFlags(){ uint32_t TFHD::getDefaultSampleFlags(){
if ( !(getFlags() & tfhdSampleFlag)){ if ( !(getFlags() & tfhdSampleFlag)){
return 0; return 0;
} }
@ -1686,12 +1686,12 @@ namespace MP4 {
return getInt32(offset); return getInt32(offset);
} }
std::string TFHD::toPrettyString(long indent){ std::string TFHD::toPrettyString(uint32_t indent){
std::stringstream r; std::stringstream r;
r << std::string(indent, ' ') << "[tfhd] Track Fragment Header (" << boxedSize() << ")" << std::endl; r << std::string(indent, ' ') << "[tfhd] Track Fragment Header (" << boxedSize() << ")" << std::endl;
r << std::string(indent + 1, ' ') << "Version " << (int)getInt8(0) << std::endl; r << std::string(indent + 1, ' ') << "Version " << (int)getInt8(0) << std::endl;
long flags = getFlags(); uint32_t flags = getFlags();
r << std::string(indent + 1, ' ') << "Flags"; r << std::string(indent + 1, ' ') << "Flags";
if (flags & tfhdBaseOffset){ if (flags & tfhdBaseOffset){
r << " BaseOffset"; r << " BaseOffset";
@ -1740,19 +1740,19 @@ namespace MP4 {
setFlags(0); setFlags(0);
} }
void AFRA::setVersion(long newVersion){ void AFRA::setVersion(uint32_t newVersion){
setInt8(newVersion, 0); setInt8(newVersion, 0);
} }
long AFRA::getVersion(){ uint32_t AFRA::getVersion(){
return getInt8(0); return getInt8(0);
} }
void AFRA::setFlags(long newFlags){ void AFRA::setFlags(uint32_t newFlags){
setInt24(newFlags, 1); setInt24(newFlags, 1);
} }
long AFRA::getFlags(){ uint32_t AFRA::getFlags(){
return getInt24(1); return getInt24(1);
} }
@ -1792,19 +1792,19 @@ namespace MP4 {
return getInt8(4) & 0x20; return getInt8(4) & 0x20;
} }
void AFRA::setTimeScale(long newVal){ void AFRA::setTimeScale(uint32_t newVal){
setInt32(newVal, 5); setInt32(newVal, 5);
} }
long AFRA::getTimeScale(){ uint32_t AFRA::getTimeScale(){
return getInt32(5); return getInt32(5);
} }
long AFRA::getEntryCount(){ uint32_t AFRA::getEntryCount(){
return getInt32(9); return getInt32(9);
} }
void AFRA::setEntry(afraentry newEntry, long no){ void AFRA::setEntry(afraentry newEntry, uint32_t no){
int entrysize = 12; int entrysize = 12;
if (getLongOffsets()){ if (getLongOffsets()){
entrysize = 16; entrysize = 16;
@ -1820,7 +1820,7 @@ namespace MP4 {
} }
} }
afraentry AFRA::getEntry(long no){ afraentry AFRA::getEntry(uint32_t no){
afraentry ret; afraentry ret;
int entrysize = 12; int entrysize = 12;
if (getLongOffsets()){ if (getLongOffsets()){
@ -1835,7 +1835,7 @@ namespace MP4 {
return ret; return ret;
} }
long AFRA::getGlobalEntryCount(){ uint32_t AFRA::getGlobalEntryCount(){
if ( !getGlobalEntries()){ if ( !getGlobalEntries()){
return 0; return 0;
} }
@ -1846,7 +1846,7 @@ namespace MP4 {
return getInt32(13 + entrysize * getEntryCount()); return getInt32(13 + entrysize * getEntryCount());
} }
void AFRA::setGlobalEntry(globalafraentry newEntry, long no){ void AFRA::setGlobalEntry(globalafraentry newEntry, uint32_t no){
int offset = 13 + 12 * getEntryCount() + 4; int offset = 13 + 12 * getEntryCount() + 4;
if (getLongOffsets()){ if (getLongOffsets()){
offset = 13 + 16 * getEntryCount() + 4; offset = 13 + 16 * getEntryCount() + 4;
@ -1880,7 +1880,7 @@ namespace MP4 {
} }
} }
globalafraentry AFRA::getGlobalEntry(long no){ globalafraentry AFRA::getGlobalEntry(uint32_t no){
globalafraentry ret; globalafraentry ret;
int offset = 13 + 12 * getEntryCount() + 4; int offset = 13 + 12 * getEntryCount() + 4;
if (getLongOffsets()){ if (getLongOffsets()){
@ -1912,7 +1912,7 @@ namespace MP4 {
return ret; return ret;
} }
std::string AFRA::toPrettyString(long indent){ std::string AFRA::toPrettyString(uint32_t indent){
std::stringstream r; std::stringstream r;
r << std::string(indent, ' ') << "[afra] Fragment Random Access (" << boxedSize() << ")" << std::endl; r << std::string(indent, ' ') << "[afra] Fragment Random Access (" << boxedSize() << ")" << std::endl;
r << std::string(indent + 1, ' ') << "Version " << getVersion() << std::endl; r << std::string(indent + 1, ' ') << "Version " << getVersion() << std::endl;
@ -1922,9 +1922,9 @@ namespace MP4 {
r << std::string(indent + 1, ' ') << "Global Entries " << getGlobalEntries() << std::endl; r << std::string(indent + 1, ' ') << "Global Entries " << getGlobalEntries() << std::endl;
r << std::string(indent + 1, ' ') << "TimeScale " << getTimeScale() << std::endl; r << std::string(indent + 1, ' ') << "TimeScale " << getTimeScale() << std::endl;
long count = getEntryCount(); uint32_t count = getEntryCount();
r << std::string(indent + 1, ' ') << "Entries (" << count << ") " << std::endl; r << std::string(indent + 1, ' ') << "Entries (" << count << ") " << std::endl;
for (long i = 0; i < count; ++i){ for (uint32_t i = 0; i < count; ++i){
afraentry tmpent = getEntry(i); afraentry tmpent = getEntry(i);
r << std::string(indent + 1, ' ') << i << ": Time " << tmpent.time << ", Offset " << tmpent.offset << std::endl; r << std::string(indent + 1, ' ') << i << ": Time " << tmpent.time << ", Offset " << tmpent.offset << std::endl;
} }
@ -1932,7 +1932,7 @@ namespace MP4 {
if (getGlobalEntries()){ if (getGlobalEntries()){
count = getGlobalEntryCount(); count = getGlobalEntryCount();
r << std::string(indent + 1, ' ') << "Global Entries (" << count << ") " << std::endl; r << std::string(indent + 1, ' ') << "Global Entries (" << count << ") " << std::endl;
for (long i = 0; i < count; ++i){ for (uint32_t i = 0; i < count; ++i){
globalafraentry tmpent = getGlobalEntry(i); globalafraentry tmpent = getGlobalEntry(i);
r << std::string(indent + 1, ' ') << i << ": T " << tmpent.time << ", S" << tmpent.segment << "F" << tmpent.fragment << ", " r << std::string(indent + 1, ' ') << i << ": T " << tmpent.time << ", S" << tmpent.segment << "F" << tmpent.fragment << ", "
<< tmpent.afraoffset << "/" << tmpent.offsetfromafra << std::endl; << tmpent.afraoffset << "/" << tmpent.offsetfromafra << std::endl;
@ -1947,43 +1947,43 @@ namespace MP4 {
setInt8(0xFF, 4); //reserved + 4-bytes NAL length setInt8(0xFF, 4); //reserved + 4-bytes NAL length
} }
void AVCC::setVersion(long newVersion){ void AVCC::setVersion(uint32_t newVersion){
setInt8(newVersion, 0); setInt8(newVersion, 0);
} }
long AVCC::getVersion(){ uint32_t AVCC::getVersion(){
return getInt8(0); return getInt8(0);
} }
void AVCC::setProfile(long newProfile){ void AVCC::setProfile(uint32_t newProfile){
setInt8(newProfile, 1); setInt8(newProfile, 1);
} }
long AVCC::getProfile(){ uint32_t AVCC::getProfile(){
return getInt8(1); return getInt8(1);
} }
void AVCC::setCompatibleProfiles(long newCompatibleProfiles){ void AVCC::setCompatibleProfiles(uint32_t newCompatibleProfiles){
setInt8(newCompatibleProfiles, 2); setInt8(newCompatibleProfiles, 2);
} }
long AVCC::getCompatibleProfiles(){ uint32_t AVCC::getCompatibleProfiles(){
return getInt8(2); return getInt8(2);
} }
void AVCC::setLevel(long newLevel){ void AVCC::setLevel(uint32_t newLevel){
setInt8(newLevel, 3); setInt8(newLevel, 3);
} }
long AVCC::getLevel(){ uint32_t AVCC::getLevel(){
return getInt8(3); return getInt8(3);
} }
void AVCC::setSPSNumber(long newSPSNumber){ void AVCC::setSPSNumber(uint32_t newSPSNumber){
setInt8(newSPSNumber, 5); setInt8(newSPSNumber, 5);
} }
long AVCC::getSPSNumber(){ uint32_t AVCC::getSPSNumber(){
return getInt8(5); return getInt8(5);
} }
@ -1994,7 +1994,7 @@ namespace MP4 {
} //not null-terminated } //not null-terminated
} }
long AVCC::getSPSLen(){ uint32_t AVCC::getSPSLen(){
return getInt16(6); return getInt16(6);
} }
@ -2002,12 +2002,12 @@ namespace MP4 {
return payload() + 8; return payload() + 8;
} }
void AVCC::setPPSNumber(long newPPSNumber){ void AVCC::setPPSNumber(uint32_t newPPSNumber){
int offset = 8 + getSPSLen(); int offset = 8 + getSPSLen();
setInt8(newPPSNumber, offset); setInt8(newPPSNumber, offset);
} }
long AVCC::getPPSNumber(){ uint32_t AVCC::getPPSNumber(){
int offset = 8 + getSPSLen(); int offset = 8 + getSPSLen();
return getInt8(offset); return getInt8(offset);
} }
@ -2020,7 +2020,7 @@ namespace MP4 {
} //not null-terminated } //not null-terminated
} }
long AVCC::getPPSLen(){ uint32_t AVCC::getPPSLen(){
int offset = 8 + getSPSLen() + 1; int offset = 8 + getSPSLen() + 1;
return getInt16(offset); return getInt16(offset);
} }
@ -2030,7 +2030,7 @@ namespace MP4 {
return payload() + offset; return payload() + offset;
} }
std::string AVCC::toPrettyString(long indent){ std::string AVCC::toPrettyString(uint32_t indent){
std::stringstream r; std::stringstream r;
r << std::string(indent, ' ') << "[avcC] H.264 Init Data (" << boxedSize() << ")" << std::endl; r << std::string(indent, ' ') << "[avcC] H.264 Init Data (" << boxedSize() << ")" << std::endl;
r << std::string(indent + 1, ' ') << "Version: " << getVersion() << std::endl; r << std::string(indent + 1, ' ') << "Version: " << getVersion() << std::endl;
@ -2065,19 +2065,19 @@ namespace MP4 {
memcpy(data + 4, "sdtp", 4); memcpy(data + 4, "sdtp", 4);
} }
void SDTP::setVersion(long newVersion){ void SDTP::setVersion(uint32_t newVersion){
setInt8(newVersion, 0); setInt8(newVersion, 0);
} }
long SDTP::getVersion(){ uint32_t SDTP::getVersion(){
return getInt8(0); return getInt8(0);
} }
void SDTP::setValue(long newValue, size_t index){ void SDTP::setValue(uint32_t newValue, size_t index){
setInt8(newValue, index); setInt8(newValue, index);
} }
long SDTP::getValue(size_t index){ uint32_t SDTP::getValue(size_t index){
getInt8(index); getInt8(index);
} }
} }

268
lib/mp4.h
View file

@ -19,8 +19,8 @@ namespace MP4 {
std::string getType(); std::string getType();
bool isType(const char* boxType); bool isType(const char* boxType);
bool read(std::string & newData); bool read(std::string & newData);
long long int boxedSize(); uint64_t boxedSize();
long long int payloadSize(); uint64_t payloadSize();
char * asBox(); char * asBox();
char * payload(); char * payload();
void clear(); void clear();
@ -31,12 +31,12 @@ namespace MP4 {
char getInt8(size_t index); char getInt8(size_t index);
void setInt16(short newData, size_t index); void setInt16(short newData, size_t index);
short getInt16(size_t index); short getInt16(size_t index);
void setInt24(long newData, size_t index); void setInt24(uint32_t newData, size_t index);
long getInt24(size_t index); uint32_t getInt24(size_t index);
void setInt32(long newData, size_t index); void setInt32(uint32_t newData, size_t index);
long getInt32(size_t index); uint32_t getInt32(size_t index);
void setInt64(long long int newData, size_t index); void setInt64(uint64_t newData, size_t index);
long long int getInt64(size_t index); uint64_t getInt64(size_t index);
//string functions //string functions
void setString(std::string newData, size_t index); void setString(std::string newData, size_t index);
void setString(char* newData, size_t size, size_t index); void setString(char* newData, size_t size, size_t index);
@ -57,10 +57,10 @@ namespace MP4 {
//Box Class //Box Class
struct afrt_runtable{ struct afrt_runtable{
long firstFragment; uint32_t firstFragment;
long long int firstTimestamp; uint64_t firstTimestamp;
long duration; uint32_t duration;
long discontinuity; uint32_t discontinuity;
}; };
//fragmentRun //fragmentRun
@ -69,24 +69,24 @@ namespace MP4 {
public: public:
AFRT(); AFRT();
void setVersion(char newVersion); void setVersion(char newVersion);
long getVersion(); uint32_t getVersion();
void setUpdate(long newUpdate); void setUpdate(uint32_t newUpdate);
long getUpdate(); uint32_t getUpdate();
void setTimeScale(long newScale); void setTimeScale(uint32_t newScale);
long getTimeScale(); uint32_t getTimeScale();
long getQualityEntryCount(); uint32_t getQualityEntryCount();
void setQualityEntry(std::string & newQuality, long no); void setQualityEntry(std::string & newQuality, uint32_t no);
const char * getQualityEntry(long no); const char * getQualityEntry(uint32_t no);
long getFragmentRunCount(); uint32_t getFragmentRunCount();
void setFragmentRun(afrt_runtable newRun, long no); void setFragmentRun(afrt_runtable newRun, uint32_t no);
afrt_runtable getFragmentRun(long no); afrt_runtable getFragmentRun(uint32_t no);
std::string toPrettyString(int indent = 0); std::string toPrettyString(int indent = 0);
}; };
//AFRT Box //AFRT Box
struct asrt_runtable{ struct asrt_runtable{
long firstSegment; uint32_t firstSegment;
long fragmentsPerSegment; uint32_t fragmentsPerSegment;
}; };
/// ASRT Box class /// ASRT Box class
@ -94,15 +94,15 @@ namespace MP4 {
public: public:
ASRT(); ASRT();
void setVersion(char newVersion); void setVersion(char newVersion);
long getVersion(); uint32_t getVersion();
void setUpdate(long newUpdate); void setUpdate(uint32_t newUpdate);
long getUpdate(); uint32_t getUpdate();
long getQualityEntryCount(); uint32_t getQualityEntryCount();
void setQualityEntry(std::string & newQuality, long no); void setQualityEntry(std::string & newQuality, uint32_t no);
const char* getQualityEntry(long no); const char* getQualityEntry(uint32_t no);
long getSegmentRunEntryCount(); uint32_t getSegmentRunEntryCount();
void setSegmentRun(long firstSegment, long fragmentsPerSegment, long no); void setSegmentRun(uint32_t firstSegment, uint32_t fragmentsPerSegment, uint32_t no);
asrt_runtable getSegmentRun(long no); asrt_runtable getSegmentRun(uint32_t no);
std::string toPrettyString(int indent = 0); std::string toPrettyString(int indent = 0);
}; };
//ASRT Box //ASRT Box
@ -113,49 +113,49 @@ namespace MP4 {
ABST(); ABST();
void setVersion(char newVersion); void setVersion(char newVersion);
char getVersion(); char getVersion();
void setFlags(long newFlags); void setFlags(uint32_t newFlags);
long getFlags(); uint32_t getFlags();
void setBootstrapinfoVersion(long newVersion); void setBootstrapinfoVersion(uint32_t newVersion);
long getBootstrapinfoVersion(); uint32_t getBootstrapinfoVersion();
void setProfile(char newProfile); void setProfile(char newProfile);
char getProfile(); char getProfile();
void setLive(bool newLive); void setLive(bool newLive);
bool getLive(); bool getLive();
void setUpdate(bool newUpdate); void setUpdate(bool newUpdate);
bool getUpdate(); bool getUpdate();
void setTimeScale(long newTimeScale); void setTimeScale(uint32_t newTimeScale);
long getTimeScale(); uint32_t getTimeScale();
void setCurrentMediaTime(long long int newTime); void setCurrentMediaTime(uint64_t newTime);
long long int getCurrentMediaTime(); uint64_t getCurrentMediaTime();
void setSmpteTimeCodeOffset(long long int newTime); void setSmpteTimeCodeOffset(uint64_t newTime);
long long int getSmpteTimeCodeOffset(); uint64_t getSmpteTimeCodeOffset();
void setMovieIdentifier(std::string & newIdentifier); void setMovieIdentifier(std::string & newIdentifier);
char * getMovieIdentifier(); char * getMovieIdentifier();
long getServerEntryCount(); uint32_t getServerEntryCount();
void setServerEntry(std::string & entry, long no); void setServerEntry(std::string & entry, uint32_t no);
const char * getServerEntry(long no); const char * getServerEntry(uint32_t no);
long getQualityEntryCount(); uint32_t getQualityEntryCount();
void setQualityEntry(std::string & entry, long no); void setQualityEntry(std::string & entry, uint32_t no);
const char * getQualityEntry(long no); const char * getQualityEntry(uint32_t no);
void setDrmData(std::string newDrm); void setDrmData(std::string newDrm);
char * getDrmData(); char * getDrmData();
void setMetaData(std::string newMetaData); void setMetaData(std::string newMetaData);
char * getMetaData(); char * getMetaData();
long getSegmentRunTableCount(); uint32_t getSegmentRunTableCount();
void setSegmentRunTable(ASRT & table, long no); void setSegmentRunTable(ASRT & table, uint32_t no);
ASRT & getSegmentRunTable(long no); ASRT & getSegmentRunTable(uint32_t no);
long getFragmentRunTableCount(); uint32_t getFragmentRunTableCount();
void setFragmentRunTable(AFRT & table, long no); void setFragmentRunTable(AFRT & table, uint32_t no);
AFRT & getFragmentRunTable(long no); AFRT & getFragmentRunTable(uint32_t no);
std::string toPrettyString(long indent = 0); std::string toPrettyString(uint32_t indent = 0);
}; };
//ABST Box //ABST Box
class MFHD: public Box{ class MFHD: public Box{
public: public:
MFHD(); MFHD();
void setSequenceNumber(long newSequenceNumber); void setSequenceNumber(uint32_t newSequenceNumber);
long getSequenceNumber(); uint32_t getSequenceNumber();
std::string toPrettyString(int indent = 0); std::string toPrettyString(int indent = 0);
}; };
//MFHD Box //MFHD Box
@ -163,9 +163,9 @@ namespace MP4 {
class MOOF: public Box{ class MOOF: public Box{
public: public:
MOOF(); MOOF();
long getContentCount(); uint32_t getContentCount();
void setContent(Box & newContent, long no); void setContent(Box & newContent, uint32_t no);
Box & getContent(long no); Box & getContent(uint32_t no);
std::string toPrettyString(int indent = 0); std::string toPrettyString(int indent = 0);
}; };
//MOOF Box //MOOF Box
@ -173,18 +173,18 @@ namespace MP4 {
class TRAF: public Box{ class TRAF: public Box{
public: public:
TRAF(); TRAF();
long getContentCount(); uint32_t getContentCount();
void setContent(Box & newContent, long no); void setContent(Box & newContent, uint32_t no);
Box & getContent(long no); Box & getContent(uint32_t no);
std::string toPrettyString(int indent = 0); std::string toPrettyString(int indent = 0);
}; };
//TRAF Box //TRAF Box
struct trunSampleInformation{ struct trunSampleInformation{
long sampleDuration; uint32_t sampleDuration;
long sampleSize; uint32_t sampleSize;
long sampleFlags; uint32_t sampleFlags;
long sampleOffset; uint32_t sampleOffset;
}; };
enum trunflags{ enum trunflags{
trundataOffset = 0x00000001, trundataOffset = 0x00000001,
@ -205,20 +205,20 @@ namespace MP4 {
isKeySample = 0x00000000, isKeySample = 0x00000000,
MUST_BE_PRESENT = 0x1 MUST_BE_PRESENT = 0x1
}; };
std::string prettySampleFlags(long flag); std::string prettySampleFlags(uint32_t flag);
class TRUN: public Box{ class TRUN: public Box{
public: public:
TRUN(); TRUN();
void setFlags(long newFlags); void setFlags(uint32_t newFlags);
long getFlags(); uint32_t getFlags();
void setDataOffset(long newOffset); void setDataOffset(uint32_t newOffset);
long getDataOffset(); uint32_t getDataOffset();
void setFirstSampleFlags(long newSampleFlags); void setFirstSampleFlags(uint32_t newSampleFlags);
long getFirstSampleFlags(); uint32_t getFirstSampleFlags();
long getSampleInformationCount(); uint32_t getSampleInformationCount();
void setSampleInformation(trunSampleInformation newSample, long no); void setSampleInformation(trunSampleInformation newSample, uint32_t no);
trunSampleInformation getSampleInformation(long no); trunSampleInformation getSampleInformation(uint32_t no);
std::string toPrettyString(long indent = 0); std::string toPrettyString(uint32_t indent = 0);
}; };
enum tfhdflags{ enum tfhdflags{
@ -232,91 +232,91 @@ namespace MP4 {
class TFHD: public Box{ class TFHD: public Box{
public: public:
TFHD(); TFHD();
void setFlags(long newFlags); void setFlags(uint32_t newFlags);
long getFlags(); uint32_t getFlags();
void setTrackID(long newID); void setTrackID(uint32_t newID);
long getTrackID(); uint32_t getTrackID();
void setBaseDataOffset(long long newOffset); void setBaseDataOffset(uint64_t newOffset);
long long getBaseDataOffset(); uint64_t getBaseDataOffset();
void setSampleDescriptionIndex(long newIndex); void setSampleDescriptionIndex(uint32_t newIndex);
long getSampleDescriptionIndex(); uint32_t getSampleDescriptionIndex();
void setDefaultSampleDuration(long newDuration); void setDefaultSampleDuration(uint32_t newDuration);
long getDefaultSampleDuration(); uint32_t getDefaultSampleDuration();
void setDefaultSampleSize(long newSize); void setDefaultSampleSize(uint32_t newSize);
long getDefaultSampleSize(); uint32_t getDefaultSampleSize();
void setDefaultSampleFlags(long newFlags); void setDefaultSampleFlags(uint32_t newFlags);
long getDefaultSampleFlags(); uint32_t getDefaultSampleFlags();
std::string toPrettyString(long indent = 0); std::string toPrettyString(uint32_t indent = 0);
}; };
struct afraentry{ struct afraentry{
long long time; uint64_t time;
long long offset; uint64_t offset;
}; };
struct globalafraentry{ struct globalafraentry{
long long time; uint64_t time;
long segment; uint32_t segment;
long fragment; uint32_t fragment;
long long afraoffset; uint64_t afraoffset;
long long offsetfromafra; uint64_t offsetfromafra;
}; };
class AFRA: public Box{ class AFRA: public Box{
public: public:
AFRA(); AFRA();
void setVersion(long newVersion); void setVersion(uint32_t newVersion);
long getVersion(); uint32_t getVersion();
void setFlags(long newFlags); void setFlags(uint32_t newFlags);
long getFlags(); uint32_t getFlags();
void setLongIDs(bool newVal); void setLongIDs(bool newVal);
bool getLongIDs(); bool getLongIDs();
void setLongOffsets(bool newVal); void setLongOffsets(bool newVal);
bool getLongOffsets(); bool getLongOffsets();
void setGlobalEntries(bool newVal); void setGlobalEntries(bool newVal);
bool getGlobalEntries(); bool getGlobalEntries();
void setTimeScale(long newVal); void setTimeScale(uint32_t newVal);
long getTimeScale(); uint32_t getTimeScale();
long getEntryCount(); uint32_t getEntryCount();
void setEntry(afraentry newEntry, long no); void setEntry(afraentry newEntry, uint32_t no);
afraentry getEntry(long no); afraentry getEntry(uint32_t no);
long getGlobalEntryCount(); uint32_t getGlobalEntryCount();
void setGlobalEntry(globalafraentry newEntry, long no); void setGlobalEntry(globalafraentry newEntry, uint32_t no);
globalafraentry getGlobalEntry(long no); globalafraentry getGlobalEntry(uint32_t no);
std::string toPrettyString(long indent = 0); std::string toPrettyString(uint32_t indent = 0);
}; };
class AVCC: public Box{ class AVCC: public Box{
public: public:
AVCC(); AVCC();
void setVersion(long newVersion); void setVersion(uint32_t newVersion);
long getVersion(); uint32_t getVersion();
void setProfile(long newProfile); void setProfile(uint32_t newProfile);
long getProfile(); uint32_t getProfile();
void setCompatibleProfiles(long newCompatibleProfiles); void setCompatibleProfiles(uint32_t newCompatibleProfiles);
long getCompatibleProfiles(); uint32_t getCompatibleProfiles();
void setLevel(long newLevel); void setLevel(uint32_t newLevel);
long getLevel(); uint32_t getLevel();
void setSPSNumber(long newSPSNumber); void setSPSNumber(uint32_t newSPSNumber);
long getSPSNumber(); uint32_t getSPSNumber();
void setSPS(std::string newSPS); void setSPS(std::string newSPS);
long getSPSLen(); uint32_t getSPSLen();
char* getSPS(); char* getSPS();
void setPPSNumber(long newPPSNumber); void setPPSNumber(uint32_t newPPSNumber);
long getPPSNumber(); uint32_t getPPSNumber();
void setPPS(std::string newPPS); void setPPS(std::string newPPS);
long getPPSLen(); uint32_t getPPSLen();
char* getPPS(); char* getPPS();
std::string asAnnexB(); std::string asAnnexB();
void setPayload(std::string newPayload); void setPayload(std::string newPayload);
std::string toPrettyString(long indent = 0); std::string toPrettyString(uint32_t indent = 0);
}; };
class SDTP: public Box{ class SDTP: public Box{
public: public:
SDTP(); SDTP();
void setVersion(long newVersion); void setVersion(uint32_t newVersion);
long getVersion(); uint32_t getVersion();
void setValue(long newValue, size_t index); void setValue(uint32_t newValue, size_t index);
long getValue(size_t index); uint32_t getValue(size_t index);
}; };
} }