00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _AP4_UTILS_H_
00030 #define _AP4_UTILS_H_
00031
00032
00033
00034
00035 #include "Ap4.h"
00036 #include "Ap4Config.h"
00037 #include "Ap4Atom.h"
00038
00039
00040
00041
00042 #define MIN(a,b) (a<b)?a:b
00043 #define MAX(a,b) (a>b)?a:b
00044
00045
00046
00047
00048 unsigned long long AP4_BytesToUInt64BE(const unsigned char* bytes);
00049 unsigned long AP4_BytesToUInt32BE(const unsigned char* bytes);
00050 unsigned long AP4_BytesToUInt24BE(const unsigned char* bytes);
00051 unsigned short AP4_BytesToUInt16BE(const unsigned char* bytes);
00052 void AP4_BytesFromUInt64BE(unsigned char* bytes, unsigned long long value);
00053 void AP4_BytesFromUInt32BE(unsigned char* bytes, unsigned long value);
00054 void AP4_BytesFromUInt24BE(unsigned char* bytes, unsigned long value);
00055 void AP4_BytesFromUInt16BE(unsigned char* bytes, unsigned short value);
00056 unsigned long AP4_DurationMsFromUnits(unsigned long units,
00057 unsigned long units_per_second);
00058 unsigned long AP4_ConvertTime(unsigned long time_value,
00059 unsigned long from_time_scale,
00060 unsigned long to_time_scale);
00061
00062
00063
00064
00065 #if defined (AP4_CONFIG_HAVE_STDIO_H)
00066 #include <stdio.h>
00067 #endif
00068
00069 #if defined (AP4_CONFIG_HAVE_SNPRINTF)
00070 #define AP4_StringFormat snprintf
00071 #else
00072 int AP4_StringFormat(char* str, AP4_Size size, const char* format, ...);
00073 #endif
00074
00075 void AP4_FormatFourChars(char* str, AP4_UI32 value);
00076 AP4_Result
00077 AP4_ParseHex(const char* hex, unsigned char* bytes, unsigned int count);
00078 AP4_Result
00079 AP4_SplitArgs(char* arg, char*& arg0, char*& arg1, char*& arg2);
00080 AP4_Result
00081 AP4_SplitArgs(char* arg, char*& arg0, char*& arg1);
00082
00083
00084
00085
00086 class AP4_PrintInspector : public AP4_AtomInspector {
00087 public:
00088 AP4_PrintInspector(AP4_ByteStream& stream);
00089 ~AP4_PrintInspector();
00090
00091
00092 void StartElement(const char* name, const char* info);
00093 void EndElement();
00094 void AddField(const char* name, AP4_UI32 value, FormatHint hint);
00095 void AddField(const char* name, const char* value, FormatHint hint);
00096
00097 private:
00098
00099 AP4_ByteStream* m_Stream;
00100 AP4_Cardinal m_Indent;
00101 };
00102
00103 #endif // _AP4_UTILS_H_