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 |   MIN & MAX
00043 +---------------------------------------------------------------------*/
00044 #define MIN(a,b) (a<b)?a:b
00045 #define MAX(a,b) (a>b)?a:b
00046 
00047 /*----------------------------------------------------------------------
00048 |   byte I/O
00049 +---------------------------------------------------------------------*/
00050 AP4_UI64 AP4_BytesToUInt64BE(const unsigned char* bytes);
00051 AP4_UI32 AP4_BytesToUInt32BE(const unsigned char* bytes);
00052 AP4_UI32 AP4_BytesToUInt24BE(const unsigned char* bytes);
00053 AP4_UI16 AP4_BytesToUInt16BE(const unsigned char* bytes);
00054 
00055 AP4_SI32 AP4_BytesToInt32BE(const unsigned char* bytes);
00056 AP4_SI16 AP4_BytesToInt16BE(const unsigned char* bytes);
00057 
00058 void AP4_BytesFromUInt64BE(unsigned char* bytes, AP4_UI64 value);
00059 void AP4_BytesFromUInt32BE(unsigned char* bytes, AP4_UI32 value);
00060 void AP4_BytesFromUInt24BE(unsigned char* bytes, AP4_UI32 value);
00061 void AP4_BytesFromUInt16BE(unsigned char* bytes, AP4_UI16 value);
00062 unsigned long AP4_DurationMsFromUnits(unsigned long units, 
00063                                       unsigned long units_per_second);
00064 unsigned long AP4_ConvertTime(unsigned long time_value,
00065                               unsigned long from_time_scale,
00066                               unsigned long to_time_scale);
00067 
00068 /*----------------------------------------------------------------------
00069 |   string utils
00070 +---------------------------------------------------------------------*/
00071 #if defined (AP4_CONFIG_HAVE_STDIO_H)
00072 #include <stdio.h>
00073 #endif
00074 
00075 #if defined (AP4_CONFIG_HAVE_SNPRINTF)
00076 #define AP4_FormatString AP4_snprintf
00077 #else
00078 int AP4_FormatString(char* str, AP4_Size size, const char* format, ...);
00079 #endif
00080 #if defined(AP4_CONFIG_HAVE_VSNPRINTF)
00081 #define AP4_FormatStringVN(s,c,f,a) AP4_vsnprintf(s,c,f,a)
00082 #else
00083 extern int AP4_FormatStringVN(char *buffer, size_t count, const char *format, va_list argptr);
00084 #endif
00085 
00086 #if defined (AP4_CONFIG_HAVE_STRING_H)
00087 #include <string.h>
00088 #define AP4_StringLength(x) strlen(x)
00089 #define AP4_CopyMemory(x,y,z) memcpy(x,y,z)
00090 #define AP4_SetMemory(x,y,z) memset(x,y,z)
00091 #define AP4_CompareStrings(x,y) strcmp(x,y)
00092 #endif
00093 
00094 void AP4_FormatFourChars(char* str, AP4_UI32 value);
00095 void AP4_FormatFourCharsPrintable(char* str, AP4_UI32 value);
00096 AP4_Result
00097 AP4_ParseHex(const char* hex, unsigned char* bytes, unsigned int count);
00098 AP4_Result
00099 AP4_SplitArgs(char* arg, char*& arg0, char*& arg1, char*& arg2);
00100 AP4_Result
00101 AP4_SplitArgs(char* arg, char*& arg0, char*& arg1);
00102 
00103 /*----------------------------------------------------------------------
00104 |   AP4_PrintInspector
00105 +---------------------------------------------------------------------*/
00106 class AP4_PrintInspector : public AP4_AtomInspector {
00107 public:
00108     AP4_PrintInspector(AP4_ByteStream& stream);
00109     ~AP4_PrintInspector();
00110 
00111     // methods
00112     void StartElement(const char* name, const char* info);
00113     void EndElement();
00114     void AddField(const char* name, AP4_UI32 value, FormatHint hint);
00115     void AddField(const char* name, const char* value, FormatHint hint);
00116     void AddField(const char* name, const unsigned char* bytes, AP4_Size size, FormatHint hint);
00117 
00118 private:
00119     // members
00120     AP4_ByteStream* m_Stream;
00121     AP4_Cardinal    m_Indent;
00122 };
00123 
00124 
00125 #endif // _AP4_UTILS_H_

Generated on Thu Mar 15 16:06:12 2007 for Bento4 MP4 SDK by  doxygen 1.5.1-p1