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 "Ap4TrakAtom.h"
00034 #include "Ap4MdhdAtom.h"
00035 #include "Ap4VmhdAtom.h"
00036 #include "Ap4SmhdAtom.h"
00037 #include "Ap4HmhdAtom.h"
00038 #include "Ap4NmhdAtom.h"
00039 #include "Ap4DrefAtom.h"
00040 #include "Ap4UrlAtom.h"
00041 #include "Ap4StcoAtom.h"
00042 #include "Ap4Co64Atom.h"
00043 #include "Ap4AtomFactory.h"
00044 #include "Ap4Utils.h"
00045
00046
00047
00048
00049 AP4_TrakAtom::AP4_TrakAtom(AP4_SampleTable* sample_table,
00050 AP4_Atom::Type hdlr_type,
00051 const char* hdlr_name,
00052 AP4_UI32 track_id,
00053 AP4_UI32 creation_time,
00054 AP4_UI32 modification_time,
00055 AP4_UI32 track_duration,
00056 AP4_UI32 media_time_scale,
00057 AP4_UI32 media_duration,
00058 AP4_UI16 volume,
00059 const char* language,
00060 AP4_UI32 width,
00061 AP4_UI32 height) :
00062 AP4_ContainerAtom(AP4_ATOM_TYPE_TRAK)
00063 {
00064 AP4_Result result;
00065
00066
00067 m_TkhdAtom = new AP4_TkhdAtom(creation_time,
00068 modification_time,
00069 track_id,
00070 track_duration,
00071 volume,
00072 width,
00073 height);
00074
00075
00076
00077
00078 AP4_ContainerAtom* mdia = new AP4_ContainerAtom(AP4_ATOM_TYPE_MDIA);
00079
00080
00081 m_HdlrAtom = new AP4_HdlrAtom(hdlr_type, hdlr_name);
00082
00083
00084 AP4_ContainerAtom* minf = new AP4_ContainerAtom(AP4_ATOM_TYPE_MINF);
00085
00086
00087 AP4_Atom* minf_header;
00088 switch (hdlr_type) {
00089 case AP4_HANDLER_TYPE_VIDE:
00090 minf_header = new AP4_VmhdAtom(0, 0, 0, 0);
00091 break;
00092
00093 case AP4_HANDLER_TYPE_SOUN:
00094 minf_header = new AP4_SmhdAtom(0);
00095 break;
00096
00097 default:
00098 minf_header = new AP4_NmhdAtom();
00099 break;
00100 }
00101
00102
00103 AP4_ContainerAtom* dinf = new AP4_ContainerAtom(AP4_ATOM_TYPE_DINF);
00104
00105
00106 AP4_Atom* url = new AP4_UrlAtom();
00107
00108
00109 AP4_DrefAtom* dref = new AP4_DrefAtom(&url, 1);
00110
00111
00112 AP4_ContainerAtom* stbl;
00113 result = sample_table->GenerateStblAtom(stbl);
00114 if (AP4_FAILED(result)) stbl = NULL;
00115
00116
00117 dinf->AddChild(dref);
00118
00119
00120 minf->AddChild(minf_header);
00121 minf->AddChild(dinf);
00122 if (stbl) minf->AddChild(stbl);
00123
00124
00125 AP4_MdhdAtom* mdhd = new AP4_MdhdAtom(creation_time,
00126 modification_time,
00127 media_time_scale,
00128 media_duration,
00129 language);
00130
00131
00132 mdia->AddChild(mdhd);
00133 mdia->AddChild(m_HdlrAtom);
00134 mdia->AddChild(minf);
00135
00136
00137 AddChild(m_TkhdAtom);
00138 AddChild(mdia);
00139 }
00140
00141
00142
00143
00144 AP4_TrakAtom::AP4_TrakAtom(AP4_Size size,
00145 AP4_ByteStream& stream,
00146 AP4_AtomFactory& atom_factory) :
00147 AP4_ContainerAtom(AP4_ATOM_TYPE_TRAK, size, false, stream, atom_factory),
00148 m_HdlrAtom(NULL),
00149 m_TkhdAtom(NULL)
00150 {
00151 AP4_Atom* tkhd = FindChild("tkhd");
00152 if (tkhd != NULL) {
00153 m_TkhdAtom = dynamic_cast<AP4_TkhdAtom*>(tkhd);
00154 } else {
00155 m_TkhdAtom = NULL;
00156 }
00157 }
00158
00159
00160
00161
00162 AP4_UI32
00163 AP4_TrakAtom::GetDuration()
00164 {
00165 if (m_TkhdAtom) {
00166 return m_TkhdAtom->GetDuration();
00167 } else {
00168 return 0;
00169 }
00170 }
00171
00172
00173
00174
00175 AP4_Result
00176 AP4_TrakAtom::SetDuration(AP4_UI32 duration)
00177 {
00178 if (m_TkhdAtom) {
00179 return m_TkhdAtom->SetDuration(duration);
00180 } else {
00181 return AP4_FAILURE;
00182 }
00183 }
00184
00185
00186
00187
00188 AP4_Result
00189 AP4_TrakAtom::AdjustChunkOffsets(AP4_Offset offset)
00190 {
00191 if (AP4_Atom* atom = FindChild("mdia/minf/stbl/co64")) {
00192 AP4_Co64Atom* co64 = dynamic_cast<AP4_Co64Atom*>(atom);
00193 co64->AdjustChunkOffsets(offset);
00194 }
00195
00196 AP4_Atom* atom = FindChild("mdia/minf/stbl/stco");
00197 if (atom != NULL) {
00198 AP4_StcoAtom* stco = dynamic_cast<AP4_StcoAtom*>(atom);
00199 stco->AdjustChunkOffsets(offset);
00200 return AP4_SUCCESS;
00201 } else {
00202 return AP4_FAILURE;
00203 }
00204 }