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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - iSFM 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 "Ap4Utils.h"
  32. #include "Ap4IsfmAtom.h"
  33. /*----------------------------------------------------------------------
  34. |       AP4_IsfmAtom::AP4_IsfmAtom
  35. +---------------------------------------------------------------------*/
  36. AP4_IsfmAtom::AP4_IsfmAtom(bool     selective_encryption,
  37.                            AP4_UI08 key_length_indicator,
  38.                            AP4_UI08 iv_length) :
  39.     AP4_Atom(AP4_ATOM_TYPE_ISFM, AP4_FULL_ATOM_HEADER_SIZE+3, true),
  40.     m_SelectiveEncryption(selective_encryption),
  41.     m_KeyIndicatorLength(key_length_indicator),
  42.     m_IvLength(iv_length)
  43. {
  44. }
  45. /*----------------------------------------------------------------------
  46. |       AP4_IsfmAtom::AP4_IsfmAtom
  47. +---------------------------------------------------------------------*/
  48. AP4_IsfmAtom::AP4_IsfmAtom(AP4_Size size, AP4_ByteStream& stream) :
  49.     AP4_Atom(AP4_ATOM_TYPE_ISFM, size, true, stream)
  50. {
  51.     AP4_UI08 s;
  52.     stream.ReadUI08(s);
  53.     m_SelectiveEncryption = ((s&1) != 0);
  54.     stream.ReadUI08(m_KeyIndicatorLength);
  55.     stream.ReadUI08(m_IvLength);
  56. }
  57. /*----------------------------------------------------------------------
  58. |       AP4_IsfmAtom::Clone
  59. +---------------------------------------------------------------------*/
  60. AP4_Atom* 
  61. AP4_IsfmAtom::Clone()
  62. {
  63.     return new AP4_IsfmAtom(m_SelectiveEncryption, 
  64.                             m_KeyIndicatorLength, 
  65.                             m_IvLength);
  66. }
  67. /*----------------------------------------------------------------------
  68. |       AP4_IsfmAtom::WriteFields
  69. +---------------------------------------------------------------------*/
  70. AP4_Result
  71. AP4_IsfmAtom::WriteFields(AP4_ByteStream& stream)
  72. {
  73.     AP4_Result result;
  74.     // selective encryption
  75.     result = stream.WriteUI08(m_SelectiveEncryption ? 1 : 0);
  76.     if (AP4_FAILED(result)) return result;
  77.     // key indicator length
  78.     result = stream.WriteUI08(m_KeyIndicatorLength);
  79.     if (AP4_FAILED(result)) return result;
  80.     // IV length
  81.     result = stream.WriteUI08(m_IvLength);
  82.     if (AP4_FAILED(result)) return result;
  83.     return AP4_SUCCESS;
  84. }
  85. /*----------------------------------------------------------------------
  86. |       AP4_IsfmAtom::InspectFields
  87. +---------------------------------------------------------------------*/
  88. AP4_Result
  89. AP4_IsfmAtom::InspectFields(AP4_AtomInspector& inspector)
  90. {
  91.     inspector.AddField("selective_encryption", m_SelectiveEncryption);
  92.     inspector.AddField("key_indicator_length", m_KeyIndicatorLength);
  93.     inspector.AddField("IV_length", m_IvLength);
  94.     return AP4_SUCCESS;
  95. }