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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - Sample Description Objects
  4. |
  5. |    Copyright 2002 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. #ifndef _AP4_ISMACRYP_H_
  29. #define _AP4_ISMACRYP_H_
  30. /*----------------------------------------------------------------------
  31. |       includes
  32. +---------------------------------------------------------------------*/
  33. #include "Ap4Types.h"
  34. #include "Ap4SampleEntry.h"
  35. #include "Ap4Atom.h"
  36. #include "Ap4AtomFactory.h"
  37. #include "Ap4SampleDescription.h"
  38. #include "Ap4Processor.h"
  39. /*----------------------------------------------------------------------
  40. |       class references
  41. +---------------------------------------------------------------------*/
  42. class AP4_StreamCipher;
  43. /*----------------------------------------------------------------------
  44. |       constants
  45. +---------------------------------------------------------------------*/
  46. const AP4_UI32 AP4_ISMACRYP_SCHEME_TYPE_IAEC = AP4_ATOM_TYPE('i','A','E','C');
  47. const AP4_Size AP4_ISMACRYP_IAEC_KEY_LENGTH = 16;
  48. /*----------------------------------------------------------------------
  49. |       AP4_EncaSampleEntry
  50. +---------------------------------------------------------------------*/
  51. class AP4_EncaSampleEntry : public AP4_AudioSampleEntry
  52. {
  53. public:
  54.     // methods
  55.     AP4_EncaSampleEntry(AP4_Size         size,
  56.                         AP4_ByteStream&  stream,
  57.                         AP4_AtomFactory& atom_factory);
  58.     AP4_EncaSampleEntry(AP4_UI32          sample_rate, 
  59.                         AP4_UI16          sample_size,
  60.                         AP4_UI16          channel_count,
  61.                         AP4_EsDescriptor* descriptor);
  62.     // methods
  63.     AP4_SampleDescription* ToSampleDescription();
  64. };
  65. /*----------------------------------------------------------------------
  66. |       AP4_EncvSampleEntry
  67. +---------------------------------------------------------------------*/
  68. class AP4_EncvSampleEntry : public AP4_VisualSampleEntry
  69. {
  70. public:
  71.     // constructors
  72.     AP4_EncvSampleEntry(AP4_Size         size,
  73.                         AP4_ByteStream&  stream,
  74.                         AP4_AtomFactory& atom_factory);
  75.     AP4_EncvSampleEntry(AP4_UI16          width,
  76.                         AP4_UI16          height,
  77.                         AP4_UI16          depth,
  78.                         const char*       compressor_name,
  79.                         AP4_EsDescriptor* descriptor);
  80.     // methods
  81.     AP4_SampleDescription* ToSampleDescription();
  82. };
  83. /*----------------------------------------------------------------------
  84. |       AP4_IsmaKeyMap
  85. +---------------------------------------------------------------------*/
  86. class AP4_IsmaKeyMap
  87. {
  88. public:
  89.     // constructors and destructor
  90.     AP4_IsmaKeyMap();
  91.     ~AP4_IsmaKeyMap();
  92.     // methods
  93.     AP4_Result SetKey(AP4_UI32 track_id, const AP4_UI08* key, const AP4_UI08* salt = NULL);
  94.     AP4_Result GetKey(AP4_UI32 track_id, const AP4_UI08*& key, const AP4_UI08*& salt);
  95. private:
  96.     // types
  97.     class KeyEntry {
  98.     public:
  99.         KeyEntry(AP4_UI32 track_id, const AP4_UI08* key, const AP4_UI08* salt = NULL);
  100.         void SetKey(const AP4_UI08* key, const AP4_UI08* salt);
  101.         AP4_Ordinal m_TrackId;
  102.         AP4_UI08    m_Key[AP4_ISMACRYP_IAEC_KEY_LENGTH];
  103.         AP4_UI08    m_Salt[AP4_ISMACRYP_IAEC_KEY_LENGTH];
  104.     };
  105.     // methods
  106.     KeyEntry* GetEntry(AP4_UI32 track_id);
  107.     // members
  108.     AP4_List<KeyEntry> m_KeyEntries;
  109. };
  110. /*----------------------------------------------------------------------
  111. |       AP4_IsmaSchemeInfo
  112. +---------------------------------------------------------------------*/
  113. class AP4_IsmaCrypSchemeInfo
  114. {
  115. public:
  116.     // constructors and destructor
  117.     AP4_IsmaCrypSchemeInfo(AP4_ContainerAtom* schi);
  118.     virtual ~AP4_IsmaCrypSchemeInfo(){}
  119.     // accessors
  120.     AP4_ContainerAtom& GetSchiAtom() { return m_SchiAtom; }
  121. protected:
  122.     AP4_ContainerAtom m_SchiAtom;
  123. };
  124. /*----------------------------------------------------------------------
  125. |       AP4_IsmaCrypSampleDescription
  126. +---------------------------------------------------------------------*/
  127. class AP4_IsmaCrypSampleDescription : public AP4_SampleDescription
  128. {
  129. public:
  130.     // constructor and destructor
  131.     AP4_IsmaCrypSampleDescription(AP4_MpegSampleDescription* original_sample_description,
  132.                                   AP4_UI32                   original_format,
  133.                                   AP4_UI32                   scheme_type,
  134.                                   AP4_UI32                   scheme_version,
  135.                                   const char*                scheme_uri,
  136.                                   AP4_ContainerAtom*         schi_atom);
  137.     ~AP4_IsmaCrypSampleDescription();
  138.     
  139.     // accessors
  140.     AP4_MpegSampleDescription* GetOriginalSampleDescription() {
  141.         return m_OriginalSampleDescription;
  142.     }
  143.     AP4_UI32    GetOriginalFormat() { return m_OriginalFormat; }
  144.     AP4_UI32    GetSchemeType()     { return m_SchemeType;     }
  145.     AP4_UI32    GetSchemeVersion()  { return m_SchemeVersion;  }
  146.     AP4_String& GetSchemeUri()      { return m_SchemeUri;      }
  147.     AP4_IsmaCrypSchemeInfo* GetSchemeInfo() { return m_SchemeInfo; }
  148.     // implementation of abstract base class methods
  149.     virtual AP4_Atom* ToAtom() const;
  150. private:
  151.     // members
  152.     AP4_MpegSampleDescription* m_OriginalSampleDescription;
  153.     AP4_UI32                   m_OriginalFormat;
  154.     AP4_UI32                   m_SchemeType;
  155.     AP4_UI32                   m_SchemeVersion;
  156.     AP4_String                 m_SchemeUri;
  157.     AP4_IsmaCrypSchemeInfo*    m_SchemeInfo;
  158. };
  159. /*----------------------------------------------------------------------
  160. |       AP4_IsmaCipher
  161. +---------------------------------------------------------------------*/
  162. class AP4_IsmaCipher
  163. {
  164. public:
  165.     // constructor and destructor
  166.     AP4_IsmaCipher(const AP4_UI08* key, 
  167.                    const AP4_UI08* salt,
  168.                    AP4_Size        iv_length,
  169.                    AP4_Size        key_indicator_length,
  170.                    bool            selective_encryption);
  171.    ~AP4_IsmaCipher();
  172.     AP4_Result EncryptSample(AP4_DataBuffer& data_in,
  173.                              AP4_DataBuffer& data_out,
  174.                              AP4_Offset      iv,
  175.                              bool            skip_encryption);
  176.     AP4_Result DecryptSample(AP4_DataBuffer& data_in,
  177.                              AP4_DataBuffer& data_out);
  178. private:
  179.     // members
  180.     AP4_StreamCipher* m_Cipher;
  181.     AP4_Size          m_IvLength;
  182.     AP4_Size          m_KeyIndicatorLength;
  183.     bool              m_SelectiveEncryption;
  184. };
  185. /*----------------------------------------------------------------------
  186. |       AP4_IsmaDecryptingProcessor
  187. +---------------------------------------------------------------------*/
  188. class AP4_IsmaDecryptingProcessor : public AP4_Processor
  189. {
  190. public:
  191.     // accessors
  192.     AP4_IsmaKeyMap& GetKeyMap() { return m_KeyMap; }
  193.     // methods
  194.     virtual AP4_Processor::TrackHandler* CreateTrackHandler(AP4_TrakAtom* trak);
  195. private:
  196.     // members
  197.     AP4_IsmaKeyMap m_KeyMap;
  198. };
  199. /*----------------------------------------------------------------------
  200. |       AP4_IsmaEncryptingProcessor
  201. +---------------------------------------------------------------------*/
  202. class AP4_IsmaEncryptingProcessor : public AP4_Processor
  203. {
  204. public:
  205.     // constructors and destructor
  206.     AP4_IsmaEncryptingProcessor(const char* kms_uri);
  207.     // accessors
  208.     AP4_IsmaKeyMap& GetKeyMap() { return m_KeyMap; }
  209.     // methods
  210.     virtual AP4_Processor::TrackHandler* CreateTrackHandler(AP4_TrakAtom* trak);
  211. private:
  212.     // members
  213.     AP4_IsmaKeyMap m_KeyMap;
  214.     AP4_String     m_KmsUri;
  215. };
  216. #endif // _AP4_ISMACRYP_H_