MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
mp4.h
Go to the documentation of this file.
1 #pragma once
2 #include <string>
3 #include <vector>
4 #include <set>
5 #include <iostream>
6 #include <iomanip>
7 #include <cstdio>
8 #include <stdint.h>
9 #include <sstream>
10 #include <deque>
11 #include <algorithm>
12 #include <vector>
13 #include "json.h"
14 #include "dtsc.h"
15 
17 namespace MP4 {
18  std::string readBoxType(FILE * newData);
19  bool skipBox(FILE * newData);
20 
21 
22  class Box {
23  public:
24  Box(char * datapointer = 0, bool manage = true);
25  Box(const Box & rs);
26  Box & operator = (const Box & rs);
27  ~Box();
28  std::string getType();
29  bool isType(const char * boxType);
30  bool read(FILE * newData);
31  bool read(std::string & newData);
32  uint64_t boxedSize();
33  uint64_t payloadSize();
34  char * asBox();
35  char * payload();
36  void clear();
37  std::string toPrettyString(uint32_t indent = 0);
38  protected:
39  //integer functions
40  void setInt8(char newData, size_t index);
41  char getInt8(size_t index);
42  void setInt16(short newData, size_t index);
43  short getInt16(size_t index);
44  void setInt24(uint32_t newData, size_t index);
45  uint32_t getInt24(size_t index);
46  void setInt32(uint32_t newData, size_t index);
47  uint32_t getInt32(size_t index);
48  void setInt64(uint64_t newData, size_t index);
49  uint64_t getInt64(size_t index);
50  //string functions
51  void setString(std::string newData, size_t index);
52  void setString(char * newData, size_t size, size_t index);
53  char * getString(size_t index);
54  size_t getStringLen(size_t index);
55  //box functions
56  Box & getBox(size_t index);
57  size_t getBoxLen(size_t index);
58  void setBox(Box & newEntry, size_t index);
59  //data functions
60  bool reserve(size_t position, size_t current, size_t wanted);
61  //internal variables
62  char * data;
63  unsigned int data_size;
64  bool managed;
65  unsigned int payloadOffset;
66  };
67  //Box Class
68 
69  class fullBox: public Box {
70  public:
71  fullBox();
72  void setVersion(char newVersion);
73  char getVersion();
74  void setFlags(uint32_t newFlags);
75  uint32_t getFlags();
76  std::string toPrettyString(uint32_t indent = 0);
77  };
78 
79  class containerBox: public Box {
80  public:
81  containerBox();
82  uint32_t getContentCount();
83  void setContent(Box & newContent, uint32_t no);
84  Box & getContent(uint32_t no);
85  std::string toPrettyString(uint32_t indent = 0);
86  };
87 
88  class containerFullBox: public fullBox {
89  public:
90  uint32_t getContentCount();
91  void setContent(Box & newContent, uint32_t no);
92  Box & getContent(uint32_t no);
93  std::string toPrettyCFBString(uint32_t indent, std::string boxName);
94  };
95 }
uint64_t getInt64(size_t index)
Gets the 64 bits integer at the given index.
Definition: mp4.cpp:583
void setBox(Box &newEntry, size_t index)
Replaces the existing box at the given index by the new box newEntry.
Definition: mp4.cpp:677
void setString(std::string newData, size_t index)
Sets the NULL-terminated string at the given index.
Definition: mp4.cpp:600
size_t getStringLen(size_t index)
Returns the length of the NULL-terminated string at the given index.
Definition: mp4.cpp:639
unsigned int payloadOffset
The offset of the payload with regards to the data.
Definition: mp4.h:65
Contains all MP4 format related code.
Definition: mp4.cpp:15
std::string getType()
Returns the values at byte positions 4 through 7.
Definition: mp4.cpp:71
unsigned int data_size
Currently reserved size.
Definition: mp4.h:63
char * payload()
Definition: mp4.cpp:203
short getInt16(size_t index)
Gets the 16 bits integer at the given index.
Definition: mp4.cpp:492
uint32_t getInt32(size_t index)
Gets the 32 bits integer at the given index.
Definition: mp4.cpp:555
size_t getBoxLen(size_t index)
Returns the size of the box at the given position.
Definition: mp4.cpp:668
std::string readBoxType(FILE *newData)
Reads the first 8 bytes and returns.
Definition: mp4.cpp:81
bool managed
If false, will not attempt to resize/free the data pointer.
Definition: mp4.h:64
Box(char *datapointer=0, bool manage=true)
Creates a new box, optionally using the indicated pointer for storage.
Definition: mp4.cpp:21
void setInt8(char newData, size_t index)
Sets the 8 bits integer at the given index.
Definition: mp4.cpp:451
Box & getBox(size_t index)
Gets a reference to the box at the given index.
Definition: mp4.cpp:651
char * getString(size_t index)
Gets the NULL-terminated string at the given index.
Definition: mp4.cpp:626
char * asBox()
Returns a copy of the data pointer.
Definition: mp4.cpp:199
bool read(FILE *newData)
Definition: mp4.cpp:122
bool reserve(size_t position, size_t current, size_t wanted)
Attempts to reserve enough space for wanted bytes of data at given position, where current bytes of d...
Definition: mp4.cpp:689
bool isType(const char *boxType)
Returns true if the given 4-byte boxtype is equal to the values at byte positions 4 through 7...
Definition: mp4.cpp:76
void setInt64(uint64_t newData, size_t index)
Sets the 64 bits integer at the given index.
Definition: mp4.cpp:569
void setInt24(uint32_t newData, size_t index)
Sets the 24 bits integer at the given index.
Definition: mp4.cpp:508
uint64_t payloadSize()
Retruns the size of the payload of thix box, excluding the header.
Definition: mp4.cpp:194
Box & operator=(const Box &rs)
Definition: mp4.cpp:44
char * data
Holds the data of this box.
Definition: mp4.h:62
void setInt16(short newData, size_t index)
Sets the 16 bits integer at the given index.
Definition: mp4.cpp:478
void clear()
Makes this box managed if it wasn&#39;t already, resetting the internal storage to 8 bytes (the minimum)...
Definition: mp4.cpp:210
~Box()
If managed, this will free the data pointer.
Definition: mp4.cpp:63
std::string toPrettyString(uint32_t indent=0)
Attempts to typecast this Box to a more specific type and call the toPrettyString() function of that ...
Definition: mp4.cpp:227
bool skipBox(FILE *newData)
Definition: mp4.cpp:94
uint64_t boxedSize()
Returns the total boxed size of this box, including the header.
Definition: mp4.cpp:185
char getInt8(size_t index)
Gets the 8 bits integer at the given index.
Definition: mp4.cpp:464
uint32_t getInt24(size_t index)
Gets the 24 bits integer at the given index.
Definition: mp4.cpp:523
void setInt32(uint32_t newData, size_t index)
Sets the 32 bits integer at the given index.
Definition: mp4.cpp:542