00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _AP4_PROTECTION_H_
00030 #define _AP4_PROTECTION_H_
00031
00032
00033
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
00042
00043
00044
00045
00046 const unsigned int AP4_PROTECTION_KEY_LENGTH = 16;
00047
00048 const AP4_UI32 AP4_PROTECTION_SCHEME_TYPE_ITUNES = AP4_ATOM_TYPE('i','t','u','n');
00049
00050
00051
00052
00053 class AP4_EncaSampleEntry : public AP4_AudioSampleEntry
00054 {
00055 public:
00056
00057 AP4_EncaSampleEntry(AP4_Size size,
00058 AP4_ByteStream& stream,
00059 AP4_AtomFactory& atom_factory);
00060 AP4_EncaSampleEntry(AP4_UI32 type,
00061 AP4_Size size,
00062 AP4_ByteStream& stream,
00063 AP4_AtomFactory& atom_factory);
00064
00065
00066 AP4_SampleDescription* ToSampleDescription();
00067 };
00068
00069
00070
00071
00072 class AP4_EncvSampleEntry : public AP4_VisualSampleEntry
00073 {
00074 public:
00075
00076 AP4_EncvSampleEntry(AP4_Size size,
00077 AP4_ByteStream& stream,
00078 AP4_AtomFactory& atom_factory);
00079 AP4_EncvSampleEntry(AP4_UI32 type,
00080 AP4_Size size,
00081 AP4_ByteStream& stream,
00082 AP4_AtomFactory& atom_factory);
00083
00084
00085 AP4_SampleDescription* ToSampleDescription();
00086 };
00087
00088
00089
00090
00091 class AP4_DrmsSampleEntry : public AP4_EncaSampleEntry
00092 {
00093 public:
00094
00095 AP4_DrmsSampleEntry(AP4_Size size,
00096 AP4_ByteStream& stream,
00097 AP4_AtomFactory& atom_factory);
00098 };
00099
00100
00101
00102
00103 class AP4_DrmiSampleEntry : public AP4_EncvSampleEntry
00104 {
00105 public:
00106
00107 AP4_DrmiSampleEntry(AP4_Size size,
00108 AP4_ByteStream& stream,
00109 AP4_AtomFactory& atom_factory);
00110 };
00111
00112
00113
00114
00115 class AP4_ProtectionKeyMap
00116 {
00117 public:
00118
00119 AP4_ProtectionKeyMap();
00120 ~AP4_ProtectionKeyMap();
00121
00122
00123 AP4_Result SetKey(AP4_UI32 track_id, const AP4_UI08* key, const AP4_UI08* iv = NULL);
00124 AP4_Result SetKeys(const AP4_ProtectionKeyMap& key_map);
00125 AP4_Result GetKeyAndIv(AP4_UI32 track_id, const AP4_UI08*& key, const AP4_UI08*& iv);
00126 const AP4_UI08* GetKey(AP4_UI32 track_id) const;
00127
00128 private:
00129
00130 class KeyEntry {
00131 public:
00132 KeyEntry(AP4_UI32 track_id, const AP4_UI08* key, const AP4_UI08* iv = NULL);
00133 void SetKey(const AP4_UI08* key, const AP4_UI08* iv);
00134 AP4_Ordinal m_TrackId;
00135 AP4_UI08 m_Key[AP4_PROTECTION_KEY_LENGTH];
00136 AP4_UI08 m_IV[AP4_PROTECTION_KEY_LENGTH];
00137 };
00138
00139
00140 KeyEntry* GetEntry(AP4_UI32 track_id) const;
00141
00142
00143 AP4_List<KeyEntry> m_KeyEntries;
00144 };
00145
00146
00147
00148
00149 class AP4_ProtectionSchemeInfo
00150 {
00151 public:
00152
00153 AP4_ProtectionSchemeInfo(AP4_ContainerAtom* schi);
00154 virtual ~AP4_ProtectionSchemeInfo();
00155
00156
00157 AP4_ContainerAtom* GetSchiAtom() { return m_SchiAtom; }
00158
00159 protected:
00160 AP4_ContainerAtom* m_SchiAtom;
00161 };
00162
00163
00164
00165
00166 class AP4_ProtectedSampleDescription : public AP4_SampleDescription
00167 {
00168 public:
00169
00170 AP4_ProtectedSampleDescription(AP4_UI32 format,
00171 AP4_SampleDescription* original_sample_description,
00172 AP4_UI32 original_format,
00173 AP4_UI32 scheme_type,
00174 AP4_UI32 scheme_version,
00175 const char* scheme_uri,
00176 AP4_ContainerAtom* schi_atom);
00177 ~AP4_ProtectedSampleDescription();
00178
00179
00180 AP4_SampleDescription* GetOriginalSampleDescription() {
00181 return m_OriginalSampleDescription;
00182 }
00183 AP4_UI32 GetOriginalFormat() const { return m_OriginalFormat; }
00184 AP4_UI32 GetSchemeType() const { return m_SchemeType; }
00185 AP4_UI32 GetSchemeVersion() const { return m_SchemeVersion; }
00186 const AP4_String& GetSchemeUri() const { return m_SchemeUri; }
00187 AP4_ProtectionSchemeInfo* GetSchemeInfo() const {
00188 return m_SchemeInfo;
00189 }
00190
00191
00192 virtual AP4_Atom* ToAtom() const;
00193
00194 private:
00195
00196 AP4_SampleDescription* m_OriginalSampleDescription;
00197 AP4_UI32 m_OriginalFormat;
00198 AP4_UI32 m_SchemeType;
00199 AP4_UI32 m_SchemeVersion;
00200 AP4_String m_SchemeUri;
00201 AP4_ProtectionSchemeInfo* m_SchemeInfo;
00202 };
00203
00204
00205
00206
00207 class AP4_BlockCipher
00208 {
00209 public:
00210
00211 typedef enum {
00212 ENCRYPT,
00213 DECRYPT
00214 } CipherDirection;
00215
00216 typedef enum {
00217 AES_128
00218 } CipherType;
00219
00220
00221 virtual ~AP4_BlockCipher() {}
00222
00223
00224 virtual AP4_Result ProcessBlock(const AP4_UI08* block_in, AP4_UI08* block_out) = 0;
00225 };
00226
00227
00228
00229
00230 class AP4_BlockCipherFactory
00231 {
00232 public:
00233
00234 virtual ~AP4_BlockCipherFactory() {}
00235 virtual AP4_Result Create(AP4_BlockCipher::CipherType type,
00236 AP4_BlockCipher::CipherDirection direction,
00237 const AP4_UI08* key,
00238 AP4_Size key_size,
00239 AP4_BlockCipher** cipher) = 0;
00240 };
00241
00242
00243
00244
00245 class AP4_DefaultBlockCipherFactory : public AP4_BlockCipherFactory
00246 {
00247 public:
00248
00249 static AP4_DefaultBlockCipherFactory Instance;
00250
00251
00252 virtual AP4_Result Create(AP4_BlockCipher::CipherType type,
00253 AP4_BlockCipher::CipherDirection direction,
00254 const AP4_UI08* key,
00255 AP4_Size key_size,
00256 AP4_BlockCipher** cipher);
00257 };
00258
00259
00260
00261
00262 class AP4_SampleDecrypter
00263 {
00264 public:
00265
00266 static AP4_SampleDecrypter* Create(AP4_ProtectedSampleDescription* sample_description,
00267 const AP4_UI08* key,
00268 AP4_Size key_size,
00269 AP4_BlockCipherFactory* block_cipher_factory = NULL);
00270
00271
00272 virtual ~AP4_SampleDecrypter() {}
00273
00274
00275 virtual AP4_Result DecryptSampleData(AP4_DataBuffer& data_in,
00276 AP4_DataBuffer& data_out) = 0;
00277 };
00278
00279
00280
00281
00282 class AP4_StandardDecryptingProcessor : public AP4_Processor
00283 {
00284 public:
00285
00286 AP4_StandardDecryptingProcessor(AP4_BlockCipherFactory* block_cipher_factory = NULL);
00287
00288
00289 AP4_ProtectionKeyMap& GetKeyMap() { return m_KeyMap; }
00290
00291
00292 virtual AP4_Processor::TrackHandler* CreateTrackHandler(AP4_TrakAtom* trak);
00293 virtual AP4_Result Initialize(AP4_AtomParent& top_level,
00294 ProgressListener* listener);
00295
00296 private:
00297
00298 AP4_BlockCipherFactory* m_BlockCipherFactory;
00299 AP4_ProtectionKeyMap m_KeyMap;
00300 };
00301
00302 #endif // _AP4_PROTECTION_H_