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
00030
00031
00032 #include "Ap4.h"
00033 #include "Ap4HdlrAtom.h"
00034 #include "Ap4AtomFactory.h"
00035 #include "Ap4Utils.h"
00036
00037
00038
00039
00040 AP4_HdlrAtom::AP4_HdlrAtom(AP4_Atom::Type hdlr_type, const char* hdlr_name) :
00041 AP4_Atom(AP4_ATOM_TYPE_HDLR, true),
00042 m_HandlerType(hdlr_type),
00043 m_HandlerName(hdlr_name)
00044 {
00045 m_Size += 20+m_HandlerName.length()+1;
00046 }
00047
00048
00049
00050
00051 AP4_HdlrAtom::AP4_HdlrAtom(AP4_Size size, AP4_ByteStream& stream) :
00052 AP4_Atom(AP4_ATOM_TYPE_HDLR, size, true, stream)
00053 {
00054 unsigned char reserved[12];
00055 stream.Read(reserved, 4, NULL);
00056 stream.ReadUI32(m_HandlerType);
00057 stream.Read(reserved, 12, NULL);
00058
00059
00060 int name_size = size-(AP4_FULL_ATOM_HEADER_SIZE+20);
00061 if (name_size > 0) {
00062 char* name = new char[name_size+1];
00063 stream.Read(name, name_size);
00064 name[name_size] = '\0';
00065 m_HandlerName = name;
00066 delete[] name;
00067 }
00068 }
00069
00070
00071
00072
00073 AP4_Result
00074 AP4_HdlrAtom::WriteFields(AP4_ByteStream& stream)
00075 {
00076 AP4_Result result;
00077
00078
00079 unsigned char reserved[12];
00080 memset(reserved, 0, sizeof(reserved));
00081 result = stream.Write(reserved, 4);
00082 if (AP4_FAILED(result)) return result;
00083 result = stream.WriteUI32(m_HandlerType);
00084 if (AP4_FAILED(result)) return result;
00085 result = stream.Write(reserved, 12);
00086 if (AP4_FAILED(result)) return result;
00087 result = stream.Write(m_HandlerName.c_str(),
00088 m_HandlerName.length()+1);
00089 if (AP4_FAILED(result)) return result;
00090
00091
00092 AP4_Size padding = m_Size-(AP4_FULL_ATOM_HEADER_SIZE+20+m_HandlerName.length()+1);
00093 while (padding--) stream.WriteUI08(0);
00094
00095 return AP4_SUCCESS;
00096 }
00097
00098
00099
00100
00101 AP4_Result
00102 AP4_HdlrAtom::InspectFields(AP4_AtomInspector& inspector)
00103 {
00104 char type[5];
00105 AP4_FormatFourChars(type, m_HandlerType);
00106 inspector.AddField("handler_type", type);
00107 inspector.AddField("handler_name", m_HandlerName.c_str());
00108
00109 return AP4_SUCCESS;
00110 }