- Main Page
- Classes
- Files

# Ap4Utils.h

Go to the documentation of this file.

    00001 /*****************************************************************
    00002 |
    00003 |    AP4 - Utilities
    00004 |
    00005 |    Copyright 2002-2006 Gilles Boccon-Gibod & Julien Boeuf
    00006 |
    00007 |
    00008 |    This file is part of Bento4/AP4 (MP4 Atom Processing Library).
    00009 |
    00010 |    Unless you have obtained Bento4 under a difference license,
    00011 |    this version of Bento4 is Bento4|GPL.
    00012 |    Bento4|GPL is free software; you can redistribute it and/or modify
    00013 |    it under the terms of the GNU General Public License as published by
    00014 |    the Free Software Foundation; either version 2, or (at your option)
    00015 |    any later version.
    00016 |
    00017 |    Bento4|GPL is distributed in the hope that it will be useful,
    00018 |    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00019 |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00020 |    GNU General Public License for more details.
    00021 |
    00022 |    You should have received a copy of the GNU General Public License
    00023 |    along with Bento4|GPL; see the file COPYING.  If not, write to the
    00024 |    Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    00025 |    02111-1307, USA.
    00026 |
    00027  ****************************************************************/
    00028
    00029 #ifndef _AP4_UTILS_H_
    00030 #define _AP4_UTILS_H_
    00031
    00032 /*----------------------------------------------------------------------
    00033 |   includes
    00034 +---------------------------------------------------------------------*/
    00035 #include "Ap4Config.h"
    00036 #include "Ap4Types.h"
    00037 #include "Ap4Results.h"
    00038 #include "Ap4Config.h"
    00039 #include "Ap4Atom.h"
    00040
    00041 /*----------------------------------------------------------------------
    00042 |   byte I/O
    00043 +---------------------------------------------------------------------*/
    00044 double   AP4_BytesToDoubleBE(const unsigned char* bytes);
    00045 AP4_UI64 AP4_BytesToUInt64BE(const unsigned char* bytes);
    00046 AP4_UI32 AP4_BytesToUInt32BE(const unsigned char* bytes);
    00047 AP4_UI32 AP4_BytesToUInt24BE(const unsigned char* bytes);
    00048 AP4_UI16 AP4_BytesToUInt16BE(const unsigned char* bytes);
    00049 AP4_SI32 AP4_BytesToInt32BE(const unsigned char* bytes);
    00050 AP4_SI16 AP4_BytesToInt16BE(const unsigned char* bytes);
    00051
    00052 void AP4_BytesFromDoubleBE(unsigned char* bytes, double value);
    00053 void AP4_BytesFromUInt64BE(unsigned char* bytes, AP4_UI64 value);
    00054 void AP4_BytesFromUInt32BE(unsigned char* bytes, AP4_UI32 value);
    00055 void AP4_BytesFromUInt24BE(unsigned char* bytes, AP4_UI32 value);
    00056 void AP4_BytesFromUInt16BE(unsigned char* bytes, AP4_UI16 value);
    00057 unsigned long AP4_DurationMsFromUnits(unsigned long units,
    00058                                       unsigned long units_per_second);
    00059 unsigned long AP4_ConvertTime(unsigned long time_value,
    00060                               unsigned long from_time_scale,
    00061                               unsigned long to_time_scale);
    00062
    00063 /*----------------------------------------------------------------------
    00064 |   string utils
    00065 +---------------------------------------------------------------------*/
    00066 #if defined (AP4_CONFIG_HAVE_STDIO_H)
    00067 #include <stdio.h>
    00068 #endif
    00069
    00070 #if defined (AP4_CONFIG_HAVE_SNPRINTF)
    00071 #define AP4_FormatString AP4_snprintf
    00072 #else
    00073 int AP4_FormatString(char* str, AP4_Size size, const char* format, ...);
    00074 #endif
    00075 #if defined(AP4_CONFIG_HAVE_VSNPRINTF)
    00076 #define AP4_FormatStringVN(s,c,f,a) AP4_vsnprintf(s,c,f,a)
    00077 #else
    00078 extern int AP4_FormatStringVN(char *buffer, size_t count, const char *format, va_list argptr);
    00079 #endif
    00080
    00081 #if defined (AP4_CONFIG_HAVE_STRING_H)
    00082 #include <string.h>
    00083 #define AP4_StringLength(x) strlen(x)
    00084 #define AP4_CopyMemory(x,y,z) memcpy(x,y,z)
    00085 #define AP4_SetMemory(x,y,z) memset(x,y,z)
    00086 #define AP4_CompareStrings(x,y) strcmp(x,y)
    00087 #endif
    00088
    00089 void AP4_FormatFourChars(char* str, AP4_UI32 value);
    00090 void AP4_FormatFourCharsPrintable(char* str, AP4_UI32 value);
    00091 AP4_Result
    00092 AP4_ParseHex(const char* hex, unsigned char* bytes, unsigned int count);
    00093 AP4_Result
    00094 AP4_SplitArgs(char* arg, char*& arg0, char*& arg1, char*& arg2);
    00095 AP4_Result
    00096 AP4_SplitArgs(char* arg, char*& arg0, char*& arg1);
    00097
    00098 /*----------------------------------------------------------------------
    00099 |   AP4_PrintInspector
    00100 +---------------------------------------------------------------------*/
    00101 class AP4_PrintInspector : public AP4_AtomInspector {
    00102 public:
    00103     AP4_PrintInspector(AP4_ByteStream& stream);
    00104     ~AP4_PrintInspector();
    00105
    00106     // methods
    00107     void StartElement(const char* name, const char* info);
    00108     void EndElement();
    00109     void AddField(const char* name, AP4_UI32 value, FormatHint hint);
    00110     void AddField(const char* name, const char* value, FormatHint hint);
    00111     void AddField(const char* name, const unsigned char* bytes, AP4_Size size, FormatHint hint);
    00112
    00113 private:
    00114     // members
    00115     AP4_ByteStream* m_Stream;
    00116     AP4_Cardinal    m_Indent;
    00117 };
    00118
    00119
    00120 #endif // _AP4_UTILS_H_