/* * Copyright 2012 Google Inc. All Rights Reserved. */ #ifndef WV_CONTENT_DECRYPTION_MODULE_H_ #define WV_CONTENT_DECRYPTION_MODULE_H_ #include #include #include #include "sys/types.h" #include namespace wvcdm { class CdmDecryptor; /** * This class allows the invoker of the ContentDecryptionModule to receive * license requests and error information. The invoker should provide a * concrete implementation for this class. */ class CdmClient { public: typedef enum { kErrorInvalidInitData = 0, kErrorInvalidKeyResponse = 1, kErrorInvalidSessionId = 2, kErrorCdmDecryptorInitializationFailed = 3, kErrorKeyAddFailed = 4 } Error; CdmClient(); virtual ~CdmClient(); virtual void keyMessage(const android::String8& sessionId, const android::Vector& message, const android::String8& defaultUrl) = 0; virtual void keyAdded(const android::String8& sessionId) = 0; virtual void keyError(const android::String8& sessionId, Error error) = 0; }; /** * The ContentDecryptionModule provides a mechanism to create a license * request, handle the license response and handle decryption of content. */ class ContentDecryptionModule { public: explicit ContentDecryptionModule(CdmClient* client); virtual ~ContentDecryptionModule(); /** * This generates a license request message and session ID for given * initialization data. * * @param[in] initData contains Content Protection system specific data * (initialization or PSSH data). * @return false on error. * @note CdmClient::keyMessage and CdmClient::keyError may be called * on successful license generation or error, respectively. */ bool generateKeyRequest(const android::Vector& initData); /** * This takes in a license response and sets up the crypto content * in preparation for decryption for a given session. * * @param[in] sessionId identifies the license request message created by * generateKeyRequest though the CdmClient::KeyMessage method. * @param[in] keyResponse is the license response from the license server. * @note CdmClient::keyError may be called on error. */ void addKey(const android::String8& sessionId, const android::Vector& keyResponse); /** * TODO:rfrias,edwinwong: These interfaces are pending finalization * of OEMCrypto APIs */ void decryptVideo(const uint8_t* keyId, const uint8_t* iv, size_t ivLength, const void* input, const android::CryptoPlugin::SubSample* subSamples, size_t numSubSamples, void* outputHandle, size_t* outputOffset, size_t* outputLength); /** * TODO:rfrias,edwinwong: These interfaces are pending finalization * of OEMCrypto APIs */ void decryptAudio(const uint8_t* keyId, const uint8_t* iv, size_t ivLength, const void* input, const android::CryptoPlugin::SubSample* subSamples, size_t numSubSamples, void* output, size_t* outputLength); /** * This releases resources and crypto contexts associated with a * given session. * * @param[in] sessionId identifies a license and associated crypto * contexts */ virtual void closeSession(const android::String8& sessionId); private: CdmClient* const mClient; android::KeyedVector mSessionIdToDecryptorMap; DISALLOW_EVIL_CONSTRUCTORS(ContentDecryptionModule); }; } // namespace wvcdm #endif // WV_CONTENT_DECRYPTION_MODULE_H_