Ap4IsmaCryp.h

Go to the documentation of this file.
00001 /*****************************************************************
00002 |
00003 |    AP4 - ISMA E&A support
00004 |
00005 |    Copyright 2002-2006 Gilles Boccon-Gibod & Julien Boeuf & 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 #ifndef _AP4_ISMACRYP_H_
00030 #define _AP4_ISMACRYP_H_
00031 
00032 /*----------------------------------------------------------------------
00033 |   includes
00034 +---------------------------------------------------------------------*/
00035 #include "Ap4Types.h"
00036 #include "Ap4SampleEntry.h"
00037 #include "Ap4Atom.h"
00038 #include "Ap4AtomFactory.h"
00039 #include "Ap4SampleDescription.h"
00040 #include "Ap4Processor.h"
00041 #include "Ap4Protection.h"
00042 
00043 /*----------------------------------------------------------------------
00044 |   class references
00045 +---------------------------------------------------------------------*/
00046 class AP4_CtrStreamCipher;
00047 class AP4_IsfmAtom;
00048 
00049 /*----------------------------------------------------------------------
00050 |   constants
00051 +---------------------------------------------------------------------*/
00052 const AP4_UI32 AP4_PROTECTION_SCHEME_TYPE_IAEC = AP4_ATOM_TYPE('i','A','E','C');
00053 
00054 /*----------------------------------------------------------------------
00055 |   AP4_IsmaCipher
00056 +---------------------------------------------------------------------*/
00057 class AP4_IsmaCipher : public AP4_SampleDecrypter
00058 {
00059 public:
00060     // factory
00061     static AP4_Result CreateSampleDecrypter(AP4_ProtectedSampleDescription* sample_description,
00062                                             const AP4_UI08*                 key, 
00063                                             AP4_Size                        key_size,
00064                                             AP4_BlockCipherFactory*         block_cipher_factory,
00065                                             AP4_IsmaCipher**                decrypter);
00066 
00067     // constructor and destructor
00068     AP4_IsmaCipher(AP4_BlockCipher* block_cipher, 
00069                    const AP4_UI08*  salt,
00070                    AP4_UI08         iv_length,
00071                    AP4_UI08         key_indicator_length,
00072                    bool             selective_encryption);
00073    ~AP4_IsmaCipher();
00074     AP4_Result EncryptSampleData(AP4_DataBuffer& data_in,
00075                                  AP4_DataBuffer& data_out,
00076                                  AP4_UI32        offset);
00077     AP4_Result DecryptSampleData(AP4_DataBuffer& data_in,
00078                                  AP4_DataBuffer& data_out);
00079     AP4_CtrStreamCipher* GetCipher()   { return m_Cipher;   }
00080     AP4_UI08             GetIvLength() { return m_IvLength; }
00081     AP4_UI08             GetKeyIndicatorLength() { return m_KeyIndicatorLength; }
00082     bool                 GetSelectiveEncryption(){ return m_SelectiveEncryption;}
00083 
00084 private:
00085     // members
00086     AP4_CtrStreamCipher* m_Cipher;
00087     AP4_UI08             m_IvLength;
00088     AP4_UI08             m_KeyIndicatorLength;
00089     bool                 m_SelectiveEncryption;
00090 };
00091 
00092 /*----------------------------------------------------------------------
00093 |   AP4_IsmaTrackDecrypter
00094 +---------------------------------------------------------------------*/
00095 class AP4_IsmaTrackDecrypter : public AP4_Processor::TrackHandler {
00096 public:
00097     // construction
00098     static AP4_Result Create(const AP4_UI08*                 key, 
00099                              AP4_Size                        key_size,
00100                              AP4_ProtectedSampleDescription* sample_description,
00101                              AP4_SampleEntry*                sample_entry,
00102                              AP4_BlockCipherFactory*         block_cipher_factory,
00103                              AP4_IsmaTrackDecrypter**        decrypter);
00104 
00105     virtual ~AP4_IsmaTrackDecrypter();
00106 
00107     // methods
00108     virtual AP4_Size   GetProcessedSampleSize(AP4_Sample& sample);
00109     virtual AP4_Result ProcessTrack();
00110     virtual AP4_Result ProcessSample(AP4_DataBuffer& data_in,
00111                                      AP4_DataBuffer& data_out);
00112 
00113 private:
00114     // constructor
00115     AP4_IsmaTrackDecrypter(AP4_IsmaCipher*  cipher,
00116                            AP4_SampleEntry* sample_entry,
00117                            AP4_UI32         original_format);
00118 
00119     // members
00120     AP4_IsmaCipher*  m_Cipher;
00121     AP4_SampleEntry* m_SampleEntry;
00122     AP4_UI32         m_OriginalFormat;
00123 };
00124 
00125 /*----------------------------------------------------------------------
00126 |   AP4_IsmaEncryptingProcessor
00127 +---------------------------------------------------------------------*/
00128 class AP4_IsmaEncryptingProcessor : public AP4_Processor
00129 {
00130 public:
00131     // constructors and destructor
00132     AP4_IsmaEncryptingProcessor(const char*             kms_uri,
00133                                 AP4_BlockCipherFactory* block_cipher_factory = NULL);
00134 
00135     // accessors
00136     AP4_ProtectionKeyMap& GetKeyMap() { return m_KeyMap; }
00137 
00138     // methods
00139     virtual AP4_Processor::TrackHandler* CreateTrackHandler(AP4_TrakAtom* trak);
00140 
00141 private:
00142     // members
00143     AP4_ProtectionKeyMap    m_KeyMap;
00144     AP4_String              m_KmsUri;
00145     AP4_BlockCipherFactory* m_BlockCipherFactory;
00146 };
00147 
00148 #endif // _AP4_ISMACRYP_H_

Generated on Thu Mar 15 16:06:11 2007 for Bento4 MP4 SDK by  doxygen 1.5.1-p1