Ap4Co64Atom.cpp
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:5k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - co64 Atoms 
  4. |
  5. |    Copyright 2002 Gilles Boccon-Gibod
  6. |
  7. |
  8. |    This file is part of Bento4/AP4 (MP4 Atom Processing Library).
  9. |
  10. |    Unless you have obtained Bento4 under a difference license,
  11. |    this version of Bento4 is Bento4|GPL.
  12. |    Bento4|GPL is free software; you can redistribute it and/or modify
  13. |    it under the terms of the GNU General Public License as published by
  14. |    the Free Software Foundation; either version 2, or (at your option)
  15. |    any later version.
  16. |
  17. |    Bento4|GPL is distributed in the hope that it will be useful,
  18. |    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. |    GNU General Public License for more details.
  21. |
  22. |    You should have received a copy of the GNU General Public License
  23. |    along with Bento4|GPL; see the file COPYING.  If not, write to the
  24. |    Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  25. |    02111-1307, USA.
  26. |
  27.  ****************************************************************/
  28. /*----------------------------------------------------------------------
  29. |       includes
  30. +---------------------------------------------------------------------*/
  31. #include "Ap4.h"
  32. #include "Ap4Co64Atom.h"
  33. #include "Ap4AtomFactory.h"
  34. #include "Ap4Utils.h"
  35. /*----------------------------------------------------------------------
  36. |       AP4_Co64Atom::AP4_Co64Atom
  37. +---------------------------------------------------------------------*/
  38. AP4_Co64Atom::AP4_Co64Atom(AP4_UI64* entries, AP4_UI32 entry_count) :
  39. AP4_Atom(AP4_ATOM_TYPE_CO64,  
  40.          AP4_FULL_ATOM_HEADER_SIZE+4+entry_count*8, 
  41.          true),
  42.          m_Entries(new AP4_UI64[entry_count]),
  43.          m_EntryCount(entry_count)
  44. {
  45.     memcpy(m_Entries, entries, m_EntryCount*8);
  46. }
  47. /*----------------------------------------------------------------------
  48. |       AP4_Co64Atom::AP4_Co64Atom
  49. +---------------------------------------------------------------------*/
  50. AP4_Co64Atom::AP4_Co64Atom(AP4_Size size, AP4_ByteStream& stream) :
  51.     AP4_Atom(AP4_ATOM_TYPE_CO64, size, true, stream)
  52. {
  53.     stream.ReadUI32(m_EntryCount);
  54.     if (m_EntryCount > (size-AP4_FULL_ATOM_HEADER_SIZE-4)/8) {
  55.         m_EntryCount = (size-AP4_FULL_ATOM_HEADER_SIZE-4)/8;
  56.     }
  57.     m_Entries = new AP4_UI64[m_EntryCount];
  58.     for (AP4_Ordinal i=0; i<m_EntryCount; i++) {
  59.         stream.ReadUI64(m_Entries[i]);
  60.     }
  61. }
  62. /*----------------------------------------------------------------------
  63. |       AP4_Co64Atom::~AP4_Co64Atom
  64. +---------------------------------------------------------------------*/
  65. AP4_Co64Atom::~AP4_Co64Atom()
  66. {
  67.     delete[] m_Entries;
  68. }
  69. /*----------------------------------------------------------------------
  70. |       AP4_Co64Atom::GetChunkOffset
  71. +---------------------------------------------------------------------*/
  72. AP4_Result
  73. AP4_Co64Atom::GetChunkOffset(AP4_Ordinal chunk, AP4_Offset& chunk_offset)
  74. {
  75.     // check the bounds
  76.     if (chunk > m_EntryCount || chunk == 0) {
  77.         return AP4_ERROR_OUT_OF_RANGE;
  78.     }
  79.     // get the chunk offset
  80.     chunk_offset = m_Entries[chunk - 1]; // m_Entries is zero index based
  81.     return AP4_SUCCESS;
  82. }
  83. /*----------------------------------------------------------------------
  84. |       AP4_Co64Atom::SetChunkOffset
  85. +---------------------------------------------------------------------*/
  86. AP4_Result
  87. AP4_Co64Atom::SetChunkOffset(AP4_Ordinal chunk, AP4_Offset chunk_offset)
  88. {
  89.     // check the bounds
  90.     if (chunk > m_EntryCount || chunk == 0) {
  91.         return AP4_ERROR_OUT_OF_RANGE;
  92.     }
  93.     // get the chunk offset
  94.     m_Entries[chunk - 1] = chunk_offset; // m_Entries is zero index based
  95.     return AP4_SUCCESS;
  96. }
  97. /*----------------------------------------------------------------------
  98. |       AP4_Co64Atom::AdjustChunkOffsets
  99. +---------------------------------------------------------------------*/
  100. AP4_Result
  101. AP4_Co64Atom::AdjustChunkOffsets(AP4_Offset offset)
  102. {
  103.     for (AP4_Ordinal i=0; i<m_EntryCount; i++) {
  104.         m_Entries[i] += offset;
  105.     }
  106.     return AP4_SUCCESS;
  107. }
  108. /*----------------------------------------------------------------------
  109. |       AP4_Co64Atom::WriteFields
  110. +---------------------------------------------------------------------*/
  111. AP4_Result
  112. AP4_Co64Atom::WriteFields(AP4_ByteStream& stream)
  113. {
  114.     AP4_Result result;
  115.     // entry count
  116.     result = stream.WriteUI32(m_EntryCount);
  117.     if (AP4_FAILED(result)) return result;
  118.     // entries
  119.     for (AP4_Ordinal i=0; i<m_EntryCount; i++) {
  120.         result = stream.WriteUI64(m_Entries[i]);
  121.         if (AP4_FAILED(result)) return result;
  122.     }
  123.     return result;
  124. }
  125. /*----------------------------------------------------------------------
  126. |       AP4_Co64Atom::InspectFields
  127. +---------------------------------------------------------------------*/
  128. AP4_Result
  129. AP4_Co64Atom::InspectFields(AP4_AtomInspector& inspector)
  130. {
  131.     inspector.AddField("entry_count", m_EntryCount);
  132.     return AP4_SUCCESS;
  133. }