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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - iKMS Atoms 
  4. |
  5. |    Copyright 2002-2005 Gilles Boccon-Gibod & Julien Boeuf
  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 "Ap4IkmsAtom.h"
  32. #include "Ap4Utils.h"
  33. /*----------------------------------------------------------------------
  34. |       AP4_IkmsAtom::AP4_IkmsAtom
  35. +---------------------------------------------------------------------*/
  36. AP4_IkmsAtom::AP4_IkmsAtom(const char* kms_uri) :
  37.     AP4_Atom(AP4_ATOM_TYPE_IKMS, AP4_FULL_ATOM_HEADER_SIZE, true),
  38.     m_KmsUri(kms_uri)
  39. {
  40.     m_Size += m_KmsUri.length()+1;
  41. }
  42. /*----------------------------------------------------------------------
  43. |       AP4_IkmsAtom::AP4_IkmsAtom
  44. +---------------------------------------------------------------------*/
  45. AP4_IkmsAtom::AP4_IkmsAtom(AP4_Size size, AP4_ByteStream& stream) :
  46.     AP4_Atom(AP4_ATOM_TYPE_IKMS, size, true, stream)
  47. {
  48.     AP4_Size string_size = size-AP4_FULL_ATOM_HEADER_SIZE;
  49.     if (string_size) {
  50.         char* str = new char[string_size];
  51.         stream.Read(str, string_size);
  52.         str[string_size-1] = ''; // force null-termination
  53.         m_KmsUri = str;
  54.         delete[] str;
  55.     }
  56. }
  57. /*----------------------------------------------------------------------
  58. |       AP4_IkmsAtom::Clone
  59. +---------------------------------------------------------------------*/
  60. AP4_Atom* 
  61. AP4_IkmsAtom::Clone()
  62. {
  63.     return new AP4_IkmsAtom(m_KmsUri.c_str());
  64. }
  65. /*----------------------------------------------------------------------
  66. |       AP4_IkmsAtom::WriteFields
  67. +---------------------------------------------------------------------*/
  68. AP4_Result
  69. AP4_IkmsAtom::WriteFields(AP4_ByteStream& stream)
  70. {
  71.     // kms uri
  72.     AP4_Result result = stream.Write(m_KmsUri.c_str(), m_KmsUri.length()+1);
  73.     if (AP4_FAILED(result)) return result;
  74.     // pad with zeros if necessary
  75.     AP4_Size padding = m_Size-(AP4_FULL_ATOM_HEADER_SIZE+m_KmsUri.length()+1);
  76.     while (padding--) stream.WriteUI08(0);
  77.     
  78.     return AP4_SUCCESS;
  79. }
  80. /*----------------------------------------------------------------------
  81. |       AP4_IkmsAtom::InspectFields
  82. +---------------------------------------------------------------------*/
  83. AP4_Result
  84. AP4_IkmsAtom::InspectFields(AP4_AtomInspector& inspector)
  85. {
  86.     inspector.AddField("kms_uri", m_KmsUri.c_str());
  87.     return AP4_SUCCESS;
  88. }