Ap4SampleEntry.cpp

00001 /*****************************************************************
00002 |
00003 |    AP4 - sample entries
00004 |
00005 |    Copyright 2002 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 /*----------------------------------------------------------------------
00030 |       includes
00031 +---------------------------------------------------------------------*/
00032 #include "Ap4SampleEntry.h"
00033 #include "Ap4Utils.h"
00034 #include "Ap4AtomFactory.h"
00035 #include "Ap4TimsAtom.h"
00036 #include "Ap4SampleDescription.h"
00037 #include "Ap4FtabAtom.h"
00038 
00039 /*----------------------------------------------------------------------
00040 |       AP4_SampleEntry::AP4_SampleEntry
00041 +---------------------------------------------------------------------*/
00042 AP4_SampleEntry::AP4_SampleEntry(AP4_Atom::Type format,
00043                                  AP4_UI16       data_reference_index) :
00044     AP4_ContainerAtom(format, AP4_ATOM_HEADER_SIZE+8, false),
00045     m_DataReferenceIndex(data_reference_index)
00046 {
00047     m_Reserved1[0] = 0;
00048     m_Reserved1[1] = 0;
00049     m_Reserved1[2] = 0;
00050     m_Reserved1[3] = 0;
00051     m_Reserved1[4] = 0;
00052     m_Reserved1[5] = 0;
00053 }
00054 
00055 /*----------------------------------------------------------------------
00056 |       AP4_SampleEntry::AP4_SampleEntry
00057 +---------------------------------------------------------------------*/
00058 AP4_SampleEntry::AP4_SampleEntry(AP4_Atom::Type format,
00059                                  AP4_Size       size) :
00060     AP4_ContainerAtom(format, size)
00061 {
00062 }
00063 
00064 /*----------------------------------------------------------------------
00065 |       AP4_SampleEntry::AP4_SampleEntry
00066 +---------------------------------------------------------------------*/
00067 AP4_SampleEntry::AP4_SampleEntry(AP4_Atom::Type   format,
00068                                  AP4_Size         size,
00069                                  AP4_ByteStream&  stream,
00070                                  AP4_AtomFactory& atom_factory) :
00071     AP4_ContainerAtom(format, size)
00072 {
00073     // read the fields before the children atoms
00074     AP4_Size fields_size = GetFieldsSize();
00075     ReadFields(stream);
00076 
00077     // read children atoms (ex: esds and maybe others)
00078     ReadChildren(atom_factory, stream, size-AP4_ATOM_HEADER_SIZE-fields_size);
00079 }
00080 
00081 /*----------------------------------------------------------------------
00082 |       AP4_SampleEntry::GetFieldsSize
00083 +---------------------------------------------------------------------*/
00084 AP4_Size
00085 AP4_SampleEntry::GetFieldsSize()
00086 {
00087     return 8;
00088 }
00089 
00090 /*----------------------------------------------------------------------
00091 |       AP4_SampleEntry::ReadFields
00092 +---------------------------------------------------------------------*/
00093 AP4_Result
00094 AP4_SampleEntry::ReadFields(AP4_ByteStream& stream)
00095 {
00096     stream.Read(m_Reserved1, sizeof(m_Reserved1), NULL);
00097     stream.ReadUI16(m_DataReferenceIndex);
00098 
00099     return AP4_SUCCESS;
00100 }
00101 
00102 /*----------------------------------------------------------------------
00103 |       AP4_SampleEntry::WriteFields
00104 +---------------------------------------------------------------------*/
00105 AP4_Result
00106 AP4_SampleEntry::WriteFields(AP4_ByteStream& stream)
00107 {
00108     AP4_Result result;
00109     
00110     // reserved1
00111     result = stream.Write(m_Reserved1, sizeof(m_Reserved1));
00112     if (AP4_FAILED(result)) return result;
00113 
00114     // data reference index
00115     result = stream.WriteUI16(m_DataReferenceIndex);
00116     if (AP4_FAILED(result)) return result;
00117     
00118     return result;
00119 }
00120 
00121 /*----------------------------------------------------------------------
00122 |       AP4_SampleEntry::Write
00123 +---------------------------------------------------------------------*/
00124 AP4_Result
00125 AP4_SampleEntry::Write(AP4_ByteStream& stream)
00126 {
00127     AP4_Result result;
00128 
00129     // write the header
00130     result = WriteHeader(stream);
00131     if (AP4_FAILED(result)) return result;
00132 
00133     // write the fields
00134     result = WriteFields(stream);
00135     if (AP4_FAILED(result)) return result;
00136 
00137     // write the children atoms
00138     return m_Children.Apply(AP4_AtomListWriter(stream));
00139 }
00140 
00141 /*----------------------------------------------------------------------
00142 |       AP4_SampleEntry::InspectFields
00143 +---------------------------------------------------------------------*/
00144 AP4_Result
00145 AP4_SampleEntry::InspectFields(AP4_AtomInspector& inspector)
00146 {
00147     inspector.AddField("data_reference_index", m_DataReferenceIndex);
00148 
00149     return AP4_SUCCESS;
00150 }
00151 
00152 /*----------------------------------------------------------------------
00153 |       AP4_SampleEntry::Inspect
00154 +---------------------------------------------------------------------*/
00155 AP4_Result
00156 AP4_SampleEntry::Inspect(AP4_AtomInspector& inspector)
00157 {
00158     // inspect the header
00159     InspectHeader(inspector);
00160 
00161     // inspect the fields
00162     InspectFields(inspector);
00163 
00164     // inspect children
00165     m_Children.Apply(AP4_AtomListInspector(inspector));
00166 
00167     // finish
00168     inspector.EndElement();
00169 
00170     return AP4_SUCCESS;
00171 }
00172 
00173 /*----------------------------------------------------------------------
00174 |       AP4_SampleEntry::OnChildChanged
00175 +---------------------------------------------------------------------*/
00176 void
00177 AP4_SampleEntry::OnChildChanged(AP4_Atom*)
00178 {
00179     // remcompute our size
00180     m_Size = GetHeaderSize()+GetFieldsSize();
00181     m_Children.Apply(AP4_AtomSizeAdder(m_Size));
00182 
00183     // update our parent
00184     if (m_Parent) m_Parent->OnChildChanged(this);
00185 }
00186 
00187 /*----------------------------------------------------------------------
00188 |       AP4_SampleEntry::ToSampleDescription
00189 +---------------------------------------------------------------------*/
00190 AP4_SampleDescription*
00191 AP4_SampleEntry::ToSampleDescription()
00192 {
00193     return new AP4_UnknownSampleDescription(this);
00194 }
00195 
00196 /*----------------------------------------------------------------------
00197 |       AP4_MpegSampleEntry::AP4_MpegSampleEntry
00198 +---------------------------------------------------------------------*/
00199 AP4_MpegSampleEntry::AP4_MpegSampleEntry(AP4_Atom::Type    format, 
00200                                          AP4_EsDescriptor* descriptor) :
00201     AP4_SampleEntry(format)
00202 {
00203     if (descriptor) AddChild(new AP4_EsdsAtom(descriptor));
00204 }
00205 
00206 /*----------------------------------------------------------------------
00207 |       AP4_MpegSampleEntry::AP4_MpegSampleEntry
00208 +---------------------------------------------------------------------*/
00209 AP4_MpegSampleEntry::AP4_MpegSampleEntry(AP4_Atom::Type format,
00210                                          AP4_Size       size) :
00211     AP4_SampleEntry(format, size)
00212 {
00213 }
00214 
00215 /*----------------------------------------------------------------------
00216 |       AP4_MpegSampleEntry::AP4_MpegSampleEntry
00217 +---------------------------------------------------------------------*/
00218 AP4_MpegSampleEntry::AP4_MpegSampleEntry(AP4_Atom::Type   format,
00219                                          AP4_Size         size,
00220                                          AP4_ByteStream&  stream,
00221                                          AP4_AtomFactory& atom_factory) :
00222     AP4_SampleEntry(format, size, stream, atom_factory)
00223 {
00224 }
00225 
00226 /*----------------------------------------------------------------------
00227 |       AP4_MpegSampleEntry::AP4_MpegSampleEntry
00228 +---------------------------------------------------------------------*/
00229 const AP4_DecoderConfigDescriptor* 
00230 AP4_MpegSampleEntry::GetDecoderConfigDescriptor()
00231 {
00232     AP4_Atom* child = GetChild(AP4_ATOM_TYPE_ESDS);
00233     if (child) {
00234         AP4_EsdsAtom* esds = (AP4_EsdsAtom*)child;
00235 
00236         // get the es descriptor
00237         const AP4_EsDescriptor* es_desc = esds->GetEsDescriptor();
00238         if (es_desc == NULL) return NULL;
00239 
00240         // get the decoder config descriptor
00241         return es_desc->GetDecoderConfigDescriptor();
00242     } else {
00243         return NULL;
00244     }
00245 }
00246 
00247 /*----------------------------------------------------------------------
00248 |       AP4_Mp4sSampleEntry::AP4_Mp4sSampleEntry
00249 +---------------------------------------------------------------------*/
00250 AP4_Mp4sSampleEntry::AP4_Mp4sSampleEntry(AP4_EsDescriptor* descriptor) :
00251     AP4_MpegSampleEntry(AP4_ATOM_TYPE_MP4S, descriptor)
00252 {
00253 }
00254 
00255 /*----------------------------------------------------------------------
00256 |       AP4_Mp4sSampleEntry::AP4_Mp4sSampleEntry
00257 +---------------------------------------------------------------------*/
00258 AP4_Mp4sSampleEntry::AP4_Mp4sSampleEntry(AP4_Size         size,
00259                                          AP4_ByteStream&  stream,
00260                                          AP4_AtomFactory& atom_factory) :
00261     AP4_MpegSampleEntry(AP4_ATOM_TYPE_MP4S, size, stream, atom_factory)
00262 {
00263 }
00264 
00265 /*----------------------------------------------------------------------
00266 |       AP4_Mp4sSampleEntry::ToSampleDescription
00267 +---------------------------------------------------------------------*/
00268 AP4_SampleDescription*
00269 AP4_Mp4sSampleEntry::ToSampleDescription()
00270 {
00271     // get the decoder config descriptor
00272     const AP4_DecoderConfigDescriptor* dc_desc;
00273     dc_desc = GetDecoderConfigDescriptor();
00274     if (dc_desc == NULL) return NULL;
00275     const AP4_DataBuffer* dsi = NULL;
00276     const AP4_DecoderSpecificInfoDescriptor* dsi_desc =
00277         dc_desc->GetDecoderSpecificInfoDescriptor();
00278     if (dsi_desc != NULL) {
00279         dsi = &dsi_desc->GetDecoderSpecificInfo();
00280     }
00281 
00282     // create a sample description
00283     return new AP4_MpegSystemSampleDescription(
00284         dc_desc->GetStreamType(),
00285         dc_desc->GetObjectTypeIndication(),
00286         dsi,
00287         dc_desc->GetBufferSize(),
00288         dc_desc->GetMaxBitrate(),
00289         dc_desc->GetAvgBitrate());
00290 }
00291 
00292 /*----------------------------------------------------------------------
00293 |       AP4_AudioSampleEntry::AP4_AudioSampleEntry
00294 +---------------------------------------------------------------------*/
00295 AP4_AudioSampleEntry::AP4_AudioSampleEntry(AP4_Atom::Type    format,
00296                                            AP4_EsDescriptor* descriptor,
00297                                            AP4_UI32          sample_rate,
00298                                            AP4_UI16          sample_size,
00299                                            AP4_UI16          channel_count) :
00300     AP4_MpegSampleEntry(format, descriptor),
00301     m_SampleRate(sample_rate),
00302     m_ChannelCount(channel_count),
00303     m_SampleSize(sample_size)
00304 {
00305     m_Predefined1 = 0;
00306     memset(m_Reserved2, 0, sizeof(m_Reserved2));
00307     m_Reserved3 = 0;
00308 
00309     m_Size += 20;
00310 }
00311 
00312 /*----------------------------------------------------------------------
00313 |       AP4_AudioSampleEntry::AP4_AudioSampleEntry
00314 +---------------------------------------------------------------------*/
00315 AP4_AudioSampleEntry::AP4_AudioSampleEntry(AP4_Atom::Type   format,
00316                                            AP4_Size         size,
00317                                            AP4_ByteStream&  stream,
00318                                            AP4_AtomFactory& atom_factory) :
00319     AP4_MpegSampleEntry(format, size)
00320 {
00321     // read fields
00322     AP4_Size fields_size = GetFieldsSize();
00323     ReadFields(stream);
00324 
00325     // read children atoms (ex: esds and maybe others)
00326     ReadChildren(atom_factory, stream, size-AP4_ATOM_HEADER_SIZE-fields_size);
00327 }
00328     
00329 /*----------------------------------------------------------------------
00330 |       AP4_AudioSampleEntry::GetFieldsSize
00331 +---------------------------------------------------------------------*/
00332 AP4_Size
00333 AP4_AudioSampleEntry::GetFieldsSize()
00334 {
00335     return AP4_SampleEntry::GetFieldsSize()+20;
00336 }
00337 
00338 /*----------------------------------------------------------------------
00339 |       AP4_AudioSampleEntry::ReadFields
00340 +---------------------------------------------------------------------*/
00341 AP4_Result
00342 AP4_AudioSampleEntry::ReadFields(AP4_ByteStream& stream)
00343 {
00344     // sample entry
00345     AP4_Result result = AP4_SampleEntry::ReadFields(stream);
00346     if (result < 0) return result;
00347 
00348     // read the fields of this class
00349     stream.Read(m_Reserved2, sizeof(m_Reserved2), NULL);
00350     stream.ReadUI16(m_ChannelCount);
00351     stream.ReadUI16(m_SampleSize);
00352     stream.ReadUI16(m_Predefined1);
00353     stream.ReadUI16(m_Reserved3);
00354     stream.ReadUI32(m_SampleRate);
00355 
00356     return AP4_SUCCESS;
00357 }
00358 
00359 /*----------------------------------------------------------------------
00360 |       AP4_AudioSampleEntry::WriteFields
00361 +---------------------------------------------------------------------*/
00362 AP4_Result
00363 AP4_AudioSampleEntry::WriteFields(AP4_ByteStream& stream)
00364 {
00365     AP4_Result result;
00366     
00367     // write the fields of the base class
00368     result = AP4_SampleEntry::WriteFields(stream);
00369 
00370     // reserved2
00371     result = stream.Write(m_Reserved2, sizeof(m_Reserved2));
00372     if (AP4_FAILED(result)) return result;
00373 
00374     // channel count
00375     result = stream.WriteUI16(m_ChannelCount);
00376     if (AP4_FAILED(result)) return result;
00377     
00378     // sample size 
00379     result = stream.WriteUI16(m_SampleSize);
00380     if (AP4_FAILED(result)) return result;
00381 
00382     // predefined1
00383     result = stream.WriteUI16(m_Predefined1);
00384     if (AP4_FAILED(result)) return result;
00385 
00386     // reserved3
00387     result = stream.WriteUI16(m_Reserved3);
00388     if (AP4_FAILED(result)) return result;
00389 
00390     // sample rate
00391     result = stream.WriteUI32(m_SampleRate);
00392     if (AP4_FAILED(result)) return result;
00393 
00394     return result;
00395 }
00396 
00397 /*----------------------------------------------------------------------
00398 |       AP4_AudioSampleEntry::InspectFields
00399 +---------------------------------------------------------------------*/
00400 AP4_Result
00401 AP4_AudioSampleEntry::InspectFields(AP4_AtomInspector& inspector)
00402 {
00403     // dump the fields from the base class
00404     AP4_SampleEntry::InspectFields(inspector);
00405 
00406     // fields
00407     inspector.AddField("channel_count", m_ChannelCount);
00408     inspector.AddField("sample_size", m_SampleSize);
00409     inspector.AddField("sample_rate", m_SampleRate>>16);
00410 
00411     return AP4_SUCCESS;
00412 }
00413 
00414 /*----------------------------------------------------------------------
00415 |       AP4_AudioSampleEntry::ToSampleDescription
00416 +---------------------------------------------------------------------*/
00417 AP4_SampleDescription*
00418 AP4_AudioSampleEntry::ToSampleDescription()
00419 {
00420     // get the decoder config descriptor
00421     const AP4_DecoderConfigDescriptor* dc_desc;
00422     dc_desc = GetDecoderConfigDescriptor();
00423     if (dc_desc == NULL) return NULL;
00424     const AP4_DataBuffer* dsi = NULL;
00425     const AP4_DecoderSpecificInfoDescriptor* dsi_desc =
00426         dc_desc->GetDecoderSpecificInfoDescriptor();
00427     if (dsi_desc != NULL) {
00428         dsi = &dsi_desc->GetDecoderSpecificInfo();
00429     }
00430 
00431     // create a sample description
00432     return new AP4_MpegAudioSampleDescription(
00433         dc_desc->GetObjectTypeIndication(),
00434         m_SampleRate>>16,
00435         m_SampleSize,
00436         m_ChannelCount,
00437         dsi,
00438         dc_desc->GetBufferSize(),
00439         dc_desc->GetMaxBitrate(),
00440         dc_desc->GetAvgBitrate());
00441 }
00442 
00443 /*----------------------------------------------------------------------
00444 |       AP4_Mp4aSampleEntry::AP4_Mp4aSampleEntry
00445 +---------------------------------------------------------------------*/
00446 AP4_Mp4aSampleEntry::AP4_Mp4aSampleEntry(AP4_UI32          sample_rate, 
00447                                          AP4_UI16          sample_size,
00448                                          AP4_UI16          channel_count,
00449                                          AP4_EsDescriptor* descriptor) :
00450     AP4_AudioSampleEntry(AP4_ATOM_TYPE_MP4A, 
00451                          descriptor,
00452                          sample_rate, 
00453                          sample_size, 
00454                          channel_count)
00455 {
00456 }
00457 
00458 /*----------------------------------------------------------------------
00459 |       AP4_Mp4aSampleEntry::AP4_Mp4aSampleEntry
00460 +---------------------------------------------------------------------*/
00461 AP4_Mp4aSampleEntry::AP4_Mp4aSampleEntry(AP4_Size         size,
00462                                          AP4_ByteStream&  stream,
00463                                          AP4_AtomFactory& atom_factory) :
00464     AP4_AudioSampleEntry(AP4_ATOM_TYPE_MP4A, size, stream, atom_factory)
00465 {
00466 }
00467 
00468 /*----------------------------------------------------------------------
00469 |       AP4_VisualSampleEntry::AP4_VisualSampleEntry
00470 +---------------------------------------------------------------------*/
00471 AP4_VisualSampleEntry::AP4_VisualSampleEntry(
00472     AP4_Atom::Type    format, 
00473     AP4_EsDescriptor* descriptor,
00474     AP4_UI16          width,
00475     AP4_UI16          height,
00476     AP4_UI16          depth,
00477     const char*       compressor_name) :
00478     AP4_MpegSampleEntry(format, descriptor),
00479     m_Predefined1(0),
00480     m_Reserved2(0),
00481     m_Width(width),
00482     m_Height(height),
00483     m_HorizResolution(0x00480000),
00484     m_VertResolution(0x00480000),
00485     m_Reserved3(0),
00486     m_FrameCount(1),
00487     m_CompressorName(compressor_name),
00488     m_Depth(depth),
00489     m_Predefined3(0xFFFF)
00490 {
00491     memset(m_Predefined2, 0, sizeof(m_Predefined2));
00492     m_Size += 70;
00493 }
00494 
00495 /*----------------------------------------------------------------------
00496 |       AP4_VisualSampleEntry::AP4_VisualSampleEntry
00497 +---------------------------------------------------------------------*/
00498 AP4_VisualSampleEntry::AP4_VisualSampleEntry(AP4_Atom::Type   format,
00499                                              AP4_Size         size, 
00500                                              AP4_ByteStream&  stream,
00501                                              AP4_AtomFactory& atom_factory) :
00502     AP4_MpegSampleEntry(format, size)
00503 {
00504     // read fields
00505     AP4_Size fields_size = GetFieldsSize();
00506     ReadFields(stream);
00507 
00508     // read children atoms (ex: esds and maybe others)
00509     ReadChildren(atom_factory, stream, size-AP4_ATOM_HEADER_SIZE-fields_size);
00510 }
00511 
00512 /*----------------------------------------------------------------------
00513 |       AP4_VisualSampleEntry::GetFieldsSize
00514 +---------------------------------------------------------------------*/
00515 AP4_Size
00516 AP4_VisualSampleEntry::GetFieldsSize()
00517 {
00518     return AP4_SampleEntry::GetFieldsSize()+70;
00519 }
00520 
00521 /*----------------------------------------------------------------------
00522 |       AP4_VisualSampleEntry::ReadFields
00523 +---------------------------------------------------------------------*/
00524 AP4_Result
00525 AP4_VisualSampleEntry::ReadFields(AP4_ByteStream& stream)
00526 {
00527     // sample entry
00528     AP4_Result result = AP4_SampleEntry::ReadFields(stream);
00529     if (result < 0) return result;
00530 
00531     // read fields from this class
00532     stream.ReadUI16(m_Predefined1);
00533     stream.ReadUI16(m_Reserved2);
00534     stream.Read(m_Predefined2, sizeof(m_Predefined2), NULL);
00535     stream.ReadUI16(m_Width);
00536     stream.ReadUI16(m_Height);
00537     stream.ReadUI32(m_HorizResolution);
00538     stream.ReadUI32(m_VertResolution);
00539     stream.ReadUI32(m_Reserved3);
00540     stream.ReadUI16(m_FrameCount);
00541 
00542     char compressor_name[33];
00543     stream.Read(compressor_name, 32);
00544     int name_length = compressor_name[0];
00545     if (name_length < 32) {
00546         compressor_name[name_length+1] = 0;
00547         m_CompressorName = &compressor_name[1];
00548     }
00549 
00550     stream.ReadUI16(m_Depth);
00551     stream.ReadUI16(m_Predefined3);
00552 
00553     return AP4_SUCCESS;
00554 }
00555 
00556 /*----------------------------------------------------------------------
00557 |       AP4_VisualSampleEntry::WriteFields
00558 +---------------------------------------------------------------------*/
00559 AP4_Result
00560 AP4_VisualSampleEntry::WriteFields(AP4_ByteStream& stream)
00561 {
00562     AP4_Result result;
00563         
00564     // write the fields of the base class
00565     result = AP4_SampleEntry::WriteFields(stream);
00566     if (AP4_FAILED(result)) return result;
00567 
00568     // predefined1
00569     result = stream.WriteUI16(m_Predefined1);
00570     if (AP4_FAILED(result)) return result;
00571     
00572     // reserved2
00573     result = stream.WriteUI16(m_Reserved2);
00574     if (AP4_FAILED(result)) return result;
00575     
00576     // predefined2
00577     result = stream.Write(m_Predefined2, sizeof(m_Predefined2));
00578     if (AP4_FAILED(result)) return result;
00579     
00580     // width
00581     result = stream.WriteUI16(m_Width);
00582     if (AP4_FAILED(result)) return result;
00583     
00584     // height
00585     result = stream.WriteUI16(m_Height);
00586     if (AP4_FAILED(result)) return result;
00587     
00588     // horizontal resolution
00589     result = stream.WriteUI32(m_HorizResolution);
00590     if (AP4_FAILED(result)) return result;
00591     
00592     // vertical resolution
00593     result = stream.WriteUI32(m_VertResolution);
00594     if (AP4_FAILED(result)) return result;
00595     
00596     // reserved3
00597     result = stream.WriteUI32(m_Reserved3);
00598     if (AP4_FAILED(result)) return result;
00599     
00600     // frame count
00601     result = stream.WriteUI16(m_FrameCount);
00602     if (AP4_FAILED(result)) return result;
00603     
00604     // compressor name
00605     unsigned char compressor_name[32];
00606     unsigned int name_length = m_CompressorName.length();
00607     if (name_length > 31) name_length = 31;
00608     compressor_name[0] = name_length;
00609     for (unsigned int i=0; i<name_length; i++) {
00610         compressor_name[i+1] = m_CompressorName[i];
00611     }
00612     for (unsigned int i=name_length+1; i<32; i++) {
00613         compressor_name[i] = 0;
00614     }
00615     result = stream.Write(compressor_name, 32);
00616     if (AP4_FAILED(result)) return result;
00617     
00618     // depth
00619     result = stream.WriteUI16(m_Depth);
00620     if (AP4_FAILED(result)) return result;
00621     
00622     // predefined3
00623     result = stream.WriteUI16(m_Predefined3);
00624     if (AP4_FAILED(result)) return result;
00625     
00626     return result;
00627 }
00628 
00629 /*----------------------------------------------------------------------
00630 |       AP4_VisualSampleEntry::InspectFields
00631 +---------------------------------------------------------------------*/
00632 AP4_Result
00633 AP4_VisualSampleEntry::InspectFields(AP4_AtomInspector& inspector)
00634 {
00635     // dump the fields of the base class
00636     AP4_SampleEntry::InspectFields(inspector);
00637 
00638     // fields
00639     inspector.AddField("width", m_Width);
00640     inspector.AddField("height", m_Height);
00641     inspector.AddField("compressor", m_CompressorName.c_str());
00642 
00643     return AP4_SUCCESS;
00644 }
00645 
00646 /*----------------------------------------------------------------------
00647 |       AP4_VisualSampleEntry::ToSampleDescription
00648 +---------------------------------------------------------------------*/
00649 AP4_SampleDescription*
00650 AP4_VisualSampleEntry::ToSampleDescription()
00651 {
00652     // get the decoder config descriptor
00653     const AP4_DecoderConfigDescriptor* dc_desc;
00654     dc_desc = GetDecoderConfigDescriptor();
00655     if (dc_desc == NULL) return NULL;
00656     const AP4_DataBuffer* dsi = NULL;
00657     const AP4_DecoderSpecificInfoDescriptor* dsi_desc =
00658         dc_desc->GetDecoderSpecificInfoDescriptor();
00659     if (dsi_desc != NULL) {
00660         dsi = &dsi_desc->GetDecoderSpecificInfo();
00661     }
00662 
00663     // create a sample description
00664     return new AP4_MpegVideoSampleDescription(
00665         dc_desc->GetObjectTypeIndication(),
00666         m_Width,
00667         m_Height,
00668         m_Depth,
00669         m_CompressorName.c_str(),
00670         dsi,
00671         dc_desc->GetBufferSize(),
00672         dc_desc->GetMaxBitrate(),
00673         dc_desc->GetAvgBitrate());
00674 }
00675 
00676 /*----------------------------------------------------------------------
00677 |       AP4_Mp4vSampleEntry::AP4_Mp4vSampleEntry
00678 +---------------------------------------------------------------------*/
00679 AP4_Mp4vSampleEntry::AP4_Mp4vSampleEntry(AP4_UI16          width,
00680                                          AP4_UI16          height,
00681                                          AP4_UI16          depth,
00682                                          const char*       compressor_name,
00683                                          AP4_EsDescriptor* descriptor) :
00684     AP4_VisualSampleEntry(AP4_ATOM_TYPE_MP4V, 
00685                           descriptor,
00686                           width, 
00687                           height, 
00688                           depth, 
00689                           compressor_name)
00690 {
00691 }
00692 
00693 /*----------------------------------------------------------------------
00694 |       AP4_Mp4vSampleEntry::AP4_Mp4aSampleEntry
00695 +---------------------------------------------------------------------*/
00696 AP4_Mp4vSampleEntry::AP4_Mp4vSampleEntry(AP4_Size         size,
00697                                          AP4_ByteStream&  stream,
00698                                          AP4_AtomFactory& atom_factory) :
00699     AP4_VisualSampleEntry(AP4_ATOM_TYPE_MP4V, size, stream, atom_factory)
00700 {
00701 }
00702 
00703 /*----------------------------------------------------------------------
00704 |       AP4_Avc1SampleEntry::AP4_Avc1SampleEntry
00705 +---------------------------------------------------------------------*/
00706 AP4_Avc1SampleEntry::AP4_Avc1SampleEntry(AP4_UI16          width,
00707                                          AP4_UI16          height,
00708                                          AP4_UI16          depth,
00709                                          const char*       compressor_name,
00710                                          AP4_EsDescriptor* descriptor) :
00711     AP4_VisualSampleEntry(AP4_ATOM_TYPE_AVC1, 
00712                           descriptor,
00713                           width, 
00714                           height, 
00715                           depth, 
00716                           compressor_name)
00717 {
00718 }
00719 
00720 /*----------------------------------------------------------------------
00721 |       AP4_Avc1SampleEntry::AP4_Avc1SampleEntry
00722 +---------------------------------------------------------------------*/
00723 AP4_Avc1SampleEntry::AP4_Avc1SampleEntry(AP4_Size         size,
00724                                          AP4_ByteStream&  stream,
00725                                          AP4_AtomFactory& atom_factory) :
00726     AP4_VisualSampleEntry(AP4_ATOM_TYPE_AVC1, size, stream, atom_factory)
00727 {
00728 }
00729 
00730 /*----------------------------------------------------------------------
00731 |       AP4_RtpHintSampleEntry::AP4_RtpHintSampleEntry
00732 +---------------------------------------------------------------------*/
00733 AP4_RtpHintSampleEntry::AP4_RtpHintSampleEntry(AP4_UI16 hint_track_version,
00734                                                AP4_UI16 highest_compatible_version,
00735                                                AP4_UI32 max_packet_size,
00736                                                AP4_UI32 timescale):
00737     AP4_SampleEntry(AP4_ATOM_TYPE_RTP),
00738     m_HintTrackVersion(hint_track_version),
00739     m_HighestCompatibleVersion(highest_compatible_version),
00740     m_MaxPacketSize(max_packet_size)
00741 {
00742     // build an atom for timescale
00743     AddChild(new AP4_TimsAtom(timescale));
00744 }
00745 
00746 /*----------------------------------------------------------------------
00747 |       AP4_RtpHintSampleEntry::AP4_RtpHintSampleEntry
00748 +---------------------------------------------------------------------*/
00749 AP4_RtpHintSampleEntry::AP4_RtpHintSampleEntry(AP4_Size         size,
00750                                                AP4_ByteStream&  stream,
00751                                                AP4_AtomFactory& atom_factory): 
00752     AP4_SampleEntry(AP4_ATOM_TYPE_RTP, size)
00753 {
00754     // read fields
00755     AP4_Size fields_size = GetFieldsSize();
00756     ReadFields(stream);
00757 
00758     // read children atoms (ex: esds and maybe others)
00759     ReadChildren(atom_factory, stream, size-AP4_ATOM_HEADER_SIZE-fields_size);
00760 }
00761 
00762 /*----------------------------------------------------------------------
00763 |       AP4_RtpHintSampleEntry::~AP4_RtpHintSampleEntry
00764 +---------------------------------------------------------------------*/
00765 AP4_RtpHintSampleEntry::~AP4_RtpHintSampleEntry() 
00766 {
00767 }
00768 
00769 /*----------------------------------------------------------------------
00770 |       AP4_RtpHintSampleEntry::GetFieldsSize
00771 +---------------------------------------------------------------------*/
00772 AP4_Size
00773 AP4_RtpHintSampleEntry::GetFieldsSize()
00774 {
00775     return AP4_SampleEntry::GetFieldsSize()+8;
00776 }
00777 
00778 /*----------------------------------------------------------------------
00779 |       AP4_RtpHintSampleEntry::ReadFields
00780 +---------------------------------------------------------------------*/
00781 AP4_Result
00782 AP4_RtpHintSampleEntry::ReadFields(AP4_ByteStream& stream)
00783 {
00784     // sample entry
00785     AP4_Result result = AP4_SampleEntry::ReadFields(stream);
00786     if (result < 0) return result;
00787 
00788     // data
00789     result = stream.ReadUI16(m_HintTrackVersion);
00790     if (AP4_FAILED(result)) return result;
00791     result = stream.ReadUI16(m_HighestCompatibleVersion);
00792     if (AP4_FAILED(result)) return result;
00793     result = stream.ReadUI32(m_MaxPacketSize);
00794     if (AP4_FAILED(result)) return result;
00795 
00796     return AP4_SUCCESS;
00797 }
00798 
00799 /*----------------------------------------------------------------------
00800 |       AP4_RtpHintSampleEntry::WriteFields
00801 +---------------------------------------------------------------------*/
00802 AP4_Result
00803 AP4_RtpHintSampleEntry::WriteFields(AP4_ByteStream& stream)
00804 {
00805     // sample entry
00806     AP4_Result result = AP4_SampleEntry::WriteFields(stream);
00807     if (AP4_FAILED(result)) return result;
00808     
00809     // data
00810     result = stream.WriteUI16(m_HintTrackVersion);
00811     if (AP4_FAILED(result)) return result;
00812     result = stream.WriteUI16(m_HighestCompatibleVersion);
00813     if (AP4_FAILED(result)) return result;
00814     result = stream.WriteUI32(m_MaxPacketSize);
00815     if (AP4_FAILED(result)) return result;
00816 
00817     return result;
00818 }
00819 
00820 /*----------------------------------------------------------------------
00821 |       AP4_RtpHintSampleEntry::InspectFields
00822 +---------------------------------------------------------------------*/
00823 AP4_Result
00824 AP4_RtpHintSampleEntry::InspectFields(AP4_AtomInspector& inspector)
00825 {
00826     // sample entry
00827     AP4_SampleEntry::InspectFields(inspector);
00828     
00829     // fields
00830     inspector.AddField("hint_track_version", m_HintTrackVersion);
00831     inspector.AddField("highest_compatible_version", m_HighestCompatibleVersion);
00832     inspector.AddField("max_packet_size", m_MaxPacketSize);
00833     
00834     return AP4_SUCCESS;
00835 }
00836 
00837 /*----------------------------------------------------------------------
00838 |       AP4_TextSampleEntry::AP4_TextSampleEntry
00839 +---------------------------------------------------------------------*/
00840 AP4_TextSampleEntry::AP4_TextSampleEntry(AP4_Size         size,
00841                                          AP4_ByteStream&  stream,
00842                                          AP4_AtomFactory& atom_factory): 
00843     AP4_SampleEntry(AP4_ATOM_TYPE_TEXT, size)
00844 {
00845     // read fields
00846     ReadFields(stream);
00847 }
00848 
00849 /*----------------------------------------------------------------------
00850 |       AP4_TextSampleEntry::~AP4_TextSampleEntry
00851 +---------------------------------------------------------------------*/
00852 AP4_TextSampleEntry::~AP4_TextSampleEntry() 
00853 {
00854 }
00855 
00856 /*----------------------------------------------------------------------
00857 |       AP4_TextSampleEntry::ReadFields
00858 +---------------------------------------------------------------------*/
00859 AP4_Result
00860 AP4_TextSampleEntry::ReadFields(AP4_ByteStream& stream)
00861 {
00862     // sample entry
00863     AP4_Result result = AP4_SampleEntry::ReadFields(stream);
00864     if (result < 0) return result;
00865 
00866     // data
00867     result = stream.ReadUI32(m_Description.DisplayFlags);
00868     if (AP4_FAILED(result)) return result;
00869     result = stream.ReadUI32(m_Description.TextJustification);
00870     if (AP4_FAILED(result)) return result;
00871     result = stream.Read(&m_Description.BackgroundColor, 4);
00872     if (AP4_FAILED(result)) return result;
00873     result = stream.ReadUI16(m_Description.TextBox.Top);
00874     if (AP4_FAILED(result)) return result;
00875     result = stream.ReadUI16(m_Description.TextBox.Left);
00876     if (AP4_FAILED(result)) return result;
00877     result = stream.ReadUI16(m_Description.TextBox.Bottom);
00878     if (AP4_FAILED(result)) return result;
00879     result = stream.ReadUI16(m_Description.TextBox.Right);
00880     if (AP4_FAILED(result)) return result;
00881     result = stream.ReadUI16(m_Description.Style.StartChar);
00882     if (AP4_FAILED(result)) return result;
00883     result = stream.ReadUI16(m_Description.Style.EndChar);
00884     if (AP4_FAILED(result)) return result;
00885     result = stream.ReadUI16(m_Description.Style.Ascent);
00886     if (AP4_FAILED(result)) return result;
00887     result = stream.ReadUI16(m_Description.Style.Font.Id);
00888     if (AP4_FAILED(result)) return result;
00889     result = stream.ReadUI08(m_Description.Style.Font.Face);
00890     if (AP4_FAILED(result)) return result;
00891     result = stream.ReadUI08(m_Description.Style.Font.Size);
00892     if (AP4_FAILED(result)) return result;
00893     result = stream.Read(&m_Description.Style.Font.Color, 4);
00894     if (AP4_FAILED(result)) return result;
00895 
00896     // TODO: stream.ReadString(); -> m_Description.DefaultFontName
00897 
00898     return AP4_SUCCESS;
00899 }
00900 
00901 /*----------------------------------------------------------------------
00902 |       AP4_TextSampleEntry::WriteFields
00903 +---------------------------------------------------------------------*/
00904 AP4_Result
00905 AP4_TextSampleEntry::WriteFields(AP4_ByteStream& stream)
00906 {
00907     // sample entry
00908     AP4_Result result = AP4_SampleEntry::WriteFields(stream);
00909     if (AP4_FAILED(result)) return result;
00910     
00911     // TODO: data
00912 
00913     return result;
00914 }
00915 
00916 /*----------------------------------------------------------------------
00917 |       AP4_TextSampleEntry::InspectFields
00918 +---------------------------------------------------------------------*/
00919 AP4_Result
00920 AP4_TextSampleEntry::InspectFields(AP4_AtomInspector& inspector)
00921 {
00922     // sample entry
00923     AP4_SampleEntry::InspectFields(inspector);
00924     
00925     // TODO: fields
00926     
00927     return AP4_SUCCESS;
00928 }
00929 
00930 /*----------------------------------------------------------------------
00931 |       AP4_Tx3gSampleEntry::AP4_Tx3gSampleEntry
00932 +---------------------------------------------------------------------*/
00933 AP4_Tx3gSampleEntry::AP4_Tx3gSampleEntry(AP4_Size         size,
00934                                          AP4_ByteStream&  stream,
00935                                          AP4_AtomFactory& atom_factory): 
00936     AP4_SampleEntry(AP4_ATOM_TYPE_TX3G, size)
00937 {
00938     // read fields
00939     AP4_Size fields_size = GetFieldsSize();
00940     ReadFields(stream);
00941 
00942     // read children atoms (fdat? blnk?)
00943     ReadChildren(atom_factory, stream, size-AP4_ATOM_HEADER_SIZE-fields_size);
00944 }
00945 
00946 /*----------------------------------------------------------------------
00947 |       AP4_Tx3gSampleEntry::~AP4_Tx3gSampleEntry
00948 +---------------------------------------------------------------------*/
00949 AP4_Tx3gSampleEntry::~AP4_Tx3gSampleEntry() 
00950 {
00951 }
00952 
00953 /*----------------------------------------------------------------------
00954 |       AP4_Tx3gSampleEntry::GetFieldsSize
00955 +---------------------------------------------------------------------*/
00956 AP4_Size
00957 AP4_Tx3gSampleEntry::GetFieldsSize()
00958 {
00959     return AP4_SampleEntry::GetFieldsSize()+4+1+1+4+2+2+2+2+2+2+2+1+1+4;
00960 }
00961 
00962 /*----------------------------------------------------------------------
00963 |       AP4_Tx3gSampleEntry::ReadFields
00964 +---------------------------------------------------------------------*/
00965 AP4_Result
00966 AP4_Tx3gSampleEntry::ReadFields(AP4_ByteStream& stream)
00967 {
00968     // sample entry
00969     AP4_Result result = AP4_SampleEntry::ReadFields(stream);
00970     if (result < 0) return result;
00971 
00972     // data
00973     result = stream.ReadUI32(m_Description.DisplayFlags);
00974     if (AP4_FAILED(result)) return result;
00975     result = stream.ReadUI08(m_Description.HorizontalJustification);
00976     if (AP4_FAILED(result)) return result;
00977     result = stream.ReadUI08(m_Description.VerticalJustification);
00978     if (AP4_FAILED(result)) return result;
00979     result = stream.Read(&m_Description.BackgroundColor, 4);
00980     if (AP4_FAILED(result)) return result;
00981     result = stream.ReadUI16(m_Description.TextBox.Top);
00982     if (AP4_FAILED(result)) return result;
00983     result = stream.ReadUI16(m_Description.TextBox.Left);
00984     if (AP4_FAILED(result)) return result;
00985     result = stream.ReadUI16(m_Description.TextBox.Bottom);
00986     if (AP4_FAILED(result)) return result;
00987     result = stream.ReadUI16(m_Description.TextBox.Right);
00988     if (AP4_FAILED(result)) return result;
00989     result = stream.ReadUI16(m_Description.Style.StartChar);
00990     if (AP4_FAILED(result)) return result;
00991     result = stream.ReadUI16(m_Description.Style.EndChar);
00992     if (AP4_FAILED(result)) return result;
00993     result = stream.ReadUI16(m_Description.Style.Font.Id);
00994     if (AP4_FAILED(result)) return result;
00995     result = stream.ReadUI08(m_Description.Style.Font.Face);
00996     if (AP4_FAILED(result)) return result;
00997     result = stream.ReadUI08(m_Description.Style.Font.Size);
00998     if (AP4_FAILED(result)) return result;
00999     result = stream.Read(&m_Description.Style.Font.Color, 4);
01000     if (AP4_FAILED(result)) return result;
01001 
01002     return AP4_SUCCESS;
01003 }
01004 
01005 /*----------------------------------------------------------------------
01006 |       AP4_Tx3gSampleEntry::WriteFields
01007 +---------------------------------------------------------------------*/
01008 AP4_Result
01009 AP4_Tx3gSampleEntry::WriteFields(AP4_ByteStream& stream)
01010 {
01011     // sample entry
01012     AP4_Result result = AP4_SampleEntry::WriteFields(stream);
01013     if (AP4_FAILED(result)) return result;
01014     
01015     // TODO: data
01016 
01017     return result;
01018 }
01019 
01020 /*----------------------------------------------------------------------
01021 |       AP4_Tx3gSampleEntry::InspectFields
01022 +---------------------------------------------------------------------*/
01023 AP4_Result
01024 AP4_Tx3gSampleEntry::InspectFields(AP4_AtomInspector& inspector)
01025 {
01026     // sample entry
01027     AP4_SampleEntry::InspectFields(inspector);
01028     
01029     // TODO: fields
01030     
01031     return AP4_SUCCESS;
01032 }
01033 
01034 /*----------------------------------------------------------------------
01035 |       AP4_Tx3gSampleEntry::GetFontNameById
01036 +---------------------------------------------------------------------*/
01037 
01038 AP4_Result 
01039 AP4_Tx3gSampleEntry::GetFontNameById(AP4_Ordinal Id, AP4_String& Name)
01040 {
01041         if(AP4_FtabAtom* ftab = dynamic_cast<AP4_FtabAtom*>(GetChild(AP4_ATOM_TYPE_FTAB)))
01042         {
01043                 AP4_Array<AP4_FtabAtom::AP4_Tx3gFontRecord> FontRecords = ftab->GetFontRecords();
01044 
01045                 for(int i = 0, j = FontRecords.ItemCount(); i < j; i++)
01046                 {
01047                         if(Id == FontRecords[i].Id)
01048                         {
01049                                 Name = FontRecords[i].Name;
01050                                 return AP4_SUCCESS;
01051                         }
01052                 }
01053         }
01054 
01055         return AP4_FAILURE;
01056 }

Generated on Tue Dec 13 14:47:20 2005 for guliverkli by  doxygen 1.4.5